Changes between Version 37 and Version 38 of SOPs/miningSAMBAM
- Timestamp:
- 08/29/17 09:36:34 (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
SOPs/miningSAMBAM
v37 v38 36 36 }}} 37 37 38 39 38 40 === Differences between SAM and BAM files === 39 41 … … 48 50 === Modify a BAM file into another BAM file === 49 51 50 In many cases, there's no need to create an intermediate SAM file. For example, to extract selected (mapped to chrM) reads:52 In many cases, there's no need to create an intermediate SAM file. 51 53 {{{ 52 samtools index accepted_hits.bam # Required if you want to select a genome region (like chrM) 54 #to extract selected (mapped to chrM) reads: 55 samtools index accepted_hits.bam # index file required if you want to select a genome region (like chrM) 53 56 samtools view -h accepted_hits.bam chrM | samtools view -bS - > accepted_hits.chrM_only.bam 57 #We need to keep the header to convert back to BAM (hence the '-h' with 'samtools view'). 58 54 59 }}} 55 We need to keep the header to convert back to BAM (hence the '-h' with 'samtools view' and the '$1 ~ ...' with awk). 60 61 {{{ 62 #extract mulitple regions (eg. chromosomes) into a new bam file 63 samtools view -bh -L chromInfo.bed alignment.bam > alignment_chr1_3.bam 64 #where chromInfo.bed is a bed file, eg. 65 chr1 1 195471971 66 chr2 1 182113224 67 chr3 1 160039680 68 }}} 69 70 {{{ 71 #rename header, eg. use only chr1 to chr3 like above 72 samtools reheader newHeader.txt alignment_chr1_3.bam> alignment_chr1_3.newHeader.bam 73 #where newheader.txt file is, 74 @HD VN:1.3 SO:coordinate 75 @SQ SN:chr1 LN:195471971 76 @SQ SN:chr2 LN:182113224 77 @SQ SN:chr3 LN:160039680 78 @PG ID:bwa PN:bwa VN:0.7.12-r1039 CL:bwa ... 79 80 }}} 81 56 82 57 83 === Count the number of mapped reads ===