Changes between Version 37 and Version 38 of SOPs/miningSAMBAM


Ignore:
Timestamp:
08/29/17 09:36:34 (7 years ago)
Author:
thiruvil
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SOPs/miningSAMBAM

    v37 v38  
    3636}}}
    3737
     38
     39
    3840=== Differences between SAM and BAM files ===
    3941
     
    4850=== Modify a BAM file into another BAM file ===
    4951
    50 In many cases, there's no need to create an intermediate SAM file.  For example, to extract selected (mapped to chrM) reads:
     52In many cases, there's no need to create an intermediate SAM file.
    5153{{{
    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:
     55samtools index accepted_hits.bam   # index file required if you want to select a genome region (like chrM)
    5356samtools 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
    5459}}}
    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
     63samtools view -bh -L chromInfo.bed alignment.bam > alignment_chr1_3.bam
     64#where chromInfo.bed is a bed file, eg.
     65chr1    1       195471971
     66chr2    1       182113224
     67chr3    1       160039680
     68}}}
     69
     70{{{
     71#rename header, eg. use only chr1 to chr3 like above
     72samtools 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
    5682
    5783=== Count the number of mapped reads ===