Created
August 21, 2019 20:36
-
-
Save chamalis/54e5a78c03114611648ec59a5f19fd80 to your computer and use it in GitHub Desktop.
Bash script to convert all SAM files found in a directory to BAM. Directory is passed as positional command line argument.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
for i in $(ls $1); do | |
filename_prefix="${i%.*}" | |
filename_extension="${i##*.}" | |
if [ "$filename_extension" == "sam" ]; then | |
samtools view -bs $i > $filename_prefix.bam | |
samtools sort $filename_prefix.bam -o $2 | |
samtools index $2 $2.index | |
rm $filename_prefix.bam | |
fi; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment