Newer
Older

Arthur Le Bars
committed
#!/usr/bin/env python3

Arthur Le Bars
committed
import sys
import utilities

Arthur Le Bars
committed
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
if not string is None and string != "":
clean_string = string.replace(" ", "_").replace("-", "_").replace("(", "").replace(")", "").replace("'", "").strip()
return clean_string
else:
return string

Arthur Le Bars
committed
# self.config_dictionary = None
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"])

Arthur Le Bars
committed
self.date = datetime.today().strftime("%Y-%m-%d")
self.origin = parameters_dictionary["description"]["origin"]
self.performed = parameters_dictionary["data"]["performed_by"]

Arthur Le Bars
committed
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"])

Arthur Le Bars
committed
# TODO: catch blocks if key is absent in input

Arthur Le Bars
committed
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:]

Arthur Le Bars
committed
self.chado_species_name = "{0} {1}".format(self.species, self.sex)

Arthur Le Bars
committed
self.full_name = ' '.join(utilities.filter_empty_not_empty_items([self.genus_uppercase, self.species, self.strain, self.sex])["not_empty"])

Arthur Le Bars
committed
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]

Arthur Le Bars
committed
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())
# 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

Arthur Le Bars
committed
self.instance_url = None
self.instance = None
self.history_id = None

Arthur Le Bars
committed
self.library = 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

Arthur Le Bars
committed
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"])

Arthur Le Bars
committed
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]

Arthur Le Bars
committed
self.existing_folders_cache = {}
self.bam_metadata_cache = {}

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