Esempio n. 1
0
def test_template_repository(template_mols, model_sort_key):
    template_repo = repo.create_template_repository()
    ids = template_repo.save(template_mols)
    data = list(template_repo.load(ids))
    data.sort(key=model_sort_key)

    assert data == template_mols
def test_initialize(initialized_repository):
    assert len(list(repo.create_backbone_repository().load())) == 3
    assert len(list(repo.create_connection_repository().load())) == 2
    assert len(list(repo.create_template_repository().load())) == 3
    assert len(list(repo.create_sidechain_repository().load())) == 3
    assert len(list(repo.create_monomer_repository().load())) == 4
    assert len(list(repo.create_regiosqm_repository().load())) == 3
    assert len(list(repo.create_pka_repository().load())) == 3
def test_initialize_predictions_only(partial_initialized_repository):
    exporter = RegioSQMExporter()
    exporter.export_regiosqm_smiles_file()

    initializer = CPMGInitializer()
    initializer._initialize_predictions_only()

    assert len(list(repo.create_backbone_repository().load())) == 3
    assert len(list(repo.create_connection_repository().load())) == 2
    assert len(list(repo.create_template_repository().load())) == 3
    assert len(list(repo.create_sidechain_repository().load())) == 3
    assert len(list(repo.create_monomer_repository().load())) == 4
    assert len(list(repo.create_regiosqm_repository().load())) == 3
    assert len(list(repo.create_pka_repository().load())) == 3
Esempio n. 4
0
def test_template_importer(json_importer):
    template_importer = importers.TemplateImporter(json_importer)
    ids = template_importer.import_data()

    template_repo = repo.create_template_repository()
    data = list(template_repo.load(ids))
    docs = json_importer.load(template_importer.saver.TYPE.STRING)
    kekules = [doc['kekule'] for doc in docs]

    assert(len(data) == 3)
    for mol in data:
        assert(mol._id != None)
        assert(mol.kekule in kekules)
        kekules.remove(mol.kekule)
    def _match_reactions(self, key):
        templates = repo.create_template_repository().load()
        ps_capable_templates = tuple(template._id for template in filter(lambda x: x.pictet_spangler_kekule, templates))

        for template_peptide in self.template_peptide_repo.load(key):
            reactions = []
            sidechain_data = set(monomer['sidechain'] for monomer in template_peptide.monomers if
                                 monomer['sidechain'] is not None)
            monomer_data = set(
                monomer['_id'] for monomer in template_peptide.monomers if monomer['sidechain'] is None)
            for mol_id in chain(sidechain_data, monomer_data):
                reactions.extend(filter(lambda x: x.template == template_peptide.template, self.reactions[mol_id]))

            first_monomer = template_peptide.monomers[0]['sidechain']
            is_proline = template_peptide.monomers[0]['proline']

            # can apply pictet_spangler reactions or template_only_reactions because
            #   1. Template 2 and 3 has unmasked aldehyde
            #   2. First monomer has a sidechain which comes from a set of aromatic heterocycles (either the sidechain
            #      undergo pictet_spangler or the template can undergo pictet_spangler/aldehyde cyclization)
            #   3. First monomer doesnt contain any aromatic atoms and is not a proline thus the template will be able
            #      to undergo the template_only_reactions
            if template_peptide.template in ps_capable_templates and \
                    ((first_monomer is not None) or (first_monomer is None and not is_proline)):

                # get pictet_spangler reactions involving only the first monomer or any other type of reaction
                reactions = filter(lambda x: ((x.type == self.PS and x.reacting_mol['_id'] == first_monomer)
                                              or x.type in (self.FC, self.TT, self.PI)), reactions)

                # sort reactions based on if they are pictet_spangler or not
                pictet, other = [], []
                for rxn in reactions:
                    other.append(rxn) if rxn.type != self.PS else pictet.append(rxn)

                if not pictet or first_monomer is None:
                    rxn_combinations = product(self.template_only_reactions[template_peptide.template], other)
                else:
                    # if pictet_spangler fails because template is not oligomerized to the peptide at the first monomer
                    # (as may occur with lysine in the peptide) then template_only_reaction will be applied. Otherwise
                    # pictet_spangler will occur, blocking the template_only_reaction from taking place
                    rxn_combinations = product(pictet, self.template_only_reactions[template_peptide.template], other)

                yield MacrocycleDataHandlerTuple(template_peptide, rxn_combinations)

            else:  # friedel_crafts, tsuji_trost, pyrrolo_indolene
                yield MacrocycleDataHandlerTuple(template_peptide,
                                                 [[rxn] for rxn in filter(lambda x: x.type != self.PS, reactions)])
def test_initialize_mol_only(partial_initialized_repository):
    assert len(list(repo.create_backbone_repository().load())) == 3
    assert len(list(repo.create_connection_repository().load())) == 2
    assert len(list(repo.create_template_repository().load())) == 3
    assert len(list(repo.create_sidechain_repository().load())) == 3
    assert len(list(repo.create_monomer_repository().load())) == 4
 def __init__(self):
     self.template_repo = repo.create_template_repository()
     super().__init__(repo.create_reaction_repository())
 def __init__(self):
     self.sidechain_repo = repo.create_sidechain_repository()
     self.monomer_repo = repo.create_monomer_repository()
     self.template_repo = repo.create_template_repository()
     super().__init__(repo.create_reaction_repository())
 def __init__(self):
     self.template_repo = repo.create_template_repository()
     self.peptide_repo = repo.create_peptide_repository()
     super().__init__(repo.create_template_peptide_repository())
Esempio n. 10
0
def test_template_repository_fail():
    template_repo = repo.create_template_repository()

    _ = template_repo.save(['dne'])

    assert len(template_repo.failed_instances) == 1
 def __init__(self, loader):
     self.loader = loader
     self.saver = repo.create_template_repository()