Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toy implementation of map-based multiple file write #4

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BasicDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Individuals;
extern SNPs ALL_SNPS;
extern Individuals ALL_SAMPLES;
extern ofstream MATCH_FILE;
map<int, ofstream*> FILE_MAP;

enum ErrorType{RECOMB=0,MI=1};
const int HET=2;
Expand Down
14 changes: 14 additions & 0 deletions GERMLINE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using namespace std;

ofstream MATCH_FILE;
map<int, ofstream*> FILE_MAP;
size_t num_samples;
unsigned long num_matches;
SNPs ALL_SNPS;
Expand Down Expand Up @@ -45,6 +46,19 @@ void GERMLINE::mine( string params )

if ( BINARY_OUT ) MATCH_FILE.open( ( out + ".bmatch" ).c_str() , ios::binary );
else MATCH_FILE.open( ( out + ".match" ).c_str() );

// Instantiate pointers to files with append access
// we want one pointer per sample?
// num_samples incremented in Individuals::addIndividual
// This is called in PEDIndividualsExtractor which is
// called in getIndividuals
stringstream sstm;
for (int i=0;i<num_samples ;i++)
{
sstm.str("");
sstm << "match_file_" << i << ".match";
FILE_MAP[i] = new ofstream(sstm.str(), std::ofstream::out | std::ofstream::app);
}

fout << params << endl;
fout << setw(65) << setfill('-') << ' ' << endl << setfill(' ');
Expand Down
45 changes: 25 additions & 20 deletions Match.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Match.h"
#include "BasicDefinitions.h"

void Match::extendBack()
{
Expand Down Expand Up @@ -322,28 +323,32 @@ void Match::print( ostream& fout )
unsigned int sid[2];
sid[0] = ALL_SNPS.getSNP(snp_start).getMarkerNumber();
sid[1] = ALL_SNPS.getSNP(snp_end).getMarkerNumber();
fout.write( (char*) &pid[0] , sizeof( unsigned int ) );
fout.write( (char*) &pid[1] , sizeof( unsigned int ) );
fout.write( (char*) &sid[0] , sizeof( unsigned int ) );
fout.write( (char*) &sid[1] , sizeof( unsigned int ) );
fout.write( (char*) &dif , sizeof( int ) );
fout.write( (char*) &hom[0] , sizeof( bool ) );
fout.write( (char*) &hom[1] , sizeof( bool ) );
ofstream fout_temp = *FILE_MAP[node[0]->getID()];
fout_temp.write( (char*) &pid[0] , sizeof( unsigned int ) );
fout_temp.write( (char*) &pid[1] , sizeof( unsigned int ) );
fout_temp.write( (char*) &sid[0] , sizeof( unsigned int ) );
fout_temp.write( (char*) &sid[1] , sizeof( unsigned int ) );
// fout.write( (char*) &dif , sizeof( int ) );
// fout.write( (char*) &hom[0] , sizeof( bool ) );
// fout.write( (char*) &hom[1] , sizeof( bool ) );
} else
{
fout << node[0]->getID() << '\t';
fout << node[1]->getID() << '\t';
fout << ALL_SNPS.getSNP(snp_start).getChr() << '\t';
fout << ALL_SNPS.getSNP(snp_start).getPhysPos() << ' ';
fout << ALL_SNPS.getSNP(snp_end).getPhysPos() << '\t';
fout << ALL_SNPS.getSNP(snp_start).getSNPID() << ' ';
fout << ALL_SNPS.getSNP(snp_end).getSNPID() << '\t';
fout << ( snp_end - snp_start + 1) << '\t';
fout << setiosflags(ios::fixed) << setprecision(2) << distance << '\t';
if ( genetic ) fout << "cM" << '\t'; else fout << "MB" << '\t';
fout << dif;
for ( int n = 0 ; n < 2 ; n++ )
if ( hom[n] ) fout << '\t' << 1; else fout << '\t' << 0;
// line_elements = line.split("\t")
// return "\t".join(line_elements[:4])
ofstream fout_temp = *FILE_MAP[node[0]->getNumericID()];
fout_temp << node[0]->getID() << '\t';
fout_temp << node[1]->getID() << '\t';
fout_temp << ALL_SNPS.getSNP(snp_start).getChr() << '\t';
fout_temp << ALL_SNPS.getSNP(snp_start).getPhysPos() << ' ';
fout_temp << ALL_SNPS.getSNP(snp_end).getPhysPos() << '\t';
// fout << ALL_SNPS.getSNP(snp_start).getSNPID() << ' ';
// fout << ALL_SNPS.getSNP(snp_end).getSNPID() << '\t';
// fout << ( snp_end - snp_start + 1) << '\t';
// fout << setiosflags(ios::fixed) << setprecision(2) << distance << '\t';
// if ( genetic ) fout << "cM" << '\t'; else fout << "MB" << '\t';
// fout << dif;
// for ( int n = 0 ; n < 2 ; n++ )
// if ( hom[n] ) fout << '\t' << 1; else fout << '\t' << 0;
fout << endl;
}
num_matches++;
Expand Down