def test_inspect_synonyms(self):
     dopamine = resolve('dopamine')[0]
     self.assertTrue(inspect_synonyms(dopamine, 'Intropin'))
     self.assertTrue(inspect_synonyms(dopamine, 'parcopa'))
     self.assertTrue(inspect_synonyms(dopamine, 'SINEMET'))
     self.assertFalse(inspect_synonyms(dopamine, 'viagra'))
     self.assertFalse(inspect_synonyms(dopamine, ''))
예제 #2
0
 def test_inchi_serialiser(self):
     serialiser = get_serializer('inchi')
     mols = resolve('Vigamox')
     buf = StringIO()
     serialiser.write_header(buf)
     buf.seek(0)
     self.assertEqual(buf.read(), 'Name:\tInChI:\n')
     self.assertEqual(
         serialiser.serialize_line(mols),
         'InChI=1S/C21H24FN3O4/c1-29-20-17-13(19(26)14(21(27)28)9-25(17)12-4-5-12)7-15(22)18(20)24-8-11'
         '-3-2-6-23-16(11)10-24/h7,9,11-12,16,23H,2-6,8,10H2,1H3,(H,27,28)/t11-,16+/m0/s1\tInChI=1S/C21'
         'H24FN3O4.ClH/c1-29-20-17-13(19(26)14(21(27)28)9-25(17)12-4-5-12)7-15(22)18(20)24-8-11-3-2-6-2'
         '3-16(11)10-24;/h7,9,11-12,16,23H,2-6,8,10H2,1H3,(H,27,28);1H/t11-,16+;/m0./s1\n'
     )
     self.assertEqual(
         serialiser.serialize_line(mols, human=True),
         'InChI=1S/C21H24FN3O4/c1-29-20-17-13(19(26)14(21(27)28)9-25(17)12-4-5-12)7-15(22)18(20)24-8-11'
         '-3-2-6-23-16(11)10-24/h7,9,11-12,16,23H,2-6,8,10H2,1H3,(H,27,28)/t11-,16+/m0/s1\tInChI=1S/C21'
         'H24FN3O4.ClH/c1-29-20-17-13(19(26)14(21(27)28)9-25(17)12-4-5-12)7-15(22)18(20)24-8-11-3-2-6-2'
         '3-16(11)10-24;/h7,9,11-12,16,23H,2-6,8,10H2,1H3,(H,27,28);1H/t11-,16+;/m0./s1\n'
     )
     self.assertEqual(
         serialiser.serialize_line(mols, human=True, name='Vigamox'),
         'Vigamox\tInChI=1S/C21H24FN3O4/c1-29-20-17-13(19(26)14(21(27)28)9-25(17)12-4-5-12)7-15(22)18(2'
         '0)24-8-11-3-2-6-23-16(11)10-24/h7,9,11-12,16,23H,2-6,8,10H2,1H3,(H,27,28)/t11-,16+/m0/s1\tInC'
         'hI=1S/C21H24FN3O4.ClH/c1-29-20-17-13(19(26)14(21(27)28)9-25(17)12-4-5-12)7-15(22)18(20)24-8-1'
         '1-3-2-6-23-16(11)10-24;/h7,9,11-12,16,23H,2-6,8,10H2,1H3,(H,27,28);1H/t11-,16+;/m0./s1\n'
     )
    def test_mols_to_targets(self):
        ret = mols_to_targets(['CHEMBL819'], organism='Escherichia coli')
        serialiser = get_serializer('uniprot')
        self.assertEqual(set(serialiser.serialize_line(ret).strip().split(',')), {'A1E3K9', 'P62593', 'P35695'})

        ret = mols_to_targets(['CHEMBL819'], organism='Escherichia coli', include_parents=True)
        serialiser = get_serializer('uniprot')
        self.assertEqual(set(serialiser.serialize_line(ret).strip().split(',')),
                         {'A1E3K9', 'P62593', 'P35695', 'P00811'})

        ret = mols_to_targets(['CHEMBL25', 'CHEMBL1'])
        serialiser = get_serializer('gene_name')
        self.assertTrue({'POLK', 'ADRA2RL2', 'CCR2', 'CHRM5', 'ADRA2L1', 'CMKAR1', 'PTPRC', 'HADH2', 'ITGAB', 'VIPR1'
                         }.issubset(set(serialiser.serialize_line(ret).strip().split(','))))

        ret = mols_to_targets(['CHEMBL2', 'CHEMBL1737'])
        serialiser = get_serializer('chembl_id')
        targets_a = set(serialiser.serialize_line(ret).strip().split(','))
        self.assertTrue({'CHEMBL213', 'CHEMBL1916', 'CHEMBL205', 'CHEMBL4071', 'CHEMBL1909043', 'CHEMBL2622',
                         }.issubset(targets_a))

        ret = mols_to_targets(['CHEMBL2', 'CHEMBL1737'], only_ids=True)
        serialiser = get_serializer('chembl_id')
        targets_b = set(serialiser.serialize_line(ret).strip().split(','))
        self.assertTrue({'CHEMBL213', 'CHEMBL1916', 'CHEMBL205', 'CHEMBL4071', 'CHEMBL1909043', 'CHEMBL2622',
                         }.issubset(targets_b))

        self.assertEqual(targets_a, targets_b)

        drugs = ['Viagra', 'Gleevec']

        ret = mols_to_targets([resolve(x)[0]['molecule_chembl_id'] for x in drugs])
        serialiser = get_serializer('uniprot')
        self.assertTrue({'Q9BQI3', 'P00523', 'O15111', 'P22612', 'P25021', 'P16591', 'Q13153', 'Q8WXR4', 'P28564',
                         }.issubset(set(serialiser.serialize_line(ret).strip().split(','))))
예제 #4
0
def main():

    options = get_options()
    with open(options.input) if options.input else sys.stdin as in_f, \
            open(options.output, 'w') if options.output else sys.stdout as out_f:

        serializer_cls = get_serializer(options.format)
        if not serializer_cls:
            sys.stderr.write('Unsupported format', options.format)
            return

        if options.human:
            serializer_cls.write_header(out_f)

        for line in in_f:
            name = line.strip()
            if not name:
                continue
            resolved = None
            try:
                resolved = resolve(name, options.single)
            except Exception as e:
                pass
            if options.parent:
                resolved = get_parents(resolved)
            out_f.write(
                serializer_cls.serialize_line(resolved,
                                              human=options.human,
                                              name=name))
예제 #5
0
 def test_inspect_synonyms(self):
     dopamine = resolve('dopamine')[0]
     self.assertTrue(inspect_synonyms(dopamine, 'Intropin'))
     self.assertTrue(inspect_synonyms(dopamine, 'parcopa'))
     self.assertTrue(inspect_synonyms(dopamine, 'SINEMET'))
     self.assertFalse(inspect_synonyms(dopamine, 'viagra'))
     self.assertFalse(inspect_synonyms(dopamine, ''))
def main():

    options = get_options()
    with open(options.input) if options.input else sys.stdin as in_f, \
            open(options.output, 'w') if options.output else sys.stdout as out_f:

        serializer_cls = get_serializer(options.format)
        if not serializer_cls:
            sys.stderr.write('Unsupported format', options.format)
            return

        if options.human:
            serializer_cls.write_header(out_f)

        for line in in_f:
            name = line.strip()
            if not name:
                continue
            resolved = None
            try:
                resolved = resolve(name, options.single)
            except Exception as e:
                pass
            if options.parent:
                resolved = get_parents(resolved)
            out_f.write(serializer_cls.serialize_line(resolved, human=options.human, name=name))
 def test_chembl_id_serialiser(self):
     serialiser = get_serializer('chembl_id')
     mols = resolve('Vigamox')
     buf = StringIO()
     serialiser.write_header(buf)
     buf.seek(0)
     self.assertEqual(buf.read(), 'Name:\tChEMBL ID:\n')
     self.assertEqual(serialiser.serialize_line(mols), 'CHEMBL32,CHEMBL1200735\n')
     self.assertEqual(serialiser.serialize_line(mols, human=True), 'CHEMBL32,CHEMBL1200735\n')
     self.assertEqual(serialiser.serialize_line(mols, human=True, name='Vigamox'),
                      'Vigamox\tCHEMBL32,CHEMBL1200735\n')
    def test_sdf_serialiser(self):

        serialiser = get_serializer('sdf')
        mols = resolve('Vigamox')
        buf = StringIO()
        serialiser.write_header(buf)
        buf.seek(0)
        self.assertEqual(buf.read(), '')
        self.assertEqual(serialiser.serialize_line(mols), sdf, serialiser.serialize_line(mols))
        self.assertEqual(serialiser.serialize_line(mols, human=True), sdf)
        self.assertEqual(serialiser.serialize_line(mols, human=True, name='Vigamox'), sdf)
        serialiser = get_serializer('mol')
        mols = resolve('Vigamox')
        buf = StringIO()
        serialiser.write_header(buf)
        buf.seek(0)
        self.assertEqual(buf.read(), '')
        self.assertEqual(serialiser.serialize_line(mols), sdf, serialiser.serialize_line(mols))
        self.assertEqual(serialiser.serialize_line(mols, human=True), sdf)
        self.assertEqual(serialiser.serialize_line(mols, human=True, name='Vigamox'), sdf)
 def test_chembl_key_serialiser(self):
     serialiser = get_serializer('inchi_key')
     mols = resolve('Vigamox')
     buf = StringIO()
     serialiser.write_header(buf)
     buf.seek(0)
     self.assertEqual(buf.read(), 'Name:\tInChI Key:\n')
     self.assertEqual(serialiser.serialize_line(mols), 'FABPRXSRWADJSP-MEDUHNTESA-N,IDIIJJHBXUESQI-DFIJPDEKSA-N\n')
     self.assertEqual(serialiser.serialize_line(mols, human=True),
                      'FABPRXSRWADJSP-MEDUHNTESA-N,IDIIJJHBXUESQI-DFIJPDEKSA-N\n')
     self.assertEqual(serialiser.serialize_line(mols, human=True, name='Vigamox'),
                      'Vigamox\tFABPRXSRWADJSP-MEDUHNTESA-N,IDIIJJHBXUESQI-DFIJPDEKSA-N\n')
예제 #10
0
 def test_chembl_id_serialiser(self):
     serialiser = get_serializer('chembl_id')
     mols = resolve('Vigamox')
     buf = StringIO()
     serialiser.write_header(buf)
     buf.seek(0)
     self.assertEqual(buf.read(), 'Name:\tChEMBL ID:\n')
     self.assertEqual(serialiser.serialize_line(mols),
                      'CHEMBL32,CHEMBL1200735\n')
     self.assertEqual(serialiser.serialize_line(mols, human=True),
                      'CHEMBL32,CHEMBL1200735\n')
     self.assertEqual(
         serialiser.serialize_line(mols, human=True, name='Vigamox'),
         'Vigamox\tCHEMBL32,CHEMBL1200735\n')
예제 #11
0
    def test_sdf_serialiser(self):

        serialiser = get_serializer('sdf')
        mols = resolve('Vigamox')
        buf = StringIO()
        serialiser.write_header(buf)
        buf.seek(0)
        self.assertEqual(buf.read(), '')
        self.assertEqual(serialiser.serialize_line(mols), sdf,
                         serialiser.serialize_line(mols))
        self.assertEqual(serialiser.serialize_line(mols, human=True), sdf)
        self.assertEqual(
            serialiser.serialize_line(mols, human=True, name='Vigamox'), sdf)
        serialiser = get_serializer('mol')
        mols = resolve('Vigamox')
        buf = StringIO()
        serialiser.write_header(buf)
        buf.seek(0)
        self.assertEqual(buf.read(), '')
        self.assertEqual(serialiser.serialize_line(mols), sdf,
                         serialiser.serialize_line(mols))
        self.assertEqual(serialiser.serialize_line(mols, human=True), sdf)
        self.assertEqual(
            serialiser.serialize_line(mols, human=True, name='Vigamox'), sdf)
예제 #12
0
 def test_smiles_serialiser(self):
     serialiser = get_serializer('smi')
     mols = resolve('Vigamox')
     buf = StringIO()
     serialiser.write_header(buf)
     buf.seek(0)
     self.assertEqual(buf.read(), 'SMILES Name\n')
     self.assertEqual(serialiser.serialize_line(mols),
                      'COc1c(N2C[C@@H]3CCCN[C@@H]3C2)c(F)cc4C(=O)C(=CN(C5CC5)c14)C(=O)O\n'
                      'Cl.COc1c(N2C[C@@H]3CCCN[C@@H]3C2)c(F)cc4C(=O)C(=CN(C5CC5)c14)C(=O)O\n')
     self.assertEqual(serialiser.serialize_line(mols, human=True),
                      'COc1c(N2C[C@@H]3CCCN[C@@H]3C2)c(F)cc4C(=O)C(=CN(C5CC5)c14)C(=O)O\n'
                      'Cl.COc1c(N2C[C@@H]3CCCN[C@@H]3C2)c(F)cc4C(=O)C(=CN(C5CC5)c14)C(=O)O\n')
     self.assertEqual(serialiser.serialize_line(mols, human=True, name='Vigamox'),
                      'COc1c(N2C[C@@H]3CCCN[C@@H]3C2)c(F)cc4C(=O)C(=CN(C5CC5)c14)C(=O)O Vigamox\n'
                      'Cl.COc1c(N2C[C@@H]3CCCN[C@@H]3C2)c(F)cc4C(=O)C(=CN(C5CC5)c14)C(=O)O Vigamox\n')
예제 #13
0
 def test_chembl_key_serialiser(self):
     serialiser = get_serializer('inchi_key')
     mols = resolve('Vigamox')
     buf = StringIO()
     serialiser.write_header(buf)
     buf.seek(0)
     self.assertEqual(buf.read(), 'Name:\tInChI Key:\n')
     self.assertEqual(
         serialiser.serialize_line(mols),
         'FABPRXSRWADJSP-MEDUHNTESA-N,IDIIJJHBXUESQI-DFIJPDEKSA-N\n')
     self.assertEqual(
         serialiser.serialize_line(mols, human=True),
         'FABPRXSRWADJSP-MEDUHNTESA-N,IDIIJJHBXUESQI-DFIJPDEKSA-N\n')
     self.assertEqual(
         serialiser.serialize_line(mols, human=True, name='Vigamox'),
         'Vigamox\tFABPRXSRWADJSP-MEDUHNTESA-N,IDIIJJHBXUESQI-DFIJPDEKSA-N\n'
     )
예제 #14
0
def main():
    options = get_options()

    source_format = options.source_format.lower()
    if source_format not in AVAILABLE_SOURCE_FORMATS:
        sys.stderr.write('Unsupported source format', options.source_format)
        return

    inp = sys.stdin
    if source_format == 'sdf':
        with open(options.input) if options.input else sys.stdin as in_f:
            options.input = None
            inp = convert_to_smiles(in_f)

    with open(options.input) if options.input else inp as in_f, \
            open(options.output, 'w') if options.output else sys.stdout as out_f:

        serializer_cls = get_serializer(options.dest_format)
        if not serializer_cls:
            sys.stderr.write('Unsupported format', options.dest_format)
            return

        if options.human:
            serializer_cls.write_header(out_f)

        for line in in_f:
            if not line or line.lower().startswith('smiles'):
                continue
            chunk = line.strip().split()[0]
            identifiers = chunk.strip().split(',')
            valid_identifiers = list()
            for identifier in identifiers:
                if chembl_id_regex.match(identifier):
                    valid_identifiers.append(identifier)
                elif smiles_regex.match(identifier):
                    valid_identifiers.extend([x['molecule_chembl_id'] for x in resolve(identifier)])
            targets = mols_to_targets(valid_identifiers,
                                      organism=options.organism,
                                      only_ids=(options.dest_format == 'chembl_id'),
                                      include_parents=options.parent,
                                      chunk_size=int(options.chunk))
            out_f.write(serializer_cls.serialize_line(targets, human=options.human, name=','.join(valid_identifiers)))
예제 #15
0
 def test_smiles_serialiser(self):
     serialiser = get_serializer('smi')
     mols = resolve('Vigamox')
     buf = StringIO()
     serialiser.write_header(buf)
     buf.seek(0)
     self.assertEqual(buf.read(), 'SMILES Name\n')
     self.assertEqual(
         serialiser.serialize_line(mols),
         'COc1c(N2C[C@@H]3CCCN[C@@H]3C2)c(F)cc4C(=O)C(=CN(C5CC5)c14)C(=O)O\n'
         'Cl.COc1c(N2C[C@@H]3CCCN[C@@H]3C2)c(F)cc4C(=O)C(=CN(C5CC5)c14)C(=O)O\n'
     )
     self.assertEqual(
         serialiser.serialize_line(mols, human=True),
         'COc1c(N2C[C@@H]3CCCN[C@@H]3C2)c(F)cc4C(=O)C(=CN(C5CC5)c14)C(=O)O\n'
         'Cl.COc1c(N2C[C@@H]3CCCN[C@@H]3C2)c(F)cc4C(=O)C(=CN(C5CC5)c14)C(=O)O\n'
     )
     self.assertEqual(
         serialiser.serialize_line(mols, human=True, name='Vigamox'),
         'COc1c(N2C[C@@H]3CCCN[C@@H]3C2)c(F)cc4C(=O)C(=CN(C5CC5)c14)C(=O)O Vigamox\n'
         'Cl.COc1c(N2C[C@@H]3CCCN[C@@H]3C2)c(F)cc4C(=O)C(=CN(C5CC5)c14)C(=O)O Vigamox\n'
     )
예제 #16
0
 def test_inchi_serialiser(self):
     serialiser = get_serializer('inchi')
     mols = resolve('Vigamox')
     buf = StringIO()
     serialiser.write_header(buf)
     buf.seek(0)
     self.assertEqual(buf.read(), 'Name:\tInChI:\n')
     self.assertEqual(serialiser.serialize_line(mols),
                      'InChI=1S/C21H24FN3O4/c1-29-20-17-13(19(26)14(21(27)28)9-25(17)12-4-5-12)7-15(22)18(20)24-8-11'
                      '-3-2-6-23-16(11)10-24/h7,9,11-12,16,23H,2-6,8,10H2,1H3,(H,27,28)/t11-,16+/m0/s1\tInChI=1S/C21'
                      'H24FN3O4.ClH/c1-29-20-17-13(19(26)14(21(27)28)9-25(17)12-4-5-12)7-15(22)18(20)24-8-11-3-2-6-2'
                      '3-16(11)10-24;/h7,9,11-12,16,23H,2-6,8,10H2,1H3,(H,27,28);1H/t11-,16+;/m0./s1\n')
     self.assertEqual(serialiser.serialize_line(mols, human=True),
                      'InChI=1S/C21H24FN3O4/c1-29-20-17-13(19(26)14(21(27)28)9-25(17)12-4-5-12)7-15(22)18(20)24-8-11'
                      '-3-2-6-23-16(11)10-24/h7,9,11-12,16,23H,2-6,8,10H2,1H3,(H,27,28)/t11-,16+/m0/s1\tInChI=1S/C21'
                      'H24FN3O4.ClH/c1-29-20-17-13(19(26)14(21(27)28)9-25(17)12-4-5-12)7-15(22)18(20)24-8-11-3-2-6-2'
                      '3-16(11)10-24;/h7,9,11-12,16,23H,2-6,8,10H2,1H3,(H,27,28);1H/t11-,16+;/m0./s1\n')
     self.assertEqual(serialiser.serialize_line(mols, human=True, name='Vigamox'),
                      'Vigamox\tInChI=1S/C21H24FN3O4/c1-29-20-17-13(19(26)14(21(27)28)9-25(17)12-4-5-12)7-15(22)18(2'
                      '0)24-8-11-3-2-6-23-16(11)10-24/h7,9,11-12,16,23H,2-6,8,10H2,1H3,(H,27,28)/t11-,16+/m0/s1\tInC'
                      'hI=1S/C21H24FN3O4.ClH/c1-29-20-17-13(19(26)14(21(27)28)9-25(17)12-4-5-12)7-15(22)18(20)24-8-1'
                      '1-3-2-6-23-16(11)10-24;/h7,9,11-12,16,23H,2-6,8,10H2,1H3,(H,27,28);1H/t11-,16+;/m0./s1\n')
예제 #17
0
    def test_get_parents(self):
        parents = get_parents(resolve('CHEMBL1642'))
        self.assertEqual(len(parents), 1)
        self.assertEqual(parents[0]['molecule_chembl_id'], 'CHEMBL941')

        parents = get_parents(resolve('CHEMBL941'))
        self.assertEqual(len(parents), 1)
        self.assertEqual(parents[0]['molecule_chembl_id'], 'CHEMBL941')

        parents = get_parents(resolve('CHEMBL1200735'))
        self.assertEqual(len(parents), 1)
        self.assertEqual(parents[0]['molecule_chembl_id'], 'CHEMBL32')

        parents = get_parents(resolve('CHEMBL32'))
        self.assertEqual(len(parents), 1)
        self.assertEqual(parents[0]['molecule_chembl_id'], 'CHEMBL32')

        parents = get_parents(resolve('CHEMBL1642') + resolve('CHEMBL1200735'))
        self.assertEqual(len(parents), 2)
        self.assertEqual(parents[1]['molecule_chembl_id'], 'CHEMBL941')
        self.assertEqual(parents[0]['molecule_chembl_id'], 'CHEMBL32')
예제 #18
0
    def test_get_parents(self):
        parents = get_parents(resolve('CHEMBL1642'))
        self.assertEqual(len(parents), 1)
        self.assertEqual(parents[0]['molecule_chembl_id'], 'CHEMBL941')

        parents = get_parents(resolve('CHEMBL941'))
        self.assertEqual(len(parents), 1)
        self.assertEqual(parents[0]['molecule_chembl_id'], 'CHEMBL941')

        parents = get_parents(resolve('CHEMBL1200735'))
        self.assertEqual(len(parents), 1)
        self.assertEqual(parents[0]['molecule_chembl_id'], 'CHEMBL32')

        parents = get_parents(resolve('CHEMBL32'))
        self.assertEqual(len(parents), 1)
        self.assertEqual(parents[0]['molecule_chembl_id'], 'CHEMBL32')

        parents = get_parents(resolve('CHEMBL1642') + resolve('CHEMBL1200735'))
        self.assertEqual(len(parents), 2)
        self.assertEqual(parents[1]['molecule_chembl_id'], 'CHEMBL941')
        self.assertEqual(parents[0]['molecule_chembl_id'], 'CHEMBL32')
예제 #19
0
    def test_resolve(self):

        ret = resolve('viagra')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL1737')

        ret = resolve('gleevec')
        self.assertEqual(len(ret), 2)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL941')
        self.assertEqual(ret[1]['molecule_chembl_id'], 'CHEMBL1642')

        ret = resolve('gleevec', single_result=True)
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL941')

        ret = resolve('aspirin')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL25')

        ret = resolve('chembl59')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL59')

        ret = resolve('OLEOYL')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL191896')

        ret = resolve('Fc1ccc2[nH]c3CCN(CCc4ccncc4)Cc3c2c1')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL300443')

        ret = resolve('VYFYYTLLBUKUHU-WTJCDBBSSA-N')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL3247442')

        ret = resolve('Vigamox')
        self.assertEqual(len(ret), 2)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL32')
        self.assertEqual(ret[1]['molecule_chembl_id'], 'CHEMBL1200735')

        ret = resolve('Vigamox', single_result=True)
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL32')

        ret = resolve(
            'InChI=1S/C8H12N4O5/c9-6(16)7-10-2-12(11-7)8-5(15)4(14)3(1-13)17-8/h2-5,8,13-15H,1H2,(H2,9,16)'
        )
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL34')
예제 #20
0
 def test_enhance_mols_with_parents(self):
     enhanced = [x['molecule_chembl_id'] for x in enhance_mols_with_parents(resolve('CHEMBL1642'))]
     self.assertEqual(enhanced, ['CHEMBL941', 'CHEMBL1642'])
예제 #21
0
    def test_resolve(self):

        ret = resolve('viagra')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL1737')

        ret = resolve('gleevec')
        self.assertEqual(len(ret), 2)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL941')
        self.assertEqual(ret[1]['molecule_chembl_id'], 'CHEMBL1642')

        ret = resolve('gleevec', single_result=True)
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL941')

        ret = resolve('aspirin')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL25')

        ret = resolve('chembl59')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL59')

        ret = resolve('OLEOYL')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL191896')

        ret = resolve('Fc1ccc2[nH]c3CCN(CCc4ccncc4)Cc3c2c1')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL300443')

        ret = resolve('VYFYYTLLBUKUHU-WTJCDBBSSA-N')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL3247442')

        ret = resolve('Vigamox')
        self.assertEqual(len(ret), 2)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL32')
        self.assertEqual(ret[1]['molecule_chembl_id'], 'CHEMBL1200735')

        ret = resolve('Vigamox', single_result=True)
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL32')

        ret = resolve('InChI=1S/C8H12N4O5/c9-6(16)7-10-2-12(11-7)8-5(15)4(14)3(1-13)17-8/h2-5,8,13-15H,1H2,(H2,9,16)')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL34')
예제 #22
0
    def test_mols_to_targets(self):
        ret = mols_to_targets(['CHEMBL819'], organism='Escherichia coli')
        serialiser = get_serializer('uniprot')
        self.assertEqual(
            set(serialiser.serialize_line(ret).strip().split(',')),
            {'A1E3K9', 'P62593', 'P35695'})

        ret = mols_to_targets(['CHEMBL819'],
                              organism='Escherichia coli',
                              include_parents=True)
        serialiser = get_serializer('uniprot')
        self.assertEqual(
            set(serialiser.serialize_line(ret).strip().split(',')),
            {'A1E3K9', 'P62593', 'P35695', 'P00811'})

        ret = mols_to_targets(['CHEMBL25', 'CHEMBL1'])
        serialiser = get_serializer('gene_name')
        self.assertTrue({
            'POLK', 'ADRA2RL2', 'CCR2', 'CHRM5', 'ADRA2L1', 'CMKAR1', 'PTPRC',
            'HADH2', 'ITGAB', 'VIPR1'
        }.issubset(set(serialiser.serialize_line(ret).strip().split(','))))

        ret = mols_to_targets(['CHEMBL2', 'CHEMBL1737'])
        serialiser = get_serializer('chembl_id')
        targets_a = set(serialiser.serialize_line(ret).strip().split(','))
        self.assertTrue({
            'CHEMBL213',
            'CHEMBL1916',
            'CHEMBL205',
            'CHEMBL4071',
            'CHEMBL1909043',
            'CHEMBL2622',
        }.issubset(targets_a))

        ret = mols_to_targets(['CHEMBL2', 'CHEMBL1737'], only_ids=True)
        serialiser = get_serializer('chembl_id')
        targets_b = set(serialiser.serialize_line(ret).strip().split(','))
        self.assertTrue({
            'CHEMBL213',
            'CHEMBL1916',
            'CHEMBL205',
            'CHEMBL4071',
            'CHEMBL1909043',
            'CHEMBL2622',
        }.issubset(targets_b))

        self.assertEqual(targets_a, targets_b)

        drugs = ['Viagra', 'Gleevec']

        ret = mols_to_targets(
            [resolve(x)[0]['molecule_chembl_id'] for x in drugs])
        serialiser = get_serializer('uniprot')
        self.assertTrue({
            'Q9BQI3',
            'P00523',
            'O15111',
            'P22612',
            'P25021',
            'P16591',
            'Q13153',
            'Q8WXR4',
            'P28564',
        }.issubset(set(serialiser.serialize_line(ret).strip().split(','))))
예제 #23
0
 def test_enhance_mols_with_parents(self):
     enhanced = [
         x['molecule_chembl_id']
         for x in enhance_mols_with_parents(resolve('CHEMBL1642'))
     ]
     self.assertEqual(enhanced, ['CHEMBL941', 'CHEMBL1642'])