def helper_genie3(X, theta_true, tf_names=[], BEELINE=False): #_string print('Running GENIE3 method', X.shape) theta_true = theta_true.real ex_matrix = pd.DataFrame(X) if args.USE_TF_NAMES == 'yes' and len(tf_names) != 0: tf_names = ['G' + str(n) for n in tf_names] else: tf_names = None gene_names = ['G' + str(c) for c in ex_matrix.columns] ex_matrix.columns = gene_names network = genie3(expression_data=ex_matrix, gene_names=gene_names, tf_names=tf_names) #, verbose=True) pred_edges = np.array(network[['TF', 'target', 'importance']]) G_pred = nx.Graph() # G_pred.add_nodes_from(['G'+str(n) for n in range(args.D)]) G_pred.add_nodes_from(['G' + str(n) for n in range(len(gene_names))]) G_pred.add_weighted_edges_from(pred_edges) # pred_theta = nx.adj_matrix(G_pred).todense() + np.eye(args.D) pred_theta = nx.adj_matrix(G_pred).todense() + np.eye(len(gene_names)) recovery_metrics = report_metrics(np.array(theta_true), np.array(pred_theta)) print( 'GENIE3: FDR, TPR, FPR, SHD, nnz_true, nnz_pred, precision, recall, Fb, aupr, auc' ) print('GENIE3: Recovery of true theta: ', *np.around(recovery_metrics, 3)) res = list(recovery_metrics) if BEELINE: res = [list(recovery_metrics), pred_theta] return res
def main(args): opts, args = parseArgs(args) inDF = pd.read_csv(opts.inFile, sep='\t', index_col=0, header=0) client = Client(processes=False) if opts.algo == 'GENIE3': network = genie3(inDF, client_or_address=client) network.to_csv(opts.outFile, index=False, sep='\t') elif opts.algo == 'GRNBoost2': network = grnboost2(inDF, client_or_address=client) network.to_csv(opts.outFile, index=False, sep='\t') else: print("Wrong algorithm name. Should either be GENIE3 or GRNBoost2.")
output_grnboost2=cell_use+'_grnboost2.csv' output_genie3=cell_use+'_genie3.csv' output_grnboost2_txt=cell_use+'_grnboost2.txt' output_genie3_txt=cell_use+'_genie3.txt' #load data ex_matrix=pd.read_csv(input_file,sep=',') ex_matrix=np.transpose(ex_matrix) tf_names=load_tf_names('mm_mgi_tfs.txt') #infer the gene regulatory network network_n=grnboost2(ex_matrix, tf_names=tf_names, verbose=True) network_g=genie3(ex_matrix, tf_names=tf_names, verbose=True) #for following igraph analysis network_n.to_csv(output_grnboost2,sep='\t') network_g.to_csv(output_genie3,sep='\t') #txt file with no header and index for FAC calculation network_n.to_csv(output_grnboost2_txt,sep='\t',header=False,index=False) network_g.to_csv(output_genie3_txt,sep='\t',header=False,index=False) ####### done!
def test_launch_genie3(self): network_df = genie3(df, tf_names=tfs) self.assertGreater(len(network_df), 100)
def run_genie3(Expr, filename='links.txt', gene_names=None, **kwargs): links = genie3(np.asmatrix(Expr.T), gene_names=gene_names, **kwargs) links.to_csv(filename, sep='\t', index=False, header=False)