Guest User

Untitled

a guest
Jan 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #-*- coding:utf-8 -*-
  3.  
  4. import re
  5. import sys
  6.  
  7. AMINOS = { 
  8.     "A": "GC.",
  9.     "R": "(?:CG.|AGA|AGG)",
  10.     "N": "(?:AAT|AAC)",
  11.     "D": "(?:GAT|GAC)",
  12.     "C": "(?:TGT|TGC)",
  13.     "Q": "(?:CAA|CAG)",
  14.     "E": "(?:GAG|GAA)",
  15.     "G": "GG.",
  16.     "H": "(?:CAT|CAC)",
  17.     "I": "(?:ATT|ATC|ATA)",
  18.     "L": "(?:CT.|TTA|TTG)",
  19.     "K": "(?:AAA|AAG)",
  20.     "M": "ATG",
  21.     "F": "(?:TTT|TTC)",
  22.     "P": "CC.",
  23.     "S": "(?:TC.|AGT|AGC)",
  24.     "T": "AC.",
  25.     "W": "TGG",
  26.     "Y": "(?:TAT|TAC)",
  27.     "V": "GT."
  28. }
  29.  
  30. def inverse(st):
  31.     M = {"C": "G", "G": "C", "A": "T", "T": "A"}
  32.     return "".join(M[c] for c in st)
  33.  
  34. with open(sys.argv[1]) as fp:
  35.     pattern = "".join(AMINOS.get(c, "") for c in fp.read())
  36.     regex = re.compile(pattern)
  37.  
  38. with open(sys.argv[2]) as fp:
  39.     sequence = "".join(line.strip() for line in fp)
  40.  
  41. for match in regex.finditer(sequence):
  42.     print "Match at %d to %d" % (match.start(), match.end())
  43.  
  44. sequence = inverse(sequence)
  45. for match in regex.finditer(sequence):
  46.     print "Match at inverse %d to %d" % (match.start(), match.end())
Add Comment
Please, Sign In to add comment