3475 |
08 Mar 16 |
peter |
// $Id$ |
3475 |
08 Mar 16 |
peter |
2 |
// |
3999 |
08 Oct 20 |
peter |
// Copyright (C) 2016, 2017, 2020 Peter Johansson |
3475 |
08 Mar 16 |
peter |
4 |
// |
3475 |
08 Mar 16 |
peter |
// This program is free software; you can redistribute it and/or modify |
3475 |
08 Mar 16 |
peter |
// it under the terms of the GNU General Public License as published by |
3475 |
08 Mar 16 |
peter |
// the Free Software Foundation; either version 3 of the License, or |
3475 |
08 Mar 16 |
peter |
// (at your option) any later version. |
3475 |
08 Mar 16 |
peter |
9 |
// |
3475 |
08 Mar 16 |
peter |
// This program is distributed in the hope that it will be useful, but |
3475 |
08 Mar 16 |
peter |
// WITHOUT ANY WARRANTY; without even the implied warranty of |
3475 |
08 Mar 16 |
peter |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3475 |
08 Mar 16 |
peter |
// General Public License for more details. |
3475 |
08 Mar 16 |
peter |
14 |
// |
3475 |
08 Mar 16 |
peter |
// You should have received a copy of the GNU General Public License |
3475 |
08 Mar 16 |
peter |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
3475 |
08 Mar 16 |
peter |
17 |
|
3475 |
08 Mar 16 |
peter |
18 |
#include <config.h> |
3475 |
08 Mar 16 |
peter |
19 |
|
3475 |
08 Mar 16 |
peter |
20 |
#include "Suite.h" |
3475 |
08 Mar 16 |
peter |
21 |
|
3883 |
24 Mar 20 |
peter |
22 |
#ifdef YAT_HAVE_HTSLIB |
3475 |
08 Mar 16 |
peter |
23 |
#include "yat/omic/Fasta.h" |
3475 |
08 Mar 16 |
peter |
24 |
#endif |
3475 |
08 Mar 16 |
peter |
25 |
|
3475 |
08 Mar 16 |
peter |
26 |
#include <algorithm> |
3475 |
08 Mar 16 |
peter |
27 |
#include <string> |
3475 |
08 Mar 16 |
peter |
28 |
|
3475 |
08 Mar 16 |
peter |
29 |
using namespace theplu::yat; |
3475 |
08 Mar 16 |
peter |
30 |
|
3475 |
08 Mar 16 |
peter |
31 |
void test1(test::Suite& suite); |
3475 |
08 Mar 16 |
peter |
32 |
|
3475 |
08 Mar 16 |
peter |
33 |
int main(int argc, char* argv[]) |
3475 |
08 Mar 16 |
peter |
34 |
{ |
3475 |
08 Mar 16 |
peter |
35 |
test::Suite suite(argc, argv, true); |
3883 |
24 Mar 20 |
peter |
36 |
#ifdef YAT_HAVE_HTSLIB |
3475 |
08 Mar 16 |
peter |
37 |
test1(suite); |
3475 |
08 Mar 16 |
peter |
38 |
#endif |
3475 |
08 Mar 16 |
peter |
39 |
return suite.return_value(); |
3475 |
08 Mar 16 |
peter |
40 |
} |
3475 |
08 Mar 16 |
peter |
41 |
|
3883 |
24 Mar 20 |
peter |
42 |
#ifdef YAT_HAVE_HTSLIB |
3475 |
08 Mar 16 |
peter |
43 |
using namespace omic; |
3475 |
08 Mar 16 |
peter |
44 |
|
3475 |
08 Mar 16 |
peter |
45 |
void test1(test::Suite& suite) |
3475 |
08 Mar 16 |
peter |
46 |
{ |
3497 |
25 May 16 |
peter |
// 'samtools fasta' is required to generate input fasta file |
3497 |
25 May 16 |
peter |
48 |
#ifndef HAVE_SAMTOOLS_FASTA_EXECUTABLE |
3579 |
16 Jan 17 |
peter |
49 |
suite.out() << "no samtools with 'samtools fasta' support found\n"; |
3497 |
25 May 16 |
peter |
50 |
exit (EXIT_SKIP); |
3497 |
25 May 16 |
peter |
51 |
#endif |
3475 |
08 Mar 16 |
peter |
52 |
Fasta fasta("../../data/foo.fasta"); |
3475 |
08 Mar 16 |
peter |
53 |
if (fasta.present("nonsense")) { |
3475 |
08 Mar 16 |
peter |
54 |
suite.err() << "error: Fasta::present nonsense\n"; |
3475 |
08 Mar 16 |
peter |
55 |
suite.add(false); |
3475 |
08 Mar 16 |
peter |
56 |
} |
3475 |
08 Mar 16 |
peter |
57 |
std::string chr = "544:991-46/1"; |
3475 |
08 Mar 16 |
peter |
58 |
if (!fasta.present(chr)) { |
3475 |
08 Mar 16 |
peter |
59 |
suite.add(false); |
3475 |
08 Mar 16 |
peter |
60 |
suite.err() << "error: " << chr << " not present\n"; |
3475 |
08 Mar 16 |
peter |
61 |
} |
3475 |
08 Mar 16 |
peter |
62 |
if (fasta.name(0) != chr) { |
3475 |
08 Mar 16 |
peter |
63 |
suite.add(false); |
3475 |
08 Mar 16 |
peter |
64 |
suite.err() << "error: name(0)!=" << chr << ": " << fasta.name(0) << "\n"; |
3475 |
08 Mar 16 |
peter |
65 |
} |
3475 |
08 Mar 16 |
peter |
66 |
if (!suite.add(fasta.nseq() == 800)) |
3475 |
08 Mar 16 |
peter |
67 |
suite.err() << "error: nseq: " << fasta.nseq() << "\n"; |
3475 |
08 Mar 16 |
peter |
68 |
if (!suite.add(fasta.sequence_length(chr) == 100)) |
3475 |
08 Mar 16 |
peter |
69 |
suite.err() << "error: sequence_length: " << fasta.sequence_length(0) |
3475 |
08 Mar 16 |
peter |
70 |
<< "\n"; |
3475 |
08 Mar 16 |
peter |
71 |
|
3475 |
08 Mar 16 |
peter |
72 |
Fasta::Sequence s = fasta.sequence(chr); |
3475 |
08 Mar 16 |
peter |
73 |
if (s.size() != fasta.sequence_length(chr)) |
3475 |
08 Mar 16 |
peter |
74 |
suite.err() << "error: Sequence::size " << s.size() << "\n"; |
3475 |
08 Mar 16 |
peter |
75 |
|
3475 |
08 Mar 16 |
peter |
76 |
int offset = 50; |
3475 |
08 Mar 16 |
peter |
77 |
int len = 25; |
3475 |
08 Mar 16 |
peter |
78 |
Fasta::Sequence s2 = fasta.sequence(chr, offset, offset+len); |
3475 |
08 Mar 16 |
peter |
79 |
if (s.size() != len) |
3475 |
08 Mar 16 |
peter |
80 |
suite.err() << "error: Sequence::size " << s2.size() << "\n"; |
3475 |
08 Mar 16 |
peter |
81 |
|
3475 |
08 Mar 16 |
peter |
82 |
if (!std::equal(s2.begin(), s2.end(), s.begin()+offset)) { |
3475 |
08 Mar 16 |
peter |
83 |
suite.add(false); |
3475 |
08 Mar 16 |
peter |
84 |
suite.err() << std::string(s2.begin(), s2.end()) << "\n"; |
3475 |
08 Mar 16 |
peter |
85 |
suite.err() << std::string(s.begin()+offset, s.begin()+offset+len) << "\n"; |
3475 |
08 Mar 16 |
peter |
86 |
} |
3475 |
08 Mar 16 |
peter |
87 |
|
3475 |
08 Mar 16 |
peter |
88 |
Fasta::Sequence rc = reverse_complement(s); |
3475 |
08 Mar 16 |
peter |
89 |
if (rc.size() != len) |
3475 |
08 Mar 16 |
peter |
90 |
suite.err() << "error: Sequence::size " << rc.size() << " in rc\n"; |
3883 |
24 Mar 20 |
peter |
91 |
|
3475 |
08 Mar 16 |
peter |
92 |
} |
3475 |
08 Mar 16 |
peter |
93 |
#endif |