Exemplo n.º 1
0
def GetTreeListOrder(treefile, outpath):
    #Create the Itol class
    itl = Itol.Itol()
    #Set the tree file
    tree = treefile

    dirname = os.path.dirname(treefile)
    if dirname == "":
        dirname = "."
    if outpath == "":
        outpath = dirname
    elif not os.path.exists(outpath):
        os.system("mkdir -p %s" % (outpath))

    rootname = os.path.basename(os.path.splitext(treefile)[0])

    #===================================
    itl.add_variable('treeFile', tree)
    itl.add_variable('treeName', rootname)
    itl.add_variable('treeFormat', 'newick')
    #===================================
    # Check parameters
    # itl.print_variables()
    #Submit the tree
    print ''
    good_upload = itl.upload()
    if good_upload == False:
        print 'There was an error:' + itl.comm.upload_output
        return 1


#Export to pdf
    print 'Exporting to pdf'
    tree_id = itl.comm.tree_id

    itol_exporter = itl.get_itol_export()
    itol_exporter.set_export_param_value('format', "eps")
    itol_exporter.set_export_param_value('displayMode', "normal")
    itol_exporter.set_export_param_value('lineWidth', "1")
    epsfile = outpath + os.sep + rootname + '.itolnormal.eps'
    pdffile = outpath + os.sep + rootname + '.itolnormal.pdf'
    itol_exporter.export(epsfile)
    orderfile = outpath + os.sep + rootname + '.listorder.txt'

    os.system("epstopdf %s" % epsfile)
    os.system("pdftotext -nopgbrk %s %s" % (pdffile, orderfile))
    os.system("rm -f %s" % pdffile)
    os.system("rm -f %s" % epsfile)
    print 'list order output to ', orderfile
Exemplo n.º 2
0
def Itol_Tree_m0(pfamid, datapath, outpath):  #{{{
    #Create the Itol class
    itl = Itol.Itol()
    #Set the tree file
    tree = datapath + os.sep + pfamid + '.kalignp.fasttree'
    (dataset1, dataset2, dataset3, dataset4) = ("", "", "", "")
    if not os.path.exists(tree):
        print >> sys.stderr, "tree file %s does not exist. Ignore" % (tree)
        return 1
    t = Tree(tree)
    leaves = t.get_leaves()
    numLeave = len(leaves)

    fontsize = GetFontSize(numLeave)

    dataset1 = datapath + os.sep + pfamid + '.numTM_and_io.txt'
    dataset2 = datapath + os.sep + pfamid + '.cmpclass.colordef.txt'
    #    dataset3 = datapath + os.sep + pfamid + '.ntermstate.colordef.txt'
    dataset4 = datapath + os.sep + pfamid + '.cluster.colordef.txt'

    colordeffile = datapath + os.sep + pfamid + '.pfam.colordef.txt'
    branchlabelfile = datapath + os.sep + pfamid + '.branchlabel.txt'

    #===================================
    itl.add_variable('treeFile', tree)
    itl.add_variable('treeName', 'PF00854')
    itl.add_variable('treeFormat', 'newick')
    if os.path.exists(colordeffile):
        itl.add_variable('colorDefinitionFile', colordeffile)
    if os.path.exists(branchlabelfile):
        itl.add_variable('branchLabelsFile', branchlabelfile)

#===================================
    if os.path.exists(dataset1):
        itl.add_variable('dataset1File', dataset1)
        itl.add_variable('dataset1Label', 'numTM_and_io')
        itl.add_variable('dataset1Separator', 'comma')
        itl.add_variable('dataset1Type', 'multibar')
        itl.add_variable('dataset1PreventOverlap', '1')
        itl.add_variable('dataset1Color', '#FF0000')

#===================================
    if os.path.exists(dataset2):
        itl.add_variable('dataset2File', dataset2)
        itl.add_variable('dataset2Label', 'cmpclass')
        itl.add_variable('dataset2Separator', 'comma')
        itl.add_variable('dataset2Type', 'colorstrip')
        itl.add_variable('dataset2StripWidth', '200')
        itl.add_variable('dataset2PreventOverlap', '1')
        itl.add_variable('dataset2ColoringType', 'both')

#===================================
    if os.path.exists(dataset3):
        itl.add_variable('dataset3File', dataset3)
        itl.add_variable('dataset3Label', 'NtermState')
        itl.add_variable('dataset3Separator', 'comma')
        itl.add_variable('dataset3Type', 'colorstrip')
        itl.add_variable('dataset3StripWidth', '200')
        itl.add_variable('dataset3PreventOverlap', '1')
        itl.add_variable('dataset3ColoringType', 'both')

#===================================
    if os.path.exists(dataset4):
        itl.add_variable('dataset4File', dataset4)
        itl.add_variable('dataset4Label', 'cluster')
        itl.add_variable('dataset4Separator', 'comma')
        itl.add_variable('dataset4Type', 'colorstrip')
        itl.add_variable('dataset4StripWidth', '200')
        itl.add_variable('dataset4PreventOverlap', '1')
        itl.add_variable('dataset4ColoringType', 'both')
        itl.add_variable('dataset4BranchColoringType', 'both')

#itl.add_variable('dataset1BarSizeMax','1')

#===================================
# Check parameters
# itl.print_variables()

#Submit the tree
    print ''
    print 'Uploading the tree.  This may take some time depending on how large the tree is and how much load there is on the itol server'
    good_upload = itl.upload()
    if good_upload == False:
        print 'There was an error:' + itl.comm.upload_output
        sys.exit(1)

#Read the tree ID
    print 'Tree ID: ' + str(itl.comm.tree_id)

    #Read the iTOL API return statement
    print 'iTOL output: ' + str(itl.comm.upload_output)

    #Website to be redirected to iTOL tree
    print 'Tree Web Page URL: ' + itl.get_webpage()

    # Warnings associated with the upload
    print 'Warnings: ' + str(itl.comm.warnings)

    #Export to pdf
    print 'Exporting to pdf'
    itol_exporter = itl.get_itol_export()
    #itol_exporter = itolexport.ItolExport()
    #itol_exporter.set_export_param_value('tree','18793532031912684633930')
    itol_exporter.set_export_param_value('format', 'eps')
    itol_exporter.set_export_param_value('displayMode', "circular")
    itol_exporter.set_export_param_value('showBS', "0")
    itol_exporter.set_export_param_value('fontSize', fontsize)
    itol_exporter.set_export_param_value('alignLabels', "1")
    itol_exporter.set_export_param_value(
        'datasetList', 'dataset1,dataset2,dataset3,dataset4')
    epsfile = outpath + os.sep + pfamid + '-itol.eps'
    pdffile = outpath + os.sep + pfamid + '-itol.pdf'
    jpgfile = outpath + os.sep + pfamid + '-itol.jpg'
    thumbfile = outpath + os.sep + "thumb." + pfamid + '-itol.jpg'
    itol_exporter.export(epsfile)
    os.system("epstopdf %s" % epsfile)
    os.system("convert %s %s" % (epsfile, jpgfile))
    os.system("convert -thumbnail 200 %s %s" % (jpgfile, thumbfile))
    print 'exported tree to ', pdffile
Exemplo n.º 3
0
def Itol_Tree_m0(treefile, outpath, method):  #{{{
    #Create the Itol class
    itl = Itol.Itol()
    #Set the tree file
    tree = treefile

    dirname = os.path.dirname(treefile)
    if dirname == "":
        dirname = "."
    if outpath == "":
        outpath = dirname
    elif not os.path.exists(outpath):
        os.system("mkdir -p %s" % (outpath))

    treefile_without_ext = os.path.splitext(treefile)[0]
    rootname = os.path.basename(os.path.splitext(treefile)[0])

    if not os.path.exists(tree):
        print >> sys.stderr, "tree file %s does not exist. Ignore" % (tree)
        return 1

    #t = Tree(tree)
    #leaves = t.get_leaves()
    #numLeave = len(leaves)

    colordeffile = treefile_without_ext + '.pfam.colordef.txt'
    branchlabelfile = treefile_without_ext + '.branchlabel.txt'
    dataset1 = ""
    dataset2 = ""
    dataset3 = ""
    dataset4 = ""

    dataset1 = treefile_without_ext + '.numTM_and_io.txt'
    dataset2 = treefile_without_ext + '.domain.txt'
    dataset3 = treefile_without_ext + '.taxo.colordef.txt'
    dataset4 = treefile_without_ext + '.cluster.colordef.txt'

    numLeave = len(open(dataset1, "r").readlines()) - 2
    fontsize = GetFontSize(numLeave)

    #===================================
    itl.add_variable('treeFile', tree)
    itl.add_variable('treeName', rootname)
    itl.add_variable('treeFormat', 'newick')
    if os.path.exists(colordeffile):
        itl.add_variable('colorDefinitionFile', colordeffile)
    if os.path.exists(branchlabelfile):
        itl.add_variable('branchLabelsFile', branchlabelfile)

#===================================
    if os.path.exists(dataset1):
        itl.add_variable('dataset1File', dataset1)
        itl.add_variable('dataset1Label', 'numTM_and_io')
        itl.add_variable('dataset1Separator', 'comma')
        itl.add_variable('dataset1Type', 'multibar')
        itl.add_variable('dataset1PreventOverlap', '1')
        itl.add_variable('dataset1MultiBarAlign', '0')
        itl.add_variable('dataset1Color', '#FF0000')
        itl.add_variable('dataset1BarSizeMax', '1000')
#===================================
    if os.path.exists(dataset2):
        itl.add_variable('dataset2File', dataset2)
        itl.add_variable('dataset2Label', 'Domain')
        itl.add_variable('dataset2Separator', 'comma')
        itl.add_variable('dataset2Type', 'domains')
        itl.add_variable('dataset2ProtSizeMax', '1000')
        itl.add_variable('dataset2PreventOverlap', '1')
        itl.add_variable('dataset2CirclesSpacing', '100')
#===================================
    if os.path.exists(dataset3):
        itl.add_variable('dataset3File', dataset3)
        itl.add_variable('dataset3Label', 'taxonomy')
        itl.add_variable('dataset3Separator', 'comma')
        itl.add_variable('dataset3Type', 'colorstrip')
        itl.add_variable('dataset3StripWidth', '300')
        itl.add_variable('dataset3PreventOverlap', '1')
        itl.add_variable('dataset3ColoringType', 'both')
        itl.add_variable('dataset3CirclesSpacing', '100')
#===================================
    if os.path.exists(dataset4):
        itl.add_variable('dataset4File', dataset4)
        itl.add_variable('dataset4Label', 'cluster')
        itl.add_variable('dataset4Separator', 'comma')
        itl.add_variable('dataset4Type', 'colorstrip')
        itl.add_variable('dataset4StripWidth', '200')
        itl.add_variable('dataset4PreventOverlap', '1')
        itl.add_variable('dataset4ColoringType', 'both')
#itl.add_variable('dataset1BarSizeMax','1')

#===================================
# Check parameters
# itl.print_variables()

#Submit the tree
    print ''
    print 'Uploading the tree.  This may take some time depending on how large the tree is and how much load there is on the itol server'
    good_upload = itl.upload()
    if good_upload == False:
        print 'There was an error:' + itl.comm.upload_output
        return 1

#Read the tree ID
    print 'Tree ID: ' + str(itl.comm.tree_id)

    #Read the iTOL API return statement
    print 'iTOL output: ' + str(itl.comm.upload_output)

    #Website to be redirected to iTOL tree
    print 'Tree Web Page URL: ' + itl.get_webpage()

    # Warnings associated with the upload
    print 'Warnings: ' + str(itl.comm.warnings)

    #Export to pdf
    print 'Exporting to pdf'
    itol_exporter = itl.get_itol_export()
    #itol_exporter = itolexport.ItolExport()
    #itol_exporter.set_export_param_value('tree','18793532031912684633930')
    itol_exporter.set_export_param_value('format', 'eps')
    itol_exporter.set_export_param_value('displayMode', "circular")
    itol_exporter.set_export_param_value('showBS', "0")
    itol_exporter.set_export_param_value('fontSize', fontsize)
    itol_exporter.set_export_param_value('alignLabels', "1")
    itol_exporter.set_export_param_value(
        'datasetList', 'dataset1,dataset2,dataset3,dataset4')
    epsfile = treefile_without_ext + '.m%d.itol.eps' % (method)
    pdffile = treefile_without_ext + '.m%d.itol.pdf' % (method)
    jpgfile = treefile_without_ext + '.m%d.itol.jpg' % (method)
    svgfile = treefile_without_ext + '.m%d.itol.svg' % (method)
    thumbfile = treefile_without_ext + '.m%d.itol.thumb.jpg' % (method)
    itol_exporter.export(epsfile)
    os.system("epstopdf %s" % epsfile)
    os.system("convert  %s %s" % (epsfile, jpgfile))
    os.system("convert -thumbnail 200 %s %s" % (jpgfile, thumbfile))
    print 'exported tree to ', pdffile

    itol_exporter.set_export_param_value('format', 'svg')
    itol_exporter.export(svgfile)
Exemplo n.º 4
0
def Itol_Tree(pfamid, datapath, outpath):
#Create the Itol class
    itl = Itol.Itol()
#Set the tree file
    treefile = "%s%s%s%s"%(datapath ,  os.sep , pfamid ,
            ".TMpro.clustalo10.fasttree")
    taxofile = "%s%s%s%s"%(datapath , os.sep , pfamid ,
            "-taxonomy-file.txt")
    TMdeffile = "%s%s%s%s"%(datapath , os.sep , pfamid ,
            "tms.txt")

    if not os.path.exists(treefile):
        print >> sys.stderr, "tree file %s does not exist. Ignore" %(treefile)
        return 1
    if myfunc.checkfile(taxofile, "taxofile") != 0:
        return 1

    
    numLeave = len(open(taxofile, "r").readlines())

#     t = Tree(treefile)
#     leaves = t.get_leaves()


    fontsize = GetFontSize(numLeave)

    colordeffile = taxofile
    branchlabelfile = ""
    dataset1 = ""
    dataset2 = ""
    dataset3 = ""
    dataset4 = ""

    dataset1 = TMdeffile
#===================================
    itl.add_variable('treeFile',treefile)
    itl.add_variable('treeName', pfamid)
    itl.add_variable('treeFormat','newick')
    if os.path.exists(colordeffile):
        itl.add_variable('colorDefinitionFile', colordeffile)
    if os.path.exists(branchlabelfile):
        itl.add_variable('branchLabelsFile', branchlabelfile)

    if os.path.exists(dataset1):
        itl.add_variable('dataset1File',dataset1)
        itl.add_variable('dataset1Label','numTM_and_repeat')
        itl.add_variable('dataset1Separator','comma')
        itl.add_variable('dataset1Type','domains')
        itl.add_variable('dataset1PreventOverlap','1')
        itl.add_variable('dataset1Color','#FF0000')
#        itl.add_variable('dataset1BarSizeMax','300')

#===================================
#     itl.add_variable('dataset1File',dataset1)
#     itl.add_variable('dataset1Label','numTM')
#     itl.add_variable('dataset1Separator','comma')
#     itl.add_variable('dataset1Type','simplebar')
#     itl.add_variable('dataset1Color','#FF0000')

#===================================
    if os.path.exists(dataset2):
        itl.add_variable('dataset2File', dataset2)
        itl.add_variable('dataset2Label', 'taxonomy')
        itl.add_variable('dataset2Separator','comma')
        itl.add_variable('dataset2Type','colorstrip')
        itl.add_variable('dataset2StripWidth','300')
        itl.add_variable('dataset2PreventOverlap','1')
        itl.add_variable('dataset2ColoringType','both')
        itl.add_variable('dataset2CirclesSpacing','100')


#===================================
    if os.path.exists(dataset3):
        itl.add_variable('dataset3File', dataset3)
        itl.add_variable('dataset3Label', 'pfam')
        itl.add_variable('dataset3Separator','tab')
        itl.add_variable('dataset3Type','colorstrip')
#        itl.add_variable('dataset3Type','ColorDefinitionFile')
#        itl.add_variable('dataset3StripWidth','300')
#        itl.add_variable('dataset3PreventOverlap','1')
#        itl.add_variable('dataset3ColoringType','both')
#        itl.add_variable('dataset3CirclesSpacing','100')

#===================================
    if os.path.exists(dataset4):
        itl.add_variable('dataset4File', dataset4)
        itl.add_variable('dataset4Label', 'cluster')
        itl.add_variable('dataset4Separator','comma')
        itl.add_variable('dataset4Type','colorstrip')
        itl.add_variable('dataset4StripWidth','200')
        itl.add_variable('dataset4PreventOverlap','1')
        itl.add_variable('dataset4ColoringType','both')
#itl.add_variable('dataset1BarSizeMax','1')

#===================================
# Check parameters
# itl.print_variables()


#Submit the tree
    print ''
    print 'Uploading the tree.  This may take some time depending on how large the tree is and how much load there is on the itol server'
    good_upload = itl.upload()
    if good_upload == False:
        print 'There was an error:'+itl.comm.upload_output
        sys.exit(1)

#Read the tree ID
    print 'Tree ID: '+str(itl.comm.tree_id)

#Read the iTOL API return statement
    print 'iTOL output: '+str(itl.comm.upload_output)

#Website to be redirected to iTOL tree
    print 'Tree Web Page URL: '+itl.get_webpage()

# Warnings associated with the upload
    print 'Warnings: '+str(itl.comm.warnings)

#Export to pdf
    print 'Exporting to pdf'
    itol_exporter = itl.get_itol_export()
#itol_exporter = itolexport.ItolExport()
#itol_exporter.set_export_param_value('tree','18793532031912684633930')
    itol_exporter.set_export_param_value('format', 'eps')
    itol_exporter.set_export_param_value('displayMode',"circular")
    itol_exporter.set_export_param_value('showBS',"0")
    itol_exporter.set_export_param_value('fontSize',fontsize)
    itol_exporter.set_export_param_value('alignLabels',"1")
    itol_exporter.set_export_param_value('datasetList','dataset1,dataset2,dataset3,dataset4')
    epsfile = outpath + os.sep + pfamid + '-itol.eps'
    pdffile = outpath + os.sep + pfamid + '-itol.pdf'
    jpgfile = outpath + os.sep + pfamid + '-itol.jpg'
    svgfile = outpath + os.sep + pfamid + '-itol.svg'
    itol_exporter.export(epsfile)
    itol_exporter.export(svgfile)
    os.system("epstopdf %s" % epsfile )
    os.system("convert  %s %s" % (epsfile, jpgfile) )
    print 'exported tree to ', pdffile
Exemplo n.º 5
0
input_dict['mem_str'] = mem_str
input_dict['write_out'] = False
angst_inputs = [input_dict]

# run angst one more time at that scaling
input_dict['write_out'] = True
input_dict['start_time'] = start_time
RunAnGST(input_dict)

#######CHANGED FOR THE ANGST SERVER######
# Run iTOL API and Upload species and gene trees
sys.path.append('/home/albertyw/itol/')
import Itol
import os
species_tree_location = input_info.species_tree_filename
itol_species_tree = Itol.Itol()
itol_species_tree.add_variable('treeFile', species_tree_location)
itol_species_tree.upload()
species_tree_webpage = itol_species_tree.get_webpage()

gene_tree_location = input_info.boots_file
itol_gene_tree = Itol.Itol()
itol_gene_tree.add_variable('treeFile', gene_tree_location)
itol_gene_tree.upload()
gene_tree_webpage = itol_gene_tree.get_webpage()

itol_file_location = os.path.dirname(
    input_info.species_tree_filename) + '/itol'
itol_file = open(itol_file_location, 'w')
itol_file.write(species_tree_webpage + "\n" + gene_tree_webpage)
itol_file.close()
Exemplo n.º 6
0
def makeITOLcall(tree, XITOL, HIST, com):
    handle = open(com["-o"] + ".TreeLabeled", "w")
    handle.write(tree.format("newick"))
    handle.close()
    buffITOL = XITOL.to_csv(header=False, sep="\t")
    handle = open(com["-o"] + "_tableXitol.txt", "w")
    handle.write(buffITOL)
    handle.close()
    buffHIST = HIST.to_csv()
    handle = open(com["-o"] + "_tableHistXitol.txt", "w")
    handle.write(buffHIST)
    handle.close()
    #handle=open(com["-o"]+"_CollapseList.txt","w")
    #handle.write(Collapse)
    #handle.close()
    #SSS=SignFeature2Itol(SN)
    #handle=open(com["-o"]+"_tableSignNodeXitol.txt","w")
    #handle.write(SSS)
    #handle.close()
    test = Itol.Itol()
    test.add_variable('treeFile', com["-o"] + ".TreeLabeled")
    test.add_variable('treeName', com["-o"])
    test.add_variable('treeFormat', "newick")
    #test.add_variable('preCollapsedFile',com["-o"]+"_CollapseList.txt")
    test.add_variable('showInternalIDs', '1')
    test.add_variable('colorDefinitionFile', com["-o"] + "_tableXitol.txt")
    test.add_variable('dataset1File', com["-o"] + "_tableHistXitol.txt")
    test.add_variable('dataset1Label', 'Counts')
    test.add_variable('dataset1Separator', 'comma')
    test.add_variable('dataset1Type', 'multibar')
    test.print_variables()
    good_upload = test.upload()
    if good_upload == False:
        print 'There was an error:' + test.comm.upload_output
    link = test.get_webpage()
    itol_exporter = test.get_itol_export()
    itol_exporter.set_export_param_value('format', 'svg')
    itol_exporter.set_export_param_value('rangesCover', 'clades')
    itol_exporter.set_export_param_value('showInternalLabels', '1')
    itol_exporter.set_export_param_value('colorBranches', '1')
    itol_exporter.set_export_param_value('datasetList', 'dataset1')
    itol_exporter.export(com["-o"] + "BetaEtree.svg")
    import re
    import sys
    print "try to add link from tree to table and then add to html file"
    SCRIPT = """
            <style>
                text:hover
                {
                    opacity: 1;
                }
            </style>
            """

    def addHref(matchobj):
        name = matchobj.group()[1:-1]
        return '><a xlink:href="#' + name + '">' + name + '</a><'

    def addOpacity(matchobj):
        name = matchobj.group()[:]
        return "opacity=0 " + name

    def addStyle(matchobj):
        name = matchobj.group()[:]
        return name + SCRIPT

    f = open(com["-o"] + "BetaEtree.svg", "r").read()
    f = re.sub("</style>", addStyle, f)
    f = re.sub(">L[0-9]*<", addHref, f)
    #f=re.sub('fill="black">[0-9_. A-z-]+</text>',addOpacity,f)
    f = re.sub('<path fill="white" .+\r', "", f)
    link = "<a href='" + link + "'>Click here to modify image</a>"
    B = link + f
    F = open(com["-o"] + ".html", "r").read()
    B = re.sub('<img src=".+" alt="some_text">', B, F)
    F = open(com["-o"] + ".html", "w")
    F.write(B)
    F.close()