Newer
Older

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

Arthur Le Bars
committed
import sys
import utilities
import logging

Loraine Gueguen
committed
import constants

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
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
if not string is None and string != "":
clean_string = string.replace(" ", "_").replace("-", "_").replace("(", "").replace(")", "").replace("'", "").strip()
return clean_string
else:
return string
def set_service_attribute(self, service, parameters_dictionary):
parameters_dictionary_services = parameters_dictionary[constants.ORG_PARAM_SERVICES]
service_value = "0"
if(service in parameters_dictionary_services.keys()
and parameters_dictionary_services[service] is not None
and parameters_dictionary_services[service] != ""):
service_value = parameters_dictionary_services[service]
return service_value
def __init__(self, parameters_dictionary):
self.parameters_dictionary = parameters_dictionary

Loraine Gueguen
committed
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]
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_name = self.clean_string(parameters_dictionary_description[constants.ORG_PARAM_DESC_COMMON_NAME])

Arthur Le Bars
committed
self.date = datetime.today().strftime("%Y-%m-%d")

Loraine Gueguen
committed
self.origin = parameters_dictionary_description[constants.ORG_PARAM_DESC_ORIGIN]

Arthur Le Bars
committed

Loraine Gueguen
committed
if parameters_dictionary_data[constants.ORG_PARAM_DATA_GENOME_VERSION] == "":

Loraine Gueguen
committed
self.genome_version = str(parameters_dictionary_data[constants.ORG_PARAM_DATA_GENOME_VERSION])

Loraine Gueguen
committed
if parameters_dictionary_data[constants.ORG_PARAM_DATA_OGS_VERSION] == "":

Loraine Gueguen
committed
self.ogs_version = str(parameters_dictionary_data[constants.ORG_PARAM_DATA_OGS_VERSION])

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

Loraine Gueguen
committed
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]

Arthur Le Bars
committed
self.blast = self.set_service_attribute(constants.ORG_PARAM_SERVICES_BLAST, parameters_dictionary)
self.go = self.set_service_attribute(constants.ORG_PARAM_SERVICES_GO, parameters_dictionary)

Loraine Gueguen
committed

Loraine Gueguen
committed
self.strain_lowercase = self.strain.lower()
self.sex_lowercase = self.sex.lower()
self.genus_uppercase = self.genus[0].upper() + self.genus_lowercase[1:]
self.genus_species = "{0}_{1}".format(self.genus_lowercase, self.species_lowercase)

Loraine Gueguen
committed
self.strain_sex = "{0}_{1}".format(self.strain_lowercase, self.sex_lowercase)

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_lowercase = self.full_name.lower()
self.species_folder_name = "_".join(utilities.filter_empty_not_empty_items(
[self.genus_lowercase, self.species_lowercase, self.strain.lower(),
self.dataset_prefix = None
if self.sex is not None or self.sex != "":
self.dataset_prefix = self.genus[0].lower() + "_" + self.species_lowercase + "_" + self.sex[0].lower()
self.dataset_prefix = self.genus[0].lower() + "_" + self.species_lowercase
# 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