comparison apollo/ApolloOrganism.py @ 0:ce4f91831680 draft default tip

planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
author yating-l
date Fri, 16 Feb 2018 10:57:13 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ce4f91831680
1 #!/usr/bin/env python
2
3 import json
4 import logging
5 from util import subtools
6
7 class ApolloOrganism(object):
8
9 def __init__(self, organism_name, organism_dir):
10 self.organism_name = organism_name
11 self.organism_dir = organism_dir
12 self.logger = logging.getLogger(__name__)
13
14 def addOrganism(self):
15 exist = subtools.arrow_get_organism(self.organism_name)
16 if not exist:
17 self.logger.debug("The organism does not exist.")
18 p = subtools.arrow_add_organism(self.organism_name, self.organism_dir)
19 if not p:
20 self.logger.error("The user is not authorized to add organism")
21 exit(-1)
22 organism = json.loads(p)
23 organism_id = organism['id']
24 self.logger.debug("A new organism %s was added to Apollo instance", p)
25 return organism_id
26 else:
27 self.logger.error("The organism %s is already on Apollo instance! Rerun the tool to use a different species name or choose to overwrite the organism", self.organism_name)
28 exit(-1)
29
30 #TODO: the JSON dictionary return by deleteOrganism still contains the deleted organism. Improve the API.
31 def deleteOrganism(self):
32 organism_id = subtools.arrow_get_organism(self.organism_name)
33 if organism_id:
34 self.logger.debug("Deleting the organism %s", self.organism_name)
35 subtools.arrow_delete_organism(organism_id)
36 if not subtools.arrow_get_organism(self.organism_name):
37 self.logger.debug("Organism %s has been deleted", self.organism_name)
38 else:
39 self.logger.error("Organism %s cannot be deleted", self.organism_name)
40 exit(-1)
41 else:
42 self.logger.error("Organism %s doesn't exist", self.organism_name)
43 exit(-1)
44
45 #TODO: API update_organism not working. Improve the API to enable updating directory.
46 def overwriteOrganism(self):
47 self.deleteOrganism()
48 p = subtools.arrow_add_organism(self.organism_name, self.organism_dir)
49 if not p:
50 self.logger.error("The user is not authorized to add organism")
51 exit(-1)
52 organism = json.loads(p)
53 organism_id = organism['id']
54 self.logger.debug("A new organism %s has been added to Apollo instance", p)
55 return organism_id
56
57
58