| 1203 | } |
| 1204 | |
| 1205 | void GenomeCopyNumber::calculateRatioUsingCG_Regression( GenomeCopyNumber & controlCopyNumber) { |
| 1206 | |
| 1207 | int degree = 1; |
| 1208 | bool intercept=0; |
| 1209 | cout << "..polynomial degree set to 1\n"; |
| 1210 | cout << "Initial guess for polynomial:\n"; |
| 1211 | |
| 1212 | //first guess about parameters |
| 1213 | |
| 1214 | double a[MAXDEGREE+1]; |
| 1215 | |
| 1216 | a[degree] = 0; |
| 1217 | a[0]=1; |
| 1218 | |
| 1219 | cout << "Y = " << a[0] << "*x+" << a[1] << "\n"; |
| 1220 | |
| 1221 | |
| 1222 | int maximalNumberOfIterations = 300; |
| 1223 | int maximalNumberOfCopies = ploidy_*2; |
| 1224 | |
| 1225 | vector <float> y; //y ~ a0x+a1 |
| 1226 | vector <float> x; |
| 1227 | vector <int> positions; |
| 1228 | |
| 1229 | //fill x and y: |
| 1230 | vector<ChrCopyNumber>::iterator it; |
| 1231 | for ( it=chrCopyNumber_.begin() ; it != chrCopyNumber_.end(); it++ ) { |
| 1232 | if (! (it->getChromosome().find("X")!=string::npos || it->getChromosome().find("Y")!=string::npos)) { |
| 1233 | vector <float> controlcounts = controlCopyNumber.getChrCopyNumber(it->getChromosome()).getRatio() ; |
| 1234 | //check that everything is all right: |
| 1235 | if (int(controlcounts.size())!=it->getLength()) { |
| 1236 | cerr << "Possible Error: calculateMedianAround ()\n"; |
| 1237 | } |
| 1238 | for (int i = 0; i< it->getLength(); i++) { |
| 1239 | if (it->getRatioAtBin(i)>0 && controlcounts[i]>0) { |
| 1240 | x.push_back(controlcounts[i]); |
| 1241 | y.push_back(it->getRatioAtBin(i)); |
| 1242 | positions.push_back(it->getCoordinateAtBin(i)); |
| 1243 | } |
| 1244 | } |
| 1245 | controlcounts.clear(); |
| 1246 | } |
| 1247 | } |
| 1248 | if (degree==1) { |
| 1249 | const char * nametmp = "/home/vboeva/NAS_public/data/projects/FREEC/TEST_FREEC_CLBMA_WES/output_WES/xy.txt"; |
| 1250 | std::ofstream file; |
| 1251 | file.open(nametmp); |
| 1252 | for ( unsigned int i=0 ;i<x.size(); i++ ) { |
| 1253 | file << positions[i]<<"\t"<<x[i] <<"\t" << y[i] <<"\n" ; |
| 1254 | } |
| 1255 | file.close(); |
| 1256 | } |
| 1257 | float rmserror = runEM(x,y,a,degree,maximalNumberOfIterations,ploidy_,maximalNumberOfCopies, intercept, normalContamination_); |
| 1258 | if (rmserror == -1) { |
| 1259 | cerr << "Error in EM => unable to calculate normalized profile\n"; |
| 1260 | return; |
| 1261 | } |
| 1262 | cout << "root mean square error = " << rmserror << "\n"; |
nothing calls this directly
no test coverage detected