def sidechain_repo(sidechain_w_id_mols):
    mock_sc_repo = mock.MagicMock(spec=REPO_SPEC)
    mock_sc_repo.load.return_value = sidechain_w_id_mols
    mock_sc_repo.save.return_value = Key(extract_ids(sidechain_w_id_mols))
    with mock.patch('cpmg.repository.create_sidechain_repository',
                    return_value=mock_sc_repo):
        yield mock_sc_repo
 def save(self, data):
     macrocycles, completed_template_peptides = self._get_completed_template_peptides(data)
     self.template_peptide_repo.mark_complete(Key(completed_template_peptides))
     if len(macrocycles):
         return self.saver.save(macrocycles)
     else:
         return []
def template_repo(template_w_id_mols):
    mock_template_repo = mock.MagicMock(spec=REPO_SPEC)
    mock_template_repo.load.return_value = template_w_id_mols
    mock_template_repo.save.return_value = Key(extract_ids(template_w_id_mols))
    with mock.patch('cpmg.repository.create_template_repository',
                    return_value=mock_template_repo):
        yield mock_template_repo
def monomer_repo(monomer_w_idx_mols):
    mock_monomer_repo = mock.MagicMock(spec=REPO_SPEC)
    mock_monomer_repo.load.return_value = monomer_w_idx_mols
    mock_monomer_repo.save.return_value = Key(extract_ids(monomer_w_idx_mols))
    with mock.patch('cpmg.repository.create_monomer_repository',
                    return_value=mock_monomer_repo):
        yield mock_monomer_repo
    def save(self, data):
        data = utils.to_list(data)
        if len(data) == 0:
            return []

        group = self._refine_group_from_data(self.GROUP, data)
        return Key(self._save(group, data))
    def save(self, data):
        completed_combos = []
        for peptide in data:
            indices = tuple(self.id_hash[monomer['_id']] for monomer in peptide.monomers)
            completed_combos.append(self.hashed_plan[indices])

        self.plan_repo.mark_complete(Key(completed_combos))
        return self.saver.save(data)
    def load(self, *, peptide_plan_key, monomer_key=Key(WholeRange()), **kwargs):
        self._hash_monomers(monomer_key)

        self.hashed_plan = {}
        for _id, indices in self.plan_repo.load(peptide_plan_key):
            monomers = [self.index_hash[index] for index in indices]
            self.hashed_plan[indices] = _id
            yield PeptideDataHandlerTuple(monomers, peptide_plan_key.peptide_length)
def peptide_plan_repo(peptide_plans_w_ids):
    mock_peptide_plan_repo = mock.MagicMock(spec=REPO_SPEC)
    mock_peptide_plan_repo.load.return_value = peptide_plans_w_ids
    mock_peptide_plan_repo.save.return_value = Key(
        [_id for _id, combo in peptide_plans_w_ids])
    with mock.patch('cpmg.repository.create_peptide_plan_repository',
                    return_value=mock_peptide_plan_repo):
        yield mock_peptide_plan_repo, peptide_plans_w_ids
def connection_repo(connection_mols_w_ids):
    mock_connection_repo = mock.MagicMock(spec=REPO_SPEC)
    mock_connection_repo.load.return_value = connection_mols_w_ids
    mock_connection_repo.save.return_value = Key(
        extract_ids(connection_mols_w_ids))
    with mock.patch('cpmg.repository.create_connection_repository',
                    return_value=mock_connection_repo):
        yield mock_connection_repo
def peptide_repo(peptide_w_id_mols):
    mock_peptide_repo = mock.MagicMock(spec=REPO_SPEC)
    mock_peptide_repo.load.return_value = peptide_w_id_mols
    mock_peptide_repo.save.return_value = Key(extract_ids(peptide_w_id_mols))
    mock_peptide_repo.mark_complete.return_value = True
    with mock.patch('cpmg.repository.create_peptide_repository',
                    return_value=mock_peptide_repo):
        yield mock_peptide_repo
 def create_index(self, index):
     with HDF5File() as file:
         group = file[self.GROUP]
         index_dataset = self._create_index_dataset(
             file[self.GROUP], group[self.INDEX_DATASET], index)
         zipped_data = zip(*self.load(Key(WholeRange())))
         ids, data = zipped_data
         for record_index, _id in zip(self._extract_index_data(index, data),
                                      ids):
             index_dataset.attrs[record_index] = _id
def peptide_data_handler_loaded_repos(monomer_repo, peptide_plan_repo,
                                      peptide_repo):
    plan_repo, peptide_plan = peptide_plan_repo
    handler = handlers.PeptideDataHandler()

    key = Key(WholeRange(),
              peptide_length=min([len(combo) for combo in peptide_plan[1]]))
    yield handler, list(
        handler.load(peptide_plan_key=key)
    ), monomer_repo, plan_repo, peptide_repo, peptide_plan, key
    def remove_dataset(self, datasets):
        datasets = utils.to_list(datasets)
        with HDF5File() as file:
            group = file[self.GROUP]
            for dataset in self._get_datasets(group):
                if dataset in datasets:
                    self._remove_index_data(
                        self.GROUP, Key(list(group[dataset].attrs.keys())))
                    del group[dataset]

        return True
def test_template_peptide_data_handler_load(peptide_repo, template_repo,
                                            peptide_w_id_mols,
                                            template_w_id_mols):
    handler = handlers.TemplatePeptideDataHandler()

    data = list(handler.load(peptide_key=Key(WholeRange())))

    peptide_repo.load.assert_called_once()
    template_repo.load.assert_called_once()
    assert len(data) == len(peptide_w_id_mols)
    for peptide, templates in data:
        assert isinstance(peptide, models.Peptide)
        assert isinstance(templates, list)
        assert len(templates) == len(template_w_id_mols)
        assert all(map(lambda x: isinstance(x, models.Template), templates))
 def __load_records_from_kekule(self, kekules):
     self.records = self.repo.load(Key(kekules, index='kekule'))
 def save(self, data):
     completed_peptides = set(template_peptide.peptide['_id'] for template_peptide in data)
     self.peptide_repo.mark_complete(Key(completed_peptides))
     return self.saver.save(data)
 def load(self, *, template_peptide_key, reaction_key=Key(WholeRange()), **kwargs):
     self._hash_reactions(reaction_key)
     return self._match_reactions(template_peptide_key)
 def load(self, sidechain_key=Key(WholeRange()), monomer_key=Key(WholeRange()), template_key=Key(WholeRange()), **kwargs):
     templates = list(self.template_repo.load(template_key))
     for nucleophile in self._get_filtered_sidechains(sidechain_key) + self._get_filtered_monomers(monomer_key):
         yield InterMolecularReactionDataHandlerTuple(nucleophile, templates)
 def load(self, template_key=Key(WholeRange()), **kwargs):
     for reacting_mol in self.template_repo.load(template_key):
         yield IntraMolecularReactionDataHandlerTuple(reacting_mol)
 def load(self, sidechain_key=Key(WholeRange()), backbone_key=Key(WholeRange()), **kwargs):
     backbones = list(self.backbone_repo.load(backbone_key))
     for sidechain in self.sidechain_repo.load(sidechain_key):
         yield MonomerDataHandlerTuple(sidechain, backbones)
 def load(self, *, sidechain_key=Key(WholeRange()), connection_key=Key(WholeRange()), **kwargs):
     connections = list(self.connection_repo.load(connection_key))
     for sidechain in self.sidechain_repo.load(sidechain_key):
         yield SidechainDataHandlerTuple(sidechain, list(filter(lambda x: x.kekule != sidechain.connection, connections)))
 def load(self, key=Key(WholeRange())):
     for doc in self.impl.load(key):
         yield self.TYPE.from_dict(doc)
    def _convert_to_id_key(self, key):
        if key.index == 'id':
            return key

        return Key(list(self._get_ids_from_index(key)),
                   peptide_length=key.peptide_length)
 def deactivate_completed(self):
     self._load_completed()
     if len(self.completed):
         self.deactivate_records(Key(self.completed))
         with HDF5File() as file:
             del file[self.GROUP][self.COMPLETE_DATASET]
 def load(self, *, peptide_length, num_records, monomer_key=Key(WholeRange()), **kwargs):
     yield PeptidePlanDataHandlerTuple(list(self.monomer_repo.load(monomer_key)), peptide_length, num_records)
 def load(self, *, peptide_key, template_key=Key(WholeRange()), **kwargs):
     templates = list(self.template_repo.load(template_key))
     for peptide in self.peptide_repo.load(peptide_key):
         yield TemplatePeptideDataHandlerTuple(peptide, templates)