diff --git a/api/db/dao.py b/api/db/dao.py index 89aec90..601e1af 100644 --- a/api/db/dao.py +++ b/api/db/dao.py @@ -1008,6 +1008,89 @@ def calorie_experiment_search(self, input): return self.read_query(query, params, tables) + def add_experiment(self, experiment: entities.CalorieRestrictionExperiment): + experiment_dict = experiment.dict(exclude_none=True) + + query = f"INSERT INTO calorie_restriction_experiment ({', '.join(experiment_dict.keys())}) " + subs = ', '.join([f'%({k})s' for k in experiment_dict.keys()]) + query += f"VALUES ({subs});" + + cur = self.cnx.cursor(dictionary=True) + cur.execute(query, experiment_dict) + self.cnx.commit() + + cur.execute( + "SELECT * FROM calorie_restriction_experiment WHERE ID=%(id)s;", + {'id': cur.lastrowid}, + ) + result = cur.fetchone() + + return result + + def get_measurement_method(self, name): + cur = self.cnx.cursor(dictionary=True) + cur.execute( + "SELECT id FROM measurement_method WHERE name_en='{}';".format(name) + ) + return cur.fetchone() + + def get_measurement_type(self, name): + cur = self.cnx.cursor(dictionary=True) + cur.execute( + "SELECT id FROM measurement_type WHERE name_en='{}';".format(name) + ) + return cur.fetchone() + + def get_model_organism(self, name): + cur = self.cnx.cursor(dictionary=True) + cur.execute( + "SELECT id FROM model_organism WHERE name_en='{}';".format(name) + ) + return cur.fetchone() + + def get_organism_sex(self, name): + cur = self.cnx.cursor(dictionary=True) + cur.execute( + "SELECT id FROM organism_sex WHERE name_en='{}';".format(name) + ) + return cur.fetchone() + + def get_organism_line(self, name): + cur = self.cnx.cursor(dictionary=True) + cur.execute( + "SELECT id FROM organism_line WHERE name_en='{}';".format(name) + ) + return cur.fetchone() + + def get_sample(self, name): + cur = self.cnx.cursor(dictionary=True) + cur.execute( + "SELECT id FROM sample WHERE name_en='{}';".format(name) + ) + return cur.fetchone() + + def get_isoform(self, name): + cur = self.cnx.cursor(dictionary=True) + cur.execute( + "SELECT id FROM isoform WHERE name_en='{}';".format(name) + ) + return cur.fetchone() + + def get_treatment_time(self, name): + cur = self.cnx.cursor(dictionary=True) + cur.execute( + "SELECT id FROM treatment_time_unit WHERE name_en='{}';".format(name) + ) + return cur.fetchone() + + def add_treatment_time(self, name): + cur = self.cnx.cursor(dictionary=True) + cur.execute( + "INSERT INTO treatment_time_unit(name_en) VALUES ('{}');".format(name) + ) + self.cnx.commit() + return cur.fetchone() + class WorkerStateDAO(BaseDAO): """Worker state Table fetcher.""" diff --git a/scripts/human_orthologs/dataset_parser.py b/scripts/human_orthologs/dataset_parser.py index 4bcd7fe..7a80d34 100644 --- a/scripts/human_orthologs/dataset_parser.py +++ b/scripts/human_orthologs/dataset_parser.py @@ -16,6 +16,10 @@ def parser(): source = Source(name='calorie_restriction') result = dao.SourceDAO().get_source(source=source) calorie_dao = dao.CalorieExperimentDAO() + correspond_measurement_method = { + 'RNAseq': 'RNA-Seq', + 'Microarray and qRT-PCR': 'microarray, qPCR', + } if result: source_id = result['id'] else: @@ -77,13 +81,12 @@ def parser(): source_id=source_id, ) dao.SourceDAO().add_relation(gene_to_source=gene_to_source) - if ( - row['measurementMethod'] == "chromatography, mass_spectrometry" - or row['measurementMethod'] == "mass_spectrometry" - ): + if row['measurementMethod'] in ("chromatography, mass_spectrometry", "mass_spectrometry",): measurement_method_str = row['measurementMethod'] else: - measurement_method_str = row['measurementMethod'].lower().replace('_', ' ') + measurement_method_str = correspond_measurement_method[ + row['measurementMethod'] + ] measurement_method_id = calorie_dao.get_measurement_method(name=measurement_method_str)[ 'id' ]