コード例 #1
0
ファイル: _by_id_validation.py プロジェクト: rvosa/peyotl
 def _post_key_check_validate_otus_obj(self, og_nex_id, otus_group, vc):
     otu_obj = otus_group.get('otuById', {})
     if not isinstance(otu_obj, dict):
         self._error_event(_NEXEL.OTUS,
                           obj=otus_group,
                           err_type=gen_WrongValueTypeWarning,
                           anc=vc.anc_list,
                           obj_nex_id=og_nex_id,
                           key_list=['otuById'])
         return errorReturn('no "otuById" in otus group')
     self._otu_group_by_id[og_nex_id] = otus_group
     vc.push_context(_NEXEL.OTU, (otus_group, og_nex_id))
     try:
         not_dict_otu = []
         ndo_id_list = []
         otu_id_obj_list = []
         for id_obj_pair in otu_obj.items():
             if not isinstance(id_obj_pair[1], dict):
                 r = check_raw_dict(id_obj_pair[1], otus_group, None, vc)
                 assert r[0] is False
                 t = r[1]
                 not_dict_otu.append(t)
                 ndo_id_list.append(id_obj_pair[0])
             else:
                 otu_id_obj_list.append(id_obj_pair)
         if not_dict_otu:
             self._error_event(_NEXEL.OTU,
                               obj=otu_obj,
                               err_type=gen_WrongValueTypeWarning,
                               anc=vc.anc_list,
                               obj_nex_id=ndo_id_list,
                               key_val_type_list=[not_dict_otu])
             return errorReturn('otu is wrong type')
         r = self._validate_otu_list(otu_id_obj_list, vc)
         if r:
             self._otu_by_otug[og_nex_id] = otu_obj
         return r
     finally:
         vc.pop_context()
コード例 #2
0
 def _post_key_check_validate_otus_obj(self, og_nex_id, otus_group, vc):
     otu_obj = otus_group.get('otuById', {})
     if not isinstance(otu_obj, dict):
         self._error_event(_NEXEL.OTUS,
                           obj=otus_group,
                           err_type=gen_WrongValueTypeWarning,
                           anc=vc.anc_list,
                           obj_nex_id=og_nex_id,
                           key_list=['otuById'])
         return errorReturn('no "otuById" in otus group')
     self._otu_group_by_id[og_nex_id] = otus_group
     vc.push_context(_NEXEL.OTU, (otus_group, og_nex_id))
     try:
         not_dict_otu = []
         ndo_id_list = []
         otu_id_obj_list = []
         for id_obj_pair in otu_obj.items():
             if not isinstance(id_obj_pair[1], dict):
                 r = check_raw_dict(id_obj_pair[1], otus_group, None, vc)
                 assert r[0] is False
                 t = r[1]
                 not_dict_otu.append(t)
                 ndo_id_list.append(id_obj_pair[0])
             else:
                 otu_id_obj_list.append(id_obj_pair)
         if not_dict_otu:
             self._error_event(_NEXEL.OTU,
                               obj=otu_obj,
                               err_type=gen_WrongValueTypeWarning,
                               anc=vc.anc_list,
                               obj_nex_id=ndo_id_list,
                               key_val_type_list=[not_dict_otu])
             return errorReturn('otu is wrong type')
         r = self._validate_otu_list(otu_id_obj_list, vc)
         if r:
             self._otu_by_otug[og_nex_id] = otu_obj
         return r
     finally:
         vc.pop_context()
コード例 #3
0
ファイル: _by_id_validation.py プロジェクト: rvosa/peyotl
 def _post_key_check_validate_nexml_obj(self, nex_obj, obj_nex_id, vc):
     otus = nex_obj.get('otusById', {})
     otus_order_list = nex_obj.get('^ot:otusElementOrder', [])
     if not isinstance(otus, dict) or (otus_order_list and (not otus)):
         self._error_event(_NEXEL.NEXML,
                           obj=nex_obj,
                           err_type=gen_WrongValueTypeWarning,
                           anc=vc.anc_list,
                           obj_nex_id=obj_nex_id,
                           key_list=['otusById'])
         return errorReturn('Missing "otusById"')
     if (not isinstance(otus_order_list, list)) or ((not otus_order_list) and otus):
         self._error_event(_NEXEL.NEXML,
                           obj=nex_obj,
                           err_type=gen_WrongValueTypeWarning,
                           anc=vc.anc_list,
                           obj_nex_id=obj_nex_id,
                           key_list=['^ot:otusElementOrder'])
         return errorReturn('Missing "^ot:otusElementOrder"')
     otus_group_list = []
     missing_ogid = []
     not_dict_og = []
     for ogid in otus_order_list:
         og = otus.get(ogid)
         if og is None:
             missing_ogid.append(ogid)
         elif not isinstance(og, dict):
             r = check_raw_dict(og, otus, ogid, vc)
             assert r[0] is False
             t = r[1]
             not_dict_og.append(t)
         else:
             otus_group_list.append((ogid, og))
     if missing_ogid:
         self._error_event(_NEXEL.NEXML,
                           obj=nex_obj,
                           err_type=gen_ReferencedIDNotFoundWarning,
                           anc=vc.anc_list,
                           obj_nex_id=obj_nex_id,
                           key_list=missing_ogid)
         return errorReturn('Missing "@id" for otus group')
     vc.push_context(_NEXEL.OTUS, (nex_obj, obj_nex_id))
     try:
         if not_dict_og:
             self._error_event(_NEXEL.OTUS,
                               obj=otus,
                               err_type=gen_WrongValueTypeWarning,
                               anc=vc.anc_list,
                               obj_nex_id=None,
                               key_val_type_list=[not_dict_og])
             return errorReturn('Otus objects of the wrong type of object')
         if not self._validate_otus_group_list(otus_group_list, vc):
             return False
     finally:
         vc.pop_context()
     # and now the trees...
     trees = nex_obj.get('treesById')
     trees_order_list = nex_obj.get('^ot:treesElementOrder')
     if (not isinstance(trees, dict)) or ((not trees) and trees_order_list):
         self._error_event(_NEXEL.NEXML,
                           obj=nex_obj,
                           err_type=gen_MissingCrucialContentWarning,
                           anc=vc.anc_list,
                           obj_nex_id=obj_nex_id,
                           key_list=['treesById'])
         return errorReturn('Missing "treesById"')
     if (not isinstance(trees_order_list, list)) or ((not trees_order_list) and trees):
         self._error_event(_NEXEL.NEXML,
                           obj=nex_obj,
                           err_type=gen_MissingCrucialContentWarning,
                           anc=vc.anc_list,
                           obj_nex_id=obj_nex_id,
                           key_list=['^ot:treesElementOrder'])
         return errorReturn('Missing "^ot:treesElementOrder"')
     trees_group_list = []
     missing_tgid = []
     not_dict_tg = []
     for tgid in trees_order_list:
         tg = trees.get(tgid)
         if tg is None:
             missing_tgid.append(tgid)
         elif not isinstance(tg, dict):
             r = check_raw_dict(tg, trees, tgid, vc)
             assert r[0] is False
             t = r[1]
             not_dict_tg.append(t)
         else:
             trees_group_list.append((tgid, tg))
     if missing_tgid:
         self._error_event(_NEXEL.NEXML,
                           obj=nex_obj,
                           err_type=gen_ReferencedIDNotFoundWarning,
                           anc=vc.anc_list,
                           obj_nex_id=obj_nex_id,
                           key_list=missing_tgid)
         return errorReturn('Missing trees group id')
     vc.push_context(_NEXEL.TREES, (nex_obj, obj_nex_id))
     try:
         if not_dict_tg:
             self._error_event(_NEXEL.TREES,
                               obj=trees,
                               err_type=gen_WrongValueTypeWarning,
                               anc=vc.anc_list,
                               obj_nex_id=None,
                               key_val_type_list=[not_dict_tg])
             return errorReturn('Trees element of the wrong type')
         if not self._validate_trees_group_list(trees_group_list, vc):
             return False
     finally:
         vc.pop_context()
     if not nex_obj.get('ot:notIntendedForSynthesis'):
         cs = nex_obj.get('ot:candidateTreeForSynthesis')
         if cs:
             if not isinstance(cs, list):
                 tree_list = [cs]
             else:
                 tree_list = cs
         else:
             tree_list = []
             for tg in trees.values():
                 tbi = tg.get('treeById', {})
                 tree_list.extend(tbi.keys())
         self._generate_ott_warnings(otus, tree_list, (nex_obj, obj_nex_id), vc)
     return True
コード例 #4
0
 def _post_key_check_validate_nexml_obj(self, nex_obj, obj_nex_id, vc):
     otus = nex_obj.get('otusById', {})
     otus_order_list = nex_obj.get('^ot:otusElementOrder', [])
     if not isinstance(otus, dict) or (otus_order_list and (not otus)):
         self._error_event(_NEXEL.NEXML,
                           obj=nex_obj,
                           err_type=gen_WrongValueTypeWarning,
                           anc=vc.anc_list,
                           obj_nex_id=obj_nex_id,
                           key_list=['otusById'])
         return errorReturn('Missing "otusById"')
     if (not isinstance(otus_order_list, list)) or ((not otus_order_list)
                                                    and otus):
         self._error_event(_NEXEL.NEXML,
                           obj=nex_obj,
                           err_type=gen_WrongValueTypeWarning,
                           anc=vc.anc_list,
                           obj_nex_id=obj_nex_id,
                           key_list=['^ot:otusElementOrder'])
         return errorReturn('Missing "^ot:otusElementOrder"')
     otus_group_list = []
     missing_ogid = []
     not_dict_og = []
     for ogid in otus_order_list:
         og = otus.get(ogid)
         if og is None:
             missing_ogid.append(ogid)
         elif not isinstance(og, dict):
             r = check_raw_dict(og, otus, ogid, vc)
             assert r[0] is False
             t = r[1]
             not_dict_og.append(t)
         else:
             otus_group_list.append((ogid, og))
     if missing_ogid:
         self._error_event(_NEXEL.NEXML,
                           obj=nex_obj,
                           err_type=gen_ReferencedIDNotFoundWarning,
                           anc=vc.anc_list,
                           obj_nex_id=obj_nex_id,
                           key_list=missing_ogid)
         return errorReturn('Missing "@id" for otus group')
     vc.push_context(_NEXEL.OTUS, (nex_obj, obj_nex_id))
     try:
         if not_dict_og:
             self._error_event(_NEXEL.OTUS,
                               obj=otus,
                               err_type=gen_WrongValueTypeWarning,
                               anc=vc.anc_list,
                               obj_nex_id=None,
                               key_val_type_list=[not_dict_og])
             return errorReturn('Otus objects of the wrong type of object')
         if not self._validate_otus_group_list(otus_group_list, vc):
             return False
     finally:
         vc.pop_context()
     # and now the trees...
     trees = nex_obj.get('treesById')
     trees_order_list = nex_obj.get('^ot:treesElementOrder')
     if (not isinstance(trees, dict)) or ((not trees) and trees_order_list):
         self._error_event(_NEXEL.NEXML,
                           obj=nex_obj,
                           err_type=gen_MissingCrucialContentWarning,
                           anc=vc.anc_list,
                           obj_nex_id=obj_nex_id,
                           key_list=['treesById'])
         return errorReturn('Missing "treesById"')
     if (not isinstance(trees_order_list, list)) or ((not trees_order_list)
                                                     and trees):
         self._error_event(_NEXEL.NEXML,
                           obj=nex_obj,
                           err_type=gen_MissingCrucialContentWarning,
                           anc=vc.anc_list,
                           obj_nex_id=obj_nex_id,
                           key_list=['^ot:treesElementOrder'])
         return errorReturn('Missing "^ot:treesElementOrder"')
     trees_group_list = []
     missing_tgid = []
     not_dict_tg = []
     for tgid in trees_order_list:
         tg = trees.get(tgid)
         if tg is None:
             missing_tgid.append(tgid)
         elif not isinstance(tg, dict):
             r = check_raw_dict(tg, trees, tgid, vc)
             assert r[0] is False
             t = r[1]
             not_dict_tg.append(t)
         else:
             trees_group_list.append((tgid, tg))
     if missing_tgid:
         self._error_event(_NEXEL.NEXML,
                           obj=nex_obj,
                           err_type=gen_ReferencedIDNotFoundWarning,
                           anc=vc.anc_list,
                           obj_nex_id=obj_nex_id,
                           key_list=missing_tgid)
         return errorReturn('Missing trees group id')
     vc.push_context(_NEXEL.TREES, (nex_obj, obj_nex_id))
     try:
         if not_dict_tg:
             self._error_event(_NEXEL.TREES,
                               obj=trees,
                               err_type=gen_WrongValueTypeWarning,
                               anc=vc.anc_list,
                               obj_nex_id=None,
                               key_val_type_list=[not_dict_tg])
             return errorReturn('Trees element of the wrong type')
         if not self._validate_trees_group_list(trees_group_list, vc):
             return False
     finally:
         vc.pop_context()
     if not nex_obj.get('ot:notIntendedForSynthesis'):
         cs = nex_obj.get('ot:candidateTreeForSynthesis')
         if cs:
             if not isinstance(cs, list):
                 tree_list = [cs]
             else:
                 tree_list = cs
         else:
             tree_list = []
             for tg in trees.values():
                 tbi = tg.get('treeById', {})
                 tree_list.extend(tbi.keys())
         self._generate_ott_warnings(otus, tree_list, (nex_obj, obj_nex_id),
                                     vc)
     return True