source: trunk/test/fasta.cc @ 3497

Last change on this file since 3497 was 3497, checked in by Peter, 5 years ago

move tests for htslib and samtools into file 'm4/yat_check_htslib.m4'
and restructure the code into sub-macros (for readability). Again we
accept samtools version 1.2; we test that 'samtools --help' works. As
before, if samtools is not available rule for creation of bam file is
replaced by a dummy rule and some tests are SKIPped. In addition, we
test if subcommand 'samtools fasta' works. If it does not, we do try
to generate a fasta file, and the test using that file (test/fasta) is
SKIPped.

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