Skip to content

Instantly share code, notes, and snippets.

@telatin
Created March 5, 2018 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telatin/e82050c1d1831281beb40ef70886c222 to your computer and use it in GitHub Desktop.
Save telatin/e82050c1d1831281beb40ef70886c222 to your computer and use it in GitHub Desktop.
#!/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}... "
samtools view -bS ${SamFile} | samtools sort -o ${SamFile/.sam/.bam} -
samtools index ${SamFile/.sam/.bam}.bam
echo "Done!"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment