Example #1
0
 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
Example #2
0
 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
Example #3
0
 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
Example #4
0
    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