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

Go to the SVN repository for this file.

1 /* $Id: dump_seqids.cpp 95044 2021-09-29 19:04:12Z whlavina $
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: Cheinan Marks
27  *
28  * File Description:
29  * Print all the seqids in an ASN index.
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbiapp.hpp>
35 #include <corelib/ncbienv.hpp>
36 #include <corelib/ncbiargs.hpp>
37 #include <corelib/ncbifile.hpp>
38 
41 
44 
45 
46 /////////////////////////////////////////////////////////////////////////////
47 // CAsnCacheDumpSeqIdsApplication::
48 
49 
51 {
52 private:
53  virtual void Init(void);
54  virtual int Run(void);
55  virtual void Exit(void);
56 };
57 
58 
59 /////////////////////////////////////////////////////////////////////////////
60 // Init test for all different types of arguments
61 
62 
64 {
65  // Create command-line argument descriptions class
66  unique_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
67 
68  // Specify USAGE context
69  arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
70  "Dump the contents of an ASN cache index.\n"
71  "The output consists of seq-id, version, "
72  "GI and sequnece length.");
73 
74  arg_desc->AddKey("cache", "Database",
75  "Path to ASN.1 cache",
77 
78  arg_desc->AddDefaultKey( "o", "GIOutputFile",
79  "If supplied, the list of seq IDs is written here.",
81  "-");
82 
83  arg_desc->AddFlag("no-timestamp", "Omit timestamp from output");
84 
85  // Setup arg.descriptions for this application
86  SetupArgDescriptions(arg_desc.release());
87 }
88 
89 
90 
92 {
93  // Get arguments
94  const CArgs& args = GetArgs();
95 
96  CAsnCacheStats::TIncludeFlags include_flags = 0;
97  if (! args["no-timestamp"]) {
98  include_flags |= CAsnCacheStats::eIncludeTimestamp;
99  }
100 
101  CStopWatch sw;
102  sw.Start();
103 
104  CDir cache_dir( args["cache"].AsString() );
105  if (! cache_dir.Exists() ) {
106  ERR_POST( Error << cache_dir.GetPath() << " does not exist!" );
107  return 1;
108  } else if ( ! cache_dir.IsDir() ) {
109  ERR_POST( Error << cache_dir.GetPath() << " does not point to a "
110  << "valid cache path!" );
111  return 2;
112  }
113 
114  CAsnCache cache( cache_dir.GetPath() );
115  CAsnCacheStats cache_stats( cache, include_flags );
116 
117  cache_stats.DumpSeqIds( args["o"].AsOutputFile() );
118 
119  return 0;
120 }
121 
122 
123 /////////////////////////////////////////////////////////////////////////////
124 // Cleanup
125 
126 
128 {
129  SetDiagStream(0);
130 }
131 
132 
133 /////////////////////////////////////////////////////////////////////////////
134 // MAIN
135 
136 
137 int main(int argc, const char* argv[])
138 {
139  // Execute main application function
140  return CAsnCacheDumpSeqIdsApplication().AppMain(argc, argv);
141 }
Contains the class definiton for CAsnCache, the main client class for accessing the ASN cache data.
CArgDescriptions –.
Definition: ncbiargs.hpp:541
CArgs –.
Definition: ncbiargs.hpp:379
virtual void Init(void)
Initialize the application.
Definition: dump_seqids.cpp:63
virtual void Exit(void)
Cleanup on application exit.
virtual int Run(void)
Run the application.
Definition: dump_seqids.cpp:91
void DumpSeqIds(CNcbiOstream &stream) const
CAsnCache is used by clients to access the ASN cache data.
Definition: asn_cache.hpp:61
CDir –.
Definition: ncbifile.hpp:1696
CStopWatch –.
Definition: ncbitime.hpp:1937
USING_SCOPE(objects)
int main(int argc, const char *argv[])
USING_NCBI_SCOPE
Definition: dump_seqids.cpp:42
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
Definition: ncbiapp.cpp:305
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:832
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
Definition: ncbiapp.cpp:1208
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
@ eInputFile
Name of file (must exist and be readable)
Definition: ncbiargs.hpp:595
@ eOutputFile
Name of file (must be writable)
Definition: ncbiargs.hpp:596
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
void SetDiagStream(CNcbiOstream *os, bool quick_flush=true, FDiagCleanup cleanup=0, void *cleanup_data=0, const string &stream_name="")
Set diagnostic stream.
Definition: ncbidiag.cpp:8086
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
virtual bool Exists(void) const
Check if directory "dirname" exists.
Definition: ncbifile.hpp:4066
bool IsDir(EFollowLinks follow=eFollowLinks) const
Check whether a directory entry is a directory.
Definition: ncbifile.hpp:3947
const string & GetPath(void) const
Get entry path.
Definition: ncbifile.hpp:3911
void Start(void)
Start the timer.
Definition: ncbitime.hpp:2764
static CStopWatch sw
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines command line argument related classes.
Defines unified interface to application:
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
Modified on Wed Sep 04 15:03:23 2024 by modify_doxy.py rev. 669887