예제 #1
0
def replicateCorrelationPlots(arr, who, conditions, ax=None, refPlate=None):
    '''
    This is to look at replicability from a well perspective (and not condition perspective).
    If the 
    Arguments:
    - conditions: list of conditions ordered as the data in arr
    - who: list or array of (plate, well) info
    '''
    if refPlate==None:
        if type(who)==list:
            who=np.array(who)
        if type(conditions)==list:
            conditions=np.array(conditions)

        f,axes=p.subplots(3,4,sharex=True, sharey=True)
        for i,plate in enumerate(['201114', '121214', '271214']):
            replicateCorrelationPlots(arr, who, conditions, ax=axes[i], refPlate=plate)
        p.show()
        return
    else:
        if ax==None:
            raise ValueError
        
        for i,currPlate in enumerate(filter(lambda x: x!=refPlate, plates)):
            currConditions = conditions[np.where(who[:,0]==currPlate)]
            currArr = arr[np.where((who[:,0]==currPlate))]
            for k,cond in enumerate(currConditions):
                refCond = np.median(arr[np.where((conditions==cond)&(who[:,0]==refPlate))])
                ax[i].scatter(refCond, currArr[k], color=couleurs[plates.index(currPlate)])
                ax[i].plot(np.linspace(np.min(currArr), np.max(currArr), 10), np.linspace(np.min(currArr), np.max(currArr), 10))
                ax[i].set_xlabel(refPlate); ax[i].set_ylabel(currPlate); ax[i].grid(True)
                
        return
def plotColorRampedResults(result, who, dose_list, compound_list, title="", 
                           fig_filename="{}_condition.png",
                           savingFolder='/media/lalil0u/New/projects/Xb_screen/dry_lab_results/MITOSIS/phenotype_analysis_up_down'):
    f=p.figure(figsize=(24,16));ax=f.add_subplot(211)
    for i,el in enumerate(dose_list):
        ax.scatter(i,result[i], color=cr[el])
        ax.text(i, result[i], compound_list[i][0], fontsize=10)
    ax.grid(True)
    ax.set_xlabel("Wells"); ax.set_ylabel("Distances")
    ax.set_title(title)
    
    ax=f.add_subplot(212)
    for i,el in enumerate(dose_list):
        ax.scatter(i,result[i], color=couleurs[plates.index(who[i,0])])
    for i,pl in enumerate(plates):
        ax.scatter(0,0, label=pl, color=couleurs[i])
    ax.legend()
    ax.grid(True)
    ax.set_xlabel("Wells"); ax.set_ylabel("Distances")
    
    p.savefig(os.path.join(savingFolder, fig_filename.format(title.split('-')[0])))
    return
    def __call__(self):
        if not os.path.isdir(self.settings.savingFolder):
            os.mkdir(self.settings.savingFolder)
        #i.Need to get the corresponding experiments - separate two cases depending if it's a control or no
        exp_list, filter_ = self._getExperiments()

        #ii. Need to measure the distances
        r=np.zeros(shape=(len(exp_list), len(self.pheno_list)))
        all_regularized_data=defaultdict(list)
        for i,exp in enumerate(exp_list):
            pl,w=exp if len(exp)==2 else exp.split('_')
            print pl
            wellPA = wellPhenoAnalysis(self.settings, pl, w, compound=self.compound, 
                                       localRegMeasure=self.localRegMeasure,
                                       nn=self.nn, pheno_list=self.pheno_list, verbose=self.verbose)
            r[i], exp_regularized_data=wellPA(filter_=filter_[plates.index(pl)]) if filter_ is not None else wellPA()
            for el in exp_regularized_data:
                all_regularized_data[el].append(exp_regularized_data[el]) 
            
        #iii. Need to save it
        self.save(r, all_regularized_data, exp_list)
        
        return 1