Skip to content
Snippets Groups Projects
speciesData.py 4.96 KiB
Newer Older
# -*- coding: utf-8 -*-

import os
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 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
        parameters_dictionary_description=parameters_dictionary["description"]
        self.species = self.clean_string(parameters_dictionary_description["species"])
        self.genus = self.clean_string(parameters_dictionary_description["genus"])
        self.strain = self.clean_string(parameters_dictionary_description["strain"])
        self.sex = self.clean_string(parameters_dictionary_description["sex"])
        self.common = self.clean_string(parameters_dictionary_description["common_name"])
        self.date = datetime.today().strftime("%Y-%m-%d")
        self.origin = parameters_dictionary["description"]["origin"]
        self.performed = parameters_dictionary["data"]["performed_by"]
        if parameters_dictionary["data"]["genome_version"] == "":
            self.genome_version = "1.0"
        else:
            self.genome_version = str(parameters_dictionary["data"]["genome_version"])
        if parameters_dictionary["data"]["ogs_version"] == "":
            self.ogs_version = "1.0"
        else:
            self.ogs_version = str(parameters_dictionary["data"]["ogs_version"])
        # TODO: catch blocks if key is absent in input
        self.genome_path = parameters_dictionary["data"]["genome_path"]
        self.transcripts_path = parameters_dictionary["data"]["transcripts_path"]
        self.proteins_path = parameters_dictionary["data"]["proteins_path"]
        self.gff_path = parameters_dictionary["data"]["gff_path"]
        self.interpro_path = parameters_dictionary["data"]["interpro_path"]
        self.blastp_path = parameters_dictionary["data"]["blastp_path"]
        self.blastx_path = parameters_dictionary["data"]["blastx_path"]
        self.orthofinder_path = parameters_dictionary["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 = self.full_name.replace("__", "_").replace("_ ", "_").replace(" _", "_")
        if self.full_name.endswith("_") or self.full_name.endswith(" "):
            self.full_name = self.full_name[0:-2]

        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())

Arthur Le Bars's avatar
Arthur Le Bars committed
        # 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 = None
        self.history_id = None
        self.library_id = None
Arthur Le Bars's avatar
Arthur Le Bars committed

        self.script_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
        self.main_dir = None
        self.species_dir = None
Arthur Le Bars's avatar
Arthur Le Bars committed

        self.tool_panel = None
        self.datasets = dict()
        self.datasets_name = dict()
        self.source_files = dict()
        self.workflow_name = None
        self.metadata = dict()
Arthur Le Bars's avatar
Arthur Le Bars committed
        self.api_key = None  # API key used to communicate with the galaxy instance. Cannot be used to do user-tied actions
Arthur Le Bars's avatar
Arthur Le Bars committed
        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"])
        self.species_folder_name  = self.species_folder_name .replace("-", "_").replace('__', '_').replace("(", "_").replace(")", "_")
        if self.species_folder_name.endswith("_"):
            self.species_folder_name = self.species_folder_name[0:-2]
        self.existing_folders_cache = {}
        self.bam_metadata_cache = {}

        # # Sanitize str attributes
        # for var in vars(self):
        #     for attr in var if type(attr) == str:
        #         attr = attr.replace("(", "_").replace(")", "_")