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

Go to the SVN repository for this file.

1 /* $Id: vcf_object_loader.cpp 38296 2017-04-24 16:17:37Z 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: Josh Cherry, Roman Katargin
27 */
28 
29 
30 #include <ncbi_pch.hpp>
31 
33 
34 #include <util/line_reader.hpp>
35 #include <util/icanceled.hpp>
36 
39 
42 
45 
46 #include <wx/filename.h>
47 
50 
51 CVcfObjectLoader::CVcfObjectLoader(const CBedLoadParams& 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 VCF (Variant Call Format) Files";
64 }
65 
67 {
68  return true;
69 }
70 
72 {
75  }
76 
77  ITERATE(vector<wxString>, it, m_FileNames) {
78  if (canceled.IsCanceled())
79  return false;
80 
81  const wxString& fn = *it;
82  CRef<CErrorContainer> errCont;
83 
84  try {
86  CStreamLineReader lineReader(file.GetIstream());
87 
88  CVcfReader reader;
89  reader.SetCanceler(&canceled);
90  errCont.Reset(new CErrorContainer((size_t)m_Params.GetNumErrors()));
91  CRef<CSeq_annot> annot(reader.ReadSeqAnnot(lineReader, errCont));
92  x_UpdateHTMLResults(fn, errCont);
93  errCont.Reset();
94 
95  if (!annot) continue;
96 
97  string label;
98 
99  bool has_name = false;
100  if (annot->CanGetDesc()) {
101  const CAnnot_descr& desc = annot->GetDesc();
102  if (desc.CanGet()) {
103  const CAnnot_descr::Tdata& data = desc.Get();
104  CSeq_annot::TDesc::Tdata::const_iterator desc_iter = data.begin();
105  for ( ; desc_iter != data.end(); ++desc_iter) {
106  if ((*desc_iter)->IsTitle() ) {
107  label = (*desc_iter)->GetTitle();
108  break;
109  }
110  if ((*desc_iter)->IsName() ) {
111  label = (*desc_iter)->GetName();
112  has_name = true;
113  }
114  }
115  }
116  }
117 
118  if (!has_name) {
119  wxFileName wx_fn(fn);
120  string fileName = ToStdString(wx_fn.GetFullName());
121  if (label.empty())
122  label = fileName;
123  annot->SetNameDesc(fileName);
124  }
125 
126  m_Objects.push_back(SObject(*annot, label));
127 
128  x_UpdateMap(*annot);
129  }
130  catch (const CException& e) {
131  x_UpdateHTMLResults(fn, errCont, e.GetMsg());
132  }
133  catch (const exception& e) {
134  x_UpdateHTMLResults(fn, errCont, e.what());
135  }
136  }
137 
138  return true;
139 }
140 
142 {
143  x_ShowErrorsDlg(wxT("VCF import errors"));
144  return x_ShowMappingDlg(m_Objects);
145 }
146 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CAnnot_descr –.
Definition: Annot_descr.hpp:66
CMapAssemblyParams GetMapAssembly() const
int GetNumErrors() const
CErrorContainer.
string GetAssemblyAcc() const
void x_CreateMapper(const string &assembly)
void x_UpdateMap(objects::CSeq_annot &annot)
bool x_ShowMappingDlg(IObjectLoader::TObjects &objects)
void SetCanceler(ICanceled *=nullptr)
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:"))
void SetNameDesc(const string &name)
Definition: Seq_annot.cpp:66
Simple implementation of ILineReader for i(o)streams.
CRef< CSeq_annot > ReadSeqAnnot(ILineReader &, ILineErrorListener *=nullptr) override
Read an object from a given line reader, render it as a single Seq-annot, if possible.
Definition: vcf_reader.cpp:181
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
vector< SObject > TObjects
char data[12]
Definition: iconv.c:80
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
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 string GetDescription() const
virtual TObjects & GetObjects()
virtual bool PreExecute()
virtual bool Execute(ICanceled &canceled)
virtual bool PostExecute()
CBedLoadParams m_Params
vector< wxString > m_FileNames
CVcfObjectLoader(const CBedLoadParams &params, const vector< wxString > &filenames)
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
static const char label[]
const Tdata & Get(void) const
Get the member data.
const TDesc & GetDesc(void) const
Get the Desc member data.
Definition: Seq_annot_.hpp:852
bool CanGetDesc(void) const
Check if it is safe to call GetDesc method.
Definition: Seq_annot_.hpp:846
bool CanGet(void) const
Check if it is safe to call Get method.
list< CRef< CAnnotdesc > > Tdata
FILE * file
Lightweight interface for getting lines of data with minimal memory copying.
#define wxT(x)
Definition: muParser.cpp:41
static int filenames
Definition: pcregrep.c:172
USING_SCOPE(objects)
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Thu Apr 25 08:20:52 2024 by modify_doxy.py rev. 669887