include/fasterGappedExtension.h File Reference

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

Go to the source code of this file.

Functions

gappedExtensionfasterGappedExtension_build (struct ungappedExtension *ungappedExtension, struct PSSMatrix PSSMatrix, int4 subjectSize, unsigned char *subject, int4 dropoff)
void fasterGappedExtension_printBeforeRow (int4 *row, unsigned char *subject, unsigned char *rowDropoff, unsigned char *columnDropoff)
void fasterGappedExtension_printAfterRow (int4 *row, unsigned char *subject, unsigned char *rowDropoff, unsigned char *columnDropoff)
void fasterGappedExtension_score (struct gappedExtension *gappedExtension)
void fasterGappedExtension_prune (struct gappedExtension *gappedExtension, struct ungappedExtension *ungappedExtension)
void fasterGappedExtension_free ()


Function Documentation

struct gappedExtension* fasterGappedExtension_build ( struct ungappedExtension ungappedExtension,
struct PSSMatrix  PSSMatrix,
int4  subjectSize,
unsigned char *  subject,
int4  dropoff 
) [read]

Definition at line 31 of file fasterGappedExtension.c.

References dpResults::best, dpResults::bestScore, ungappedExtension::end, fasterGappedExtension_dpAfterSeed(), fasterGappedExtension_dpBeforeSeed(), fasterGappedExtension_joinTraces(), fasterGappedExtension_traceAfterSeed(), fasterGappedExtension_traceBeforeSeed(), global_malloc(), int4, PSSMatrix::length, PSSMatrix::matrix, ungappedExtension::nominalScore, PSSMatrix_chop(), coordinate::queryOffset, trace::queryStart, ungappedExtension::seed, ungappedExtension::start, PSSMatrix::strandLength, coordinate::subjectOffset, trace::subjectStart, gappedExtension::trace, and trace::traceCodes.

Referenced by alignments_getTracebacks().

00034 {
00035         struct coordinate seed;
00036         unsigned char *choppedSubject;
00037         struct dpResults beforeDpResults, afterDpResults;
00038         struct trace beforeTrace, afterTrace, trace;
00039         struct PSSMatrix choppedPSSMatrix;
00040         int4 choppedSubjectSize;
00041         struct gappedExtension* gappedExtension;
00042     int4 strandOffset = 0;
00043 
00044         // Perform dynamic programming for points before the seed
00045         seed = ungappedExtension->seed;
00046     if (seed.queryOffset > PSSMatrix.strandLength)
00047     {
00048             // If query position is in the second strand, remove first strand from PSSM
00049         strandOffset = PSSMatrix.strandLength;
00050                 seed.queryOffset -= PSSMatrix.strandLength;
00051                 PSSMatrix = PSSMatrix_chop(PSSMatrix, PSSMatrix.strandLength);
00052     }
00053     else
00054     {
00055         // Otherwise remove second strand
00056         PSSMatrix.length = PSSMatrix.strandLength;
00057     }
00058 
00059 //    printf("Seed=%d,%d Length=%d,%d\n", seed.queryOffset, seed.subjectOffset, PSSMatrix.length, subjectSize);
00060 
00061         beforeDpResults = fasterGappedExtension_dpBeforeSeed(subject, PSSMatrix, seed, dropoff);
00062 
00063         // Trace back and create the trace which specifies the first half of the alignment
00064         beforeTrace = fasterGappedExtension_traceBeforeSeed(beforeDpResults, seed);
00065 
00066         // Chop the start off the query and subject so they begin at the seed
00067         choppedPSSMatrix = PSSMatrix_chop(PSSMatrix, seed.queryOffset);
00068         choppedSubject = subject + seed.subjectOffset;
00069         choppedSubjectSize = subjectSize - (seed.subjectOffset);
00070 
00071         // Perform dynamic programming for points after the seed
00072         afterDpResults = fasterGappedExtension_dpAfterSeed(choppedSubject, choppedPSSMatrix,
00073                                                       dropoff, choppedSubjectSize);
00074 
00075         // Trace back to get the trace for the seed onwards
00076         afterTrace = fasterGappedExtension_traceAfterSeed(afterDpResults, choppedPSSMatrix.length);
00077 
00078         // Join afterTrace to the end of beforeTrace
00079         trace = fasterGappedExtension_joinTraces(beforeTrace, afterTrace);
00080         free(afterTrace.traceCodes);
00081 
00082     // Adjust coordinates if extension was performed in the second strand
00083     afterDpResults.best.queryOffset += strandOffset;
00084     beforeDpResults.best.queryOffset += strandOffset;
00085         trace.queryStart += strandOffset;
00086 
00087 //      printf("Final trace length=%d\n", trace.length);
00088 
00089         // Create gapped extension
00090         gappedExtension = (struct gappedExtension*)global_malloc(sizeof(struct gappedExtension));
00091         gappedExtension->trace = trace;
00092         gappedExtension->next = NULL;
00093 
00094         // Start of afterTrace is end of the gapped extension, but we need to add seed position
00095         // to get correct offset
00096         gappedExtension->queryEnd = seed.queryOffset + afterTrace.queryStart + strandOffset;
00097         gappedExtension->subjectEnd = seed.subjectOffset + afterTrace.subjectStart;
00098 
00099 //      if (dloc == 88197331)
00100 //              printf("final[%d,%d,%d](%d)\n", beforeDpResults.bestScore, afterDpResults.bestScore,
00101 //              choppedPSSMatrix.matrix[0][choppedSubject[0]], seed.queryOffset);
00102 
00103     // Determine score by combining score from the two traces, and the match score at
00104         // the seed position
00105         gappedExtension->nominalScore = beforeDpResults.bestScore + afterDpResults.bestScore
00106                                      + choppedPSSMatrix.matrix[0][choppedSubject[0]];
00107 
00108     // Update ungappedExtension start/end
00109     ungappedExtension->start.queryOffset = trace.queryStart;
00110     ungappedExtension->end.queryOffset = gappedExtension->queryEnd;
00111     ungappedExtension->start.subjectOffset = trace.subjectStart;
00112     ungappedExtension->end.subjectOffset = gappedExtension->subjectEnd;
00113         ungappedExtension->nominalScore = gappedExtension->nominalScore;
00114 
00115     return gappedExtension;
00116 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fasterGappedExtension_free (  ) 

Definition at line 1229 of file fasterGappedExtension.c.

References fasterGappedExtension_insertQrow, fasterGappedExtension_insertSrow, fasterGappedExtension_matchRow, fasterGappedExtension_numRows, and fasterGappedExtension_traceback.

Referenced by main().

01230 {
01231         // Free memory used by traceback array
01232         while (fasterGappedExtension_numRows > 0)
01233         {
01234         fasterGappedExtension_numRows--;
01235                 free(fasterGappedExtension_traceback[fasterGappedExtension_numRows]);
01236         }
01237         free(fasterGappedExtension_traceback);
01238 
01239     free(fasterGappedExtension_matchRow);
01240     free(fasterGappedExtension_insertQrow);
01241     free(fasterGappedExtension_insertSrow);
01242 }

Here is the caller graph for this function:

void fasterGappedExtension_printAfterRow ( int4 *  row,
unsigned char *  subject,
unsigned char *  rowDropoff,
unsigned char *  columnDropoff 
)

Definition at line 1284 of file fasterGappedExtension.c.

References dpResults::best, and int4.

01286 {
01287         unsigned char* subjectPosition = subject;
01288     int4 *oldRow, *best;
01289 
01290         while (subjectPosition < columnDropoff)
01291         {
01292                 printf("     ");
01293                 subjectPosition++;
01294                 row++;
01295         }
01296 
01297     best = oldRow = row;
01298 
01299         while (subjectPosition < rowDropoff)
01300         {
01301         if (*row > *best)
01302                 best = row;
01303                 row++;
01304                 subjectPosition++;
01305         }
01306 
01307     row = oldRow; subjectPosition = columnDropoff;
01308 
01309     while (subjectPosition < rowDropoff)
01310         {
01311         if (row == best)
01312                         printf("%4d*", *row);
01313         else
01314                         printf("%4d ", *row);
01315                 row++;
01316                 subjectPosition++;
01317         }
01318 
01319         printf("\n");
01320 }

void fasterGappedExtension_printBeforeRow ( int4 *  row,
unsigned char *  subject,
unsigned char *  rowDropoff,
unsigned char *  columnDropoff 
)

Definition at line 1245 of file fasterGappedExtension.c.

References dpResults::best, and int4.

01247 {
01248         unsigned char* subjectPosition = subject;
01249     int4 *oldRow, *best;
01250 
01251         while (subjectPosition < rowDropoff)
01252         {
01253                 printf("     ");
01254                 subjectPosition++;
01255                 row++;
01256         }
01257 
01258     best = oldRow = row;
01259 
01260         while (subjectPosition < columnDropoff)
01261         {
01262         if (*row > *best)
01263                 best = row;
01264                 row++;
01265                 subjectPosition++;
01266         }
01267 
01268     row = oldRow; subjectPosition = rowDropoff;
01269 
01270     while (subjectPosition < columnDropoff)
01271         {
01272         if (row == best)
01273                         printf("%4d*", *row);
01274         else
01275                         printf("%4d ", *row);
01276                 row++;
01277                 subjectPosition++;
01278         }
01279 
01280         printf("\n");
01281 }

void fasterGappedExtension_prune ( struct gappedExtension gappedExtension,
struct ungappedExtension ungappedExtension 
)

Definition at line 131 of file fasterGappedExtension.c.

References ungappedExtension::end, int4, trace::length, ungappedExtension::next, coordinate::queryOffset, trace::queryStart, ungappedExtension::start, coordinate::subjectOffset, trace::subjectStart, gappedExtension::trace, and trace::traceCodes.

00133 {
00134         int4 queryPosition, subjectPosition;
00135         unsigned char* traceCodes;
00136         int4 count = 0, offset;
00137         struct trace trace;
00138         struct ungappedExtension *currentExtension, *previousExtension;
00139 
00140         // Get trace start point and tracecodes
00141         trace = gappedExtension->trace;
00142         queryPosition = trace.queryStart;
00143         subjectPosition = trace.subjectStart;
00144         traceCodes = trace.traceCodes;
00145 
00146         // Determine start offset
00147         offset = subjectPosition - queryPosition;
00148 
00149         // For each position in the trace
00150         while (count < trace.length)
00151         {
00152                 // Cycle through ungapped extensions and check if they overlap
00153                 // with this part of the gapped extension
00154                 previousExtension = ungappedExtension;
00155                 currentExtension = ungappedExtension->next;
00156                 while (currentExtension != NULL)
00157                 {
00158                         // If on same offset, within start and end of the ungappedExtension
00159                         if (currentExtension->start.subjectOffset -
00160                 currentExtension->start.queryOffset == offset &&
00161                             currentExtension->start.queryOffset <= queryPosition &&
00162                                 currentExtension->end.queryOffset >= queryPosition)
00163                         {
00164                                 // Remove current ungappedExtension from the list
00165                                 previousExtension->next = currentExtension->next;
00166                                 currentExtension = previousExtension->next;
00167                         }
00168                         else
00169                         {
00170                                 previousExtension = currentExtension;
00171                                 currentExtension = currentExtension->next;
00172                         }
00173                 }
00174 
00175                 // A match
00176                 if (traceCodes[count] == 0)
00177                 {
00178                         queryPosition++;
00179                         subjectPosition++;
00180                 }
00181                 // An insertion wrt. query
00182                 else if (traceCodes[count] == 1)
00183                 {
00184                         subjectPosition++;
00185                         offset++;
00186                 }
00187                 // An insertion wrt. subject
00188                 else
00189                 {
00190                         queryPosition++;
00191                         offset--;
00192                 }
00193                 count++;
00194         }
00195 }

void fasterGappedExtension_score ( struct gappedExtension gappedExtension  ) 

Definition at line 120 of file fasterGappedExtension.c.

References gappedExtension::eValue, gappedExtension::nominalScore, gappedExtension::normalizedScore, statistics_gappedCalculateEvalue(), and statistics_gappedNominal2normalized().

00121 {
00122         gappedExtension->normalizedScore
00123                 = statistics_gappedNominal2normalized(gappedExtension->nominalScore);
00124 
00125         gappedExtension->eValue
00126                 = statistics_gappedCalculateEvalue(gappedExtension->normalizedScore);
00127 }

Here is the call graph for this function:


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