fasta和fastq格式文件的shell小练习

根据网上的教程 ,加上自已的理解,做出小练习。首先打开数据

mkdir   ~/biosoft
cd ~/biosoft
wget https://sourceforge.net/projects/bowtie-bio/files/bowtie2/2.3.4.3/bowtie2-2.3.4.3-linux-x86_64.zip 
unzip bowtie2-2.3.4.3-linux-x86_64.zip 
cd ~/biosoft/bowtie2-2.3.4.3-linux-x86_64/example/reads

1.统计reads_1.fq 文件中共有多少条序列信息

less -SN reads_1.fq|  sed -n 1~4p |wc -l
![image.png](https://upload-images.jianshu.io/upload_images/15565422-f53174bc04df139d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

2.输出所有的reads_1.fq文件中的标识符(即以@开头的那一行)

grep '^@' reads_1.fq > 2.txt
cat 2.txt
![image.png](https://upload-images.jianshu.io/upload_images/15565422-5fe44c43dc74453d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

3.输出reads_1.fq文件中的 所有序列信息(即每个序列的第二行)

less -SN reads_1.fq| paste - - - - | cut -f 2
![image.png](https://upload-images.jianshu.io/upload_images/15565422-c77bd739352e453e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

4.输出以‘+’及其后面的描述信息(即每个序列的第三行)

less -SN reads_1.fq| paste - - - - | cut -f 3

5.输出质量值信息(即每个序列的第四行)

less -SN reads_1.fq| paste - - - - | cut -f 4

6. 计算reads_1.fq 文件含有N碱基的reads个数

less -SN reads_1.fq| paste - - - - | cut -f 2|grep  N|wc

7.统计文件中reads_1.fq文件里面的序列的碱基总数

less -SN reads_1.fq| paste - - - - | cut -f 2|grep -o [ATCGN]|wc

8.计算reads_1.fq 所有的reads中N碱基的总数

less -SN reads_1.fq| paste - - - - | cut -f 2|grep -o N|wc

总共有26001.

9.统计reads_1.fq 中测序碱基质量值恰好为Q20的个数

less -SN reads_1.fq| paste - - - - | cut -f 4|grep -o "5"|wc

结果为21369.

10.统计reads_1.fq 中测序碱基质量值恰好为Q30的个数

less -SN reads_1.fq| paste - - - - | cut -f 4|grep -o "?"|wc

结果为21574.

11.统计reads_1.fq 中所有序列的第一位碱基的ATCGN分布情况

less -SN reads_1.fq| paste - - - - | cut -f 2|cut -c 1|sort |uniq -c
![image.png](https://upload-images.jianshu.io/upload_images/15565422-62284dabaea2cea8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

12.将reads_1.fq 转为reads_1.fa文件(即将fastq转化为fasta)

less -SN reads_1.fq| paste - - - - | cut -f 1,2|tr '\t' '\n'|tr '@' '>'  >> reads_1.fa

13.统计上述reads_1.fa文件中共有多少条序列

wc reads_1.fa 

14.计算reads_1.fa文件中总的碱基序列的GC数量

less -SN reads_1.fa| paste - -  | cut -f 2|grep -o [GC]|wc

在使用代码的过程中,发现GC与[GC]的答案不一样,可能是与grep的参数不一样。

![image.png](https://upload-images.jianshu.io/upload_images/15565422-63040091cb1fc0f9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

15.删除 reads_1.fa文件中的每条序列的N碱基

less reads_1.fa|tr -d "N"|grep N

16.删除 reads_1.fa文件中的含有N碱基的序列

less  reads_1.fa | paste - - | grep -v N 

17.删除 reads_1.fa文件中的短于65bp的序列

less reads_1.fa | paste - -|awk '{if (length($2)>65) print}'|wc
![image.png](https://upload-images.jianshu.io/upload_images/15565422-6dd66bfe1e98f657.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

18.删除 reads_1.fa文件每条序列的前后五个碱基

less reads_1.fa | paste - - | cut -f2 |cut -c 5- |  cut -c -5

19.删除 reads_1.fa文件中的长于125bp的序列

less reads_1.fa | paste - -|awk '{if (length($2)>125) print}'|wc

第20道题,目前还不会做,研究中......

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容