From cddf637ac9cfe11badc5844767f265560d1ba25e Mon Sep 17 00:00:00 2001 From: Cory Maughmer Date: Tue, 25 Aug 2020 13:51:46 -0500 Subject: [PATCH] returnAllOrganisms parameter for add_organism (#41) * 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 Co-authored-by: Cory Maughmer --- README.rst | 2 ++ apollo/organisms/__init__.py | 28 +++++++++++++++++---- arrow/commands/organisms/add_organism.py | 9 +++++-- arrow/commands/organisms/delete_organism.py | 11 +++++--- arrow/commands/remote/add_organism.py | 7 +++++- bootstrap_apollo.sh | 7 ++++++ docs/commands/organisms.rst | 7 ++++-- setup.py | 2 +- 8 files changed, 59 insertions(+), 14 deletions(-) diff --git a/README.rst b/README.rst index 1ad79675..265aecef 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/apollo/organisms/__init__.py b/apollo/organisms/__init__.py index 0173ef21..37991bbb 100644 --- a/apollo/organisms/__init__.py +++ b/apollo/organisms/__init__.py @@ -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 @@ -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 """ @@ -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): @@ -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): """ diff --git a/arrow/commands/organisms/add_organism.py b/arrow/commands/organisms/add_organism.py index 46df55be..8da97847 100644 --- a/arrow/commands/organisms/add_organism.py +++ b/arrow/commands/organisms/add_organism.py @@ -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) diff --git a/arrow/commands/organisms/delete_organism.py b/arrow/commands/organisms/delete_organism.py index 4950dcfa..5353dc98 100644 --- a/arrow/commands/organisms/delete_organism.py +++ b/arrow/commands/organisms/delete_organism.py @@ -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) diff --git a/arrow/commands/remote/add_organism.py b/arrow/commands/remote/add_organism.py index fca813a2..8d0f529f 100644 --- a/arrow/commands/remote/add_organism.py +++ b/arrow/commands/remote/add_organism.py @@ -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) diff --git a/bootstrap_apollo.sh b/bootstrap_apollo.sh index 92166e7a..cb732541 100755 --- a/bootstrap_apollo.sh +++ b/bootstrap_apollo.sh @@ -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 ;; diff --git a/docs/commands/organisms.rst b/docs/commands/organisms.rst index bfd4205a..4f32c092 100644 --- a/docs/commands/organisms.rst +++ b/docs/commands/organisms.rst @@ -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. @@ -65,7 +66,7 @@ Remove features of an organism **Help** -Delete an organim +Delete an organism **Output** @@ -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 @@ -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. diff --git a/setup.py b/setup.py index 03ca7a83..8978aa6a 100644 --- a/setup.py +++ b/setup.py @@ -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",