Skip to content

Commit

Permalink
External control over output
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus D. R. Klarqvist committed Aug 11, 2017
1 parent d83361e commit 38844da
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
14 changes: 10 additions & 4 deletions io/TomahawkOutput/TomahawkOutputReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ TomahawkOutputReader::TomahawkOutputReader() :
filesize(0),
position(0),
size(0),
output_header(true),
writer_output_type(WRITER_TYPE::binary),
writer(nullptr),
contigs(nullptr),
Expand Down Expand Up @@ -45,14 +46,19 @@ bool TomahawkOutputReader::view(const std::string& input){
return(this->__viewFilter()); // Otherwise normal filter function
}

bool TomahawkOutputReader::__viewRegion(void){
void TomahawkOutputReader::__openWriter(void){
if(this->writer_output_type == WRITER_TYPE::natural){
this->writer = new TomahawkOutputWriterNatural(this->contigs, &this->header);
}
else this->writer = new TomahawkOutputWriter(this->contigs, &this->header);

this->writer->open();
this->writer->writeHeader();
if(this->output_header)
this->writer->writeHeader();
}

bool TomahawkOutputReader::__viewRegion(void){
this->__openWriter();

if(this->interval_tree != nullptr){
const entry_type* entry;
Expand Down Expand Up @@ -133,11 +139,11 @@ bool TomahawkOutputReader::__viewOnly(void){
}

bool TomahawkOutputReader::__viewFilter(void){
this->__openWriter();
const entry_type* entry;
while(this->nextVariant(entry)){
if(this->filter.filter(*entry))
// std::cout << this->contigs[entry->AcontigID].name << '\t' << this->contigs[entry->BcontigID].name << '\t' << *entry << '\n';
entry->write(std::cout, this->contigs);
*this->writer << entry;
}

return true;
Expand Down
16 changes: 16 additions & 0 deletions io/TomahawkOutput/TomahawkOutputReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ class TomahawkOutputReader {
bool index(const std::string& filename);
bool summary(const std::string& input);

//
bool setWriterType(const int type){
if(type == 0)
this->writer_output_type = WRITER_TYPE::binary;
else if(type == 1)
this->writer_output_type = WRITER_TYPE::natural;
else {
std::cerr << "unknown writer type: " << type << std::endl;
return false;
}
return true;
}
void setWriteHeader(const bool write){ this->output_header = write; }

// Read entire file into memory
filter_type& getFilter(void){ return this->filter; }

Expand All @@ -70,6 +84,7 @@ class TomahawkOutputReader {
bool __viewFilter(void);
bool __viewRegion(void);
bool __checkRegion(const entry_type* const entry);
void __openWriter(void);

public:
U64 filesize; // input file size
Expand All @@ -79,6 +94,7 @@ class TomahawkOutputReader {
std::ifstream stream; // reader stream
reader_type reader; // reader
header_type header; // header
bool output_header;

IO::BasicBuffer buffer; // internal buffer
IO::BasicBuffer output_buffer; // internal buffer
Expand Down
38 changes: 31 additions & 7 deletions view.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ void view_usage(void){
"\n"
"Options:\n"
" -i FILE input Tomahawk (required)\n"
" -o FILE output file (- for stdout)\n\n"

"Twk parameters\n"
" -G (twk) drop genotypes in output [null]\n"
" -o FILE output file (- for stdout)\n"
" -h/H (twk/two) header only / no header [null]\n"
" -N output in tab-delimited text format [null]\n"
" -B output in binary TWO/TWK format (default)[null]\n"
" -O char output type: b for TWO format, n for tab-delimited format (default: b)\n"
" -N output in tab-delimited text format (see -O) [null]\n"
" -B output in binary TWO/TWK format (see -O, default)[null]\n"
" -t INT number of CPU threads (default: maximum available)\n\n"

// Twk parameters
"Twk parameters\n"
" -G drop genotypes in output [null]\n\n"

// Two parameters
"Two parameters\n"
" -p float number of parts to split problem into (default: 1)\n"
Expand Down Expand Up @@ -74,11 +76,13 @@ int view(int argc, char** argv){
float minDprime = -1, maxDprime = 1;
int64_t minAlleles = 0, maxAlleles = std::numeric_limits<int64_t>::max();
U16 flagInclude = 0, flagExclude = 0;
bool outputHeader = true;
int outputType = 0;

int c = 0;
int long_index = 0;
int hits = 0;
while ((c = getopt_long(argc, argv, "i:o:P:p:a:A:R:r:f:F:d:D:w:W:hHGs", long_options, &long_index)) != -1){
while ((c = getopt_long(argc, argv, "i:o:P:p:a:A:R:r:f:F:d:D:w:W:O:hHGsNB", long_options, &long_index)) != -1){
//std::cerr << c << ":" << (char)c << '\t' << long_index << std::endl;
hits += 2;
switch (c){
Expand Down Expand Up @@ -190,6 +194,21 @@ int view(int argc, char** argv){
SILENT = 1;
--hits;
break;
case 'h':
outputHeader = true;
break;
case 'H':
outputHeader = false;
break;
case 'N':
outputType = 1;
break;
case 'B':
outputType = 0;
break;
case 'O':
outputType = atoi(optarg);
break;
}
}

Expand Down Expand Up @@ -245,6 +264,11 @@ int view(int argc, char** argv){
if(!filter.setFilterJointHF(minAlleles, maxAlleles)) return false;
if(!filter.setFilterP(minP, maxP)) return false;
if(!filter.setFilterDprime(minDprime, maxDprime)) return false;
reader.setWriteHeader(outputHeader);
if(!reader.setWriterType(outputType)){
std::cerr << "failed set output type" << std::endl;
return false;
}

if(!reader.Open(input))
return false;
Expand Down

0 comments on commit 38844da

Please sign in to comment.