source: trunk/test/fasta.cc @ 3579

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

merge release 0.14 into trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1// $Id: fasta.cc 3579 2017-01-16 03:54:43Z peter $
2//
3// Copyright (C) 2016, 2017 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  suite.out() << "no samtools with 'samtools fasta' support found\n";
50  exit (EXIT_SKIP);
51#endif
52  Fasta fasta("../../data/foo.fasta");
53  if (fasta.present("nonsense")) {
54    suite.err() << "error: Fasta::present nonsense\n";
55    suite.add(false);
56  }
57  std::string chr = "544:991-46/1";
58  if (!fasta.present(chr)) {
59    suite.add(false);
60    suite.err() << "error: " << chr << " not present\n";
61  }
62  if (fasta.name(0) != chr) {
63    suite.add(false);
64    suite.err() << "error: name(0)!=" << chr << ": " << fasta.name(0) << "\n";
65  }
66  if (!suite.add(fasta.nseq() == 800))
67    suite.err() << "error: nseq: " << fasta.nseq() << "\n";
68  if (!suite.add(fasta.sequence_length(chr) == 100))
69    suite.err() << "error: sequence_length: " << fasta.sequence_length(0)
70                << "\n";
71
72  Fasta::Sequence s = fasta.sequence(chr);
73  if (s.size() != fasta.sequence_length(chr))
74    suite.err() << "error: Sequence::size " << s.size() << "\n";
75
76  int offset = 50;
77  int len = 25;
78  Fasta::Sequence s2 = fasta.sequence(chr, offset, offset+len);
79  if (s.size() != len)
80    suite.err() << "error: Sequence::size " << s2.size() << "\n";
81
82  if (!std::equal(s2.begin(), s2.end(), s.begin()+offset)) {
83    suite.add(false);
84    suite.err() << std::string(s2.begin(), s2.end()) << "\n";
85    suite.err() << std::string(s.begin()+offset, s.begin()+offset+len) << "\n";
86  }
87
88  Fasta::Sequence rc = reverse_complement(s);
89  if (rc.size() != len)
90    suite.err() << "error: Sequence::size " << rc.size() << " in rc\n";
91 
92}
93#endif
Note: See TracBrowser for help on using the repository browser.