89 arg_desc->SetUsageContext(
91 "Extract Genbank source qualifiers",
96 arg_desc->AddOptionalKey(
"i",
"IDsFile",
97 "IDs file name. Defaults to stdin",
100 arg_desc->AddOptionalKey(
"seq-entry",
"SeqEntryFile",
101 "File containing Seq-entry in ASN.1 format",
104 arg_desc->SetDependency(
"seq-entry",
111 arg_desc->AddOptionalKey(
"f",
"FieldsList",
114 arg_desc->SetDependency(
"f",
118 arg_desc->SetDependency(
"f",
122 arg_desc->AddOptionalKey(
"F",
"FieldsFile",
125 arg_desc->SetDependency(
"F",
129 arg_desc->AddFlag(
"all-fields",
"List all fields");
133 arg_desc->AddFlag(
"list-supported-fields",
134 "List in alphabetical order the fields that srcchk can display; ignore other arguments");
139 arg_desc->AddOptionalKey(
"o",
"OutputFile",
140 "Output file name. Defaults to stdout",
145 arg_desc->AddDefaultKey(
"delim",
"Delimiter",
159 if (args[
"list-supported-fields"]) {
161 sort(begin(sortedFields), end(sortedFields));
162 for (
const auto& field : sortedFields) {
163 cout << field <<
"\n";
181 for (
size_t pos=0; pos < errorCount; ++pos) {
184 return (errorCount ? 1 : 0);
194 string error_msg = args[
"o"] ?
195 "Unable to open output file \"" + args[
"o"].AsString() +
"\"." :
196 "Unable to write to stdout.";
203 const streamsize maxLineSize(100);
204 char line[maxLineSize];
213 pIfstr = args[
"i"] ? &args[
"i"].AsInputFile() : &cin;
215 catch(
const std::exception&) {
216 string error_msg = args[
"i"] ?
217 "Unable to open ID file \"" + args[
"i"].AsString() +
"\"." :
218 "Unable to read IDs from stdin.";
224 vector<pair<string, CBioseq_Handle> > vecIdBsh;
225 while (!pIfstr->eof()) {
226 pIfstr->getline(line, maxLineSize);
227 if (line[0] == 0 || line[0] ==
'#') {
235 vecIdBsh.push_back(make_pair(
id,bsh));
241 string err_msg =
"Malformatted ID \"" +
id +
"\"";
259 if (!args[
"seq-entry"]) {
264 string error_msg = args[
"o"] ?
265 "Unable to open output file \"" + args[
"o"].AsString() +
"\"." :
266 "Unable to write to stdout.";
278 const char* infile = args[
"seq-entry"].AsString().c_str();
282 string msg(
"Unable to open Seq-entry file \"" + args[
"seq-entry"].AsString() +
"\".");
294 string msg(
"Unable to process Seq-entry file \"" + args[
"seq-entry"].AsString() +
"\".");
311 if (args[
"all-fields"]) {
317 string fieldString = args[
"f"].AsString();
322 const streamsize maxLineSize(100);
323 char line[maxLineSize];
326 pIfstr = &args[
"F"].AsInputFile();
328 catch (
const std::exception& e) {
331 "Unable to open fields file \"" + args[
"F"].AsString() +
"\".");
336 while (!pIfstr->eof()) {
337 pIfstr->getline(line, maxLineSize);
338 if (line[0] == 0 || line[0] ==
'#') {
346 if (field ==
"id" || field ==
"accession") {
350 fields.push_back(field);
370 return &args[
"o"].AsOutputFile();
372 catch(
const std::exception&) {
394 <<
error.SeverityStr().c_str()
396 <<
error.ErrorMessage().c_str()
404 int main(
int argc,
const char** argv)
static void SetupObjectManager(const CArgs &args, objects::CObjectManager &obj_mgr, TLoaders loaders=fDefault)
Set up the standard object manager data loaders according to the arguments provided above.
size_t Count() const override
const ILineError & GetError(size_t uPos) const override
bool xTryProcessSeqEntry(const CArgs &)
bool xTryProcessIdFile(const CArgs &)
CSrcWriter * xInitWriter(const CArgs &)
CRef< CSrcWriter > m_pWriter
CRef< CObjectManager > m_pObjMngr
CNcbiOstream * xInitOutputStream(const CArgs &)
void Init()
Initialize the application.
int Run()
Run the application.
CRef< CMessageListenerBase > m_pErrors
bool xGetDesiredFields(const CArgs &, vector< string > &)
void xDumpError(const ILineError &, std::ostream &)
static CSrcError * Create(ncbi::EDiagSev severity, const std::string &)
Used to generate tables showing qualifier-field entries occuring in the BioSources of instances of Bi...
static bool ValidateFields(const FIELDS &fields, ILineErrorListener *=nullptr)
Verify that each string in fields is a valid qualifier name.
static const FIELDS sAllSrcCheckFields
All possible fields processed by srchck application, in their canonical order.
static const FIELDS sDefaultSrcCheckFields
Default fields processed by srcchk application, in their canonical order.
void SetDelimiter(const string &delimiter)
Set the column delimiter for the output table.
virtual bool WriteBioseqHandles(const vector< pair< string, CBioseq_Handle > > &, const FIELDS &, CNcbiOstream &, ILineErrorListener *=nullptr)
Write a table of the specified qualifier-field entries found in the BioSources of a vector of Bioseqs...
virtual bool WriteSeqEntry(const CSeq_entry &, CScope &, CNcbiOstream &, bool=false)
Write a table of all qualifier-field entries occurring in the BioSources for a given Seq-entry,...
std::ofstream out("events_result.xml")
main entry point for tests
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
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.
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
@ eTakeOwnership
An object can take ownership of another.
@ eExcludes
One argument excludes another.
@ eInputFile
Name of file (must exist and be readable)
@ eString
An arbitrary string.
@ eOutputFile
Name of file (must be writable)
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
@ eDiag_Error
Error message.
TErrCode GetErrCode(void) const
Get error code.
@ eSerial_AsnText
ASN.1 text.
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
@ eFormat
Contents not parsable as expected.
pair< TObjectPtr, TTypeInfo > ObjectInfo(C &obj)
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
void Reset(void)
Reset reference object.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
static string PrintableString(const CTempString str, TPrintableMode mode=fNewLine_Quote|fNonAscii_Passthru)
Get a printable version of the specified string.
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
@ fNonAscii_Quote
Octal for all non-ASCII characters.
void CONNECT_Init(const IRWRegistry *reg=0, CRWLock *lock=0, TConnectInitFlags flag=eConnectInit_OwnNothing, FSSLSetup ssl=0)
Init [X]CONNECT library with the specified "reg" and "lock" (ownership for either or both can be deta...
constexpr auto sort(_Init &&init)
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
int main(int argc, const char **argv)