生信人的linux考试20题
一、 在任意文件夹下面创建形如 1/2/3/4/5/6/7/8/9 格式的文件夹系列
vip39@VM-0-15-ubuntu:~/test$ mkdir -p 1/2/3/4/5/6/7/8/9
vip39@VM-0-15-ubuntu:~/test$ ls
1
vip39@VM-0-15-ubuntu:~/test$ tree
.
└── 1
└── 2
└── 3
└── 4
└── 5
└── 6
└── 7
└── 8
└── 9
9 directories, 0 files
- 这个题目考的
mkdir -p
的用法,详见Linux Day1: cd/pwd/mkdir/rmdir
二、在创建好的文件夹下面,比如我的是 /Users/jimmy/tmp/1/2/3/4/5/6/7/8/9 ,里面创建文本文件 me.txt
三、在文本文件 me.txt 里面输入内容:
vip39@VM-0-15-ubuntu:~/test$ cd ./1/2/3/4/5/6/7/8/9/
vip39@VM-0-15-ubuntu:~/test/1/2/3/4/5/6/7/8/9$ touch me.txt
vip39@VM-0-15-ubuntu:~/test/1/2/3/4/5/6/7/8/9$ ls
me.txt
vip39@VM-0-15-ubuntu:~/test/1/2/3/4/5/6/7/8/9$ vim me.txt
vip39@VM-0-15-ubuntu:~/test/1/2/3/4/5/6/7/8/9$ cat me.txt
Go to: http://www.biotrainee.com/
I love bioinfomatics.
And you ?
-
cd ./1/2/3/4/5/6/7/8/9/
善用Tab键补全 -
touch
、vi
/vim
、cat
的使用,详见:
Linux Day4: more/less/touch
Linux Day20:Vim
Linux Day3: cat/nl/head/tail - 这个题也可以使用:
vip39@VM-0-15-ubuntu:~/test$ cat > me.txt
Go to: http://www.biotrainee.com/
I love bioinfomatics.
And you ?
^C
vip39@VM-0-15-ubuntu:~/test$ cat me.txt
Go to: http://www.biotrainee.com/
I love bioinfomatics.
And you ?
-
>
的用法可以参考:Liunx Day15:管道和重定向
四、删除上面创建的文件夹 1/2/3/4/5/6/7/8/9
及文本文件 me.txt
vip39@VM-0-15-ubuntu:~$ cd test/
vip39@VM-0-15-ubuntu:~/test$ ls
1
vip39@VM-0-15-ubuntu:~/test$ rm -r 1/
vip39@VM-0-15-ubuntu:~/test$ ls
vip39@VM-0-15-ubuntu:~/test$ tree
.
0 directories, 0 files
-
rm
的用法,详见:Linux Day2: ls/cp/rm/mv
五、在任意文件夹下面创建 folder1~5这5个文件夹,然后每个文件夹下面继续创建 folder1~5这5个文件夹,效果如下:
vip39@VM-0-15-ubuntu:~/test$ mkdir -p folder{1..5}/folder{1..5}
vip39@VM-0-15-ubuntu:~/test$ ls *
folder1:
folder1 folder2 folder3 folder4 folder5
folder2:
folder1 folder2 folder3 folder4 folder5
folder3:
folder1 folder2 folder3 folder4 folder5
folder4:
folder1 folder2 folder3 folder4 folder5
folder5:
folder1 folder2 folder3 folder4 folder5
六、在第五题创建的每一个文件夹下面都 创建第二题文本文件 me.txt ,内容也要一样。
vip39@VM-0-15-ubuntu:~/test$ echo folder{1..5}/folder{1..5}|xargs -n 1 cp me.txt
vip39@VM-0-15-ubuntu:~/test$ tree
.
|-- folder1
| |-- folder1
| | `-- me.txt
| |-- folder2
| | `-- me.txt
| |-- folder3
| | `-- me.txt
| |-- folder4
| | `-- me.txt
| `-- folder5
| `-- me.txt
|-- folder2
| |-- folder1
| | `-- me.txt
| |-- folder2
| | `-- me.txt
| |-- folder3
| | `-- me.txt
| |-- folder4
| | `-- me.txt
| `-- folder5
| `-- me.txt
|-- folder3
| |-- folder1
| | `-- me.txt
| |-- folder2
| | `-- me.txt
| |-- folder3
| | `-- me.txt
| |-- folder4
| | `-- me.txt
| `-- folder5
| `-- me.txt
|-- folder4
| |-- folder1
| | `-- me.txt
| |-- folder2
| | `-- me.txt
| |-- folder3
| | `-- me.txt
| |-- folder4
| | `-- me.txt
| `-- folder5
| `-- me.txt
|-- folder5
| |-- folder1
| | `-- me.txt
| |-- folder2
| | `-- me.txt
| |-- folder3
| | `-- me.txt
| |-- folder4
| | `-- me.txt
| `-- folder5
| `-- me.txt
`-- me.txt
30 directories, 26 files
-
xargs
的用法xargs命令
七,再次删除掉前面几个步骤建立的文件夹及文件
vip39@VM-0-15-ubuntu:~/test$ ls
folder1 folder2 folder3 folder4 folder5 me.txt
vip39@VM-0-15-ubuntu:~/test$ rm -rf folder*
vip39@VM-0-15-ubuntu:~/test$ ls
me.txt
vip39@VM-0-15-ubuntu:~/test$ rm me.txt
vip39@VM-0-15-ubuntu:~/test$ ls
vip39@VM-0-15-ubuntu:~/test$
八、下载 http://www.biotrainee.com/jmzeng/igv/test.bed 文件,后在里面选择含有 H3K4me3 的那一行是第几行,该文件总共有几行。
vip39@VM-0-15-ubuntu:~/test$ wget -c http://www.biotrainee.com/jmzeng/igv/test.bed
--2018-12-11 20:14:50-- http://www.biotrainee.com/jmzeng/igv/test.bed
Resolving www.biotrainee.com (www.biotrainee.com)... 123.206.72.184
Connecting to www.biotrainee.com (www.biotrainee.com)|123.206.72.184|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3099 (3.0K)
Saving to: ‘test.bed’
test.bed 100%[=========================>] 3.03K --.-KB/s in 0s
2018-12-11 20:14:50 (480 MB/s) - ‘test.bed’ saved [3099/3099]
vip39@VM-0-15-ubuntu:~/test$ ls
test.bed
vip39@VM-0-15-ubuntu:~/test$ cat test.bed | grep -n H3K4me3
8:chr1 9810 10438 ID=SRX387603;Name=H3K4me3%20(@%20HMLE);Title=GSM1280527:%20HMLE%20Twist3D%20H3K4me3%20rep2%3B%20Homo%20sapiens%3B%20ChIP-Seq;Cell%20group=Breast;<br>source_name=HMLE_Twist3D_H3K4me3;cell%20type=human%20mammary%20epithelial%20cells;transfected%20with=Twist1;culture%20type=sphere;chip%20antibody=H3K4me3;chip%20antibody%20vendor=Millipore; 222 . 9810 10438 0,226,255
vip39@VM-0-15-ubuntu:~/test$ cat test.bed |wc
10 88 3099
-
grep
及wc
的用法可见:
Linux Day21:grep/sed/awk
wc的用法
九、下载 http://www.biotrainee.com/jmzeng/rmDuplicate.zip 文件,并且解压,查看里面的文件夹结构
# 下载
vip39@VM-0-15-ubuntu:~/test$ wget http://www.biotrainee.com/jmzeng/rmDuplicate.zip
--2018-12-11 21:02:42-- http://www.biotrainee.com/jmzeng/rmDuplicate.zip
Resolving www.biotrainee.com (www.biotrainee.com)... 123.206.72.184
Connecting to www.biotrainee.com (www.biotrainee.com)|123.206.72.184|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104931 (102K) [application/zip]
Saving to: ‘rmDuplicate.zip’
rmDuplicate.zip 100%[=========================>] 102.47K 523KB/s in 0.2s
2018-12-11 21:02:43 (523 KB/s) - ‘rmDuplicate.zip’ saved [104931/104931]
vip39@VM-0-15-ubuntu:~/test$ ls
rmDuplicate.zip test.bed
# 解压
vip39@VM-0-15-ubuntu:~/test$ unzip rmDuplicate.zip
Archive: rmDuplicate.zip
creating: rmDuplicate/
creating: rmDuplicate/picard/
creating: rmDuplicate/picard/paired/
inflating: rmDuplicate/picard/paired/readme.txt
···
inflating: rmDuplicate/samtools/single/tmp.sorted.vcf.gz
# 查看文件结构
vip39@VM-0-15-ubuntu:~/test$ cd rmDuplicate/
vip39@VM-0-15-ubuntu:~/test/rmDuplicate$ tree
.
├── picard
│ ├── paired
│ │ ├── readme.txt
│ │ ├── tmp.header
│ │ ├── tmp.MarkDuplicates.log
│ │ ├── tmp.metrics
│ │ ├── tmp.rmdup.bai
│ │ ├── tmp.rmdup.bam
│ │ ├── tmp.sam
│ │ └── tmp.sorted.bam
│ └── single
│ ├── readme.txt
│ ├── tmp.header
│ ├── tmp.MarkDuplicates.log
│ ├── tmp.metrics
│ ├── tmp.rmdup.bai
│ ├── tmp.rmdup.bam
│ ├── tmp.sam
│ └── tmp.sorted.bam
└── samtools
├── paired
│ ├── readme.txt
│ ├── tmp.header
│ ├── tmp.rmdup.bam
│ ├── tmp.rmdup.vcf.gz
│ ├── tmp.sam
│ ├── tmp.sorted.bam
│ └── tmp.sorted.vcf.gz
└── single
├── readme.txt
├── tmp.header
├── tmp.rmdup.bam
├── tmp.rmdup.vcf.gz
├── tmp.sam
├── tmp.sorted.bam
└── tmp.sorted.vcf.gz
6 directories, 30 files
- 解压命令的使用Linux Day27:Linux 压缩、解压缩命令
十、打开第九题解压的文件,进入 rmDuplicate/samtools/single 文件夹里面,查看后缀为 .sam 的文件,搞清楚 生物信息学里面的SAM/BAM 定义是什么
- 详细可看浅谈SAM格式
十一、安装 samtools 软件
vip39@VM-0-15-ubuntu:~/src$ source ~/miniconda3/bin/activate
(base) vip39@VM-0-15-ubuntu:~/src$ conda install samtools=1.8 y
# 检查一下能否运行
(base) vip39@VM-0-15-ubuntu:~/src$ samtools
Program: samtools (Tools for alignments in the SAM format)
Version: 1.7 (using htslib 1.7)
Usage: samtools <command> [options]
- conda的安装及使用:Conda的安装
十二、打开后缀为BAM 的文件,找到产生该文件的命令。 提示一下命令是:
十三题、根据上面的命令,找到我使用的参考基因组 /home/jianmingzeng/reference/index/bowtie/hg38 具体有多少条染色体
(base) vip39@VM-0-15-ubuntu:~$ samtools view -H ~/test/rmDuplicate/samtools/single/tmp.sorted.bam |awk '{print $2}'|cut -c4-9|sort -n|uniq -c|grep -v '_'
1 bowtie
1 chr1
1 chr10
1 chr11
1 chr12
1 chr13
1 chr14
1 chr15
1 chr16
1 chr17
1 chr18
1 chr19
1 chr2
1 chr20
1 chr21
1 chr22
1 chr3
1 chr4
1 chr5
1 chr6
1 chr7
1 chr8
1 chr9
1 chrM
1 chrX
1 chrY
1 1.0
(base) vip39@VM-0-15-ubuntu:~$ samtools view -H ~/test/rmDuplicate/samtools/single/tmp.sorted.bam |awk '{print $2}'|cut -c4-9|sort -n|uniq -c|grep -v '_'|wc
27 54 365
# 不算前两个,应该是25条
十四题、上面的后缀为BAM 的文件的第二列,只有 0 和 16 两个数字,用 cut/sort/uniq等命令统计它们的个数。
(base) vip39@VM-0-15-ubuntu:~$ samtools view ~/test/rmDuplicate/samtools/single/tmp.sorted.bam |cut -f2|sort|uniq -c
29 0
24 16
十五题、重新打开 rmDuplicate/samtools/paired 文件夹下面的后缀为BAM 的文件,再次查看第二列,并且统计
(base) vip39@VM-0-15-ubuntu:~/test/rmDuplicate/samtools/paired$ samtools view tmp.sorted.bam | cut -f2|sort -n |uniq -c
3 83
2 97
9 99
8 147
3 163
1 323
1 353
1 371
1 387
1 433
十六题、下载 http://www.biotrainee.com/jmzeng/sickle/sickle-results.zip 文件,并且解压,查看里面的文件夹结构, 这个文件有2.3M,注意留心下载时间及下载速度。
(base) vip39@VM-0-15-ubuntu:~/test$ cd sickle-results/
(base) vip39@VM-0-15-ubuntu:~/test/sickle-results$ tree
.
├── command.txt
├── single_tmp_fastqc.html
├── single_tmp_fastqc.zip
├── test1_fastqc.html
├── test1_fastqc.zip
├── test2_fastqc.html
├── test2_fastqc.zip
├── trimmed_output_file1_fastqc.html
├── trimmed_output_file1_fastqc.zip
├── trimmed_output_file2_fastqc.html
└── trimmed_output_file2_fastqc.zip
十七题、解压 sickle-results/single_tmp_fastqc.zip 文件,并且进入解压后的文件夹,找到 fastqc_data.txt 文件,并且搜索该文本文件以 >>开头的有多少行?
(base) vip39@VM-0-15-ubuntu:~/test/sickle-results/single_tmp_fastqc$ cat fastqc_data.txt | grep '^>>'|wc -l
24
# 也可以使用:
(base) vip39@VM-0-15-ubuntu:~/test/sickle-results/single_tmp_fastqc$ cat fastqc_data.txt | awk '/^>>/{print $0}'|wc -l
24
十八题、下载 http://www.biotrainee.com/jmzeng/tmp/hg38.tss 文件,去NCBI找到TP53/BRCA1等自己感兴趣的基因对应的 refseq数据库 ID,然后找到它们的hg38.tss 文件的哪一行。
(base) vip39@VM-0-15-ubuntu:~/test$ cat hg38.tss | grep -n "NM_001126113"
29346:NM_001126113 chr17 7685550 7689550 1
十九题、解析hg38.tss 文件,统计每条染色体的基因个数。
(base) vip39@VM-0-15-ubuntu:~/test$ cat hg38.tss |cut -f2|sort|uniq -c|grep -v '_'
6050 chr1
2824 chr10
3449 chr11
2931 chr12
1122 chr13
1883 chr14
2168 chr15
2507 chr16
3309 chr17
873 chr18
3817 chr19
4042 chr2
1676 chr20
868 chr21
1274 chr22
3277 chr3
2250 chr4
2684 chr5
3029 chr6
2720 chr7
2069 chr8
2301 chr9
2 chrM
2553 chrX
414 chrY
二十题、解析hg38.tss 文件,统计NM和NR开头的熟练,了解NM和NR开头的含义。
(base) vip39@VM-0-15-ubuntu:~/test$ cat hg38.tss |awk '{print$1}'|cut -c1-2|sort|uniq -c
51064 NM
15954 NR
生信文件格式fastqc
资料推荐
- 生信菜鸟团的浅谈FastQ和FastA格式,以及测序数据质量控制之FastQC
- 生信技能书论坛的blat简介与格式解读
- 还有视频讲解:英语视频;中文视频
- 生信技能书系列视频:https://www.bilibili.com/video/av28813815/?p=12
fasta和fastq格式文件的shell小练习
1)统计reads_1.fq 文件中共有多少条序列信息
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ ls
longreads.fq reads_12.fq reads_1.fq reads_2.fq simulate.pl
# 第一种:
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fq
...
@r10000
GGTGATGCGCGGCTCCGTGCCGCCAAAGCCGTCCGGCACTGACTNGTCGCAG
+
E<**G2F;';H$%9>*0,;0%---<*9-4B7(5A!4C.C,<".5**$<6,:"
# 第二种:
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fq | wc
40000 40000 228569
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fq | paste - - - - | wc
10000 40000 2285692
# 我也试过这种:
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fq |grep '^@' | wc
10219 10219 93042
# 嗯,还不知道问题出在哪里
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fq |grep '^@'
···
@r9966
@(9=@B*;&G<4/F#51*>@B3&0H03@.90-"BHH.#7'*74/.?(&&145G'89#*?:?(!"+8@G02*6B<,#+CE9+?-&67*=1/&4A$:G<:;4965D;;)/B=*?B;'6F//1A#"%7+.1D@=/?93B:A3>.<D%69:/G'6),E4(F(41;'"3C)'?BEC;8$H7A?!5D%3D;-.B'%9>/88>9DEA"H8C6#4"5*63=
@r9967
···
# 嗯,然后及发现一些奇妙的东西
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fq | paste - - - - | less -SN
2)输出所有的reads_1.fq文件中的标识符(即以@开头的那一行)
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fq | paste - - - - | cut -f1
# 或者使用awk
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ awk '{if(NR%4==1)print}' reads_1.fq
3) 输出reads_1.fq文件中的 所有序列信息(即每个序列的第二行)
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fq | paste - - - - | cut -f2
4)输出以‘+’及其后面的描述信息(即每个序列的第三行)
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fq | paste - - - - | cut -f3
5)输出质量值信息(即每个序列的第四行)
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fq | paste - - - - | cut -f4
# -c 计算符合范本样式的列数。
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ awk '{if(NR%4==2)print}' reads_1.fq | grep -c N
6429
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ awk '{if(NR%4==2)print}' reads_1.fq | grep N |wc
6429 6429 782897
7) 统计文件中reads_1.fq文件里面的序列的碱基总数
# -o 只输出文件中匹配到的部分。
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ awk '{if(NR%4==2)print}' reads_1.fq | grep -o [ATCGN]|wc
1088399 1088399 2176798
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ awk '{if(NR%4==2)print length}' reads_1.fq | paste -s -d + |bc
8)计算reads_1.fq 所有的reads中N碱基的总数
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ awk '{if(NR%4==2)print}' reads_1.fq | grep -o N |wc
26001 26001 52002
9)统计reads_1.fq 中测序碱基质量值恰好为Q20的个数
-
目前Illumina机器得到的基本是illumina 1.8方案。
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ awk '{if(NR%4==0)print}' reads_1.fq | grep -o 5 |wc
21369 21369 42738
10)统计reads_1.fq 中测序碱基质量值恰好为Q30的个数
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ awk '{if(NR%4==0)print}' reads_1.fq | grep -o ? |wc
21574 21574 43148
11)统计reads_1.fq 中所有序列的第一位碱基的ATCGNatcg分布情况
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ awk '{if(NR%4==2)print}' reads_1.fq | cut -c1 |sort|uniq -c
2184 A
2203 C
2219 G
1141 N
2253 T
12)将reads_1.fq 转为reads_1.fa文件(即将fastq转化为fasta)
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fq | paste - - - - | cut -f1,2|tr '\t' '\n'|tr '@' '>' > reads_1.fa
13) 统计上述reads_1.fa文件中共有多少条序列
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ wc reads_1.fa
20000 20000 1167293 reads_1.fa
14)计算reads_1.fa文件中总的碱基序列的GC数量
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fa |grep -o G|wc
264740 264740 529480
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fa |grep -o C|wc
265243 265243 530486
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fa |grep -o [GC]|wc
529983 529983 1059966
15)删除 reads_1.fa文件中的每条序列的N碱基
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fa |tr -d "N"
16)删除 reads_1.fa文件中的含有N碱基的序列
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fa |paste - -|grep -v N | wc
3571 7142 340122
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fa |paste - -|grep -v N | tr '\t' '\n'
17) 删除 reads_1.fa文件中的短于65bp的序列
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat reads_1.fa |paste - -|awk '{if (length($2)>65) print}'|wc
7076 14152 992399
18) 删除 reads_1.fa文件每条序列的前后五个碱基
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ head reads_1.fa|paste - - | cut -f2|cut -c5-
# 上面是前5个
生信格式SAM、BAM
资料推荐
- 生信菜鸟团的浅谈SAM格式
- 生信媛的高通量数据分析必须知道的山姆大叔(SAM)
- 生信技能树系列视频数据格式,以及SAM、BAM练习题讲解
- 生信菜鸟团的sam和bam格式文件的shell小练习
sam和bam格式文件的shell小练习
1) 统计共多少条reads(pair-end reads这里算一条)参与了比对参考基因组
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@'|wc
20000 391929 7049181
# 左右两个序列算作一条,所以为10000
2) 统计共有多少种比对的类型(即第二列数值有多少种)及其分布。
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@' | cut -f2|sort|uniq -c|sort -k1,1nr
4650 163
4650 83
4516 147
4516 99
213 141
213 77
165 137
165 69
153 133
153 73
136 165
136 89
125 101
125 153
24 129
24 65
16 113
16 177
2 161
2 81
- picard sam flag:https://broadinstitute.github.io/picard/explain-flags.html
3)筛选出比对失败的reads,看看序列特征。
# 第6列的* 代表为比对失败
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@' |awk '{if($6=="*")print}'|wc
1005 12608 255140
4) 比对失败的reads区分成单端失败和双端失败情况,并且拿到序列ID
# 单端失败
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@' |awk '{if($6=="*")print $1}'|sort|uniq -c|grep -w 1
# 双端失败
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@' |awk '{if($6=="*")print $1}'|sort|uniq -c|grep -w 2
5) 筛选出比对质量值大于30的情况(看第5列)
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@' |awk '{if($5>30)print}'|wc
18632 372088 6662664
6) 筛选出比对成功,但是并不是完全匹配的序列
“M”表示 match或 mismatch;
“I”表示 insert
“D”表示 deletion
“N”表示 skipped(跳过这段区域)
“S”表示 soft clipping(被剪切的序列存在于序列中)
“H”表示 hard clipping(被剪切的序列不存在于序列中)
“P”表示 padding
“=”表示 match
“X”表示 mismatch(错配,位置是一一对应的)
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@' |awk '{if($6!="*")print$6}'|grep "[IDNSHPX]"|wc
1900 1900 18522
7) 筛选出inset size长度大于1250bp的 pair-end reads
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@' |awk '{if($7>1250)print}'|less -S
8) 统计参考基因组上面各条染色体的成功比对reads数量
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@' |cut -f3|sort -u
*
gi|9626243|ref|NC_001416.1|
9) 筛选出原始fq序列里面有N的比对情况
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@'|awk '{if($10~N)print}'|wc
20000 391929 7049181
10) 筛选出原始fq序列里面有N,但是比对的时候却是完全匹配的情况
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@'|awk '{if($10 ~ N)print}'|awk '{if($6 !~ "[IDNSHP]")print}'|awk '{if($6!="*")print}'|less -S
11) sam文件里面的头文件行数
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ grep '^@' tmp.sam|wc
3 19 262
12) sam文件里每一行的tags个数一样吗;13) sam文件里每一行的tags个数分别是多少个
14) sam文件里记录的参考基因组染色体长度分别是?
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ head tmp.sam | grep 'LN'
@SQ SN:gi|9626243|ref|NC_001416.1| LN:48502
15) 找到比对情况有insertion情况的
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@'|awk '{if($6~I)print}'|less -S
16) 找到比对情况有deletion情况的
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@'|awk '{if($6~D)print}'|less -S
17)取出位于参考基因组某区域的比对记录,比如 5013到50130 区域
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@'|awk '{if($4>5013 && $4 <50130)print}'|less -S
18) 把sam文件按照染色体以及起始坐标排序
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.sam | grep -v '^@'|awk '{print $4}'|sort -n
# 还有点问题
19) 找到 102M3D11M 的比对情况,计算其reads片段长度
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ grep 102M3D11M
tmp.sam |cut -f 10|wc
1 1 114
# 所以就114咯
20) 安装samtools软件后使用samtools软件的各个功能尝试把上述题目重新做一遍。
vip39@VM-0-15-ubuntu:~$ source miniconda3/bin/activate
(base) vip39@VM-0-15-ubuntu:~$ cd src/
(base) vip39@VM-0-15-ubuntu:~/src$ conda install samtools=1.7 y
生信格式VCF
资料推荐
- 生信菜鸟团的vcf格式,略略略~~;还有我的基因组28-必须要理解vcf格式记录的变异位点信息 ;以及转载-VCF格式详解.
- 生信技能树系列视频,详见B站;
- 生信星球的VCF格式
VCF格式文件的shell小练习
1.把突变记录的vcf文件区分成 INDEL和SNP条目
# SNP:
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.vcf | grep -v '^#'|less -S|awk '{if (length($4)==1 && length($5)==1) print}'
gi|9626243|ref|NC_001416.1| 1104 . C A 225 . DP=43;VDB=0.162843;SGB=-0.693079;MQSB=0.981133;MQ0F=0;AC=2;AN=2;DP4=0,0,8,21;MQ=41 GT:PL 1/1:255,84,0
gi|9626243|ref|NC_001416.1| 1344 . G T 225 . DP=37;VDB=0.273288;SGB=-0.690438;MQSB=1;MQ0F=0;AC=2;AN=2;DP4=0,0,9,8;MQ=42 GT:PL 1/1:255,51,0
gi|9626243|ref|NC_001416.1| 2143 . C G 225 . DP=46;VDB=0.902087;SGB=-0.692831;MQSB=1;MQ0F=0;AC=2;AN=2;DP4=0,0,10,14;MQ=42 GT:PL 1/1:255,72,0
gi|9626243|ref|NC_001416.1| 3316 . T C 225 . DP=59;VDB=0.712644;SGB=-0.69311;MQSB=0.899452;MQ0F=0;AC=2;AN=2;DP4=0,0,18,13;MQ=41 GT:PL 1/1:255,93,0
gi|9626243|ref|NC_001416.1| 3406 . G T 218 . DP=40;VDB=0.0470228;SGB=-0.69168;MQSB=0.920044;MQ0F=0;AC=2;AN=2;DP4=0,0,10,9;MQ=41 GT:PL 1/1:248,54,0
gi|9626243|ref|NC_001416.1| 5812 . A C 24.4299 . DP=13;VDB=0.0618664;SGB=-0.511536;MQSB=1;MQ0F=0;AC=2;AN=2;DP4=0,0,2,1;MQ=30 GT:PL 1/1:54,9,0
gi|9626243|ref|NC_001416.1| 7089 . A C 208 . DP=26;VDB=0.135432;SGB=-0.688148;MQSB=1;MQ0F=0;AC=2;AN=2;DP4=0,0,3,12;MQ=42 GT:PL 1/1:238,45,0
gi|9626243|ref|NC_001416.1| 9632 . T A 97 . DP=17;VDB=0.677364;SGB=-0.636426;MQSB=1.01283;MQ0F=0;AC=2;AN=2;DP4=0,0,3,4;MQ=42 GT:PL 1/1:154,44,29
gi|9626243|ref|NC_001416.1| 9642 . T A 132 . DP=20;VDB=0.959419;SGB=-0.670168;MQSB=1.00775;MQ0F=0;AC=2;AN=2;DP4=0,0,4,6;MQ=42 GT:PL 1/1:162,30,0
gi|9626243|ref|NC_001416.1| 12512 . G A 225 . DP=46;VDB=0.828249;SGB=-0.692562;MQSB=0.261423;MQ0F=0;AC=2;AN=2;DP4=0,0,14,8;MQ=41 GT:PL 1/1:255,66,0
gi|9626243|ref|NC_001416.1| 14897 . G C 225 . DP=38;VDB=0.449535;SGB=-0.689466;MQSB=0.976745;MQ0F=0;AC=2;AN=2;DP4=0,0,10,6;MQ=41 GT:PL 1/1:255,48,0
...
# indel:
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.vcf | grep -v '^#'|less -S|awk '{if (length($4)!=1 || length($5)!=1) print}'
gi|9626243|ref|NC_001416.1| 2 . GGCG GGCGCGGGGGCG 9.81282 . INDEL;IDV=1;IMF=0.5;DP=2;VDB=0.02;SGB=-0.379885;MQ0F=0;AC=2;AN=2;DP4=1,0,1,0;MQ=33 GT:PL 1/1:36,1,0
gi|9626243|ref|NC_001416.1| 245 . ATT AT 157 . INDEL;IDV=33;IMF=0.942857;DP=35;VDB=0.518706;SGB=-0.692562;MQSB=0.121547;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=6,7,13,9;MQ=36 GT:PL 0/1:192,0,23
gi|9626243|ref|NC_001416.1| 351 . ATGCTGAAATT A 108 . INDEL;IDV=1;IMF=0.0285714;DP=35;VDB=0.511365;SGB=-0.688148;MQSB=0.406871;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=8,12,8,7;MQ=28 GT:PL 0/1:141,0,110
gi|9626243|ref|NC_001416.1| 353 . GCTGAAATTGA G 215 . INDEL;IDV=24;IMF=0.685714;DP=35;VDB=0.58815;SGB=-0.692976;MQSB=0.711476;MQ0F=0;AC=2;AN=2;DP4=4,5,13,13;MQ=28 GT:PL 1/1:244,0,3
gi|9626243|ref|NC_001416.1| 2817 . GA G 175 . INDEL;IDV=41;IMF=0.911111;DP=45;VDB=0.367939;SGB=-0.693136;MQSB=0.45851;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=3,7,20,15;MQ=41 GT:PL 0/1:210,0,28
gi|9626243|ref|NC_001416.1| 2951 . ACCC A 159 . INDEL;IDV=1;IMF=0.0322581;DP=31;VDB=0.195299;SGB=-0.691153;MQSB=0.340099;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=5,8,9,9;MQ=38 GT:PL 0/1:193,0,16
gi|9626243|ref|NC_001416.1| 2952 . CCCACC CCC 228 . INDEL;IDV=28;IMF=0.903226;DP=31;VDB=0.210377;SGB=-0.692831;MQSB=0.340099;MQ0F=0;AC=2;AN=2;DP4=2,5,12,12;MQ=38 GT:PL 1/1:255,27,0
gi|9626243|ref|NC_001416.1| 3262 . GCC GC 152 . INDEL;IDV=1;IMF=0.0217391;DP=46;VDB=0.483903;SGB=-0.69311;MQSB=0.887966;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=7,8,13,18;MQ=41 GT:PL 0/1:187,0,17
gi|9626243|ref|NC_001416.1| 3264 . CA C 150 . INDEL;IDV=41;IMF=0.803922;DP=51;VDB=0.874867;SGB=-0.69312;MQSB=0.94394;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=10,9,14,18;MQ=41 GT:PL 0/1:184,0,26
gi|9626243|ref|NC_001416.1| 3634 . ACGC AC 228 . INDEL;IDV=25;IMF=0.892857;DP=28;VDB=0.621512;SGB=-0.692067;MQSB=1;MQ0F=0;AC=2;AN=2;DP4=3,5,15,5;MQ=41 GT:PL 1/1:255,19,0
gi|9626243|ref|NC_001416.1| 6290 . GT G 167 . INDEL;IDV=38;IMF=0.926829;DP=41;VDB=0.910269;SGB=-0.693097;MQSB=0.903761;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=7,4
...
2.统计INDEL和SNP条目的各自的平均测序深度
3.把INDEL条目再区分成insertion和deletion情况
# insertion
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.vcf | grep -v '^#'|less -S|awk '{if (length($4)<length($5)) print}'
gi|9626243|ref|NC_001416.1| 2 . GGCG GGCGCGGGGGCG 9.81282 . INDEL;IDV=1;IMF=0.5;DP=2;VDB=0.02;SGB=-0.379885;MQ0F=0;AC=2;AN=2;DP4=1,0,1,0;MQ=33 GT:PL1/1:36,1,0
# deletion
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.vcf | grep -v '^#'|less -S|awk '{if (length($4)>length($5)) print}'
gi|9626243|ref|NC_001416.1| 245 . ATT AT 157 . INDEL;IDV=33;IMF=0.942857;DP=35;VDB=0.518706;SGB=-0.692562;MQSB=0.121547;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=6,7,13,9;MQ=36 GT:PL 0/1:192,0,23
gi|9626243|ref|NC_001416.1| 351 . ATGCTGAAATT A 108 . INDEL;IDV=1;IMF=0.0285714;DP=35;VDB=0.511365;SGB=-0.688148;MQSB=0.406871;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=8,12,8,7;MQ=28 GT:PL 0/1:141,0,110
gi|9626243|ref|NC_001416.1| 353 . GCTGAAATTGA G 215 . INDEL;IDV=24;IMF=0.685714;DP=35;VDB=0.58815;SGB=-0.692976;MQSB=0.711476;MQ0F=0;AC=2;AN=2;DP4=4,5,13,13;MQ=28 GT:PL 1/1:244,0,3
gi|9626243|ref|NC_001416.1| 2817 . GA G 175 . INDEL;IDV=41;IMF=0.911111;DP=45;VDB=0.367939;SGB=-0.693136;MQSB=0.45851;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=3,7,20,15;MQ=41 GT:PL 0/1:210,0,28
gi|9626243|ref|NC_001416.1| 2951 . ACCC A 159 . INDEL;IDV=1;IMF=0.0322581;DP=31;VDB=0.195299;SGB=-0.691153;MQSB=0.340099;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=5,8,9,9;MQ=38 GT:PL 0/1:193,0,16
gi|9626243|ref|NC_001416.1| 2952 . CCCACC CCC 228 . INDEL;IDV=28;IMF=0.903226;DP=31;VDB=0.210377;SGB=-0.692831;MQSB=0.340099;MQ0F=0;AC=2;AN=2;DP4=2,5,12,12;MQ=38 GT:PL 1/1:255,27,0
gi|9626243|ref|NC_001416.1| 3262 . GCC GC 152 . INDEL;IDV=1;IMF=0.0217391;DP=46;VDB=0.483903;SGB=-0.69311;MQSB=0.887966;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=7,8,13,18;MQ=41 GT:PL 0/1:187,0,17
gi|9626243|ref|NC_001416.1| 3264 . CA C 150 . INDEL;IDV=41;IMF=0.803922;DP=51;VDB=0.874867;SGB=-0.69312;MQSB=0.94394;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2
...
4.统计SNP条目的突变组合分布频率
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.vcf |grep -v '^#'|awk '{if (length($4)==1 && length($5)==1) print}'|cut -f4,5|sort|uniq -c
7 A C
1 A G
4 A T
2 C A
4 C G
3 G A
2 G C
4 G T
6 T A
1 T C
2 T G
5.找到基因型不是 1/1 的条目,个数
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.vcf |grep -v '^#'|awk '{ print $10}'|grep -v '^1/1'
0/1:192,0,23
0/1:141,0,110
0/1:210,0,28
0/1:193,0,16
0/1:187,0,17
0/1:184,0,26
0/1:202,0,22
0/1:116,0,41
0/1:254,0,30
0/1:180,0,38
0/1:184,0,41
0/1:167,0,21
0/1:197,0,115
0/1:192,0,37
0/1:45,0,87
0/1:47,0,128
0/1:44,0,157
0/1:255,0,13
0/1:239,0,13
0/1:198,0,20
0/1:236,0,93
0/1:194,0,94
0/1:195,0,56
0/1:67,0,168
0/1:255,0,20
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.vcf |grep -v '^#'|awk '{ print $10}'|grep -v '^1/1'|wc
25 25 326
6.筛选测序深度大于20的条目
7.筛选变异位点质量值大于30的条目
vip39@VM-0-15-ubuntu:~/test/bowtie2-2.3.4.3-linux-x86_64/example/reads$ cat tmp.vcf |awk '{if ($6>30) print}'|grep -v '^#'|less -S|head
gi|9626243|ref|NC_001416.1| 245 . ATT AT 157 . INDEL;IDV=33;IMF=0.942857;DP=35;VDB=0.518706;SGB=-0.692562;MQSB=0.121547;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=6,7,13,9;MQ=36 GT:PL 0/1:192,0,23
gi|9626243|ref|NC_001416.1| 351 . ATGCTGAAATT A 108 . INDEL;IDV=1;IMF=0.0285714;DP=35;VDB=0.511365;SGB=-0.688148;MQSB=0.406871;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=8,12,8,7;MQ=28 GT:PL 0/1:141,0,110
gi|9626243|ref|NC_001416.1| 353 . GCTGAAATTGA G 215 . INDEL;IDV=24;IMF=0.685714;DP=35;VDB=0.58815;SGB=-0.692976;MQSB=0.711476;MQ0F=0;AC=2;AN=2;DP4=4,5,13,13;MQ=28 GT:PL 1/1:244,0,3
gi|9626243|ref|NC_001416.1| 1104 . C A 225 . DP=43;VDB=0.162843;SGB=-0.693079;MQSB=0.981133;MQ0F=0;AC=2;AN=2;DP4=0,0,8,21;MQ=41 GT:PL 1/1:255,84,0
gi|9626243|ref|NC_001416.1| 1344 . G T 225 . DP=37;VDB=0.273288;SGB=-0.690438;MQSB=1;MQ0F=0;AC=2;AN=2;DP4=0,0,9,8;MQ=42 GT:PL 1/1:255,51,0
gi|9626243|ref|NC_001416.1| 2143 . C G 225 . DP=46;VDB=0.902087;SGB=-0.692831;MQSB=1;MQ0F=0;AC=2;AN=2;DP4=0,0,10,14;MQ=42 GT:PL 1/1:255,72,0
gi|9626243|ref|NC_001416.1| 2817 . GA G 175 . INDEL;IDV=41;IMF=0.911111;DP=45;VDB=0.367939;SGB=-0.693136;MQSB=0.45851;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=3,7,20,15;MQ=41 GT:PL 0/1:210,0,28
gi|9626243|ref|NC_001416.1| 2951 . ACCC A 159 . INDEL;IDV=1;IMF=0.0322581;DP=31;VDB=0.195299;SGB=-0.691153;MQSB=0.340099;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=5,8,9,9;MQ=38 GT:PL 0/1:193,0,16
gi|9626243|ref|NC_001416.1| 2952 . CCCACC CCC 228 . INDEL;IDV=28;IMF=0.903226;DP=31;VDB=0.210377;SGB=-0.692831;MQSB=0.340099;MQ0F=0;AC=2;AN=2;DP4=2,5,12,12;MQ=38 GT:PL 1/1:255,27,0
gi|9626243|ref|NC_001416.1| 3262 . GCC GC 152 . INDEL;IDV=1;IMF=0.0217391;DP=46;VDB=0.483903;SGB=-0.69311;MQSB=0.887966;MQ0F=0;ICB=1;HOB=0.5;AC=1;AN=2;DP4=7,8,13,18;MQ=41 GT:PL 0/1:187,0,17
8.组合筛选变异位点质量值大于30并且深度大于20的条目
9. 理解DP4=4,7,11,18 这样的字段,就是 Number of high-quality ref-forward , ref-reverse, alt-forward and alt-reverse bases 计算每个变异位点的 AF
10.在前面步骤的bam文件里面找到这个vcf文件的某一个突变位点的测序深度表明的那些reads,并且在IGV里面可视化bam和vcf定位到该变异位点。
生信技能树公益视频合辑:学习顺序是linux,r,软件安装,geo,小技巧,ngs组学!
请猛戳下面链接:
B站链接:https://m.bilibili.com/space/338686099
YouTube链接:https://m.youtube.com/channel/UC67sImqK7V8tSWHMG8azIVA/playlists
生信工程师入门最佳指南:https://mp.weixin.qq.com/s/vaX4ttaLIa19MefD86WfUA