コード例 #1
0
    def make_markers(self, ltId, pos, feature, trajectory_dir, num_cluster):
        # find the feature and coordinate files
        labteks_found = filter(lambda x: x[:len(ltId)]==ltId, os.listdir(trajectory_dir))
        if len(labteks_found) == 0:
            raise ValueError('%s not found in %s' % (ltId, self.base_dir))
        if len(labteks_found) > 1:
            raise ValueError('multiple labteks found')
        labtek_dir = os.path.join(trajectory_dir, labteks_found[0])
        
        feature_file = 'hist_tabFeatures_{:>05}_01.pkl'.format(pos)
        
        try:
            fp = open(os.path.join(labtek_dir, feature_file), 'r')
            tab, coord, hist = pickle.load(fp)
            fp.close()
        except:
            pdb.set_trace()
        tab, toDel = correct_from_Nan(tab, perMovie=False)
        new_coord = []#np.array(coord)[[el for el in range(len(coord)) if el not in toDel]]
        for i,el in enumerate(coord):
            if i not in toDel:
                new_coord.append(el)
            
        if feature in FEATURES:
            tab = histLogTrsforming(tab)
            cm = ColorMap()
            cr = cm.makeColorRamp(256, ["#FFFF00", "#FF0000"])
            
            # centers_PLT0023_11--ex2005_06_03--sp2005_04_19--tt17--c3_w00210_01.pkl 
            # traj_noF_densities_w00210_01.hdf5.pkl
            ending = '%05i_01.pkl' % int(pos)
            feature_index = FEATURES.index(feature)
                        
            values = tab[:,feature_index]
            
            print "Working on feature {} with this range min {} max {}".format(feature, *FEATURE_RANGE[feature])
            print "In this well min {} max {}".format(np.min(values), np.max(values))
            
            colors = [cm.getColorFromMap(x, cr, FEATURE_RANGE[feature][0], FEATURE_RANGE[feature][1])
                      for x in values.tolist()]
            
        elif feature=='labels':
            #we are going to predict on the fly the clustering labels not to have to stock them smw (fast to predict)
            
            f=open('../resultData/features_on_films/labelsKM_whole_k{}.pkl'.format(num_cluster))
            labels, perc, who, length=pickle.load(f); f.close()

            where_=np.where(who=='{}--{}'.format(ltId, pos))[0]
            labels=labels[np.sum(length[:where_]):np.sum(length[:where_+1])]
            assert(len(labels)==len(new_coord))
            colors = [diverging_colors_traj[labels[k]] for k in range(tab.shape[0])]
            
        markers = {}
        for i, track_coord in enumerate(new_coord):                    
            tvec, xvec, yvec = track_coord
            for t, x, y in zip(tvec, xvec, yvec):
                if not t in markers:
                    markers[t] = []
                markers[t].append((x, y, colors[i]))
        return markers
コード例 #2
0
 def getMask(self):
     file_=os.path.join(self.settings.outputFolder, self.plate, self.settings.trajFeaturesFilename.format(self.well))
 
     f=open(file_, 'r')
     arr, _,__= pickle.load(f)
     f.close()
     
     _, toDel = correct_from_Nan(arr, perMovie=False)
     
     return toDel
コード例 #3
0
                      help="The well which you are interested in")
    
    (options, args) = parser.parse_args()

    print "Working on ", options.plate, options.well

    model_file='../resultData/features_on_films/kmeans_model.pkl'
    in_folder = '/share/data20T/mitocheck/tracking_results'
    out_folder = '../resultData/features_on_films/trajectory_cluster_distributions'
    try:
        f=open(os.path.join(in_folder, options.plate, 'hist_tabFeatures_{}.pkl'.format(options.well)))
        arr, _, _= pickle.load(f); f.close()
    except:
        labels=None
    else:
        arr, _ = correct_from_Nan(arr, perMovie=False)
        
        f=open(model_file, 'r')
        model, mean, std, pca, pca_std=pickle.load(f)
        
        labels=exploitingKMeans_wModel(model, arr, mean, std, pca_std, pca, num_PC=7)
        
    finally:
        try:
            f=open(os.path.join(out_folder, 'trajectory_cluster_{}.pkl'.format(options.plate)))
            d=pickle.load(f)
            f.close()
        except:
            d={}
        finally:
            d.update({options.well:labels})