Commit 0b736751 authored by Gaik Tamazian's avatar Gaik Tamazian
Browse files

Show warning if a FASTA index file is outdated

If modification time of a FASTA index file is less than modification
time of its FASTA file, then the warning message is shown; resolves
parent cc963efb
......@@ -244,7 +244,14 @@ void FastaReference::open(string reffilename, bool usemmap, bool useFullHeader)
struct stat stFileInfo;
string indexFileName = filename + index->indexFileExtension();
// if we can find an index file, use it
if(stat(indexFileName.c_str(), &stFileInfo) == 0) {
if(stat(indexFileName.c_str(), &stFileInfo) == 0) {
// check if the index file is older than the FASTA file
struct stat index_attrib, fasta_attrib;
stat(indexFileName.c_str(), &index_attrib);
stat(reffilename.c_str(), &fasta_attrib);
if (fasta_attrib.st_mtime > index_attrib.st_mtime) {
cerr << "Warning: the index file is older than the FASTA file." << endl;
} else { // otherwise, read the reference and generate the index file in the cwd
cerr << "index file " << indexFileName << " not found, generating..." << endl;
......@@ -102,3 +102,21 @@ $BT getfasta -fi test.iupac.fa -bed test.iupac.bed -s -fo - > obs
check obs exp
rm obs exp test.iupac.fa.fai
# test the warning about an outdated FASTA index file
echo " getfasta.t10...\c"
echo \
# create an index file
echo -e "chr2\t2\t10" | $BT getfasta -fi test.fa -bed - -fo - > /dev/null
# modify the FASTA file in a second
sleep 1
touch test.fa
echo -e "chr2\t2\t10" | $BT getfasta -fi test.fa -bed - -fo - \
> /dev/null 2> obs
echo "Warning: the index file is older than the FASTA file." > exp
check obs exp
rm obs exp test.fa test.fa.fai
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment