SAMTOOLS HowTo

From TaejoonLab
Jump to: navigation, search

SAM to BAM

#!/bin/bash
NUM_THREADS=4

for SAM in $(ls *.sam)
do
  BAM=${SAM/.sam/}".bam"
  SORTED_BAM=${SAM/.sam/}".sorted.bam"
  samtools view -@ $NUM_THREADS -b -h $SAM > $BAM
  samtools sort $BAM > $SORTED_BAM
  samtools index $SORTED_BAM
  rm $SAM $BAM
done

BAM to BedGraph & BigWig

#!/bin/bash
## Installation
# conda install bedtools ucsc-faSize ucsc-bedGraphToBigWig

GENOME_FA="my_genome.fa"
GENOME_SEQLEN="my_genome.seqlen"
faSize -detailed $GENOME_FA > $GENOME_SEQLEN

for BAM in $(ls *bam)
do
  echo $BAM
  BG=${BAM/.bam/}".bedgraph"
  BIGWIG=${BAM/.bam/}".bigWig"

  bedtools genomecov -ibam $BAM -bg > $BG
  bedGraphToBigWig $BG $GENOME_SEQLEN -blockSize=10 $BIGWIG
done

[[Category:HowTo]