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

Go to the SVN repository for this file.

1 /* $Id: agp_object_loader.cpp 45451 2020-08-05 19:09:49Z asztalos $
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 * Authors: Roman Katargin
27 */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <corelib/ncbifile.hpp>
33 
34 #include <util/icanceled.hpp>
35 
37 
41 
44 
45 #include <gui/objutils/label.hpp>
46 
47 
50 
51 CAgpObjectLoader::CAgpObjectLoader(const CAgpLoadParams& params, const vector<wxString>& filenames)
52  : m_Params(params), m_FileNames(filenames)
53 {
54 }
55 
57 {
58  return m_Objects;
59 }
60 
62 {
63  return "Loading AGP Files";
64 }
65 
67 {
68  return true;
69 }
70 
72 {
73  wxString fasta_file = m_Params.GetFastaFile();
74 
76  CRef<CScope> scope(new CScope(*obj_mgr));
77  scope->AddDefaults();
78 
79  CRef<CSeq_entry> fasta_seqs;
80  if ( !fasta_file.empty() ) {
81  CRef<CErrorContainer> errCont(new CErrorContainer(100));
82  try {
83  CCompressedFile file(fasta_file);
84  CRef<ILineReader> line_reader(ILineReader::New(file.GetIstream()));
86  reader.SetCanceler(&canceled);
87  fasta_seqs = reader.ReadSet(kMax_Int, errCont.GetPointer());
88  x_UpdateHTMLResults(fasta_file, errCont);
89  }
90  catch (const CException& e) {
91  x_UpdateHTMLResults(fasta_file, errCont, e.GetMsg());
92  }
93  catch (const exception& e) {
94  x_UpdateHTMLResults(fasta_file, errCont, e.what());
95  }
96  }
97 
99  parse_flags |= m_Params.GetSetGapInfo() ? CAgpToSeqEntry::fSetSeqGap : 0;
100 
101 
102  ITERATE(vector<wxString>, it, m_FileNames) {
103  if (canceled.IsCanceled())
104  return false;
105 
106  const wxString& fn = *it;
107 
108  try {
109  CCompressedFile file(fn);
110 
111  vector<CRef<CSeq_entry> > entries;
112  //--- AgpRead(*istr_p, entries, comp_id_rule, set_gap_info);
113 
114  CAgpToSeqEntry agpToSeqEntry( parse_flags );
115  agpToSeqEntry.ReadStream( file.GetIstream() );
116  // swap is faster than "="
117  entries.swap( agpToSeqEntry.GetResult() );
118  x_UpdateHTMLResults(fn, 0, kEmptyStr, agpToSeqEntry.GetErrorMessage());
119 
120  NON_CONST_ITERATE(vector<CRef<CSeq_entry> >, it2, entries) {
121  CRef<CSeq_entry> &entry = *it2;
122 
123  string label;
124  CLabel::GetLabel(*entry, &label, CLabel::eDefault, scope);
125  m_Objects.push_back(SObject(*entry, label));
126  }
127  }
128  catch (const CException& e) {
129  x_UpdateHTMLResults(fn, 0, e.GetMsg());
130  }
131  catch (const exception& e) {
132  x_UpdateHTMLResults(fn, 0, e.what());
133  }
134  }
135 
136  if (fasta_seqs) {
137  string label;
138  CLabel::GetLabel(*fasta_seqs, &label, CLabel::eDefault, scope);
139  m_Objects.push_back(SObject(*fasta_seqs, label));
140  }
141 
142  return true;
143 }
144 
146 {
147  x_ShowErrorsDlg(wxT("AGP import errors"));
148  return true;
149 }
150 
USING_SCOPE(objects)
bool GetSetGapInfo() const
int GetParseIDs() const
wxString GetFastaFile() const
virtual string GetErrorMessage(const string &filename=NcbiEmptyString)
Return a string with one (or two, depending on error) source line(s) on which the error occured,...
Definition: agp_util.cpp:1194
virtual int ReadStream(CNcbiIstream &is, EFinalize eFinalize=eFinalize_Yes)
Read an AGP file from the given input stream.
Definition: agp_util.cpp:1084
This class is used to turn an AGP file into a vector of Seq-entry's.
@ fSetSeqGap
Found gaps will not be given Seq-data such as Type and Linkage.
@ fForceLocalId
All IDs will be treated as local IDs.
TSeqEntryRefVec & GetResult(void)
This gets the results found, but don't call before finalizing.
CErrorContainer.
Base class for reading FASTA sequences.
Definition: fasta.hpp:80
void SetCanceler(ICanceled *=nullptr)
void x_ShowErrorsDlg(const wxString &title)
void x_UpdateHTMLResults(const wxString &object, objects::ILineErrorListener *errCont, const string &exception="", const string &error_msg="", const wxString &objectName=wxT("File:"))
CScope –.
Definition: scope.hpp:92
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
vector< SObject > TObjects
Operators to edit gaps in sequences.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
virtual bool PreExecute()
CAgpLoadParams m_Params
CAgpObjectLoader(const CAgpLoadParams &params, const vector< wxString > &filenames)
virtual bool Execute(ICanceled &canceled)
virtual string GetDescription() const
virtual TObjects & GetObjects()
vector< wxString > m_FileNames
virtual bool PostExecute()
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
@ eDefault
Definition: label.hpp:73
CRef< CSeq_entry > ReadSet(int max_seqs=kMax_Int, ILineErrorListener *pMessageListener=nullptr)
Read multiple sequences (by default, as many as are available.)
Definition: fasta.cpp:442
static CRef< ILineReader > New(const string &filename)
Return a new ILineReader object corresponding to the given filename, taking "-" (but not "....
Definition: line_reader.cpp:49
@ fParseGaps
Make a delta sequence if gaps found.
Definition: fasta.hpp:91
@ fDisableParseRange
No ranges in seq-ids. Ranges part of seq-id instead.
Definition: fasta.hpp:114
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:504
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
#define kMax_Int
Definition: ncbi_limits.h:184
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
virtual bool IsCanceled(void) const =0
#define kEmptyStr
Definition: ncbistr.hpp:123
static const char label[]
FILE * file
#define wxT(x)
Definition: muParser.cpp:41
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
The Object manager core.
static int filenames
Definition: pcregrep.c:172
static wxAcceleratorEntry entries[3]
Modified on Thu Feb 29 12:22:50 2024 by modify_doxy.py rev. 669887