Trees | Indices | Help |
---|
|
1 import os, string 2 import Martel 3 from Martel import RecordReader 4 from cStringIO import StringIO 57 count = 0 8 while 1: 9 record = reader.next() 10 if record is None: 11 if check_remainder: 12 infile, text = reader.remainder() 13 if text: 14 raise AssertionError, text 15 line = infile.readline() 16 if line: 17 raise AssertionError, repr(line) 18 return count 19 #print repr(record) 20 #print string.split(record, "\n")[0] 21 count = count + 12224 s = """\ 25 >seq1 26 SEQUENCE 27 28 >seq2 29 MULTI 30 LINE 31 SEQUENCE 32 33 >seq3 34 35 >seq4 36 37 """ 38 reader = RecordReader.StartsWith(StringIO(s), ">") 39 assert test_count(reader) == 4 40 41 reader = RecordReader.StartsWith(StringIO(""), ">") 42 assert test_count(reader) == 0 43 44 reader = RecordReader.StartsWith(StringIO(">seq\n"), ">") 45 assert test_count(reader) == 146 47 sp_sample = os.path.join("samples", "sample.swissprot") 48 5254 lookahead = open(sp_sample).read() 55 reader = RecordReader.StartsWith(StringIO(""), "ID", lookahead = lookahead) 56 assert test_count(reader) == 857 6163 lookahead = open(sp_sample).read() 64 reader = RecordReader.EndsWith(StringIO(""), "//\n", lookahead = lookahead) 65 assert test_count(reader) == 866 6769 s = "a\nID\nb\nID\n" 70 reader = RecordReader.Until(StringIO(s), "ID") 71 assert test_count(reader, check_remainder = 0) == 1 72 assert reader.remainder()[1]7375 lookahead = "a\nID\nb\nID\n" 76 reader = RecordReader.Until(StringIO(""), "ID", lookahead = lookahead) 77 assert test_count(reader, check_remainder = 0) == 1 78 assert reader.remainder()[1]7981 s = "1\n2\n3\n4\n5\n6\n7\n8\n" 82 reader = RecordReader.CountLines(StringIO(s), 2) 83 assert test_count(reader) == 48486 lookahead = "1\n2\n3\n4\n5\n6\n7\n8\n" 87 reader = RecordReader.CountLines(StringIO(""), 2, lookahead = lookahead) 88 assert test_count(reader) == 48991 s = "1\n2\n3\n4\n5\n6\n7\n8\n" 92 infile = StringIO(s) 93 reader = RecordReader.Nothing(infile) 94 assert test_count(reader, check_remainder = 0) == 0 95 assert infile.readline() == "1\n"9698 lookahead = "1\n2\n3\n4\n5\n6\n7\n8\n" 99 reader = RecordReader.Nothing(StringIO(""), lookahead = lookahead) 100 assert test_count(reader, check_remainder = 0) == 0 101 file, result = reader.remainder() 102 assert result == lookahead, (result, lookahead)103 104106 s = "1\n2\n3\n4\n5\n6\n7\n8\n" 107 infile = StringIO(s) 108 reader = RecordReader.Everything(infile) 109 assert test_count(reader) == 1 110 assert not infile.readline()111113 lookahead = "1\n2\n3\n4\n5\n6\n7\n8\n" 114 reader = RecordReader.Everything(StringIO(""), lookahead = lookahead) 115 assert test_count(reader) == 1116118 test_start() 119 test_start_lines() 120 test_end() 121 test_end_lines() 122 test_until() 123 test_until_lines() 124 test_count_lines() 125 test_count_lines_lines() 126 test_nothing() 127 test_nothing_lines() 128 test_everything() 129 test_everything_lines() 130 131 test_fasta()132 133 134 if __name__ == "__main__": 135 test() 136 print "All tests passed." 137
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Feb 7 11:51:55 2008 | http://epydoc.sourceforge.net |