def main(): ontology = dag.DAG(config.go_fpath) #gene_annotation = utils.get_annotation(config.annotation_fpath, config.filtered_annotation_fpath, ontology.get_root()) gene_annotation = utils.get_annotation(config.annotation_fpath, config.filtered_annotation_fpath, ontology.get_root()) print "Number of annotated genes:%d" % len(gene_annotation) network = utils.create_network(config.network_fpath) print "Number of nodes in network:%d" % network.number_of_nodes() '''
non_sim_avg = 0.0 for node in network.nodes(): if not node in neighbors: count += 1 nterms = gene_annotation[node] sim = compute_gene_sim_total(nterms, terms) #sim = compute_gene_sim_max(nterms, terms) non_sim_avg += sim non_sim_avg /= count print "%s, %f, %f" % (gene, sim_avg, non_sim_avg) if __name__ == "__main__": dag = DAG(config.go_fpath) gene_annotation = utils.get_annotation(config.annotation_fpath, config.filtered_annotation_fpath, dag.get_root().id) term_ic = utils.calculate_ic(gene_annotation, dag, config.ic_fpath) network = utils.create_network(config.network_fpath) # Remove unannotated gene from network for node in network.nodes(): if not node in gene_annotation: network.remove_node(node) # Remove individual nodes by get the largest indepedent connected component network = nx.connected_component_subgraphs(network)[0] sim_cache = utils.read_sim(config.simcache_fpath) #compute_term_in_neighbour_ratio() #compute_avg_term_num()
else: csv = pd.read_csv('data/{}_labels.csv'.format(args.phase)) x = np.array([ cv2.cvtColor( cv2.imread('data/{}/{:.0f}_{:.0f}.tif'.format( args.phase, j['slide'], j['rid'])), cv2.COLOR_BGR2RGB) for _, j in csv.iterrows() ]) np.save('data/{}/y.npy'.format(args.phase), np.array(csv['y'].tolist())) np.save('data/{}/x.npy'.format(args.phase), x) elif args.opt == 'get_annotation': filelist = glob.glob('data/cells/Sedeen/*.session.xml') filelist.sort() annotations = get_annotation(filelist) if not os.path.exists('segmentation&classification/cells'): os.mkdir('segmentation&classification/cells') np.save('segmentation&classification/cells/annotation.npy', annotations) elif args.opt == 'get_centroid': seg = np.load('segmentation&classification/{}/seg.npy'.format(args.phase)) def _add_data(region_prop): tmp = [] for j in region_prop: if j.major_axis_length / j.minor_axis_length < 3 and j.area < 1200: tmp.append(j.centroid + (j.label, )) tmp = np.array(tmp) return tmp