|
| 1 | +/* -*- Mode: C ; indent-tabs-mode: nil ; c-file-style: "stroustrup" ; column-number-mode: t -*- |
| 2 | +
|
| 3 | + Project: YAHA, DNA alignment tool designed to find optimal split-read mappings on single-end queries. |
| 4 | + Author: Greg Faust (gf4ea@virginia.edu) |
| 5 | +
|
| 6 | + File: AlignArgs.c Includes code for AlignmentArgs Structure. |
| 7 | +
|
| 8 | + License Information: |
| 9 | +
|
| 10 | + Copyright 2009-2015 Gregory G. Faust |
| 11 | +
|
| 12 | + Licensed under the MIT license (the "License"); |
| 13 | + You may not use this file except in compliance with the License. |
| 14 | + You may obtain a copy of the License at http://opensource.org/licenses/MIT |
| 15 | +
|
| 16 | +*/ |
| 17 | + |
| 18 | +#include <stdlib.h> |
| 19 | +#include "Math.h" |
| 20 | + |
| 21 | +///// |
| 22 | +// AlignmentArgs Structure. |
| 23 | +///// |
| 24 | + |
| 25 | +#define DEFAULT_ARG_VALUE -1 |
| 26 | + |
| 27 | +AlignmentArgs_t * makeAlignmentArgs () |
| 28 | +{ |
| 29 | + AlignmentArgs_t * AAs = (AlignmentArgs_t *) malloc(sizeof(AlignmentArgs_t)); |
| 30 | + |
| 31 | + // Set all the default values. |
| 32 | + AAs->gfileName = NULL; |
| 33 | + AAs->xfileName = NULL; |
| 34 | + AAs->qfileName = "stdin"; |
| 35 | + AAs->ofileName = NULL; |
| 36 | + AAs->numThreads = 1; |
| 37 | + AAs->fastq = FALSE; |
| 38 | + |
| 39 | +#ifdef QUERYSTATS |
| 40 | + AAs->qsfileName = NULL; |
| 41 | + AAs->queryStats = FALSE; |
| 42 | +#endif |
| 43 | + |
| 44 | + // Any defaults that depend on other parameters must be set after the program args are processed. |
| 45 | + // So, mark them as DEFAULT_ARG_VALUE |
| 46 | + |
| 47 | + // Index parameters |
| 48 | + AAs->wordLen = 15; |
| 49 | + AAs->skipDist = 1; |
| 50 | + AAs->maxHits = DEFAULT_ARG_VALUE; |
| 51 | + |
| 52 | + // General Alignment Parameters |
| 53 | + AAs->maxGap = 50; |
| 54 | + AAs->maxIntron = DEFAULT_ARG_VALUE; |
| 55 | + AAs->minMatch = 25; |
| 56 | + AAs->minIdentity = 0.9; |
| 57 | + AAs->bandWidth = 5; |
| 58 | + AAs->maxDesert = 50; |
| 59 | + AAs->minRawScore = DEFAULT_ARG_VALUE; |
| 60 | + AAs->minNonOverlap = DEFAULT_ARG_VALUE; |
| 61 | + |
| 62 | + // These are the BWASW defaults. |
| 63 | + AAs->affineGapScoring = TRUE; |
| 64 | + AAs->GOCost = 5; |
| 65 | + AAs->GECost = 2; |
| 66 | + AAs->RCost = 3; |
| 67 | + AAs->MScore = 1; |
| 68 | + AAs->XCutoff = 25; |
| 69 | + |
| 70 | + // These are for filtering of alignments against a "best" set of query spanning alignments. |
| 71 | + AAs->OQC = TRUE; |
| 72 | + AAs->OQCMinNonOverlap = DEFAULT_ARG_VALUE; |
| 73 | + AAs->BPCost = 5; |
| 74 | + AAs->maxBPLog = 5; |
| 75 | + // By default, output only primary alignments. |
| 76 | + // AAs->FBSMaxSimilar = 1; |
| 77 | + AAs->FBS = FALSE; |
| 78 | + AAs->FBS_PSLength = 0.90; |
| 79 | + AAs->FBS_PSScore = 0.90; |
| 80 | + |
| 81 | + // For now, just make the default the max. |
| 82 | + AAs->maxQueryLength = 32000; |
| 83 | + AAs->verbose = FALSE; |
| 84 | + |
| 85 | + AAs->outputBlast8 = FALSE; |
| 86 | + AAs->outputSAM = TRUE; |
| 87 | + AAs->hardClip = TRUE; |
| 88 | + |
| 89 | + return AAs; |
| 90 | +} |
| 91 | + |
| 92 | +void disposeAlignmentArgs(AlignmentArgs_t * AAs) |
| 93 | +{ |
| 94 | + // The name of the index file and output file are always generated. |
| 95 | + if (AAs->gfileName != NULL) free(AAs->gfileName); |
| 96 | + if (AAs->ofileName != NULL) free(AAs->ofileName); |
| 97 | + free(AAs); |
| 98 | +} |
| 99 | + |
| 100 | +void printAlignmentArgs(AlignmentArgs_t * AAs, FILE * out) |
| 101 | +{ |
| 102 | + if (AAs->gfileName != NULL) fprintf(out, "Genome filename: %s\n", AAs->gfileName); |
| 103 | + if (AAs->xfileName != NULL) fprintf(out, "Index filename: %s\n", AAs->xfileName); |
| 104 | + if (AAs->qfileName != NULL) fprintf(out, "Query filename: %s\n", AAs->qfileName); |
| 105 | + if (AAs->ofileName != NULL) fprintf(out, "Output filename: %s\n", AAs->ofileName); |
| 106 | +} |
| 107 | + |
| 108 | +void postProcessAlignmentArgs(AlignmentArgs_t * AAs, BOOL query) |
| 109 | +{ |
| 110 | + // Make sure values not specified for AAs have reasonable values. |
| 111 | + if (AAs->maxIntron == DEFAULT_ARG_VALUE) |
| 112 | + AAs->maxIntron = AAs->maxGap; |
| 113 | + if (AAs->minRawScore == DEFAULT_ARG_VALUE) |
| 114 | + AAs->minRawScore = AAs->minMatch; |
| 115 | + if (AAs->OQCMinNonOverlap == DEFAULT_ARG_VALUE) |
| 116 | + AAs->OQCMinNonOverlap = AAs->minMatch; |
| 117 | + if (AAs->OQCMinNonOverlap <= 0) |
| 118 | + { |
| 119 | + fprintf(stderr, "MNO parameter must be >=1. MNO=1 will be used.\n"); |
| 120 | + AAs->OQCMinNonOverlap = 1; |
| 121 | + } |
| 122 | + if (AAs->minNonOverlap == DEFAULT_ARG_VALUE) |
| 123 | + { |
| 124 | + AAs->minNonOverlap = AAs->OQCMinNonOverlap; // 1; |
| 125 | + } |
| 126 | + if (!AAs->affineGapScoring) |
| 127 | + { |
| 128 | + // Simulate edit distance by appropriate setting of the scoring paramenters. |
| 129 | + // This is not well tested. |
| 130 | + AAs->MScore = 1; |
| 131 | + AAs->RCost = AAs->GECost = 1; |
| 132 | + AAs->GOCost = 0; |
| 133 | + } |
| 134 | + // Calculate the min extension length requiring DP. |
| 135 | + // Since we always dp perfect extensions, the next bp is a mismatch. |
| 136 | + // DP is only needed if the length of the extension is long enough |
| 137 | + // to have enough matches to make up for the cost of the mismatch. |
| 138 | + // The following is equivalent to ceiling(RCost/MScore) + 2; |
| 139 | + // We take the min of RCost and a single base gap cost. |
| 140 | + // But for any rational choice of the cost parameters, RCost <= AAs->GOCost + AAs->GECost. |
| 141 | + int len = 1; |
| 142 | + int score = 0; |
| 143 | + int target = MIN(AAs->RCost, AAs->GOCost + AAs->GECost); |
| 144 | + while (score <= target) |
| 145 | + { |
| 146 | + score += AAs->MScore; |
| 147 | + len += 1; |
| 148 | + } |
| 149 | + AAs->minExtLength = len; |
| 150 | + |
| 151 | + if (AAs->maxHits == DEFAULT_ARG_VALUE) |
| 152 | + { |
| 153 | + if (query) AAs->maxHits = 650; |
| 154 | + else AAs->maxHits = SUINT_MAX_VALUE - 10; |
| 155 | + } |
| 156 | + else AAs->maxHits = MIN(AAs->maxHits, SUINT_MAX_VALUE - 10); |
| 157 | + // Only values between 1 and 9 make sense for this parameter. |
| 158 | + // For now, we will do the right thing with a warning. |
| 159 | + if (AAs->maxBPLog < 1) |
| 160 | + { |
| 161 | + fprintf(stderr, "MGDP parameter must be between 1 and 9 (inclusive). MGDP=1 will be used.\n"); |
| 162 | + AAs->maxBPLog = 1; |
| 163 | + } |
| 164 | + if (AAs->maxBPLog > 9) |
| 165 | + { |
| 166 | + fprintf(stderr, "MGDP parameter must be between 1 and 9 (inclusive). MGDP=9 will be used.\n"); |
| 167 | + AAs->maxBPLog = 9; |
| 168 | + } |
| 169 | +} |
0 commit comments