diff rgToolFactory.py @ 30:fb3fa6a2874d draft

Citations added (thanks John!) and a few more output formats for Alistair Chilcott
author fubar
date Thu, 28 Aug 2014 02:22:39 -0400
parents bff4c9bfabc7
children
line wrap: on
line diff
--- a/rgToolFactory.py	Thu Aug 07 22:11:02 2014 -0400
+++ b/rgToolFactory.py	Thu Aug 28 02:22:39 2014 -0400
@@ -134,6 +134,19 @@
            stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0
 
 
+def parse_citations(citations_text):
+    """
+    """
+    citations = [c for c in citations_text.split("**ENTRY**") if c.strip()]
+    citation_tuples = []
+    for citation in citations:
+        if citation.startswith("doi"):
+            citation_tuples.append( ("doi", citation[len("doi"):].strip() ) )
+        else:
+            citation_tuples.append( ("bibtex", citation[len("bibtex"):].strip() ) )
+    return citation_tuples
+
+
 class ScriptRunner:
     """class is a wrapper for an arbitrary script
     """
@@ -264,6 +277,10 @@
 %(help)s
 
 </help>
+<citations>
+    %(citations)s
+    <citation type="doi">10.1093/bioinformatics/bts573</citation>
+</citations>
 </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto
 
         newCommand="""
@@ -303,7 +320,8 @@
         xdict = {}
         xdict['requirements'] = ''
         if self.opts.make_HTML:
-            xdict['requirements'] = protorequirements
+            if self.opts.include_dependencies == "yes":
+                xdict['requirements'] = protorequirements
         xdict['tool_version'] = self.opts.tool_version
         xdict['test1Input'] = self.test1Input
         xdict['test1HTML'] = self.test1HTML
@@ -323,6 +341,16 @@
             xdict['help'] = ''.join([x for x in helptext])
         else:
             xdict['help'] = 'Please ask the tool author (%s) for help as none was supplied at tool generation\n' % (self.opts.user_email)
+        if self.opts.citations:
+            citationstext = open(self.opts.citations,'r').read()
+            citation_tuples = parse_citations(citationstext)
+            citations_xml = ""
+            for citation_type, citation_content in citation_tuples:
+                citation_xml = """<citation type="%s">%s</citation>""" % (citation_type, html_escape(citation_content))
+                citations_xml += citation_xml
+            xdict['citations'] = citations_xml
+        else:
+            xdict['citations'] = ""
         coda = ['**Script**','Pressing execute will run the following code over your input file and generate some outputs in your history::']
         coda.append('\n')
         coda.append(self.indentedScript)
@@ -671,6 +699,7 @@
     a('--make_Tool',default=None)
     a('--make_HTML',default=None)
     a('--help_text',default=None)
+    a('--citations',default=None)
     a('--tool_desc',default=None)
     a('--new_tool',default=None)
     a('--tool_version',default=None)