Repository 'jbrowsearchivecreator'
hg clone https://testtoolshed.g2.bx.psu.edu/repos/yating-l/jbrowsearchivecreator

Changeset 31:127037c49bc8 (2017-10-16)
Previous changeset 30:2191bd0798a9 (2017-10-13) Next changeset 32:7b955a58d8f2 (2017-10-20)
Commit message:
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
modified:
TrackHub.py
apollo/ApolloInstance.py
jbrowseArchiveCreator.py
tool_dependencies.xml
util/Reader.py
util/subtools.py
added:
templates/apollo-arrow.yml
b
diff -r 2191bd0798a9 -r 127037c49bc8 TrackHub.py
--- a/TrackHub.py Fri Oct 13 16:19:03 2017 -0400
+++ b/TrackHub.py Mon Oct 16 18:03:58 2017 -0400
b
@@ -16,7 +16,7 @@
 
 
 class TrackHub:
-    def __init__(self, inputFastaFile, apollo_user, outputFile, extra_files_path, tool_directory, trackType, apollo_host):
+    def __init__(self, inputFastaFile, apollo_user, outputFile, extra_files_path, tool_directory, trackType, apollo_host, user_email):
         
         self.rootAssemblyHub = None
 
@@ -37,7 +37,7 @@
         self.chromSizesFile = None
 
         # Set up apollo
-        self.apollo = ApolloInstance(apollo_host)
+        self.apollo = ApolloInstance(apollo_host, tool_directory, user_email)
         self.apollo_user = apollo_user
         
         # Set all the missing variables of this class, and create physically the folders/files
b
diff -r 2191bd0798a9 -r 127037c49bc8 apollo/ApolloInstance.py
--- a/apollo/ApolloInstance.py Fri Oct 13 16:19:03 2017 -0400
+++ b/apollo/ApolloInstance.py Mon Oct 16 18:03:58 2017 -0400
[
@@ -1,23 +1,52 @@
 #!/usr/bin/env python
+import os
 import json
+import shutil
+import tempfile
 import logging
 from util import subtools
+from mako.lookup import TemplateLookup
+
 
 class ApolloInstance(object):
-    def __init__(self, apollo_host):
+    def __init__(self, apollo_host, tool_directory, user_email):
         self.apollo_host = apollo_host
+        self.tool_directory = tool_directory
+        self.default_user = user_email
         self.logger = logging.getLogger(__name__)
+        self.apolloTemplate = self._getApolloTemplate()
+        self._arrow_init()
+    
+    def _arrow_init(self):
+        arrow_config = tempfile.NamedTemporaryFile(bufsize=0)
+        with open(arrow_config.name, 'w') as conf:
+            htmlMakoRendered = self.apolloTemplate.render(
+            apollo_host = self.apollo_host,
+            admin_user = self.default_user,
+            admin_pw = '1234'
+        )
+            conf.write(htmlMakoRendered)
+
+        home_dir = os.path.expanduser('~')
+        arrow_config_dir = os.path.join(home_dir, '.apollo-arrow.yml')
+        shutil.copyfile(arrow_config.name, arrow_config_dir)
+        self.logger.debug("Initated arrow: apollo-arrow.yml= %s", arrow_config_dir)
+
+
+    def _getApolloTemplate(self):
+        mylookup = TemplateLookup(directories=[os.path.join(self.tool_directory, 'templates')],
+                                  output_encoding='utf-8', encoding_errors='replace')
+        apolloTemplate = mylookup.get_template("apollo-arrow.yml")
+        return apolloTemplate
 
     def getHost(self):
         return self.apollo_host
 
     def createApolloUser(self, apollo_user, admin=None):
         p = subtools.arrow_create_user(apollo_user.user_email, apollo_user.firstname, apollo_user.lastname, apollo_user.password, admin) 
-        print p
-        if p:
-            user_info = json.loads(p)
-            user_id = user_info.get('userId')
-        if not p or not user_id:
+        user_info = json.loads(p)
+        user_id = user_info.get('userId')
+        if not user_id:
             self.logger.debug("Cannot create new user: %s; The user may already exist", apollo_user.user_email)
             user_id = subtools.arrow_get_users(apollo_user.user_email)
         self.logger.debug("Got user_id for new or existing user: user_id = %s", str(user_id))
b
diff -r 2191bd0798a9 -r 127037c49bc8 jbrowseArchiveCreator.py
--- a/jbrowseArchiveCreator.py Fri Oct 13 16:19:03 2017 -0400
+++ b/jbrowseArchiveCreator.py Mon Oct 16 18:03:58 2017 -0400
b
@@ -40,6 +40,7 @@
     debug_mode = reader.getDebugMode()
     track_type = reader.getTrackType()
     #jbrowse_path = reader.getJBrowsePath()
+    apollo_path = reader.getApolloPath()
     apollo_host = reader.getApolloHost()
     apollo_user = reader.getApolloUser()
  
@@ -54,7 +55,7 @@
  
     # Create the Track Hub folder
     logging.info('#### JBrowseArchiveCreator: Creating the Track Hub folder ####\n')
-    trackHub = TrackHub(reference_genome, apollo_user, outputFile, extra_files_path, toolDirectory, track_type, apollo_host)
+    trackHub = TrackHub(reference_genome, apollo_user, outputFile, extra_files_path, toolDirectory, track_type, apollo_host, user_email) 
 
     # Create Ordered Dictionary to add the tracks in the tool form order
     logging.info('#### JBrowseArchiveCreator: Preparing track data ####\n')
b
diff -r 2191bd0798a9 -r 127037c49bc8 templates/apollo-arrow.yml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/apollo-arrow.yml Mon Oct 16 18:03:58 2017 -0400
b
@@ -0,0 +1,10 @@
+## Apollo's Arrow: Global Configuration File.
+# Each stanza should contian a single galaxy server to control.
+#
+# You can set the key __default to the name of a default instance
+__default: local
+
+local:
+    url: ${apollo_host}
+    username: ${admin_user}
+    password: ${admin_pw}
b
diff -r 2191bd0798a9 -r 127037c49bc8 tool_dependencies.xml
--- a/tool_dependencies.xml Fri Oct 13 16:19:03 2017 -0400
+++ b/tool_dependencies.xml Mon Oct 16 18:03:58 2017 -0400
b
@@ -58,9 +58,6 @@
                 <actions architecture="x86_64" os="linux">
                     <action type="download_by_url">http://jbrowse.org/wordpress/wp-content/plugins/download-monitor/download.php?id=105</action>
                     <action type="make_directory">$INSTALL_DIR/jbrowse</action>
-                    <action type="set_environment">
-                        <environment_variable action="set_to" name="HOME">$INSTALL_DIR/jbrowse</environment_variable>
-                    </action>
                     <action type="shell_command">
                         export HOME=$INSTALL_DIR/jbrowse &amp;&amp; ./setup.sh
                     </action>
@@ -89,6 +86,8 @@
                     export PYTHONPATH=$PYTHONPATH:$INSTALL_DIR/apollo &amp;&amp; 
                     python setup.py install --install-lib $INSTALL_DIR/apollo
                 </action>
+                <action type="make_directory">$INSTALL_DIR/apollo/config</action>
+                
                 <action type="set_environment">
                     <environment_variable action="append_to" name="PYTHONPATH">$INSTALL_DIR/apollo</environment_variable>
                     <environment_variable action="append_to" name="PATH">$INSTALL_DIR/apollo</environment_variable>
b
diff -r 2191bd0798a9 -r 127037c49bc8 util/Reader.py
--- a/util/Reader.py Fri Oct 13 16:19:03 2017 -0400
+++ b/util/Reader.py Mon Oct 16 18:03:58 2017 -0400
b
@@ -74,6 +74,10 @@
         track_type = self.args.get("track_type")
         return track_type
     
+    def getApolloPath(self):
+        apollo_path = self.args.get("apollo_path")
+        return apollo_path
+    
     def getApolloHost(self):
         apollo_host = self.args.get("apollo_host")
         return apollo_host
b
diff -r 2191bd0798a9 -r 127037c49bc8 util/subtools.py
--- a/util/subtools.py Fri Oct 13 16:19:03 2017 -0400
+++ b/util/subtools.py Mon Oct 16 18:03:58 2017 -0400
[
@@ -342,7 +342,10 @@
     array_call = ['arrow', 'users', 'create_user', user_email, firstname, lastname, password]
     if admin:
         array_call += ['--role', 'admin']
+    logging.debug("%s", array_call)
+    print array_call
     p = subprocess.check_output(array_call)
+    print ("p = %s", p)
     return p
 
 def arrow_update_organism_permissions(user_id, organism, **user_permissions):
@@ -364,9 +367,12 @@
 
 def arrow_get_users(user_email):
     array_call = ['arrow', 'users', 'get_users']
+    logging.debug("%s", array_call)
+    print array_call
     p = subprocess.check_output(array_call)
     all_users = json.loads(p)
     for d  in all_users:
         if d['username'] == user_email:
             return d['userId']
     logging.error("Cannot find user %s", user_email)
+