import xml.dom.minidom from ch.systemsx.cisd.common.exceptions import UserFailureException configuration = {} configuration["YEAST"] = ["PLASMID"] configuration["BACTERIA"] = ["PLASMID"] configuration["CELL_LINE"] = ["PLASMID"] configuration["FLY"] = ["PLASMID"] def getSampleTypeCode(sampleAdaptor): return sampleAdaptor.samplePE().getSampleType().getCode() def calculate(): #Configuration sampleTypeCode = getSampleTypeCode(entity) typesForGenotype = configuration[sampleTypeCode] genotypeResult = "" isFirst = True parentIterables = [{ "child" : entity, "parents" : entity.parents(), "lost" : [] }] while len(parentIterables) > 0: parentGroup = parentIterables.pop(0) parents = parentGroup["parents"] child = parentGroup["child"] lostList = parentGroup["lost"][:] newLostList = [] newParentIterables = [] for parent in parents: parentTypeCode = getSampleTypeCode(parent) if parentTypeCode in typesForGenotype: parentCode = parent.code() #Add the code annotationMap = getAnnotationsForParent(parent, child) if(annotationMap["PLASMID_RELATIONSHIP"] == "LOT"): newLostList.append(parent.entityPE().getPermId()) elif parent.entityPE().getPermId() not in lostList: #Check if is the first to add the separator or not if isFirst: isFirst = False else: genotypeResult = genotypeResult + "\n" genotypeResult = genotypeResult + parent.code() + " " + getAnnotationString(annotationMap) else: newParentIterables.append({ "child" : parent, "parents" : parent.parents() }) for newParentIterable in newParentIterables: lostList.extend(newLostList); newParentIterable["lost"] = lostList; parentIterables.append(newParentIterable); return genotypeResult def getAnnotationString(annotationMap): return annotationMap["PLASMID_RELATIONSHIP"] + " " + annotationMap["PLASMID_ANNOTATION"] def getAnnotationsForParent(parent, child): permId = parent.entityPE().getPermId() annotations = child.propertyValue("ANNOTATIONS_STATE") if (annotations is not None) and ('