annotate util/Reader.py @ 2:8ff4b84d709f draft

planemo upload for repository https://github.com/Yating-L/jbrowsehub-to-apollo.git commit 324276a31f1d9e410c37d4514ad9432ba6051e35-dirty
author yating-l
date Wed, 25 Oct 2017 12:41:34 -0400
parents 2ae1e96a8380
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
1 import json
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
2 import re
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
3 import logging
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
4 import codecs
1
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
5 import socket
0
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
6 from apollo.ApolloUser import ApolloUser
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
7 from util import santitizer
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
8
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
9 class Reader(object):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
10
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
11 def __init__(self, input_json_file):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
12 self.inputFile = input_json_file
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
13 self.args = self.loadJson()
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
14
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
15
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
16 def loadJson(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
17 try:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
18 data_file = codecs.open(self.inputFile, 'r', 'utf-8')
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
19 return json.load(data_file)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
20 except IOError:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
21 print "Cannot find JSON file\n"
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
22 exit(1)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
23
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
24 def getJBrowseHubDir(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
25 try:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
26 return self.args["jbrowse_hub"]
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
27 except KeyError:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
28 print ("jbrowse_hub is not defined in the input file!")
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
29 exit(1)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
30
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
31 def getToolDir(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
32 try:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
33 return self.args["tool_directory"]
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
34 except KeyError:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
35 print ("tool_directory is not defined in the input file!")
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
36 exit(1)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
37
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
38 def getExtFilesPath(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
39 try:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
40 return self.args["extra_files_path"]
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
41 except KeyError:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
42 print ("extra_files_path is not defined in the input file!")
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
43 exit(1)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
44
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
45 def getUserEmail(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
46 try:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
47 return self.args["user_email"]
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
48 except KeyError:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
49 print ("user_email is not defined in the input file!")
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
50 exit(1)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
51
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
52 def getDebugMode(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
53 try:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
54 return self.args["debug_mode"]
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
55 except KeyError:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
56 print ("debug_mode is not defined in the input file!")
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
57 exit(1)
1
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
58
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
59 def getPortNum(self):
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
60 try:
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
61 return self.args["port"]
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
62 except KeyError:
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
63 print ("port is not defined in the input file!")
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
64 exit(1)
0
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
65
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
66 def getApolloHost(self):
1
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
67 #apollo_host = self.args.get("apollo_host")
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
68 hostname = socket.gethostname()
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
69 ip = socket.gethostbyname(hostname)
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
70 protocol = socket.getprotobyname(hostname)
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
71 apollo_host = str(protocol) + str(ip)
0
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
72 return apollo_host
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
73
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
74
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
75 def getSpeciesName(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
76 species_name = santitizer.sanitize_name_input(self.args["species_name"])
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
77 return species_name
1
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
78
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
79 def getAdminUser(self):
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
80 admin_info = self.args.get("apollo_admin")
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
81 user_email = admin_info['user_email']
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
82 password = admin_info['password']
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
83 apollo_admin = ApolloUser(user_email, password)
2ae1e96a8380 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a8c47ae0025953ef398bdc689dc5df5516edf686-dirty
yating-l
parents: 0
diff changeset
84 return apollo_admin
0
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
85
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
86 def getApolloUser(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
87 user_info = self.args.get("apollo_user")
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
88 if not user_info:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
89 firstname = "demo"
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
90 lastname = "user"
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
91 password = "gonramp"
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
92 user_email = self.getUserEmail()
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
93 else:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
94 firstname = user_info['firstname']
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
95 lastname = user_info['lastname']
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
96 user_email = user_info['user_email']
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
97 password = user_info['password']
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
98 apollo_user = ApolloUser(user_email, firstname, lastname, password)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
99 return apollo_user
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
100
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
101