CigarRollerTest.cpp

00001 /*
00002  *  Copyright (C) 2010  Regents of the University of Michigan
00003  *
00004  *   This program is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 
00019 // put TEST below here, so that makedepend will see the .h, so that we
00020 // can get a clean dependency for SmithWaterman.o, so that we can at least
00021 // compile the header when we change it.
00022 
00023 
00024 #include <getopt.h>
00025 #include "Generic.h"
00026 #include "CigarRollerTest.h"
00027 
00028 //
00029 // Test the obvious cases.
00030 // Add non-obvious ones as bugs come up.
00031 //
00032 int CigarRollerTest::test(void)
00033 {
00034     // Create the CigarRoller.
00035     CigarRoller cigar;
00036 
00037     int failures = 0, testNum = 0;
00038 
00039     //   const char *str;
00040     String str;
00041     std::string result;
00042     
00043     cigar.getCigarString(str);
00044     result = str.c_str();
00045     //    result = str = cigar.getString(); delete str;
00046 
00047     check(failures, ++testNum, "constructor", result, "");    // test empty case
00048 
00049     CigarRoller::CigarOperator op;
00050 
00051     op.operation = CigarRoller::match;
00052     op.count = 10;
00053 
00054     cigar += op;
00055 
00056     op.count=5;
00057 
00058     cigar += op;
00059 
00060     op.count=5; op.operation = CigarRoller::mismatch;   // test that match/mismatch get combined
00061 
00062     cigar += op;
00063 
00064     op.count=5; op.operation = CigarRoller::insert;
00065 
00066     cigar += op;
00067 
00068     op.count=5; op.operation = CigarRoller::insert;
00069 
00070     cigar += op;
00071 
00072     op.count=5; op.operation = CigarRoller::del;
00073 
00074     cigar += op;
00075 
00076     op.count=5; op.operation = CigarRoller::mismatch;
00077 
00078     cigar += op;
00079 
00080     op.count=5; op.operation = CigarRoller::match;
00081 
00082     cigar += op;
00083 
00084     op.count=5; op.operation = CigarRoller::skip;
00085 
00086     cigar += op;
00087 
00088     op.count=5; op.operation = CigarRoller::match;
00089 
00090     cigar += op;
00091 
00092     op.count=2; op.operation = CigarRoller::pad;
00093 
00094     cigar += op;
00095 
00096     op.count=3; op.operation = CigarRoller::match;
00097 
00098     cigar += op;
00099 
00100     cigar.getCigarString(str);
00101     result = str.c_str();
00102     //    result = str = cigar.getString();  delete str;
00103 
00104     check(failures, ++testNum, "match combining", "20M10I5D10M5N5M2P3M", result);
00105     check(failures, ++testNum, "length check", 8, cigar.size());
00106 
00107     //////////////////////////////////////////////////////////////////////////////////////////////////////////
00108     // Test getRefOffset, getQueryIndex, getRefPosition, & getQueryIndex(that takes ref position)
00109 
00110     // Validate the reference offsets when passing in a query index,
00111     // and the query offsets when passing in a query index.
00112     // Spot check the offsets out of order - to verify order doesn't matter.
00113     check(failures, ++testNum, "getRefOffset(20)", -1, cigar.getRefOffset(20));
00114     check(failures, ++testNum, "getRefOffset(30)", 25, cigar.getRefOffset(30));
00115     check(failures, ++testNum, "getRefOffset(46)", 46, cigar.getRefOffset(46));
00116     check(failures, ++testNum, "getRefOffset(0)", 0, cigar.getRefOffset(0));
00117     check(failures, ++testNum, "getRefPosition(20, 5)", -1, cigar.getRefPosition(20, 5));
00118     check(failures, ++testNum, "getRefPosition(30, 5)", 30, cigar.getRefPosition(30, 5));
00119     check(failures, ++testNum, "getRefPosition(46, 5)", 51, cigar.getRefPosition(46, 5));
00120     check(failures, ++testNum, "getRefPosition(0, 5)", 5, cigar.getRefPosition(0, 5));
00121     check(failures, ++testNum, "getQueryIndex(20)", CigarRoller::INDEX_NA, cigar.getQueryIndex(20));
00122     check(failures, ++testNum, "getQueryIndex(30)", 35, cigar.getQueryIndex(30));
00123     check(failures, ++testNum, "getQueryIndex(35)", Cigar::INDEX_NA, cigar.getQueryIndex(35));
00124     check(failures, ++testNum, "getQueryIndex(46)", 46, cigar.getQueryIndex(46));
00125     check(failures, ++testNum, "getQueryIndex(0)", 0, cigar.getQueryIndex(0));
00126     check(failures, ++testNum, "getQueryIndex(25, 5)", -1, cigar.getQueryIndex(20));
00127     check(failures, ++testNum, "getQueryIndex(35, 5)", 35, cigar.getQueryIndex(30));
00128     check(failures, ++testNum, "getQueryIndex(40, 5)", -1, cigar.getQueryIndex(35));
00129     check(failures, ++testNum, "getQueryIndex(51, 5)", 46, cigar.getQueryIndex(46));
00130     check(failures, ++testNum, "getQueryIndex(5, 5)", 0, cigar.getQueryIndex(0));
00131 
00132     int i = 0;
00133     int queryIndex = 0;
00134     int refOffset = 0;
00135     // Validate the 20 matches.
00136     for(i = 0; i < 20; i++)
00137     {
00138         check(failures, ++testNum, "getRefOffset(queryIndex)", refOffset, cigar.getRefOffset(queryIndex));
00139         check(failures, ++testNum, "getQueryIndex(refOffset)", queryIndex, cigar.getQueryIndex(refOffset));
00140         check(failures, ++testNum, "getRefPosition(queryIndex, 5)", refOffset + 5, cigar.getRefPosition(queryIndex, 5));
00141         check(failures, ++testNum, "getQueryIndex(refPosition, 5)", queryIndex, cigar.getQueryIndex(refOffset + 5, 5));
00142         ++queryIndex;
00143         ++refOffset;
00144     }
00145     // Validate the 10 Inserts - exist in query, but not in the reference.
00146     for(i = 0; i < 10; i++)
00147     {
00148         check(failures, ++testNum, "getRefOffset(queryIndex)", -1, cigar.getRefOffset(queryIndex));
00149         check(failures, ++testNum, "getRefPosition(queryIndex, 5)", -1, cigar.getRefPosition(queryIndex, 5));
00150         ++queryIndex;
00151     }
00152     // Validate the 5 Deletions - exist in the reference, but not the query.
00153     for(i = 0; i < 5; i++)
00154     {
00155         check(failures, ++testNum, "getQueryIndex(refOffset)", -1, cigar.getQueryIndex(refOffset));
00156         check(failures, ++testNum, "getQueryIndex(refPosition, 5)", -1, cigar.getQueryIndex(refOffset + 5, 5));
00157         refOffset++;
00158     }
00159     // Validate the 10 matches.
00160     for(i = 0; i < 10; i++)
00161     {
00162         check(failures, ++testNum, "getRefOffset(queryIndex)", refOffset, cigar.getRefOffset(queryIndex));
00163         check(failures, ++testNum, "getQueryIndex(refOffset)", queryIndex, cigar.getQueryIndex(refOffset));
00164         check(failures, ++testNum, "getRefPosition(queryIndex, 5)", refOffset + 5, cigar.getRefPosition(queryIndex, 5));
00165         check(failures, ++testNum, "getQueryIndex(refPosition, 5)", queryIndex, cigar.getQueryIndex(refOffset + 5, 5));
00166         ++queryIndex;
00167         ++refOffset;
00168     }
00169     // Validate the 5 Skips - exist in the reference, but not the query.
00170     for(i = 0; i < 5; i++)
00171     {
00172         check(failures, ++testNum, "getQueryIndex(refOffset)", -1, cigar.getQueryIndex(refOffset));
00173         check(failures, ++testNum, "getQueryIndex(refPosition, 5)", -1, cigar.getQueryIndex(refOffset + 5, 5));
00174         refOffset++;
00175     }
00176     // Validate the 5 matches.
00177     for(i = 0; i < 5; i++)
00178     {
00179         check(failures, ++testNum, "getRefOffset(queryIndex)", refOffset, cigar.getRefOffset(queryIndex));
00180         check(failures, ++testNum, "getQueryIndex(refOffset)", queryIndex, cigar.getQueryIndex(refOffset));
00181         check(failures, ++testNum, "getRefPosition(queryIndex, 5)", refOffset + 5, cigar.getRefPosition(queryIndex, 5));
00182         check(failures, ++testNum, "getQueryIndex(refPosition, 5)", queryIndex, cigar.getQueryIndex(refOffset + 5, 5));
00183         ++queryIndex;
00184         ++refOffset;
00185     }
00186     // Nothing to validate for the 2 pads since they do not show up in either the reference or the query.
00187     // Validate the 3 matches.
00188     for(i = 0; i < 3; i++)
00189     {
00190         check(failures, ++testNum, "getRefOffset(queryIndex)", refOffset, cigar.getRefOffset(queryIndex));
00191         check(failures, ++testNum, "getQueryIndex(refOffset)", queryIndex, cigar.getQueryIndex(refOffset));
00192         check(failures, ++testNum, "getRefPosition(queryIndex, 5)", refOffset + 5, cigar.getRefPosition(queryIndex, 5));
00193         check(failures, ++testNum, "getQueryIndex(refPosition, 5)", queryIndex, cigar.getQueryIndex(refOffset + 5, 5));
00194         ++queryIndex;
00195         ++refOffset;
00196     }
00197 
00198     // Validate that if you go beyond the end, -1 is returned.
00199     check(failures, ++testNum, "getRefOffset(queryIndex)", -1, cigar.getRefOffset(queryIndex));
00200     check(failures, ++testNum, "getQueryIndex(refOffset)", -1, cigar.getQueryIndex(refOffset));
00201     check(failures, ++testNum, "getRefPosition(queryIndex, 5)", -1, cigar.getRefPosition(queryIndex, 5));
00202     check(failures, ++testNum, "getQueryIndex(refPosition, 5)", -1, cigar.getQueryIndex(refOffset + 5, 5));
00203     ++queryIndex;
00204     ++refOffset;
00205     check(failures, ++testNum, "getRefOffset(queryIndex)", -1, cigar.getRefOffset(queryIndex));
00206     check(failures, ++testNum, "getQueryIndex(refOffset)", -1, cigar.getQueryIndex(refOffset));
00207     check(failures, ++testNum, "getRefPosition(queryIndex, 5)", -1, cigar.getRefPosition(queryIndex, 5));
00208     check(failures, ++testNum, "getQueryIndex(refPosition, 5)", -1, cigar.getQueryIndex(refOffset + 5, 5));
00209 
00210     ////////////////////////////////////////////////////////////////////////
00211     // Test getNumOverlaps
00212     
00213     // When query starts at position 5:
00214     // Overlaps are at 5-24, 30-39, 45-49, 50-52
00215 
00216     // Test with region [1-5) where query starts at position 5 = 0 overlaps.
00217     check(failures, ++testNum, "getNumOverlaps(1, 5, 5)", (uint32_t)0, cigar.getNumOverlaps(1, 5, 5));
00218 
00219     // Test with region [53-101) where query starts at position 5 = 0 overlaps.
00220     check(failures, ++testNum, "getNumOverlaps(53, 101, 5)", (uint32_t)0, cigar.getNumOverlaps(53, 101, 5));
00221 
00222     // Test with region [53-10) where query starts at position 5 = 0 overlaps.
00223     check(failures, ++testNum, "getNumOverlaps(53, 10, 5)", (uint32_t)0, cigar.getNumOverlaps(53, 10, 5));
00224 
00225     // Test with region [35-10) where query starts at position 5 = 0 overlaps.
00226     check(failures, ++testNum, "getNumOverlaps(35, 10, 5)", (uint32_t)0, cigar.getNumOverlaps(35, 10, 5));
00227 
00228     // Test with region [35-1) where query starts at position 5 = 0 overlaps.
00229     check(failures, ++testNum, "getNumOverlaps(35, 1, 5)", (uint32_t)0, cigar.getNumOverlaps(35, 1, 5));
00230 
00231     // Test with region [1-6) where query starts at position 5 - 1 overlap = pos 5.
00232     check(failures, ++testNum, "getNumOverlaps(1, 6, 5)", (uint32_t)1, cigar.getNumOverlaps(1, 6, 5));
00233 
00234     // Test with region [25-30) where query has only DELETIONS from the reference = 0 overlaps.
00235     check(failures, ++testNum, "getNumOverlaps(25, 30, 5)", (uint32_t)0, cigar.getNumOverlaps(25, 30, 5));
00236 
00237     // Test with region [24-30) where query has only a match at position 24 = 1 overlap.
00238     check(failures, ++testNum, "getNumOverlaps(24, 30, 5)", (uint32_t)1, cigar.getNumOverlaps(24, 30, 5));
00239 
00240     // Test with region [25-31) where query has only a match at position 30 = 1 overlap.
00241     check(failures, ++testNum, "getNumOverlaps(25, 31, 5)", (uint32_t)1, cigar.getNumOverlaps(25, 31, 5));
00242 
00243     // Test with region [1-31), match pos 5-24 & 30 = 21 overlaps
00244     check(failures, ++testNum, "getNumOverlaps(1, 31, 5)", (uint32_t)21, cigar.getNumOverlaps(1, 31, 5));
00245 
00246     // Test a region that covers the entire range [1-101), match pos 5-24, 30-39, 45-49, & 50-52 = 38 overlaps
00247     check(failures, ++testNum, "getNumOverlaps(1, 101, 5)", (uint32_t)38, cigar.getNumOverlaps(1, 101, 5));
00248 
00249     // Test a region that covers the entire range [-1--1), (whole region) match pos 5-24, 30-39, 45-49, & 50-52 = 38 overlaps
00250     check(failures, ++testNum, "getNumOverlaps(-1, -1, 5)", (uint32_t)38, cigar.getNumOverlaps(-1, -1, 5));
00251 
00252     // Test a region that covers the entire range [6-52), match pos 6-24, 30-39, 45-49, & 50-51 = 36 overlaps
00253     check(failures, ++testNum, "getNumOverlaps(6, 52, 5)", (uint32_t)36, cigar.getNumOverlaps(6, 52, 5));
00254 
00255     // Test with region [40-45) where query has only SKIPS from the reference = 0 overlaps.
00256     check(failures, ++testNum, "getNumOverlaps(40, 45, 5)", (uint32_t)0, cigar.getNumOverlaps(40, 45, 5));
00257 
00258     // Test a region that covers the range [-1-10), (whole region) match pos 5-9 = 5 overlaps
00259     check(failures, ++testNum, "getNumOverlaps(-1, 10, 5)", (uint32_t)5, cigar.getNumOverlaps(-1, 10, 5));
00260 
00261     // Test a region that covers the range [50--1), (whole region) match pos 50-52 = 3 overlaps
00262     check(failures, ++testNum, "getNumOverlaps(50, -1, 5)", (uint32_t)3, cigar.getNumOverlaps(50, -1, 5));
00263 
00264     ////////////////////////////////////////////////////////////////////////////
00265     // Test a new CIGAR.
00266     cigar.Set("4M10N4M3I2M4D3M");
00267     String expectedResult = "4M10N4M3I2M4D3M";
00268     String cigarString = "HI";
00269     cigar.getCigarString(cigarString);
00270     check(failures, ++testNum, "getCigarString", expectedResult, cigarString);
00271 
00272     ////////////////////////
00273     // Test getNumOverlaps.
00274     check(failures, ++testNum, "getNumOverlaps(5,32,5)", (uint32_t)13, cigar.getNumOverlaps(5,32,5));
00275     check(failures, ++testNum, "getNumOverlaps(5,31,5)", (uint32_t)12, cigar.getNumOverlaps(5,31,5));
00276     check(failures, ++testNum, "getNumOverlaps(0,100,5)", (uint32_t)13, cigar.getNumOverlaps(0,100,5));
00277     check(failures, ++testNum, "getNumOverlaps(-1, -1,5)", (uint32_t)13, cigar.getNumOverlaps(-1, -1,5));
00278     check(failures, ++testNum, "getNumOverlaps(-1,10,5)", (uint32_t)4, cigar.getNumOverlaps(-1,10,5));
00279     check(failures, ++testNum, "getNumOverlaps(10,-1,5)", (uint32_t)9, cigar.getNumOverlaps(10,-1,5));
00280     check(failures, ++testNum, "getNumOverlaps(9,19,5)", (uint32_t)0, cigar.getNumOverlaps(9,19,5));
00281     check(failures, ++testNum, "getNumOverlaps(9,20,5)", (uint32_t)1, cigar.getNumOverlaps(9,20,5));
00282     check(failures, ++testNum, "getNumOverlaps(9,6,5)", (uint32_t)0, cigar.getNumOverlaps(9,6,5));
00283     check(failures, ++testNum, "getNumOverlaps(0,5,5)", (uint32_t)0, cigar.getNumOverlaps(0,5,5));
00284     check(failures, ++testNum, "getNumOverlaps(32,40,5)", (uint32_t)0, cigar.getNumOverlaps(32,40,5));
00285     check(failures, ++testNum, "getNumOverlaps(0,5,1)", (uint32_t)4, cigar.getNumOverlaps(0,5,1));
00286     check(failures, ++testNum, "getNumOverlaps(32,40,32)", (uint32_t)4, cigar.getNumOverlaps(32,40,32));
00287 
00288     // Get Query Index for reference offset 0 - 27
00289     // 4M
00290     check(failures, ++testNum, "getQueryIndex(0)", 0, cigar.getQueryIndex(0));
00291     check(failures, ++testNum, "getQueryIndex(1)", 1, cigar.getQueryIndex(1));
00292     check(failures, ++testNum, "getQueryIndex(2)", 2, cigar.getQueryIndex(2));
00293     check(failures, ++testNum, "getQueryIndex(3)", 3, cigar.getQueryIndex(3));
00294     // 10N
00295     check(failures, ++testNum, "getQueryIndex(4)", -1, cigar.getQueryIndex(4));
00296     check(failures, ++testNum, "getQueryIndex(5)", -1, cigar.getQueryIndex(5));
00297     check(failures, ++testNum, "getQueryIndex(6)", -1, cigar.getQueryIndex(6));
00298     check(failures, ++testNum, "getQueryIndex(7)", -1, cigar.getQueryIndex(7));
00299     check(failures, ++testNum, "getQueryIndex(8)", -1, cigar.getQueryIndex(8));
00300     check(failures, ++testNum, "getQueryIndex(9)", -1, cigar.getQueryIndex(9));
00301     check(failures, ++testNum, "getQueryIndex(10)", -1, cigar.getQueryIndex(10));
00302     check(failures, ++testNum, "getQueryIndex(11)", -1, cigar.getQueryIndex(11));
00303     check(failures, ++testNum, "getQueryIndex(12)", -1, cigar.getQueryIndex(12));
00304     check(failures, ++testNum, "getQueryIndex(13)", -1, cigar.getQueryIndex(13));
00305     // 4M
00306     check(failures, ++testNum, "getQueryIndex(14)", 4, cigar.getQueryIndex(14));
00307     check(failures, ++testNum, "getQueryIndex(15)", 5, cigar.getQueryIndex(15));
00308     check(failures, ++testNum, "getQueryIndex(16)", 6, cigar.getQueryIndex(16));
00309     check(failures, ++testNum, "getQueryIndex(17)", 7, cigar.getQueryIndex(17));
00310     // 3I - nothing to check - not in reference - covers query indices  8-10
00311     // 2M
00312     check(failures, ++testNum, "getQueryIndex(18)", 11, cigar.getQueryIndex(18));
00313     check(failures, ++testNum, "getQueryIndex(19)", 12, cigar.getQueryIndex(19));
00314     // 4D
00315     check(failures, ++testNum, "getQueryIndex(20)", -1, cigar.getQueryIndex(20));
00316     check(failures, ++testNum, "getQueryIndex(21)", -1, cigar.getQueryIndex(21));
00317     check(failures, ++testNum, "getQueryIndex(22)", -1, cigar.getQueryIndex(22));
00318     check(failures, ++testNum, "getQueryIndex(23)", -1, cigar.getQueryIndex(23));
00319     // 3M
00320     check(failures, ++testNum, "getQueryIndex(24)", 13, cigar.getQueryIndex(24));
00321     check(failures, ++testNum, "getQueryIndex(25)", 14, cigar.getQueryIndex(25));
00322     check(failures, ++testNum, "getQueryIndex(26)", 15, cigar.getQueryIndex(26));
00323 
00324     //  Get Query Index for reference positions 0-33
00325     // N/A
00326     check(failures, ++testNum, "getQueryIndex(0, 5)", -1, cigar.getQueryIndex(0, 5));
00327     check(failures, ++testNum, "getQueryIndex(1, 5)", -1, cigar.getQueryIndex(1, 5));
00328     check(failures, ++testNum, "getQueryIndex(2, 5)", -1, cigar.getQueryIndex(2, 5));
00329     check(failures, ++testNum, "getQueryIndex(3, 5)", -1, cigar.getQueryIndex(3, 5));
00330     check(failures, ++testNum, "getQueryIndex(4, 5)", -1, cigar.getQueryIndex(4, 5));
00331     // 4M
00332     check(failures, ++testNum, "getQueryIndex(5, 5)", 0, cigar.getQueryIndex(5, 5));
00333     check(failures, ++testNum, "getQueryIndex(6, 5)", 1, cigar.getQueryIndex(6, 5));
00334     check(failures, ++testNum, "getQueryIndex(7, 5)", 2, cigar.getQueryIndex(7, 5));
00335     check(failures, ++testNum, "getQueryIndex(8, 5)", 3, cigar.getQueryIndex(8, 5));
00336     // 10N
00337     check(failures, ++testNum, "getQueryIndex(9, 5)", -1, cigar.getQueryIndex(9, 5));
00338     check(failures, ++testNum, "getQueryIndex(10, 5)", -1, cigar.getQueryIndex(10, 5));
00339     check(failures, ++testNum, "getQueryIndex(11, 5)", -1, cigar.getQueryIndex(11, 5));
00340     check(failures, ++testNum, "getQueryIndex(12, 5)", -1, cigar.getQueryIndex(12, 5));
00341     check(failures, ++testNum, "getQueryIndex(13, 5)", -1, cigar.getQueryIndex(13, 5));
00342     check(failures, ++testNum, "getQueryIndex(14, 5)", -1, cigar.getQueryIndex(14, 5));
00343     check(failures, ++testNum, "getQueryIndex(15, 5)", -1, cigar.getQueryIndex(15, 5));
00344     check(failures, ++testNum, "getQueryIndex(16, 5)", -1, cigar.getQueryIndex(16, 5));
00345     check(failures, ++testNum, "getQueryIndex(17, 5)", -1, cigar.getQueryIndex(17, 5));
00346     check(failures, ++testNum, "getQueryIndex(18, 5)", -1, cigar.getQueryIndex(18, 5));
00347     // 4M
00348     check(failures, ++testNum, "getQueryIndex(19, 5)", 4, cigar.getQueryIndex(19, 5));
00349     check(failures, ++testNum, "getQueryIndex(20, 5)", 5, cigar.getQueryIndex(20, 5));
00350     check(failures, ++testNum, "getQueryIndex(21, 5)", 6, cigar.getQueryIndex(21, 5));
00351     check(failures, ++testNum, "getQueryIndex(22, 5)", 7, cigar.getQueryIndex(22, 5));
00352     // 3I - nothing to check - not in reference - covers query indices  8-10
00353     // 2M
00354     check(failures, ++testNum, "getQueryIndex(23, 5)", 11, cigar.getQueryIndex(23, 5));
00355     check(failures, ++testNum, "getQueryIndex(24, 5)", 12, cigar.getQueryIndex(24, 5));
00356     // 4D
00357     check(failures, ++testNum, "getQueryIndex(25, 5)", -1, cigar.getQueryIndex(25, 5));
00358     check(failures, ++testNum, "getQueryIndex(26, 5)", -1, cigar.getQueryIndex(26, 5));
00359     check(failures, ++testNum, "getQueryIndex(27, 5)", -1, cigar.getQueryIndex(27, 5));
00360     check(failures, ++testNum, "getQueryIndex(28, 5)", -1, cigar.getQueryIndex(28, 5));
00361     // 3M
00362     check(failures, ++testNum, "getQueryIndex(29, 5)", 13, cigar.getQueryIndex(29, 5));
00363     check(failures, ++testNum, "getQueryIndex(30, 5)", 14, cigar.getQueryIndex(30, 5));
00364     check(failures, ++testNum, "getQueryIndex(31, 5)", 15, cigar.getQueryIndex(31, 5));
00365 
00366     // Get reference offset for query index 0 - 17
00367     // 4M
00368     check(failures, ++testNum, "getRefOffset(0)", 0, cigar.getRefOffset(0));
00369     check(failures, ++testNum, "getRefOffset(1)", 1, cigar.getRefOffset(1));
00370     check(failures, ++testNum, "getRefOffset(2)", 2, cigar.getRefOffset(2));
00371     check(failures, ++testNum, "getRefOffset(3)", 3, cigar.getRefOffset(3));
00372     // 10N - nothing to check - not in query - covers ref offsets 4-13
00373     // 4M
00374     check(failures, ++testNum, "getRefOffset(4)", 14, cigar.getRefOffset(4));
00375     check(failures, ++testNum, "getRefOffset(5)", 15, cigar.getRefOffset(5));
00376     check(failures, ++testNum, "getRefOffset(6)", 16, cigar.getRefOffset(6));
00377     check(failures, ++testNum, "getRefOffset(7)", 17, cigar.getRefOffset(7));
00378     // 3I
00379     check(failures, ++testNum, "getRefOffset(8)", -1, cigar.getRefOffset(8));
00380     check(failures, ++testNum, "getRefOffset(9)", -1, cigar.getRefOffset(9));
00381     check(failures, ++testNum, "getRefOffset(10)", -1, cigar.getRefOffset(10));
00382     // 2M
00383     check(failures, ++testNum, "getRefOffset(11)", 18, cigar.getRefOffset(11));
00384     check(failures, ++testNum, "getRefOffset(12)", 19, cigar.getRefOffset(12));
00385     // 4D - nothing to check - not in query - covers ref offsets 20-23
00386     // 3M
00387     check(failures, ++testNum, "getRefOffset(13)", 24, cigar.getRefOffset(13));
00388     check(failures, ++testNum, "getRefOffset(14)", 25, cigar.getRefOffset(14));
00389     check(failures, ++testNum, "getRefOffset(15)", 26, cigar.getRefOffset(15));
00390 
00391 
00392     // Get reference position for query index 0 - 17
00393     // 4M
00394     check(failures, ++testNum, "getRefPosition(0, 5)", 5, cigar.getRefPosition(0, 5));
00395     check(failures, ++testNum, "getRefPosition(1, 5)", 6, cigar.getRefPosition(1, 5));
00396     check(failures, ++testNum, "getRefPosition(2, 5)", 7, cigar.getRefPosition(2, 5));
00397     check(failures, ++testNum, "getRefPosition(3, 5)", 8, cigar.getRefPosition(3, 5));
00398     // 10N - nothing to check - not in query - covers ref offsets 4-13
00399     // 4M
00400     check(failures, ++testNum, "getRefPosition(4, 5)", 19, cigar.getRefPosition(4, 5));
00401     check(failures, ++testNum, "getRefPosition(5, 5)", 20, cigar.getRefPosition(5, 5));
00402     check(failures, ++testNum, "getRefPosition(6, 5)", 21, cigar.getRefPosition(6, 5));
00403     check(failures, ++testNum, "getRefPosition(7, 5)", 22, cigar.getRefPosition(7, 5));
00404     // 3I
00405     check(failures, ++testNum, "getRefPosition(8, 5)", -1, cigar.getRefPosition(8, 5));
00406     check(failures, ++testNum, "getRefPosition(9, 5)", -1, cigar.getRefPosition(9, 5));
00407     check(failures, ++testNum, "getRefPosition(10, 5)", -1, cigar.getRefPosition(10, 5));
00408     // 2M
00409     check(failures, ++testNum, "getRefPosition(11, 5)", 23, cigar.getRefPosition(11, 5));
00410     check(failures, ++testNum, "getRefPosition(12, 5)", 24, cigar.getRefPosition(12, 5));
00411     // 4D - nothing to check - not in query - covers ref pos 25-28
00412     // 3M
00413     check(failures, ++testNum, "getRefPosition(13, 5)", 29, cigar.getRefPosition(13, 5));
00414     check(failures, ++testNum, "getRefPosition(14, 5)", 30, cigar.getRefPosition(14, 5));
00415     check(failures, ++testNum, "getRefPosition(15, 5)", 31, cigar.getRefPosition(15, 5));
00416 
00417 
00418 
00419     ////////////////////////////////////////////////////////////////////////////
00420     // Test a new CIGAR set by buffer.
00421     // 2S 3M 1I 2M 1D 1M 2P 1M 3N 1M 3H
00422     uint32_t cigarBuf[] = {0x24,  // 2S = 2 << 4 | 4
00423                            0x30,  // 3M = 3 << 4 | 0
00424                            0x11,  // 1I = 1 << 4 | 1
00425                            0x20,  // 2M = 2 << 4 | 0
00426                            0x12,  // 1D = 1 << 4 | 2
00427                            0x10,  // 1M = 1 << 4 | 0
00428                            0x26,  // 2P = 2 << 4 | 6
00429                            0x10,  // 1m = 1 << 4 | 0
00430                            0x33,  // 3N = 3 << 4 | 3
00431                            0x10,  // 1M = 1 << 4 | 0
00432                            0x35}; // 3H = 3 << 4 | 5
00433     cigar.Set(cigarBuf, 11);
00434     cigarString = "HI";
00435     cigar.getCigarString(cigarString);
00436     expectedResult = "2S3M1I2M1D1M2P1M3N1M3H";
00437     check(failures, ++testNum, "getCigarString", expectedResult, cigarString);
00438     check(failures, ++testNum, "getNumEndClips", 3, cigar.getNumEndClips());
00439     check(failures, ++testNum, "getNumBeginClips", 2, cigar.getNumBeginClips());
00440 
00441     std::cout << "\nCigarRoller PASS: " << testNum - failures << "  FAIL: " << failures << std::endl;
00442     // return the number of failures.
00443     return(failures);
00444 }
00445 
00446 
00447 int main(int argc, const char **argv)
00448 {
00449     CigarRollerTest roller;
00450     
00451     bool showAllCasesFlag = false;
00452     int opt;
00453 
00454     while(( opt = getopt(argc, (char **) argv, "v")) != -1) {
00455         switch(opt) {
00456             case 'v':
00457                 showAllCasesFlag = true;
00458                 break;
00459             default:
00460                 std::cerr << "usage: testSW [-v]" << std::endl;
00461                 exit(1);
00462         }
00463     }
00464 
00465 
00466     //
00467     // do cigar roller tests first
00468     //
00469     return(roller.test());
00470 
00471     // CIGAR explanation - for backward SW runs, the corresponding
00472     // CIGAR string is generated from the back of the string to the
00473     // front.  Recall that the soft clipping is only done at the
00474     // "end" of the string, taking direction into account.
00475 
00476     // Comment out this result since it doesn't refelct the results of test.
00477     //    cout << endl << "Total Errors found: " << errors << endl;
00478 }
Generated on Tue Sep 6 17:52:01 2011 for libStatGen Software by  doxygen 1.6.3