1 /*===========================================================================
2 *
3 * PUBLIC DOMAIN NOTICE
4 * National Center for Biotechnology Information
5 *
6 * This software/database is a "United States Government Work" under the
7 * terms of the United States Copyright Act. It was written as part of
8 * the author's official duties as a United States Government employee and
9 * thus cannot be copyrighted. This software/database is freely available
10 * to the public for use. The National Library of Medicine and the U.S.
11 * Government have not placed any restriction on its use or reproduction.
12 *
13 * Although all reasonable efforts have been taken to ensure the accuracy
14 * and reliability of the software and data, the NLM and the U.S.
15 * Government do not and cannot warrant the performance or results that
16 * may be obtained by using this software or data. The NLM and the U.S.
17 * Government disclaim all warranties, express or implied, including
18 * warranties of performance, merchantability or fitness for any particular
19 * purpose.
20 *
21 * Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26
27 /**
28 * Unit tests for NGS Pileup
29 */
30
31 #include <ktst/unit_test.hpp>
32
33 #include <sysalloc.h>
34
35 #include <sstream>
36
37 #include "../../tools/ngs-pileup/ngs-pileup.cpp"
38
39 using namespace std;
40 using namespace ncbi::NK;
41
42 TEST_SUITE(NgsPileupTestSuite);
43
44 class NGSPileupFixture
45 {
46 public:
NGSPileupFixture()47 NGSPileupFixture()
48 {
49 ps . output = & m_str;
50 }
51
Run()52 string Run()
53 {
54 NGS_Pileup ( ps ) . Run ();
55 return m_str . str ();
56 }
57
58 ostringstream m_str;
59 NGS_Pileup::Settings ps;
60 };
61
FIXTURE_TEST_CASE(NoInput,NGSPileupFixture)62 FIXTURE_TEST_CASE ( NoInput, NGSPileupFixture )
63 {
64 Run ();
65 REQUIRE_EQ ( string(), m_str . str() );
66 }
67
FIXTURE_TEST_CASE(BadInput,NGSPileupFixture)68 FIXTURE_TEST_CASE ( BadInput, NGSPileupFixture )
69 {
70 ps . AddInput ( "blah" );
71 REQUIRE_THROW ( Run() );
72 REQUIRE_EQ ( string(), m_str . str() );
73 }
74
FIXTURE_TEST_CASE(Basic,NGSPileupFixture)75 FIXTURE_TEST_CASE ( Basic, NGSPileupFixture )
76 {
77 ps . AddInput ( "SRR833251" ); // a small accession with primary and secondary alignments
78 string expectedStart = "gi|169794206|ref|NC_010410.1|\t19376\t1\n"; //TODO: expand when pileup prints out more data
79 REQUIRE_EQ ( expectedStart, Run () . substr ( 0, expectedStart . length () ) );
80 }
81
FIXTURE_TEST_CASE(SingleReference_ByCommonName,NGSPileupFixture)82 FIXTURE_TEST_CASE ( SingleReference_ByCommonName, NGSPileupFixture )
83 {
84 ps . AddInput ( "ERR247027" );
85 ps . AddReference ( "Pf3D7_13" );
86 string expectedStart = "AL844509.2\t1212494\t1"; //TODO: expand when pileup prints out more data
87 string actual = Run ();
88 REQUIRE_EQ ( expectedStart, actual . substr ( 0, expectedStart . length () ) );
89 }
90
FIXTURE_TEST_CASE(SingleReference_ByCanonicalName,NGSPileupFixture)91 FIXTURE_TEST_CASE ( SingleReference_ByCanonicalName, NGSPileupFixture )
92 {
93 ps . AddInput ( "ERR247027" );
94 ps . AddReference ( "AL844509.2" );
95 string expectedStart = "AL844509.2\t1212494\t1"; //TODO: expand when pileup prints out more data
96 REQUIRE_EQ ( expectedStart, Run () . substr ( 0, expectedStart . length () ) );
97 }
98
FIXTURE_TEST_CASE(SingleReference_Slice,NGSPileupFixture)99 FIXTURE_TEST_CASE ( SingleReference_Slice, NGSPileupFixture )
100 {
101 ps . AddInput ( "ERR247027" );
102 ps . AddReferenceSlice ( "AL844509.2", 1212492, 3 );
103 string expected =
104 "AL844509.2\t1212494\t1\n" /* this position is 1-based */
105 "AL844509.2\t1212495\t1\n";
106 //TODO: expand when pileup prints out more data
107 REQUIRE_EQ ( expected, Run () );
108 }
109
110 #if 0
111 FIXTURE_TEST_CASE ( MultipleReferences, NGSPileupFixture )
112 {
113 ps . AddInput ( "SRR1068024" ); // 38 references
114 const string ref1 = "0000000.72b.NC2_17738";
115 const string ref2 = "0000000.72b.NC2_14823"; // this one should come first in the output
116 ps . AddReference ( ref1 );
117 ps . AddReference ( ref2 );
118 string expectedStart = ref2 + "\t1\t1";
119
120 string res = Run();
121
122 REQUIRE_EQ ( expectedStart, res . substr ( 0, expectedStart . length () ) );
123 REQUIRE_NE ( string :: npos, res. find ( ref2 ) );
124 }
125
126 FIXTURE_TEST_CASE ( MultipleInputs, NGSPileupFixture )
127 { // ERR334733 ERR334777 align against the same reference, ERR334733's position comes first so it has to
128 // be the first on the output regardless of order of accessions on the command line
129 ps . AddInput ( "ERR334777" );
130 ps . AddInput ( "ERR334733" );
131 string expectedStart = "FN433596.1\t805952\t1"; // comes from ERR334733
132 string res = Run();
133 REQUIRE_EQ ( expectedStart, res . substr ( 0, expectedStart . length () ) );
134 REQUIRE_NE ( string :: npos, res. find ( "2424446" ) ); // one of the positions from ERR334777
135 }
136
137 FIXTURE_TEST_CASE ( AllReferencses, NGSPileupFixture )
138 {
139 ps . AddInput ( "SRR341578" );
140 string expectedStart = "NC_011748.1\t1\t1";
141 REQUIRE_EQ ( expectedStart, Run () . substr ( 0, expectedStart . length () ) );
142 }
143
144 //TODO: multiple input overlapping
145 #endif
146 //////////////////////////////////////////// Main
147 extern "C"
148 {
149
150 #include <kapp/args.h>
151 #include <kfg/config.h>
152
KAppVersion(void)153 ver_t CC KAppVersion ( void )
154 {
155 return 0x1000000;
156 }
UsageSummary(const char * progname)157 rc_t CC UsageSummary (const char * progname)
158 {
159 return 0;
160 }
161
Usage(const Args * args)162 rc_t CC Usage ( const Args * args )
163 {
164 return 0;
165 }
166
167 const char UsageDefaultName[] = "test-ngs-pileup";
168
KMain(int argc,char * argv[])169 rc_t CC KMain ( int argc, char *argv [] )
170 {
171 KConfigDisableUserSettings();
172 rc_t rc=NgsPileupTestSuite(argc, argv);
173 return rc;
174 }
175
176 }
177
178