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

Go to the SVN repository for this file.

1 /* $Id: ace2asn.cpp 91815 2020-12-14 17:25:11Z grichenk $
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: Aleksey Grichenko
27  *
28  * File Description:
29  * Tool to convert ACE file to ASN.1 Seq-entry
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistd.hpp>
35 #include <corelib/ncbiapp.hpp>
36 #include <corelib/ncbienv.hpp>
37 #include <corelib/ncbiargs.hpp>
39 
40 #include <serial/serial.hpp>
43 
44 using namespace ncbi;
45 using namespace objects;
46 
47 
48 /////////////////////////////////////////////////////////////////////////////
49 //
50 // Phrap reader application
51 //
52 
53 
55 {
56 public:
57  virtual void Init(void);
58  virtual int Run (void);
59 };
60 
61 
63 {
64  unique_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
65 
66  arg_desc->AddKey("ace", "AceFile", "Source ACE file",
68 
69  arg_desc->AddOptionalKey("asn", "AsnFile",
70  "Output ASN.1 text file",
72  arg_desc->AddOptionalKey("asnb", "AsnBinFile",
73  "Output ASN.1 binary file",
76 
77  arg_desc->AddDefaultKey("no_complement",
78  "fPhrap_NoComplement",
79  "Ignore 'complemented' flags of traces",
81  "f");
82  arg_desc->AddDefaultKey("pack_data",
83  "fPhrap_PackSeqData",
84  "Use best coding to pack sequence data",
86  "t");
87  arg_desc->AddDefaultKey("gaps",
88  "fPhrap_FeatGaps",
89  "Add features with list of gaps",
91  "t");
92  arg_desc->AddDefaultKey("base_segs",
93  "fPhrap_FeatBaseSegs",
94  "Add features with base segments",
96  "t");
97  arg_desc->AddDefaultKey("read_locs",
98  "fPhrap_FeatReadLocs",
99  "Add features with padded read starts",
101  "f");
102  arg_desc->AddDefaultKey("tags",
103  "fPhrap_FeatTags",
104  "Convert CT and RT tags to features",
106  "t");
107  arg_desc->AddDefaultKey("quality",
108  "fPhrap_FeatQuality",
109  "Add quality/alignment features",
111  "t");
112  arg_desc->AddDefaultKey("descr",
113  "fPhrap_Descr",
114  "Add descriptors (DS and WA tags)",
116  "t");
117  arg_desc->AddDefaultKey("fuzz",
118  "fPhrap_PadsToFuzz",
119  "Add padded coordinates using int-fuzz",
121  "f");
122  arg_desc->AddDefaultKey("align", "AlignType",
123  "Alignment type",
124  CArgDescriptions::eString, "optimized");
125  arg_desc->SetConstraint("align",
126  &(*new CArgAllow_Strings,
127  "none", "optimized", "all", "pairs"));
128  arg_desc->AddDefaultKey("ace_version", "AceVersion",
129  "ACE format version",
130  CArgDescriptions::eString, "auto");
131  arg_desc->SetConstraint("ace_version",
132  &(*new CArgAllow_Strings,
133  "auto", "old", "new"));
134 
135  string prog_description = "ACE to ASN.1 converter\n";
136  arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
137  prog_description, false);
138 
139  SetupArgDescriptions(arg_desc.release());
140 }
141 
142 
144 {
145  // Process command line args: get GI to load
146  const CArgs& args = GetArgs();
147 
149 
150 
151  if ( args["no_complement"].AsBoolean() ) {
153  };
154  if ( args["pack_data"].AsBoolean() ) {
156  }
157  if ( args["gaps"].AsBoolean() ) {
159  }
160  if ( args["base_segs"].AsBoolean() ) {
162  }
163  if ( args["read_locs"].AsBoolean() ) {
165  }
166  if ( args["tags"].AsBoolean() ) {
168  }
169  if ( args["quality"].AsBoolean() ) {
171  }
172  if ( args["descr"].AsBoolean() ) {
173  flags |= fPhrap_Descr;
174  }
175  if ( args["fuzz"].AsBoolean() ) {
177  }
178 
179  if (args["align"].AsString() == "optimized") {
181  }
182  else if (args["align"].AsString() == "all") {
184  }
185  else if (args["align"].AsString() == "pairs") {
187  }
188 
189  if (args["ace_version"].AsString() == "new") {
191  }
192  if (args["ace_version"].AsString() == "old") {
194  }
195 
196  NcbiCout << "Reading ACE file..." << NcbiEndl;
197  CRef<CSeq_entry> entry = ReadPhrap(args["ace"].AsInputFile(), flags);
198  bool to_file = args["asn"] || args["asnb"];
199  if ( to_file ) {
200  NcbiCout << "Saving Seq-entry..." << NcbiEndl;
201  if (args["asn"]) {
202  args["asn"].AsOutputFile() << MSerial_AsnText << *entry;
203  }
204  if (args["asnb"]) {
205  args["asnb"].AsOutputFile() << MSerial_AsnBinary << *entry;
206  }
207  }
208  else {
209  NcbiCout << MSerial_AsnText << *entry;
210  }
211  return 0;
212 }
213 
214 
215 
216 /////////////////////////////////////////////////////////////////////////////
217 // MAIN
218 
219 
220 int main(int argc, const char* argv[])
221 {
222  return CAce2AsnApp().AppMain(argc, argv, 0, eDS_Default, 0);
223 }
int main(int argc, const char *argv[])
Definition: ace2asn.cpp:220
virtual void Init(void)
Initialize the application.
Definition: ace2asn.cpp:62
virtual int Run(void)
Run the application.
Definition: ace2asn.cpp:143
CArgAllow_Strings –.
Definition: ncbiargs.hpp:1641
CArgDescriptions –.
Definition: ncbiargs.hpp:541
CArgs –.
Definition: ncbiargs.hpp:379
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
static void Init(void)
Definition: cursor6.c:76
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
#define CNcbiApplication
@ fBinary
Open as binary file; for eInputFile, eOutputFile, eIOFile.
Definition: ncbiargs.hpp:620
@ eInputFile
Name of file (must exist and be readable)
Definition: ncbiargs.hpp:595
@ eBoolean
{'true', 't', 'false', 'f'}, case-insensitive
Definition: ncbiargs.hpp:590
@ eString
An arbitrary string.
Definition: ncbiargs.hpp:589
@ eOutputFile
Name of file (must be writable)
Definition: ncbiargs.hpp:596
@ eDS_Default
Try standard log file (app.name + ".log") in /log/, use stderr on failure.
Definition: ncbidiag.hpp:1790
#define MSerial_AsnBinary
Definition: serialbase.hpp:697
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
#define NcbiEndl
Definition: ncbistre.hpp:548
#define NcbiCout
Definition: ncbistre.hpp:543
void Run(void)
Enter the main loop.
Magic spell ;-) needed for some weird compilers... very empiric.
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
#define GetArgs
Avoid preprocessor name clash with the NCBI C Toolkit.
Definition: ncbiapp_api.hpp:53
Defines command line argument related classes.
Defines unified interface to application:
CRef< CSeq_entry > ReadPhrap(CNcbiIstream &in, TPhrapReaderFlags flags=fPhrap_Default)
Definition: phrap.cpp:2377
int TPhrapReaderFlags
Definition: phrap.hpp:78
@ fPhrap_AlignAll
global all-in-one alignment
Definition: phrap.hpp:60
@ fPhrap_FeatBaseSegs
add features with base segments
Definition: phrap.hpp:54
@ fPhrap_AlignPairs
separate alignment for each trace
Definition: phrap.hpp:61
@ fPhrap_NoComplement
ignore "complemented" flags of traces.
Definition: phrap.hpp:48
@ fPhrap_FeatGaps
add features with list of gaps
Definition: phrap.hpp:53
@ fPhrap_NewVersion
force new ACE format
Definition: phrap.hpp:65
@ fPhrap_Descr
add descriptors (DS, WA)
Definition: phrap.hpp:59
@ fPhrap_PadsToFuzz
Add int-fuzz.p-m to indicate padded coordinates offset.
Definition: phrap.hpp:67
@ fPhrap_FeatReadLocs
add padded read starts
Definition: phrap.hpp:55
@ fPhrap_FeatQuality
add quality/alignment features
Definition: phrap.hpp:57
@ fPhrap_AlignOptimized
split global alignment into parts
Definition: phrap.hpp:62
@ fPhrap_OldVersion
force old ACE format
Definition: phrap.hpp:64
@ fPhrap_FeatTags
convert CT and RT tags to features
Definition: phrap.hpp:56
@ fPhrap_PackSeqData
use best coding to pack sequence data
Definition: phrap.hpp:51
Modified on Tue Dec 05 02:10:25 2023 by modify_doxy.py rev. 669887