NCBI C++ ToolKit
cobalt_test_util.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: cobalt_test_util.cpp 63632 2014-07-16 14:22:12Z boratyng $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Greg Boratyn
27 *
28 * File Description:
29 * Utilities for Cobalt unit tests
30 *
31 *
32 * ===========================================================================
33 */
34 
35 #include <ncbi_pch.hpp>
37 #include <objmgr/seq_vector.hpp>
41 #include <serial/iterator.hpp>
42 #include <algo/cobalt/cobalt.hpp>
43 
44 #ifndef SKIP_DOXYGEN_PROCESSING
45 
47 USING_SCOPE(cobalt);
49 
50 
51 int ReadFastaQueries(const string& filename,
52  vector< CRef<objects::CSeq_loc> >& seqs,
53  CRef<objects::CScope>& scope,
54  bool parse_deflines /* = false*/,
55  objects::CSeqIdGenerator* id_generator /* = NULL*/)
56 {
57  seqs.clear();
58  CNcbiIfstream instream(filename.c_str());
59  if (!instream) {
60  return -1;
61  }
62 
63  CStreamLineReader line_reader(instream);
66 
67  if (!parse_deflines) {
69  }
70 
71  CFastaReader fasta_reader(line_reader, flags);
72  fasta_reader.IgnoreProblem(
74 
75  if (id_generator) {
76  fasta_reader.SetIDGenerator(*id_generator);
77  }
78 
79  scope->AddDefaults();
80  while (!line_reader.AtEOF()) {
81 
82  CRef<CSeq_entry> entry = fasta_reader.ReadOneSeq();
83 
84  if (entry == 0) {
85  return -1;
86  }
87  scope->AddTopLevelSeqEntry(*entry);
89  CRef<CSeq_loc> seqloc(new CSeq_loc());
90  seqloc->SetWhole().Assign(*itr->GetId().front());
91  seqs.push_back(seqloc);
92  }
93 
94  return 0;
95 }
96 
97 
98 
99 int ReadMsa(const string& filename, CRef<CSeq_align>& align,
100  CRef<CScope> scope, bool parse_deflines /* = false*/,
101  objects::CSeqIdGenerator* id_generator /* = NULL*/)
102 {
103  if (scope.Empty()) {
104  return -1;
105  }
106 
107  CNcbiIfstream instream(filename.c_str());
108  if (!instream) {
109  return -1;
110  }
111  CStreamLineReader line_reader(instream);
112 
115 
116  if (!parse_deflines) {
118  }
119 
120  CFastaReader fasta_reader(line_reader, flags);
121  fasta_reader.IgnoreProblem(
123 
124  if (id_generator) {
125  fasta_reader.SetIDGenerator(*id_generator);
126  }
127 
128  CRef<CSeq_entry> entry = fasta_reader.ReadAlignedSet(-1);
129  if (entry.Empty()) {
130  return -1;
131  }
132  scope->AddTopLevelSeqEntry(*entry);
133 
134  // notify of a problem if the whole file was not read
135  if (!line_reader.AtEOF()) {
136  return -1;
137  }
138 
139  align = entry->GetAnnot().front()->GetData().GetAlign().front();
140 
141  return 0;
142 }
143 
144 
145 #endif /* SKIP_DOXYGEN_PROCESSING */
Data loader implementation that uses the blast databases.
Base class for reading FASTA sequences.
Definition: fasta.hpp:80
const TAnnot & GetAnnot(void) const
Definition: Seq_entry.cpp:179
Simple implementation of ILineReader for i(o)streams.
Template class for iteration on objects of class C (non-medifiable version)
Definition: iterator.hpp:767
@ eProblem_ModifierFoundButNoneExpected
Definition: line_error.hpp:80
Interface for CMultiAligner.
USING_SCOPE(cobalt)
int ReadFastaQueries(const string &filename, vector< CRef< objects::CSeq_loc > > &seqs, CRef< objects::CScope > &scope, bool parse_deflines, objects::CSeqIdGenerator *id_generator)
int ReadMsa(const string &filename, CRef< CSeq_align > &align, CRef< CScope > scope, bool parse_deflines, objects::CSeqIdGenerator *id_generator)
USING_NCBI_SCOPE
static uch flags
Operators to edit gaps in sequences.
virtual CRef< CSeq_entry > ReadOneSeq(ILineErrorListener *pMessageListener=nullptr)
Read a single effective sequence, which may turn out to be a segmented set.
Definition: fasta.cpp:312
CSeqIdGenerator & SetIDGenerator(void)
Definition: fasta.hpp:174
long TFlags
binary OR of EFlags
Definition: fasta.hpp:117
CRef< CSeq_entry > ReadAlignedSet(int reference_row, ILineErrorListener *pMessageListener=nullptr)
Read as many sequences as are available, and interpret them as an alignment, with hyphens marking rel...
Definition: fasta.cpp:1683
bool AtEOF(void) const
Indicates (negatively) whether there is any more input.
void IgnoreProblem(ILineError::EProblem problem)
Definition: fasta.cpp:2221
@ fNoParseID
Generate an ID (whole defline -> title)
Definition: fasta.hpp:90
@ fForceType
Force specified type regardless of accession.
Definition: fasta.hpp:89
@ fValidate
Check (alphabetic) residue validity.
Definition: fasta.hpp:100
@ fAssumeProt
Assume prots unless accns indicate otherwise.
Definition: fasta.hpp:88
void SetWhole(TWhole &v)
Definition: Seq_loc.hpp:982
CConstBeginInfo ConstBegin(const C &obj)
Get starting point of non-modifiable object hierarchy.
Definition: iterator.hpp:1012
CSeq_entry_Handle AddTopLevelSeqEntry(CSeq_entry &top_entry, TPriority pri=kPriority_Default, EExist action=eExist_Default)
Add seq_entry, default priority is higher than for defaults or loaders Add object to the score with p...
Definition: scope.cpp:522
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
Definition: ncbiobj.hpp:719
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
The Object manager core.
Modified on Fri Sep 20 14:58:08 2024 by modify_doxy.py rev. 669887