def report(params): """ circos_report to markdown file and html file Args: report input dict, key is `yaml`, value is yaml file path:: "xx": path of xx. Returns: dict : key is `yaml`,value is yaml file path """ # handle input yamlin = params["yaml"] indict = yaml.load(open(yamlin)) yamlfile = "circos_report.json" paramstr = json.dumps(indict) cmd1 = "echo '%s' > %s " % (paramstr, yamlfile) tag1 = "make sure the existed yaml file" log.run("tag1", cmd1, i=None, o=[yamlfile]) templ = get_template("circos_report") out = "circos_report.md" cmd = "%s -t %s -j %s -o %s -y" % (render, templ, yamlfile, out) log.run("render circos_report template", cmd) cmd = "%s %s" % (md2html, out) log.run("md2html circos_report ", cmd) outdict = {} outdict["circos_report"] = out yamlout = yamladd(yamlin, outdict) yamlout["circos_report_outdir"] = os.getcwd() return yamlout
def report(params): """ enrichreport to markdown file and html file Args: report input dict, key is `yaml`, value is yaml file path:: "xx": path of xx. Returns: dict : key is `yaml`,value is yaml file path """ # handle input yamlin = params["yaml"] indict = yaml.load(open(yamlin)) enrichreportl = get_template("enrichreport") out = "enrichreport.md" cmd = "%s -t %s -j %s -o %s -y" % (render, enrichreportl, yamlin, out) log.run("render enrichreport template", cmd) cmd = "%s %s" % (md2html, out) log.run("md2html enrichreport ", cmd, o=["html.tgz"]) outdict = {} outdict["enrichreport"] = out yamlout = yamladd(yamlin, outdict) yamlout["enrichreport_outdir"] = os.getcwd() return yamlout
def main_multi(params): '''params is an input dict including the following keys Args: params (dict) : key is `yaml`, value is a yaml file:: plotinfo: { karytotype : karytotype file of circos chrom_unit : the basic number of unit(numeric) species : data file including unit of all chromosomes used for bedtools }, circos_report_template : the report template cnvinp : the output of calling cnv snvinp : the output of calling snv svinp : the output of calling sv circos_multi_tmp : the template of snv&cnv&sv's conf Returns: params (dict) : key is `yaml`, value is a yaml file:: plotinfo : { karytotype : karytotype file of circos chrom_unit : the basic number of unit(numeric) species : data file including unit of all chromosomes used for bedtools snp_min : the min value of snp file snp_max : the max value of snp file indel_min : the min value of indel file indel_max : the max value of indel file cnv_min : the min value of the cnv file cnv_max : the max value of the cnv file outfile : the output name of circos file snp_out : the file are used for the snp input of circos png indel_out : the file are used for the indel input of circos png cnv_out : the file are used as the cnv input of circos' png sv_out : the file are used as the sv input of circos' png } outconf : name of the circos conf file circos_multi_tmp : the template of snv&cnv&sv's conf circos_report_template : the report template snp : the snp file after separated from annotated file indel : the indel file after separated from annotated file snvinp : the output of calling snv cnvinp : the output of calling cnv svinp : the output of calling sv ''' # handle input ... yamlin = params["yaml"] indict = yaml.load(open(yamlin).read()) cycle_param = parse_param(indict) circos_res = data_cycle(cycle_param) # handle output ... outdict = {} outdict["circos_res"] = circos_res outdict["circos_text"] = "circos图由里到外依次为sv,cnv,snp和indel的结果" yamlout = yamladd(yamlin, outdict) return yamlout
def arrange(params): """ circos_report arrange output files Args: params: indict , key is `yaml`, value in yaml file:: circos_res: { patient1: saved circos' info of the patient { conf: the conf file of the specific patient png: the png file of the specific patient } } Returns: dict : key is `yaml`, value is the path of yaml file """ # handle input yamlin = params["yaml"] indict = yaml.load(open(yamlin).read()) pngs = data_cycle(indict) # process cmd log.move(pngs, "report/circos") #handle out outdict = {} outdict["circos_pngs"] = pngs yamlout = yamladd(yamlin, outdict) return yamlout
def arrange(arr_dict, yamlfile): func_pdfs_report = files_report(arr_dict['func_pdfs']) go_dot_pdfs_report = files_report(arr_dict['go_dot_pdfs']) go_net_pdfs_report = files_report(arr_dict['go_net_pdfs']) kegg_pdfs_report = files_report(arr_dict['kegg_pdfs']) func_xls_report = transfor(arr_dict['func_csvs']) go_xls_report = transfor(arr_dict['go_csvs']) go_xls_all = transfor(arr_dict['go_csvs_all']) kegg_xls_report = transfor(arr_dict['kegg_csvs']) kegg_xls_all = transfor(arr_dict['kegg_csvs_all']) if len(kegg_pdfs_report) == 0: kegg_pdf_report = '' else: kegg_pdf_report = kegg_pdfs_report[0] out_dict = {"func_pdfs_report": func_pdfs_report, "go_dot_pdfs_report": go_dot_pdfs_report, "go_net_pdfs_report": go_net_pdfs_report, \ "kegg_pdf_report": kegg_pdf_report, "func_xls_report": func_xls_report, "go_xls_report": go_xls_report, "kegg_xls_report": kegg_xls_report} # report paramters # res = yamladd(yamlfile, out_dict) return res
def arrange(ymlfile): """ {{projName}} arrange output files use log.run """ # handle input indict = yaml.load(open(ymlfile).read()) # process cmd and user log.move to arrange files to report pass # handle output #handle out outdict = {} yamladd(ymlfile, outdict) return ymlfile
def main_cnv(params): '''params is an input dict including the following keys Args: params (dict) : key is `yaml`, value is a yaml file:: plotinfo: { karytotype : karytotype file of circos chrom_unit : the basic number of unit(numeric) species : data file including unit of all chromosomes used for bedtools }, circos_report_template : the report template cnvinp : the output of calling cnv circos_cnv_tmp : the template of cnv's conf Returns: params (dict) : key is `yaml`, value is a yaml file:: plotinfo : { karytotype : karytotype file of circos chrom_unit : the basic number of unit(numeric) species : data file including unit of all chromosomes used for bedtools cnv_min : the min value of the cnv file cnv_max : the max value of the cnv file outfile : the output name of circos file cnv_out : the file are used as the cnv input of circos' png } outconf : name of the circos conf file circos_cnv_tmp : the template of cnv's conf circos_report_template : the report template cnvinp : the output of calling cnv ''' # handle input ... yamlin = params["yaml"] indict = yaml.load(open(yamlin).read()) cycle_param = parse_param(indict) circos_res = data_cycle(cycle_param) # handle output ... outdict = {} outdict["circos_res"] = circos_res outdict["circos_text"] = "circos图为cnv的结果" yamlout = yamladd(yamlin, outdict) return yamlout
def circmd(params): '''params is an input dict which includes the following keys Args: params (dict) : key is `yaml`, value is a yaml file:: 'outconf:': the name of the circos conf file Returns: str : out yaml file ''' # handle input ... yamlin = params["yaml"] indict = yaml.load(open(yamlin).read()) data_cycle(indict) # handle output ... outdict = {} yamlout = yamladd(yamlin, outdict) return yamlout
def report(ymlfile): """ {{projName}} to markdown file and html file """ # handle input indict = yaml.load(open(ymlfile)) render_yml = "{{projName}}_render.yml" cmd = "echo '%s' > %s" % (json.dumps(indict),render_yml) log.run("get {{projName}} args to render",cmd) templ = get_template("{{projName}}") out = "{{projName}}.md" cmd = "%s -t %s -j %s -o %s -y" % (render,templ,render_yml,out) log.run("render {{projName}} template",cmd,docker="jbioi/report",singularity="report.img") cmd = "%s %s" % (md2html,out) log.run("md2html {{projName}} ",cmd,docker="jbioi/report",singularity="report.img") outdict = {} outdict["{{projName}}"] = out yamlout = yamladd(yamlin,outdict) yamlout["{{projName}}_outdir"] = os.getcwd() return ymlfile
def enrich(parms): '''Gene GO functional annotation, GO enrichment and KEGG enrichment Args: parms (dict) : which has the following keys:: { yaml : a yaml file including parms for gene enrich analysis } Returns: dict : ``{"yaml": yamlfile for arrange and report}`` ''' yaml_file = parms["yaml"] fp = open(yaml_file) enrich_dict = yaml.load(fp.read()) fp.close() files = enrich_dict['enrichFiles'] func_pdfs, func_csvs, func_xls = [], [], [] go_dot_pdfs, go_net_pdfs, go_csvs, go_csvs_all, go_xls, go_xls_all = [], [], [], [], [], [] kegg_pdfs, kegg_csvs, kegg_csvs_all, kegg_xls, kegg_xls_all = [], [], [], [], [] id_files = [] for prefix, enrichFile in files.items(): # check file # with open(enrichFile, 'r') as f: head = f.readline().split('\t') try: gidx = head.index("Gene") except ValueError: print("\n\nInput file: {} need the head include 'Gene'.\n\n". format(enrichFile)) # functation annotation # cmd = "%s %s %s" % (funcAnnoGO, enrichFile, prefix) log.run('func annotation', cmd, i=[enrichFile]) # GO enrich analysis # cmd = "%s %s %s" % (enrichGO, enrichFile, prefix) log.run('GO enrich analysis', cmd) # KEGG enrich analysis # cmd = "%s %s %s" % (enrichKEGG, enrichFile, prefix) log.run('KEGG enrich analysis', cmd) for item in ['CC', 'BP', 'MF']: func_pdfs.append('{prefix}.go.{item}.bar.func.pdf'.format( prefix=prefix, item=item)) func_csvs.append('{prefix}.go.{item}.func.csv'.format( prefix=prefix, item=item)) func_xls.append('{prefix}.go.{item}.func.xls'.format(prefix=prefix, item=item)) go_dot_pdfs.append('{prefix}.go.{item}.dot.enrich.pdf'.format( prefix=prefix, item=item)) go_net_pdfs.append('{prefix}.go.{item}.net.enrich.pdf'.format( prefix=prefix, item=item)) go_csvs.append('{prefix}.go.{item}.enrich.csv'.format( prefix=prefix, item=item)) go_csvs_all.append('{prefix}.go.{item}.enrich.all.csv'.format( prefix=prefix, item=item)) go_xls.append('{prefix}.go.{item}.enrich.xls'.format(prefix=prefix, item=item)) go_xls_all.append('{prefix}.go.{item}.enrich.all.xls'.format( prefix=prefix, item=item)) id_files.append("{}.gene_id.csv".format(prefix)) kegg_pdfs.append('{}.KEGG.enrich.pdf'.format(prefix)) kegg_csvs.append('{}.KEGG.enrich.csv'.format(prefix)) kegg_csvs_all.append('{}.KEGG.enrich.all.csv'.format(prefix)) kegg_xls.append('{}.KEGG.enrich.xls'.format(prefix)) kegg_xls_all.append('{}.KEGG.enrich.all.xls'.format(prefix)) out_dict = {'func_pdfs':func_pdfs, 'go_dot_pdfs':go_dot_pdfs, 'go_net_pdfs': go_net_pdfs, 'kegg_pdfs':kegg_pdfs, \ 'func_csvs': func_csvs, 'func_xls': func_xls, 'go_csvs': go_csvs, 'go_xls': go_xls, 'go_csvs_all': go_csvs_all, 'go_xls_all': go_xls_all, 'kegg_csvs': kegg_csvs , \ 'kegg_csvs_all': kegg_csvs_all, 'kegg_xls': kegg_xls, 'kegg_xls_all': kegg_xls_all} res = yamladd(yaml_file, out_dict) # csv2xls # cmd = "{csv2xls} {yamlfile}".format(csv2xls=csv2xls, yamlfile=yaml_file) log.run('csv2xls', cmd) return res