def post_serializer(obj, level_name="", general_handler=None): if isinstance(obj, dict) and not hasattr(obj, 'serializer'): from webfront.views.entry import filter_entry_overview from webfront.views.structure import filter_structure_overview if "entries" in obj: obj["entries"] = filter_entry_overview(obj["entries"], general_handler, "protein") if "structures" in obj: obj["structures"] = filter_structure_overview(obj["structures"], general_handler, "protein") else: if not isinstance(obj.serializer, ProteinSerializer): prots = [x[0] for x in general_handler.queryset_manager.get_queryset("protein") .values_list("accession").distinct()] remove_empty_structures = False arr = [obj] if isinstance(obj, dict) else obj for o in arr: if "proteins" in o: o["proteins"] = [p for p in o["proteins"] if level_name in prots and( (("accession" in p and p["accession"] == level_name) or ("protein" in p and p["protein"]["accession"] == level_name)))] if len(o["proteins"]) == 0: remove_empty_structures = True if remove_empty_structures: arr = [a for a in arr if len(a["proteins"]) > 0] if len(arr) == 0: raise ReferenceError("The entry {} doesn't exist in the selected url".format(level_name)) return obj
def post_serializer(obj, level_name="", general_handler=None): if isinstance(obj, dict) and not hasattr(obj, "serializer"): from webfront.views.entry import filter_entry_overview from webfront.views.protein import filter_protein_overview if "entries" in obj: obj["entries"] = filter_entry_overview(obj["entries"], general_handler, "structure") if "proteins" in obj: obj["proteins"] = filter_protein_overview(obj["proteins"], general_handler, "structure") else: if not isinstance(obj.serializer, StructureSerializer): arr = obj if isinstance(obj, dict): arr = [obj] for o in arr: if "structures" in o: o["structures"] = [ p for p in o["structures"] if ("accession" in p and p["accession"] == level_name) or ( "structure" in p and "accession" in p["structure"] and p["structure"]["accession"] == level_name ) ] return obj
def post_serializer(obj, level_name="", general_handler=None): if isinstance(obj, dict) and not hasattr(obj, 'serializer'): from webfront.views.entry import filter_entry_overview from webfront.views.structure import filter_structure_overview if "entries" in obj: obj["entries"] = filter_entry_overview(obj["entries"], general_handler, "protein") if "structures" in obj: obj["structures"] = filter_structure_overview(obj["structures"], general_handler, "protein") return obj prots = [x[0] for x in general_handler.queryset_manager.get_queryset("protein") .values_list("accession").distinct()] if hasattr(obj, 'serializer') and not isinstance(obj.serializer, ProteinSerializer): remove_empty_structures = False arr = obj if isinstance(obj, list) else [obj] for o in arr: if "proteins" in o: o["proteins"] = [p for p in o["proteins"] if (level_name == "uniprot" or ("source_database"in p and p["source_database"] == level_name)) and (prots is None or p["accession"] in prots)] if len(o["proteins"]) == 0: remove_empty_structures = True if remove_empty_structures: arr = [a for a in arr if len(a["proteins"]) > 0] if len(arr) == 0: raise ReferenceError("There are not proteins fo the database {} with the selected filters" .format(level_name)) return obj
def post_serializer(obj, level_name="", general_handler=None): if isinstance(obj, dict) and not hasattr(obj, "serializer"): from webfront.views.entry import filter_entry_overview from webfront.views.protein import filter_protein_overview if "entries" in obj: obj["entries"] = filter_entry_overview(obj["entries"], general_handler, "structure") if "proteins" in obj: obj["proteins"] = filter_protein_overview(obj["proteins"], general_handler, "structure") return obj try: structures = [ x[0] for x in general_handler.queryset_manager.get_queryset("structure").values_list("accession").distinct() ] arr = [obj] if isinstance(obj, dict) else obj for result in arr: result["structures"] = [x for x in result["structures"] if x["accession"] in structures] finally: return obj
def post_serializer(obj, level_name="", general_handler=None): if isinstance(obj, dict) and not hasattr(obj, "serializer"): from webfront.views.entry import filter_entry_overview from webfront.views.protein import filter_protein_overview if "entries" in obj: obj["entries"] = filter_entry_overview(obj["entries"], general_handler, "structure") if "proteins" in obj: obj["proteins"] = filter_protein_overview(obj["proteins"], general_handler, "structure") else: pdb = general_handler.get_from_store(PDBAccessionHandler, "pdb_accession") arr = obj remove_empty_structures = False if isinstance(obj, dict): arr = [obj] for o in arr: if "structures" in o: o["structures"] = [ p for p in o["structures"] if ("chain" in p and p["chain"] == level_name and p["structure"]["accession"] == pdb) or ( "structure" in p and "chain" in p["structure"] and p["structure"]["chain"] == level_name and p["structure"]["accession"] == pdb ) ] if len(o["structures"]) == 0: remove_empty_structures = True if ( "entries" in o and isinstance(o["entries"], list) and len(o["entries"]) > 0 and "chain" in o["entries"][0] ): o["entries"] = [ p for p in o["entries"] if ("chain" in p and p["chain"] == level_name) or ("structure" in p and "chain" in p["structure"] and p["entry"]["chain"] == level_name) ] if len(o["entries"]) == 0: raise ReferenceError("The chain {} doesn't exist in the selected structure".format(level_name)) if ( "proteins" in o and isinstance(o["proteins"], list) and len(o["proteins"]) > 0 and "chain" in o["proteins"][0] ): o["proteins"] = [ p for p in o["proteins"] if ("chain" in p and p["chain"] == level_name) or ("structure" in p and "chain" in p["structure"] and p["entry"]["chain"] == level_name) ] if len(o["proteins"]) == 0: raise ReferenceError("The chain {} doesn't exist in the selected structure".format(level_name)) if "metadata" in o and "chains" in o["metadata"] and isinstance(o["metadata"]["chains"], dict): o["metadata"]["chains"] = { p: o["metadata"]["chains"][p] for p in o["metadata"]["chains"] if (level_name in p) } if remove_empty_structures: arr = [a for a in arr if len(a["structures"]) > 0] if len(arr) == 0: raise ReferenceError("The chain {} doesn't exist in the selected structure".format(level_name)) return arr return obj