diff --git a/plasmid/source/core-plugins/petermigration/1/as/definitions.py b/plasmid/source/core-plugins/petermigration/1/as/definitions.py index 2499678ad13f11bb98fd311b7393c5a2a4160173..093b5af7d6d4d058105551280f67745023da3869 100644 --- a/plasmid/source/core-plugins/petermigration/1/as/definitions.py +++ b/plasmid/source/core-plugins/petermigration/1/as/definitions.py @@ -29,14 +29,21 @@ tmScriptName= "TM" # Storage # numberOfStorageGroups = 15 -stogageGroupPropertyCodes = ["STORAGE_NAME", "STORAGE_ROW", "STORAGE_COLUMN", "STORAGE_BOX_NAME", "STORAGE_USER", "STORAGE_BOX_POSITION"] #This is duplicated below, needs cleanup -storageGroupDefinition = [ - ["STORAGE_NAME_0", "Physical Storage 0", "location", DataType.CONTROLLEDVOCABULARY, "FREEZER", "Storage Name 0", None, None, False], - ["STORAGE_ROW_0", "Physical Storage 0", "Storage Row", DataType.INTEGER, None, "Storage Row 0", None, None, False], - ["STORAGE_COLUMN_0", "Physical Storage 0", "Storage Column", DataType.INTEGER, None, "Storage Column 0", None, None, False], - ["STORAGE_BOX_NAME_0", "Physical Storage 0", "box label", DataType.VARCHAR, None, "Storage Box Name 0", None, None, False], - ["STORAGE_USER_0", "Physical Storage 0", "frozen by", DataType.CONTROLLEDVOCABULARY, "ALL_LAB_MEMBERS", "Storage User Id 0", None, None, False], - ["STORAGE_BOX_POSITION_0", "Physical Storage 0", "position", DataType.VARCHAR, None, "Storage Box Position 0", None, None, False] + +def getStorageGroupPropertyCodes(): + propertyCodes = []; + for property in getStorageGroupDefinition(): + propertyCodes.append(property[0]); + return propertyCodes; + +def getStorageGroupDefinition(): + return [ + ["STORAGE_NAME", "Physical Storage", "location", DataType.CONTROLLEDVOCABULARY, "FREEZER", "Storage Name", None, None, False], + ["STORAGE_ROW", "Physical Storage", "Storage Row", DataType.INTEGER, None, "Storage Row", None, None, False], + ["STORAGE_COLUMN", "Physical Storage", "Storage Column", DataType.INTEGER, None, "Storage Column", None, None, False], + ["STORAGE_BOX_NAME", "Physical Storage", "box label", DataType.VARCHAR, None, "Storage Box Name", None, None, False], + ["STORAGE_USER", "Physical Storage", "frozen by", DataType.CONTROLLEDVOCABULARY, "ALL_LAB_MEMBERS", "Storage User Id", None, None, False], + ["STORAGE_BOX_POSITION", "Physical Storage", "position", DataType.VARCHAR, None, "Storage Box Position", 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 2eadba2c48b138c303ea4c2d2d79eb4d9484df8c..7c21e80069e787679e1173c58629028511ed96b7 100644 --- a/plasmid/source/core-plugins/petermigration/1/as/definitionsVoc.py +++ b/plasmid/source/core-plugins/petermigration/1/as/definitionsVoc.py @@ -4,11 +4,11 @@ # # Helper Methods # -def getVocaularyTermCodeForVocabularyAndTermLabel(vocabularyCode, termLabel): +def getVocabularyTermCodeForVocabularyAndTermLabel(vocabularyCode, termLabel): vocabulary = vocacbularyDefinitions[vocabularyCode] for term in vocabulary: if term[1] == termLabel: - print repr("TERM NOT FOUND IN VOCABULARY LIST: " + unicode(vocabularyCode) + " : '" + unicode(termLabel) + "'") + #print repr("TERM NOT FOUND IN VOCABULARY LIST: " + unicode(vocabularyCode) + " : '" + unicode(termLabel) + "'") return term[0] return None diff --git a/plasmid/source/core-plugins/petermigration/1/as/initialize-master-data.py b/plasmid/source/core-plugins/petermigration/1/as/initialize-master-data.py index 8227260d1e9709108df94dec543b99f402e2ce4f..adfa8fb482bae0d9e8a8e0cd15450ec835d57f62 100644 --- a/plasmid/source/core-plugins/petermigration/1/as/initialize-master-data.py +++ b/plasmid/source/core-plugins/petermigration/1/as/initialize-master-data.py @@ -17,8 +17,8 @@ ## ## Configuration ## -#PATH_TO_MANAGE_PROPERTIES_SCRIPTS = "/Users/juanf/Documents/workspace/openbis/source/core-plugins/petermigration/1/compatibility/"; -PATH_TO_MANAGE_PROPERTIES_SCRIPTS = "/Users/barillac/openbis-peter/servers/core-plugins/petermigration/1/compatibility/"; +PATH_TO_MANAGE_PROPERTIES_SCRIPTS = "/Users/juanf/Documents/workspace/openbis/source/core-plugins/petermigration/1/compatibility/"; +#PATH_TO_MANAGE_PROPERTIES_SCRIPTS = "/Users/barillac/openbis-peter/servers/core-plugins/petermigration/1/compatibility/"; # MasterDataRegistrationTransaction Class import definitions @@ -112,13 +112,12 @@ def createProperty(propertyCode, dataType, propertyLabel, propertyDescription, v return property; def addStorageGroups(numGroups, sampleType): - storageGroup = copy.copy(definitions.storageGroupDefinition); - for storageIdx in range(1,(numGroups + 1)): + storageGroup = definitions.getStorageGroupDefinition(); for property in storageGroup: - property[0] = property[0].replace(str(storageIdx-1), str(storageIdx)); - property[1] = property[1].replace(str(storageIdx-1), str(storageIdx)); - property[5] = property[5].replace(str(storageIdx-1), str(storageIdx)); + property[0] = property[0] + "_" + str(storageIdx); + property[1] = property[1] + "_" + str(storageIdx); + property[5] = property[5] + "_" + str(storageIdx); addPropertiesToSamples([sampleType], storageGroup); #Valid Script Types: DYNAMIC_PROPERTY, MANAGED_PROPERTY, ENTITY_VALIDATION @@ -213,17 +212,15 @@ createExperimentTypeWithProperties("OLIGO", "BOX TO HOLD SAMPLES OF THIS TYPE FO ## Sample Types ## createSampleTypeWithProperties("ANTIBODY", "", definitions.antibodyDefinition); +addStorageGroups(definitions.numberOfStorageGroups, "ANTIBODY"); createSampleTypeWithProperties("CELL", "", definitions.cellDefinition); +addStorageGroups(definitions.numberOfStorageGroups, "CELL"); createSampleTypeWithProperties("STRAIN", "", definitions.strainDefinition); createSampleTypeWithProperties("PLASMID", "", definitions.plasmidDefinition); createSampleTypeWithProperties("CHEMICAL", "", definitions.chemicalDefinition); createSampleTypeWithProperties("SIRNA", "", definitions.siRNADefinition); createSampleTypeWithProperties("OLIGO", "", definitions.oligoDefinition); - - -addStorageGroups(definitions.numberOfStorageGroups, "ANTIBODY"); - ## ## Data set Types ## 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 bdf94353e953e4b7a5daaf5911b557501db43d64..65a33a031031d62bd5cb4c4e3226f4417d50343c 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 @@ -42,7 +42,7 @@ def setEntityProperties(tr, definition, entity, properties): 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) + possiblePropertyValue = definitionsVoc.getVocabularyTermCodeForVocabularyAndTermLabel(propertyDefinition[4], propertyValue) if possiblePropertyValue is not None: propertyValue = possiblePropertyValue else: #We rely on the Add Hock Terms if is None @@ -183,7 +183,7 @@ class FileMakerEntityAdaptor(EntityAdaptor): class FMPeterOpenBISDTO(OpenBISDTO): def isInOpenBIS(self, tr): code = self.getIdentifier(tr) - if code is not None: + if (code is not None) and (' ' not in code): sampleID2Sample[self.values["NAME"]] = self.values sample = getSampleForUpdate("/INVENTORY/"+code, None, tr) if sample is not None: @@ -194,14 +194,17 @@ class FMPeterOpenBISDTO(OpenBISDTO): else : return False else: - print "Null Code found in: " + self.__class__.__name__ + print "Invalid Code found '" + str(code) + "' for '" + self.__class__.__name__ + "'" return True class FMPeterBoxAdaptor(FileMakerEntityAdaptor): selectBoxQuery = None entityIdFieldName = None entityCodeFieldName = None - + + def addEntity(self, values): + self.entities.append(FMPeterEntityBoxOpenBISDTO(values, self.definition)) + def init(self): print "Reading boxes for: " + self.__class__.__name__ emptyBox = 0 @@ -236,7 +239,7 @@ class FMPeterBoxAdaptor(FileMakerEntityAdaptor): #The antibody is not there. What the *#%$& emptyBox += 1 - print "Not found: " + str(emptyBox) + print "Boxes positions with empty entityId for " + self.__class__.__name__ + ":" + str(emptyBox) for entiyCode, allBoxes in boxes.iteritems(): self.addEntity({ @@ -247,42 +250,14 @@ class FMPeterBoxAdaptor(FileMakerEntityAdaptor): result.close() preparedStatement.close() -## -## Antibodies -## -class AntibodyAdaptor(FileMakerEntityAdaptor): - - def init(self): - self.selectQuery = "SELECT * FROM \"boxit antibodies\"" - self.definition = definitions.antibodyDefinition - FileMakerEntityAdaptor.init(self) - - def addEntity(self, values): - self.entities.append(AntibodyOpenBISDTO(values, self.definition)) - -class AntibodyOpenBISDTO(FMPeterOpenBISDTO): - def write(self, tr): - sample = getSampleForUpdate("/INVENTORY/"+self.values["ANTIBODY_ID_NR"],"ANTIBODY", tr) - setEntityProperties(tr, self.definition, sample, self.values); - - def getIdentifier(self, tr): - return self.values["ANTIBODY_ID_NR"] - -class AntibodyBoxAdaptor(FMPeterBoxAdaptor): - selectBoxQuery = "SELECT * FROM \"antibody boxes\"" - entityIdFieldName = "antibody ID" - entityCodeFieldName = "ANTIBODY_ID_NR" - - def addEntity(self, values): - self.entities.append(AntibodyBoxOpenBISDTO(values, self.definition)) - -class AntibodyBoxOpenBISDTO(OpenBISDTO): +class FMPeterEntityBoxOpenBISDTO(OpenBISDTO): def write(self, tr): sample = getSampleForUpdate("/INVENTORY/"+self.values["*CODE"], None, tr) + print "BOXES SIZE: " + self.values["*CODE"] + " " + str(len(self.values["*BOXESLIST"])) #Delete old boxes for boxNum in range(1, definitions.numberOfStorageGroups+1): - for propertyCode in definitions.stogageGroupPropertyCodes: + for propertyCode in definitions.getStorageGroupPropertyCodes(): sample.setPropertyValue(propertyCode + "_" + str(boxNum), None) #Add new boxes boxNum = 1 @@ -290,14 +265,14 @@ class AntibodyBoxOpenBISDTO(OpenBISDTO): boxNum += 1 for propertyCode, propertyValue in box.iteritems(): if propertyCode == "STORAGE_NAME": - freezerName = definitionsVoc.getVocaularyTermCodeForVocabularyAndTermLabel("FREEZER", propertyValue) + freezerName = definitionsVoc.getVocabularyTermCodeForVocabularyAndTermLabel("FREEZER", propertyValue) if freezerName is None: #print repr("NOT FOUND FEEZER: " + self.values["ANTIBODY_ID_NR"] + " : '" + unicode(propertyValue) + "'") propertyValue = None else: propertyValue = freezerName if propertyCode == "STORAGE_USER": - storageUser = definitionsVoc.getVocaularyTermCodeForVocabularyAndTermLabel("ALL_LAB_MEMBERS", propertyValue) + storageUser = definitionsVoc.getVocabularyTermCodeForVocabularyAndTermLabel("ALL_LAB_MEMBERS", propertyValue) if storageUser is None: #print repr("NOT FOUND USER: " + self.values["ANTIBODY_ID_NR"] + " : '" + unicode(propertyValue) + "'") propertyValue = None @@ -313,7 +288,7 @@ class AntibodyBoxOpenBISDTO(OpenBISDTO): if sample is not None: for boxNum in range(1, definitions.numberOfStorageGroups+1): storedSignature = ""; - for propertyCode in definitions.stogageGroupPropertyCodes: + for propertyCode in definitions.getStorageGroupPropertyCodes(): propertyValue = sample.getPropertyValue(propertyCode + "_" + str(boxNum)) if propertyValue is not None: propertyValue = unicode(propertyValue) @@ -326,12 +301,12 @@ class AntibodyBoxOpenBISDTO(OpenBISDTO): def isInOpenBIS(self, tr): for box in self.values["*BOXESLIST"]: boxSignature = ""; - for propertyCode in definitions.stogageGroupPropertyCodes: + for propertyCode in definitions.getStorageGroupPropertyCodes(): propertyValue = box[propertyCode] if propertyCode == "STORAGE_NAME": - propertyValue = definitionsVoc.getVocaularyTermCodeForVocabularyAndTermLabel("FREEZER", propertyValue) + propertyValue = definitionsVoc.getVocabularyTermCodeForVocabularyAndTermLabel("FREEZER", propertyValue) if propertyCode == "STORAGE_USER": - propertyValue = definitionsVoc.getVocaularyTermCodeForVocabularyAndTermLabel("LAB_MEMBERS_INITIALS", propertyValue) + propertyValue = definitionsVoc.getVocabularyTermCodeForVocabularyAndTermLabel("LAB_MEMBERS_INITIALS", propertyValue) if propertyValue is not None: propertyValue = unicode(propertyValue) @@ -339,6 +314,30 @@ class AntibodyBoxOpenBISDTO(OpenBISDTO): if not self.isBoxPressent(boxSignature, tr): return False return True +## +## Antibodies +## +class AntibodyAdaptor(FileMakerEntityAdaptor): + def init(self): + self.selectQuery = "SELECT * FROM \"boxit antibodies\"" + self.definition = definitions.antibodyDefinition + FileMakerEntityAdaptor.init(self) + + def addEntity(self, values): + self.entities.append(AntibodyOpenBISDTO(values, self.definition)) + +class AntibodyOpenBISDTO(FMPeterOpenBISDTO): + def write(self, tr): + sample = getSampleForUpdate("/INVENTORY/"+self.values["ANTIBODY_ID_NR"],"ANTIBODY", tr) + setEntityProperties(tr, self.definition, sample, self.values); + + def getIdentifier(self, tr): + return self.values["ANTIBODY_ID_NR"] + +class AntibodyBoxAdaptor(FMPeterBoxAdaptor): + selectBoxQuery = "SELECT * FROM \"antibody boxes\"" + entityIdFieldName = "antibody ID" + entityCodeFieldName = "ANTIBODY_ID_NR" ## ## Cells @@ -364,6 +363,11 @@ class CellOpenBISDTO(FMPeterOpenBISDTO): code = self.values["CELL_ID_NR_COPY"] return code +class CellBoxAdaptor(FMPeterBoxAdaptor): + selectBoxQuery = "SELECT * FROM \"cell boxes\"" + entityIdFieldName = "cell ID" + entityCodeFieldName = "CELL_ID_NR_COPY" + ## ## Strains ## @@ -548,16 +552,18 @@ 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"), - #CellAdaptor(fmConnString, fmUser, fmPass, "BOXIT_cells_Peter"), - #PlasmidAdaptor(fmConnString, fmUser, fmPass, "BOXIT_plasmids_Peter"), - #StrainAdaptor(fmConnString, fmUser, fmPass, "BOXIT_strains_Peter"), - #SirnaAdaptor(fmConnString, fmUser, fmPass, "BOXIT_Main_Menu_Peter"), - #ChemicalAdaptor(fmConnString, fmUser, fmPass, "BOXIT_Main_Menu_Peter"), - #OligoAdaptor(fmConnString, fmUser, fmPass, "BOXIT_oligos_Peter"), - DocumentsAdaptor(fmConnString, fmUser, fmPass, "BOXIT_documents_Peter")] +# AntibodyAdaptor(fmConnString, fmUser, fmPass, "BOXIT_antibodies_Peter"), +# AntibodyBoxAdaptor(fmConnString, fmUser, fmPass, "BOXIT_antibody_boxes_Peter"), +# PlasmidAdaptor(fmConnString, fmUser, fmPass, "BOXIT_plasmids_Peter"), +# StrainAdaptor(fmConnString, fmUser, fmPass, "BOXIT_strains_Peter"), +# SirnaAdaptor(fmConnString, fmUser, fmPass, "BOXIT_Main_Menu_Peter"), +# ChemicalAdaptor(fmConnString, fmUser, fmPass, "BOXIT_Main_Menu_Peter"), +# OligoAdaptor(fmConnString, fmUser, fmPass, "BOXIT_oligos_Peter"), +adaptors = [CellAdaptor(fmConnString, fmUser, fmPass, "BOXIT_cells_Peter"), + CellBoxAdaptor(fmConnString, fmUser, fmPass, "BOXIT_cell_boxes_Peter"), + DocumentsAdaptor(fmConnString, fmUser, fmPass, "BOXIT_documents_Peter")] + def createDataHierarchy(tr): inventorySpace = tr.getSpace("INVENTORY") if inventorySpace == None: