示例#1
0
    def build_groups(self, mpsnl, force_new=False, snlgroup_guess=None, testing_mode=False):
        # testing mode is used to see if something already exists in DB w/o adding it to the db

        match_found = False
        if not force_new:
            if snlgroup_guess:
                sgp = self.snlgroups.find_one({'snlgroup_id': snlgroup_guess})
                snlgroup = SNLGroup.from_dict(sgp)
                match_found, spec_group = self._add_if_belongs(snlgroup, mpsnl, testing_mode)

            if not match_found:
                # look at all potential matches
                for entry in self.snlgroups.find({'snlgroup_key': mpsnl.snlgroup_key},
                                                 sort=[("num_snl", DESCENDING)]):
                    snlgroup = SNLGroup.from_dict(entry)
                    match_found, spec_group = self._add_if_belongs(snlgroup, mpsnl, testing_mode)
                    if match_found:
                        break

        if not match_found:
            # add a new SNLGroup
            snlgroup_id = self._get_next_snlgroup_id()
            snlgroup = SNLGroup(snlgroup_id, mpsnl)
            spec_group=None
            if snlgroup.species_groups:
                spec_group = snlgroup.species_groups.keys()[0]
            if not testing_mode:
                self.snlgroups.insert(snlgroup.as_dict())

        return snlgroup, not match_found, spec_group
示例#2
0
    def switch_canonical_snl(self, snlgroup_id, canonical_mpsnl):
        sgp = self.snlgroups.find_one({'snlgroup_id': snlgroup_id})
        snlgroup = SNLGroup.from_dict(sgp)

        all_snl_ids = [sid for sid in snlgroup.all_snl_ids]
        if canonical_mpsnl.snl_id not in all_snl_ids:
            raise ValueError('Canonical SNL must already be in snlgroup to switch!')

        new_group = SNLGroup(snlgroup_id, canonical_mpsnl, all_snl_ids)
        self.snlgroups.update({'snlgroup_id': snlgroup_id}, new_group.as_dict())
示例#3
0
    def switch_canonical_snl(self, snlgroup_id, canonical_mpsnl):
        sgp = self.snlgroups.find_one({'snlgroup_id': snlgroup_id})
        snlgroup = SNLGroup.from_dict(sgp)

        all_snl_ids = [sid for sid in snlgroup.all_snl_ids]
        if canonical_mpsnl.snl_id not in all_snl_ids:
            raise ValueError(
                'Canonical SNL must already be in snlgroup to switch!')

        new_group = SNLGroup(snlgroup_id, canonical_mpsnl, all_snl_ids)
        self.snlgroups.update({'snlgroup_id': snlgroup_id},
                              new_group.as_dict())
示例#4
0
    def build_groups(self,
                     mpsnl,
                     force_new=False,
                     snlgroup_guess=None,
                     testing_mode=False):
        # testing mode is used to see if something already exists in DB w/o adding it to the db

        match_found = False
        if not force_new:
            if snlgroup_guess:
                sgp = self.snlgroups.find_one({'snlgroup_id': snlgroup_guess})
                snlgroup = SNLGroup.from_dict(sgp)
                match_found, spec_group = self._add_if_belongs(
                    snlgroup, mpsnl, testing_mode)

            if not match_found:
                # look at all potential matches
                for entry in self.snlgroups.find(
                    {'snlgroup_key': mpsnl.snlgroup_key},
                        sort=[("num_snl", DESCENDING)]):
                    snlgroup = SNLGroup.from_dict(entry)
                    match_found, spec_group = self._add_if_belongs(
                        snlgroup, mpsnl, testing_mode)
                    if match_found:
                        break

        if not match_found:
            # add a new SNLGroup
            snlgroup_id = self._get_next_snlgroup_id()
            snlgroup = SNLGroup(snlgroup_id, mpsnl)
            spec_group = None
            if snlgroup.species_groups:
                spec_group = snlgroup.species_groups.keys()[0]
            if not testing_mode:
                self.snlgroups.insert(snlgroup.as_dict())

        return snlgroup, not match_found, spec_group