Skip to content

Commit

Permalink
bump to stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
openpaul committed Aug 11, 2016
1 parent fadbe94 commit bcfc920
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 86 deletions.
67 changes: 31 additions & 36 deletions rtk/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ std::mutex rarefyMutex;
void lineCntOut(const string inF, const string outF, const string arg4){
ifstream in(inF.c_str());
ofstream out(outF.c_str(), ios::out);
if (!in){
if (!in){
#ifdef notRpackage
cerr << "Can't open infile " << inF << endl; std::exit(99);
cerr << "Can't open infile " << inF << endl; std::exit(99);
#endif
}
if (!out){
if (!out){
#ifdef notRpackage
cerr << "Can't open outfile " << outF << endl; std::exit(99);
cerr << "Can't open outfile " << outF << endl; std::exit(99);
#endif
}
//read file that contains nicely ordered all indexes of lines to be extracted
string line;
vector<uint> srtTar;
ifstream idxS(arg4.c_str());
if (!idxS){
if (!idxS){
#ifdef notRpackage
cerr << "Can't open outfile " << arg4 << endl; std::exit(99);
cerr << "Can't open outfile " << arg4 << endl; std::exit(99);
#endif
}
while (getline(idxS, line, '\n')) {
Expand All @@ -35,7 +35,7 @@ cerr << "Can't open outfile " << arg4 << endl; std::exit(99);
sort(srtTar.begin(), srtTar.end());

//sort through new file
if (!out){
if (!out){
#ifdef notRpackage
cerr << "Can't open outfile " << outF << endl; std::exit(99);
#endif
Expand All @@ -53,7 +53,7 @@ cerr << "Can't open outfile " << outF << endl; std::exit(99);

in.close(); out.close();
if (j != srtTar.size()){

#ifdef notRpackage
cerr << "Missed " << (srtTar.size() - j) << " entries." << endl;
#endif
Expand All @@ -66,24 +66,24 @@ num_threads(nt), richness(-1), Shannon(-1.f){
for (uint i = 0; i < vec.size(); i++){
cumSum += vec[i];
}
if (verbose){
if (verbose){
#ifdef notRpackage
cerr << (long)cumSum << " allocating ";
#endif
}
//arr = (int*) malloc((int)cumSum * sizeof(int));
//arr = new unsigned short[(int)cumSum];
arr.resize((long)cumSum);
if (verbose){
if (verbose){
#ifdef notRpackage
cerr << "memory";
cerr << "memory";
#endif
}
totSum = cumSum;
long k(0); uint posInVec(-1);
//numFeatures = 0;
for (size_t i = 0; i< vec.size(); i++){

long maxG = (long)vec[i];
IDs.push_back( std::to_string(i));

Expand All @@ -99,9 +99,9 @@ cerr << "memory";
}
posInVec++;
numFeatures = posInVec;
if (verbose){
if (verbose){
#ifdef notRpackage
cerr << "..\n";
cerr << "..\n";
#endif
}
}
Expand All @@ -119,17 +119,12 @@ smplVec::smplVec(const string inF, const int nt) :IDs(0),totSum(0), num_threads(
vec.push_back(num); IDs.push_back(ID);
}
in.close();
//
#ifdef notRpackage
cerr<<"tt";std::vector<unsigned short> v((int)cumSum);
#endif

if (verbose){
#ifdef notRpackage
cerr<<(long)cumSum<<" allocating ";
#endif
}
//arr = (int*) malloc((int)cumSum * sizeof(int));
//arr = new unsigned short[(int)cumSum];
#ifdef notRpackage
cerr<<(long)cumSum<<" allocating ";
#endif
}
arr.resize((long)cumSum);
if (verbose){
#ifdef notRpackage
Expand All @@ -139,7 +134,7 @@ cerr<<(long)cumSum<<" allocating ";
totSum = cumSum;
long k(0); uint posInVec(0);
for (size_t i = 0; i< vec.size(); i++){

long maxG = (long)vec[i];
maxG += k;
if (maxG == 0){ continue; }//not really a feature, doesnt need ot be counted as cat
Expand Down Expand Up @@ -461,9 +456,9 @@ double smplVec::calc_eveness(const vector<uint>& vec){
void DivEsts::print2file(const string file){
if (richness.size()<1){return;}
ofstream out(file.c_str());
if (!out){
if (!out){
#ifdef notRpackage
cerr << "Couldn't open diversity estimate file " << file << endl; std::exit(99);
cerr << "Couldn't open diversity estimate file " << file << endl; std::exit(99);
#endif
}
out<<"Richness\t"<<richness[0];
Expand Down Expand Up @@ -496,14 +491,14 @@ void printDivMat(const string outF, vector<DivEsts*>& inD, bool printDIV ){

string outFmedian = outF + "median_alpha_diversity.tsv";
ofstream out(outFmedian.c_str());
if (!out){
if (!out){
#ifdef notRpackage
cerr << "Couldn't open diversity estimate matrix " << outF << endl; std::exit(99);
cerr << "Couldn't open diversity estimate matrix " << outF << endl; std::exit(99);
#endif
}
out << "Smpl\tRichness\tShannon\tSimpson\tInv. Simpson\tChao1\tEveness\n";
for (size_t i = 0; i < inD.size(); i++){
if (inD[i] == NULL){
if (inD[i] == NULL){
#ifdef notRpackage
cerr << "Empty vector at index " << i << "in div mat building.\n";
#endif
Expand Down Expand Up @@ -599,9 +594,9 @@ cerr << "Empty vector at index " << i << "in div mat building.\n";
}
void printRareMat(const string outF, vector< map< uint, uint >>& rMat, vector< string >& sampleNames, vector < string >& rowId){
ofstream out(outF.c_str());
if (!out){
if (!out){
#ifdef notRpackage
cerr << "Couldn't open rarefy matrix file " << outF << endl; std::exit(99);
cerr << "Couldn't open rarefy matrix file " << outF << endl; std::exit(99);
#endif
}

Expand Down Expand Up @@ -636,9 +631,9 @@ string printSimpleMap(map<uint, uint> vec, string outF, string id, vector<string
// to the disk.
// this way we dont need memory to do
ofstream out(outF.c_str(), ios::binary);
if (!out){
if (!out){
#ifdef notRpackage
cerr << "Couldn't open tmpvec file " << outF << endl; std::exit(99);
cerr << "Couldn't open tmpvec file " << outF << endl; std::exit(99);
#endif
}
for(uint i = 0; i < rowNames.size(); i++){
Expand Down Expand Up @@ -689,9 +684,9 @@ void reassembleTmpMat(vector<string> inF, vector< string > rowNames, vector< str
}

ofstream out(outF.c_str());
if (!out){
if (!out){
#ifdef notRpackage
cerr << "Couldn't open tmpvec file " << outF << endl; std::exit(99);
cerr << "Couldn't open tmpvec file " << outF << endl; std::exit(99);
#endif
}
out << "Rarefied";
Expand Down
62 changes: 12 additions & 50 deletions rtk/Rare.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
// rarefaction.cpp
// usage: rarefaction in_matrix outfile
//outfile contains richness and sample sum; in same dir several files are created
//C:\Users\Falk\SkyDrive\science\data\test\test.mat.subs

//#include "Matrix.h"
#include "ClStr2Mat.h"
#include "Rare.h"

const char* rar_ver="0.7 beta";
const char* rar_ver="0.9";


rareStruct* calcDivRar(int i, Matrix* Mo, DivEsts* div, long rareDep,
Expand Down Expand Up @@ -39,6 +33,8 @@ rareStruct* calcDivRar(int i, Matrix* Mo, DivEsts* div, long rareDep,
rareStruct* calcDivRarVec(int i, vector<string> fileNames, DivEsts* div, long rareDep,
vector<vector<uint>>* abundInRow, vector<vector<uint>>* occuencesInRow, string outF,
int repeats, int writeFiles){

exit(0);
// cout << i << " ";
smplVec* cur = new smplVec(fileNames[i],4);

Expand Down Expand Up @@ -176,7 +172,7 @@ xtra("") {
else if (!strcmp(argv[i], "-xtra"))
xtra = (argv[++i]);



}

Expand Down Expand Up @@ -280,6 +276,7 @@ void rareExtremLowMem(string inF, string outF, int writeFiles, string arg4, int
}else if( i == 3){
cout << "..." << std::endl ;
}

uint toWhere = done + numThr - 1;
if ((uint)((uint)fileNames.size() - 2 ) < toWhere){
toWhere = fileNames.size() - 2;
Expand All @@ -297,6 +294,7 @@ void rareExtremLowMem(string inF, string outF, int writeFiles, string arg4, int
tmpRS = calcDivRarVec(i, fileNames, div, rareDep, &abundInRow, &occuencesInRow, outF, repeats, writeFiles);
i++;


// process created data, first threads, then main thread
i = done;
for (; i < toWhere; i++){
Expand Down Expand Up @@ -384,50 +382,14 @@ int main(int argc, char* argv[])
string arg4 = std::to_string(opts->depth);
bool verbose = opts->verbose;

//mode = argv[1];

/*
long rareDep = 1000; int repeats (1);
//bool splitMode(false),mergeMode(false),sumUpMode(false);
string inF = argv[2];
string outF = argv[3];
// hardcode mode, as the others are excluded for newRow
// can be removed, as soon as other functionality is ready
// to be used. June 2016
//string mode = argv[1];
string mode = argv[1];
string arg4 = "";
uint numThr = 1; //number of threads to use
if (argc>=5){
arg4 = argv[4];
}
if (argc>5){
repeats = atoi(argv[5]);
}
int writeFiles = repeats;
if (argc>6){
writeFiles = atoi(argv[6]);
}
if (argc > 7){
numThr = atoi(argv[7]);
}
if( writeFiles > repeats){
cerr << "Can not write more files than repeats. Set writefiles to repeats" << std::endl;
int writeFiles = repeats;
}
// flag to store data on disk
bool storeBinary = true;
vector < vector < string > > tmpMatFiles (writeFiles );
if (argc > 8){
storeBinary = atoi(argv[8]);
}*/

//all modes that classify as rarefactions:
if (mode == "swap" || mode == "memory") {
if(opts->input == ""){
cerr << "No input file specified. Exiting" << std::endl;
exit(0);
}
opts->print_rare_details();
}

Expand Down Expand Up @@ -566,7 +528,7 @@ int main(int argc, char* argv[])
// this will be used for Chao2 estimation
vector<vector<uint>> abundInRow(opts->repeats, vector<uint>(Mo->rowNum(),0));
vector<vector<uint>> occuencesInRow(opts->repeats, vector<uint>(Mo->rowNum(),0));

//object to keep matrices
vector < vector < string > > tmpMatFiles(opts->write);
//cerr << "TH";
Expand Down Expand Up @@ -601,7 +563,7 @@ int main(int argc, char* argv[])
divvs[i] = tmpRS->div;
string curS = Mo->getSampleName(i);
//divvs[i-done]->print2file(outF + curS + "_alpha_div.tsv");

// add the matrices to the container
if(NoOfMatrices > 0){
if(opts->writeSwap){
Expand Down

0 comments on commit bcfc920

Please sign in to comment.