Skip to content
Snippets Groups Projects

Release v2.1.0

Merged Loraine Gueguen requested to merge dev into master
1 file
+ 6
4
Compare changes
  • Side-by-side
  • Inline
+ 69
68
@@ -4,9 +4,6 @@
import yaml
import logging
import sys
import os
import subprocess
import bioblend
import constants
def load_yaml(yaml_file):
@@ -36,12 +33,16 @@ def parse_config(config_file):
"""
config_dict = load_yaml(config_file)
if isinstance(config_dict, dict):
#logging.debug("Config dictionary: {0}".format(config_dict))
return config_dict
else:
logging.critical("Config yaml file is not a dictionary" % config_file)
if not isinstance(config_dict, dict):
logging.critical("Config yaml file is not a dictionary (%s)" % config_file)
sys.exit()
else:
for required_parameter in constants.REQUIRED_PARAMETERS:
if not config_dict[required_parameter]:
logging.critical("{0} parameter improperly configured in config file {1}".format(required_parameter, config_file))
sys.exit()
return config_dict
def parse_input(input_file):
"""
@@ -75,47 +76,13 @@ def filter_empty_not_empty_items(li):
filtered_dict["not_empty"].append(i)
return filtered_dict
def no_empty_items(li):
def check_galaxy_state(genus_lowercase, species, script_dir):
"""
Read the logs of the galaxy container for the current species to check if the service is "ready"
:param genus_lowercase:
:param species:
:param script_dir:
:return:
"""
# Run supervisorctl status in the galaxy container via serexec
# Change serexec permissions in repo
try:
os.chmod("%s/serexec" % script_dir, 0o0755)
except PermissionError:
logging.warning("serexec permissions incorrect in %s" % script_dir)
galaxy_logs = subprocess.run(["%s/serexec" % script_dir, "{0}_{1}_galaxy".format(genus_lowercase, species),
"supervisorctl", "status", "galaxy:"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if "galaxy:galaxy_web RUNNING" in str(galaxy_logs.stdout) \
and "galaxy:handler0 RUNNING" in str(galaxy_logs.stdout) \
and "galaxy:handler1 RUNNING" in str(galaxy_logs.stdout):
return 1
else:
return 0
def get_species_history_id(instance, full_name):
"""
Set and return the current species history id in its galaxy instance
:param instance:
:param full_name:
:return:
"""
histories = instance.histories.get_histories(name=str(full_name))
history_id = histories[0]["id"]
show_history = instance.histories.show_history(history_id=history_id)
return [history_id, show_history]
empty = True
for i in li:
if i is None or i == "":
empty = False
return empty
def get_gspecies_string_from_sp_dict(sp_dict):
@@ -143,7 +110,6 @@ def get_unique_species_str_list(sp_dict_list):
return unique_species_li
def get_unique_species_dict_list(sp_dict_list):
"""
Filter the species dictionary list to return only unique genus_species combinations
@@ -162,34 +128,67 @@ def get_unique_species_dict_list(sp_dict_list):
if gspecies not in unique_species_dict.keys() or ( constants.ORG_PARAM_DESC_MAIN_SPECIES in sp[constants.ORG_PARAM_DESC].keys() and
sp[constants.ORG_PARAM_DESC][constants.ORG_PARAM_DESC_MAIN_SPECIES] == True ) :
unique_species_dict[gspecies] = sp
else:
continue
for k, v in unique_species_dict.items():
unique_species_list_of_dict.append(v)
return unique_species_list_of_dict
def run_tool(instance, tool_id, history_id, tool_inputs):
def get_sp_picture(sp_dict_list):
"""
Get the picture for each species: the picture of the main strain if exists, other strain if not
"""
output_dict = None
try:
logging.debug("Running tool {0} with tool inputs: {1}".format(tool_id, tool_inputs))
output_dict = instance.tools.run_tool(
tool_id=tool_id,
history_id=history_id,
tool_inputs=tool_inputs)
except bioblend.ConnectionError:
logging.error("Unexpected HTTP response (bioblend.ConnectionError) when running tool {0} with tool inputs: {1}".format(tool_id, tool_inputs))
sp_picture_dict = {}
for sp in sp_dict_list:
return output_dict
genus_species = get_gspecies_string_from_sp_dict(sp)
# logging.debug("picture path for {0} {1}: {2}".format(genus_species,
# sp[constants.ORG_PARAM_DESC][constants.ORG_PARAM_DESC_STRAIN],
# sp[constants.ORG_PARAM_DESC][constants.ORG_PARAM_DESC_PICTURE_PATH]))
# no picture stored yet for this genus_species
if genus_species not in sp_picture_dict.keys() \
or (genus_species in sp_picture_dict.keys()
and sp_picture_dict[genus_species] == None):
if constants.ORG_PARAM_DESC_PICTURE_PATH in sp[constants.ORG_PARAM_DESC].keys() \
and sp[constants.ORG_PARAM_DESC][constants.ORG_PARAM_DESC_PICTURE_PATH] != None \
and sp[constants.ORG_PARAM_DESC][constants.ORG_PARAM_DESC_PICTURE_PATH] != "":
sp_picture_dict[genus_species] = sp[constants.ORG_PARAM_DESC][constants.ORG_PARAM_DESC_PICTURE_PATH]
else:
sp_picture_dict[genus_species] = None
# overwrite stored picture if a picture exists for the main strain
if (constants.ORG_PARAM_DESC_MAIN_SPECIES in sp[constants.ORG_PARAM_DESC].keys()
and sp[constants.ORG_PARAM_DESC][constants.ORG_PARAM_DESC_MAIN_SPECIES] == True )\
and (constants.ORG_PARAM_DESC_PICTURE_PATH in sp[constants.ORG_PARAM_DESC].keys()
and sp[constants.ORG_PARAM_DESC][constants.ORG_PARAM_DESC_PICTURE_PATH] != None
and sp[constants.ORG_PARAM_DESC][constants.ORG_PARAM_DESC_PICTURE_PATH] != ""):
sp_picture_dict[genus_species] = sp[constants.ORG_PARAM_DESC][constants.ORG_PARAM_DESC_PICTURE_PATH]
# logging.debug("picture dict: %s" % sp_picture_dict)
return sp_picture_dict
def get_sp_jbrowse_links(org_list):
"""
Get the jbrowse links from all strains for each species
"""
def run_tool_and_get_single_output_dataset_id(instance, tool_id, history_id, tool_inputs):
jbrowse_links_dict = {}
output_dict = run_tool(instance, tool_id, history_id, tool_inputs)
single_output_dataset_id = output_dict["outputs"][0]["id"]
for org in org_list:
gspecies = org.genus_species
if org.contig_prefix != "":
if gspecies not in jbrowse_links_dict.keys():
jbrowse_links_dict[gspecies] = org.contig_prefix + ">" + org.species_folder_name
else:
jbrowse_links_dict[gspecies] = jbrowse_links_dict[gspecies] + ";" + org.contig_prefix + ">" + org.species_folder_name
return single_output_dataset_id
return jbrowse_links_dict
def create_org_param_dict_from_constants():
"""
@@ -206,9 +205,11 @@ def create_org_param_dict_from_constants():
org_param_dict["org_param_desc_strain"] = constants.ORG_PARAM_DESC_STRAIN
org_param_dict["org_param_desc_common_name"] = constants.ORG_PARAM_DESC_COMMON_NAME
org_param_dict["org_param_desc_origin"] = constants.ORG_PARAM_DESC_ORIGIN
org_param_dict["org_param_desc_picture_path"] = constants.ORG_PARAM_DESC_PICTURE_PATH
org_param_dict["org_param_desc_main_species"] = constants.ORG_PARAM_DESC_MAIN_SPECIES
org_param_dict["org_param_data"] = constants.ORG_PARAM_DATA
org_param_dict["org_param_data_genome_path"] = constants.ORG_PARAM_DATA_GENOME_PATH
org_param_dict["org_param_data_genome_contig_prefix"] = constants.ORG_PARAM_DATA_GENOME_CONTIG_PREFIX
org_param_dict["org_param_data_transcripts_path"] = constants.ORG_PARAM_DATA_TRANSCRIPTS_PATH
org_param_dict["org_param_data_proteins_path"] = constants.ORG_PARAM_DATA_PROTEINS_PATH
org_param_dict["org_param_data_gff_path"] = constants.ORG_PARAM_DATA_GFF_PATH
@@ -218,8 +219,8 @@ def create_org_param_dict_from_constants():
org_param_dict["org_param_data_blastx_path"] = constants.ORG_PARAM_DATA_BLASTX_PATH
org_param_dict["org_param_data_genome_version"] = constants.ORG_PARAM_DATA_GENOME_VERSION
org_param_dict["org_param_data_ogs_version"] = constants.ORG_PARAM_DATA_OGS_VERSION
org_param_dict["org_param_data_performed_by"] = constants.ORG_PARAM_DATA_PERFORMED_BY
org_param_dict["org_param_services"] = constants.ORG_PARAM_SERVICES
org_param_dict["org_param_services_blast"] = constants.ORG_PARAM_SERVICES_BLAST
org_param_dict["org_param_services_go"] = constants.ORG_PARAM_SERVICES_GO
return org_param_dict
\ No newline at end of file
return org_param_dict
Loading