User:Timothee Flutre/Notebook/Postdoc/2013/12/01: Difference between revisions
From OpenWetWare
(→One-liners for high-throughput sequencing data: minor change) |
(→One-liners for high-throughput sequencing data: add R1/2 entries and reads) |
||
Line 41: | Line 41: | ||
57898 + 0 with mate mapped to a different chr | 57898 + 0 with mate mapped to a different chr | ||
44330 + 0 with mate mapped to a different chr (mapQ>=5) | 44330 + 0 with mate mapped to a different chr (mapQ>=5) | ||
* '''list of different flags in the bam file''': along with their number of occurrences | |||
samtools view $OUT | cut -f2 | sort | uniq -c | sort -k1,1nr -k2,2n | |||
# | awk '{sum+=$1}END{print sum}' # <- same as line 1 | |||
[http://www.htslib.org/doc/sam.html list] of bits used to form the flags | |||
[http://broadinstitute.github.io/picard/explain-flags.html this] website is useful to interpret flags | |||
for instance, if there are N entries with flag 99, there should also be N entries with flag 147; idem for 83 and 163; idem for 77 and 141; etc | |||
* '''total number of entries in the bam file''': same as line 1 | * '''total number of entries in the bam file''': same as line 1 | ||
Line 54: | Line 65: | ||
samtools view -f 0x4 $OUT | wc -l | samtools view -f 0x4 $OUT | wc -l | ||
* ''' | * '''not-primary/supplementary entries''': see [http://seqanswers.com/forums/showthread.php?t=40239 details] | ||
samtools view -f 0x0100 $OUT | wc -l | samtools view -f 0x0100 $OUT | wc -l | ||
samtools view -f 0x0800 $OUT | wc -l | |||
* ''' | * '''R1 and R2 entries''': | ||
samtools view $OUT | nbE1=$(samtools view -f 0x0040 -c $OUT) | ||
nbE2=$(samtools view -f 0x0080 -c $OUT) | |||
echo "$nbE1 + $nbE2" | bc -l # same as line 1 | |||
* '''R1 and R2 reads''': | |||
samtools view -f 0x0040 $OUT | cut -f1 | sort | uniq -c > tmp1 | |||
samtools view -f 0x0080 $OUT | cut -f1 | sort | uniq -c > tmp2 | |||
wc -l < tmp1 # same as line 7 | |||
wc -l < tmp2 # same as line 8 | |||
cat tmp1 | awk '{print $1}' | sort | uniq -c | |||
cat tmp2 | awk '{print $1}' | sort | uniq -c | |||
<!-- ##### DO NOT edit below this line unless you know what you are doing. ##### --> | <!-- ##### DO NOT edit below this line unless you know what you are doing. ##### --> |
Revision as of 08:26, 1 July 2015
Project name | <html><img src="/images/9/94/Report.png" border="0" /></html> Main project page Next entry<html><img src="/images/5/5c/Resultset_next.png" border="0" /></html> |
One-liners for high-throughput sequencing data
IN1="reads_R1.fastq.gz" IN2="reads_R2.fastq.gz" OUT="alignments.bam"
nbLines=$(zcat $IN1 | wc -l); echo "scale=0; "${nbLines}"/4" | bc -l
samtools view $OUT | cut -f1 | sort | uniq | wc -l
samtools flagstat $OUT which returns something like: 4635834 + 0 in total (QC-passed reads + QC-failed reads) 20290 + 0 secondary 0 + 0 supplimentary 0 + 0 duplicates 4443270 + 0 mapped (95.85%:-nan%) 4615544 + 0 paired in sequencing 2307772 + 0 read1 2307772 + 0 read2 4299122 + 0 properly paired (93.14%:-nan%) 4412810 + 0 with itself and mate mapped 10170 + 0 singletons (0.22%:-nan%) 57898 + 0 with mate mapped to a different chr 44330 + 0 with mate mapped to a different chr (mapQ>=5)
samtools view $OUT | cut -f2 | sort | uniq -c | sort -k1,1nr -k2,2n # | awk '{sum+=$1}END{print sum}' # <- same as line 1 list of bits used to form the flags this website is useful to interpret flags for instance, if there are N entries with flag 99, there should also be N entries with flag 147; idem for 83 and 163; idem for 77 and 141; etc
samtools view $OUT | wc -l
samtools view -F 0x4 $OUT | wc -l
samtools view -f 0x4 $OUT | wc -l
samtools view -f 0x0100 $OUT | wc -l samtools view -f 0x0800 $OUT | wc -l
nbE1=$(samtools view -f 0x0040 -c $OUT) nbE2=$(samtools view -f 0x0080 -c $OUT) echo "$nbE1 + $nbE2" | bc -l # same as line 1
samtools view -f 0x0040 $OUT | cut -f1 | sort | uniq -c > tmp1 samtools view -f 0x0080 $OUT | cut -f1 | sort | uniq -c > tmp2 wc -l < tmp1 # same as line 7 wc -l < tmp2 # same as line 8 cat tmp1 | awk '{print $1}' | sort | uniq -c cat tmp2 | awk '{print $1}' | sort | uniq -c |