def delimiter(delim): assert len(delim) == 1, \ "delimiter can only be a single character long, not %s" % repr(delim) assert delim not in "\n\r", "Cannot use %s as a delimiter" % repr(delim) field = Martel.Group("field", Martel.Rep(Martel.AnyBut(delim + "\r\n"))) line = field + Martel.Rep(Martel.Str(delim) + field) + Martel.AnyEol() record = Martel.Group("record", line) format = Martel.ParseRecords("delimited", {}, record, RecordReader.CountLines, (1, )) return format
def test_reader_parser(): record = Martel.Group("start", Martel.Rep(Martel.Str("abc"))) + \ Martel.Group("end", Martel.Rep(Martel.Str("xyz"))) parser = record.make_parser() parser = Parser.Parser(parser.tagtable) parser.setErrorHandler(handler.ErrorHandler()) parser.parseString("abc" * 10 + "xyz") try: parser.parseString("abc" * 10 + "xyzQ") except Parser.ParserPositionException: pass else: raise AssertionError, "didn't get a position exception" try: parser.parseString("abc" * 10 + "x") except Parser.ParserPositionException: pass else: raise AssertionError, "didn't get a position exception"
def test_record_parser(): record = Martel.Group("A", Martel.Str("X\n") + Martel.Re("a*\n")) p = record.make_parser() parser = Parser.RecordParser("blah", {}, p.tagtable, (0, 1, {}), RecordReader.StartsWith, ("X", )) err = CountErrors() parser.setErrorHandler(err) count = CountRecords("A") parser.setContentHandler(count) parser.parseString("X\na\nX\nb\nX\naaa\nX\naaaa\nX\nq\nX\na\n") assert err.fatal_error_count == 0, err.fatal_error_count assert err.error_count == 2, err.error_count assert count.count == 4, count.count
"""Martel definitions for the output files produced by primer3. """ import Martel any_space = Martel.Re("[ ]+") blank_line = Martel.AnyEol() comment_line = Martel.Str("#") + Martel.ToEol() # comments and blank lines in the file comments = Martel.Group("comments", blank_line + comment_line + blank_line + comment_line) # 1 PRODUCT SIZE: 289 product_size = Martel.Group("product_size", Martel.Re("[\d]+")) start_primer = Martel.Group( "start_primer", any_space + Martel.Re("[\d]+") + Martel.Str(" PRODUCT SIZE: ")) primer_start_line = Martel.Group("primer_start_line", start_primer + product_size + Martel.AnyEol()) # a blank line that signifies a new primer is coming up single_primer_line = Martel.Group("single_primer_line", blank_line) # FORWARD PRIMER 1725 20 59.96 55.00 AGGGAAGGGATGCTAGGTGT primer_space = Martel.Str(" " * 5) any_integer = Martel.Re("[\d]+") any_float = Martel.Re("[\d\.]+") sequence = Martel.Re("[GATCN]+")
def Simple(tag, tag_data): return Martel.Group( tag, Martel.Str(tag + " ") + Martel.Group(tag_data, Martel.Re("[^\R]*")) + Martel.AnyEol())
DR_general = Martel.Re("(?P<database_identifier>[^;]+);" \ "(?P<primary_identifier>[^;]+); " \ "(?P<secondary_identifier>([^.\R]|(?!.\R)\.)+)") DR_prosite = Martel.Re("(?P<database_identifier>(PROSITE|PFAM)); " \ "(?P<primary_identifier>[^;]+); " \ "(?P<secondary_identifier>[^;]+); " \ "(?P<status_identifier>[^.]+)") DR_embl = Martel.Re("(?P<database_identifier>EMBL); " \ "(?P<primary_identifier>[^;]+); " \ "(?P<secondary_identifier>[^;]+); " \ "(?P<status_identifier>[^.]+)") DR = Martel.Group("DR", Martel.Str("DR ") + \ Martel.Group("database_reference", Martel.Alt(DR_embl, DR_prosite, DR_general)) + \ Martel.Str(".") + Martel.AnyEol()) DR_block = Martel.Group("DR_block", Martel.Rep1(DR)) #--- KW KW = Simple("KW", "keyword") KW_block = Martel.Group("KW_block", Martel.Rep1(KW)) #--- FT # FT DOMAIN 77 88 ASP/GLU-RICH (ACIDIC). # 123456789012345678901234567890123456789012345678901234567890123456789012345
# Copyright 2001 by Katharine Lindner. All rights reserved. # This code is part of the Biopython distribution and governed by its # license. Please see the LICENSE file that should have been included # as part of this package. """Martel regular expression for Intelligenetic format (DEPRECATED). This is a huge regular regular expression for the IntelliGenetics/MASE format, built using the 'regular expressions on steroids' capabilities of Martel. """ #http://immuno.bme.nwu.edu/seqhunt.html # Martel import Martel # --- first set up some helper constants and functions comment_line = Martel.Group( "comment_line", \ Martel.Str( ';' ) + Martel.ToEol( "comment" ) ) comment_lines = Martel.Group("comment_lines", Martel.Rep(comment_line)) title_line = Martel.Group( "title_line", \ Martel.Expression.Assert( Martel.Str( ';' ), 1 ) + Martel.ToEol() ) residue_line = Martel.Group( "residue_line", \ Martel.Expression.Assert( Martel.Str( ';' ), 1 ) + Martel.ToEol( "sequence" ) ) residue_lines = Martel.Group("residue_lines", Martel.Rep1(residue_line)) intelligenetics_record = comment_lines + title_line + residue_lines
def test_single(): ele = get_element( Martel.Group("spam", Martel.Str("X"), {"format": "swissprot"})) check_element(ele, ("spam", {"format": "swissprot"}))
def test_none(): ele = get_element(Martel.Group("spam", Martel.Str("X"))) check_element(ele, ("spam", {})) ele = get_element(Martel.Group("spam", Martel.Str("X"), {})) check_element(ele, ("spam", {}))
"""Example of registering a database with the Biopython-specific system. """ from Bio.sources import CGI local_cgi = CGI(name = "local_cgi", delay = 0.0, cgi = "http://www.myserver.org/cgi-bin/my_local.cgi", url = "http://www.myserver.org/cgi_documentation.html", doc = "Query a local databases", failure_cases = []) import Martel my_failures = [ (Martel.Str("Sequence not available"), "No sequence found")] from Bio import register_db register_db(name = "nucleotide-genbank-local", key = "uid", source = local_cgi, failure = my_failures) register_db(name = "genbank", behavior = "concurrent") from Bio import group_db group_db("genbank", "nucleotide-genbank-local") group_db("genbank", "nucleotide-genbank-cgi") from Bio import db print db.keys()
"""Martel format for primersearch output files, """ import Martel blank_line = Martel.AnyEol() # Primer name D1S2660 primer_name = Martel.Group("primer_name", Martel.ToEol()) primer_name_line = Martel.Str("Primer name ") + primer_name # Amplimer 1 amplifier = Martel.Group("amplifier", Martel.Re("[\d]+")) amplimer_line = Martel.Str("Amplimer ") + amplifier + Martel.AnyEol() # Sequence: AC074298 AC074298 # Telomere associated sequence for Arabidopsis thaliana TEL1N # CCGGTTTCTCTGGTTGAAAA hits forward strand at 114 with 0 mismatches # TCACATTCCCAAATGTAGATCG hits reverse strand at [114] with 0 mismatches seq_indent = Martel.Str("\t") sequence_id = Martel.Group("sequence_id", Martel.ToEol()) sequence_descr = Martel.Group("sequence_descr", Martel.ToEol()) sequence_info = sequence_id + sequence_descr forward_strand_info = Martel.Group("forward_strand_info", Martel.ToEol()) reverse_strand_info = Martel.Group("reverse_strand_info", Martel.ToEol()) amplifier_sequence = Martel.Group( "amplifier_sequence", sequence_info + forward_strand_info + reverse_strand_info) amplifier_sequence_lines = seq_indent + Martel.Str("Sequence: ") + \ amplifier_sequence