1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
/*
* Copyright (C) 2011 Regents of the University of Michigan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <getopt.h>
#include "Generic.h"
#include <stdio.h>
#include "ReferenceSequence.h"
#include "UnitTest.h"
#include <assert.h>
#include <sstream>
class ReferenceSequenceTest : public UnitTest
{
public:
ReferenceSequenceTest(const char *title) : UnitTest(title) {;}
void test1();
void test2();
void test3();
void humanGenomeTest1();
void test() {
test1();
test2();
test3();
// This test is very slow:
// humanGenomeTest1();
}
};
void ReferenceSequenceTest::test1(void)
{
std::string sequence("ACTGACTGACTGACTGACTGACTGACTGACTGACTGACTG");
std::string word;
word="ACTG";
check(m_failures, ++m_testNum, "Test wordMatch with std::string", true,
Sequence::wordMatch(sequence, 4, word));
std::stringstream output;
Sequence::printNearbyWords(output, sequence, 8, word, 4);
std::string expect("\
word 'ACTG' found -4 away from position 8.\n\
word 'ACTG' found 0 away from position 8.\n\
");
check(m_failures, ++m_testNum, "Test printNearbyWords with std::string", expect, output.str());
Sequence::getString(sequence, 4, 4, word);
check(m_failures, ++m_testNum, "Test getString with std::string", "ACTG", word);
Sequence::getHighLightedString(sequence, 0, 12, word, 4, 8);
check(m_failures, ++m_testNum, "Test getHighLightedStribng with std::string", "ACTGactgACTG",word);
#if 0
// busted test - don't know why
output.clear();
output.str(std::string());
// Sequence::printBaseContext(std::cout, sequence, 8, 4);
Sequence::printBaseContext(output, sequence, 8, 4);
expect="\
index: 8\n\
ACTGACTGA\n\
^\n\
";
check(m_failures, ++m_testNum, "Test printBaseContext with std::string", expect, output.str());
#endif
std::string result;
std::string read("ACTGZZZZACTG");
expect = " ^^^^ ";
Sequence::getMismatchHatString(sequence, 4, result, read);
check(m_failures, ++m_testNum, "Test getMismatchHatString with std::string", expect, result);
read="ACTG";
std::string quality("");
size_t location = Sequence::simpleLocalAligner(sequence, 0, read, quality, 12);
check(m_failures, ++m_testNum, "Test simpleLocalAligner with std::string", (size_t) 0, location);
read="ACNG";
int misMatches = Sequence::getMismatchCount(sequence, 0, read);
check(m_failures, ++m_testNum, "Test getMismatchCount with std::string", 1, misMatches);
read="ACNG";
quality="$$$$";
int sumQ = Sequence::getSumQ(sequence, 0, read, quality);
check(m_failures, ++m_testNum, "Test getSumQ with std::string", 3, sumQ);
}
void ReferenceSequenceTest::test2(void)
{
PackedSequenceData sequence;
std::string word;
sequence.push_back('A');
sequence.push_back('C');
sequence.push_back('T');
sequence.push_back('G');
sequence.push_back('A');
sequence.push_back('C');
sequence.push_back('T');
sequence.push_back('G');
sequence.push_back('A');
sequence.push_back('C');
sequence.push_back('T');
sequence.push_back('G');
sequence.push_back('A');
sequence.push_back('C');
sequence.push_back('T');
sequence.push_back('G');
Sequence::getString(sequence, 4, 4, word);
check(m_failures, ++m_testNum, "Test getString with PackedSequenceData", "ACTG", word);
std::cout << "test2 sequence utilization is " << sequence.getUtilization() * 100 << "% - expect around 6.25%" << std::endl;
}
void ReferenceSequenceTest::test3(void)
{
std::vector<PackedSequenceData> chromosomeSequence;
std::vector<std::string> chromosomeNames;
bool result = loadFastaFile("../phiX.fa", chromosomeSequence, chromosomeNames);
if(result) {
std::cout << "../phiX.fa not found - skipping these tests." << std::endl;
return;
}
std::cout << "phiX reference utilization is " << chromosomeSequence[0].getUtilization() * 100 << "% - expect around 96.8%" << std::endl;
check(m_failures, ++m_testNum, "Test loadFastaFile with PackedSequenceData", (size_t) 1, chromosomeNames.size());
check(m_failures, ++m_testNum, "Test loadFastaFile with PackedSequenceData", (size_t) 1, chromosomeSequence.size());
check(m_failures, ++m_testNum, "Test loadFastaFile with PackedSequenceData", "1", chromosomeNames[0]);
std::string word;
Sequence::getString(chromosomeSequence[0], 60, 10, word);
check(m_failures, ++m_testNum, "Test loadFastaFile with PackedSequenceData", "AAATTATCTT", word);
}
void ReferenceSequenceTest::humanGenomeTest1(void)
{
std::vector<PackedSequenceData> chromosomeSequence;
std::vector<std::string> chromosomeNames;
#define HUMAN_GENOME "/data/local/ref/karma.ref/human.g1k.v37.fa"
bool result = loadFastaFile(HUMAN_GENOME, chromosomeSequence, chromosomeNames);
if(result) {
std::cout << HUMAN_GENOME << " not found - skipping these tests." << std::endl;
return;
}
}
int main(int argc, char **argv)
{
ReferenceSequenceTest test("ReferenceSequenceTest");
test.test();
std::cout << test;
exit(test.getFailureCount());
}
|