Skip to content

Commit

Permalink
returnAllOrganisms parameter for add_organism (#41)
Browse files Browse the repository at this point in the history
* added apollo3 link

* Exposed returnAllOrganisms option to the Organisms.addOrganisms API call

* param name fix

* rebuilt arrow properly

* fixed call

* added delete organisms

* arrow/docs rebuild

Co-authored-by: Nathan Dunn <[email protected]>
Co-authored-by: Cory Maughmer <[email protected]>
  • Loading branch information
3 people authored Aug 25, 2020
1 parent 3733712 commit cddf637
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ Or with the Arrow client:
History
-------

- 4.2.6
- Prevent from displaying login/password in the logs
- 4.2.5
- Prevent from displaying login/password in the logs
- 4.2.4
Expand Down
28 changes: 23 additions & 5 deletions apollo/organisms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OrganismsClient(Client):

@raise_error_decorator
def add_organism(self, common_name, directory, blatdb=None, genus=None,
species=None, public=False, metadata=None):
species=None, public=False, metadata=None, return_all=None):
"""
Add an organism
Expand All @@ -37,6 +37,9 @@ def add_organism(self, common_name, directory, blatdb=None, genus=None,
:type metadata: str
:param metadata: JSON formatted arbitrary metadata
:type return_all: bool
:param return_all: Return all organisms (true / false) (default true)
:rtype: dict
:return: a dictionary with information about the new organism
"""
Expand All @@ -57,13 +60,18 @@ def add_organism(self, common_name, directory, blatdb=None, genus=None,
# Apollo wants a string
metadata = json.dumps(metadata)
data['metadata'] = metadata
if return_all is not None:
data['returnAllOrganisms'] = return_all

response = self.post('addOrganism', data)
# Apollo decides here that it would be nice to return information about
# EVERY organism. LMAO.
if type(response) is not list:
return response
return [x for x in response if x['commonName'] == common_name][0]
if len(response) > 0:
return [x for x in response if x['commonName'] == common_name][0]
else:
return data

def update_organism(self, organism_id, common_name, directory, blatdb=None, species=None, genus=None, public=False,
no_reload_sequences=False):
Expand Down Expand Up @@ -149,17 +157,27 @@ def show_organism(self, common_name):
orgs = orgs[0]
return orgs

def delete_organism(self, organism_id):
def delete_organism(self, organism_id, return_all=None):
"""
Delete an organim
Delete an organism
:type organism_id: str
:param organism_id: Organism ID Number
:type return_all: bool
:param return_all: Return all organisms (true / false) (default true)
:rtype: list
:return: A list of all remaining organisms
"""
return self.post('deleteOrganism', {'id': organism_id})
data = {
'id': organism_id,
}
if return_all is not None:
data['returnAllOrganisms'] = return_all

return self.post('deleteOrganism', data)

def delete_features(self, organism_id):
"""
Expand Down
9 changes: 7 additions & 2 deletions arrow/commands/organisms/add_organism.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@
help="JSON formatted arbitrary metadata",
type=str
)
@click.option(
"--return_all",
help="Return all organisms (true / false) (default true)",
is_flag=True
)
@pass_context
@custom_exception
@dict_output
def cli(ctx, common_name, directory, blatdb="", genus="", species="", public=False, metadata=""):
def cli(ctx, common_name, directory, blatdb="", genus="", species="", public=False, metadata="", return_all=""):
"""Add an organism
Output:
a dictionary with information about the new organism
"""
return ctx.gi.organisms.add_organism(common_name, directory, blatdb=blatdb, genus=genus, species=species, public=public, metadata=metadata)
return ctx.gi.organisms.add_organism(common_name, directory, blatdb=blatdb, genus=genus, species=species, public=public, metadata=metadata, return_all=return_all)
11 changes: 8 additions & 3 deletions arrow/commands/organisms/delete_organism.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

@click.command('delete_organism')
@click.argument("organism_id", type=str)
@click.option(
"--return_all",
help="Return all organisms (true / false) (default true)",
is_flag=True
)
@pass_context
@custom_exception
@list_output
def cli(ctx, organism_id):
"""Delete an organim
def cli(ctx, organism_id, return_all=""):
"""Delete an organism
Output:
A list of all remaining organisms
"""
return ctx.gi.organisms.delete_organism(organism_id)
return ctx.gi.organisms.delete_organism(organism_id, return_all=return_all)
7 changes: 6 additions & 1 deletion arrow/commands/remote/add_organism.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ def cli(ctx, common_name, organism_data, blatdb="", genus="", species="", public
a dictionary with information about the new organism
"""
return ctx.gi.remote.add_organism(common_name, organism_data, blatdb=blatdb, genus=genus, species=species, public=public, non_default_translation_table=non_default_translation_table, metadata=metadata)
print("running the add organism command ")
return_all = return_no_organisms is None or return_no_organisms is True
print("return all is: "+str(return_all))
return ctx.gi.remote.add_organism(common_name, organism_data, blatdb=blatdb, genus=genus, species=species,
public=public, non_default_translation_table=non_default_translation_table,
metadata=metadata, return_all=return_all)
7 changes: 7 additions & 0 deletions bootstrap_apollo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ do
mkdir -p $APOLLO_DATA_DIRECTORY
shift
;;
--apollo3)
SHOULD_LAUNCH_DOCKER=0
ARROW_GLOBAL_CONFIG_PATH=`pwd`/test-data/local-apollo3-arrow.yml
APOLLO_DATA_DIRECTORY=$GALAXY_SHARED_DIR
mkdir -p $APOLLO_DATA_DIRECTORY
shift
;;
*)
shift
;;
Expand Down
7 changes: 5 additions & 2 deletions docs/commands/organisms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Add an organism
--species TEXT Species
--public Should the organism be public or not
--metadata TEXT JSON formatted arbitrary metadata
--return_all Return all organisms (true / false) (default true)
-h, --help Show this message and exit.

Expand Down Expand Up @@ -65,7 +66,7 @@ Remove features of an organism

**Help**

Delete an organim
Delete an organism


**Output**
Expand All @@ -76,7 +77,8 @@ Delete an organim
**Options**::


-h, --help Show this message and exit.
--return_all Return all organisms (true / false) (default true)
-h, --help Show this message and exit.

``get_organism_creator`` command
Expand Down Expand Up @@ -221,5 +223,6 @@ Update an organism
--public User's email
--no_reload_sequences Set this if you don't want Apollo to reload genome
sequences (no change in genome sequence)
-h, --help Show this message and exit.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setup(
name="apollo",
version='4.2.5',
version='4.2.6',
description="Apollo API library",
long_description=readme,
author="Helena Rasche;Anthony Bretaudeau;Nathan Dunn",
Expand Down

0 comments on commit cddf637

Please sign in to comment.