diff --git a/gga_init.py b/gga_init.py index e630db1238f396cdd0e294c8d38d02058bb77561..6c2f7029bf9f7898deaf172f2303565406cfb9c3 100755 --- a/gga_init.py +++ b/gga_init.py @@ -38,7 +38,7 @@ class DeploySpeciesStack(speciesData.SpeciesData): """ - def make_directory_tree(self): + def make_directory_tree(self, picture_path): """ Generate the directory tree for an organism @@ -76,19 +76,19 @@ class DeploySpeciesStack(speciesData.SpeciesData): logging.debug("Using default banner for Tripal pages") self.config.pop(constants.CONF_TRIPAL_BANNER_PATH, None) - # Copy the organism picture for tripal if one was specified in the input species - if self.picture_path is not None: - if os.path.isfile(self.picture_path): - picture_path_basename = os.path.basename(self.picture_path) + # Copy the organism picture for tripal + if picture_path is not None: + if os.path.isfile(picture_path): + picture_path_basename = os.path.basename(picture_path) picture_path_filename, picture_path_extension = os.path.splitext(picture_path_basename) if picture_path_extension == ".png" or picture_path_extension == ".jpg": picture_dest_name = "species%s" % picture_path_extension picture_dest_path = os.path.join(self.species_dir, picture_dest_name) - shutil.copy(self.picture_path, picture_dest_path) + shutil.copy(picture_path, picture_dest_path) else: - logging.error("Specified organism picture has wrong extension (must be '.png' or '.jpg'): {0}".format(self.picture_path)) + logging.error("Specified organism picture has wrong extension (must be '.png' or '.jpg'): {0}".format(picture_path)) else: - logging.error("Specified organism picture not found {0} for {1}".format(self.picture_path, self.genus_uppercase + " " + self.species)) + logging.error("Specified organism picture not found {0} for {1}".format(picture_path, self.genus_uppercase + " " + self.species)) # Create nginx dirs and write/re-write nginx conf make_dirs(dir_paths_li=["./nginx", "./nginx/conf"]) @@ -127,10 +127,10 @@ class DeploySpeciesStack(speciesData.SpeciesData): # Create input file vars dict input_vars = {"genus": self.genus_lowercase, "Genus": self.genus_uppercase, "species": self.species, - "genus_species": self.genus_species, "genus_species_strain_sex": self.species_folder_name, - "genus_species_sex": "{0}_{1}_{2}".format(self.genus_lowercase, self.species.lower(), self.sex), - "strain": self.strain, "sex": self.sex, "Genus_species": self.genus_species[0].upper() + self.genus_species[1:], - "blast": self.blast, "picture_path": self.picture_path} + "genus_species": self.genus_species, "genus_species_strain_sex": self.species_folder_name, + "genus_species_sex": "{0}_{1}_{2}".format(self.genus_lowercase, self.species_lower(), self.sex), + "strain": self.strain, "sex": self.sex, "Genus_species": "{0} {1}".format(self.genus_uppercase, self.species_lower()), + "blast": self.blast, "picture_path": self.picture_path} if (len(self.config.keys()) == 0): logging.error("Empty config dictionary") # Merge the two dicts @@ -402,6 +402,7 @@ if __name__ == "__main__": make_traefik_compose_files(config=config, main_dir=main_dir) unique_sp_dict_list = utilities.get_unique_species_dict_list(sp_dict_list=sp_dict_list) + sp_picture_dict = utilities.get_sp_picture(sp_dict_list=sp_dict_list) logging.info("Deploying stacks for organisms in input file %s" % args.input) for sp_dict in unique_sp_dict_list: @@ -422,7 +423,8 @@ if __name__ == "__main__": logging.info("gga_init.py called for %s %s", deploy_stack_for_current_organism.genus, deploy_stack_for_current_organism.species) # Make/update directory tree - deploy_stack_for_current_organism.make_directory_tree() + picture_path = sp_picture_dict[deploy_stack_for_current_organism.genus_species] + deploy_stack_for_current_organism.make_directory_tree(picture_path) logging.info("Successfully generated the directory tree for %s %s", deploy_stack_for_current_organism.genus, deploy_stack_for_current_organism.species) # Make compose files diff --git a/speciesData.py b/speciesData.py index 49ffed5416ede69e0f49fd295608ebd20cc735e7..34c817fd23e93710c086b1534d0207730fcfc83f 100755 --- a/speciesData.py +++ b/speciesData.py @@ -93,20 +93,25 @@ class SpeciesData: else: self.picture_path = None - self.genus_lowercase = self.genus[0].lower() + self.genus[1:] - self.genus_uppercase = self.genus[0].upper() + self.genus[1:] + self.genus_lowercase = self.genus.lower() + self.species_lower = self.species.lower() + self.genus_uppercase = self.genus[0].upper() + self.genus_lowercase[1:] + self.genus_species = "{0}_{1}".format(self.genus_lowercase, self.species_lower) + self.chado_species_name = "{0} {1}".format(self.species, self.sex) self.full_name = ' '.join(utilities.filter_empty_not_empty_items([self.genus_uppercase, self.species, self.strain, self.sex])["not_empty"]) - self.full_name_lowercase = self.full_name.lower() self.abbreviation = "_".join(utilities.filter_empty_not_empty_items([self.genus_lowercase[0], self.species, self.strain, self.sex])["not_empty"]) - - self.genus_species = "{0}_{1}".format(self.genus.lower(), self.species.lower()) + + self.species_folder_name = "_".join(utilities.filter_empty_not_empty_items( + [self.genus_lowercase, self.species_lower(), self.strain.lower(), + self.sex.lower()])["not_empty"]) + self.dataset_prefix = None if self.sex is not None or self.sex != "": - self.dataset_prefix = self.genus[0].lower() + "_" + self.species.lower() + "_" + self.sex[0].lower() + self.dataset_prefix = self.genus[0].lower() + "_" + self.species_lower + "_" + self.sex[0].lower() else: - self.dataset_prefix = self.genus[0].lower() + "_" + self.species.lower() + self.dataset_prefix = self.genus[0].lower() + "_" + self.species_lower # Bioblend/Chado IDs for an organism analyses/organisms/datasets/history/library self.org_id = None @@ -131,6 +136,3 @@ class SpeciesData: self.api_key = None # API key used to communicate with the galaxy instance. Cannot be used to do user-tied actions self.datasets = dict() self.config = None # Custom config used to set environment variables inside containers - self.species_folder_name = "_".join(utilities.filter_empty_not_empty_items( - [self.genus_lowercase.lower(), self.species.lower(), self.strain.lower(), - self.sex.lower()])["not_empty"]) diff --git a/templates/gspecies_compose.yml.j2 b/templates/gspecies_compose.yml.j2 index 9b8c3f60f5f6532312a707f2d6d7c090fa6e0b02..97dbb0000bcf779a9f6667d5376d24f888c096be 100644 --- a/templates/gspecies_compose.yml.j2 +++ b/templates/gspecies_compose.yml.j2 @@ -38,18 +38,18 @@ services: - ./docker_data/galaxy/:/export/:ro - ./src_data/:/project_data/:ro - ./src_data:/data:ro - {% if 'tripal_banner_path' is defined %} + {% if 'tripal_banner_path' is defined %} - ./banner.png:/var/www/html/banner.png:ro - {% endif %} + {% endif %} #- /groups/XXX/:/groups/XXX/:ro # We do this when we have symlinks in src_data pointing to /groups/XXX/... - {% if 'picture_path' is defined %} - {% if 'png' in picture_path %} + {% if 'picture_path' is defined %} + {% if 'png' in picture_path %} - ./species.png:/var/www/html/species.png:ro - {% endif %} - {% if 'jpg' in picture_path %} + {% endif %} + {% if 'jpg' in picture_path %} - ./species.jpg:/var/www/html/species.jpg:ro + {% endif %} {% endif %} - {% endif %} environment: DB_HOST: tripal-db.{{ genus_species }} BASE_URL_PATH: /sp/{{ genus_species }} diff --git a/utilities.py b/utilities.py index bae4e0241df54ecf4340fba978044f608b4ac992..f08c11b25b25d1e4a65eeb2685acc68f987c01f1 100755 --- a/utilities.py +++ b/utilities.py @@ -162,14 +162,28 @@ 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 get_sp_picture(sp_dict_list): + """ + Get the picture for each species: the picture of the main strain if exists, other strain if not + """ + + sp_picture_dict = {} + + for sp in sp_dict_list: + gspecies = get_gspecies_string_from_sp_dict(sp) + if gspecies not in sp_picture_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 ): + if sp[constants.ORG_PARAM_DESC_PICTURE_PATH] != "": + sp_picture_dict[gspecies] = sp[constants.ORG_PARAM_DESC_PICTURE_PATH] + + return sp_picture_dict + def run_tool(instance, tool_id, history_id, tool_inputs): output_dict = None @@ -223,4 +237,4 @@ def create_org_param_dict_from_constants(): org_param_dict["org_param_services"] = constants.ORG_PARAM_SERVICES org_param_dict["org_param_services_blast"] = constants.ORG_PARAM_SERVICES_BLAST - return org_param_dict \ No newline at end of file + return org_param_dict