// Add() is typically used when creating a GLIX from GFF records. // It can be called multiple times with the same label, the // maximum position determines the sequence length. void GLIX::Add(const char *Label, int Pos) { SEQDATA *IE = SeqIndexLookup(Label); if (0 == IE) AddToIndex(Label, Pos + 1); else { if (Pos + 1 > IE->Length) IE->Length = Pos + 1; } }
const TFile& TFileCollection::Merge(const TFile& file) { // if (!file.FindInGeneratedPool()) // return; TRef myfile = FindByAlias(file); if (!myfile) { myfile = new TFile(file); Files.push_back(myfile); } else myfile->MergeAliases(file); AddToIndex(*myfile); return *myfile; }
OGRErr OGRMILayerAttrIndex::IndexAllFeatures( int iField ) { poLayer->ResetReading(); OGRFeature *poFeature = nullptr; while( (poFeature = poLayer->GetNextFeature()) != nullptr ) { const OGRErr eErr = AddToIndex( poFeature, iField ); delete poFeature; if( eErr != OGRERR_NONE ) return eErr; } poLayer->ResetReading(); return OGRERR_NONE; }
OGRErr OGRMILayerAttrIndex::IndexAllFeatures( int /* iField */ ) { OGRFeature *poFeature; poLayer->ResetReading(); while( (poFeature = poLayer->GetNextFeature()) != NULL ) { OGRErr eErr = AddToIndex( poFeature ); delete poFeature; if( eErr != CE_None ) return eErr; } poLayer->ResetReading(); return OGRERR_NONE; }
void FilterB(int Tlen_, char *B_, int Qlen_, const FilterParams &FP, int Diameter, bool Comp) { if (Comp) Quit("-diameter requires -fwdonly (this needs to be fixed!)"); SeqQ = B_; Tlen = Tlen_; Qlen = Qlen_; MinMatch = FP.SeedLength; MaxError = FP.SeedDiffs; TubeOffset = FP.TubeOffset; const int Kmask = pow4(k) - 1; // Ukonnen's Lemma MinKmersPerHit = MinMatch + 1 - k*(MaxError + 1); // Maximum distance between SeqQ positions of two k-mers in a match // (More stringent bounds may be possible, but not a big problem // if two adjacent matches get merged). MaxKmerDist = MinMatch - k; TubeWidth = TubeOffset + MaxError; if (TubeOffset < MaxError) { Log("TubeOffset < MaxError\n"); exit(1); } if (MinKmersPerHit <= 0) { Log("MinKmersPerHit <= 0\n"); exit(1); } MaxActiveTubes = (Tlen + TubeWidth - 1)/TubeOffset + 1; Tubes = all(TubeState, MaxActiveTubes); zero(Tubes, TubeState, MaxActiveTubes); // Ticker tracks cycling of circular list of active tubes. int Ticker = TubeWidth; // Initialize index to cover first window int StartKmerValidPos = 0; int EndKmerValidPos = 0; AllocateIndex(Diameter, k); const int KmerCount = Diameter - k + 1; int Start; int End; for (Start = 0; Start < KmerCount; ++Start) { int StartKmer = GetKmer(SeqQ, Start); AddToIndex(StartKmer, Start); } #if DEBUG ValidateIndex(SeqQ, 0, Diameter - k); #endif // Scan entire sequence. // Start is coordinate of first base in first k-mer in sliding window // End is coordinate of first base in last k-mer in sliding window Start = 0; End = Start + Diameter - k; int StartKmer = GetKmer(SeqQ, Start); if (StartKmer == -1) { StartKmer = 0; StartKmerValidPos = Start + k + 1; } int EndKmer = GetKmer(SeqQ, End); if (EndKmer == -1) { EndKmer = 0; EndKmerValidPos = End + k + 1; } for (; End < Qlen - k; ++Start, ++End) { #if DEBUG if (Start%10000 == 0) fprintf(stderr, "%d\n", Start); //if (Start%1000 == 0) // ValidateIndex(SeqQ, Start, End); #endif if (Start >= StartKmerValidPos) { assert(StartKmer == GetKmer(SeqQ, Start)); for (DeclareListPtr(p) = GetListPtr(StartKmer); NotEndOfList(p); p = GetListNext(p)) { int HitPos = GetListPos(p); CommonKmer(Start, HitPos); } DeleteFirstInstanceFromIndex(StartKmer, Start); } if (0 == --Ticker) { TubeEnd(Start); Ticker = TubeOffset; } { char c = SeqQ[Start + k]; int x = CharToLetter[c]; if (x < 0) { StartKmer = 0; StartKmerValidPos = Start + k + 1; } else StartKmer = ((StartKmer << 2) | x) & Kmask; } { char c = SeqQ[End + k]; int x = CharToLetter[c]; if (x < 0) { EndKmer = 0; EndKmerValidPos = End + k + 1; } else EndKmer = ((EndKmer << 2) | x) & Kmask; if (End+1 >= EndKmerValidPos) { assert(EndKmer == GetKmer(SeqQ, End+1)); AddToIndex(EndKmer, End+1); } } } #if DEBUG ValidateIndex(SeqQ, Start, Qlen - k); #endif // Special case for end of sequence, don't slide the index // for the last Diameter bases. for (; Start < Qlen - k; ++Start) { { char c = SeqQ[Start + k]; int x = CharToLetter[c]; if (x < 0) { StartKmer = 0; StartKmerValidPos = Start + k + 1; } else StartKmer = ((StartKmer << 2) | x) & Kmask; } if (Start >= StartKmerValidPos) { for (DeclareListPtr(p) = GetListPtr(StartKmer); NotEndOfList(p); p = GetListNext(p)) { int HitPos = GetListPos(p); CommonKmer(Start, HitPos); } } if (0 == --Ticker) { TubeEnd(Start); Ticker = TubeOffset; } } TubeEnd(Qlen - 1); int DiagFrom = CalcDiagIndex(Tlen - 1, Qlen - 1) - TubeWidth; int DiagTo = CalcDiagIndex(0, Qlen - 1) + TubeWidth; int TubeFrom = CalcTubeIndex(DiagFrom); if (TubeFrom < 0) TubeFrom = 0; int TubeTo = CalcTubeIndex(DiagTo); for (int TubeIndex = TubeFrom; TubeIndex <= TubeTo; ++TubeIndex) TubeFlush(TubeIndex); freemem(Tubes); }