def __init__(self, s=None, ps=None):
     if isinstance(s, basestring):
         self.sequence = Seq(s)
     else:
         self.sequence = s
     self.prosite = ExPASy.get_prosite_raw(ps)
     self.record = Prosite.read(self.prosite)
     self.pat = pa.compile(self.record.pattern)
     self.regexp = re.compile(pa.prosite_to_re(self.record.pattern))
Example #2
0
                      "C", "B", "CQ"), ("Q", "QQ", "QAQ", "QC", "AQ", "QCQ")),
    ("[<ABC>].", ("", "A", "AQ", "QA", "QAQ"), ()),

    # Some ranges
    ("A(3).", ("AAA", "AAAB", "AAAAA", "BAAA"), ("AA", "AABA", "BBB", "")),
    ("x(3).", ("AAA", "BBB", "ABC"), ("AA", "B", "")),
    ("A(3)-B(3).", ("AAABBB", "BBBAAABBB"), ("ABABABAB", "AABBB")),
    ("A(2,3)-B(1,3).", ("AABB", "AAB", "AABBB", "AAAB"), ("ABBB", "QQQQQ")),
    ("A-x(1,5)-B.", ("ABB", "ABBBBBB", "ACCCCCB", "ACB"), ("ACCCCCCB", "AB")),
    ("[AB](3,4).", ("AAA", "AAAA", "ABAB", "BABA", "BBAB"), ("ABC", "CBA",
                                                             "QQQQ")),
    ("{AB}(3,5)-A(2).", ("CCCAA", "QCQAQCQAAQ"), ("ABAAA", )),
)

for pattern, good_list, bad_list in unchanged_patterns:
    p = Pattern.Prosite(pattern=pattern)
    print "Patterns:", repr(pattern), repr(p.re.pattern), \
          repr(p.grouped_re.pattern)
    assert p.tostring() == pattern, (p.tostring(), pattern)
    for x in good_list:
        if p.re.search(x) is None:
            print "\t", "should be good re, but failed:", repr(x)
    for x in bad_list:
        if p.re.search(x) is not None:
            print "\t", "should be bad re, but succeeded:", repr(x)
    for x in good_list:
        m = p.search(Seq.Seq(x))
        if m is None:
            print "\t", "should be good group re, but failed:", repr(x)
        else:
            #print "x=", repr(x)
Example #3
0
    "{[A-B]}.",
    "[{AB}].",
    "(A).",
    "[A>]-B.",
    "A-[<B].",
    "A(3,).",
    "A(-1).",
    #"A(5,2).",  # too complicated to check via re
    "A(2, 5).",
    "A(B,C).",
    "A-[<G].",
    "[G>]-A.",
    "1.",
    "[1].",
    "[A1B].",
    #"[AA].",   # too complicated to check via re
    "{1}.",
    "[<].",
    "[>].",
    "[A<B].",
    "[A>B].",
    )
for pat in bad_patterns:
    print pat, "-",
    try:
        Pattern.compile(pat)
    except TypeError:
        print "correctly failed"
    else:
        print "INCORRECTLY PASSED"