예제 #1
0
파일: galaxy.py 프로젝트: padilha/ToolDog
    def add_citation(self, publication):
        """
        Add publication(s) to the tool (XML: <citations>).

        :param publication: Publication object.
        :type publication: :class:`tooldog.biotool_model.Publication`
        """
        LOGGER.debug("Adding citation to GalaxyToolGen object...")
        if not hasattr(self.tool, 'citations'):
            self.tool.citations = gxtp.Citations()
        # Add citation depending the type (doi, pmid...)
        if publication.doi is not None:
            if not self.tool.citations.has_citation('doi', publication.doi):
                self.tool.citations.append(
                    gxtp.Citation('doi', publication.doi))
        # <citation> only supports doi and bibtex as a type
        elif publication.pmid is not None:
            # self.tool.citations.append(gxtp.Citation('pmid', publication.pmid))
            LOGGER.warn(
                'pmid is not supported by <citation>, citation skipped')
        elif publication.pmcid is not None:
            # self.tool.citations.append(gxtp.Citation('pmcid', publication.pmcid))
            LOGGER.warn(
                'pmcid is not supported by <citation>, citation skipped')
예제 #2
0
 def makeXML(self):  # noqa
     """
     Create a Galaxy xml tool wrapper for the new script
     Uses galaxyhtml
     Hmmm. How to get the command line into correct order...
     """
     if self.command_override:
         self.newtool.command_override = self.command_override  # config file
     else:
         self.newtool.command_override = self.xmlcl
     cite = gxtp.Citations()
     acite = gxtp.Citation(type="doi",
                           value="10.1093/bioinformatics/bts573")
     cite.append(acite)
     self.newtool.citations = cite
     safertext = ""
     if self.args.help_text:
         helptext = open(self.args.help_text, "r").readlines()
         safertext = "\n".join([cheetah_escape(x) for x in helptext])
     if len(safertext.strip()) == 0:
         safertext = (
             "Ask the tool author (%s) to rebuild with help text please\n" %
             (self.args.user_email))
     if self.args.script_path:
         if len(safertext) > 0:
             safertext = safertext + "\n\n------\n"  # transition allowed!
         scr = [x for x in self.spacedScript if x.strip() > ""]
         scr.insert(0, "\n\nScript::\n")
         if len(scr) > 300:
             scr = (scr[:100] +
                    ["    >300 lines - stuff deleted", "    ......"] +
                    scr[-100:])
         scr.append("\n")
         safertext = safertext + "\n".join(scr)
     self.newtool.help = safertext
     self.newtool.version_command = f'echo "{self.args.tool_version}"'
     std = gxtp.Stdios()
     std1 = gxtp.Stdio()
     std.append(std1)
     self.newtool.stdios = std
     requirements = gxtp.Requirements()
     if self.args.packages:
         try:
             for d in self.args.packages.split(","):
                 ver = None
                 packg = None
                 d = d.replace("==", ":")
                 d = d.replace("=", ":")
                 if ":" in d:
                     packg, ver = d.split(":")
                     ver = ver.strip()
                     packg = packg.strip()
                 else:
                     packg = d.strip()
                     ver = None
                 if ver == "":
                     ver = None
                 if packg:
                     requirements.append(
                         gxtp.Requirement("package", packg.strip(), ver))
         except Exception:
             print(
                 "### malformed packages string supplied - cannot parse =",
                 self.args.packages,
             )
             sys.exit(2)
     self.newtool.requirements = requirements
     if self.args.parampass == "0":
         self.doNoXMLparam()
     else:
         self.doXMLparam()
     self.newtool.outputs = self.toutputs
     self.newtool.inputs = self.tinputs
     if self.args.script_path:
         configfiles = gxtp.Configfiles()
         configfiles.append(
             gxtp.Configfile(name="runme",
                             text="\n".join(self.escapedScript)))
         self.newtool.configfiles = configfiles
     tests = gxtp.Tests()
     test_a = gxtp.Test()
     for tp in self.testparam:
         test_a.append(tp)
     tests.append(test_a)
     self.newtool.tests = tests
     self.newtool.add_comment(
         "Created by %s at %s using the Galaxy Tool Factory." %
         (self.args.user_email, timenow()))
     self.newtool.add_comment("Source in git at: %s" % (toolFactoryURL))
     exml0 = self.newtool.export()
     exml = exml0.replace(FAKEEXE,
                          "")  # temporary work around until PR accepted
     if (
             self.test_override
     ):  # cannot do this inside galaxyxml as it expects lxml objects for tests
         part1 = exml.split("<tests>")[0]
         part2 = exml.split("</tests>")[1]
         fixed = "%s\n%s\n%s" % (part1, "\n".join(
             self.test_override), part2)
         exml = fixed
     # exml = exml.replace('range="1:"', 'range="1000:"')
     xf = open("%s.xml" % self.tool_name, "w")
     xf.write(exml)
     xf.write("\n")
     xf.close()