#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os import sys import utilities import logging import constants from _datetime import datetime class SpeciesData: """ This class contains attributes and functions to interact with the galaxy container of the GGA environment Parent class of LoadData, GetData, DeploySpeciesStack, GgaPreprocess and RunWorkflow """ def get_species_dir(self): species_dir = None if os.path.isdir(self.main_dir) and not self.genus_species is None: species_dir = os.path.join(self.main_dir, self.genus_species) else: logging.error("Cannot set species dir with '{0}/{1}'".format(self.main_dir,self.genus_species)) return species_dir def goto_species_dir(self): """ Go to the species directory (starting from the main dir) :return: """ species_dir = self.get_species_dir() try: os.chdir(species_dir) except OSError: logging.critical("Cannot access %s" % species_dir) sys.exit(0) return 1 def clean_string(self, string): if not string is None and string != "": clean_string = string.replace(" ", "_").replace("-", "_").replace("(", "").replace(")", "").replace("'", "").strip() return clean_string else: return string def __init__(self, parameters_dictionary): self.parameters_dictionary = parameters_dictionary self.name = parameters_dictionary[constants.ORG_PARAM_NAME] parameters_dictionary_description=parameters_dictionary[constants.ORG_PARAM_DESC] parameters_dictionary_data = parameters_dictionary[constants.ORG_PARAM_DATA] parameters_dictionary_services = parameters_dictionary[constants.ORG_PARAM_SERVICES] self.species = self.clean_string(parameters_dictionary_description[constants.ORG_PARAM_DESC_SPECIES]) self.genus = self.clean_string(parameters_dictionary_description[constants.ORG_PARAM_DESC_GENUS]) self.strain = self.clean_string(parameters_dictionary_description[constants.ORG_PARAM_DESC_STRAIN]) self.sex = self.clean_string(parameters_dictionary_description[constants.ORG_PARAM_DESC_SEX]) self.common = self.clean_string(parameters_dictionary_description[constants.ORG_PARAM_DESC_COMMON_NAME]) self.date = datetime.today().strftime("%Y-%m-%d") self.origin = parameters_dictionary_description[constants.ORG_PARAM_DESC_ORIGIN] self.performed = parameters_dictionary_data[constants.constants.ORG_PARAM_DATA_PERFORMED_BY] if parameters_dictionary_data[constants.ORG_PARAM_DATA_GENOME_VERSION] == "": self.genome_version = "1.0" else: self.genome_version = str(parameters_dictionary_data[constants.ORG_PARAM_DATA_GENOME_VERSION]) if parameters_dictionary_data[constants.ORG_PARAM_DATA_OGS_VERSION] == "": self.ogs_version = "1.0" else: self.ogs_version = str(parameters_dictionary_data[constants.ORG_PARAM_DATA_OGS_VERSION]) # TODO: catch blocks if key is absent in input self.genome_path = parameters_dictionary_data[constants.ORG_PARAM_DATA_GENOME_PATH] self.transcripts_path = parameters_dictionary_data[constants.ORG_PARAM_DATA_TRANSCRIPTS_PATH] self.proteins_path = parameters_dictionary_data[constants.ORG_PARAM_DATA_PROTEINS_PATH] self.gff_path = parameters_dictionary_data[constants.ORG_PARAM_DATA_GFF_PATH] self.interpro_path = parameters_dictionary_data[constants.ORG_PARAM_DATA_INTERPRO_PATH] self.blastp_path = parameters_dictionary_data[constants.ORG_PARAM_DATA_BLASTP_PATH] self.blastx_path = parameters_dictionary_data[constants.ORG_PARAM_DATA_BLASTX_PATH] self.orthofinder_path = parameters_dictionary_data[constants.ORG_PARAM_DATA_ORTHOFINDER_PATH] self.genus_lowercase = self.genus[0].lower() + self.genus[1:] self.genus_uppercase = self.genus[0].upper() + self.genus[1:] 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.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() else: 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 self.genome_analysis_id = None self.ogs_analysis_id = None self.instance_url = None self.instance = None self.history_id = None self.library = None self.library_id = None self.script_dir = os.path.dirname(os.path.realpath(sys.argv[0])) self.main_dir = None self.species_dir = None self.tool_panel = None self.datasets = dict() self.datasets_name = dict() self.source_files = dict() self.workflow_name = None self.metadata = dict() 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"])