Esempio n. 1
0
def main():
    with lt.open_file() as write_f:
        for f in lt.files_in_dir(sys.argv[-1]):
            pdb_id = os.path.split(f)[1].split('.')[0]
            ligands = check_ligands(f)
            if len(ligands) > 0:
                print >> write_f, pdb_id, '\t', ' '.join(ligands)
Esempio n. 2
0
def main():
    hbs = []
    for hb2_f in lt.files_in_dir(sys.argv[-1]):
        if hb2_f[-4:] == '.hb2':
            hbs.extend(read_hb2(hb2_f))

    write_initial(hbs)
    hbs = [(pro, phos_res, neighbor_res)
           for pro, phos_res, neighbor_res, _ in hbs]

    lt.pickle_dump(hbs, 'hbplus')
Esempio n. 3
0
def main():
    null = open(os.devnull, 'w')
    # sys.stderr = null
    """
    """

    res_neighbors = []
    for pdb_f in lt.files_in_dir(sys.argv[-1]):
        f_path, f_name = os.path.split(pdb_f)
        f_name, f_exten = os.path.splitext(f_name)
        if f_exten == '.pdb':
            pdb_id = f_name
            res_neighbors.extend(pdb_neighbors(pdb_f, pdb_id))

    write_result(res_neighbors, file_suffix='original')

    sta = [len(v) for k, v in res_neighbors.iteritems()]
    sta = lt.lis_sta(sta)
    with lt.open_file('phos_neighbors_num') as w_f:
        for k, v in sta.items():
            print >> '{0:<10}{1:<10}'.format(k, v)
Esempio n. 4
0
def main():
    null = open(os.devnull, 'w')
    sys.stderr = null

    dist = []
    for pdb_f in lt.files_in_dir(sys.argv[-1]):
        pdb_id = pdb_f[-8:-4]
        p_dist = pdb_dist(pdb_f, pdb_id)
        dist += p_dist

    def myround(n):
        n = np.round(n, 1)
        a, b = str(n).split('.')
        n = a + '.' + b[0]
        return float(n)

    dist = sorted(dist)
    dist = [myround(d) for d in dist]
    dist = [d for d in dist if d < 10.0]

    sta = lt.lis_sta(dist)
    with lt.open_file(file_suffix='dist_sta') as w_f:
        for num, freq in sta:
            print >> w_f, '{0:<10}{1}'.format(num, freq)
def read_pickle():
    for f in lt.files_in_dir(sys.argv[-1]):
        if 'hbplus' in f:
            hbplus_neighbors = lt.pickle_load(f)
        if 'salt' in f:
            salt_neighbors = lt.pickle_load(f)

    hbplus_neighbors_dic = OrderedDict()
    for pdb_id, res, neighbors in hbplus_neighbors:
        hbplus_neighbors_dic[(pdb_id, res)] = neighbors
    salt_neighbors_dic = {}
    for pdb_id, res, neighbors in salt_neighbors:
        salt_neighbors_dic[(pdb_id, res)] = neighbors

    combine_neighbors = []
    for k, v in hbplus_neighbors_dic.iteritems():
        if k in salt_neighbors_dic.keys():
            v.extend(salt_neighbors_dic[k])
            v = set(v)
            combine_neighbors.append((k[0], k[1], v))
        else:
            combine_neighbors.append((k[0], k[1], v))

    return combine_neighbors
Esempio n. 6
0
def main():
    null = open(os.devnull, 'w')
    # sys.stderr = null
    """
    write original center:neighbors
    write pdb_ids
    write neighbors:pdbs
    """
    def write_result(res_neighbors, file_suffix):
        pdbs = list(set([pdb_id for pdb_id, _, _ in res_neighbors]))
        with lt.open_file(file_name='pdb_id',
                          inner_dir=file_suffix,
                          file_suffix=file_suffix) as w_f:
            print >> w_f, 'num:', '\t', len(pdbs)
            for pdb in pdbs:
                print >> w_f, pdb

        res_neighbors = sorted(res_neighbors)
        with lt.open_file(file_name='res_neighbors',
                          inner_dir=file_suffix,
                          file_suffix=file_suffix) as w_f:
            for pdb_id, res, neighbors in res_neighbors:
                print >> w_f, '{0:<20}{1:<20}{2}'.format(
                    pdb_id, res, '  '.join(neighbors))

        HASH = {
            'VAL': 'V',
            'ILE': 'I',
            'LEU': 'L',
            'GLU': 'E',
            'GLN': 'Q',
            'ASP': 'D',
            'ASN': 'N',
            'HIS': 'H',
            'TRP': 'W',
            'PHE': 'F',
            'TYR': 'Y',
            'ARG': 'R',
            'LYS': 'K',
            'SER': 'S',
            'THR': 'T',
            'MET': 'M',
            'ALA': 'A',
            'GLY': 'G',
            'PRO': 'P',
            'CYS': 'C'
        }
        neighbor_pdbs = {}
        for pdb_id, res, neighbors in res_neighbors:
            neighbors = [n.split('_')[0] for n in neighbors]
            neighbors = [HASH[n] for n in neighbors]
            neighbors = ''.join(sorted(neighbors))
            if not neighbors in neighbor_pdbs.keys():
                neighbor_pdbs[neighbors] = [pdb_id]
            else:
                if not pdb_id in neighbor_pdbs[neighbors]:
                    neighbor_pdbs[neighbors].append(pdb_id)
        neighbor_pdbs = [(len(pdbs), neighbors, pdbs)
                         for neighbors, pdbs in neighbor_pdbs.iteritems()]
        neighbor_pdbs = sorted(neighbor_pdbs, reverse=True)
        with lt.open_file(file_name='neighbor_pdbs',
                          inner_dir=file_suffix,
                          file_suffix=file_suffix) as w_f:
            for _, neighbors, pdbs in neighbor_pdbs:
                pdbs = [pdb for pdb in pdbs]
                print >> w_f, '{0:<10}{1}'.format(neighbors, ' '.join(pdbs))

    res_neighbors = []
    for pdb_f in lt.files_in_dir(sys.argv[-1]):
        f_path, f_name = os.path.split(pdb_f)
        f_name, f_exten = os.path.splitext(f_name)
        pdb_id = f_name
        res_neighbors.extend(pdb_neighbors(pdb_f, pdb_id))

    #write original
    pdbs = set([
        pdb_id for pdb_id, _, neighbors in res_neighbors if len(neighbors) > 0
    ])
    with lt.open_file(file_suffix='original_pdbs') as w_f:
        for p in pdbs:
            print >> w_f, p
    with lt.open_file(file_suffix='orignal') as w_f:
        for pdb_id, res, neighbors in res_neighbors:
            if len(neighbors) > 0:
                print >> w_f, '{0:<20}{1:<20}{2}'.format(
                    pdb_id, res, ' '.join(neighbors))
    with lt.open_file(file_suffix='orignal_simple') as w_f:
        for pdb_id, res, neighbors in res_neighbors:
            if len(neighbors) > 0:
                HASH = {
                    'VAL': 'V',
                    'ILE': 'I',
                    'LEU': 'L',
                    'GLU': 'E',
                    'GLN': 'Q',
                    'ASP': 'D',
                    'ASN': 'N',
                    'HIS': 'H',
                    'TRP': 'W',
                    'PHE': 'F',
                    'TYR': 'Y',
                    'ARG': 'R',
                    'LYS': 'K',
                    'SER': 'S',
                    'THR': 'T',
                    'MET': 'M',
                    'ALA': 'A',
                    'GLY': 'G',
                    'PRO': 'P',
                    'CYS': 'C'
                }
                neighbors = [n.split('_')[0] for n in neighbors]
                neighbors = [HASH.get(n, '') for n in neighbors]
                neighbors = ''.join(sorted(neighbors))
                print >> w_f, '{0:<20}{1:<20}{2}'.format(
                    pdb_id, res, ''.join(neighbors))
    # res_neighbors format: [(pdb_id,residue,[neighbor_resiudes])]

    # delete non-standard residues
    STAND_RES = [
        'VAL', 'ILE', 'LEU', 'GLU', 'GLN', 'ASP', 'ASN', 'HIS', 'TRP', 'PHE',
        'TYR', 'ARG', 'LYS', 'SER', 'THR', 'MET', 'ALA', 'GLY', 'PRO', 'CYS'
    ]

    res_neighbors = [(pdb_id, res,
                      [n for n in neighbors if n.split('_')[0] in STAND_RES])
                     for pdb_id, res, neighbors in res_neighbors]
    res_neighbors = [(pdb_id, res, neighbors)
                     for pdb_id, res, neighbors in res_neighbors
                     if len(neighbors) > 0]
    # bad_pdbs = set([pdb_id for pdb_id,res,neighbors in res_neighbors for n in neighbors if not n.split('_')[0] in STAND_RES])
    # res_neighbors = [(pdb_id,res,neighbors) for pdb_id,res,neighbors in res_neighbors if not pdb_id in bad_pdbs]
    write_result(res_neighbors, file_suffix='filter_non_standard')

    # # delete water
    # res_neighbors = [(pdb_id, res, [n for n in neighbors if n.split(
    # '_')[-1] != 'HOH']) for pdb_id, res, neighbors in res_neighbors]
    # res_neighbors = [(pdb_id, res, neighbors) for pdb_id,
    # res, neighbors in res_neighbors if len(neighbors) > 0]
    # write_result(res_neighbors, file_suffix='delete_water')

    # delete same_chain
    res_neighbors = [
        (pdb_id, res,
         [n for n in neighbors if n.split('_')[-1] != res.split('_')[-1]])
        for pdb_id, res, neighbors in res_neighbors
    ]
    res_neighbors = [(pdb_id, res, neighbors)
                     for pdb_id, res, neighbors in res_neighbors
                     if len(neighbors) > 0]
    write_result(res_neighbors, file_suffix='filter_same_chain')
    #delete same_chain
    # bad_pdbs = set([pdb_id for pdb_id,res,neighbors in res_neighbors for n in neighbors if n.split('_')[-1] == res.split('_')[-1]])
    # res_neighbors = [(pdb_id,res,neighbors) for pdb_id,res,neighbors in res_neighbors if not pdb_id in bad_pdbs]
    # write_result(res_neighbors, file_suffix='delete_same_chain')

    #neighbors = 1
    res_neighbors1 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) == 1]
    write_result(res_neighbors1, file_suffix='1_neighbor')
    #neighbors = 2
    res_neighbors2 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) == 2]
    write_result(res_neighbors2, file_suffix='2_neighbor')
    #neighbors = 3
    res_neighbors3 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) == 3]
    write_result(res_neighbors3, file_suffix='3_neighbor')
    #neighbors = 4
    res_neighbors4 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) == 4]
    write_result(res_neighbors4, file_suffix='4_neighbor')
    #neighbors = 5
    res_neighbors5 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) == 5]
    write_result(res_neighbors5, file_suffix='5_neighbor')
    #neighbors = 6
    res_neighbors6 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) == 6]
    write_result(res_neighbors6, file_suffix='6_neighbor')
    #neighbors > 6
    res_neighbors7 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) > 6]
    write_result(res_neighbors7, file_suffix='7_neighbor')

    num1 = len(set([pdb_id for pdb_id, _, _ in res_neighbors1]))
    num2 = len(set([pdb_id for pdb_id, _, _ in res_neighbors2]))
    num3 = len(set([pdb_id for pdb_id, _, _ in res_neighbors3]))
    num4 = len(set([pdb_id for pdb_id, _, _ in res_neighbors4]))
    num5 = len(set([pdb_id for pdb_id, _, _ in res_neighbors5]))
    num6 = len(set([pdb_id for pdb_id, _, _ in res_neighbors6]))
    num7 = len(set([pdb_id for pdb_id, _, _ in res_neighbors7]))

    sta = [num1, num2, num3, num4, num5, num6, num7]
    with lt.open_file(file_suffix='sta') as w_f:
        print >> w_f, '{0:<20}{1}'.format('neighbors num', 'pdb_num')
        for i, num in enumerate(sta):
            print >> w_f, '{0:<20}{1}'.format(i + 1, num)
        print >> w_f, '{0:<20}{1}'.format('total', sum(sta))
Esempio n. 7
0
def main():
    phos_neighbors = {}
    good_pdb = []
    bad_pdb = []
    for pdb_f in lt.files_in_dir(sys.argv[-1]):
        f_path, f_name = os.path.split(pdb_f)
        f_id, f_ex = os.path.splitext(f_name)
        neighbors = pdb_neighbors(pdb_f, f_id)
        print neighbors
        if len(neighbors) > 0:
            for k, v in neighbors.iteritems():
                if len(v) > 0:
                    phos_neighbors[f_id] = neighbors
                    good_pdb.append(f_id)
                else:
                    bad_pdb.append(f_id)

    lt.write_list(good_pdb, 'good_pdb')
    lt.write_list(bad_pdb, 'bad_pdb')
    # delete res_id and clear empty
    phos_neighbors_v1 = {}
    for k, v in phos_neighbors.iteritems():
        phos_neighbors_v1[k] = {}
        for vk, vv in v.iteritems():
            phos_neighbors_v1[k][vk] = []
            vvn = []
            if len(vv) > 0:
                for vi in vv:
                    vvn.append(vi.split('_')[0])
                vvn = sorted(vvn)
                phos_neighbors_v1[k][vk] = vvn

    # delete non-standard residues
    stand_res = [
        'VAL', 'ILE', 'LEU', 'GLU', 'GLN', 'ASP', 'ASN', 'HIS', 'TRP', 'PHE',
        'TYR', 'ARG', 'LYS', 'SER', 'THR', 'MET', 'ALA', 'GLY', 'PRO', 'CYS'
    ]
    phos_neighbors_v2 = {}
    for k, v in phos_neighbors_v1.iteritems():
        phos_neighbors_v2[k] = {}
        for vk, vv in v.iteritems():
            vvn = []
            for vi in vv:
                if vi in stand_res:
                    vvn.append(vi)
            if len(vvn) > 0:
                vvn = sorted(vvn)
                phos_neighbors_v2[k][vk] = vvn

    # delete uncomplete patterns
    phos_neighbors_v3 = {}
    for k, v in phos_neighbors_v2.iteritems():
        phos_neighbors_v3[k] = {}
        for vk, vv in v.iteritems():
            if len(vv) >= 3:
                phos_neighbors_v3[k][vk] = vv

    def write_phosneighbors(phos_neighbors, ofile):
        keys = phos_neighbors.keys()
        keys = sorted(keys)
        for k in keys:
            print >> ofile, k

        print >> ofile, '*' * 80
        for k in keys:
            v = phos_neighbors[k]
            print >> ofile, k
            for vk, vv in v.iteritems():
                print >> ofile, '    ', vk, '\t', ' '.join(vv)

        print >> ofile, '*' * 80
        phos_sta = {}
        for k, v in phos_neighbors.iteritems():
            for vk, vv in v.iteritems():
                if not tuple(vv) in phos_sta.keys():
                    phos_sta[tuple(vv)] = [k]
                else:
                    phos_sta[tuple(vv)].append(k)
        phos_sta_list = []
        for k, v in phos_sta.iteritems():
            phos_sta_list.append((len(v), k, v))
        phos_sta_list = sorted(phos_sta_list, reverse=True)
        for len_v, k, v in phos_sta_list:
            print >> ofile, '{0:150}{1:<8}{2}'.format(k, len_v, ','.join(v))

    ofile = lt.open_file('phos_neighbors_original')
    write_phosneighbors(phos_neighbors, ofile)
    ofile = lt.open_file('phos_neighbors_sorted')
    write_phosneighbors(phos_neighbors_v1, ofile)
    ofile = lt.open_file('phos_neighbors_clear')
    write_phosneighbors(phos_neighbors_v2, ofile)
    ofile = lt.open_file('phos_neighbors_clean')
    write_phosneighbors(phos_neighbors_v3, ofile)
Esempio n. 8
0
import os
import sys
import subprocess
import lt
for f in lt.files_in_dir(sys.argv[-1]):
    subprocess.call('~/hbplus/hbplus/hbplus', f, "-f 'SEP.txt'")
Esempio n. 9
0
def main():
    null = open(os.devnull, 'w')
    # sys.stderr = null
    """
    write original center:neighbors
    write pdb_ids
    write neighbors:pdbs
    """

    res_neighbors = []
    for pdb_f in lt.files_in_dir(sys.argv[-1]):
        f_path, f_name = os.path.split(pdb_f)
        f_name, f_exten = os.path.splitext(f_name)
        if f_exten == '.pdb':
            pdb_id = f_name
            res_neighbors.extend(pdb_neighbors(pdb_f, pdb_id))

    write_result(res_neighbors, file_suffix='original')

    #neighbors = 1
    res_neighbors1 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) == 1]
    write_result(res_neighbors1, file_suffix='1_neighbor')
    #neighbors = 2
    res_neighbors2 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) == 2]
    write_result(res_neighbors2, file_suffix='2_neighbor')
    #neighbors = 3
    res_neighbors3 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) == 3]
    write_result(res_neighbors3, file_suffix='3_neighbor')
    #neighbors = 4
    res_neighbors4 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) == 4]
    write_result(res_neighbors4, file_suffix='4_neighbor')
    #neighbors = 5
    res_neighbors5 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) == 5]
    write_result(res_neighbors5, file_suffix='5_neighbor')
    #neighbors = 6
    res_neighbors6 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) == 6]
    write_result(res_neighbors6, file_suffix='6_neighbor')
    #neighbors > 6
    res_neighbors7 = [(pdb_id, res, neighbors)
                      for pdb_id, res, neighbors in res_neighbors
                      if len(neighbors) > 6]
    write_result(res_neighbors7, file_suffix='7_neighbor')

    num1 = len(set([pdb_id for pdb_id, _, _ in res_neighbors1]))
    num2 = len(set([pdb_id for pdb_id, _, _ in res_neighbors2]))
    num3 = len(set([pdb_id for pdb_id, _, _ in res_neighbors3]))
    num4 = len(set([pdb_id for pdb_id, _, _ in res_neighbors4]))
    num5 = len(set([pdb_id for pdb_id, _, _ in res_neighbors5]))
    num6 = len(set([pdb_id for pdb_id, _, _ in res_neighbors6]))
    num7 = len(set([pdb_id for pdb_id, _, _ in res_neighbors7]))

    sta = [num1, num2, num3, num4, num5, num6, num7]
    with lt.open_file(file_suffix='sta') as w_f:
        print >> w_f, '{0:<20}{1}'.format('neighbors num', 'pdb_num')
        for i, num in enumerate(sta):
            print >> w_f, '{0:<20}{1}'.format(i + 1, num)
        print >> w_f, '{0:<20}{1}'.format('total', sum(sta))