示例#1
0
def list_all_cid_from_sdf(sdffile, ID_tag, outfile):
    fp = file(outfile, 'w')
    for sdf in sdfiterator.sdf_iter(sdffile):
        tagdict = get_sdf_tags(sdf)
        cid = tagdict[ID_tag]
        fp.write('%s\n' % cid)

    fp.close()
    return
def batch_sdf_to_smiles(sdfs):
    from compounddb.sdfiterator import sdf_iter
    from io import StringIO
    buf = ''
    err = 0
    for sdf in sdf_iter(StringIO(str(sdfs))):
        try:
            buf += sdf_to_smiles(sdf)
        except InputError:
            err += 1
    return (buf, err)
示例#3
0
def format_sdf_for_qsar(sdffile, output, ID_tag):
    """Cerius2 uses 1st line in SDF as ID tag
....   some sdf has blank 1st line, so we need to format SDF
....   by filling cid to 1st line in SDF"""

    fp = file(output, 'w')
    for sdf in sdfiterator.sdf_iter(sdffile):
        tagdict = get_sdf_tags(sdf)
        cid = tagdict[ID_tag]

        fp.write('%s\n' % cid)
        fp.write(sdf.split('\n', 1)[1].split('M  END')[0])
        fp.write('M  END\n')
        fp.write('''> <%s>
%s

''' % (ID_tag, cid))
        fp.write('$$$$\n')

    fp.close()
    return