Skip to content

Commit

Permalink
correct 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 1f6e798 commit d83361e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
8 changes: 3 additions & 5 deletions io/TomahawkOutput/TomahawkOutputReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TomahawkOutputReader::TomahawkOutputReader() :
filesize(0),
position(0),
size(0),
writer_output_type(WRITER_TYPE::natural),
writer_output_type(WRITER_TYPE::binary),
writer(nullptr),
contigs(nullptr),
contig_htable(nullptr),
Expand Down Expand Up @@ -47,11 +47,9 @@ bool TomahawkOutputReader::view(const std::string& input){

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

this->writer->open();
this->writer->writeHeader();
Expand Down
39 changes: 28 additions & 11 deletions io/TomahawkOutput/TomahawkOutputWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ class TomahawkOutputWriterInterface {
protected:
typedef TomahawkOutputEntry entry_type;
typedef TomahawkOutputHeader<Tomahawk::Constants::WRITE_HEADER_LD_MAGIC_LENGTH> header_type;
typedef Totempole::TotempoleContigBase contig_type;

public:
TomahawkOutputWriterInterface() : stream(nullptr){}
TomahawkOutputWriterInterface(const contig_type* contigs, const header_type* header) :
stream(nullptr),
header(header),
contigs(contigs)
{}
virtual ~TomahawkOutputWriterInterface(){ delete this->stream; }

bool open(void){
Expand Down Expand Up @@ -58,6 +63,8 @@ class TomahawkOutputWriterInterface {
protected:
std::string outFile;
stream_type* stream;
const header_type* header;
const contig_type* contigs;
};

// case binary
Expand All @@ -67,8 +74,9 @@ class TomahawkOutputWriter : public TomahawkOutputWriterInterface {
typedef IO::GZController tgzf_controller_type;

public:
TomahawkOutputWriter() : flush_limit(524288){}
TomahawkOutputWriter(const U32 flush_limit) :
TomahawkOutputWriter(const contig_type* contigs, const header_type* header) : TomahawkOutputWriterInterface(contigs, header), flush_limit(524288){}
TomahawkOutputWriter(const contig_type* contigs, const header_type* header, const U32 flush_limit) :
TomahawkOutputWriterInterface(contigs, header),
flush_limit(flush_limit),
buffer(flush_limit + 524288)
{
Expand All @@ -83,7 +91,13 @@ class TomahawkOutputWriter : public TomahawkOutputWriterInterface {
this->buffer.deleteAll();
}

inline void flush(void){ this->stream->flush(); }
inline void flush(void){
this->controller.Deflate(this->buffer);
this->stream->write(&this->controller.buffer_[0], this->controller.buffer_.size());
this->controller.Clear();
this->buffer.reset();
this->stream->flush();
}
inline bool close(void){ this->stream->close(); return true; }

void operator<<(const entry_type* const entry){
Expand All @@ -96,8 +110,15 @@ class TomahawkOutputWriter : public TomahawkOutputWriterInterface {
}
}

void writeHeader(void){ };
void writeEOF(void){};
void writeHeader(void){
*reinterpret_cast<std::ofstream*>(&this->stream->getStream()) << *this->header;
for(U32 i = 0; i < this->header->n_contig; ++i)
*reinterpret_cast<std::ofstream*>(&this->stream->getStream()) << this->contigs[i];

};
void writeEOF(void){
//this->stream->write(reinterpret_cast<const char*>(&Tomahawk::Constants::eof[0]), Tomahawk::Constants::eof_length*sizeof(U64));
};

private:
U32 flush_limit;
Expand All @@ -108,10 +129,9 @@ class TomahawkOutputWriter : public TomahawkOutputWriterInterface {
// case binary
class TomahawkOutputWriterNatural : public TomahawkOutputWriterInterface {
typedef TomahawkOutputWriterNatural self_type;
typedef Totempole::TotempoleContigBase contig_type;

public:
TomahawkOutputWriterNatural() : contigs(nullptr){}
TomahawkOutputWriterNatural(const contig_type* contigs, const header_type* header) : TomahawkOutputWriterInterface(contigs, header){}
~TomahawkOutputWriterNatural(){
// Flush upon termination
this->flush();
Expand All @@ -123,15 +143,12 @@ class TomahawkOutputWriterNatural : public TomahawkOutputWriterInterface {
entry->write(*reinterpret_cast<std::ofstream*>(&this->stream->getStream()), this->contigs);
}

void setContigs(const contig_type* const contigs){ this->contigs = contigs; }
void writeHeader(void){
const std::string header = "FLAG\tAcontigID\tAposition\tBcontigID\tBpositionID\tp1\tp2\tq1\tq2\tD\tDprime\tR2\tP\tchiSqFisher\tchiSqModel\n";
this->stream->getStream() << header;
};
void writeEOF(void){};

private:
const contig_type* contigs;
};

}
Expand Down

0 comments on commit d83361e

Please sign in to comment.