MCPcopy Create free account
hub / github.com/BoevaLab/FREEC / evaluateContaminationwithLR

Method evaluateContaminationwithLR

src/GenomeCopyNumber.cpp:3452–3525  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3450}
3451
3452float GenomeCopyNumber::evaluateContaminationwithLR () {
3453 string::size_type pos = 0;
3454 vector <float> observed_values;
3455 vector <float> expected_values;
3456 map<string,int>::iterator it;
3457
3458 for ( it=chromosomesInd_.begin() ; it != chromosomesInd_.end(); it++ ) {
3459 string chrNumber = (*it).first;
3460 if ( ( pos = chrNumber.find("chr")) != string::npos )
3461 chrNumber.replace( pos, 3, "" );
3462 if ( ( pos = chrNumber.find("X")) != string::npos ) //exclude X and Y from the analysis
3463 continue;
3464 if ( ( pos = chrNumber.find("Y")) != string::npos )
3465 continue;
3466 int index = findIndex(chrNumber);
3467 if (index == NA) {
3468 cerr << "An error occurred in GenomeCopyNumber::evaluateContamination: could not find an index for "<<chrNumber<<"\n";
3469 return 0;
3470 }
3471 int length = chrCopyNumber_[index].getLength();
3472 for (int i = 0; i< length; i++) {
3473 float observed = chrCopyNumber_[index].getRatioAtBin(i);
3474 if (observed!=NA) {
3475 if (isRatioLogged_)
3476 observed=pow(2,observed);
3477 float expected = observed;
3478 if (chrCopyNumber_[index].isMedianCalculated()) {
3479 expected = round_by_ploidy(chrCopyNumber_[index].getMedianProfileAtI(i),ploidy_) ;
3480 }
3481 if (expected!=NA && expected<1+2.0/ploidy_){
3482 observed_values.push_back(observed-1);
3483 expected_values.push_back(expected-1);
3484 }
3485 }
3486 }
3487 }
3488
3489 vector <float> x = expected_values;
3490 vector <float> y = observed_values;
3491
3492 int n = x.size();
3493 float sum_x = 0;
3494 float sum_y = 0;
3495 float sum_x2 = 0;
3496 float sum_y2 = 0;
3497 float sum_xy = 0;
3498 for (int i = 0; i < n; i++) {
3499 sum_x += x[i];
3500 sum_y += y[i];
3501 sum_x2 += x[i] * x[i];
3502 sum_y2 += y[i] * y[i];
3503 sum_xy += x[i] * y[i];
3504 }
3505
3506 float a = (n * sum_xy - sum_x * sum_y) / (n * sum_x2 - sum_x * sum_x); //CARINO
3507 a =sum_xy/sum_x2; //VALENTINA
3508 // float b = (sum_x2 * sum_y - sum_x * sum_xy) / (n * sum_x2 - sum_x * sum_x);
3509 float contam_a = (1-a)/(1-a+2*a/(float)ploidy_);

Callers 1

runWithDefinedPloidyFunction · 0.80

Calls 5

round_by_ploidyFunction · 0.85
getRatioAtBinMethod · 0.80
isMedianCalculatedMethod · 0.80
getMedianProfileAtIMethod · 0.80
getLengthMethod · 0.45

Tested by

no test coverage detected