Skip to content
Snippets Groups Projects
speciesData.py 5.07 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 goto_species_dir(self):
        """
        Go to the species directory (starting from the main dir)

        :return:
        """

        os.chdir(self.main_dir)
        species_dir = os.path.join(self.main_dir, self.genus_species) + "/"
        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.name = parameters_dictionary["name"]
        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_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()
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
Loraine Gueguen's avatar
Loraine Gueguen committed
        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.existing_folders_cache = {}
        self.bam_metadata_cache = {}