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

Go to the SVN repository for this file.

1 /* $Id: psl_object_loader.cpp 44439 2019-12-18 19:51:52Z katargir $
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 
40 
42 
45 
46 #include <wx/filename.h>
47 
50 
51 CPslObjectLoader::CPslObjectLoader(const CPslLoadParams& 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 PSL Alignmemnt Files";
64 }
65 
67 {
68  return true;
69 }
70 
72 {
75  }
76 
77  for (const auto& fn : m_FileNames) {
78  if (canceled.IsCanceled())
79  return false;
80 
81  CRef<CErrorContainer> errCont;
82 
83  wxFileName fileName(fn);
84  string annot_name = "File: " + ToStdString(fileName.GetFullName());
85 
86  try {
88  CNcbiIstream& istream = file.GetIstream();
89  CStreamLineReader lineReader(istream);
90 
91  errCont.Reset(new CErrorContainer(1000));
93 
94  for (size_t counter = 1;; ++counter) {
95  if (canceled.IsCanceled())
96  return false;
97 
98  if (lineReader.AtEOF() || !istream.good() || istream.eof())
99  break;
100 
101  auto seq_annot = reader.ReadSeqAnnot(lineReader, errCont);
102  if (!seq_annot)
103  continue;
104 
105  m_Objects.push_back(SObject(*seq_annot, annot_name + " (" + NStr::NumericToString(counter) + ")"));
106 
107  x_UpdateMap(*seq_annot);
108  }
109 
110  x_UpdateHTMLResults(fn, errCont);
111  errCont.Reset();
112  }
113  catch (const CException& e) {
114  x_UpdateHTMLResults(fn, errCont, e.GetMsg());
115  }
116  catch (const exception& e) {
117  x_UpdateHTMLResults(fn, errCont, e.what());
118  }
119  }
120 
121  return true;
122 }
123 
125 {
126  x_ShowErrorsDlg(wxT("PSL Alignments import errors"));
127  return x_ShowMappingDlg(m_Objects);
128 }
129 
CErrorContainer.
string GetAssemblyAcc() const
void x_CreateMapper(const string &assembly)
void x_UpdateMap(objects::CSeq_annot &annot)
bool x_ShowMappingDlg(IObjectLoader::TObjects &objects)
CMapAssemblyParams GetMapAssembly() const
virtual CRef< CSeq_annot > ReadSeqAnnot(CNcbiIstream &istr, ILineErrorListener *pErrors=nullptr)
Read an object from a given input stream, render it as a single Seq-annot.
CRef –.
Definition: ncbiobj.hpp:618
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:"))
Simple implementation of ILineReader for i(o)streams.
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
vector< SObject > TObjects
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 TObjects & GetObjects()
CPslLoadParams m_Params
vector< wxString > m_FileNames
virtual bool PostExecute()
CPslObjectLoader(const CPslLoadParams &params, const vector< wxString > &filenames)
virtual string GetDescription() const
virtual bool Execute(ICanceled &canceled)
virtual bool PreExecute()
bool AtEOF(void) const
Indicates (negatively) whether there is any more input.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
FILE * file
#define wxT(x)
Definition: muParser.cpp:41
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
static int filenames
Definition: pcregrep.c:172
USING_SCOPE(objects)
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Tue May 28 05:54:37 2024 by modify_doxy.py rev. 669887