From f4dd85a0892a2312344adbee1c805fd5ede4ed1c Mon Sep 17 00:00:00 2001 From: barillac <barillac> Date: Thu, 11 Dec 2014 13:38:44 +0000 Subject: [PATCH] new sample types added SVN: 33027 --- .../petermigration/1/as/definitions.py | 30 +-- .../petermigration/1/as/definitionsVoc.py | 28 ++- .../drop-boxes/petermigration/migration.py | 197 +++++++++++++++++- 3 files changed, 231 insertions(+), 24 deletions(-) diff --git a/plasmid/source/core-plugins/petermigration/1/as/definitions.py b/plasmid/source/core-plugins/petermigration/1/as/definitions.py index 2f679851f7d..220f739068a 100644 --- a/plasmid/source/core-plugins/petermigration/1/as/definitions.py +++ b/plasmid/source/core-plugins/petermigration/1/as/definitions.py @@ -180,7 +180,7 @@ strainDefinition = [ ["MODIFICATION_DATE", "General", "modification date", DataType.TIMESTAMP, None, "", None, None, False], ["MODIFIED_BY", "General", "modified by", DataType.CONTROLLEDVOCABULARY, "ALL_LAB_MEMBERS", "", None, None, False], ["NUMBER", "General", "number", DataType.VARCHAR, None, "", None, None, False], - ["OBTAINED_FROM", "General", "obtained from", DataType.VARCHAR, None, "", None, None, False], + ["STRAIN_OBTAINED_FROM", "General", "obtained from", DataType.VARCHAR, None, "", None, None, False], ["ORF", "General", "orf", DataType.VARCHAR, None, "", None, None, False], ["PAGE_NUMBER", "General", "page number", DataType.VARCHAR, None, "", None, None, False], ["PARENTAL_CELL", "General", "parental cell", DataType.VARCHAR, None, "", None, None, False], @@ -211,7 +211,7 @@ oligoDefinition = [ ["AMOUNT", "General", "amount", DataType.REAL, None, "", None, None, False], ["BARCODE", "General", "barcode", DataType.VARCHAR, None, "", None, None, False], ["BARCODE_LABEL", "General", "barcode label", DataType.VARCHAR, None, "", None, None, False], - ["COMPANY", "General", "company", DataType.CONTROLLEDVOCABULARY, "OLIGO_COMPANY", "", None, None, False], + ["OLIGO_COMPANY", "General", "company", DataType.CONTROLLEDVOCABULARY, "OLIGO_COMPANY", "", None, None, False], ["CONCENTRATION", "General", "concentration", DataType.REAL, None, "", None, None, False], ["CONCENTRATION_UNIT", "General", "concentration unit", DataType.CONTROLLEDVOCABULARY, "CONC_UNITS", "", None, None, False], ["CREATION_DATE", "General", "creation date", DataType.TIMESTAMP, None, "", None, None, False], @@ -232,7 +232,7 @@ oligoDefinition = [ ["NAME", "General", "oligo ID", DataType.INTEGER, None, "", None, None, False], ["OLIGO_ID_NR", "General", "oligo_id_nr", DataType.VARCHAR, None, "", None, None, False], ["ORDER_DATE", "General", "order date", DataType.VARCHAR, None, "", None, None, False], - ["ORGANISM", "General", "organism", DataType.CONTROLLEDVOCABULARY, "OLIGO_ORGANISM", "", None, None, False], + ["OLIGO_ORGANISM", "General", "organism", DataType.CONTROLLEDVOCABULARY, "OLIGO_ORGANISM", "", None, None, False], ["PAGE_NUMBER", "General", "page number", DataType.VARCHAR, None, "", None, None, False], ["PRIMER_PARTNER", "General", "primer partner", DataType.VARCHAR, None, "", None, None, False], ["PRIMER_POSITION", "General", "primer position", DataType.CONTROLLEDVOCABULARY, "PRIMER_POSITION", "", None, None, False], @@ -285,9 +285,9 @@ plasmidDefinition = [ ["ORIGIN_OF_REPLICATION", "General", "origin of replication", DataType.VARCHAR, None, "", None, None, False], ["OTHER_MARKER", "General", "other marker", DataType.VARCHAR, None, "", None, None, False], ["PAGE_NUMBER", "General", "page number", DataType.VARCHAR, None, "", None, None, False], - ["PERSPLASMIDNUM", "General", "persPlasmidnum", DataType.INTEGER, None, "", None, None, False], + ["PERSPLASMIDNUM", "General", "persPlasmidnum", DataType.REAL, None, "", None, None, False], ["PETERPLASMIDNUM", "General", "PeterPlasmidNum", DataType.INTEGER, None, "", None, None, False], - ["PLASMID_ID", "General", "plasmid ID", DataType.VARCHAR, None, "", None, None, False], + ["NAME", "General", "plasmid ID", DataType.VARCHAR, None, "", None, None, False], ["PLASMID_ID_NR", "General", "plasmid_id_nr", DataType.VARCHAR, None, "", None, None, False], ["PLASMIDNAME", "General", "plasmidname", DataType.VARCHAR, None, "", None, None, False], ["PRIMERS", "General", "primers", DataType.VARCHAR, None, "", None, None, False], @@ -302,8 +302,8 @@ plasmidDefinition = [ ["SIZE_INSERT", "General", "size insert", DataType.REAL, None, "", None, None, False], ["SIZE_OF_INSERT", "General", "size of insert", DataType.VARCHAR, None, "", None, None, False], ["SIZE_VECTOR", "General", "size vector", DataType.REAL, None, "", None, None, False], - ["SOURCE", "General", "source", DataType.VARCHAR, None, "", None, None, False], - ["SPECIES", "General", "species", DataType.CONTROLLEDVOCABULARY, "PLASMID_ORGANISM", "", None, None, False], + ["PLASMID_SOURCE", "General", "source", DataType.VARCHAR, None, "", None, None, False], + ["PLASMID_SPECIES", "General", "species", DataType.CONTROLLEDVOCABULARY, "PLASMID_ORGANISM", "", None, None, False], #["TUBES", "General", "TUBES", DataType.VARCHAR, None, "", None, None, False], ["URL", "General", "url", DataType.VARCHAR, None, "", None, None, False] ]; @@ -319,14 +319,14 @@ chemicalDefinition = [ siRNADefinition = [ ["INVESTIGATOR", "General", "investigator", DataType.CONTROLLEDVOCABULARY, "ALL_LAB_MEMBERS", "", None, None, False], ["GENE_LOCUS", "General", "gene locus", DataType.VARCHAR, None, "", None, None, False], - ["EXON_OR_THREE_PRIME", "General", "exon or three prime", DataType.VARCHAR, None, "", None, None, False], - ["EXON", "General", "exon #", DataType.VARCHAR, None, "", None, None, False], + ["EXON_OR_THREE_PRIME", "General", "exon or three prime", DataType.CONTROLLEDVOCABULARY, "EXON_OR_THREE_PRIME", "", None, None, False], + ["EXON", "General", "exon #", DataType.INTEGER, None, "", None, None, False], ["3_PRIME_POSITION", "General", "3' position", DataType.VARCHAR, None, "", None, None, False], - ["SPECIES", "General", "species", DataType.VARCHAR, None, "", None, None, False], + ["SIRNA_SPECIES", "General", "species", DataType.CONTROLLEDVOCABULARY, "SIRNA_SPECIES", "", None, None, False], ["SEQUENCE", "General", "SEQUENCE", DataType.VARCHAR, None, "", None, None, False], - ["COMPANY", "General", "Company", DataType.VARCHAR, None, "", None, None, False], - ["STOCK_CONCENTRATION", "General", "Stock concentration", DataType.VARCHAR, None, "", None, None, False], - ["WORKING_CONCENTRATION", "General", "Working concentration", DataType.VARCHAR, None, "", None, None, False], + ["SIRNA_COMPANY", "General", "Company", DataType.CONTROLLEDVOCABULARY, "SIRNA_COMPANY", "", None, None, False], + ["STOCK_CONCENTRATION", "General", "Stock concentration", DataType.REAL, None, "", None, None, False], + ["WORKING_CONCENTRATION", "General", "Working concentration", DataType.REAL, None, "", None, None, False], ["EFFICIENCY", "General", "Efficiency", DataType.VARCHAR, None, "", None, None, False], ["EFFICIENCY_QPCR", "General", "Efficiency_qPCR", DataType.VARCHAR, None, "", None, None, False], ["EFFICIENCY_WESTERN", "General", "Efficiency_Western", DataType.VARCHAR, None, "", None, None, False], @@ -338,12 +338,12 @@ siRNADefinition = [ ["PUBLISHED", "General", "Published", DataType.VARCHAR, None, "", None, None, False], ["LIBRARY", "General", "Library", DataType.VARCHAR, None, "", None, None, False], ["CHARACTERIZED_BY_COMPANY", "General", "Characterized by company", DataType.VARCHAR, None, "", None, None, False], - ["NUMBERINPOOL", "General", "NumberINpool", DataType.VARCHAR, None, "", None, None, False], + ["NUMBERINPOOL", "General", "NumberINpool", DataType.INTEGER, None, "", None, None, False], ["TEST", "General", "Test", DataType.VARCHAR, None, "", None, None, False], ["CHEMICAL_MODIFICATION", "General", "Chemical modification", DataType.VARCHAR, None, "", None, None, False], ["OLIGO_NAME", "General", "Oligo name", DataType.VARCHAR, None, "", None, None, False], ["SIRNA_OLIGONUMBER", "General", "siRNA_OligoNumber", DataType.VARCHAR, None, "", None, None, False], - ["FREEZER_LOCATION", "General", "Freezer Location", DataType.VARCHAR, None, "", None, None, False], + ["SIRNA_FREEZER_LOCATION", "General", "Freezer Location", DataType.CONTROLLEDVOCABULARY, "SIRNA_FREEZER_LOCATION", "", None, None, False], ["DRAWER", "General", "Drawer", DataType.VARCHAR, None, "", None, None, False] ]; diff --git a/plasmid/source/core-plugins/petermigration/1/as/definitionsVoc.py b/plasmid/source/core-plugins/petermigration/1/as/definitionsVoc.py index a65f8d07a59..a63b4f78643 100644 --- a/plasmid/source/core-plugins/petermigration/1/as/definitionsVoc.py +++ b/plasmid/source/core-plugins/petermigration/1/as/definitionsVoc.py @@ -736,8 +736,34 @@ vocacbularyDefinitions = { ["SV40", "SV40"], ["TET_ON", "tet on"], ["TET_OFF", "tet off"], - ["RIM1", "rim1"], + ["RIM1", "rim1"] ], + "EXON_OR_THREE_PRIME" : [ + ["EXON", "exon"], + ["3P", "3'"], + ["5P", "5'"] + ], + "SIRNA_SPECIES" : [ + ["HUMAN", "Human"], + ["MOUSE", "Mouse'"] + ], + "SIRNA_COMPANY" : [ + ["AMBION", "Ambion"], + ["DHARMACON", "Dharmacon'"], + ["INVITORGEN", "Invitrogen'"], + ["MICROSYNTH", "Microsynth'"], + ["QIAGEN", "Qiagen'"], + ["GIFT", "Gift'"] + ], + "SIRNA_FREEZER_LOCATION" : [ + ["BIGLABFREEZER", "BigLab freezer"], + ["SMALLLAB_BIGFREEZER", "SmallLab Big freezer'"], + ["FREEZER_G17", "Freezer G17'"], + ["G93-FRANK", "G9.3--Frank'"], + ["FREEZER-G17_BOX_NATHALIE", "Freezer G17 Box Nathalie'"], + ["BOX-THIBAULT-BIGFREEZER-SMALLLAB", "Box thibault Big freezer small lab'"], + ["BOX-NATHALIE", "Box Nathalie'"] + ], "FREEZER" : [ ["G9_FRIDGE-1", "G9 Fridge 1"], ["G9_FRIDGE-2", "G9 Fridge 2"], diff --git a/plasmid/source/core-plugins/petermigration/1/dss/drop-boxes/petermigration/migration.py b/plasmid/source/core-plugins/petermigration/1/dss/drop-boxes/petermigration/migration.py index 3bd8b0f3925..2e0335b67a4 100644 --- a/plasmid/source/core-plugins/petermigration/1/dss/drop-boxes/petermigration/migration.py +++ b/plasmid/source/core-plugins/petermigration/1/dss/drop-boxes/petermigration/migration.py @@ -36,6 +36,10 @@ def setEntityProperties(tr, definition, entity, properties): propertyDefinition = definitions.getPropertyDefinitionByCode(definition, propertyCode) if propertyValue is not None: propertyValue = unicode(propertyValue) + + if propertyDefinition is not None and propertyDefinition[3] == DataType.TIMESTAMP and propertyValue is not None: + date_val = datetime.strptime(propertyValue, "%Y") + propertyValue = datetime.strftime(date_val, "%Y-%m-%d") if propertyDefinition is not None and propertyDefinition[3] == DataType.CONTROLLEDVOCABULARY and propertyValue is not None: possiblePropertyValue = definitionsVoc.getVocaularyTermCodeForVocabularyAndTermLabel(propertyDefinition[4], propertyValue) @@ -45,19 +49,19 @@ def setEntityProperties(tr, definition, entity, properties): #Create new vocabulary term vocabulary = tr.getVocabularyForUpdate(propertyDefinition[4]) term = tr.createNewVocabularyTerm() - codeToUse = re.sub(r'\W+','',propertyValue) + codeToUse = re.sub(r'\W+','_',propertyValue) labelToUse = propertyValue if len(codeToUse) is 0: codeToUse = "None" + str(random.random()) if len(codeToUse) > 60: - codeToUse = codeToUse[:60] + codeToUse = codeToUse[:50] term.setCode(codeToUse) term.setLabel(labelToUse) term.setOrdinal(vocabulary.getTerms().size()) vocabulary.addTerm(term) #Uses new vocabulary term propertyValue = codeToUse - #print "CREATED FOR VOCABULARY " + propertyDefinition[4] + " NEW TERM WITH CODE " + codeToUse + print repr(entity.getCode() + ", CREATED FOR VOCABULARY: " + propertyDefinition[4] + ", FOUND VALUE: " + labelToUse + ", NEW TERM WITH CODE: " + codeToUse) if propertyDefinition is not None: #Sometimes special fields are added for other purposes, these should not be set entity.setPropertyValue(propertyCode, propertyValue) @@ -108,7 +112,7 @@ class OpenBISDTO: pass ## -## Costumer specific logic +## Costumer specific logic: generic part ## experimentCache = {} sampleCache = {} @@ -133,7 +137,7 @@ def getExperimentForUpdate(experimentIdentifier, experimentType, tr): def getSampleForUpdate(sampleIdentifier, sampleType, tr): if sampleIdentifier not in sampleCache: - print "Cache failed " + sampleIdentifier + ":" + str(sampleType) + #print "Cache failed " + sampleIdentifier + ":" + str(sampleType) sample = tr.getSampleForUpdate(sampleIdentifier) if sample is None and sampleType is not None: #print "Cache Create " + sampleIdentifier + ":" + str(sampleType) @@ -172,7 +176,10 @@ class FileMakerEntityAdaptor(EntityAdaptor): self.addEntity(values) result.close() preparedStatement.close() - + +## +## Customer specific logic: different sample types +## class AntibodyAdaptor(FileMakerEntityAdaptor): def init(self): @@ -317,6 +324,175 @@ class AntibodyBoxOpenBISDTO(OpenBISDTO): if not self.isBoxPressent(boxSignature, tr): return False return True + +class CellAdaptor(FileMakerEntityAdaptor): + + def init(self): + self.selectQuery = "SELECT * FROM \"boxit cells\"" + self.definition = definitions.cellDefinition + FileMakerEntityAdaptor.init(self) + + def addEntity(self, values): + self.entities.append(CellOpenBISDTO(values, self.definition)) + +class CellOpenBISDTO(OpenBISDTO): + def write(self, tr): + code = self.values["CELL_ID_NR_COPY"] + if code is not None and code.startswith("c_"): + sample = getSampleForUpdate("/INVENTORY/"+code,"CELL", tr) + setEntityProperties(tr, self.definition, sample, self.values); + + def getIdentifier(self, tr): + code = self.values["CELL_ID_NR_COPY"] + return code + + def isInOpenBIS(self, tr): + antibodyID2Antibody[self.values["NAME"]] = self.values + code = self.values["CELL_ID_NR_COPY"] + if code is not None and code.startswith("c_"): + sample = getSampleForUpdate("/INVENTORY/"+ code, None, tr) + if sample is not None: + lastModificationData = self.values["MODIFICATION_DATE"].strip() + lastModificationData = str(datetime.strptime(lastModificationData, "%Y-%m-%d"))[:10] + lastModificationOpenBIS = sample.getPropertyValue("MODIFICATION_DATE")[:10] + return lastModificationOpenBIS == lastModificationData + else : + return False + +class StrainAdaptor(FileMakerEntityAdaptor): + + def init(self): + self.selectQuery = "SELECT * FROM \"boxit strains\"" + self.definition = definitions.strainDefinition + FileMakerEntityAdaptor.init(self) + + def addEntity(self, values): + self.entities.append(StrainOpenBISDTO(values, self.definition)) + +class StrainOpenBISDTO(OpenBISDTO): + def write(self, tr): + code = self.values["STRAIN_ID_NR"] + if code is not None: + sample = getSampleForUpdate("/INVENTORY/"+code,"STRAIN", tr) + setEntityProperties(tr, self.definition, sample, self.values); + + def getIdentifier(self, tr): + code = self.values["STRAIN_ID_NR"] + return code + + def isInOpenBIS(self, tr): + antibodyID2Antibody[self.values["NAME"]] = self.values + code = self.values["STRAIN_ID_NR"] + if code is not None: + sample = getSampleForUpdate("/INVENTORY/"+ code, None, tr) + if sample is not None: + lastModificationData = self.values["MODIFICATION_DATE"].strip() + lastModificationData = str(datetime.strptime(lastModificationData, "%Y-%m-%d"))[:10] + lastModificationOpenBIS = sample.getPropertyValue("MODIFICATION_DATE")[:10] + return lastModificationOpenBIS == lastModificationData + else : + return False + +class PlasmidAdaptor(FileMakerEntityAdaptor): + + def init(self): + self.selectQuery = "SELECT * FROM \"boxit plasmids\"" + self.definition = definitions.plasmidDefinition + FileMakerEntityAdaptor.init(self) + + def addEntity(self, values): + self.entities.append(PlasmidOpenBISDTO(values, self.definition)) + +class PlasmidOpenBISDTO(OpenBISDTO): + def write(self, tr): + code = self.values["PLASMID_ID_NR"] + if code is not None: + sample = getSampleForUpdate("/INVENTORY/"+code,"PLASMID", tr) + setEntityProperties(tr, self.definition, sample, self.values); + + def getIdentifier(self, tr): + code = self.values["PLASMID_ID_NR"] + return code + + def isInOpenBIS(self, tr): + antibodyID2Antibody[self.values["NAME"]] = self.values + code = self.values["PLASMID_ID_NR"] + if code is not None: + sample = getSampleForUpdate("/INVENTORY/"+ code, None, tr) + if sample is not None: + lastModificationData = self.values["MODIFICATION_DATE"].strip() + lastModificationData = str(datetime.strptime(lastModificationData, "%Y-%m-%d"))[:10] + lastModificationOpenBIS = sample.getPropertyValue("MODIFICATION_DATE")[:10] + return lastModificationOpenBIS == lastModificationData + else : + return False + +class ChemicalAdaptor(FileMakerEntityAdaptor): + + def init(self): + self.selectQuery = "SELECT * FROM \"Chemicals\"" + self.definition = definitions.chemicalDefinition + FileMakerEntityAdaptor.init(self) + + def addEntity(self, values): + self.entities.append(ChemicalOpenBISDTO(values, self.definition)) + +class ChemicalOpenBISDTO(OpenBISDTO): + def write(self, tr): + code = "CHEM_" + self.values["RECORD_NUMBER"] + if code is not None: + sample = getSampleForUpdate("/INVENTORY/"+code,"CHEMICAL", tr) + setEntityProperties(tr, self.definition, sample, self.values); + + def getIdentifier(self, tr): + code = "CHEM_" + self.values["RECORD_NUMBER"] + return code + + def isInOpenBIS(self, tr): + code = "CHEM_" + self.values["RECORD_NUMBER"] + if code is not None: + sample = getSampleForUpdate("/INVENTORY/"+ code, None, tr) + if sample is not None: + lastModificationData = self.values["MODIFICATION_DATE"].strip() + lastModificationData = str(datetime.strptime(lastModificationData, "%Y-%m-%d"))[:10] + lastModificationOpenBIS = sample.getPropertyValue("MODIFICATION_DATE")[:10] + return lastModificationOpenBIS == lastModificationData + else : + return False + +class SirnaAdaptor(FileMakerEntityAdaptor): + + def init(self): + self.selectQuery = "SELECT * FROM \"siRNA\"" + self.definition = definitions.siRNADefinition + FileMakerEntityAdaptor.init(self) + + def addEntity(self, values): + self.entities.append(SirnaOpenBISDTO(values, self.definition)) + +class SirnaOpenBISDTO(OpenBISDTO): + def write(self, tr): + code = self.values["SIRNA_OLIGONUMBER"] + if code is not None: + sample = getSampleForUpdate("/INVENTORY/"+code,"SIRNA", tr) + setEntityProperties(tr, self.definition, sample, self.values); + + def getIdentifier(self, tr): + code = self.values["SIRNA_OLIGONUMBER"] + return code + + def isInOpenBIS(self, tr): + code = self.values["SIRNA_OLIGONUMBER"] + if code is not None: + sample = getSampleForUpdate("/INVENTORY/"+ code, None, tr) + if sample is not None: + lastModificationData = self.values["MODIFICATION_DATE"].strip() + lastModificationData = str(datetime.strptime(lastModificationData, "%Y-%m-%d"))[:10] + lastModificationOpenBIS = sample.getPropertyValue("MODIFICATION_DATE")[:10] + return lastModificationOpenBIS == lastModificationData + else : + return False + class DocumentsAdaptor(FileMakerEntityAdaptor): @@ -379,8 +555,13 @@ fmConnStringServer = "jdbc:filemaker://fm.ethz.ch/" fmUserServer= "sistemp" fmPassServer = "ibcimsb2014" -adaptors = [AntibodyAdaptor(fmConnString, fmUser, fmPass, "BOXIT_antibodies_Peter"), - AntibodyBoxAdaptor(fmConnString, fmUser, fmPass, "BOXIT_antibody_boxes_Peter"), +#adaptors = [#AntibodyAdaptor(fmConnString, fmUser, fmPass, "BOXIT_antibodies_Peter"), + #AntibodyBoxAdaptor(fmConnString, fmUser, fmPass, "BOXIT_antibody_boxes_Peter"), + #CellAdaptor(fmConnString, fmUser, fmPass, "BOXIT_cells_Peter"), + #PlasmidAdaptor(fmConnString, fmUser, fmPass, "BOXIT_plasmids_Peter"), + #StrainAdaptor(fmConnString, fmUser, fmPass, "BOXIT_strains_Peter"), + #ChemicalAdaptor(fmConnString, fmUser, fmPass, "BOXIT_Main_Menu_Peter"),] +adaptors = [SirnaAdaptor(fmConnString, fmUser, fmPass, "BOXIT_Main_Menu_Peter"), DocumentsAdaptor(fmConnString, fmUser, fmPass, "BOXIT_documents_Peter")] def createDataHierarchy(tr): -- GitLab