Commit 9aaf3fdc authored by Jerome Mariette's avatar Jerome Mariette
Browse files

imrove some classes and add run/project info to the analysis

parent 79d56732
......@@ -86,23 +86,26 @@ class Analysis (Component):
self.description = description
self.software = software
self.options = options
self.id = id
self.version = version
self.set_parent_analysis(parent_analysis)
self.results = {}
self.run = None
self.project = None
# Set the temp folder to the ng6 temp folder
ng6conf = NG6ConfigReader()
tempfile.tempdir = ng6conf.get_tmp_directory()
self.set_parent_analysis(parent_analysis)
if id != None : # If not a new analysis
self.version = version
logging.getLogger("Analysis.__init__").debug("Building analysis with id=" + str(id) + " [" + str(self) + "]")
self.id = id
t3mysql = t3MySQLdb()
self.run = Run.get_from_id(self.__get_run_id())
from ng6.project import Project
self.project = Project.get_from_id(self.__get_project_id())
self.directory = t3mysql.select_analysis_directory(id)
self.__run = Run.get_from_id(t3mysql.select_analysis_run_id(id))
logging.getLogger("Analysis.__init__").debug("Building analysis with id=" + str(id) + " [" + str(self) + "]")
else :
self.version = self.get_version()
logging.getLogger("Analysis.__init__").debug("Building brand new analysis [" + str(self) + "]")
# First find out a uniq id
uniq = False
directory_name = uuid.uuid4().hex[:9]
while True:
save_dir = os.path.join(ng6conf.get_save_directory()+self.DIRECTORIES_STRUCTURE, directory_name)
......@@ -114,6 +117,7 @@ class Analysis (Component):
work_dir = os.path.join(ng6conf.get_work_directory()+self.DIRECTORIES_STRUCTURE, directory_name)
os.makedirs(work_dir, 0751)
self.directory = os.path.join(self.DIRECTORIES_STRUCTURE, directory_name)
logging.getLogger("Analysis.__init__").debug("Building brand new analysis [" + str(self) + "]")
def set_parent_analysis(self, parent_analysis):
if parent_analysis != None:
......@@ -207,15 +211,6 @@ class Analysis (Component):
except :
return None
def set_run(self, run):
"""
Sets the run value of an analysis
@param run : the run object
"""
self.__run = run
def save(self):
"""
update the database info
......@@ -234,7 +229,6 @@ class Analysis (Component):
# Finaly return it's id
return self.id
def get_config_file_path(self):
return os.path.join(self.output_directory, self.ANALYSIS_CONFIG_FILE_NAME)
......@@ -303,8 +297,8 @@ class Analysis (Component):
try : # If there are mids
if self.__run :
mids_desc = self.__run.get_mids_description()
if self.run :
mids_desc = self.run.get_mids_description()
else :
run_id = self.__get_run_id()
my_run = Run.get_from_id(run_id)
......@@ -507,6 +501,13 @@ class Analysis (Component):
t3mysql = t3MySQLdb()
return t3mysql.select_analysis_run_id(self.id)
def __get_project_id(self):
"""
Return the project id the analysis belongs to
@return project_id : the project id the analysis belongs to
"""
t3mysql = t3MySQLdb()
return t3mysql.select_analysis_project_id(self.id)
def __get_save_directory(self):
"""
......
......@@ -54,7 +54,6 @@ class Project(object):
self.name = name
self.description = description
def get_runs(self):
"""
Return a table of Run object that belongs to the project
......@@ -67,7 +66,6 @@ class Project(object):
runs.append(Run.get_from_id(run_id))
return runs
def add_analysis(self, my_analysis):
"""
Add the analysis to the project
......@@ -77,7 +75,6 @@ class Project(object):
t3mysql = t3MySQLdb()
t3mysql.add_analysis_to_project(self.id, analysis_id)
def add_run(self, my_run):
"""
Add and save the run to the project
......@@ -99,7 +96,6 @@ class Project(object):
analysis.append(Analysis.get_from_id(analysis_id))
return analysis
def sync(self):
"""
Synchronyze data related analysis belonging to the Project between temporary folder and long term storage folder.
......@@ -138,4 +134,4 @@ class Project(object):
[name, description] = t3mysql.select_project(id)
return Project(name, description, None, id)
except :
pass
return None
......@@ -179,7 +179,6 @@ class Run(object):
Utils.tar_files(files, os.path.join(self.__get_work_directory(), archive_name), delete)
Utils.bz2(os.path.join(self.__get_work_directory(), archive_name), self.__get_work_directory(), True)
def set_nb_sequences(self, nb_seqs):
"""
Sets the number of sequences to nb_seqs
......@@ -191,7 +190,6 @@ class Run(object):
else :
raise UnsavedRunError()
def set_full_size(self, full_size):
"""
Sets the number of nucleotides in all sequences
......@@ -203,7 +201,6 @@ class Run(object):
else :
raise UnsavedRunError()
def get_analysis(self):
"""
Return a table of Analysis object that belongs to the run
......@@ -217,7 +214,6 @@ class Run(object):
analysis.append(Analysis.get_from_id(analysis_id))
return analysis
def sync(self):
"""
Synchronyze data related to the Run between temporary folder and long term storage folder.
......@@ -245,7 +241,6 @@ class Run(object):
except Exception, err:
raise Exception(str(err))
def add_analysis(self, my_analysis):
"""
Add the analysis to the run
......@@ -259,14 +254,12 @@ class Run(object):
else :
raise UnsavedRunError()
def get_directory_path(self):
"""
Return the full path to the Run directory
"""
return self.__get_save_directory()
def get_mids_description(self):
"""
Return a dictionary with mids description
......@@ -277,7 +270,6 @@ class Run(object):
else :
return t3mysql.select_run_samples(self.id)
def add_mids_description(self, mids_desc):
"""
Add a mids description to the run
......@@ -287,7 +279,6 @@ class Run(object):
# First add the description to the python object
self.__mids_description = mids_desc
def get_config_file(self):
"""
Return a Run config file
......@@ -318,7 +309,6 @@ class Run(object):
config.write(open(config_path,'w'))
return config_path
def get_run_files(self, pattern, unzip=True):
"""
Return list of file corresponding to the pattern
......@@ -346,7 +336,6 @@ class Run(object):
list.append(file)
return list
def save(self):
"""
Creates the run config file and save it in the run directory
......@@ -364,7 +353,6 @@ class Run(object):
# Finaly return it's id
return self.id
def __get_work_directory(self):
"""
Return the full path of the run directory into the work dir
......@@ -372,7 +360,6 @@ class Run(object):
ng6conf = NG6ConfigReader()
return ng6conf.get_work_directory() + self.directory
def __get_save_directory(self):
"""
Return the full path of the run directory into the save dir
......@@ -380,7 +367,6 @@ class Run(object):
ng6conf = NG6ConfigReader()
return ng6conf.get_save_directory() + self.directory
@staticmethod
def get_from_id (id):
"""
......@@ -404,7 +390,7 @@ class Run(object):
return my_run
except :
logging.getLogger("Run.get_from_id").debug("Impossible to build run id=" + str(id))
return None
@staticmethod
def get_from_config (config_file):
......
......@@ -51,7 +51,6 @@ class t3MySQLdb(object):
self.passwd = passwd
self.db = db
#--------------------------------------------------------------------
# Project functions
......@@ -102,7 +101,6 @@ class t3MySQLdb(object):
conn.close()
return project_id
def select_project(self, project_id):
"""
Return the run infos
......@@ -121,7 +119,6 @@ class t3MySQLdb(object):
logging.getLogger("t3MySQLdb.select_project").debug("Returning [" + str([res[0], res[1]]) + "]")
return [res[0], res[1]]
def get_project_analysis_ids(self, project_id):
"""
Return a list of analysis ids belonging to the project
......@@ -140,6 +137,23 @@ class t3MySQLdb(object):
conn.close()
return analysis_ids
def select_analysis_project_id(self, analysis_id):
"""
Return the analysis project id or None
@param analysis_id : the analysis ID
@return : the project id the analysis belongs to
"""
try:
conn = connect(self.host, self.user, self.passwd, self.db)
curs = conn.cursor()
req = "SELECT project_id FROM tx_nG6_project_analyze WHERE analyze_id='" + str(analysis_id) + "'"
curs.execute(req)
res = curs.fetchall()[0]
curs.close()
conn.close()
return res[0]
except:
return None
def get_project_runs_ids(self, project_id):
"""
......@@ -159,11 +173,9 @@ class t3MySQLdb(object):
conn.close()
return run_ids
#--------------------------------------------------------------------
# Run functions
def add_run(self, name, date, directory, species, data_nature,
type, nb_sequences, full_seq_size, description, sequencer, hidden=1):
"""
......@@ -204,7 +216,6 @@ class t3MySQLdb(object):
return run_id
def add_run_to_project(self, project_id, run_id):
"""
Add to the database a new run
......@@ -221,7 +232,6 @@ class t3MySQLdb(object):
curs.close()
conn.close()
def select_run(self, run_id):
"""
Return the run infos
......@@ -240,7 +250,6 @@ class t3MySQLdb(object):
logging.getLogger("t3MySQLdb.select_run").debug("Returning [" + str([res[0], res[1], res[2], res[3], res[4], res[5], res[6]]) + "]")
return [res[0], res[1], res[2], res[3], res[4], res[5], res[6]]
def select_run_directory(self, run_id):
"""
Return the run directory
......@@ -256,7 +265,6 @@ class t3MySQLdb(object):
conn.close()
return res[0]
def update_run_info(self, run_id, name=None, date=None, directory=None, species=None, data_nature=None, type=None, nb_sequences=None, full_seq_size=None, description=None, sequencer=None, hidden=None):
"""
Add to the database a new Analyze done on a run
......@@ -306,7 +314,6 @@ class t3MySQLdb(object):
conn.commit()
conn.close()
def get_run_analysis_ids(self, run_id):
"""
Return a list of analysis ids belonging to the run
......@@ -325,7 +332,6 @@ class t3MySQLdb(object):
conn.close()
return analysis_ids
def add_sample_to_run(self, run_id, mid, description):
"""
add a sample to the run
......@@ -354,8 +360,7 @@ class t3MySQLdb(object):
if( str(sample_pid[0]) != str(self.cfg_reader.get_pid()) ):
raise Exception('t3MySQLdb', 'The id of the sample ' + mid + ' cannot be to retrieve.')
return sample_id
return sample_id
def select_run_samples(self, run_id):
"""
......@@ -373,11 +378,9 @@ class t3MySQLdb(object):
mids[result[0]] = result[1]
return mids
#--------------------------------------------------------------------
# Analyze functions
def add_analysis(self, aclass, name, description, date, directory, software, version, params, hidden=1, parent_uid=0):
"""
Update an Analyze
......@@ -414,7 +417,6 @@ class t3MySQLdb(object):
return analysis_id
def add_analysis_to_project(self, project_id, analysis_id):
"""
Add to the database a new Analyze done on a project
......@@ -431,7 +433,6 @@ class t3MySQLdb(object):
curs.close()
conn.close()
def add_analysis_to_run(self, run_id, analysis_id):
"""
Add to the database a new Analyze done on a run
......@@ -448,7 +449,6 @@ class t3MySQLdb(object):
curs.close()
conn.close()
def add_result(self, analysis_id, file, key, value, group):
"""
Add to the analysis a new result
......@@ -471,7 +471,6 @@ class t3MySQLdb(object):
curs.close()
conn.close()
def update_analysis_field(self, analysis_id, field, value):
"""
Update an Analyze
......@@ -489,7 +488,6 @@ class t3MySQLdb(object):
curs.close()
conn.close()
def select_analysis_directory(self, analysis_id):
"""
Return the analysis directory
......@@ -505,22 +503,23 @@ class t3MySQLdb(object):
conn.close()
return res[0]
def select_analysis_run_id(self, analysis_id):
"""
Return the analysis run id or None
@param analysis_id : the analysis ID
@return : the run id the analysis belongs to
"""
conn = connect(self.host, self.user, self.passwd, self.db)
curs = conn.cursor()
req = "SELECT run_id FROM tx_nG6_run_analyze WHERE analyze_id='" + str(analysis_id) + "'"
curs.execute(req)
res = curs.fetchall()[0]
curs.close()
conn.close()
return res[0]
try:
conn = connect(self.host, self.user, self.passwd, self.db)
curs = conn.cursor()
req = "SELECT run_id FROM tx_nG6_run_analyze WHERE analyze_id='" + str(analysis_id) + "'"
curs.execute(req)
res = curs.fetchall()[0]
curs.close()
conn.close()
return res[0]
except:
return None
def select_analysis(self, analysis_id):
"""
......@@ -545,7 +544,6 @@ class t3MySQLdb(object):
logging.getLogger("t3MySQLdb.select_analysis").debug("Returning [" + str([res[0], res[1], res[2], res[3], res[4], res[5]]) + "]")
return [res[0], res[1], res[2], res[3], res[4], res[5]]
def select_analysis_run_id(self, analysis_id):
"""
Return the run_id the analysis belongs to
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment