| 709 | } |
| 710 | |
| 711 | void ChrCopyNumber::calculateCopyNumberMedian(int ploidy, int minCNAlength, bool noisyData, bool CompleteGenomicsData, bool isLogged){ //create median profiles using 'bpfinal_' and store them in medianProfile_, info about medians themselves is stored in medianValues_ and about SD in sd_, lengths of fragments in bpLengths_ |
| 712 | if (ploidy!=ploidy_) { |
| 713 | cerr << "..Warning: in calculateCopyNumberMedian() class's ploidy is different from "<<ploidy<<"\n"; |
| 714 | ploidy_=ploidy; |
| 715 | } |
| 716 | int breakPointStart = 0; |
| 717 | int breakPointEnd; |
| 718 | float median; |
| 719 | |
| 720 | bpfinal_.push_back(length_-1); //add last point |
| 721 | |
| 722 | vector <int> seg_ends; |
| 723 | vector <int> seg_starts; |
| 724 | |
| 725 | if (int(medianProfile_.size())!=length_) { |
| 726 | medianProfile_ = vector <float> (length_,NA); |
| 727 | } |
| 728 | |
| 729 | //for BAF: |
| 730 | bool isBAFpresent = false; |
| 731 | //float medianBAF; |
| 732 | float estimatedBAF; |
| 733 | float fittedBAF; |
| 734 | float uncertainty; |
| 735 | string medianBAFSym; |
| 736 | if (BAF_.size()>0) { |
| 737 | isBAFpresent = true; |
| 738 | //medianBAFProfile_ = vector <float> (length_,NA); |
| 739 | estimatedBAFProfile_ = vector <float> (length_,NA); |
| 740 | fittedBAFProfile_ = vector <float> (length_,NA); |
| 741 | medianBAFSymbol_ = vector <std::string> (length_,"-"); |
| 742 | estimatedBAFuncertainty_ = vector <float> (length_,NA); |
| 743 | cout << "..Control: BAF profile is present\n"; |
| 744 | } |
| 745 | |
| 746 | //clear existing values: |
| 747 | sd_.clear(); |
| 748 | medianValues_.clear(); |
| 749 | fragmentNotNA_lengths_.clear(); |
| 750 | fragment_lengths_.clear(); |
| 751 | BAFsymbPerFrag_.clear(); |
| 752 | estBAFuncertaintyPerFrag_.clear(); |
| 753 | |
| 754 | for (int i = 0; i < (int)bpfinal_.size();i++) { |
| 755 | breakPointEnd = bpfinal_[i]; |
| 756 | //int ndatapoints = breakPointEnd-breakPointStart+1; |
| 757 | vector<float> data; |
| 758 | //vector<float> dataBAF; |
| 759 | int notNA = 0; |
| 760 | string BAFValuesInTheSegment = ""; //here we merge all SNP Values of this segment |
| 761 | for (int j = breakPointStart; j <= breakPointEnd; j++) |
| 762 | { |
| 763 | if (ratio_[j] != NA) { |
| 764 | data.push_back(ratio_[j]); |
| 765 | notNA++; |
| 766 | if (isBAFpresent && BAF_[j]!=NA && BAFvalues_[j] != ""){ |
| 767 | //dataBAF.push_back(BAF_[j]); |
| 768 | if (BAFValuesInTheSegment != ""){ |
no test coverage detected