| 1310 | } |
| 1311 | |
| 1312 | int GenomeCopyNumber::calculateRatio( GenomeCopyNumber & controlCopyNumber, int degree, bool intercept) { |
| 1313 | |
| 1314 | |
| 1315 | int maximalNumberOfIterations = 300; |
| 1316 | int maximalNumberOfCopies = ploidy_*2; |
| 1317 | int realNumberOfIterations = maximalNumberOfIterations; |
| 1318 | |
| 1319 | int successfulFit = 0; |
| 1320 | |
| 1321 | if(isRatioLogged_) { |
| 1322 | intercept=1; degree=1;//because it is loglogscale |
| 1323 | vector <float> y; //y ~ a0x+a1 |
| 1324 | vector <float> x; |
| 1325 | |
| 1326 | //fill x and y: |
| 1327 | vector<ChrCopyNumber>::iterator it; |
| 1328 | for ( it=chrCopyNumber_.begin() ; it != chrCopyNumber_.end(); it++ ) { |
| 1329 | if (! (it->getChromosome().find("X")!=string::npos || it->getChromosome().find("Y")!=string::npos)) { |
| 1330 | vector <float> controlcounts = controlCopyNumber.getChrCopyNumber(it->getChromosome()).getValues() ; |
| 1331 | //check that everything is all right: |
| 1332 | if (int(controlcounts.size())!=it->getLength()) { |
| 1333 | cerr << "Possible Error: calculateMedianAround ()\n"; |
| 1334 | } |
| 1335 | for (int i = 0; i< it->getLength(); i++) { |
| 1336 | if (it->getValueAt(i)>0 && controlcounts[i]>0) { |
| 1337 | x.push_back(log(controlcounts[i])); |
| 1338 | y.push_back(log(it->getValueAt(i))); |
| 1339 | } |
| 1340 | } |
| 1341 | controlcounts.clear(); |
| 1342 | } |
| 1343 | } |
| 1344 | cout << "Initial guess for polynomial:\n"; |
| 1345 | |
| 1346 | int nvars = degree; //1 if the fit is linear |
| 1347 | ap::real_2d_array xy; |
| 1348 | int npoints = x.size(); |
| 1349 | xy.setlength(npoints,nvars+1); |
| 1350 | int pos = 0; |
| 1351 | for (int i = 0; i <(int)x.size(); i++) { |
| 1352 | xy(pos,degree) = y[i]; |
| 1353 | xy(pos,degree-1) = x[i];; |
| 1354 | for (int j = degree-2; j>=0; j--) { |
| 1355 | xy(pos,j)=xy(pos,j+1)*x[i]; |
| 1356 | } |
| 1357 | pos++; |
| 1358 | } |
| 1359 | linearmodel lm; |
| 1360 | int info; |
| 1361 | lrreport ar; |
| 1362 | if (intercept) |
| 1363 | lrbuild(xy,npoints,nvars,info,lm,ar); |
| 1364 | else |
| 1365 | lrbuildz(xy,npoints,nvars,info,lm,ar); |
| 1366 | |
| 1367 | if (info != 1) { |
| 1368 | cerr << "Error in linear regression, code: " << info <<"\n"; |
| 1369 | } |
no test coverage detected