Created
March 5, 2018 15:45
-
-
Save telatin/1bde71a8b5aa7562abc6e09b93785d2b to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# A first example of 'for loop' to iterate a set of commands over a list of files | |
SamFilesCount=$(ls *.sam | wc -l); | |
echo "In this directory you have ${SamFilesCount}" | |
# Loop throught all .sam files (note: won't work if no .sam files are present!) | |
for SamFile in *.sam | |
do | |
echo -n "Converting ${SamFile}... " | |
if [[ -s "${SamFile}" ]] | |
then | |
samtools view -bS ${SamFile} | samtools sort -o ${SamFile/.sam/.bam} - | |
samtools index ${SamFile/.sam/.bam}.bam | |
echo "Done!" | |
else | |
echo "Skipping $SamFile: it's empty!" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment