Skip to content

Commit

Permalink
Rename function and add filter by release, taxonomy and assemblies
Browse files Browse the repository at this point in the history
  • Loading branch information
tcezard committed May 23, 2024
1 parent 73721ec commit 64c1ffa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,30 @@ def get_release_inventory_info_for_assembly(taxonomy_id, assembly_accession, rel
return results[0][0]


def get_release_pending(release_species_inventory_table, metadata_connection_handle, status=None):
def format_status(status_list):
return f"({str(status_list).strip('[]')})"

if 'Pending' in status:
status.remove('Pending')
if status:
status_statement = f"and (release_status in {format_status(status)} or release_status is null)"
def get_release_for_status_and_version(release_species_inventory_table, metadata_connection_handle, status=None,
release_version=None, taxonomy_id=None, assembly_accessions=None):
def format_list(list_to_format):
return f"({str(list_to_format).strip('[]')})"

if status:
if 'Pending' in status:
status.remove('Pending')
if status:
status_statement = f"and (release_status in {format_list(status)} or release_status is null)"
else:
status_statement = f"and release_status is null"
else:
status_statement = f"and release_status is null"
status_statement = f"and release_status in {format_list(status)}"
else:
status_statement = f"and release_status in {format_status(status)}"
status_statement = None

query = (f"select taxonomy, assembly_accession, release_version from {release_species_inventory_table} "
"where should_be_released "
"and num_rs_to_release > 0 "
f"{status_statement}" if status_statement else ''
"ORDER BY release_version, taxonomy, assembly_accession")
f"where should_be_released "
f"and num_rs_to_release > 0 "
f"{status_statement}" if status_statement else ''
f"and release_version={release_version} " if release_version else ''
f"and taxonomy={taxonomy_id} " if taxonomy_id else ''
f"and assembly_accessions in {format_list(assembly_accessions)} " if assembly_accessions else ''
"ORDER BY release_version, taxonomy, assembly_accession")
results = get_all_results_for_query(metadata_connection_handle, query)
yield results
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from argparse import ArgumentParser

import os
Expand All @@ -22,7 +23,7 @@
from ebi_eva_common_pyutils.logger import logging_config
from ebi_eva_internal_pyutils.metadata_utils import get_metadata_connection_handle
from ebi_eva_common_pyutils.config import cfg
from run_release_in_embassy.release_metadata import get_release_assemblies_for_taxonomy, get_release_pending
from run_release_in_embassy.release_metadata import get_release_assemblies_for_taxonomy, get_release_for_status_and_version
from run_release_in_embassy.release_common_utils import get_release_folder_name


Expand Down Expand Up @@ -106,15 +107,17 @@ def run_release_for_species(taxonomy_id, release_assemblies, release_version, re
run_command_with_output(f"Running workflow file {workflow_file_path}", workflow_command)


def list_pending_release(status):
def list_pending_release(status, release_version, taxonomy_id, assembly_accessions):
private_config_xml_file = cfg.query("maven", "settings_file")
profile = cfg.query("maven", "environment")
release_species_inventory_table = cfg.query('release', 'inventory_table')
with get_metadata_connection_handle(profile, private_config_xml_file) as metadata_connection_handle:
header = ['taxonomy', 'assembly_accession', 'release_version']
table = []
for taxonomy, assembly_accession, release_version in get_release_pending(release_species_inventory_table,
metadata_connection_handle, status):
for taxonomy, assembly_accession, release_version in get_release_for_status_and_version(
release_species_inventory_table, metadata_connection_handle, status, release_version,
taxonomy_id, assembly_accessions
):
table.append((taxonomy, assembly_accession, release_version))
pretty_print(header, table)

Expand All @@ -129,20 +132,27 @@ def load_config(*args):

def main():
argparse = ArgumentParser()
argparse.add_argument("--list", nargs='+',
argparse.add_argument_group()
argparse.add_argument("--list_status", nargs='+',
help="Generate the list of species and assembly that needs to be released",
choices=['Pending', 'Started', 'Completed'])
argparse.add_argument("--taxonomy_id", help="ex: 9913", required=True)
argparse.add_argument("--taxonomy_id", help="ex: 9913")
argparse.add_argument("--assembly_accessions", nargs='+', help="ex: GCA_000003055.3")
argparse.add_argument("--release_version", required=True)
argparse.add_argument("--resume", default=False, required=False,
argparse.add_argument("--release_version")
argparse.add_argument("--resume", default=False,
help="Resume the nextflow pipeline for the specified taxonomy and assembly")
args = argparse.parse_args()
load_config()
logging_config.add_stdout_handler()
if args.list:
list_pending_release(args.list)
if args.list_status:
list_pending_release(args.list, args.release_version, args.taxonomy_id, args.assembly_accessions)
else:
if not args.taxonomy_id:
logger.error('--taxonomy_id is required when running the release')
sys.exit(1)
if not args.release_version:
logger.error('--release_version is required when running the release')
sys.exit(1)
run_release_for_species(args.taxonomy_id, args.assembly_accessions, args.release_version, args.resume)


Expand Down

0 comments on commit 64c1ffa

Please sign in to comment.