@@ -0,0 +1,1458 @@
+%22%22%22%0ACalculate the pairwise percent identities from protein alignments. We only consider identical sequences%0Ain the alignment%0A%22%22%22%0A%0Aimport os%0Aimport sys%0A%0Aimport argparse%0A%0A%0Adef read_fasta(filename):%0A    seq = %7B%7D%0A    seqid = None%0A    prot = ''%0A    with open(filename, 'r') as f:%0A        for l in f:%0A            if l.startswith('%3E'):%0A                if seqid:%0A                    seq%5Bseqid%5D = prot%0A                prot = ''%0A                seqid = l.strip().replace('%3E', '')%0A            else:%0A                prot += l.strip()%0A    seq%5Bseqid%5D = prot%0A    return seq%0A%0A%0Adef pairwise(seqs):%0A    allseqs = seqs.keys()%0A    allseqs.sort()%0A    for i in range(len(allseqs)):%0A        for j in range(len(allseqs)):%0A            maxp = max(len(seqs%5Ballseqs%5Bi%5D%5D), len(seqs%5Ballseqs%5Bj%5D%5D))%0A            same = 0%0A            diff = 0%0A            for p in range(maxp):%0A                if seqs%5Ballseqs%5Bi%5D%5D%5Bp%5D == '-' and seqs%5Ballseqs%5Bj%5D%5D%5Bp%5D == '-':%0A                    pass%0A                if seqs%5Ballseqs%5Bi%5D%5D%5Bp%5D == seqs%5Ballseqs%5Bj%5D%5D%5Bp%5D:%0A                    same += 1%0A                else:%0A                    diff += 1%0A            print(%22%7B%7D%5Ct%7B%7D%5Ct%7B%7D%22.format(allseqs%5Bi%5D, allseqs%5Bj%5D, (same/(same+diff))*100))%0A%0A%0A%0Aif __name__ == '__main__':%0A    parser = argparse.ArgumentParser(description=%22Calculate the percent pairwise ID between all pairs of sequences%22)%0A    parser.add_argument('-f', help='protein fasta file')%0A    args = parser.parse_args()%0A%0A    sq = read_fasta(args.f)%0A    pairwise(sq)

Calculate pairwise percent ID