| 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 | | |
| | 20 | === Convert, sort, and/or index === |
| | 21 | |
| | 22 | {{{ |
| | 23 | # Convert SAM to BAM: |
| | 24 | samtools view -bS -o foo.bam foo.sam |
| | 25 | }}} |
| | 26 | |
| | 27 | {{{ |
| | 28 | # Convert BAM to SAM: |
| | 29 | samtools view -h -o foo.sam foo.bam |
| | 30 | }}} |
| | 31 | {{{ |
| | 32 | # Sort BAM file (where ".bam" is added to "foo.sorted") |
| | 33 | samtools sort foo.bam -T foo > foo.sorted.bam |
| | 34 | }}} |
| | 35 | {{{ |
| | 36 | # Index a sorted BAM file (which creates foo.sorted.bam.bai): |
| | 37 | samtools index foo.sorted.bam |
| | 38 | |
| | 39 | # Both foo.sorted.bam and foo.sorted.bam.bai are needed for visualization. |
| | 40 | }}} |
| | 41 | |
| | 42 | All 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 |
| | 46 | 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 |
| | 47 | }}} |
| | 48 | |