Beispiel #1
0
    def _runRScript(RScript):
        rscriptname = rosettahelper.writeTempFile(".", RScript)
        #p = subprocess.Popen(["/opt/R-2.15.1/bin/R","CMD", "BATCH", rscriptname])
        p = subprocess.Popen(["R", "CMD", "BATCH", rscriptname])
        while True:
            time.sleep(0.3)
            errcode = p.poll()
            if errcode != None:
                break
        rout = "%s.Rout" % rscriptname
        delete_file(rscriptname)
        #colortext.warning(rosettahelper.readFile(rout))

        rout_contents = None
        if os.path.exists(rout):
            rout_contents = rosettahelper.readFile(rout)

        if errcode != 0:
            if os.path.exists(rout):
                colortext.warning(rout_contents)
                delete_file(rout)
            raise colortext.Exception(
                "The R script failed with error code %d." % errcode)
        delete_file(rout)
        return rout_contents
Beispiel #2
0
 def _correlation_coefficient(inputfname, output_filename, filetype, experiment_field = "ExperimentalDDG"):
     '''File suffix: pearsons_r
        Description: Pearson's r
        '''
     # todo: The graph size is not being set correctly i.e. the max function call is wrong in the script
     title = "" # "Pearson's r"
     RScript = rosettahelper.readFile(os.path.join(script_path, "R", "pearsons.R")) % vars()
     return RInterface._runRScript(RScript)
Beispiel #3
0
 def correlation_coefficient_gplot(inputfname, output_filename, filetype, experiment_field = "ExperimentalDDG"):
     '''File suffix: pearsons_r_gplot
        Description: Pearson's r
        Filename: ggplot_pearsons.R
        Priority: 1
        '''
     title = "" #Pearson's r"
     RScript = rosettahelper.readFile(os.path.join(script_path, "R", "ggplot_pearsons.R")) % vars()
     return RInterface._runRScript(RScript)
Beispiel #4
0
 def correlation_coefficient_gplot_crop(inputfname, output_filename, filetype, experiment_field = "ExperimentalDDG"):
     '''File suffix: pearsons_r_gplot_cropped
        Description: Pearson's r filtering with quantile(res, probs = c(0.05,0.95))
        Filename: ggplot_pearsons_cropped.R
        Priority: 3
        '''
     title = "" #Pearson's r filtering with quantile(res, probs = c(0.05,0.95))"
     RScript = rosettahelper.readFile(os.path.join(script_path, "R", "ggplot_pearsons_cropped.R")) % vars()
     return RInterface._runRScript(RScript)
Beispiel #5
0
 def _correlation_coefficient(inputfname,
                              output_filename,
                              filetype,
                              experiment_field="ExperimentalDDG"):
     '''File suffix: pearsons_r
        Description: Pearson's r
        '''
     # todo: The graph size is not being set correctly i.e. the max function call is wrong in the script
     title = ""  # "Pearson's r"
     RScript = rosettahelper.readFile(
         os.path.join(script_path, "R", "pearsons.R")) % vars()
     return RInterface._runRScript(RScript)
Beispiel #6
0
 def correlation_coefficient_gplot(inputfname,
                                   output_filename,
                                   filetype,
                                   experiment_field="ExperimentalDDG"):
     '''File suffix: pearsons_r_gplot
        Description: Pearson's r
        Filename: ggplot_pearsons.R
        Priority: 1
        '''
     title = ""  #Pearson's r"
     RScript = rosettahelper.readFile(
         os.path.join(script_path, "R", "ggplot_pearsons.R")) % vars()
     return RInterface._runRScript(RScript)
Beispiel #7
0
 def correlation_coefficient_gplot_crop(inputfname,
                                        output_filename,
                                        filetype,
                                        experiment_field="ExperimentalDDG"):
     '''File suffix: pearsons_r_gplot_cropped
        Description: Pearson's r filtering with quantile(res, probs = c(0.05,0.95))
        Filename: ggplot_pearsons_cropped.R
        Priority: 3
        '''
     title = ""  #Pearson's r filtering with quantile(res, probs = c(0.05,0.95))"
     RScript = rosettahelper.readFile(
         os.path.join(script_path, "R",
                      "ggplot_pearsons_cropped.R")) % vars()
     return RInterface._runRScript(RScript)
Beispiel #8
0
    def _runRScript(RScript):
        rscriptname = rosettahelper.writeTempFile(".", RScript)
        #p = subprocess.Popen(["/opt/R-2.15.1/bin/R","CMD", "BATCH", rscriptname])
        p = subprocess.Popen(["R", "CMD", "BATCH", rscriptname])
        while True:
            time.sleep(0.3)
            errcode = p.poll()
            if errcode != None:
                break
        rout = "%s.Rout" % rscriptname
        delete_file(rscriptname)
        #colortext.warning(rosettahelper.readFile(rout))

        rout_contents = None
        if os.path.exists(rout):
            rout_contents = rosettahelper.readFile(rout)

        if errcode != 0:
            if os.path.exists(rout):
                colortext.warning(rout_contents)
                delete_file(rout)
            raise colortext.Exception("The R script failed with error code %d." % errcode)
        delete_file(rout)
        return rout_contents
Beispiel #9
0
    def CreateReport(self, outfname = 'test.pdf', description = None, filetype = "pdf"):

        latexdoc = latex.LaTeXDocument("$\\Delta\\Delta$G analysis", pdf_title = "DDG analysis")

        analysis_objects = self.analyzer.PlotAll(filetype = filetype, createFiles = False)

        analysis_by_dataset = {}
        for analysis_object in analysis_objects:
            dataset = analysis_object.dataset
            analysis_by_dataset[dataset] = analysis_by_dataset.get(dataset, [])
            analysis_by_dataset[dataset].append(analysis_object)

        count = 0
        try:
            if description:
                latexdoc.addSection("Description")
                for tagged_line in description:
                    color = tagged_line[0]
                    line = tagged_line[1]
                    latexdoc.addLaTeXCode("\\textcolor{%s}{%s}\n" % (color, line))

            if analysis_by_dataset:
                latexdoc.addSection("Analysis")

            for dataset, analysis_objects in analysis_by_dataset.iteritems():
                latexdoc.addSubsection(dataset)

                # The tab solution here is messy. Redo this when we decide what LaTeX floats we want to use
                captiontabs = []
                imagetabs = []
                for analysis_object in analysis_objects:
                    count +=1
                    filename = "graph%d" + (".%s" % filetype)
                    rosettahelper.writeFile(filename % count, analysis_object.contents)
                    captiontabs.append(analysis_object.description)
                    imagetabs.append(latexdoc.getImageText(filename % count, width_cm = 6))
                    self.graphfiles.append(filename)

                assert(len(captiontabs) == len(imagetabs))
                captiontabs = [captiontabs[i:i+2] for i in range(0, len(captiontabs), 2)]
                imagetabs = [imagetabs[i:i+2] for i in range(0, len(imagetabs), 2)]
                assert(len(captiontabs) == len(imagetabs))

                tabs = []
                for i in range(len(captiontabs)):
                    tabs.append(captiontabs[i])
                    tabs.append(imagetabs[i])

                latexdoc.addTabular(tabs, alignment = 'c')

            latexdoc.clearPage()
            latexdoc.addSection("R files")
            for analysisType, data in sorted(RFunctions.iteritems(), key=lambda x: x[1][2]):
                description = data[0]
                RFunction = data[1]
                filename = data[3]
                latexdoc.addSubsection(description)
                latexdoc.addTypewriterText(rosettahelper.readFile(os.path.join(script_path, "R", filename)), language="R")
                latexdoc.clearPage()

            latexdoc.compile_pdf(outfname)
        except Exception, e:
            self.clean()
            raise
Beispiel #10
0
    def CreateReport(self,
                     outfname='test.pdf',
                     description=None,
                     filetype="pdf"):

        latexdoc = latex.LaTeXDocument("$\\Delta\\Delta$G analysis",
                                       pdf_title="DDG analysis")

        analysis_objects = self.analyzer.PlotAll(filetype=filetype,
                                                 createFiles=False)

        analysis_by_dataset = {}
        for analysis_object in analysis_objects:
            dataset = analysis_object.dataset
            analysis_by_dataset[dataset] = analysis_by_dataset.get(dataset, [])
            analysis_by_dataset[dataset].append(analysis_object)

        count = 0
        try:
            if description:
                latexdoc.addSection("Description")
                for tagged_line in description:
                    color = tagged_line[0]
                    line = tagged_line[1]
                    latexdoc.addLaTeXCode("\\textcolor{%s}{%s}\n" %
                                          (color, line))

            if analysis_by_dataset:
                latexdoc.addSection("Analysis")

            for dataset, analysis_objects in analysis_by_dataset.iteritems():
                latexdoc.addSubsection(dataset)

                # The tab solution here is messy. Redo this when we decide what LaTeX floats we want to use
                captiontabs = []
                imagetabs = []
                for analysis_object in analysis_objects:
                    count += 1
                    filename = "graph%d" + (".%s" % filetype)
                    rosettahelper.writeFile(filename % count,
                                            analysis_object.contents)
                    captiontabs.append(analysis_object.description)
                    imagetabs.append(
                        latexdoc.getImageText(filename % count, width_cm=6))
                    self.graphfiles.append(filename)

                assert (len(captiontabs) == len(imagetabs))
                captiontabs = [
                    captiontabs[i:i + 2]
                    for i in range(0, len(captiontabs), 2)
                ]
                imagetabs = [
                    imagetabs[i:i + 2] for i in range(0, len(imagetabs), 2)
                ]
                assert (len(captiontabs) == len(imagetabs))

                tabs = []
                for i in range(len(captiontabs)):
                    tabs.append(captiontabs[i])
                    tabs.append(imagetabs[i])

                latexdoc.addTabular(tabs, alignment='c')

            latexdoc.clearPage()
            latexdoc.addSection("R files")
            for analysisType, data in sorted(RFunctions.iteritems(),
                                             key=lambda x: x[1][2]):
                description = data[0]
                RFunction = data[1]
                filename = data[3]
                latexdoc.addSubsection(description)
                latexdoc.addTypewriterText(rosettahelper.readFile(
                    os.path.join(script_path, "R", filename)),
                                           language="R")
                latexdoc.clearPage()

            latexdoc.compile_pdf(outfname)
        except Exception, e:
            self.clean()
            raise