50 virtual void Init(
void);
51 virtual int Run(
void);
52 virtual void Exit(
void);
60 void x_ReadVCFBlob(
const string& fname, vector<char>& vcf_blob);
66 arg_desc->SetUsageContext(
GetArguments().GetProgramBasename(),
"Demo application to read VCF files");
74 arg_desc->AddFlag(
"sv_cols",
"Output only the first five columns from the data section of the input file");
80 arg_desc->AddFlag(
"deserialize_and_compare",
"Deserialize data and compare it with the existing variant data");
82 arg_desc->AddOptionalKey(
"range",
"GenomicRange",
"Specify the genomic range for which to extract the data",
CArgDescriptions::eString);
104 cout <<
"Starting to read file: " << fname << endl;
109 bool has_errors =
false;
110 bool read_data =
false;
113 read_data = reader.
ReadData(
file.GetIstream(
false),
nullptr, err_cont, progress);
117 cout <<
"Loading VCF file " << fname <<
" failed: " << e.
GetMsg();
120 catch (
const exception& e) {
121 cout <<
"Loading VCF file " << fname <<
" failed: " << e.
what();
128 cout <<
"VCF file was successfully loaded into memory" << endl;
131 for (
const auto& it : chr_names) {
133 cout << it <<
"\t" << var->Count() <<
" variants\n";
138 if (args[
"serial"]) {
139 const string& serial_fname = args[
"serial"].AsString();
140 auto start = chrono::steady_clock::now();
141 for (
const auto& it : chr_names) {
143 var->WriteSerializedData(it +
"_" + serial_fname);
145 auto diff = chrono::steady_clock::now() - start;
146 cout <<
"Serialization of all data took: " <<
147 chrono::duration_cast<chrono::milliseconds>(diff).count() <<
" ms" << endl;
149 if (args[
"deserialize_and_compare"]) {
150 for (
const auto& it : chr_names) {
154 if (*orig_var == *new_variant) {
155 cout << it <<
"\t" <<
"are the same\n";
158 cout << it <<
"\t" <<
"are not the same\n";
167 for (
const auto& it : chr_names) {
169 string out_fname = it +
"_" + args[
"o"].AsString();
171 var->List(
out, args[
"sv_cols"]);
173 cout <<
"Finished listing columns" << endl;
176 cout <<
"Listing data columns has failed: " << e.
GetMsg() << endl;
183 for (
const auto& it : chr_names) {
185 string out_fname = it +
"_" + args[
"index"].AsString();
187 var->ListPositionVectors(
out);
189 cout <<
"Finished listing index vectors " << endl;
192 cout <<
"Listing index vectors has failed: " << e.
GetMsg() << endl;
202 cout <<
text << endl;
207 bool has_errors = (errCont && errCont->Count() > 0);
209 for (
size_t i = 0;
i < errCont->Count(); ++
i) {
210 const auto& lerror = errCont->GetError(
i);
211 cerr <<
"Line " << lerror.Line() <<
". " << lerror.Message() << endl;
224 if (!args[
"range"]) {
228 cout <<
"Number of variants read: " << new_variant->Count() << endl;
231 cout <<
"Failed to load data from " << fname <<
": " << e.
GetMsg() << endl;
246 vector<char> vcf_blob;
252 cout <<
"There are " << variants.
Count(
range) <<
" variants in the specified range";
264 if (range_str.empty())
267 vector<string> positions;
269 if (positions.size() != 2) {
285 cout <<
"Parsed: " << from <<
" and " << to << endl;
287 cout <<
"Range: " <<
range.GetFrom() <<
" and " <<
range.GetTo() << endl;
298 cerr <<
"Cannot open " + fname +
"\nas: " + e.
GetMsg() << endl;
303 char*
buf = vcf_blob.data();
318 else if (args[
"iserial"]) {
354 cout <<
"Press any key to end the demo app" << endl;
bool x_LoadVCFFile(const string &fname)
void x_ReadVCFBlob(const string &fname, vector< char > &vcf_blob)
virtual void Exit(void)
Cleanup on application exit.
bool x_LoadSerializedData(const string &fname)
virtual int Run(void)
Run the application.
TSeqRange x_ParseRange(const string &range_str)
virtual void Init(void)
Initialize the application.
bool x_ListErrors(objects::IMessageListener *errCont)
void x_UpdateProgress(const string &text)
Class responsible to read VCF files.
vector< string > GetChromosomeNames() const
Returns a vector, holding the chrs/contigs identifiers, read from the file.
function< void(const string &)> TReportProgress
CRef< CVCFVariantList > GetVariantsForChr(const string &chr_name) const
Retrieves the variants list for a given chr/contig.
bool ReadData(CNcbiIstream &in, ICanceled *canceled=nullptr, objects::ILineErrorListener *listener=nullptr, TReportProgress prog_func=TReportProgress(), TOnVCFVariantListReady on_variants_list_ready=TOnVCFVariantListReady())
Reads only the data section of the file.
Class for support low level input/output for files.
void List(CNcbiOstream &out) const
static const vector< string > & s_GetAllColNames()
contains sm_INFO, sm_SAMPLES
int NcbiSys_main(int argc, ncbi::TXChar *argv[])
std::ofstream out("events_result.xml")
main entry point for tests
unsigned int TSeqPos
Type for sequence locations and lengths.
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.
@ eInputFile
Name of file (must exist and be readable)
@ eString
An arbitrary string.
@ eOutputFile
Name of file (must be writable)
void SetDiagStream(CNcbiOstream *os, bool quick_flush=true, FDiagCleanup cleanup=0, void *cleanup_data=0, const string &stream_name="")
Set diagnostic stream.
const string & GetMsg(void) const
Get message string.
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
void Close(void)
Close file.
void Open(const string &filename, EOpenMode open_mode, EAccessMode access_mode, EShareMode share_mode=eShare)
Open file.
Uint8 GetFileSize(void) const
Get file size.
size_t Read(void *buf, size_t count) const
Read file.
@ eOpen
Open an existing file, or create a new one.
void Reset(void)
Reset reference object.
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
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)
static Uint8 StringToUInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Uint8.
static string UInt8ToString(Uint8 value, TNumToStringFlags flags=0, int base=10)
Convert UInt8 to string.
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
static void text(MDB_val *v)
range(_Ty, _Ty) -> range< _Ty >
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Process information in the NCBI Registry, including working with configuration files.
C++ I/O stream wrappers to compress/decompress data on-the-fly.