Skip to content

Commit

Permalink
v10.2 - some code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
valeu committed Dec 9, 2016
1 parent b9db18a commit 4ca9c11
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 271 deletions.
30 changes: 24 additions & 6 deletions src/BAFpileup.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*************************************************************************
Copyright (c) 2010-2016, Valentina BOEVA.
>>> SOURCE LICENSE >>>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation (www.fsf.org); either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>>
*************************************************************************/


#include "BAFpileup.h"

using namespace std;
Expand Down Expand Up @@ -55,7 +76,7 @@ float BAFpileup::calculateFlankLength(std::string const& mateFileName, std::stri
time_t t0 = time(NULL);
#endif

MateOrientation matesOrientation = getMateOrientation(matesOrientation_str);
// MateOrientation matesOrientation = getMateOrientation(matesOrientation_str); // will not consider read orientation to increase speed
char* line_buffer;
FILE *stream;
char buffer[MAX_BUFFER];
Expand Down Expand Up @@ -118,8 +139,6 @@ float BAFpileup::calculateFlankLength(std::string const& mateFileName, std::stri
fileMates.close();
}




fragmentLength = fragmentLength/j;
float flanks = fragmentLength/2;
Expand Down Expand Up @@ -214,10 +233,9 @@ void BAFpileup::createBedFileWithChromosomeLengths(std::string bedFileWithRegion

ofstream myfile;
myfile.open(bedFileWithRegionsOfInterest.c_str());
for (int i = 0; i < chr_names.size(); i++)
{
for (unsigned int i = 0; i < chr_names.size(); i++) {
myfile << "chr"<< chr_names[i] << "\t" << "1" << "\t" << lengths[i] << "\n";
}
}
myfile.close();
}

Expand Down
73 changes: 11 additions & 62 deletions src/ChrCopyNumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,48 +91,13 @@ ChrCopyNumber::ChrCopyNumber(int windowSize, int chrLength, std::string const& c
cout << "..Reading "<< captureFile << "\n";
cout << "..Your file must be in .BED format, and it must be sorted\n";
std::string line;
// exons_Count = 0;
// exons_Countchr = 0;
// while (std::getline(file,line))
// {
// exons_Count++;
// }
// chr_namestmp = vector<string>(exons_Count);
// int l=0;
// file.clear();
// file.seekg(0);
// while (std::getline(file,line))
// {
// int i = 0;
// while (line[i] != 'r')
// {
// i++;
// }
// i++;
// while (line[i] != '\t')
// {
// chr_namestmp[l] += line[i];
// i++;
// }
// i++;
// l++;
// }
// file.clear();
// file.seekg(0);
// l = 0;

// length_ should end up equal to the number of exons matching this chromosome.
length_ = 0;
size_t tried = 0;


while (std::getline(file,line)) {
//
// if (chr_namestmp[l] == chromosome_)
// {
// exons_Countchr++;
// }
// l++;

// Avoid catching a carriage return if the file uses windows-style line endings
if(line.size() != 0 && line[line.size() - 1] == '\r')
Expand Down Expand Up @@ -192,21 +157,10 @@ ChrCopyNumber::ChrCopyNumber(int windowSize, int chrLength, std::string const& c

}

// length_ = exons_Countchr;
// coordinatesTmp_ = vector<string>(exons_Countchr);
// endsTmp_ = vector<string>(exons_Countchr);
// genes_names = vector<string>(exons_Countchr);
// chr_names= vector<string>(exons_Countchr);
//
// l=0;
// int j = 0;
// file.clear();
// file.seekg(0);
if(tried != length_) {
if(int(tried) != length_) {
std::cerr << "Warning: skipped " << (tried - length_) << " lines due to formatting problems\n";
}


exons_Countchr_ = length_;

readCount_ = vector<float>(exons_Countchr_,0);
Expand Down Expand Up @@ -349,7 +303,7 @@ float ChrCopyNumber::getPopulation_subc(int i)

std::string ChrCopyNumber::getGeneNameAtBin(int i)
{
if (genes_names.size()>=i)
if (i<int(genes_names.size()))
return genes_names[i];
return "";
}
Expand All @@ -373,7 +327,7 @@ int ChrCopyNumber::getExons_Countchr() {
}

void ChrCopyNumber::setNotNprofileAt(int i, float value) {
if (i<notNprofile_.size())
if (i<int(notNprofile_.size()))
notNprofile_[i] = value;
else
cout <<"out of boundaries!!\n";
Expand Down Expand Up @@ -513,15 +467,10 @@ void ChrCopyNumber::recalculateRatio(ChrCopyNumber control){
ratio_[i] = ratio_[i]/controlRatio;
if (ratio_[i]<0)
ratio_[i] = NA;
}
else
} else
ratio_[i] = NA;
} else
if (ratio_[i]==0)
//ratio_[i] = 1;
ratio_[i] = NA;
else
ratio_[i] = NA;
ratio_[i] = NA;
//cout << readCount_[i] << "\t" << control.getValueAt(i) << "\t" << ratio_[i] << "\n";
}
}
Expand Down Expand Up @@ -573,7 +522,7 @@ void ChrCopyNumber::setAllNormal() {
if ((int)ratio_.size()!=length_)
ratio_.resize(length_);
for (int i = 0; i<length_; i++) {
if (readCount_[i] != NA && i<notNprofile_.size() &&notNprofile_[i]>0) {
if (readCount_[i] != NA && i<int(notNprofile_.size()) &&notNprofile_[i]>0) {
ratio_[i] = 1;
} else {
ratio_[i] = NA;
Expand Down Expand Up @@ -724,7 +673,7 @@ void ChrCopyNumber::calculateCopyNumberMedian(int ploidy, int minCNAlength, bool
vector <int> seg_ends;
vector <int> seg_starts;

if (medianProfile_.size()!=length_) {
if (int(medianProfile_.size())!=length_) {
medianProfile_ = vector <float> (length_,NA);
}

Expand Down Expand Up @@ -784,7 +733,7 @@ void ChrCopyNumber::calculateCopyNumberMedian(int ploidy, int minCNAlength, bool

bool ifHomoz = false;
float locMedian=NA;
if (data.size()>=minCNAlength && data.size()>0)
if (int(data.size())>=minCNAlength && data.size()>0)
locMedian = get_median(data); //including the last point
if (isBAFpresent && notNA > 100 && locMedian < 1 && noisyData ) {
vector<string>heteroValuesPerWindowStrings = split(BAFValuesInTheSegment, ';');
Expand Down Expand Up @@ -1544,7 +1493,7 @@ std::string ChrCopyNumber::getBAFsymbolAt (int i) {
}

float ChrCopyNumber::getEstimatedBAFuncertaintyAtI(int i) {
if (i>0 &&i<estimatedBAFuncertainty_.size())
if (i>0 &&i<int(estimatedBAFuncertainty_.size()))
return estimatedBAFuncertainty_[i];
return NA;
}
Expand Down Expand Up @@ -1717,12 +1666,12 @@ float ChrCopyNumber::getLevelAt(int unsigned i, int ploidy) {


void ChrCopyNumber::setRCountToZeroForNNNN() {
for (int i = 0; i< notNprofile_.size(); i++) {
for (unsigned int i = 0; i< notNprofile_.size(); i++) {
if (notNprofile_[i]==0) {
readCount_[i]=0;
}
}
for (int i = notNprofile_.size(); i< readCount_.size(); i++) {
for (unsigned int i = notNprofile_.size(); i< readCount_.size(); i++) {
readCount_[i]=0;
}
}
Expand Down
Loading

0 comments on commit 4ca9c11

Please sign in to comment.