annotate util/Reader.py @ 0:bc00f5c4c59e draft

planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
author yating-l
date Tue, 17 Oct 2017 17:28:05 -0400
parents
children 2ae1e96a8380
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
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
5 from apollo.ApolloUser import ApolloUser
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
6 from util import santitizer
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
7
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
8 class Reader(object):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
9
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
10 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
11 self.inputFile = input_json_file
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
12 self.args = self.loadJson()
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
13
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 def loadJson(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
16 try:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
17 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
18 return json.load(data_file)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
19 except IOError:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
20 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
21 exit(1)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
22
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
23 def getJBrowseHubDir(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
24 try:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
25 return self.args["jbrowse_hub"]
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
26 except KeyError:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
27 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
28 exit(1)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
29
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
30 def getToolDir(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
31 try:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
32 return self.args["tool_directory"]
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
33 except KeyError:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
34 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
35 exit(1)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
36
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
37 def getExtFilesPath(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
38 try:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
39 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
40 except KeyError:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
41 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
42 exit(1)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
43
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
44 def getUserEmail(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
45 try:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
46 return self.args["user_email"]
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
47 except KeyError:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
48 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
49 exit(1)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
50
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
51 def getDebugMode(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
52 try:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
53 return self.args["debug_mode"]
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
54 except KeyError:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
55 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
56 exit(1)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
57
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
58 def getApolloHost(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
59 apollo_host = self.args.get("apollo_host")
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
60 return apollo_host
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
61
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
62
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
63 def getSpeciesName(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
64 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
65 return species_name
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
66
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
67 def getGenomeName(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
68 jbrowse_hub = self.getJBrowseHubDir()
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
69 with open(jbrowse_hub, 'r') as f:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
70 html = f.read()
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
71 m = re.search('The new Organism "(.+?)" is created on Apollo', html)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
72 if m:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
73 genome_name = m.group(1)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
74 else:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
75 print("Cannot find genome name in the jbrowse hub file!")
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
76 exit(1)
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
77 return genome_name
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
78
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
79
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
80 def getApolloUser(self):
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
81 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
82 if not user_info:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
83 firstname = "demo"
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
84 lastname = "user"
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
85 password = "gonramp"
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
86 user_email = self.getUserEmail()
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
87 else:
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
88 firstname = user_info['firstname']
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
89 lastname = user_info['lastname']
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
90 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
91 password = user_info['password']
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
92 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
93 return apollo_user
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
94
bc00f5c4c59e planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git
yating-l
parents:
diff changeset
95