libStatGen Software 1
TrimSequence.cpp
1/*
2 * Copyright (C) 2010 Regents of the University of Michigan
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "TrimSequence.h"
19
20#include <assert.h>
21#include <iostream>
22#include <stdlib.h>
23#include <string>
24
25int main(int argc, const char **argv)
26{
27 std::string test;
28 std::string::iterator result;
29
30 //
31 // from the left:
32 //
33 test = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
34 result = trimSequence(test, 'A', true);
35 assert(result == test.begin());
36
37 test = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
38 result = trimSequence(test, '~', true);
39 assert(result == test.end());
40
41 test = "AAAAABCDEFGHIJKLMNOPQRSTUVWXYZ";
42 result = trimSequence(test, 'B', true);
43 assert(result == (test.begin() + 5));
44
45 test = "AAAAAAAABCDEFGHIJKLMNOPQRSTUVWXYZ";
46 result = trimSequence(test, 'B', true);
47 assert(result == (test.begin() + 8));
48
49 test = "AAAAAAAABCDEFGHIJKLMNOPQRSTUVWXYZ";
50 result = trimSequence(test, 'F', true);
51 assert(result == (test.begin() + 12));
52
53 test = "AAAAAAAABCDEFGHIJKLMNOPQRSTUVWXYZ";
54 result = trimSequence(test, '@', true);
55 assert(result == (test.begin() + 0));
56
57 test = "AAAAAAAABCDEFGHIJKLMNOPQRSTUVWXYZ";
58 result = trimSequence(test, '@', true);
59 assert(result == (test.begin() + 0));
60
61 test = "AAAFAAAABCDEFGHIJKLMNOPQRSTUVWXYZ";
62 result = trimSequence(test, 'F', true);
63 assert(result == (test.begin() + 12));
64
65 // trim left 12 bases, and untrimmed bases are 'FG' (turn bug into this test cass)
66 test = "AAAFAAAABCDEFG";
67 result = trimSequence(test, 'F', true);
68 assert(result == (test.begin() + 12));
69
70 //
71 // from the right:
72 //
73 test = "ZYXWVUTSRQPONMLKJIHGFEDCBA";
74 result = trimSequence(test, 'A', false);
75 assert(result == test.end());
76
77 test = "ZYXWVUTSRQPONMLKJIHGFEDCBA";
78 result = trimSequence(test, '~', false);
79 assert(result == test.begin());
80
81 test = "ZYXWVUTSRQPONMLKJIHGFEDCBAAAAA";
82 result = trimSequence(test, 'B', false);
83 assert(result == (test.end() - 5));
84
85 test = "ZYXWVUTSRQPONMLKJIHGFEDCBAAAAAAA";
86 result = trimSequence(test, 'B', false);
87 assert(result == (test.end() - 7));
88
89 test = "ZYXWVUTSRQPONMLKJIHGFEDCBAAAAAAAA";
90 result = trimSequence(test, 'F', false);
91 assert(result == (test.end() - 12));
92
93 test = "ZYXWVUTSRQPONMLKJIHGFEDCBAAAAAAAA";
94 result = trimSequence(test, '@', false);
95 assert(result == (test.end() + 0));
96
97 test = "ZYXWVUTSRQPONMLKJIHGFEDCBAAAAFAAA";
98 result = trimSequence(test, 'F', false);
99 assert(result == (test.end() - 12));
100
101 test = "#################################";
102 result = trimSequence(test, 'F', false);
103 assert(result == (test.begin()));
104
105#if 0
106 // TODO: add explanation why this test case should trim 5 right most bases?
107 test = ">BC@>28B==>=><?@=?>@8(>0309261/;6=@";
108 result = trimSequence(test, '0', false);
109 assert(result == (test.end())-5);
110#endif
111
112 exit(0);
113}