File indexing completed on 2025-01-31 09:22:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #include "LEMIVModel.hh"
0031
0032 #include "ClassifiedDamage.hh"
0033 #include "Damage.hh"
0034 #include "DamageClassifier.hh"
0035
0036 #include <cmath>
0037 #include <iostream>
0038 #include <fstream>
0039 #include <algorithm>
0040
0041
0042
0043 LEMIVModel::LEMIVModel(double pLoopLength,double pNi, double pNc,
0044 double pNDSB,double pFunrej,double pTfast,double pTslow):
0045 fLoopLength(pLoopLength),
0046 fNi(pNi),
0047 fNc(pNc),
0048 fNDSB(pNDSB),
0049 fFunrej(pFunrej),
0050 fTfast(pTfast),
0051 fTslow(pTslow)
0052 {
0053 fBpForDSB = 10;
0054 fDefaultsChromosomeSizes={250, 250, 242, 242, 198, 198, 190, 190, 182,
0055 182, 171, 171, 159, 159, 145, 145, 138, 138, 134,
0056 134, 135, 135, 133, 133, 114, 114, 107, 107, 102,
0057 102, 90, 90, 83, 83, 80, 80, 59, 59, 64, 64, 47, 47, 51, 51, 156, 57};
0058 }
0059
0060
0061
0062 double LEMIVModel::ComputeUnrej(double pTime)
0063 {
0064 double lambdac = (fNDSB-fNi)/fNc;
0065 double Ffast = fNi/fNDSB;
0066 double Fslow = fNc*lambdac/fNDSB;
0067
0068 return Ffast*std::exp(-std::log(2)*pTime/fTfast)+
0069 (Fslow-fFunrej)*std::exp(-std::log(2)*pTime/fTslow)+
0070 fFunrej;
0071 }
0072
0073
0074
0075 void LEMIVModel::ComputeAndSetDamageInput(std::vector<Damage> vecDamage)
0076 {
0077
0078 double nidsb=0;
0079 double ncdsb=0;
0080 double ndsb=0;
0081
0082 DamageClassifier damclass = DamageClassifier();
0083
0084 auto sortedDamage = damclass.SortDamageByChromo(vecDamage);
0085
0086 if (fChromosomeBpMap.size() == 0) {
0087 std::cout<<"=====> LEMIV Calculation will Using Default Choromosome sizes"<<std::endl;
0088 for (int ii=0;ii<fDefaultsChromosomeSizes.size();ii++) {
0089 unsigned long long int nBp = fDefaultsChromosomeSizes[ii]*1E6;
0090 fChromosomeBpMap.insert({ii,nBp});
0091 }
0092 }
0093
0094 int i=0;
0095 for(auto it=sortedDamage.begin();it!=sortedDamage.end();it++)
0096 {
0097 i++;
0098
0099 std::vector<Damage> chromoDamage;
0100 for(auto itt=it->second.begin();itt!=it->second.end();itt++)
0101 {
0102 std::move(itt->second.begin(), itt->second.end(), std::back_inserter(chromoDamage));
0103 }
0104
0105
0106 std::sort(chromoDamage.begin(), chromoDamage.end(),
0107 [](const Damage& a, const Damage& b) {
0108 return a.GetCopyNb() < b.GetCopyNb();
0109 });
0110
0111
0112 auto chromID = it->first;
0113 if (fChromosomeBpMap.find(chromID) == fChromosomeBpMap.end()) {
0114 std::cerr<<"**** Fatal Error *****"<<std::endl;
0115 std::cerr<<"LEMIVModel::ComputeAndSetDamageInput: Cannot find size info for chrom ID "
0116 <<chromID<<std::endl;
0117 std::cerr<<"*************** *****"<<std::endl;
0118 exit(EXIT_FAILURE);
0119 }
0120 for(auto startLoop=0;startLoop<fChromosomeBpMap[chromID];startLoop+=fLoopLength)
0121 {
0122
0123 int n = GetDSBPerLoop(chromoDamage,startLoop);
0124
0125 ndsb+=n;
0126
0127 if(n==1)
0128 nidsb+=1.0;
0129 if(n>=2)
0130 ncdsb+=1.0;
0131 }
0132 }
0133
0134
0135 SetNumDSB(ndsb/fDose);
0136 SetNumDomainIsolated(nidsb/fDose);
0137 SetNumDomainClustered(ncdsb/fDose);
0138 }
0139
0140
0141
0142 int LEMIVModel::GetDSBPerLoop(std::vector<Damage> vecDamage,unsigned int startLoop)
0143 {
0144
0145 std::vector<Damage> loopDamage;
0146
0147 for(int i=0;i<vecDamage.size();i++)
0148 {
0149 if((vecDamage[i].GetCopyNb()>startLoop)&&(vecDamage[i].GetCopyNb()<startLoop+fLoopLength))
0150 {
0151 loopDamage.push_back(vecDamage[i]);
0152 }
0153 }
0154
0155
0156 DamageClassifier dam;
0157 auto classifiedDamage = dam.MakeCluster(loopDamage,fBpForDSB,false);
0158
0159
0160 return dam.GetNumDSB(classifiedDamage);
0161 }
0162
0163
0164
0165 void LEMIVModel::CalculateRepair(double pTMax, double pDeltaT)
0166 {
0167 fUCurve.clear();
0168
0169 for(double time=0.;time<=pTMax;time+=pDeltaT)
0170 {
0171 fUCurve.push_back(std::make_pair(time,ComputeUnrej(time)));
0172 }
0173
0174 }
0175
0176
0177
0178 void LEMIVModel::WriteOutput(std::string pFileName)
0179 {
0180 std::fstream file;
0181 file.open(pFileName.c_str(), std::ios_base::out);
0182
0183 file <<"#============================================= LEMIV MODEL =============================================#\n";
0184 file << " LEMIV Model, CalculateRepair with:\n";
0185 file << "#Number of DSBs: " << fNDSB * fDose << " DSBs.\n";
0186 file << "#Number of domains with clustered DSB, Nc = " << fNc * fDose << " domains.\n";
0187 file << "#Number of domains with isolated DSB, Ni = " << fNi * fDose<< " domains.\n";
0188 file << "#Funrej = " << fFunrej << "\n";
0189 file << "#Tfast = " << fTfast << " h-1 " << "#Tslow = " << fTslow << " h-1\n";
0190 file << "#LoopLength (length of domain) = " << fLoopLength<<" bp \n";
0191 file <<"#========================================================================================================#\n";
0192 file << "Time (h)\tU\n";
0193
0194 for(int i=0;i<fUCurve.size();i++)
0195 {
0196 file << fUCurve[i].first << "\t" << fUCurve[i].second << "\n";
0197 }
0198
0199 file.close();
0200 }