Exemplo n.º 1
0
def main():
    """ Visualizes normal modes memberships of an NMA experiment in a rectangle, where columns indicate the 
    membership (blue receptor, red ligand) and the tone of the color shows a linear relationship towards the overlap 
    towards the true deformation vector. """

    parser = argparse.ArgumentParser(
        description=
        'Visualizes normal modes memberships of an NMA experiment in a rectangle, where columns indicate the membership (blue receptor, red ligand) and the tone of the color shows a linear relationship towards the overlap  towards the true deformation vector.'
    )
    parser.add_argument('resultsPath',
                        help='Path to the experimental resultsfolder')
    parser.add_argument(
        '--extractNPZ',
        action="store_true",
        help=
        'The NMA models are in a *.npz.tar.gz file. If this is not set, the input is expected in a *.npz subfolder in each experiment results folder'
    )
    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)
    args = parser.parse_args()

    resultsPath = makeStringEndWith(getFullPathOfURI(args.resultsPath), "/")
    folders = glob.glob(resultsPath + "*")

    if args.extractNPZ:
        extractNPZs(folders)

    getAllModeInformation(folders, resultsPath)
Exemplo n.º 2
0
def main():
    """ Run the ResultsCombiner and output the absolute path of the created combined results folder. 
    
        Args:
            customArgs: optional args object from an argparser, when this program is not called directly in the shell
    
        Returns:
            Absolute absolute path of the created combined results folder.
    """
    parser = argparse.ArgumentParser(
        description=
        'Script to copy the content of multiple folders with a common prefix \
    (such as a experimental setup description) into one folder. This script relies on the fact that the string given by --prefix and \
    stored in the variable "afterUniquePrefix" appears after the unique part of the experiment setup, and will not be part of the output name anymore',
        epilog=
        "Returns: Absolute absolute path of the created combined results folder.\n Example: python ResultsCombinter.py /home/oliwa/workspace/TNMA1/output/2ballAtomcomplexk025A6_U1 \n -> all files from all folders /home/oliwa/workspace/TNMA1/output/2ballAtomcomplexk025A6_U1* are copied in the new created folder /home/oliwa/workspace/TNMA1/output/2ballAtomcomplexk025A6_U1"
    )
    parser.add_argument(
        'resultsPath',
        help=
        'Unique prefix string of the folders whose content should be copied into a new folder'
    )
    parser.add_argument(
        '--prefix',
        help=
        'String common among folders after unique prefix, which will not be part of the name anymore, default is \"NumberOf\"'
    )
    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)
    args = parser.parse_args()

    # afterUniquePrefix denotes the string after the unique prefix, this afterUniquePrefix string and all that follows will not be part of the output name
    if args.prefix:
        afterUniquePrefix = args.prefix
    else:
        afterUniquePrefix = "NumberOf"

    foldersToCombine = glob.glob(args.resultsPath + "*")

    outputfolder = foldersToCombine[0][0:foldersToCombine[0].
                                       find(afterUniquePrefix)]
    mkdir_p(outputfolder)
    for resultPath in foldersToCombine:
        customCopytree(resultPath, outputfolder)

    outputfolder = makeStringEndWith(getFullPathOfURI(outputfolder), "/")
    print outputfolder
    return outputfolder
Exemplo n.º 3
0
def outputLatex(path, experimentDescriptor, shortDescription):
    """ Write the latex document with the plot files as figures 
     
    Args:
        path: path with the pdfs and also the output path
        experimentDescriptor: string describing the experiment
    """
    path = makeStringEndWith(path, "/")
    pictures = sorted(glob.glob(path+"*.pdf"))
     
    # the header
    LaTeXHeader = """
\documentclass[12pt]{article}
\usepackage[latin1]{inputenc}
\usepackage[hmargin=1in,vmargin=1in]{geometry}
\usepackage[pdftex]{graphicx}
\usepackage{subfigure}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{float}
\usepackage{txfonts}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{subfigure}
\usepackage{textpos}
 
\\renewcommand{\headrulewidth}{1pt} 
 
\\begin{document}
 
\\title{Protein-Protein Docking Benchmark 4.0 Experimental Results}
 
\\author{Tomasz Oliwa, [email protected] \\\ TTIC \\\ 
{\small\em \  Date:  \\today }}
\date{}
\maketitle
 
\\begin{abstract}
Benchmark 4.0 plots are presented in this document based on the following plot file:
%s 
\end{abstract}
 
\\fancyhead[R]{\small{Benchmark 4.0 RMSD reductions} }
\\fancyfoot[C]{\\thepage}
 
""" % (experimentDescriptor)
 
# end document
    LaTeXEnd = """\n \end{document} """
 
#one latex page with results
    LaTeXBeginPage = """
\\newpage
 
\\begin{figure}
\\vspace{-4em}
\\begin{textblock}{10.2}[0,0](-0.2,-0.2)\hspace{0.2cm} %s \\ \end{textblock}\n
""" % (shortDescription)
 
    LaTeXEndPage = """
\end{figure}
"""
    pages = ""
    for a,b,c,d,e,f,g,h in grouper(8, pictures):
        singlePage = LaTeXBeginPage
        if a is not None:
            a = ntpath.basename(a)
            singlePage += "\subfigure{\hspace{-2em}\includegraphics[width=7.7cm]{"+str(a)+"}}\n"
        if b is not None:
            b = ntpath.basename(b)
            singlePage += "\subfigure{\hspace{-2em}\includegraphics[width=7.7cm]{"+str(b)+"}}\n"
        if c is not None:
            c = ntpath.basename(c)
            singlePage += "\subfigure{\hspace{-2em}\includegraphics[width=7.7cm]{"+str(c)+"}}\n"                
        if d is not None:
            d = ntpath.basename(d)
            singlePage += "\subfigure{\hspace{-2em}\includegraphics[width=7.7cm]{"+str(d)+"}}\n"
        if e is not None:
            e = ntpath.basename(e)
            singlePage += "\subfigure{\hspace{-2em}\includegraphics[width=7.7cm]{"+str(e)+"}}\n"
        if f is not None:
            f = ntpath.basename(f)
            singlePage += "\subfigure{\hspace{-2em}\includegraphics[width=7.7cm]{"+str(f)+"}}\n"
        if g is not None:
            g = ntpath.basename(g)
            singlePage += "\subfigure{\hspace{-2em}\includegraphics[width=7.7cm]{"+str(g)+"}}\n"
        if h is not None:
            h = ntpath.basename(h)
            singlePage += "\subfigure{\hspace{4.4em}\includegraphics[width=7.7cm]{"+str(h)+"}}\n"
        pages += singlePage
        pages += LaTeXEndPage
    outputLaTeX = LaTeXHeader + str(pages) + LaTeXEnd
    outputName = "latexCombined.tex"
    text_file = open(path+outputName, "w")
    text_file.write(outputLaTeX)
    text_file.close()
     
    # run latex
    try:
        os.chdir(path)
        shellCommand = "pdflatex "+ outputName
        os.system(shellCommand)
        # change the working path back to the directory of the program
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
    except Exception, err:
        print "Exception occurred when combining direct result files: ", err
        print traceback.format_exc()
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser(
        description=
        'This program runs several helper programs to go from individual NMA results to analysis and plots',
        epilog='Result: The results are written to <uniquePrefix_Path>_results/'
    )
    parser.add_argument(
        '--uniqueResultsPrefix_Path',
        help=
        'Absolute path and unique prefix of the individual result file folders, for example /home/oliwa/nmaData/output/2bb_Individual_U1_results/test2/2bbb_Individual_k05_A10_lambdaC_enforceT_U1'
    )
    parser.add_argument(
        '--uniqueResultsPrefixInterface_Path',
        help=
        'Absolute path and unique prefix of the individual interface result file folders, for example /home/oliwa/nmaData/output/2bb_Individual_U1_results/test2/2bbb_Individual_k05_A10_lambdaC_enforceT_U1'
    )
    parser.add_argument(
        '--resultsDescriptor',
        help=
        'Short string descriptor of method used, this will be used in plot legends, for example "U1_submatrix"'
    )
    parser.add_argument(
        '--canonicalResults_Path',
        nargs='?',
        help=
        'Absolute path to the individual canonical results, for example /home/oliwa/nmaData/output/2bb_Individual_U1_results/2bbb_Individual_canonical/"'
    )
    parser.add_argument(
        '--canonicalResultsInterface_Path',
        nargs='?',
        help=
        'Absolute path to the individual interface canonical results, for example /home/oliwa/nmaData/output/2bb_Individual_U1_results/2bbb_Individual_canonical/"'
    )
    # optional flags
    parser.add_argument(
        '--categoryMultiplier',
        help=
        'Integer that is a multiplier of the category size for success failure plotrates. For 2c, set this to 10, default is 1.'
    )
    parser.add_argument(
        '--dontCombine',
        action="store_true",
        help='Take the first argument as the individual results path.')
    parser.add_argument(
        '--dontCompare',
        action="store_true",
        help=
        'Do not compare results with optional (for instance canonical) results, just analyze and plot them.'
    )
    parser.add_argument(
        '--isComplex',
        action="store_true",
        help=
        'Results are from complex NMA data, not individual protein, set benchmark categories accordingly.'
    )
    parser.add_argument(
        '--pythonPath',
        help=
        'Use Absolute path to the python interpreter, for example /home/oliwa/anaconda/bin/python'
    )
    parser.add_argument(
        '-excludeAfterDistance',
        help=
        'exclude proteins that have their x-measure (distance) bigger than this value'
    )
    parser.add_argument(
        '--excludeBasedonDistancePath',
        help=
        "Exclude proteins from analysis if their distances are above a threshold."
    )
    parser.add_argument(
        '--sf_benchmarkSubsetPath',
        help="path to the benchmark difficulty categories for the sf rates")
    parser.add_argument(
        '--excludefirstKModes',
        help=
        "Exclude first k modes from overlap, correlation and collectivity analysis (for example if the first 6 modes are trivial normal modes, give the value 6)."
    )
    parser.add_argument(
        '--plotOnlyReduction',
        action="store_true",
        help=
        'If set, only RMSD reduction and associated plots are made, not measures plots/barplots (overlap, collectivity etc.)'
    )
    parser.add_argument(
        '--excludeFromList',
        help=
        "Path to list with protein names to only use (exclude the others) from postanalysis. "
    )

    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)
    args = parser.parse_args()

    if args.categoryMultiplier:
        categoryMultiplier = args.categoryMultiplier
    else:
        categoryMultiplier = 1.0

    # exclude first k modes if argument has been given
    if args.excludefirstKModes:
        excludefirstKModes = int(args.excludefirstKModes)
    else:
        excludefirstKModes = None

    #paths
    if args.isComplex:  # /allinterfaceSuperposedPdbs/ or /benchmark40/ or /eigenspectrumCases/
        benchmarkSubset_Path = "/home/oliwa/workspace/TNMA1/src/BenchmarkAssessmentsOfDifficultyBoundComplex/benchmark40/"
        sf_benchmarkSubsetPath = benchmarkSubset_Path
        taxonomyPath = "/home/oliwa/workspace/TNMA1/src/BenchmarkAssessmentsOfDifficulty/enzymeantibody/complexonlypdbs/"
    else:
        benchmarkSubset_Path = "/home/oliwa/workspace/TNMA1/src/BenchmarkAssessmentsOfDifficulty/allinterfaceSuperposed/"
        sf_benchmarkSubsetPath = benchmarkSubset_Path
        taxonomyPath = "/home/oliwa/workspace/TNMA1/src/BenchmarkAssessmentsOfDifficulty/enzymeantibody/with_r_u_suffix/"

    if args.sf_benchmarkSubsetPath:
        sf_benchmarkSubsetPath = args.sf_benchmarkSubsetPath

    if args.pythonPath:
        pythonPath = args.pythonPath
    else:
        pythonPath = "python"
    AnalysisPlotter_Path = "/home/oliwa/workspace/TNMA1/src/AnalysisPlotter.py"
    SuccessFailureAnalyzer_Path = "/home/oliwa/workspace/TNMA1/src/SuccessFailureAnalyzer.py"
    SuccessFailurePlotter_Path = "/home/oliwa/workspace/TNMA1/src/SuccessFailurePlotter.py"
    VarargsPlotter_Path = "/home/oliwa/workspace/TNMA1/src/VarargsPlotter.py"

    print "Benchmark difficulties in:", benchmarkSubset_Path
    print "Sf rates difficulties  in:", sf_benchmarkSubsetPath

    runPostAnalyzerInput = ""
    if not args.dontCombine:
        # ResultsCombiner.py
        if args.uniqueResultsPrefix_Path:
            bashCommand = pythonPath + " ResultsCombiner.py " + args.uniqueResultsPrefix_Path
            combinedIndividualResults_Path = runBashCommand(
                bashCommand).strip()
            runPostAnalyzerInput += "--whole " + combinedIndividualResults_Path
        if args.uniqueResultsPrefixInterface_Path:
            bashCommand = pythonPath + " ResultsCombiner.py " + args.uniqueResultsPrefixInterface_Path
            combinedIndividualResultsInterface_Path = runBashCommand(
                bashCommand).strip()
            runPostAnalyzerInput += " --interface " + combinedIndividualResultsInterface_Path
    else:
        # Take the first argument as the combined results path
        if args.uniqueResultsPrefix_Path:
            combinedIndividualResults_Path = makeStringEndWith(
                getFullPathOfURI(args.uniqueResultsPrefix_Path), "/")
            runPostAnalyzerInput += "--whole " + combinedIndividualResults_Path
        if args.uniqueResultsPrefixInterface_Path:
            combinedIndividualResultsInterface_Path = makeStringEndWith(
                getFullPathOfURI(args.uniqueResultsPrefixInterface_Path), "/")
            runPostAnalyzerInput += " --interface " + combinedIndividualResultsInterface_Path

    print combinedIndividualResults_Path

    # RunPostAnalyzer.py
    if args.isComplex:
        bashCommand = pythonPath + " RunPostAnalyzer.py --pythonPath " + pythonPath + " --onlypdb " + runPostAnalyzerInput + " --subset " + benchmarkSubset_Path
        postAnalysisResults_Path = getAllAfterLastChar(
            runBashCommand(bashCommand), "postAnalysis finished.").strip()
    else:
        if not args.excludeBasedonDistancePath:
            bashCommand = pythonPath + " RunPostAnalyzer.py --pythonPath " + pythonPath + " " + runPostAnalyzerInput + " --subset " + benchmarkSubset_Path
        else:
            bashCommand = pythonPath + " RunPostAnalyzer.py --pythonPath " + pythonPath + " " + runPostAnalyzerInput + " --subset " + benchmarkSubset_Path + " -excludeAfterDistance " + args.excludeAfterDistance + " --excludeBasedonDistancePath " + args.excludeBasedonDistancePath
        if excludefirstKModes:
            bashCommand = bashCommand + " --excludefirstKModes " + str(
                excludefirstKModes)
        if args.excludeFromList:
            bashCommand = bashCommand + " --excludeFromList " + args.excludeFromList
        postAnalysisResults_Path = getAllAfterLastChar(
            runBashCommand(bashCommand), "postAnalysis finished.").strip()
    print postAnalysisResults_Path

    # MakePlotfile.py
    if not args.dontCompare:
        bashCommand = pythonPath + " MakePlotFile.py --resultsDescriptor " + args.resultsDescriptor + " " + combinedIndividualResults_Path + " " + args.canonicalResults_Path
    else:
        # Do not compare results with optional (for instance canonical) results, just analyze and plot them
        bashCommand = pythonPath + " MakePlotFile.py --resultsDescriptor " + args.resultsDescriptor + " " + combinedIndividualResults_Path
    plotFile_Path = runBashCommand(bashCommand).strip()
    print plotFile_Path

    # AnalysisPlotter.py
    if args.plotOnlyReduction:
        bashCommand = pythonPath + " " + AnalysisPlotter_Path + " --plotOnlyReduction " + plotFile_Path + " " + postAnalysisResults_Path
    else:
        bashCommand = pythonPath + " " + AnalysisPlotter_Path + " " + plotFile_Path + " " + postAnalysisResults_Path
    plotFolderPath = getAllAfterLastChar(runBashCommand(bashCommand),
                                         "postPlot finished.").strip()
    if args.isComplex:
        bashCommand = pythonPath + " " + AnalysisPlotter_Path + " --plotOnlyReduction --plotLRMS " + plotFile_Path + " " + postAnalysisResults_Path
        runBashCommand(bashCommand)
    print plotFolderPath

    if not args.dontCompare:
        # SuccessFailureAnalyzer.py
        ### old bashCommand = pythonPath+" "+SuccessFailureAnalyzer_Path+" "+combinedIndividualResults_Path+ " "+args.canonicalResults_Path+" "+postAnalysisResults_Path
        if not args.excludeBasedonDistancePath:
            bashCommand = pythonPath + " " + SuccessFailureAnalyzer_Path + " -resultsPath " + combinedIndividualResults_Path + " -resultsPath_Interface " + combinedIndividualResultsInterface_Path + " -canonicalResultsPath " + args.canonicalResults_Path + " -canonicalResultsPath_Interface " + args.canonicalResultsInterface_Path + " -outputPath " + postAnalysisResults_Path
        else:
            bashCommand = pythonPath + " " + SuccessFailureAnalyzer_Path + " -resultsPath " + combinedIndividualResults_Path + " -resultsPath_Interface " + combinedIndividualResultsInterface_Path + " -canonicalResultsPath " + args.canonicalResults_Path + " -canonicalResultsPath_Interface " + args.canonicalResultsInterface_Path + " -outputPath " + postAnalysisResults_Path + " -excludeAfterDistance " + args.excludeAfterDistance + " --excludeBasedonDistancePath " + args.excludeBasedonDistancePath
        successFailureAnalyzerOutput_Path = getAllAfterLastChar(
            runBashCommand(bashCommand),
            "successFailureAnalyzer finished.").strip()
        print successFailureAnalyzerOutput_Path

        # SuccessFailurePlotter.py
        if args.isComplex:
            bashCommand = pythonPath + " " + SuccessFailurePlotter_Path + " --isComplex --categoryMultiplier " + categoryMultiplier + " " + successFailureAnalyzerOutput_Path + " " + benchmarkSubset_Path + " " + taxonomyPath + " " + plotFolderPath
        else:
            bashCommand = pythonPath + " " + SuccessFailurePlotter_Path + " --categoryMultiplier " + categoryMultiplier + " " + successFailureAnalyzerOutput_Path + " " + sf_benchmarkSubsetPath + " " + taxonomyPath + " " + plotFolderPath
        runBashCommand(bashCommand)


#         #Plot AUC difference
#         bashCommand = pythonPath+" "+VarargsPlotter_Path+" --resultsDenoteAreas -title quality_measure_protein -xLabel modes -yLabel measure -outputFile "+postAnalysisResults_Path+"plots/whole_measure "+"--colorCode rgb "+postAnalysisResults_Path + "successiveAUCs/RMSD_auc_normalized_successiveProteinAll.txt " +postAnalysisResults_Path + "successiveAUCs/RMSD_auc_successiveProteinAll_stepPoints.txt " + "all " +postAnalysisResults_Path + "successiveAUCs/RMSD_auc_normalized_successiveProteinDifficult.txt " +postAnalysisResults_Path + "successiveAUCs/RMSD_auc_successiveProteinDifficult_stepPoints.txt " + "difficult "+postAnalysisResults_Path + "successiveAUCs/RMSD_auc_normalized_successiveProteinMedium.txt " +postAnalysisResults_Path + "successiveAUCs/RMSD_auc_successiveProteinMedium_stepPoints.txt " + "medium "+postAnalysisResults_Path + "successiveAUCs/RMSD_auc_normalized_successiveProteinRigid.txt " + postAnalysisResults_Path + "successiveAUCs/RMSD_auc_successiveProteinRigid_stepPoints.txt " + "rigid "
#         runBashCommand(bashCommand)
#         bashCommand = pythonPath+" "+VarargsPlotter_Path+" --resultsDenoteAreas -title quality_measure_interface -xLabel modes -yLabel measure -outputFile "+postAnalysisResults_Path+"plots/interface_measure "+"--colorCode rgb "+postAnalysisResults_Path + "successiveAUCs/RMSD_auc_normalized_successiveInterfaceAll.txt " +postAnalysisResults_Path + "successiveAUCs/RMSD_auc_successiveInterfaceAll_stepPoints.txt " + "all " +postAnalysisResults_Path + "successiveAUCs/RMSD_auc_normalized_successiveInterfaceDifficult.txt " +postAnalysisResults_Path + "successiveAUCs/RMSD_auc_successiveInterfaceDifficult_stepPoints.txt " + "difficult "+postAnalysisResults_Path + "successiveAUCs/RMSD_auc_normalized_successiveInterfaceMedium.txt " +postAnalysisResults_Path + "successiveAUCs/RMSD_auc_successiveInterfaceMedium_stepPoints.txt " + "medium "+postAnalysisResults_Path + "successiveAUCs/RMSD_auc_normalized_successiveInterfaceRigid.txt " + postAnalysisResults_Path + "successiveAUCs/RMSD_auc_successiveInterfaceRigid_stepPoints.txt " + "rigid "
#         runBashCommand(bashCommand)
#         print "finished plotting AUC difference"

# MakeLatexGallery.py
    if args.plotOnlyReduction:
        print "combining into latex gallery"
        bashCommand = pythonPath + " MakeLatexGallery.py " + plotFolderPath
        runBashCommand(bashCommand)
Exemplo n.º 5
0
def main():
    """ Run the program MakePlotFile.py 
    
        Returns:
            path to the created plotFile.txt file
    """
    parser = argparse.ArgumentParser(
        description=
        'This program creates a plot file for PostPlot*.py \n It assumes that the PostAnalysis has been already run (for example via the RunPostAnalyzer).',
        epilog=
        'Result: The plot file is written to <resultsPath>_results/plotFile.txt'
    )
    parser.add_argument(
        'resultsPath',
        help='Path to the individual (per protein) results, to be plotted')
    parser.add_argument(
        'optionalResultsPath',
        nargs='?',
        help=
        'Optional path to the individual (per protein) canonical results, which can be used as comparison in the plots'
    )
    parser.add_argument(
        '--resultsDescriptor',
        help=
        'A string describing the approach that created the results, default is \"submatrix\"'
    )
    parser.add_argument(
        '--optionalResultsDescriptor',
        help=
        'A string describing the approach that created the optional results, default is \"canonical\"'
    )
    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)
    args = parser.parse_args()

    # setup paths of individual and post analyzer results and the descriptors
    postAnalyzerSuffix = "_results/"

    if args.resultsDescriptor:
        resultsDescriptor = args.resultsDescriptor
    else:
        resultsDescriptor = "submatrix"

    if args.optionalResultsDescriptor:
        optionalResultsDescriptor = args.optionalResultsDescriptor
    else:
        optionalResultsDescriptor = "canonical"

    resultsPath = makeStringEndWith(getFullPathOfURI(args.resultsPath), "/")
    assert os.path.isdir(resultsPath)
    resultsPostAnalyzerPath = makeStringEndWith(
        makeStringNotEndWith(resultsPath, "/") + postAnalyzerSuffix, "/")
    assert os.path.isdir(resultsPostAnalyzerPath)

    plotString = createPlotString(resultsPostAnalyzerPath, resultsDescriptor)
    plotString = listOflistsToString(plotString)

    if args.optionalResultsPath:
        optionalResultsPath = makeStringEndWith(
            getFullPathOfURI(args.optionalResultsPath), "/")
        assert os.path.isdir(optionalResultsPath)
        optionalResultsPostAnalyzerPath = makeStringEndWith(
            makeStringNotEndWith(optionalResultsPath, "/") +
            postAnalyzerSuffix, "/")
        assert os.path.isdir(optionalResultsPostAnalyzerPath)

        optionalPlotString = createPlotString(optionalResultsPostAnalyzerPath,
                                              optionalResultsDescriptor)
        optionalPlotString = listOflistsToString(optionalPlotString)
        plotString = plotString + "\n" + optionalPlotString

    with open(resultsPostAnalyzerPath + "plotFile.txt", "w") as text_file:
        text_file.write(plotString)

    print getFullPathOfURI(resultsPostAnalyzerPath + "plotFile.txt")
    return getFullPathOfURI(resultsPostAnalyzerPath + "plotFile.txt")
Exemplo n.º 6
0
def main():
    parser = argparse.ArgumentParser(description='Visualize eigenvalues and overlaps')
    parser.add_argument('resultsPath', help='Absolute path of the results folders')
    parser.add_argument('outputPath', help='outputPath')
    parser.add_argument('-title', help='title of the plot')
    parser.add_argument('-fileToLookFor_overlap', help='Specify the file with the overlap information')
    parser.add_argument('-fileToLookFor_differencesInRank', help='Specify the file with the differencesInRank information')    
    parser.add_argument('-modes', help='Specify how many modes to plot')
    parser.add_argument('-upperOverlapLimit', help='Upper overlap limit, force manually')
     
    if len(sys.argv)==1:
        parser.print_help()
        sys.exit(1)
    args = parser.parse_args()    
    
    if args.modes:
        modes = int(args.modes)
    else:
        modes = 4
        
    if args.title:
        title = args.title
    else:
        title = ""
        
    if args.outputPath:
        outputPath = args.outputPath
    else:
        outputPath = ""        
        
    fileToLookFor_overlap = "singleModeOverlapsFromSuperset.txt"
    fileToLookFor_differencesInRank = "differencesInRank.txt"
    if args.fileToLookFor_overlap:
        fileToLookFor_overlap = args.fileToLookFor
    if args.fileToLookFor_differencesInRank:
        fileToLookFor_differencesInRank = args.fileToLookFor_differencesInRank        
        
    assert os.path.isdir(args.resultsPath)
    assert os.path.isdir(args.outputPath)


    all340proteinsPaths = glob.glob(args.resultsPath+"*/")
    
    difficults = np.loadtxt("/home/oliwa/workspace/TNMA1/src/BenchmarkAssessmentsOfDifficulty/allinterfaceSuperposed/difficult.txt", dtype="string")
    difficults = set(difficults)    
    
    dataToPlot_overlaps = []
    dataToPlot_differencesInRank = []
    proteins = []
    counter = 0
    
    for proteinPath in sorted(all340proteinsPaths):
        proteinPath = makeStringEndWith(proteinPath, "/")
        
        protein = makeStringNotEndWith(os.path.basename(os.path.normpath(proteinPath)), "/")
        
        if protein not in difficults:
            continue
        counter += 1

        try:
            # load overlap
            overlap = np.loadtxt(proteinPath+fileToLookFor_overlap)
            overlap = overlap[:modes]
            overlap = abs(np.array(overlap))
            overlap = list(overlap)
            if args.upperOverlapLimit:
                for i in range(0, len(overlap)):
                    if overlap[i] > float(args.upperOverlapLimit):
                        overlap[i] = float(args.upperOverlapLimit)
            dataToPlot_overlaps.append(overlap)
            protein = os.path.basename(os.path.normpath(proteinPath))
            proteins.append(protein)
            # load ranking differences
            differenceInRank = np.loadtxt(proteinPath+fileToLookFor_differencesInRank, dtype="int")
            differenceInRank = list(differenceInRank)
            dataToPlot_differencesInRank.append(differenceInRank[:modes])

        except IOError as err:
            print "IOError occurred, probably there is no such file at the path: ", err
            print traceback.format_exc()           
            
            
    print proteins
            
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    #x, y = np.random.rand(2, 100) * 4
    y = range(1, len(proteins)+1)
    x = range(1, modes+1)
    
    xpos, ypos = np.meshgrid(x, y)
    x = xpos.flatten()
    y = ypos.flatten()
    
    colors = []
    print "overlaps len: ", len(dataToPlot_overlaps)
    print "overlaps: ", dataToPlot_overlaps    
    
    dataToPlot_overlaps_flattened = np.array(dataToPlot_overlaps).flatten()
    maxOverlap = max(dataToPlot_overlaps_flattened)
    print "maxOverlap:", maxOverlap
    
    for element in dataToPlot_overlaps_flattened:
        colors.append(plt.cm.jet(element/maxOverlap))
        #print plt.cm.jet(element/maxOverlap)

    print "x", len(x)
    print "y", len(y)
    #print "colors", len(colors)
    
    print "dataToPlot_differencesInRank len: ",dataToPlot_differencesInRank
    dataToPlot_differencesInRank = np.array(dataToPlot_differencesInRank).flatten() + 0.0001
    print "dataToPlot_differencesInRank len: ", len(dataToPlot_differencesInRank.flatten())
    
    dx=np.ones(len(x))*0.5
    dy=dx
    
    p = ax.bar3d(x-0.25, y-0.25, np.zeros(len(x)), dx, dy, dataToPlot_differencesInRank, color=colors, zsort='average')
    
    ax.set_zlim([min(dataToPlot_differencesInRank), max(dataToPlot_differencesInRank)])
    #ax.set_title(title)
    
    # x label for the ascending modes
    #ax.set_xticklabels(range(1, modes+1), minor=False)
    plt.gca().xaxis.set_major_locator(plt.NullLocator())
    ax.set_xlabel("ascending lambda^R modes") 
    # y label for the proteins
    #ax.set_yticklabels(proteins, minor=False)
    plt.gca().yaxis.set_major_locator(plt.NullLocator())
    ax.set_ylabel("proteins")
# #     dataToPlot_overlaps = np.array(dataToPlot_overlaps)      
# #             
# #     fig, ax = plt.subplots(1)
# #     ax.set_yticklabels(proteins, minor=False)
# #     ax.xaxis.tick_top()    
# #     
# #     p = ax.pcolormesh(dataToPlot_overlaps, cmap="bone")
# #     fig.colorbar(p)  
# #     
# #     # put the major ticks at the middle of each cell, notice "reverse" use of dimension
# #     ax.set_yticks(np.arange(dataToPlot_overlaps.shape[0])+0.5, minor=False)
# #     ax.set_xticks(np.arange(dataToPlot_overlaps.shape[1])+0.5, minor=False)   
# #     
# #     # want a more natural, table-like display (sorting)
# #     ax.invert_yaxis()
# #     ax.xaxis.tick_top()
# #     
# #     ax.set_xticklabels(range(1, modes+1), minor=False)
# #     ax.set_yticklabels(proteins, minor=False) 
# #             
# #     if args.title:
# #         plt.title(args.title+"\n\n")
        
    # output
    #outputPath = makeStringEndWith(args.outputPath, "/")+"eigenVis"
    
    #mkdir_p(outputPath)
    plt.savefig(outputPath+'/eigenVis_'+title+'.eps', bbox_inches='tight')
    plt.savefig(outputPath+'/eigenVis_'+title+'.pdf', bbox_inches='tight') 
    #plt.show()
    # close and reset the plot 
    plt.clf()
    plt.cla()
    plt.close()         
    print "total proteins: ", counter
Exemplo n.º 7
0
def main():
    parser = argparse.ArgumentParser(description='Visualize eigenvalues and overlaps')
    parser.add_argument('resultsPath', help='Absolute path of the results folders')
    parser.add_argument('outputPath', help='outputPath')
    parser.add_argument('-title', help='title of the plot')
    parser.add_argument('-fileToLookFor', help='Specify the file with the overlap information')
    parser.add_argument('-modes', help='Specify how many modes to plot')
    parser.add_argument('-upperOverlapLimit', help='Upper overlap limit, force manually')
     
    if len(sys.argv)==1:
        parser.print_help()
        sys.exit(1)
    args = parser.parse_args()    
    
    if args.modes:
        modes = int(args.modes)
    else:
        modes = 10
        
    if args.title:
        title = args.title
    else:
        title = ""
        
    fileToLookFor = "singleModeOverlapsFromSuperset.txt"
    if args.fileToLookFor:
        fileToLookFor = args.fileToLookFor
        
    assert os.path.isdir(args.resultsPath)
    assert os.path.isdir(args.outputPath)


    all340proteinsPaths = glob.glob(args.resultsPath+"*/")
    
    dataToPlot = []
    proteins = []
    for proteinPath in sorted(all340proteinsPaths):
        proteinPath = makeStringEndWith(proteinPath, "/")
        try:
            overlap = np.loadtxt(proteinPath+fileToLookFor)
            overlap = overlap[:modes]
            overlap = abs(np.array(overlap))
            if args.upperOverlapLimit:
                for i in range(0, len(overlap)):
                    if overlap[i] > float(args.upperOverlapLimit):
                        overlap[i] = float(args.upperOverlapLimit)
            dataToPlot.append(overlap)
            protein = os.path.basename(os.path.normpath(proteinPath))
            proteins.append(protein)
        except IOError as err:
            print "IOError occurred, probably there is no such file at the path: ", err
            print traceback.format_exc()
            
    dataToPlot = np.array(dataToPlot)      
            
    fig, ax = plt.subplots(1)
    ax.set_yticklabels(proteins, minor=False)
    ax.xaxis.tick_top()    
    
    p = ax.pcolormesh(dataToPlot, cmap="gray")
    fig.colorbar(p)  
    
    # put the major ticks at the middle of each cell, notice "reverse" use of dimension
    ax.set_yticks(np.arange(dataToPlot.shape[0])+0.5, minor=False)
    ax.set_xticks(np.arange(dataToPlot.shape[1])+0.5, minor=False)   
    
    # want a more natural, table-like display (sorting)
    ax.invert_yaxis()
    ax.xaxis.tick_top()
    
    ax.set_xticklabels(range(1, modes+1), minor=False)
    ax.set_yticklabels(proteins, minor=False) 
            
    if args.title:
        plt.title(args.title+"\n\n")
        
    # output
    outputPath = makeStringEndWith(args.outputPath, "/")+"eigenVis"
    mkdir_p(outputPath)
    plt.savefig(outputPath+'/eigenVis_'+title+'.eps', bbox_inches='tight')
    plt.savefig(outputPath+'/eigenVis_'+title+'.pdf', bbox_inches='tight') 
    #plt.show()
    # close and reset the plot 
    plt.clf()
    plt.cla()
    plt.close()