Skip to content

Commit

Permalink
reinstate warning for index file older than FASTA
Browse files Browse the repository at this point in the history
  • Loading branch information
brentp committed Nov 28, 2022
1 parent acfc394 commit cddbadf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/utils/Fasta/Fasta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,21 @@ FastaIndex::FastaIndex(bool useFullHeader)
void FastaIndex::readIndexFile(string fname) {

faidx = fai_load(fname.c_str());
const char *idx_path = (fname + ".fai").c_str();

// NOTE: can use faidx_set_cache_size to improve performance of repeated queries.
if(faidx == NULL) {
cerr << "Warning: malformed fasta index file " << fname << endl;
exit(1);
}

struct stat index_attr, fasta_attr;
stat(idx_path, &index_attr);
stat(fname.c_str(), &fasta_attr);
if(fasta_attr.st_mtime > index_attr.st_mtime) {
cerr << "Warning: the index file is older than the FASTA file." << endl;
}

int n_seq = faidx_nseq(faidx);
for(int i = 0; i < n_seq; i++){
const char* chrom_name = faidx_iseq(faidx, i);
Expand Down
3 changes: 0 additions & 3 deletions src/utils/Fasta/Fasta.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class FastaIndex : public map<string, FastaIndexEntry> {
vector<string> sequenceNames;
void indexReference(string refName);
void readIndexFile(string fname);
//void writeIndexFile(string fname);
FastaIndexEntry entry(string key);
bool chromFound(string name);
void flushEntryToIndex(FastaIndexEntry& entry);
Expand All @@ -64,8 +63,6 @@ class FastaReference {
bool usingfullheader;
FastaReference(void) : usingmmap(false), usingfullheader(false) { }
~FastaReference(void);
//FILE* file;
//void* filemm;
size_t filesize;
FastaIndex* index;
vector<FastaIndexEntry> findSequencesStartingWith(string seqnameStart);
Expand Down
4 changes: 2 additions & 2 deletions test/getfasta/test-getfasta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ check obs exp
rm obs exp test.iupac.fa.fai

# test the warning about an outdated FASTA index file
echo -e " getfasta.t10..disabled..\c"
echo -e " getfasta.t10...\c"
echo \
">chr1
cggggggggg
Expand All @@ -127,7 +127,7 @@ touch test.fa
echo -e "chr2\t2\t10" | $BT getfasta -fi test.fa -bed - \
> /dev/null 2> obs
echo "Warning: the index file is older than the FASTA file." > exp
#check obs exp
check obs exp
rm obs exp test.fa test.fa.fai


Expand Down

0 comments on commit cddbadf

Please sign in to comment.