def addTreatment(xb, dose): is_ctrl = xb in CONTROLS.values() c=None if not is_ctrl: if xb not in CONTROLS: warn('This xenobiotic {} has no control defined yet.'.format(xb)) else: controls = Treatment.objects.filter(xb = CONTROLS[xb])#.get(dose =dose) if len(controls)==0: c=addTreatment(CONTROLS[xb], dose) elif len(controls)==1: if controls[0].dose==dose: c=controls[0] else: c=addTreatment(CONTROLS[xb], dose) else: controls = controls.filter(dose=dose) if len(controls)==0: c=addTreatment(CONTROLS[xb], dose) elif len(controls)>1: raise else: c=controls[0] treatment = Treatment(xb=xb, dose = dose, is_ctrl = is_ctrl, ctrl = c) treatment.save() return treatment
def _getExperiments(self): if self.settings.norm=='neg_ctrl': if self.compound not in CONTROLS.values(): return self._getUsable(), None else: exp_list = [] filter_=[] for plate in plates: l= self._getUsable() size_=2 if len(l)>3 else 1 f_=np.random.permutation(len(l)) filter_.append(f_[size_:]); exp_list.extend(['{}_{}'.format(el[0], el[1]) for el in np.array(l)[f_[:size_]]]) if self.verbose: print "Chosen for plate ", plate, np.array(l)[f_[:size_]] return exp_list, filter_ elif self.settings.norm=='plate': return self._getUsable(), None else: raise ValueError
def parameterStabilityEvaluation(well_num=50,n_list=list([0.4,0.5,0.6,0.7,0.8]), h_list=[10], deg_list=[2,3], pheno_list=['Anaphase_ch1', 'Apoptosis_ch1', 'Folded_ch1', 'Interphase_ch1', 'Metaphase_ch1', 'Polylobbed_ch1', 'Prometaphase_ch1', 'WMicronuclei_ch1'], loadingFolder='/media/lalil0u/New/projects/Xb_screen/dry_lab_results', passed=None): ''' Here we're looking at how well results are robust to parameters change (result r1) and how well a subset of parameters is able to separate experiments (variance of r2). ''' param_num=len(n_list)*len(h_list)*len(deg_list) param_list=[] if passed is None: passed,_,_,_=quality_control.computingToRedo(threshold_flou=0.4, threshold_init_cell_count=20) selected=np.array(passed)[np.random.permutation(len(passed))[:well_num]] processedDict={}; result=defaultdict(list) for pl,w in selected: if pl not in processedDict: print "Opening processed dictionary file for pl ", pl f=open(os.path.join(loadingFolder, "processedDictResult_P{}.pkl".format(pl))) processedDict[pl]=pickle.load(f); f.close() try: currCtrl=quality_control.usable_XBSC(CONTROLS[processedDict[pl][int(w)]['Xenobiotic']], 0, pl) except KeyError: if processedDict[pl][int(w)]['Xenobiotic'] in CONTROLS.values(): currCtrl=quality_control.usable_XBSC(processedDict[pl][int(w)]['Xenobiotic'], 0, pl) else: raise KeyError for pheno in pheno_list: y_exp=np.array(processedDict[pl][int(w)][pheno]) for n,h,deg in product(n_list, h_list, deg_list): if (n,h,deg) not in param_list: param_list.append((n,h,deg)) r=[] for pl, ctrl in filter(lambda x: x[1]!=w,currCtrl): y_ctrl = np.array(processedDict[pl][int(ctrl)][pheno]) _, r_exp=localReg(y_exp, n, h, deg, plot=False) _, r_ctrl = localReg(y_ctrl, n, h, deg, plot=False) r.append(np.max(np.abs(r_exp-r_ctrl))) result[pheno].append(np.median(r)) print "Done with local regressions" for pheno in pheno_list: np.reshape(result[pheno], newshape=(well_num, param_num)) r1=[np.ones(shape=(param_num, param_num), dtype=float) for pheno in pheno_list] r2=[np.zeros(shape=(param_num,), dtype=list) for pheno in pheno_list] for i, pheno in enumerate(pheno_list): result[pheno]=np.reshape(result[pheno], newshape=(well_num, param_num)) for k in range(param_num): r2[i][k]=[0] iter_ = np.nditer(result[pheno][1:,k], flags=['c_index']) #one-dim array: the order is the same in C or F while not iter_.finished : r2[i][k]= np.hstack((r2[i][k],[a-iter_[0] for a in np.nditer(result[pheno][:iter_.index+1,k])])) iter_.iternext() r2[i][k]=np.abs(r2[i][k][1:])/np.mean(result[pheno][:,k]) for j in range(k): r1[i][k,j]=spearmanr(result[pheno][:,k],result[pheno][:,j])[0] r1[i][j,k]=r1[i][k,j] return passed, param_list,r1, r2