include/alignments.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void alignments_initialize ()
void alignments_createNew (uint4 descriptionLocation, uint4 descriptionLength, unsigned char *subject, int4 subjectLength, int4 encodedLength)
void alignments_addUngappedExtension (struct ungappedExtension *newExtension)
void alignments_performScoring (struct PSSMatrix PSSMatrix)
void alignments_getFinalAlignmentDescriptions ()
void alignments_loadSubjectsIntoMemory (struct PSSMatrix PSSMatrix)
void alignment_unpackSubject (struct alignment *alignment)
void alignments_findGoodAlignments (struct PSSMatrix PSSMatrix)
void alignments_findFinalAlignments (struct PSSMatrix PSSMatrix)
void alignments_getTracebacks (struct PSSMatrix PSSMatrix)
int alignments_isFinalAlignment (uint4 score)
void alignments_addGappedExtension (struct alignment *alignment, struct gappedExtension *newExtension)
void alignments_addFinalAlignment (int4 highestNominalScore, struct alignment *alignment)
void alignments_sortFinalAlignments ()
void alignments_free ()

Variables

memBlocksalignments_alignments
memSingleBlockalignments_goodAlignments
memSingleBlockalignments_finalAlignments
alignmentalignments_currentAlignment
uint4 alignments_numClusters


Function Documentation

void alignment_unpackSubject ( struct alignment alignment  ) 

void alignments_addFinalAlignment ( int4  highestNominalScore,
struct alignment alignment 
)

Definition at line 433 of file alignments.c.

References finalAlignment::alignment, alignments_finalAlignments, finalAlignment::description, finalAlignment::highestNominalScore, and memSingleBlock_newEntry().

Referenced by alignments_findFinalAlignments(), alignments_findTopFinalAlignments(), search_nucleotideSsearch(), and search_proteinSsearch().

00434 {
00435         struct finalAlignment* finalAlignment;
00436 
00437     // Get a new final alignment entry
00438     finalAlignment = memSingleBlock_newEntry(alignments_finalAlignments);
00439 
00440         // Insert alignment information into the new final alignment
00441         finalAlignment->highestNominalScore = highestNominalScore;
00442         finalAlignment->alignment = alignment;
00443         finalAlignment->description = NULL;
00444 }

Here is the call graph for this function:

Here is the caller graph for this function:

void alignments_addGappedExtension ( struct alignment alignment,
struct gappedExtension newExtension 
)

Definition at line 164 of file alignments.c.

References alignment::gappedExtensions, gappedExtension::next, and gappedExtension::nominalScore.

Referenced by alignments_getTracebacks(), search_nucleotideSsearch(), and search_proteinSsearch().

00165 {
00166         struct gappedExtension *currentExtension, *previousExtension;
00167 
00168         // If this is the first high-scoring gapped extension for this alignment
00169         if (alignment->gappedExtensions == NULL)
00170         {
00171                 // Make this the first gapped extension in the alignment
00172                 alignment->gappedExtensions = newExtension;
00173         }
00174         else
00175         {
00176                 // Start at beginning of list of gapped extensions (one with highest score)
00177                 currentExtension = alignment->gappedExtensions;
00178                 previousExtension = NULL;
00179 
00180                 // Move through list of existing extensions until we either reach the
00181                 // end or reach one with a score less than newExtension
00182                 while (currentExtension != NULL &&
00183                       (currentExtension->nominalScore > newExtension->nominalScore))
00184                 {
00185                         previousExtension = currentExtension;
00186                         currentExtension = currentExtension->next;
00187                 }
00188 
00189                 if (previousExtension == NULL)
00190                 {
00191                         // This is the highest scoring extension, insert at front of the queue
00192                         alignment->gappedExtensions = newExtension;
00193                         newExtension->next = currentExtension;
00194                 }
00195                 else
00196                 {
00197                         // Insert between higher and lower scoring extensions
00198                         previousExtension->next = newExtension;
00199                         newExtension->next = currentExtension;
00200                 }
00201         }
00202 }

Here is the caller graph for this function:

void alignments_addUngappedExtension ( struct ungappedExtension newExtension  ) 

Definition at line 122 of file alignments.c.

References alignments_currentAlignment, ungappedExtension::next, ungappedExtension::nominalScore, and alignment::ungappedExtensions.

Referenced by search_nucleotide(), search_nucleotide_largeTable(), search_nucleotide_longWord(), search_protein1hit(), and search_protein2hit().

00123 {
00124         struct ungappedExtension *currentExtension, *previousExtension;
00125 
00126         // Start at beginning of ungapped extensions (one with highest score)
00127         currentExtension = alignments_currentAlignment->ungappedExtensions;
00128 
00129         // If there are none, add first/sole extension
00130         if (currentExtension == NULL)
00131         {
00132                 alignments_currentAlignment->ungappedExtensions = newExtension;
00133         }
00134         else
00135         {
00136                 previousExtension = NULL;
00137 
00138                 // Else move through list of existing extensions until we either reach the
00139                 // end or reach one with a score less than newExtension
00140                 while (currentExtension != NULL &&
00141                       (currentExtension->nominalScore > newExtension->nominalScore))
00142                 {
00143                         previousExtension = currentExtension;
00144                         currentExtension = currentExtension->next;
00145                 }
00146 
00147                 if (previousExtension == NULL)
00148                 {
00149                         // This is the highest scoring alignment, insert at front of
00150                         // the queue
00151                         alignments_currentAlignment->ungappedExtensions = newExtension;
00152                         newExtension->next = currentExtension;
00153                 }
00154                 else
00155                 {
00156                         // Insert between higher and lower scoring extensions
00157                         previousExtension->next = newExtension;
00158                         newExtension->next = currentExtension;
00159                 }
00160         }
00161 }

Here is the caller graph for this function:

void alignments_createNew ( uint4  descriptionLocation,
uint4  descriptionLength,
unsigned char *  subject,
int4  subjectLength,
int4  encodedLength 
)

Definition at line 41 of file alignments.c.

References alignments_alignments, alignments_currentAlignment, blast_numTriggerSequences, alignment::cluster, alignment::descriptionLength, alignment::descriptionLocation, alignment::edits, alignment::encodedLength, encoding_alphabetType, encoding_nucleotide, alignment::gappedExtensions, alignment::inMemorySubject, alignment::joinChecked, memBlocks_newEntry(), alignment::numUnpackRegions, alignment::subject, alignment::subjectLength, alignment::ungappedExtensions, and alignment::unpackRegions.

Referenced by search_nucleotide(), search_nucleotide_largeTable(), search_nucleotide_longWord(), search_nucleotideSsearch(), search_protein1hit(), search_protein2hit(), and search_proteinSsearch().

00044 {
00045         struct alignment* alignment;
00046 
00047         // Get slot for new alignment
00048         alignment = (struct alignment*)memBlocks_newEntry(alignments_alignments);
00049 
00050         // Create/initialize contents
00051         alignment->ungappedExtensions = NULL;
00052         alignment->gappedExtensions = NULL;
00053         alignment->descriptionLocation = descriptionLocation;
00054     alignment->descriptionLength = descriptionLength;
00055         alignment->subject = subject;
00056         alignment->subjectLength = subjectLength;
00057         alignment->joinChecked = 0;
00058     alignment->encodedLength = encodedLength;
00059     alignment->inMemorySubject = 0;
00060     alignment->unpackRegions = NULL;
00061         alignment->numUnpackRegions = 0;
00062     alignment->edits = NULL;
00063     alignment->cluster = 0;
00064 
00065     // Record pointer to wilcard edits if there are any for this subject
00066     if (encoding_alphabetType == encoding_nucleotide)
00067     {
00068         alignment->edits = subject + ((alignment->subjectLength + 3) / 4);
00069         if (alignment->edits == subject + encodedLength)
00070         {
00071             alignment->edits = NULL;
00072                 }
00073     }
00074 
00075         alignments_currentAlignment = alignment;
00076     blast_numTriggerSequences++;
00077 }

Here is the call graph for this function:

Here is the caller graph for this function:

void alignments_findFinalAlignments ( struct PSSMatrix  PSSMatrix  ) 

Definition at line 1147 of file alignments.c.

References finalAlignment::alignment, alignments_addFinalAlignment(), alignments_findTopFinalAlignments(), alignments_goodAlignments, alignments_regularGappedAlignment(), alignments_sortGoodAlignments(), blast_gappedNominalCutoff, blast_nominalR1cutoff, blast_nominalR2cutoff, alignment::descriptionLocation, finalAlignment::highestNominalScore, int4, memSingleBlock_getCurrent(), memSingleBlock_getEntry(), memSingleBlock_resetCurrent(), ungappedExtension::next, ungappedExtension::nominalScore, memSingleBlock::numEntries, parameters_numDisplayAlignments, parameters_verboseDloc, ungappedExtension::status, ungappedExtension_DELETED, ungappedExtension_print(), and alignment::ungappedExtensions.

Referenced by blast_search().

01148 {
01149     struct finalAlignment* goodAlignment;
01150     struct alignment* alignment;
01151         struct ungappedExtension* ungappedExtension;
01152     int4 bestScore;
01153 
01154     // Sort good alignments by score
01155     // TODO: How long does this take?
01156     alignments_sortGoodAlignments();
01157 
01158     // If we have more good alignments than we can display
01159     if (parameters_numDisplayAlignments > 0 &&
01160             alignments_goodAlignments->numEntries > parameters_numDisplayAlignments)
01161         {
01162         goodAlignment = memSingleBlock_getEntry(alignments_goodAlignments,
01163                                                 parameters_numDisplayAlignments - 1);
01164 
01165                 // If it is clear we will have more final alignments than we can display
01166                 if (goodAlignment->highestNominalScore > blast_nominalR2cutoff)
01167         {
01168                 // Find the top N alignments
01169                         alignments_findTopFinalAlignments(PSSMatrix);
01170             return;
01171         }
01172     }
01173 
01174     // Further score all good alignments to see if they score above cutoff
01175     memSingleBlock_resetCurrent(alignments_goodAlignments);
01176     while ((goodAlignment = memSingleBlock_getCurrent(alignments_goodAlignments)) != NULL)
01177     {
01178                 alignment = goodAlignment->alignment;
01179 
01180         bestScore = 0;
01181         // For each ungapped extension that hasn't been deleted
01182         ungappedExtension = alignment->ungappedExtensions;
01183         while (ungappedExtension != NULL)
01184         {
01185             #ifdef VERBOSE
01186             if (parameters_verboseDloc == alignment->descriptionLocation)
01187                                 ungappedExtension_print(ungappedExtension);
01188             #endif
01189 
01190             if (ungappedExtension->status != ungappedExtension_DELETED)
01191             {
01192                 // If it isn't clear if the extension is above cutoff
01193                 if (ungappedExtension->nominalScore >= blast_nominalR1cutoff &&
01194                     ungappedExtension->nominalScore <= blast_nominalR2cutoff)
01195                 {
01196                     // Perform regular gapped scoring
01197                     alignments_regularGappedAlignment(PSSMatrix, ungappedExtension, alignment);
01198                 }
01199 
01200                 // Update the alignment's best score
01201                 if (ungappedExtension->nominalScore > bestScore)
01202                     bestScore = ungappedExtension->nominalScore;
01203             }
01204             ungappedExtension = ungappedExtension->next;
01205         }
01206 
01207         goodAlignment->highestNominalScore = bestScore;
01208 
01209         // If the alignment scores above cutoff, include in list of final alignments
01210         if (goodAlignment->highestNominalScore >= blast_gappedNominalCutoff)
01211         {
01212             alignments_addFinalAlignment(goodAlignment->highestNominalScore, alignment);
01213         }
01214     }
01215 }

Here is the call graph for this function:

Here is the caller graph for this function:

void alignments_findGoodAlignments ( struct PSSMatrix  PSSMatrix  ) 

Definition at line 748 of file alignments.c.

References alignments_addGoodAlignment(), alignments_alignments, alignments_expandCluster(), alignments_numVolumes, alignments_pruneRegion(), alignments_volumeAlignments, blast_dloc, blast_nominalR1cutoff, blast_numGoodAlignments, blast_numGoodExtensions, bytepackGappedScoring_score(), constants_initialAllocAlignments, encoding_alphabetType, encoding_protein, gappedScoring_score(), int4, memBlocks_getCurrent(), memBlocks_initialize(), memBlocks_resetCurrent(), ungappedExtension::next, parameters_bytepackedScoring, parameters_semiGappedScoring, parameters_tableScoring, semiGappedScoring_score(), statistics_gappedNominalDropoff, ungappedExtension::status, tableGappedScoring_score(), ungappedExtension_DELETED, ungappedExtension_findSeed(), ungappedExtension_GAPPED, and ungappedExtension_SEMIGAPPED.

Referenced by blast_search().

00749 {
00750         struct alignment* alignment;
00751         struct ungappedExtension* ungappedExtension;
00752         int4 bestScore, numExtensions, hasChildren;
00753 
00754     // For each alignment
00755     memBlocks_resetCurrent(alignments_alignments);
00756         while ((alignment = (struct alignment*)memBlocks_getCurrent(alignments_alignments)) != NULL)
00757         {
00758         bestScore = 0;
00759                 blast_dloc = alignment->descriptionLocation;
00760 
00761         // Record if subject has children
00762         if (encoding_alphabetType == encoding_protein &&
00763             alignment->encodedLength > alignment->subjectLength + 2)
00764                 hasChildren = 1;
00765                 else
00766                 hasChildren = 0;
00767 
00768         // For each ungapped extension (in descending order of score)
00769         numExtensions = 0;
00770         ungappedExtension = alignment->ungappedExtensions;
00771         while (ungappedExtension != NULL)
00772         {
00773                 if (ungappedExtension->status != ungappedExtension_DELETED)
00774             {
00775                 // Find the seed
00776                 ungappedExtension_findSeed(ungappedExtension, PSSMatrix, alignment->subject);
00777 
00778                 // Byte-packed scoring
00779                 if (parameters_bytepackedScoring)
00780                 {
00781                     ungappedExtension->nominalScore
00782                         = bytepackGappedScoring_score(ungappedExtension, PSSMatrix, alignment->subjectLength,
00783                            alignment->subject, statistics_gappedNominalDropoff);
00784 
00785                     // Mark as semigapped
00786                     ungappedExtension->status = ungappedExtension_SEMIGAPPED;
00787                 }
00788                 // Table driven scoring
00789                 else if (parameters_tableScoring)
00790                 {
00791                     ungappedExtension->nominalScore
00792                         = tableGappedScoring_score(ungappedExtension, PSSMatrix, alignment->subjectLength,
00793                            alignment->subject, statistics_gappedNominalDropoff);
00794 
00795                     // Mark as semigapped
00796                     ungappedExtension->status = ungappedExtension_SEMIGAPPED;
00797                 }
00798                 // Semi-gapped scoring
00799                 else if (parameters_semiGappedScoring)
00800                 {
00801                     ungappedExtension->nominalScore
00802                         = semiGappedScoring_score(ungappedExtension, PSSMatrix, alignment->subjectLength,
00803                                                   alignment->subject, statistics_gappedNominalDropoff);
00804 
00805                     // Mark as semigapped
00806                     ungappedExtension->status = ungappedExtension_SEMIGAPPED;
00807                 }
00808                 // Regular gapped scoring
00809                 else
00810                 {
00811                     ungappedExtension->nominalScore
00812                         = gappedScoring_score(ungappedExtension, PSSMatrix, alignment->subjectLength,
00813                                               alignment->subject, statistics_gappedNominalDropoff);
00814 
00815                     // Mark as gapped
00816                     ungappedExtension->status = ungappedExtension_GAPPED;
00817                 }
00818 
00819                 // If alignment scores above R1 cutoff
00820                 if (ungappedExtension->nominalScore >= blast_nominalR1cutoff)
00821                 {
00822                     if (hasChildren)
00823                     {
00824                         // Subject has children so perform stage1 and 2 on children
00825                         alignments_expandCluster(alignment, PSSMatrix);
00826                                                 bestScore = 0;
00827                         break;
00828                                         }
00829                     else if (ungappedExtension->nominalScore > bestScore)
00830                     {
00831                         // Update best score for the alignment
00832                         bestScore = ungappedExtension->nominalScore;
00833                     }
00834                 }
00835                 else
00836                 {
00837                     // Else mark it as deleted
00838                     ungappedExtension->status = ungappedExtension_DELETED;
00839                 }
00840 
00841                 // Remove any ungapped extensions in this alignment that are in the area covered
00842                 // by the gapped scoring just performed
00843                 alignments_pruneRegion(alignment, ungappedExtension);
00844 
00845                 numExtensions++;
00846                         }
00847 
00848             ungappedExtension = ungappedExtension->next;
00849                 }
00850 
00851         // If this alignment contains gapped extensions that could score above cutoff
00852         if (bestScore >= blast_nominalR1cutoff)
00853         {
00854             // If a single sequence add to list of "good" alignments
00855             alignments_addGoodAlignment(bestScore, alignment);
00856 
00857             blast_numGoodExtensions += numExtensions;
00858             blast_numGoodAlignments++;
00859         }
00860     }
00861 
00862         // Record point to list of alignments for this volume
00863         alignments_volumeAlignments[alignments_numVolumes] = alignments_alignments;
00864         alignments_numVolumes++;
00865 
00866         // Construct new list for next volume (if there is one)
00867     alignments_alignments = memBlocks_initialize(sizeof(struct alignment),
00868                             constants_initialAllocAlignments);
00869 }

Here is the call graph for this function:

Here is the caller graph for this function:

void alignments_free (  ) 

Definition at line 696 of file alignments.c.

References finalAlignment::alignment, alignment_freeAlignment(), alignments_alignments, alignments_finalAlignments, alignments_goodAlignments, alignments_numVolumes, alignments_volumeAlignments, finalAlignment::description, memBlocks_free(), memBlocks_getCurrent(), memBlocks_resetCurrent(), memSingleBlock_free(), memSingleBlock_getCurrent(), memSingleBlock_resetCurrent(), uint4, ungappedExtension_extensions, and unpack_free().

Referenced by blast_search().

00697 {
00698         struct alignment* alignment;
00699         struct finalAlignment* finalAlignment;
00700         uint4 volumeCount;
00701 
00702     memBlocks_resetCurrent(alignments_alignments);
00703 
00704     // Free unused block of alignments
00705         memBlocks_free(alignments_alignments);
00706 
00707     // For each volume
00708         volumeCount = 0;
00709         while (volumeCount < alignments_numVolumes)
00710         {
00711                 alignments_alignments = alignments_volumeAlignments[volumeCount];
00712 
00713                 // For each alignment
00714         memBlocks_resetCurrent(alignments_alignments);
00715                 while ((alignment = (struct alignment*)memBlocks_getCurrent(alignments_alignments)) != NULL)
00716                 {
00717                         alignment_freeAlignment(alignment);
00718                 }
00719 
00720                 // Free blocks of alignments
00721                 memBlocks_free(alignments_alignments);
00722 
00723                 volumeCount++;
00724         }
00725 
00726     // Free memory used by ungapped extensions
00727         memBlocks_free(ungappedExtension_extensions);
00728 
00729     // Free good alignments
00730         memSingleBlock_free(alignments_goodAlignments);
00731 
00732     // For each final alignment, free the description
00733     memSingleBlock_resetCurrent(alignments_finalAlignments);
00734     while ((finalAlignment = memSingleBlock_getCurrent(alignments_finalAlignments)) != NULL)
00735     {
00736                 free(finalAlignment->description);
00737     }
00738 
00739     // Free final alignments
00740         memSingleBlock_free(alignments_finalAlignments);
00741 
00742         // Free all the unpacked regions
00743         unpack_free();
00744 }

Here is the call graph for this function:

Here is the caller graph for this function:

void alignments_getFinalAlignmentDescriptions (  ) 

Definition at line 612 of file alignments.c.

References alignments_compareAlignmentDescriptionLocations(), alignments_compareFinalAlignments(), alignments_finalAlignments, memSingleBlock::block, descriptions_getDescription(), memSingleBlock_getCurrent(), memSingleBlock_resetCurrent(), and memSingleBlock::numEntries.

Referenced by blast_search().

00613 {
00614         struct finalAlignment* finalAlignment;
00615 
00616     // Sort descriptions in order of description location (to speed up disk access)
00617         qsort(alignments_finalAlignments->block, alignments_finalAlignments->numEntries,
00618           sizeof(struct finalAlignment), alignments_compareAlignmentDescriptionLocations);
00619 
00620     // For each alignment, read the description
00621     memSingleBlock_resetCurrent(alignments_finalAlignments);
00622     while ((finalAlignment = memSingleBlock_getCurrent(alignments_finalAlignments)) != NULL)
00623     {
00624                 finalAlignment->description
00625                 = descriptions_getDescription(finalAlignment->alignment->descriptionLocation,
00626                                           finalAlignment->alignment->descriptionLength);
00627     }
00628 
00629     // Re-sort the final alignments by score
00630         qsort(alignments_finalAlignments->block, alignments_finalAlignments->numEntries,
00631           sizeof(struct finalAlignment), alignments_compareFinalAlignments);
00632 }

Here is the call graph for this function:

Here is the caller graph for this function:

void alignments_getTracebacks ( struct PSSMatrix  PSSMatrix  ) 

Definition at line 1283 of file alignments.c.

References finalAlignment::alignment, alignments_addGappedExtension(), alignments_finalAlignments, alignments_pruneOverlappingExtensions(), alignments_pruneRegion(), alignments_selectRegion(), alignments_sortFinalAlignments(), alignments_unpruneRegion(), blast_dloc, blast_gappedExtendTime, blast_gappedNominalCutoff, blast_unpackTime, constants_maximumTracebackSize, alignment::descriptionLocation, fasterGappedExtension_build(), gappedExtension_build(), gappedExtension_score(), alignment::gappedExtensions, gappedScoring_score(), finalAlignment::highestNominalScore, int4, PSSMatrix::length, memSingleBlock_getCurrent(), memSingleBlock_getEntry(), memSingleBlock_getLastEntry(), memSingleBlock_resetCurrent(), ungappedExtension::next, gappedExtension::nominalScore, ungappedExtension::nominalScore, memSingleBlock::numEntries, alignment::numUnpackRegions, parameters_numDisplayAlignments, parameters_numDisplayTracebacks, parameters_tableScoring, ungappedExtension::seed, statistics_gappedFinalNominalDropoff, ungappedExtension::status, alignment::subject, unpackRegion::subject, alignment::subjectLength, coordinate::subjectOffset, gappedExtension::trace, trace::traceCodes, uint8, ungappedExtension_DELETED, alignment::ungappedExtensions, unpack_entireSubjectUnpacked(), unpack_selectRegion(), unpack_unpackSubject(), unpackRegion::unpackedSubject, and alignment::unpackRegions.

Referenced by blast_search().

01284 {
01285     struct finalAlignment* finalAlignment;
01286         struct gappedExtension* gappedExtension;
01287         struct ungappedExtension* ungappedExtension, *highestScoringExtension, oldUngappedExtension;
01288     struct alignment* alignment;
01289     struct unpackRegion* unpackRegion;
01290     int4 numProcessed = 0, numAboveCutoff = 0, repeatComputeTracebacks = 1;
01291         int4 alignmentCount;
01292         unsigned char* subject;
01293 
01294     // Sort final alignments by score
01295     alignments_sortFinalAlignments();
01296 
01297 //    alignments_printFinalAlignments();
01298 
01299     // Only keep alignments above cutoff
01300     while (alignments_finalAlignments->numEntries > 0)
01301     {
01302         // Get last alignment in list
01303                 finalAlignment = memSingleBlock_getLastEntry(alignments_finalAlignments);
01304 
01305         // Stop if above cutoff
01306         if (finalAlignment->highestNominalScore != 0)
01307                 break;
01308 
01309         // Otherwise remove it from the list
01310         alignments_finalAlignments->numEntries--;
01311     }
01312 
01313     // For each alignment that is in the top numDisplayAlignments but not the top numDisplayTracebacks
01314     alignmentCount = parameters_numDisplayTracebacks;
01315     while (alignmentCount < parameters_numDisplayAlignments &&
01316            alignmentCount < alignments_finalAlignments->numEntries)
01317         {
01318         finalAlignment = memSingleBlock_getEntry(alignments_finalAlignments, alignmentCount);
01319         alignment = finalAlignment->alignment;
01320         blast_dloc = alignment->descriptionLocation;
01321 
01322         // Get the highest scoring ungapped extension
01323         ungappedExtension = alignment->ungappedExtensions;
01324         highestScoringExtension = ungappedExtension;
01325         while (ungappedExtension != NULL)
01326         {
01327                 if (ungappedExtension->nominalScore > highestScoringExtension->nominalScore &&
01328                 ungappedExtension->status != ungappedExtension_DELETED)
01329             {
01330                                 highestScoringExtension = ungappedExtension;
01331             }
01332                 ungappedExtension = ungappedExtension->next;
01333                 }
01334 
01335         if (highestScoringExtension != NULL)
01336         {
01337                 subject = alignments_selectRegion(alignment, highestScoringExtension);
01338 
01339             // Perform gapped scoring with higher dropoff
01340             highestScoringExtension->nominalScore
01341                 = gappedScoring_score(highestScoringExtension, PSSMatrix, alignment->subjectLength,
01342                                       subject, statistics_gappedFinalNominalDropoff);
01343 
01344                         finalAlignment->highestNominalScore = highestScoringExtension->nominalScore;
01345         }
01346 
01347 //        printf("Rescore with larger dropoff num %d: Score=%d\n", alignmentCount, highestScoringExtension->nominalScore);
01348         alignmentCount++;
01349     }
01350 
01351         while (repeatComputeTracebacks)
01352     {
01353         numAboveCutoff = 0; numProcessed = 0;
01354         memSingleBlock_resetCurrent(alignments_finalAlignments);
01355         while (((finalAlignment = memSingleBlock_getCurrent(alignments_finalAlignments)) != NULL)
01356         && (numAboveCutoff < parameters_numDisplayTracebacks || parameters_numDisplayTracebacks == 0))
01357         {
01358             alignment = finalAlignment->alignment;
01359             blast_dloc = alignment->descriptionLocation;
01360 
01361             // If traceback haven't been computed for this alignment
01362             if (alignment->gappedExtensions == NULL)
01363             {
01364                 // Unpack part or all of the subject (for nucleotide)
01365                 blast_gappedExtendTime += clock();
01366                 blast_unpackTime -= clock();
01367                 unpack_unpackSubject(PSSMatrix, alignment);
01368                 blast_unpackTime += clock();
01369                 blast_gappedExtendTime -= clock();
01370 
01371                 // For each ungapped extension that hasn't been deleted
01372                 ungappedExtension = alignment->ungappedExtensions;
01373                 while (ungappedExtension != NULL)
01374                 {
01375                     // If extension scores above cutoff
01376                     if (ungappedExtension->status != ungappedExtension_DELETED)
01377                     {
01378                         // Make copy of ungapped extension
01379                         oldUngappedExtension = *ungappedExtension;
01380 
01381                         // If subject and query are short enough and sequence does not have multiple
01382                         // unpack regions, use faster but less memory efficient gapped alignment with traceback
01383                         if (((uint8)PSSMatrix.length * (uint8)alignment->subjectLength <
01384                             (uint8)constants_maximumTracebackSize) && unpack_entireSubjectUnpacked(alignment))
01385                         {
01386                             gappedExtension
01387                                 = fasterGappedExtension_build(ungappedExtension, PSSMatrix,
01388                                   alignment->subjectLength, alignment->unpackRegions[0].unpackedSubject,
01389                                   statistics_gappedFinalNominalDropoff);
01390                         }
01391                         // Otherwise use slower but more memory-efficient gapped alignment
01392                         else
01393                         {
01394                             unpackRegion = unpack_selectRegion(alignment->unpackRegions,
01395                                            alignment->numUnpackRegions, ungappedExtension->seed.subjectOffset);
01396 
01397                             gappedExtension
01398                                 = gappedExtension_build(ungappedExtension, PSSMatrix, alignment->subjectLength,
01399                                       alignment->subject, unpackRegion, statistics_gappedFinalNominalDropoff);
01400                         }
01401 
01402                         // Calculate normalized score and e-value
01403                         gappedExtension_score(gappedExtension);
01404 
01405                         // Add it to the current alignment
01406                         if (gappedExtension->nominalScore >= blast_gappedNominalCutoff)
01407                             alignments_addGappedExtension(alignment, gappedExtension);
01408                         else
01409                         {
01410                             free(gappedExtension->trace.traceCodes);
01411                             free(gappedExtension);
01412                         }
01413 
01414                         // Check for ungapped extensions that were mistakenly pruned
01415                         if (parameters_tableScoring)
01416                                 alignments_unpruneRegion(alignment, &oldUngappedExtension,
01417                                                      ungappedExtension, PSSMatrix);
01418 
01419                         // Remove any ungapped extensions in this alignment that are in the area covered
01420                         // by the gapped scoring just performed
01421                         alignments_pruneRegion(alignment, ungappedExtension);
01422                    }
01423                    ungappedExtension = ungappedExtension->next;
01424                 }
01425 
01426                 // Finally prune extensions that share a start or end point
01427                 alignments_pruneOverlappingExtensions(alignment);
01428 
01429 //                printf("Was %d Now %d\n", finalAlignment->highestNominalScore, alignment->gappedExtensions->nominalScore);
01430 
01431                 // Update final alignment's high-score to that of the first (and highest-scoring)
01432                 // gapped extension in the list
01433                 if (alignment->gappedExtensions != NULL)
01434                     finalAlignment->highestNominalScore = alignment->gappedExtensions->nominalScore;
01435                 else
01436                     finalAlignment->highestNominalScore = 0;
01437 
01438                 numProcessed++;
01439 //                  printf("Computed alignment score=%d\n", finalAlignment->highestNominalScore);
01440                         }
01441 
01442             // Tally number of final alignments above cutoff
01443             if (finalAlignment->highestNominalScore > 0)
01444                 numAboveCutoff++;
01445         }
01446 
01447 //      printf("Traceback alignments performed=%d\n", numProcessed);
01448 
01449         // Sort final alignments by score
01450         alignments_sortFinalAlignments();
01451 
01452 //        printf("repeatComputeTracebacks:");
01453 
01454         // If the first numDisplayTracebacks alignments have traceback computed, stop
01455         numProcessed = 0; repeatComputeTracebacks = 0;
01456         memSingleBlock_resetCurrent(alignments_finalAlignments);
01457         while ((finalAlignment = memSingleBlock_getCurrent(alignments_finalAlignments)) != NULL
01458                && numProcessed < parameters_numDisplayTracebacks)
01459         {
01460             alignment = finalAlignment->alignment;
01461             if (alignment->gappedExtensions == NULL && finalAlignment->highestNominalScore != 0)
01462             {
01463 //              printf("1");
01464                 repeatComputeTracebacks = 1;
01465                                 break;
01466             }
01467 //            printf("0");
01468 
01469             numProcessed++;
01470                 }
01471 
01472         }
01473 
01474     // Only keep top N alignments
01475     if (parameters_numDisplayAlignments != 0 &&
01476         alignments_finalAlignments->numEntries > parameters_numDisplayAlignments)
01477         {
01478                 alignments_finalAlignments->numEntries = parameters_numDisplayAlignments;
01479     }
01480 
01481     // Only keep alignments above cutoff
01482     while (alignments_finalAlignments->numEntries > 0)
01483     {
01484         // Get last alignment in list
01485                 finalAlignment = memSingleBlock_getLastEntry(alignments_finalAlignments);
01486 
01487         // Stop if above cutoff
01488         if (finalAlignment->highestNominalScore != 0)
01489                 break;
01490 
01491         // Otherwise remove it from the list
01492         alignments_finalAlignments->numEntries--;
01493     }
01494 }

Here is the call graph for this function:

Here is the caller graph for this function:

void alignments_initialize (  ) 

Definition at line 22 of file alignments.c.

References alignments_alignments, alignments_currentAlignment, alignments_finalAlignments, alignments_finalAlignmentsSorted, alignments_goodAlignments, alignments_numVolumes, blast_numGoodExtensions, constants_initialAllocAlignments, constants_initialAllocFinalAlignments, constants_initialAllocGoodAlignments, memBlocks_initialize(), memSingleBlock_initialize(), and unpack_initialize().

Referenced by blast_search().

00023 {
00024         // Initialize alignments, good alignments and final alignments blocks
00025     alignments_alignments = memBlocks_initialize(sizeof(struct alignment),
00026                             constants_initialAllocAlignments);
00027         alignments_goodAlignments = memSingleBlock_initialize(sizeof(struct finalAlignment),
00028                                 constants_initialAllocGoodAlignments);
00029         alignments_finalAlignments = memSingleBlock_initialize(sizeof(struct finalAlignment),
00030                                  constants_initialAllocFinalAlignments);
00031 
00032     // Initialize code for processing regions of a subject
00033     unpack_initialize(blast_numGoodExtensions);
00034 
00035     alignments_currentAlignment = NULL;
00036         alignments_numVolumes = 0;
00037     alignments_finalAlignmentsSorted = 0;
00038 }

Here is the call graph for this function:

Here is the caller graph for this function:

int alignments_isFinalAlignment ( uint4  score  ) 

Definition at line 1498 of file alignments.c.

References finalAlignment::alignment, alignment_freeAlignment(), alignments_finalAlignments, alignments_finalAlignmentsSorted, alignments_sortFinalAlignments(), finalAlignment::highestNominalScore, memSingleBlock_getEntry(), memSingleBlock::numEntries, and parameters_numDisplayAlignments.

Referenced by search_nucleotideSsearch(), and search_proteinSsearch().

01499 {
01500         struct finalAlignment* finalAlignment;
01501     struct alignment* alignment;
01502 
01503 //    printf("%d,%d\n", parameters_numDisplayAlignments, alignments_finalAlignments->numEntries);
01504 
01505         if (parameters_numDisplayAlignments == 0 ||
01506         alignments_finalAlignments->numEntries < parameters_numDisplayAlignments)
01507         return 1;
01508 
01509         if (!alignments_finalAlignmentsSorted)
01510     {
01511         // Sort final alignments by score
01512         alignments_sortFinalAlignments();
01513         alignments_finalAlignmentsSorted = 1;
01514     }
01515 
01516     // Get the N-1th final alignment
01517     finalAlignment = memSingleBlock_getEntry(alignments_finalAlignments,
01518                                              parameters_numDisplayAlignments - 1);
01519 
01520         // If new alignment scores high enough to be in the top N
01521         if (score > finalAlignment->highestNominalScore)
01522     {
01523                 // Final alignments will need to be resorted
01524                 alignments_finalAlignmentsSorted = 0;
01525 
01526         // Free the lowest scoring final alignment
01527                 alignment = finalAlignment->alignment;
01528                 alignment_freeAlignment(alignment);
01529         alignments_finalAlignments->numEntries--;
01530 
01531         return 1;
01532     }
01533     else
01534     {
01535         return 0;
01536     }
01537 }

Here is the call graph for this function:

Here is the caller graph for this function:

void alignments_loadSubjectsIntoMemory ( struct PSSMatrix  PSSMatrix  ) 

Definition at line 873 of file alignments.c.

References finalAlignment::alignment, alignments_finalAlignments, alignments_goodAlignments, alignments_sortGoodAlignments(), alignment::encodedLength, finalAlignment::highestNominalScore, alignment::inMemorySubject, int4, memSingleBlock_getEntry(), memSingleBlock::numEntries, parameters_numDisplayAlignments, parameters_semiGappedR1, parameters_semiGappedR2, and unpack_loadSubject().

Referenced by blast_search().

00874 {
00875         struct finalAlignment *goodAlignment, *finalAlignment;
00876         struct alignment* alignment;
00877     int4 minimumDynamicCutoff, position, totalLengths = 0, totalCopied = 0;
00878 
00879     // First dismiss good alignments that can't make it into the top N
00880         if (parameters_numDisplayAlignments > 0 &&
00881             alignments_goodAlignments->numEntries > parameters_numDisplayAlignments)
00882     {
00883         // Sort good alignments by score
00884         alignments_sortGoodAlignments();
00885 
00886         // Get the Nth alignment
00887         goodAlignment = memSingleBlock_getEntry(alignments_goodAlignments, parameters_numDisplayAlignments);
00888 
00889         // Calculate the minimum possible dynamic cutoff
00890         minimumDynamicCutoff = goodAlignment->highestNominalScore / parameters_semiGappedR2
00891                              * parameters_semiGappedR1;
00892 
00893                 // Move through good alignments
00894         position = parameters_numDisplayAlignments;
00895         while (position < alignments_goodAlignments->numEntries)
00896         {
00897                 // Stop when score is below minimum dynamic cutoff
00898             goodAlignment = memSingleBlock_getEntry(alignments_goodAlignments, position);
00899             if (goodAlignment->highestNominalScore < minimumDynamicCutoff)
00900                         {
00901 //              printf("Changed numGoodAlignments from %d to %d\n",
00902 //                                      alignments_goodAlignments->numEntries, position); fflush(stdout);
00903                                 alignments_goodAlignments->numEntries = position;
00904                 break;
00905                         }
00906             position++;
00907                 }
00908         }
00909 
00910     // For each good alignment (for BLAST)
00911     position = 0;
00912     while (position < alignments_goodAlignments->numEntries)
00913     {
00914         goodAlignment = memSingleBlock_getEntry(alignments_goodAlignments, position);
00915         alignment = goodAlignment->alignment;
00916 
00917         // Load subject sequence into memory if not already loaded
00918                 if (alignment->inMemorySubject == 0)
00919         {
00920                 totalCopied += unpack_loadSubject(PSSMatrix, alignment);
00921                 totalLengths += alignment->encodedLength;
00922         }
00923 
00924                 position++;
00925         }
00926 
00927     // For each final alignment (for protein SSEARCH)
00928     position = 0;
00929     while (position < alignments_finalAlignments->numEntries)
00930     {
00931         finalAlignment = memSingleBlock_getEntry(alignments_finalAlignments, position);
00932         alignment = finalAlignment->alignment;
00933 
00934         // Load subject sequence into memory if not already loaded
00935                 if (alignment->inMemorySubject == 0)
00936             unpack_loadSubject(PSSMatrix, alignment);
00937 
00938                 position++;
00939         }
00940 
00941 //    printf("alignments_loadSubjectsIntoMemory=%d/%d\n", totalCopied, totalLengths);
00942 }

Here is the call graph for this function:

Here is the caller graph for this function:

void alignments_performScoring ( struct PSSMatrix  PSSMatrix  ) 

void alignments_sortFinalAlignments (  ) 

Definition at line 484 of file alignments.c.

References alignments_compareFinalAlignments(), alignments_finalAlignments, memSingleBlock::block, and memSingleBlock::numEntries.

Referenced by alignments_findTopFinalAlignments(), alignments_getTracebacks(), alignments_isFinalAlignment(), and search_proteinSsearch().

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

struct memBlocks* alignments_alignments

Definition at line 5 of file alignments.h.

Referenced by alignments_createNew(), alignments_findGoodAlignments(), alignments_free(), and alignments_initialize().

struct alignment* alignments_currentAlignment

Definition at line 10 of file alignments.h.

Referenced by alignments_addUngappedExtension(), alignments_createNew(), alignments_expandCluster(), alignments_initialize(), search_nucleotide(), search_nucleotide_largeTable(), search_nucleotide_longWord(), search_nucleotideSsearch(), search_protein1hit(), search_protein2hit(), and search_proteinSsearch().

struct memSingleBlock* alignments_finalAlignments

Definition at line 9 of file alignments.h.

Referenced by alignments_addFinalAlignment(), alignments_findTopFinalAlignments(), alignments_free(), alignments_getFinalAlignmentDescriptions(), alignments_getTracebacks(), alignments_initialize(), alignments_isFinalAlignment(), alignments_loadSubjectsIntoMemory(), alignments_moveGoodToFinal(), alignments_printFinalAlignments(), alignments_sortFinalAlignments(), blast_search(), print_gappedAlignmentsBrief(), and print_gappedAlignmentsFull().

struct memSingleBlock* alignments_goodAlignments

Definition at line 7 of file alignments.h.

Referenced by alignments_addGoodAlignment(), alignments_findFinalAlignments(), alignments_findTopFinalAlignments(), alignments_free(), alignments_initialize(), alignments_loadSubjectsIntoMemory(), alignments_moveGoodToFinal(), alignments_printGoodAlignments(), and alignments_sortGoodAlignments().

uint4 alignments_numClusters

Definition at line 16 of file alignments.c.

Referenced by alignments_expandCluster(), and print_gappedAlignmentsFull().


Generated on Wed Dec 19 20:48:54 2007 for fsa-blast by  doxygen 1.5.2