Back to index

python-biopython  1.60
Functions | Variables
test_GenBank Namespace Reference

Functions

def do_comparison
def t_write_format
def t_cleaning_features
def t_ensembl_locus

Variables

tuple gb_file_dir = os.path.join(os.getcwd(), 'GenBank')
list test_files
list write_format_files
list files_to_parse = []
tuple feature_parser = GenBank.FeatureParser(debug_level = 0)
tuple record_parser = GenBank.RecordParser(debug_level = 0)
list all_parsers = [feature_parser, record_parser]
tuple handle = open(filename, 'r')
tuple iterator = GenBank.Iterator(handle, parser)
tuple cur_record = iterator.next()
tuple ann_keys = cur_record.annotations.keys()

Function Documentation

def test_GenBank.do_comparison (   good_record,
  test_record 
)
Compare two records to see if they are the same.

Ths compares the two GenBank record, and will raise an AssertionError
if two lines do not match, showing the non-matching lines.

Definition at line 110 of file test_GenBank.py.

00110 
00111 def do_comparison(good_record, test_record):
00112     """Compare two records to see if they are the same.
00113 
00114     Ths compares the two GenBank record, and will raise an AssertionError
00115     if two lines do not match, showing the non-matching lines.
00116     """
00117     good_handle = cStringIO.StringIO(good_record)
00118     test_handle = cStringIO.StringIO(test_record)
00119 
00120     while 1:
00121         good_line = good_handle.readline()
00122         test_line = test_handle.readline()
00123 
00124         if not(good_line) and not(test_line):
00125             break
00126         if not(good_line):
00127             raise AssertionError("Extra info in Test: `%s`" % test_line)
00128         if not(test_line):
00129             raise AssertionError("Extra info in Expected: `%s`" % good_line)
00130         test_normalized = ' '.join([x for x in test_line.split() if x])
00131         good_normalized = ' '.join([x for x in good_line.split() if x])
00132         assert test_normalized == good_normalized, \
00133                "Expected does not match Test.\nExpect:`%s`\nTest  :`%s`\n" % \
00134                (good_line, test_line)
    

Here is the caller graph for this function:

Test the ability to clean up feature values.

Definition at line 163 of file test_GenBank.py.

00163 
00164 def t_cleaning_features():
00165     """Test the ability to clean up feature values.
00166     """
00167     parser = GenBank.FeatureParser(feature_cleaner = \
00168                                    utils.FeatureValueCleaner())
00169     handle = open(os.path.join("GenBank", "arab1.gb"))
00170     iterator = GenBank.Iterator(handle, parser)
00171 
00172     first_record = iterator.next()
00173     
00174     # test for cleaning of translation
00175     translation_feature = first_record.features[1]
00176     test_trans = translation_feature.qualifiers["translation"][0]
00177     assert test_trans.find(" ") == -1, \
00178       "Did not clean spaces out of the translation"
00179     assert test_trans.find("\012") == -1, \
00180       "Did not clean newlines out of the translation"
00181 
00182     handle.close()

Here is the call graph for this function:

Definition at line 186 of file test_GenBank.py.

00186 
00187 def t_ensembl_locus():
00188     line = "LOCUS       HG531_PATCH 1000000 bp DNA HTG 18-JUN-2011\n"
00189     s = GenBank.Scanner.GenBankScanner()
00190     c = GenBank._FeatureConsumer(True)
00191     s._feed_first_line(c, line)
00192     assert c.data.name == "HG531_PATCH", c.data.name
00193     assert c._expected_size == 1000000, c._expected_size
00194 
00195     line = "LOCUS       HG531_PATCH 759984 bp DNA HTG 18-JUN-2011\n"
00196     s = GenBank.Scanner.GenBankScanner()
00197     c = GenBank._FeatureConsumer(True)
00198     s._feed_first_line(c, line)
00199     assert c.data.name == "HG531_PATCH", c.data.name
00200     assert c._expected_size == 759984, c._expected_size
00201 
00202     line = "LOCUS       HG506_HG1000_1_PATCH 814959 bp DNA HTG 18-JUN-2011\n"
00203     s = GenBank.Scanner.GenBankScanner()
00204     c = GenBank._FeatureConsumer(True)
00205     s._feed_first_line(c, line)
00206     assert c.data.name == "HG506_HG1000_1_PATCH", c.data.name
00207     assert c._expected_size == 814959, c._expected_size
00208 
00209     line = "LOCUS       HG506_HG1000_1_PATCH 1219964 bp DNA HTG 18-JUN-2011\n"
00210     s = GenBank.Scanner.GenBankScanner()
00211     c = GenBank._FeatureConsumer(True)
00212     s._feed_first_line(c, line)
00213     assert c.data.name == "HG506_HG1000_1_PATCH", c.data.name
00214     assert c._expected_size == 1219964, c._expected_size
00215 
    print "Done"

Definition at line 135 of file test_GenBank.py.

00135 
00136 def t_write_format():
00137     record_parser = GenBank.RecordParser(debug_level = 0)
00138 
00139     for file in write_format_files:
00140         print "Testing GenBank writing for %s..." % os.path.basename(file)
00141         cur_handle = open(os.path.join("GenBank", file), "r")
00142         compare_handle = open(os.path.join("GenBank", file), "r")
00143         
00144         iterator = GenBank.Iterator(cur_handle, record_parser)
00145         compare_iterator = GenBank.Iterator(compare_handle)
00146         
00147         while 1:
00148             cur_record = iterator.next()
00149             compare_record = compare_iterator.next()
00150             
00151             if cur_record is None or compare_record is None:
00152                 break
00153 
00154             print "\tTesting for %s" % cur_record.version
00155 
00156             output_record = str(cur_record) + "\n"
00157             do_comparison(compare_record, output_record)
00158 
00159         cur_handle.close()
00160         compare_handle.close()
00161 
00162 t_write_format()

Here is the call graph for this function:


Variable Documentation

Definition at line 44 of file test_GenBank.py.

tuple test_GenBank.ann_keys = cur_record.annotations.keys()

Definition at line 69 of file test_GenBank.py.

tuple test_GenBank.cur_record = iterator.next()

Definition at line 56 of file test_GenBank.py.

tuple test_GenBank.feature_parser = GenBank.FeatureParser(debug_level = 0)

Definition at line 41 of file test_GenBank.py.

Definition at line 28 of file test_GenBank.py.

tuple test_GenBank.gb_file_dir = os.path.join(os.getcwd(), 'GenBank')

Definition at line 12 of file test_GenBank.py.

tuple test_GenBank.handle = open(filename, 'r')

Definition at line 52 of file test_GenBank.py.

tuple test_GenBank.iterator = GenBank.Iterator(handle, parser)

Definition at line 53 of file test_GenBank.py.

tuple test_GenBank.record_parser = GenBank.RecordParser(debug_level = 0)

Definition at line 42 of file test_GenBank.py.

Initial value:
00001 ['noref.gb', 'cor6_6.gb', 'iro.gb', 'pri1.gb', 'arab1.gb',
00002               'protein_refseq.gb', 'extra_keywords.gb', 'one_of.gb',
00003               'NT_019265.gb', 'origin_line.gb', 'blank_seq.gb',
00004               'dbsource_wrap.gb', 'gbvrl1_start.seq', 'NC_005816.gb']

Definition at line 14 of file test_GenBank.py.

Initial value:
00001 ['noref.gb', 'cor6_6.gb', 'iro.gb', 'pri1.gb', 'arab1.gb',
00002                       'extra_keywords.gb', 'one_of.gb', 'origin_line.gb']

Definition at line 20 of file test_GenBank.py.