Skip to content

Commit

Permalink
Show warning if a FASTA index file is outdated
Browse files Browse the repository at this point in the history
If modification time of a FASTA index file is less than modification
time of its FASTA file, then the warning message is shown; resolves
#228.
  • Loading branch information
gtamazian committed May 25, 2015
1 parent cc963ef commit 0b73675
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/utils/Fasta/Fasta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
index->readIndexFile(indexFileName);
} else { // otherwise, read the reference and generate the index file in the cwd
cerr << "index file " << indexFileName << " not found, generating..." << endl;
Expand Down
18 changes: 18 additions & 0 deletions test/getfasta/test-getfasta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
">chr1
cggggggggg
>chr2
AAATTTTTTTTTT" > test.fa
# 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

0 comments on commit 0b73675

Please sign in to comment.