Changes between Version 44 and Version 45 of SOPs/miningSAMBAM


Ignore:
Timestamp:
09/21/20 16:03:12 (4 years ago)
Author:
gbell
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SOPs/miningSAMBAM

    v44 v45  
    66
    77All fields in a SAM/BAM file are explained in the [http://samtools.github.io/hts-specs/SAMv1.pdf Sequence Alignment/Map Format Specification].
    8 
    9 === Convert, sort, and/or index ===
    10 
    11 {{{
    12 # Convert SAM to BAM:
    13 samtools view -bS -o foo.bam foo.sam
    14 }}}
    15 
    16 {{{
    17 # Convert BAM to SAM:
    18 samtools view -h -o foo.sam foo.bam
    19 }}}
    20 {{{
    21 # Sort BAM file (where ".bam" is added to "foo.sorted")
    22 samtools sort foo.bam -T foo > foo.sorted.bam
    23 }}}
    24 {{{
    25 # Index a sorted BAM file (which creates foo.sorted.bam.bai):
    26 samtools index foo.sorted.bam
    27    
    28 # Both foo.sorted.bam and foo.sorted.bam.bai are needed for visualization.
    29  }}}
    30 
    31 All three steps (SAM=>BAM, sorting, and indexing) can be merged into one command.  See
    32 {{{
    33 /nfs/BaRC_Public/BaRC_code/Perl/SAM_to_BAM_sort_index/SAM_to_BAM_sort_index.pl
    34 # Or on a folder of SAM files
    35 for samFile in `/bin/ls *.sam`; do bsub /nfs/BaRC_Public/BaRC_code/Perl/SAM_to_BAM_sort_index/SAM_to_BAM_sort_index.pl $samFile ; done
    36 }}}
    37 
    388
    399
     
    4818  * For archiving purposes, keep only the BAM file.  The SAM file can easily be regenerated (if ever needed).
    4919
     20=== Convert, sort, and/or index ===
     21
     22{{{
     23# Convert SAM to BAM:
     24samtools view -bS -o foo.bam foo.sam
     25}}}
     26
     27{{{
     28# Convert BAM to SAM:
     29samtools view -h -o foo.sam foo.bam
     30}}}
     31{{{
     32# Sort BAM file (where ".bam" is added to "foo.sorted")
     33samtools sort foo.bam -T foo > foo.sorted.bam
     34}}}
     35{{{
     36# Index a sorted BAM file (which creates foo.sorted.bam.bai):
     37samtools index foo.sorted.bam
     38   
     39# Both foo.sorted.bam and foo.sorted.bam.bai are needed for visualization.
     40 }}}
     41
     42All three steps (SAM=>BAM, sorting, and indexing) can be merged into one command.  See
     43{{{
     44/nfs/BaRC_Public/BaRC_code/Perl/SAM_to_BAM_sort_index/SAM_to_BAM_sort_index.pl
     45# Or on a folder of SAM files
     46for samFile in `/bin/ls *.sam`; do bsub /nfs/BaRC_Public/BaRC_code/Perl/SAM_to_BAM_sort_index/SAM_to_BAM_sort_index.pl $samFile ; done
     47}}}
     48
    5049=== Modify a BAM file into another BAM file ===
    5150
     
    6059
    6160{{{
    62 #extract mulitple regions (eg. chromosomes) into a new bam file
     61#extract multiple regions (e.g., chromosomes) into a new bam file
    6362samtools view -bh -L chromInfo.bed alignment.bam > alignment_chr1_3.bam
    64 #where chromInfo.bed is a bed file, eg.
     63#where chromInfo.bed is a bed file, e.g.,
    6564chr1    1       195471971
    6665chr2    1       182113224
     
    6968
    7069{{{
    71 #rename header, eg. use only chr1 to chr3 like above
     70#rename header, e.g., use only chr1 to chr3 like above
    7271samtools reheader newHeader.txt alignment_chr1_3.bam> alignment_chr1_3.newHeader.bam
    7372#where newheader.txt file is,