File: tigr.pm

package info (click to toggle)
bioperl 1.6.924-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 50,776 kB
  • ctags: 11,412
  • sloc: perl: 175,865; xml: 27,565; lisp: 2,034; sh: 1,958; makefile: 19
file content (1355 lines) | stat: -rw-r--r-- 33,170 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
# BioPerl module for Bio::SeqIO::tigr
#
# Please direct questions and support issues to <bioperl-l@bioperl.org> 
#
# Cared for by Josh Lauricha (laurichj@bioinfo.ucr.edu)
#
# Copyright Josh Lauricha
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::SeqIO::tigr - TIGR XML sequence input/output stream

=head1 SYNOPSIS

Do not use this module directly.  Use it via the Bio::SeqIO class.

=head1 DESCRIPTION

This object can transform Bio::Seq objects to and from efa flat
file databases.

=head1 FEEDBACK

=head2 Mailing Lists

User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists.  Your participation is much appreciated.

  bioperl-l@bioperl.org                  - General discussion
  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists

=head2 Support 

Please direct usage questions or support issues to the mailing list:

I<bioperl-l@bioperl.org>

rather than to the module maintainer directly. Many experienced and 
reponsive experts will be able look at the problem and quickly 
address it. Please include a thorough description of the problem 
with code and data examples if at all possible.

=head2 Reporting Bugs

Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution.
Bug reports can be submitted via the web:

  https://github.com/bioperl/bioperl-live/issues

=head1 AUTHORS - Josh Lauricha

Email: laurichj@bioinfo.ucr.edu


=head1 APPENDIX

The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _

=cut

# TODO:
#  - Clean up code
#  - Find and fix bugs ;)

# Let the code begin...
package Bio::SeqIO::tigr;
use strict;

use Bio::Seq::RichSeq;
use Bio::Species;
use Bio::Annotation::Comment;
use Bio::SeqFeature::Generic;
use Bio::Seq::SeqFactory;
use Bio::Seq::RichSeq;
use Data::Dumper;
use Error qw/:try/;

use base qw(Bio::SeqIO);

sub _initialize
{
	my($self, @args) = @_;

	$self->SUPER::_initialize(@args);
	$self->sequence_factory(Bio::Seq::SeqFactory->new(
			-type => 'Bio::Seq::RichSeq')
	);

	# Parse the document
	$self->_process();
}

=head2 next_seq

 Title   : next_seq
 Usage   : $seq = $stream->next_seq()
 Function: returns the next sequence in the stream
 Returns : Bio::Seq object
 Args    : NONE

=cut

sub next_seq()
{
	my ($self) = @_;
	
	# Check for any more sequences
	return if !defined($self->{_sequences}) or scalar(@{$self->{_sequences}}) < 1;

	# get the next sequence
	my $seq = shift(@{ $self->{_sequences} } );

	# Get the 5' and 3' ends
	my ($source) = grep { $_->primary_tag() eq 'source' } $seq->get_SeqFeatures();
	my ($end5) = $source->get_tag_values('end5');
	my ($end3) = $source->get_tag_values('end3');

	# Sort the 5' and 3':
	my ($start, $end) = ( $end5 < $end3  ? ( $end5, $end3 ) : ( $end3, $end5 ) );

	# make the start a perl index
	$start -= 1;

	# Figure out the length
	my $length = $end - $start;

	# check to make sure $start >= 0 and $end <= length(assembly_seq)
    if($start < 0) {
        throw Bio::Root::OutOfRange("the sequence start is $start < 0");
    } elsif($end > length($self->{_assembly}->{seq})) {
        throw Bio::Root::OutOfRange("the sequence end is $end < " . length($self->{_assembly}->{seq}));
    } elsif($start >= $end) {
        throw Bio::Root::OutOfRange("the sequence start is after end $start >= $end");
    }

	# Get and set the real sequence
	$seq->seq(substr($self->{_assembly}->{seq}, $start, $length));

	if( $end5 > $end3 ) {
		# Reverse complement the sequence
		$seq->seq( $seq->primary_seq()->revcom()->seq() );
	}

	# add the translation to each CDS
	foreach my $feat ($seq->get_SeqFeatures()) {
		next if $feat->primary_tag() ne "CDS";

		# Check for an invalid protein
		try {
			# Get the subsq
			my $cds = Bio::PrimarySeq->new(
				-strand => 1,
				-id  => $seq->accession_number(),
				-seq => $seq->subseq($feat->location())
			);

			# Translate it
			my $trans = $cds->translate(undef, undef, undef, undef, 1, 1)->seq();

			# Add the tag
			$feat->add_tag_value(translation => $trans);
		} catch Bio::Root::Exception with {
			print STDERR 'TIGR strikes again, the CDS is not a valid protein: ', $seq->accession_number(), "\n"
				if $self->verbose() > 0;
		};
	}

	# Set the display id to the accession number if there
	# is no display id
	$seq->display_id( $seq->accession_number() ) unless $seq->display_id();
	
	return $seq;
}

sub _process
{
	my($self) = @_;
	my $line;
	my $tu = undef;

	$line = $self->_readline();
	do {
		if($line =~ /<\?xml\s+version\s+=\s+"\d+\.\d+"\?>/o) {
			# do nothing
		} elsif ($line =~ /<!DOCTYPE (\w+) SYSTEM "[\w\.]+">/o) {
			$self->throw("DOCTYPE of $1, not TIGR!")
				if $1 ne "TIGR" ;
		} elsif ($line =~ /<TIGR>/o) {
			$self->_pushback($line);
			$self->_process_tigr();
		} elsif ($line =~ /<ASSEMBLY.*?>/o) {
			$self->_pushback($line);
			$self->_process_assembly();
		} elsif ($line =~ /<\/TIGR>/o) {
			$self->{'eof'}     = 1;
			return;
		} else {
			$self->throw("Unknown or Invalid process directive:",
				join('', ($line =~ /^\s*(<[^>]+>)/o)));
		}
		$line = $self->_readline();
	} while( defined( $line ) );
}

sub _process_tigr
{
	my($self) = @_;
	my $line;

	$line = $self->_readline();
	if($line !~ /<TIGR>/o) {
		$self->throw("Bio::SeqIO::tigr::_process_tigr called but no ",
		             "<TIGR> found in stream");
	}

	$line = $self->_readline();
	if($line =~ /<PSEUDOCHROMOSOME>/o) {
		$self->_pushback($line);
		$self->_process_pseudochromosome();
	} elsif ($line =~ /<ASSEMBLY.*?>/o) {
		$self->_pushback($line);
		$self->_process_assembly();
	}
}

sub _process_pseudochromosome
{
	my($self) = @_;
	my $line;

	$line = $self->_readline();
	return if $line !~ /<PSEUDOCHROMOSOME>/o;

	$line = $self->_readline();

	if($line =~ /<SCAFFOLD>/o) {
		$self->_pushback($line);
		$self->_process_scaffold();
		$line = $self->_readline();
	} else {
		$self->warn( "No Scaffold found in <PSUEDOCHROMOSOME> this " .
		             "is a violation of the TIGR dtd, but we ignore " .
		             "it so we are ignoring the error\n"
		);
	}

	if($line =~ /<ASSEMBLY.*>/o) {
		$self->_pushback($line);
		$self->_process_assembly();
		$line = $self->_readline();
	} else {
		$self->throw("Missing required ASSEMBLY in <PSEUDOCHROMOSOME>");
	}

	if($line =~ /<\/PSEUDOCHROMOSOME>/) {
		return;
	}

	$self->throw("Reached end of _process_psuedochromosome");
}

sub _process_assembly
{
	my($self) = @_;
	my $line;

	$line = $self->_readline();
	if($line !~ /<ASSEMBLY([^>]*)>/o) {
		$self->throw("Bio::SeqIO::tigr::_process_assembly called ",
		             "but no <ASSEMBLY> found in stream");
	}

	my %attribs = ($1 =~ /(\w+)\s*=\s+"(.*?)"/og);
	$self->{_assembly}->{date}       = $attribs{CURRENT_DATE};
	$self->{_assembly}->{db}         = $attribs{DATABASE};
	$self->{_assembly}->{chromosome} = $attribs{CHROMOSOME};

	$line = $self->_readline();
	my($attr, $val); 
	if(($attr, $val) = ($line =~ /<ASMBL_ID([^>]*)>([^<]*)<\/ASMBL_ID>/o)) {
		%attribs = ($attr =~ /(\w+)\s*=\s+"(.*?)"/og);
		$self->{_assembly}->{clone_name} = $attribs{CLONE_NAME};
		$self->{_assembly}->{clone} = $val;
		$line = $self->_readtag();
	} else {
		$self->throw("Required <ASMBL_ID> missing");
	}

	if($line =~ /<COORDSET>/o) {
		$self->_pushback($line);
		my $cs = $self->_process_coordset();

		$self->{_assembly}->{end5} = $cs->{end5};
		$self->{_assembly}->{end3} = $cs->{end3};

		$line = $self->_readline();
	} else {
		$self->throw("Required <COORDSET> missing");
	}

	if($line =~ /<HEADER>/o) {
		$self->_pushback($line);
		$self->_process_header();
		$line = $self->_readline();
	} else {
		$self->throw("Required <HEADER> missing");
	}

	if($line =~ /<TILING_PATH>/o) {
		$self->_pushback($line);
		$self->_process_tiling_path();
		$line = $self->_readline();
	}

	if($line =~ /<GENE_LIST>/o) {
		$self->_pushback($line);
		$self->_process_gene_list();
		$line = $self->_readline();
	} else {
		$self->throw("Required <GENE_LIST> missing");
	}

	if($line =~ /<MISC_INFO>/o) {
		$self->_pushback($line);
		$self->_process_misc_info();
		$line = $self->_readline();
	}

	if($line =~ /<REPEAT_LIST>/o) {
		$self->_pushback($line);
		$self->_process_repeat_list();
		$line = $self->_readline();
	}

	if($line =~ /<ASSEMBLY_SEQUENCE>/o) {
		$self->_pushback($line);
		$self->_process_assembly_seq();
		$line = $self->_readline();
	} else {
		$self->throw("Required <ASSEMBLY_SEQUENCE> missing");
	}

	if($line =~ /<\/ASSEMBLY>/o) {
		return;
	}
	$self->throw("Reached the end of <ASSEMBLY>");
}

sub _process_assembly_seq()
{
	my ($self) = @_;
	my $line;
	
	$line = $self->_readline();
	if($line !~ /<ASSEMBLY_SEQUENCE>/o) {
		$self->throw("Bio::SeqIO::tigr::_process_assembly_seq called ".
			     "with no <ASSEMBLY_SEQUENCE> in the stream");
	}

	# Protect agains lots of smaller lines
	my @chunks;

	do {
		$line = $self->_readline();
		last unless $line;

		my $seq;
		if (($seq) = ($line =~ /^\s*(\w+)\s*$/o)) {
			push(@chunks, $seq);
		} elsif( ($seq) = ( $line =~ /^\s*(\w+)<\/ASSEMBLY_SEQUENCE>\s*$/o) ) {
			push(@chunks, $seq);
			$self->{_assembly}->{seq} = join('', @chunks);
			return;
		}
	} while( $line );

	$self->throw("Reached end of _proces_assembly");
}

sub _process_coordset($)
{
	my ($self) = @_;
	my $line;
	my $h;

	$line = $self->_readline();
	if($line =~ /<COORDSET>/o) {
		$self->_pushback($line);
		$line = $self->_readtag();
		($h->{end5}, $h->{end3}) = ($line =~ /<COORDSET>\s*<END5>\s*(\d+)\s*<\/END5>\s*<END3>\s*(\d+)\s*<\/END3>/os);
		if(!defined($h->{end5}) or !defined($h->{end3})) {
			$self->throw("Invalid <COORDSET>: $line");
		}
		return $h;
	} else {
		$self->throw("Bio::SeqIO::tigr::_process_coordset() called ",
		             "but no <COORDSET> found in stream");
	}
}

sub _process_header
{
	my ($self) = @_;
	my $line = $self->_readline();

	if($line !~ /<HEADER>/o) {
		$self->throw("Bio::SeqIO::tigr::_process_header called ",
		             "but no <HEADER> found in stream");
	}

	$line = $self->_readtag();
	if($line =~ /<CLONE_NAME>([^>]+)<\/CLONE_NAME>/o) {
		$self->{_assembly}->{clone_name} = $1;
		$line = $self->_readtag();
	} else {
		$self->throw("Required <CLONE_NAME> missing");
	}

	if($line =~ /<SEQ_LAST_TOUCHED>/o) {
		# Ignored for now
		$line = $self->_readtag();
	} else {
		$self->throw("Reqired <SEQ_LAST_TOUCHED> missing");
	}

	if($line =~ /<GB_ACCESSION>([^<]*)<\/GB_ACCESSION>/o) {
		$self->{_assembly}->{gb} = $1;
		$line = $self->_readtag();
	} else {
		$self->throw("Required <GB_ACCESSION> missing");
	}

	if($line =~ /<ORGANISM>\s*(.+)\s*<\/ORGANISM>/o) {
		my( $genus, $species, @ss ) = split(/\s+/o, $1);
		$self->{_assembly}->{species} = Bio::Species->new();
		$self->{_assembly}->{species}->genus($genus);
		$self->{_assembly}->{species}->species($species);
		$self->{_assembly}->{species}->sub_species(join(' ', @ss)) if scalar(@ss) > 0;

		$line = $self->_readtag();
	} else {
		$self->throw("Required <ORGANISM> missing");
	}

	if($line =~ /<LINEAGE>([^<]*)<\/LINEAGE>/o) {
		$self->{_assembly}->{species}->classification(
			$self->{_assembly}->{species}->species(),
			reverse(split(/\s*;\s*/o, $1))
		);
		$line = $self->_readtag();
	} else {
		$self->throw("Required <LINEAGE> missing");
	}

	if($line =~ /<SEQ_GROUP>([^<]*)<\/SEQ_GROUP>/o) {
		# ingnored
		$line = $self->_readtag();
	} else {
		$self->throw("Required <SEQ_GROUP> missing");
	}

	while($line =~ /<KEYWORDS>[^<]*<\/KEYWORDS>/o) {
		push(@{$self->{_assembly}->{keywords}}, $1);
		$line = $self->_readtag();
	}

	while($line =~ /<GB_DESCRIPTION>([^<]+)<\/GB_DESCRIPTION>/o) {
		push(@{$self->{_assembly}->{gb_desc}},$1);
		$line = $self->_readtag();
	}

	while($line =~ /<GB_COMMENT>([^<]+)<\/GB_COMMENT>/o) {
		push(@{$self->{_assembly}->{gb_comment}}, $1);
		$line = $self->_readtag();
	}

	if(my %h = ($line =~ /<AUTHOR_LIST(?:\s*(\w+)\s*=\s*"([^"]+)"\s*)*>/o)) {
		#$header->{'AUTHOR_LIST'}=$h{'CONTACT'};
		# Ignored
		while($line !~ /<\/AUTHOR_LIST>/o) {
			$self->_readtag();
		}
		$line = $self->_readline();
	} else {
		$self->throw("Required <AUTHOR_LIST> missing");
	}

	if($line =~ /<\/HEADER>/o) {
		return;
	}

	$self->throw("Reached end of header\n");
}

sub _process_gene_list
{
	my($self) = @_;
	my $line;

	$line = $self->_readline();
	if($line !~ /<GENE_LIST>/o) {
		$self->throw("Bio::SeqIO::tigr::_process_gene_list called ",
		             "but no <GENE_LIST> in the stream");
	}

	$line = $self->_readline();
	if($line =~ /<PROTEIN_CODING>/o) {
		$self->_pushback($line);
		$self->_process_protein_coding();
		$line = $self->_readline();
	} else {
		$self->throw("Required <PROTEIN_CODING> missing");
	}

	if($line =~ /<RNA_GENES>/o) {
		$self->_pushback($line);
		$self->_process_rna_genes();
		$line = $self->_readline();
	} else {
		$self->throw("Required <RNA_GENES> missing");
	}

	if($line =~ /<\/GENE_LIST>/o) {
		return;
	}

	$self->throw("Reached end of _process_gene_list");
}

sub _process_protein_coding
{
	my ($self) = @_;
	my $line = $self->_readline();

	if($line !~ /<PROTEIN_CODING>/o) {
		$self->throw("Bio::SeqIO::tigr::_process_protein_coding called"
		             . "but no <GENE_LIST> in the stream");
	}

	$line = $self->_readline();
	while($line and $line =~ /<TU>/o) {
		$self->_pushback($line);
		$self->_process_tu();
		$line = $self->_readline();
	}

	# Sort the sequences
	@{$self->{_sequences}} = sort {
		my($one, $two) = ( $a, $b );
		($one) = grep { $_->primary_tag() eq 'source' } $one->get_SeqFeatures();
		($two) = grep { $_->primary_tag() eq 'source' } $two->get_SeqFeatures();
		return 0 unless defined $one and defined $two;
		($one) = sort { $a <=> $b } $one->get_tagset_values(qw/end5 end3/);
		($two) = sort { $a <=> $b } $two->get_tagset_values(qw/end5 end3/);
		return $one <=> $two;
	} @{$self->{_sequences}};

	if($line =~ /<\/PROTEIN_CODING>/o) {
		return;
	}

	$self->throw("Reached end of _process_protein_coding");
}


sub _process_rna_genes
{
	my ($self) = @_;
	my $line = $self->_readline();

	if($line =~ /<RNA_GENES>/o) {
		while($line !~ /<\/RNA_GENES>/o) {
			$line = $self->_readline();
		}
	} else {
		$self->throw("Bio::SeqIO::tigr::_process_rna_genes called ",
		             "but no <RNA_GENES> in the stream");
	}
}

sub _process_misc_info
{
	my ($self) = @_;
	my $line = $self->_readline();

	if($line =~ /<MISC_INFO>/o) {
		while($line !~ /<\/MISC_INFO>/o) {
			$line = $self->_readline();
		}
	} else {
		$self->throw("Bio::SeqIO::tigr::_process_misc_info called ",
		             "but no <MISC_INFO> in the stream");
	}
}

sub _process_repeat_list
{
	my ($self) = @_;
	my $line = $self->_readline();

	if($line =~ /<REPEAT_LIST>/o) {
		while($line !~ /<\/REPEAT_LIST>/o) {
			$line = $self->_readline();
		}
	} else {
		$self->throw("Bio::SeqIO::tigr::_process_repeat_list called ",
		             "but no <MISC_INFO> in the stream");
	}
}

sub _process_tiling_path
{
	my($self) = @_;
	my $line = $self->_readline();


	if($line =~ /<TILING_PATH>/o) {
		while($line !~ /<\/TILING_PATH>/o) {
			$line = $self->_readline();
		}
	} else {
		$self->throw("Bio::SeqIO::tigr::_process_repeat_list called ",
		             "but no <MISC_INFO> in the stream");
	}
}

sub _process_scaffold
{
	my ($self) = @_;
	my $line;

	# for now we just skip them
	$line = $self->_readline();
	return if $line !~ /<SCAFFOLD>/o;
	do {
		$line = $self->_readline();
	} while(defined($line) && $line !~ /<\/SCAFFOLD>/o);
}

sub _process_tu
{
	my($self) = @_;
	my $line = $self->_readline();

	try {
		my $tu = Bio::Seq::RichSeq->new(-strand => 1);
		$tu->species( $self->{_assembly}->{species} );

		# Add the source tag, so we can add the GO annotations to it
		$tu->add_SeqFeature(Bio::SeqFeature::Generic->new(-source_tag => 'TIGR', -primary_tag => 'source'));
		
		if($line !~ /<TU>/o) {
			$self->throw("Process_tu called when no <TU> tag");
		}

		$line = $self->_readtag();
		if ($line =~ /<FEAT_NAME>([\w\.]+)<\/FEAT_NAME>/o) {
			$tu->accession_number($1);
			$tu->add_secondary_accession($1);
			$line = $self->_readtag();
		} else {
			$self->throw("Invalid Feat_Name");
		}

		while($line =~ /<GENE_SYNONYM>/o) {
			# ignore
			$line = $self->_readtag();
		}
	
		while($line =~ /<CHROMO_LINK>\s*([\w\.]+)\s*<\/CHROMO_LINK>/o) {
			$tu->add_secondary_accession($1);
			$line = $self->_readtag();
		}

		if ($line =~ /<DATE>([^>]*)<\/DATE>/o) {
			$tu->add_date($1) if $1 and $1 !~ /^\s*$/o;
			$line = $self->_readline();
		} else {
			#$self->throw("Invalid Date: $line");
		}

		if ($line =~ /<GENE_INFO>/o) {
			$self->_pushback($line);
			$self->_process_gene_info($tu);
			$line = $self->_readline();
		} else {
			$self->throw("Invalid Gene_Info");
		}

		my $source;
		my $end5;
		my $end3;
		if($line =~ /<COORDSET>/o) {
			$self->_pushback($line);
			my $cs = $self->_process_coordset();
	
			$end5 = $cs->{end5};
			$end3 = $cs->{end3};

			my $length = $end3 - $end5;
			my $strand = $length <=> 0;
			$length = $length * $strand;
			$length++; # Correct for starting at 1, not 0

			# Add X filler sequence
			$tu->seq('X' x $length);

			# Get the source tag:
			my($source) = grep { $_->primary_tag() eq 'source' } $tu->get_SeqFeatures();

			# Set the start and end values
			$source->start(1);
			$source->end($length);
			$source->strand(1);

			# Add a bunch of tags to it
			$source->add_tag_value(clone      => $self->{_assembly}->{clone});
			$source->add_tag_value(clone_name => $self->{_assembly}->{clone_name});
			$source->add_tag_value(end5       => $end5);
			$source->add_tag_value(end3       => $end3);
			$source->add_tag_value(chromosome => $self->{_assembly}->{chromosome});
			$source->add_tag_value(strand     => ( $strand == 1 ? 'positive' : 'negative' ));

			$line = $self->_readline();
		} else {
			$self->throw("Invalid Coordset");
		}

		if($line =~ /<MODEL[^>]*>/o) {
			do {
				$self->_pushback($line);
				$self->_process_model($tu, $end5, $end3);
				$line = $self->_readline();
			} while($line =~ /<MODEL[^>]*>/o);
			$self->_pushback($line);
			$line = $self->_readtag();
		} else {
			$self->throw("Expected <MODEL> not found");
		}
		
		if($line =~ /<TRANSCRIPT_SEQUENCE>/o) {
			my @chunks;
			$line = $self->_readline();
			while ($line =~ /^\s*([ACGT]+)\s*$/o) {
				push( @chunks, $1 );
				$line = $self->_readline();
			}
			#	$line = $self->_readline();
		}
		
		if($line =~ /<GENE_EVIDENCE>/o) {
			$line = $self->_readtag();
		}
		
		while($line =~ /<URL[^>]*>[^<]*<\/URL>/o) {
			$line = $self->_readtag();
		}
		
		if($line =~ /<\/TU>/o) {
			push(@{$self->{_sequences}}, $tu);
			return;
		} else {
			$self->throw("Expected </TU> not found: $line");
		}
	} catch Bio::Root::OutOfRange with {
		my $E = shift;
		$self->warn(sprintf("One sub location of a sequence is invalid near line $.\: %s", $E->text()));
		$line = $self->_readline() until $line =~ /<\/TU>/o;
		return;
	};
}

sub _process_gene_info
{
	my($self, $tu) = @_;
	my $line = $self->_readline();

	$self->throw("Invalid Gene Info: $line") if $line !~ /<GENE_INFO>/o;
	$line = $self->_readline();

	if($line =~ /<LOCUS>\s*([\w\.]+)\s*<\/LOCUS>/o) {
		$tu->accession_number($1);
		$tu->add_secondary_accession($1);
		$line = $self->_readline();
	} elsif( $line =~ /<LOCUS>.*<\/LOCUS>/o) {
		# We should throw an error, but TIGR doesn't alwasy play
		# nice with adhering to their dtd
		$line = $self->_readtag();
	} else {
		#$self->throw("Invalid Locus: $line");
	}

	if($line =~ /<ALT_LOCUS>\s*([\w\.]+)\s*<\/ALT_LOCUS>/o) {
		$tu->accession_number($1);
		$tu->add_secondary_accession($1);
		$line = $self->_readline();
	}

	if($line =~ /<PUB_LOCUS>\s*([\w\.]+)\s*<\/PUB_LOCUS>/o) {
		$tu->accession_number($1);
		$tu->add_secondary_accession($1);
		$line = $self->_readtag();
	} elsif( $line =~ /<PUB_LOCUS>.*<\/PUB_LOCUS>/o) {
		$line = $self->_readtag();
#		$self->throw("Invalid Pub_Locus");
	}

	if($line =~ /<GENE_NAME.*>.*<\/GENE_NAME>/o) {
		# Skip the GENE_NAME
		$line = $self->_readtag();
	}

	if(my($attr, $value) = ($line =~ /<COM_NAME([^>]*)>([^>]+)<\/COM_NAME>/o)) {
		#%attribs = ($attr =~ /(\w+)\s*=\s+"(.*?)"/og);
		#$geneinfo->{'CURATED'} = $attribs{CURATED};
		#$geneinfo->{IS_PRIMARY} = $attribs{IS_PRIMARY}
		# TODO: add a tag on sources for curated
		$tu->desc($value);
		$line = $self->_readtag();
	} else {
		$self->throw("invalid com_name: $line");
	}

	while($line =~ /<COMMENT>([^<]+)<\/COMMENT>/o) {
		my $comment = Bio::Annotation::Comment->new(
			-text => $1
		);
		$tu->annotation()->add_Annotation('comment', $comment);
		$line = $self->_readtag();
	}

	while($line =~ /<PUB_COMMENT>([^<]+)<\/PUB_COMMENT>/o) {
		my $comment = Bio::Annotation::Comment->new(
			-text => $1
		);
		$tu->annotation()->add_Annotation('comment', $comment);
		$line = $self->_readtag();
	}

	if($line =~ /<EC_NUM>([\w\-\\\.]+)<\/EC_NUM>/o) {
		#$geneinfo->{'EC_NUM'} = $1;
		$line = $self->_readtag();
	}

	if($line =~ /<GENE_SYM>\s*([^<]+)\s*<\/GENE_SYM>/o) {
		#$tu->add_secondary_accession($1);
		$line = $self->_readtag();
	}

	if($line =~ /<IS_PSEUDOGENE>([^>]+)<\/IS_PSEUDOGENE>/o) {
		#$geneinfo->{'IS_PSEUDOGENE'} = $1;
		$line = $self->_readtag();
	} else {
		$self->throw("invalid is_pseudogene: $line");
	}

	if($line =~ /<FUNCT_ANNOT_EVIDENCE/o) {
		$line = $self->_readtag();
	}

	if($line =~ /<DATE>([^>]+)<\/DATE>/o) {
		#$geneinfo->{'DATE'} = $1;
		$line = $self->_readtag();
	}

	while($line =~ /<GENE_ONTOLOGY>/o) {
		# Get the source tag
		my($source) = grep { $_->primary_tag() eq 'source' } $tu->get_SeqFeatures();

		my @ids = ( $line =~ /(<GO_ID.*?<\/GO_ID>)/gso);
		foreach my $go (@ids) {
			my($assignment) = ($go =~ /<GO_ID\s+ASSIGNMENT\s+=\s+"GO:(\d+)">/os);
			my($term)       = ($go =~ /<GO_TERM>([^<]+)<\/GO_TERM>/os);
			my($type)       = ($go =~ /<GO_TYPE>([^<]+)<\/GO_TYPE>/os);
			# TODO: Add GO annotation
			if(defined $type and defined $assignment and defined $term) {
				# Add the GO Annotation
				$source->add_tag_value(
				GO => "ID: $assignment; Type: $type; $term"
				);
			}
		}
		$line = $self->_readtag();
	}
	
	if($line =~ /<\/GENE_INFO/o) {
		return;
	}

	$self->throw("unexpected end of gene_info");
}

sub _build_location
{
	my($self, $end5, $end3, $length, $cs) = @_;
	
	# Find the start and end of the location
	# relative to the sequence.
	my $start = abs( $end5 - $cs->{end5} ) + 1;
	my $end   = abs( $end5 - $cs->{end3} ) + 1;

	# Do some bounds checking:
	if( $start < 1 ) {
		throw Bio::Root::OutOfRange(
			-text => "locations' start( $start) must be >= 1"
		);
	} elsif( $end > $length ) {
		throw Bio::Root::OutOfRange(
			-text => "locations' end( $end ) must be <= length( $length )"
		);
	} elsif( $start > $end ) {
		throw Bio::Root::OutOfRange(
			-text => "locations' start ( $start ) must be < end ( $end ) $end5, $end3, $cs->{end5}, $cs->{end3}"
		);
	}

	return Bio::Location::Simple->new( -start => $start, -end => $end, -strand => 1 );
}

sub _process_model
{
	my($self, $tu, $end5, $end3) = @_;
	my $line;
	my( $source ) = grep { $_->primary_tag() eq 'source' } $tu->get_SeqFeatures();
	my $model = Bio::SeqFeature::Generic->new(
		-source_tag  => 'TIGR',
		-primary_tag => 'MODEL',
	);

	$line = $self->_readline();
	if($line !~ /<MODEL ([^>]+)>/o) {
		$self->throw("Invalid Model: $line")
	}
	my %attribs = ($1 =~ /(\w+)\s*=\s*"([^"]*)"/og);
	#$model->{'CURATED'} = $attribs{'CURATED'};
	# TODO: Add tag to model
	$line = $self->_readline();

	if($line =~ /<FEAT_NAME>\s*([\w\.]+)\s*<\/FEAT_NAME>/o) {
		$model->add_tag_value( feat_name => $1 );
		$tu->add_secondary_accession($1);
		$line = $self->_readline();
	} else {
		$self->throw("Invalid Feature Name: $line");
	}

	if($line =~ /<PUB_LOCUS>\s*([\w\.]+)\s*<\/PUB_LOCUS>/o) {
		$model->add_tag_value( pub_locus => $1 );
		$tu->add_secondary_accession($1);
		$line = $self->_readline();
	} else {
#		$self->throw("Invalid Pub_Locus: $line");
	}

	if($line =~ /<CDNA_SUPPORT>/o) {
		$self->_pushback($line);
		$self->_process_cdna_support( $model );
		$line = $self->_readline();
	}

	while($line =~ /<CHROMO_LINK>([^>]+)<\/CHROMO_LINK>/o) {
		$model->add_tag_value( chromo_link => $1 );
		$line = $self->_readline();
	} 

	if($line =~ /<DATE>([^>]+)<\/DATE>/o) {
		$line = $self->_readline();
	} else {
		$self->throw("Invalid Date: $line");
	}

	if($line =~ /<COORDSET>/o) {
		$self->_pushback($line);
		my $cs = $self->_process_coordset();
		my $loc = $self->_build_location($end5, $end3, $tu->length(), $cs);
		
		$model->start( $loc->start() );
		$model->end(   $loc->end()   );
		$line = $self->_readline();
	} else {
		$self->throw("Invalid Coordset: $line");
	}

	my $exon = Bio::SeqFeature::Generic->new(
		-source_tag  => 'TIGR',
		-primary_tag => 'EXON',
		-location => Bio::Location::Split->new(),
		-tags => [ locus => $tu->accession_number() ],
	);
	$exon->add_tag_value( model => $model->get_tag_values('feat_name') );

	my $cds  = Bio::SeqFeature::Generic->new(
		-source_tag  => 'TIGR',
		-primary_tag => 'CDS',
		-location => Bio::Location::Split->new(),
		-tags => [ locus => $tu->accession_number() ],
	);
	$cds->add_tag_value( model => $model->get_tag_values('feat_name') );
	my $utr = [];

	if($line =~ /<EXON>/o) {
		do {
			$self->_pushback($line);
			$self->_process_exon( $tu, $exon, $cds, $utr, $end5, $end3 );
			$line = $self->_readline();
		} while($line =~ /<EXON>/o);
	} else {
		$self->throw("Required <EXON> missing");
	}
	
	until($line =~ /<\/MODEL>/o) {
		$line = $self->_readline();
	}


	$_->add_tag_value( model => $model->get_tag_values('feat_name') )
		foreach @$utr;

	# Add the model, EXONs, CDS, and UTRs
	$tu->add_SeqFeature($model) if $model and $model->start() >= 1;
	$tu->add_SeqFeature($exon)  if $exon  and scalar($exon->location()->each_Location()) >= 1;
	$tu->add_SeqFeature($cds)   if $cds   and scalar($cds->location()->each_Location()) >= 1;
	$tu->add_SeqFeature(@$utr);

	return;
}

sub _process_cdna_support
{
	my($self, $model) = @_;
	my $line = $self->_readline();

	if($line !~ /<CDNA_SUPPORT>/o) {
		$self->throw("Bio::SeqIO::tigr::_process_cdna_support called ",
		             "but no <CDNA_SUPPORT> in the stream");
	}

	$line = $self->_readline();

	while( $line =~ /<ACCESSION([^>]+)>(.*)<\/ACCESSION>/o) {
		# Save the text
		my $desc = $2;
		
		# Get the element's attributes
		my %attribs = ($1 =~ /(\w+)\s*=\s*"([^"]*)"/og);

		# Add the tag to the model
		$model->add_tag_value(
			cdna_support => "DBXRef: $attribs{DBXREF}; $desc"
		);

		$line = $self->_readline();
	}

	if( $line =~ /<\/CDNA_SUPPORT>/o) {
		return;
	}
	$self->throw("reached end of _process_cdna_support");
}


sub _process_exon
{
	my($self, $tu, $exon, $cds, $utr, $end5, $end3 ) = @_;
	my $line = $self->_readline();

	if($line !~ /<EXON>/o) {
		$self->throw("Bio::SeqIO::tigr::_process_exon called ",
		             "but no <EXON> in the stream");
	}

	$line = $self->_readtag();
	if($line =~ /<FEAT_NAME>([^<]+)<\/FEAT_NAME>/o) {
		# Ignore
		$line = $self->_readtag();
	} else {
		$self->throw("Required <FEAT_NAME> missing");
	}

	if($line =~ /<DATE>([^<]+)<\/DATE>/o) {
		# Ignore
		$line = $self->_readtag();
	} else {
		$self->throw("Required <DATE> missing");
	}

	if($line =~ /<COORDSET>/o) {
		$self->_pushback($line);
		my $cs = $self->_process_coordset();
		my $loc = $self->_build_location($end5, $end3, $tu->length(), $cs);
		$exon->location()->add_sub_Location($loc);
		$line = $self->_readline();
	} else {
		$self->throw("Required <COORDSET> missing");
	}

	if($line =~ /<CDS>/o) {
		$self->_pushback($line);
		$self->_process_cds($tu, $end5, $end3, $cds);
		$line = $self->_readline();
	}

	if($line =~ /<UTRS>/o) {
		$self->_pushback($line);
		$self->_process_utrs($tu, $end5, $end3, $utr);
		$line = $self->_readline();
	}

	if($line =~ /<\/EXON>/o) {
		return;
	}

	$self->throw("Reached End of Bio::SeqIO::tigr::_process_exon");
}

sub _process_cds
{
	my($self, $tu, $end5, $end3, $cds) = @_;
	my $line = $self->_readline();

	if($line !~ /<CDS>/o) {
		$self->throw("Bio::SeqIO::tigr::_process_cda_support called ",
		             "but no <CDS> in the stream");
	}
	
	$line = $self->_readtag();
	if($line =~ /<FEAT_NAME>([^<]+)<\/FEAT_NAME>/o) {
		#$cds->{'FEAT_NAME'} = $1;
		$line = $self->_readtag();
	} else {
		$self->throw("Required <FEAT_NAME> missing");
	}

	if($line =~ /<DATE>([^<]+)<\/DATE>/o) {
		#$cds->{'DATE'} = $1;
		$line = $self->_readtag();
	} else {
		$self->throw("Required <DATE> missing");
	}

	if($line =~ /<COORDSET>/o) {
		$self->_pushback($line);
		my $cs = $self->_process_coordset();
		my $loc = $self->_build_location($end5, $end3, $tu->length(), $cs);
		$cds->location()->add_sub_Location($loc);
		$line = $self->_readline();
	} else {
		$self->throw("Required <COORDSET> missing");
	}

	if($line =~ /<\/CDS>/o) {
		return;
	}

	$self->throw("Reached onf of Bio::SeqIO::tigr::_process_cds");
}

sub _process_utrs
{
	my($self, $tu, $end5, $end3, $utrs) = @_;
	my $line = $self->_readline();

	if($line !~ /<UTRS/o) {
		$self->throw("Bio::SeqIO::tigr::_process_utrs called but no ",
		             "<UTRS> found in stream");
	}

	$line = $self->_readline();
	while($line !~ /<\/UTRS>/o) {
		$self->_pushback($line);
		if($line =~ /<LEFT_UTR>/o) {
			$self->_process_left_utr($tu, $end5, $end3, $utrs);
		} elsif ($line =~ /<RIGHT_UTR>/o) {
			$self->_process_right_utr($tu, $end5, $end3, $utrs);
		} elsif ($line =~ /<EXTENDED_UTR>/o) {
			$self->_process_ext_utr($tu, $end5, $end3, $utrs);
		} else {
			$self->throw("Unexpected tag");
		}
	
		$line = $self->_readline();
	}

	if($line =~ /<\/UTRS>/o) {
		return $utrs;
	}
	$self->throw("Reached end of Bio::SeqIO::tigr::_process_utrs");
}

sub _process_left_utr
{
	my($self, $tu, $end5, $end3, $utrs) = @_;
	my $line = $self->_readline();
	my $coordset;

	if($line !~ /<LEFT_UTR>/o) {
		$self->throw("Bio::SeqIO::tigr::_process_left_utr called but ",
		             "no <LEFT_UTR> found in stream");
	}

	$line = $self->_readtag();
	if($line =~ /<COORDSET>/o) {
		$self->_pushback($line);
		my $cs = $self->_process_coordset();
		my $loc = $self->_build_location($end5, $end3, $tu->length(), $cs);

		push(@$utrs, Bio::SeqFeature::Generic->new(
		        -source_tag  => 'TIGR',
				-primary_tag => 'LEFT_UTR',
				-strand => 1,
				-start => $loc->start(),
				-end   => $loc->end()
		));

		$line = $self->_readline();
	} else {
		$self->throw("Required <COORDSET> missing");
	}

	if($line =~ /<\/LEFT_UTR>/o) {
		return;
	}
	$self->throw("Reached end of Bio::SeqIO::tigr::_process_left_utr");
}

sub _process_right_utr
{
	my($self, $tu, $end5, $end3, $utrs) = @_;
	my $line = $self->_readline();
	my $coordset;

	if($line !~ /<RIGHT_UTR>/o) {
		$self->throw("Bio::SeqIO::tigr::_process_right_utr called but ",
		             "no <RIGHT_UTR> found in stream");
	}

	$line = $self->_readtag();
	if($line =~ /<COORDSET>/o) {
		$self->_pushback($line);
		$coordset = $self->_process_coordset();
		$self->_pushback($line);
		my $cs = $self->_process_coordset();
		my $loc = $self->_build_location($end5, $end3, $tu->length(), $cs);

		push(@$utrs, Bio::SeqFeature::Generic->new(
		        -source_tag  => 'TIGR',
				-primary_tag => 'RIGHT_UTR',
				-strand => 1,
				-start => $loc->start(),
				-end   => $loc->end()
		));

		$line = $self->_readline();
	} else {
		$self->throw("Required <COORDSET> missing");
	}

	if($line =~ /<\/RIGHT_UTR>/o) {
		return $coordset;
	}
	$self->throw("Reached end of Bio::SeqIO::tigr::_process_right_utr");
}

sub _process_ext_utr
{
	my($self, $tu, $end5, $end3, $utrs) = @_;
	my $line = $self->_readline();
	my $coordset;

	if($line !~ /<EXTENDED_UTR>/o) {
		$self->throw("Bio::SeqIO::tigr::_process_ext_utr called but ",
		             "no <EXTENDED_UTR> found in stream");
	}

	$line = $self->_readtag();
	if($line =~ /<COORDSET>/o) {
		$self->_pushback($line);
		my $cs = $self->_process_coordset();
		my $loc = $self->_build_location($end5, $end3, $tu->length(), $cs);

		push(@$utrs, Bio::SeqFeature::Generic->new(
		        -source_tag  => 'TIGR',
				-primary_tag => 'EXTENDED_UTR',
				-strand => 1,
				-start => $loc->start(),
				-end   => $loc->end()
		));

		$line = $self->_readline();
	} else {
		$self->throw("Required <COORDSET> missing");
	}

	if($line =~ /<\/EXTENDED_UTR>/o) {
		return $coordset;
	}
	$self->throw("Reached end of Bio::SeqIO::tigr::_process_ext_utr");
}

sub _readtag
{
	my($self) = @_;
	my $line = $self->_readline();
	chomp($line);

	my $tag;
	if(($tag) = ($line =~ /^[^<]*<\/(\w+)/o)) {
		$self->_pushback($1) if $line =~ /<\/$tag>(.+)$/;
		return "</$tag>";
	}
 
	until(($tag) = ($line =~ /<(\w+)[^>]*>/o)) {
		$line = $self->_readline();
		chomp $line;
	}

	until($line =~ /<\/$tag>/) {
		$line .= $self->_readline();
	}

	if(my ($val) = ($line =~ /(<$tag.*>.*?<\/$tag>)/s)) {
		if($line =~ /<\/$tag>\s*(\w+[\s\w]*?)\s*$/s) {
			$self->_pushback($1)
		}
		return $val;
	}
	$self->throw("summerror");
}

sub _readline
{
	my($self) = @_;
	my $line;
	do {
		$line = $self->SUPER::_readline();
	} while(defined($line) and $line =~ /^\s*$/o);

	return $line;
}

sub throw
{
	my($self, @s) = @_;
	my $string = "[$.]" . join('', @s);
	$self->SUPER::throw($string);
}

1;