for smoothv, weightv in weights: d3p += smooth(raw, int(smoothv)) * weightv raw = d3p else: #print(type(weights),np.nanmean(raw)) if weights == "submed": raw -= np.nanmedian(raw) d3p = raw #print(weights, "here") if args.nan0 and "Exp" not in signal: d3p[np.isnan(d3p)] = 0 btosee.append([x, d3p, signal]) if sup_sig != None: btosee.append(sup_sig) sup_sig = None ToSee.append(btosee) """ for signal in args.filename: print(signal) x, d3p = replication_data(cell, "", chromosome=ch, start=start, end=end, resolution=resolution, raw=False,filename=signal) ToSee += [[[x,d3p, signal]]] """ plotly_blocks(x, ToSee, name=args.name, default="lines")
weight_t = np.sum(x0[tstart - start:tend - start]) x0[tstart - start:tend - start] = weight_t * np.array(opti.best) / np.sum(opti.best) end_error, gMRTp, gMRT, gRFD, gRFDs, wRFD = run(x0, ndiff, start, end) print("New Global error", initerror) if cell != "Cerevisae": ToSee = [[[1 - gMRTpi, "MRTi"], [1 - gMRTp, "MRT"], [ x[::10 // resolution], 1 - gMRT[:len(x[::10 // resolution])], "MRTexp" ]], [[gRFD, "RFDExp"], [gRFDsi, "RFDsimi_init"], [gRFDs, "RFDsim_end"]]] else: ToSee = [[[1 - gMRTpi, "MRTi"], [1 - gMRTp, "MRT"], [x, 1 - gMRT, "MRTexp"]], [[gRFD, "RFDExp"], [gRFDsi, "RFDsimi_init"], [gRFDs, "RFDsim_end"]]] ToSee += [[[init, "init"], [x0, "Optimised"]], [[smooth(np.abs(gRFD - gRFDs), 250), "dsm"]]] plotly_blocks(x, ToSee, name=args.name + "global_%i" % i, default="lines") pd.DataFrame({ "signalValue": x0, "chromStart": x * 1000, "chromEnd": x * 1000, "chrom": ["chr%i" % ch] * len(x) }).to_csv(args.name + "optimised_signal.csv", index=False, sep="\t") print(initerrorg, end_error)
# print(mask_RFD) if args.input: ToSee += [[[d3ps, "initiation"]]] if "Yeast" in cell: _, tere = replication_data(cell, "ter", chromosome=ch, start=start, end=end, resolution=1, raw=False) #print(tere) ToSee += [[[tere * 20, "TerExp"], [Pt, "ProbaTer"]]] ToSee += [[[stallp, "stalling"]]] if not args.only_one or (args.only_one and ch == 1): plotly_blocks(x, ToSee, name=name_w + ".html", default="lines") print(len(GData), len(d3p)) GData["signal"] = d3p GData.to_csv(args.name + "global_profiles.csv", index=False, float_format="%.2f") ldatg.to_csv(args.name + "global_scores.csv", index=False) pRFD = stats.pearsonr(np.concatenate(gRFD), np.concatenate(gRFDe)), sRFD = np.std(np.concatenate(gRFD) - np.concatenate(gRFDe)) pMRT = stats.pearsonr(np.concatenate(gMRT), np.concatenate(gMRTe)), sMRT = np.std(np.concatenate(gMRT) - np.concatenate(gMRTe)) meanCodire = np.mean(codire) print(args.name + "global_corre.csv")
initerror,MRTpi,MRTi,RFDi,RFDsi,wRFDt = evaluate(x0t,score=False) print("Initial local error",initerror) opti = PSO(evaluate,bounds=[0,1],x0=x0t,num_particles=15,maxiter=20,velocity_scale=100/len(x0t)) end_error,MRTp,MRT,RFD,RFDs,wRFDt = evaluate(opti.best,score=False) #print("End error",end_error) if cell != "Cerevisae": ToSee = [[[1-MRTpi, "MRTi"],[1-MRTp, "MRT"], [x[::10//resolution], 1 - MRT[:len(x[::10//resolution])], "MRTexp"]], [[RFD, "RFDExp"], [RFDsi, "RFDsimi_init"],[RFDs, "RFDsim_end"]]] else: ToSee = [[[1-MRTpi, "MRTi"],[1-MRTp, "MRT"], [x[tstart:tend], 1 - MRT, "MRTexp"]], [[RFD, "RFDExp"], [RFDsi, "RFDsimi_init"],[RFDs, "RFDsim_end"],[RFDs+np.mean(left+right,axis=0),"Corrected2"],[gRFDsi[int((tstart-start)/res):int((tend-start)/res)]]]] ToSee += [[[initt,"init"],[opti.best,"Optimised"]],[[np.mean(left,axis=0)],[np.mean(right,axis=0)]]] plotly_blocks(x[tstart:tend],ToSee, name=args.name+"local_%i" % i, default="lines") #Print reconneect: exclude = int(len(x0t) * 0.1) weight_t = np.sum(x0[tstart-start:tend-start][exclude:-exclude]) x0[tstart-start:tend-start][exclude:-exclude] = weight_t * np.array(opti.best)[exclude:-exclude] / np.sum(opti.best[exclude:-exclude]) end_error,gMRTp,gMRT,gRFD,gRFDs,wRFD = run(x0,ndiff,start,end) print("New Global error",initerror) if cell != "Cerevisae": ToSee = [[[1-gMRTpi, "MRTi"],[1-gMRTp, "MRT"], [x[::10//resolution], 1 - gMRT[:len(x[::10//resolution])], "MRTexp"]], [[gRFD, "RFDExp"], [gRFDsi, "RFDsimi_init"],[gRFDs, "RFDsim_end"]]] else: ToSee = [[[1-gMRTpi, "MRTi"],[1-gMRTp, "MRT"], [x, 1 - gMRT, "MRTexp"]],