Mercurial > repos > yating-l > gonramp_apollo_tools
annotate apollo/ApolloOrganism.py @ 0:1da8b9042af4 draft
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
author | yating-l |
---|---|
date | Mon, 27 Nov 2017 14:47:03 -0500 |
parents | |
children | 4be6fcac4bf2 |
rev | line source |
---|---|
0
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
1 #!/usr/bin/env python |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
2 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
3 import json |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
4 import logging |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
5 from util import subtools |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
6 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
7 class ApolloOrganism(object): |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
8 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
9 def __init__(self, organism_name, organism_dir): |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
10 self.organism_name = organism_name |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
11 self.organism_dir = organism_dir |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
12 self.logger = logging.getLogger(__name__) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
13 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
14 def addOrganism(self): |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
15 exist = self.getOrganism(self.organism_name) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
16 if not exist: |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
17 self.logger.debug("The organism does not exist.") |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
18 p = subtools.arrow_add_organism(self.organism_name, self.organism_dir) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
19 if not p: |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
20 self.logger.error("The user is not authorized to add organism") |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
21 exit(-1) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
22 organism = json.loads(p) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
23 organism_id = organism['id'] |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
24 self.logger.debug("A new organism %s was added to Apollo instance", p) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
25 return organism_id |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
26 else: |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
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) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
28 exit(-1) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
29 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
30 #TODO: the JSON dictionary return by deleteOrganism still contains the deleted organism. Improve the API. |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
31 def deleteOrganism(self): |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
32 organism_id = self.getOrganism(self.organism_name) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
33 if organism_id: |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
34 self.logger.debug("Deleting the organism %s", self.organism_name) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
35 subtools.arrow_delete_organism(organism_id) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
36 if not self.getOrganism(self.organism_name): |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
37 self.logger.debug("Organism %s has been deleted", self.organism_name) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
38 else: |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
39 self.logger.error("Organism %s cannot be deleted", self.organism_name) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
40 exit(-1) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
41 else: |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
42 self.logger.error("Organism %s doesn't exist", self.organism_name) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
43 exit(-1) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
44 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
45 #TODO: filtering by commonName doesn't work. Improve the API. |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
46 @staticmethod |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
47 def getOrganism(organism_name): |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
48 p = subtools.arrow_get_organism(organism_name) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
49 if p: |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
50 return str(p) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
51 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
52 #TODO: API update_organism not working. Improve the API to enable updating directory. |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
53 def overwriteOrganism(self): |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
54 self.deleteOrganism() |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
55 p = subtools.arrow_add_organism(self.organism_name, self.organism_dir) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
56 if not p: |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
57 self.logger.error("The user is not authorized to add organism") |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
58 exit(-1) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
59 organism = json.loads(p) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
60 organism_id = organism['id'] |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
61 self.logger.debug("A new organism %s has been added to Apollo instance", p) |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
62 return organism_id |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
63 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
64 |
1da8b9042af4
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
yating-l
parents:
diff
changeset
|
65 |