Skip to content

Instantly share code, notes, and snippets.

@Phoenix-Effect
Created July 15, 2018 10:08
Show Gist options
  • Save Phoenix-Effect/eedb3ff1a73c6d5ca5adbb7eb7835766 to your computer and use it in GitHub Desktop.
Save Phoenix-Effect/eedb3ff1a73c6d5ca5adbb7eb7835766 to your computer and use it in GitHub Desktop.
Checks if the bam index files in a directory are newer than their corresponding bam files.
#!/bin/bash
# Directory of the directory you want to scan
DIR="ENTER DIRECTORY HERE"
TOTALBAMS=0
OLDINDEX=0
UNINDEXED=0
for file in $DIR*.bam; do # Iterate over all bam files in given directory
((TOTALBAMS++)) #Count the bam
if [ -f "$file.bai" ]; then # If index exists then check if its newer than bam
if [ "$file" -nt "$file.bai" ]; then
((OLDINDEX++)) # If bam is newer then increment old index counter
fi
else
((UNINDEXED++)) # If index doesn't exist then increment unindexed
fi
done
printf "Total bams in directory: $TOTALBAMS\n"
printf "Old bams: $OLDINDEX\n"
printf "Unindexed bams: $UNINDEXED\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment