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

Go to the SVN repository for this file.

1 #include <ncbi_pch.hpp>
2 #include <corelib/ncbiapp.hpp>
3 #include <corelib/ncbiargs.hpp>
6 #include <objmgr/scope.hpp>
10 //#include <objtools/readers/hgvs/hgvs_validator.hpp>
13 #include <corelib/ncbiexpt.hpp>
14 
17 
18 
20 {
21 public:
22  enum EErrCode {
24  };
25 
26  virtual const char* GetErrCodeString(void) const;
28 };
29 
30 
32 {
33  switch( GetErrCode() ) {
34  case eParseError: return "eParseError";
35  default: return CException::GetErrCodeString();
36  }
37 }
38 
39 
41 {
42 public:
43  virtual void Init(void);
44  virtual int Run(void);
45 };
46 
48 {
49  unique_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
50 
51  arg_desc->AddDefaultKey
52  ("i",
53  "input",
54  "Text file containing hgvs expression",
56  "-",
58 
59  arg_desc->AddDefaultKey
60  ("o",
61  "output",
62  "Output file for seqfeat; used in conjunction with -out",
64  "-",
66 
67  arg_desc->AddFlag("return-irep",
68  "Return intermediate representation as output");
69 
70  // Program description
71  string prog_description = "Convert hgvs expression to a Seq-feat\n";
72  arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
73  prog_description, false);
74 
75  SetupArgDescriptions(arg_desc.release());
76 
79  return;
80 }
81 
82 
84 {
85  const CArgs& args = GetArgs();
88  CRef<CScope> scope(new CScope(*obj_mgr));
89  scope->AddDefaults();
90 
91  CNcbiIstream& istr = args["i"].AsInputFile();
92  CNcbiOstream& ostr = args["o"].AsOutputFile();
93 
94  string hgvs_expression;
95  try {
96  istr >> hgvs_expression;
97  } catch (CEofException e) {
98  return 1;
99  }
100 
101  CHgvsParser hgvs_parser;
103  bool success = hgvs_parser.Apply(hgvs_expression, irep);
104 
105  if (!success) {
106  NCBI_THROW(CHgvsVariantException, eParseError, "Failed to parse " + hgvs_expression);
107  }
108 
109  if (args["return-irep"]) {
110  ostr << MSerial_AsnText << *irep;
111  return 0;
112  }
113 
114  CRef<CSeq_feat> seq_feat;
115  auto seq_type = irep->GetSequence_variant().GetSeqtype();
116  if (seq_type == eVariantSeqType_p) {
117  unique_ptr<CHgvsIrepReader> irep_reader(new CHgvsProtIrepReader(*scope));
118  seq_feat = irep_reader->CreateSeqfeat(*irep);
119  } else {
120  unique_ptr<CHgvsIrepReader> irep_reader(new CHgvsNaIrepReader(*scope));
121  seq_feat = irep_reader->CreateSeqfeat(*irep);
122 
123  }
124 
125  bool IsCDS = (seq_type == eVariantSeqType_c);
126 
127  g_ValidateVariationSeqfeat(*seq_feat, scope, IsCDS);
128 
129  ostr << MSerial_AsnText << *seq_feat;
130  return 0;
131 }
132 
133 
134 int main(int argc, const char* argv[])
135 {
136  SetDiagFilter(eDiagFilter_All, "!(1306.12)");
137  return CHgvsToSeqfeatConverter().AppMain(argc, argv);
138 }
CArgDescriptions –.
Definition: ncbiargs.hpp:541
CArgs –.
Definition: ncbiargs.hpp:379
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:366
bool Apply(const string &hgvs_expression, CRef< CVariantExpression > &varient_irep) const
Definition: hgvs_parser.cpp:64
virtual int Run(void)
Run the application.
Definition: hgvsreader.cpp:83
virtual void Init(void)
Initialize the application.
Definition: hgvsreader.cpp:47
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
Definition: hgvsreader.cpp:31
NCBI_EXCEPTION_DEFAULT(CHgvsVariantException, CException)
CScope –.
Definition: scope.hpp:92
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
Definition: ncbiapp.cpp:285
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
Definition: ncbiapp.cpp:799
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
Definition: ncbiapp.cpp:1175
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
@ fPreOpen
Open file right away; for eInputFile, eOutputFile, eIOFile.
Definition: ncbiargs.hpp:618
@ eInputFile
Name of file (must exist and be readable)
Definition: ncbiargs.hpp:595
@ eOutputFile
Name of file (must be writable)
Definition: ncbiargs.hpp:596
void SetDiagFilter(EDiagFilter what, const char *filter_str)
Set diagnostic filter.
Definition: ncbidiag.cpp:7670
EDiagSev SetDiagPostLevel(EDiagSev post_sev=eDiag_Error)
Set the threshold severity for posting the messages.
Definition: ncbidiag.cpp:6129
@ eDiag_Info
Informational message.
Definition: ncbidiag.hpp:651
@ eDiag_Fatal
Fatal error – guarantees exit(or abort)
Definition: ncbidiag.hpp:655
@ eDiagFilter_All
for all non-FATAL
Definition: ncbidiag.hpp:2531
TErrCode GetErrCode(void) const
Get error code.
Definition: ncbiexpt.cpp:453
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
EErrCode
Error types that an application can generate.
Definition: ncbiexpt.hpp:884
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
Definition: ncbiexpt.cpp:444
static void SetStackTraceLevel(EDiagSev level)
Set severity level for saving and printing stack trace.
Definition: ncbiexpt.cpp:129
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
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
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
@ eVariantSeqType_p
protein
@ eVariantSeqType_c
coding
USING_SCOPE(objects)
int main(int argc, const char *argv[])
Definition: hgvsreader.cpp:134
USING_NCBI_SCOPE
Definition: hgvsreader.cpp:15
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines command line argument related classes.
Defines NCBI C++ exception handling.
The Object manager core.
void g_ValidateVariationSeqfeat(const CSeq_feat &feat, CScope *scope, bool IsCDS=false)
Modified on Tue Nov 28 02:23:44 2023 by modify_doxy.py rev. 669887