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.protein import filter_protein_overview from webfront.views.structure import filter_structure_overview if "structures" in obj: obj["structures"] = filter_structure_overview(obj["structures"], general_handler, "entry") if "proteins" in obj: obj["proteins"] = filter_protein_overview(obj["proteins"], general_handler, "entry") return obj remove_empty_structures = False if hasattr(obj, 'serializer') or isinstance(obj, list): entries = [x[0] for x in general_handler.queryset_manager.get_queryset("entry") .values_list("accession").distinct()] arr = [obj] if isinstance(obj, dict) else obj for o in arr: if "entries" in o: o["entries"] = [e for e in o["entries"] if re.match(db_members, e["source_database"], flags=re.IGNORECASE) and "integrated" not in e and e["accession"] in entries] if len(o["entries"]) == 0: remove_empty_structures = True if remove_empty_structures: arr = [a for a in arr if len(a["entries"]) > 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") 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.protein import filter_protein_overview from webfront.views.structure import filter_structure_overview if "structures" in obj: obj["structures"] = filter_structure_overview(obj["structures"], general_handler, "entry") if "proteins" in obj: obj["proteins"] = filter_protein_overview(obj["proteins"], general_handler, "entry") return obj remove_empty_structures = False if hasattr(obj, 'serializer') or isinstance(obj, list): arr = [obj] if isinstance(obj, dict) else obj for o in arr: if "entries" in o: o["entries"] = [e for e in o["entries"] if e["source_database"].lower() == "interpro"] if len(o["entries"]) == 0: remove_empty_structures = True if remove_empty_structures: arr = [a for a in arr if len(a["entries"]) > 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: 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