Skip to content

Instantly share code, notes, and snippets.

@danielecook
Created August 11, 2020 19:35
Show Gist options
  • Save danielecook/2582c5285f06cb33827e8b6bdbc05897 to your computer and use it in GitHub Desktop.
Save danielecook/2582c5285f06cb33827e8b6bdbc05897 to your computer and use it in GitHub Desktop.
Fix missing BAM indices
# This quick script will check for big differences in a bams index and creation date and perform indexing.
for i in *.bam; do
bam=${i}
bai=${i}.bai
bam_date=$(stat -c %Y ${bam})
bai_date=$(stat -c %Y ${bai})
diff=`expr ${bam_date} - ${bai_date}`
if [ ${diff} -gt 100000 ]; then
echo "${bam} ${diff}";
sbatch --job-name=${bam} --partition=cpu --time=3:00:00 --cpus-per-task=32 --wrap "samtools index -@ 32 ${bam}"
fi;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment