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