def ppi(file1, mutation):
    """ PTM present at the interface of two proteins and known to play role in interaction (PTMfunc; Beltrao et al. Cell 2012)"""
    with open('ppi_mutation.txt', 'w') as out:
        with open(file1, 'rU') as f:
            for ls in f:
                line = ls.split()
                with open(mutation) as mu:
                    for m in mu:
                        m = m.split()
                        if len(line) > 7:
                            if m[0] == line[1] and m[1] == line[3]:
                                take = line[1] + '\t' + line[2] + '\t' + line[3
                                    ] + '\t' + 'PTMfunc'
                                fi = take.split()
                                with open('yeastID.txt') as i:
                                    for di in i:
                                        di = di.split()
                                        if len(di) > 2 and di[2] == fi[0]:
                                            summary = open('summary.txt', 'a+')
                                            summary.write(di[0] + '\t' + di[2] +
                                                '\t' + fi[2] + '\t' + '\t' + 'PPI' +
                                                '\t' + 'PTMfunc' + '\n')
                                            if take > str(0):
                                                with open('ppi_mutation.txt', 'a') as out:
                                                    out.write(take + '\n')
                                                    continue
                            if m[0] == line[6] and m[1] == line[3]:
                                take2 = line[6] + '\t' + line[2] + '\t' + line[
                                    3] + '\t' + 'PTMfunc'
                                fi = take2.split()
                                with open('yeastID.txt') as i:
                                    for di in i:
                                        di = di.split()
                                        if len(di) > 2 and di[2] == fi[0]:
                                            summary = open('summary.txt', 'a+')
                                            summary.write(di[0] + '\t' + di[2] +
                                                '\t' + fi[2] + '\t' + '\t' + 'PPI' +
                                                '\t' + 'PTMfunc' + '\n')
                                            if take2 > str(0):
                                                with open('ppi_mutation.txt', 'a+') as out:
                                                    out.write(take2 + '\n')
