无参结果填加差异结果,类似有参的all_compare.xls
import sys import glob deg = [] deg.extend(sorted(glob.glob(sys.argv[1]+"/"+"*.Differential_analysis_results.xls"))) compares = [] for each in deg: deg_ = each.split("/")[-1].strip(".Differential_analysis_results.xls") compares.append(deg_) print(deg_ + "_" + deg_.split("vs")[0] + "\t" + deg_ + "_" + deg_.split("vs")[1] + "\t" + deg_ + "_log2FoldChange" + "\t" + deg_ + "_pvalue" + "\t" + deg_ + "_padj") deg_result = {} all_annot = open(sys.argv[2]).readlines() header = all_annot[0].strip().split("\t")[0:66] print("\t".join(header)) for each in deg: compare = each.split("/")[-1].strip(".Differential_analysis_results.xls") deg_file = open(each).readlines() headers = deg_file[0].strip().split("\t") compare_control = compare + "_" + compare.split("vs")[0] compare_treat = compare + "_" + compare.split("vs")[1] compare_log2fc = compare + "_log2FoldChange" compare_pvalue = compare + "_pvalue" compare_padj = compare + "_padj" for each_lines in deg_file[1:]: each_value = each_lines.strip().split("\t") gene_id = each_value[0] if gene_id not in deg_result.keys(): deg_result[gene_id] = {} else: next deg_result[gene_id][compare_control] = each_value[1] deg_result[gene_id][compare_treat] = each_value[2] deg_result[gene_id][compare_log2fc] = each_value[3] deg_result[gene_id][compare_pvalue] = each_value[4] deg_result[gene_id][compare_padj] = each_value[5] #all_annot = open(sys.argv[2]).readlines() #header = all_annot[0].strip().split("\t")[0:66] #print("\t".join(header)) for each in all_annot[1:]: each_lines = each.strip().split("\t") befor = "\t".join(each_lines[0:66]) after_list = [] for each_c in compares: compare_control = each_c + "_" + each_c.split("vs")[0] compare_treat = each_c + "_" + each_c.split("vs")[1] compare_log2fc = each_c + "_log2FoldChange" compare_pvalue = each_c + "_pvalue" compare_padj = each_c + "_padj" after_list.append(deg_result[each_lines[0]][compare_control]) after_list.append(deg_result[each_lines[0]][compare_treat]) after_list.append(deg_result[each_lines[0]][compare_log2fc]) after_list.append(deg_result[each_lines[0]][compare_pvalue]) after_list.append(deg_result[each_lines[0]][compare_padj]) after = "\t".join(after_list) print(befor+"\t"+after)