changeset 7:cfeab429f660 draft

planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit b9143221aee2cd09e1334ee56ff9651550b1797a
author gga
date Fri, 15 Mar 2019 06:04:22 -0400
parents eb389ee1408e
children 496444ad9291
files __pycache__/webapollo.cpython-36.pyc create_or_update_organism.py create_or_update_organism.xml webapollo.pyc
diffstat 4 files changed, 58 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
Binary file __pycache__/webapollo.cpython-36.pyc has changed
--- a/create_or_update_organism.py	Tue Oct 30 04:29:26 2018 -0400
+++ b/create_or_update_organism.py	Fri Mar 15 06:04:22 2019 -0400
@@ -4,18 +4,33 @@
 import argparse
 import json
 import logging
+import os
 import shutil
+import subprocess
 import sys
+import tempfile
 import time
 
+
 from webapollo import GuessOrg, OrgOrGuess, PermissionCheck, WAAuth, WebApolloInstance
 logging.basicConfig(level=logging.INFO)
 log = logging.getLogger(__name__)
 
+
+def IsBlatEnabled():
+    if 'BLAT_ENABLED' not in os.environ:
+        return False
+    value = os.environ['BLAT_ENABLED']
+    if value.lower() in ('true', 't', '1'):
+        return True
+    else:
+        return False
+
+
 if __name__ == '__main__':
     parser = argparse.ArgumentParser(description='Create or update an organism in an Apollo instance')
     WAAuth(parser)
-
+    parser.add_argument('jbrowse_src', help='Old JBrowse Data Directory')
     parser.add_argument('jbrowse', help='JBrowse Data Directory')
     parser.add_argument('email', help='User Email')
     OrgOrGuess(parser)
@@ -24,8 +39,38 @@
     parser.add_argument('--public', action='store_true', help='Make organism public')
     parser.add_argument('--group', help='Give access to a user group')
     parser.add_argument('--remove_old_directory', action='store_true', help='Remove old directory')
+    args = parser.parse_args()
+    CHUNK_SIZE = 2**20
+    blat_db = None
 
-    args = parser.parse_args()
+    # Cleanup if existing
+    if(os.path.exists(args.jbrowse)):
+        shutil.rmtree(args.jbrowse)
+    # Copy files
+    shutil.copytree(args.jbrowse_src, args.jbrowse)
+
+    path_fasta = args.jbrowse + '/seq/genome.fasta'
+    path_2bit = args.jbrowse + '/seq/genome.2bit'
+
+    # Convert fasta if existing
+    if(IsBlatEnabled() and os.path.exists(path_fasta)):
+        arg = ['faToTwoBit', path_fasta, path_2bit]
+        tmp_stderr = tempfile.NamedTemporaryFile(prefix="tmp-twobit-converter-stderr")
+        proc = subprocess.Popen(args=arg, shell=False, cwd=args.jbrowse, stderr=tmp_stderr.fileno())
+        return_code = proc.wait()
+        if return_code:
+            tmp_stderr.flush()
+            tmp_stderr.seek(0)
+            print("Error building index:", file=sys.stderr)
+            while True:
+                chunk = tmp_stderr.read(CHUNK_SIZE)
+                if not chunk:
+                    break
+                sys.stderr.write(chunk)
+            sys.exit(return_code)
+        blat_db = path_2bit
+        tmp_stderr.close()
+
     wa = WebApolloInstance(args.apollo, args.username, args.password)
 
     org_cn = GuessOrg(args, wa)
@@ -56,7 +101,8 @@
             # mandatory
             genus=args.genus,
             species=args.species,
-            public=args.public
+            public=args.public,
+            blatdb=blat_db
         )
         time.sleep(2)
         if args.remove_old_directory and args.jbrowse != old_directory:
@@ -72,7 +118,8 @@
             args.jbrowse,
             genus=args.genus,
             species=args.species,
-            public=args.public
+            public=args.public,
+            blatdb=blat_db
         )
 
         # Must sleep before we're ready to handle
--- a/create_or_update_organism.xml	Tue Oct 30 04:29:26 2018 -0400
+++ b/create_or_update_organism.xml	Fri Mar 15 06:04:22 2019 -0400
@@ -1,15 +1,14 @@
 <?xml version="1.0"?>
-<tool id="create_or_update" name="Create or Update Organism" version="3.3">
+<tool id="create_or_update" name="Create or Update Organism" version="3.4">
   <description>will create the organism if it doesn't exist, and update otherwise</description>
   <macros>
     <import>macros.xml</import>
   </macros>
-  <expand macro="requirements"/>
+  <expand macro="requirements">
+    <requirement type="package" version="377">ucsc-fatotwobit</requirement>
+  </expand>
   <code file="webapollo.py"/>
   <command detect_errors="aggressive"><![CDATA[
-cp -R '${jbrowse.extra_files_path}/data/' "@DATA_DIR@/${jbrowse.id}"
-
-&&
 
 python $__tool_directory__/create_or_update_organism.py
 
@@ -20,11 +19,14 @@
 #if str($group) != "None":
 --group '${group}'
 #end if
+
 ${remove_old_directory}
 $public
 
 @ORG_OR_GUESS@
 
+'${jbrowse.extra_files_path}/data/'
+
 "@DATA_DIR@/${jbrowse.id}"
 
 $__user_email__
Binary file webapollo.pyc has changed