/
agave.pm
1792 lines (1250 loc) · 55.5 KB
/
agave.pm
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
# BioPerl module: Bio::SeqIO::agave
#
# AGAVE: Architecture for Genomic Annotation, Visualization and Exchange.
#
# You may distribute this module under the same terms as perl itself
#
# POD documentation - main docs before the code
#
# The original version of the module can be found here:
# http://www.agavexml.org/
#
# ### TODO: live link for this anymore?
# The DTD for AGAVE XML was once located here (dead link):
# http://www.lifecde.com/products/agave/schema/v2_3/agave.dtd
#
#
=head1 NAME
Bio::SeqIO::agave - AGAVE sequence output stream.
=head1 SYNOPSIS
It is probably best not to use this object directly, but
rather go through the SeqIO handler system. Go:
$in = Bio::SeqIO->new('-file' => "$file_in",
'-format' => 'EMBL');
$out = Bio::SeqIO->new('-file' => ">$file_out",
'-format' => 'AGAVE');
while (my $seq = $in->next_seq){
$out->write_seq($seq);
}
=head1 DESCRIPTION
This object can transform Bio::Seq objects to agave xml file and
vice-versa. I (Simon) coded up this module because I needed a parser
to extract data from AGAVE xml to be utitlized by the GenQuire genome
annotation system (See http://www.bioinformatics.org/Genquire).
***NOTE*** At the moment, not all of the tags are implemented. In
general, I followed the output format for the XEMBL project
http://www.ebi.ac.uk/xembl/
=cut
=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:
http://bugzilla.open-bio.org/
=head1 AUTHOR - Simon K. Chan
Email:
=head1 APPENDIX
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _
=cut
# ===================
# Let the code begin...
package Bio::SeqIO::agave;
use strict;
use IO::File;
use Bio::SeqFeature::Generic;
use Bio::Seq;
use Bio::PrimarySeq;
use Bio::Seq::SeqFactory;
use Bio::Annotation::Reference;
use Bio::Species;
use XML::Writer;
use Data::Dumper;
use base qw(Bio::SeqIO);
# ==================================================================================
sub _initialize {
my ($self,@args) = @_;
$self->SUPER::_initialize(@args); # Run the constructor of the parent class.
my %tmp = @args ;
$self->{'file'} = $tmp{'-file'};
if ($self->{'file'} !~ /^>/) {
$self->_process;
# Parse the thing, but only if it is the input file (ie not
# outputing agave file, but reading it).
$self->{'parsed'} = 1;
# Set the flag to let the code know that the agave xml file
# has been parsed.
}
$self->{'seqs_stored'} = 0;
}
# ==================================================================================
=head2 _process
Title : _process
Usage : $self->_process
Function : Parses the agave xml file.
Args : None.
Returns : Nothing.
Note : Method(s) that call(s) this method : _initialize
Method(s) that this method calls : _process_sciobj
FIRST/START sub.
=cut
sub _process {
my ($self) = @_;
while (1) {
my $line = $self->_readline;
next unless $line;
next if $line =~ /^\s*$/;
if ($line =~ /<\?xml version/o) {
# do nothing
} elsif ($line =~ /\<!DOCTYPE (\w+) SYSTEM "([\w\.]+)"\>/) {
$self->throw("Error: This xml file is not in AGAVE format! DOCTYPE: $1 , SYSTEM: $2\n\n")
if $1 ne 'sciobj' || $2 ne 'sciobj.dtd';
} elsif ($line =~ /<sciobj (.*)>/) {
push @{$self->{'sciobj'}}, $self->_process_sciobj($1);
} elsif ($line =~ /<\/sciobj>/) {
last; # It is finished.
} else {
# throw an error message. The above conditions should
# take care all of the possible options...?
# $self->throw("Error: Do not recognize this AGAVE xml
# line: $line\n\n");
}
} # close while loop
return;
}
# ==================================================================================
=head2 _process_sciobj
Title : _process_sciobj
Usage : $self->_process_sciobj
Function : Parses the data between the <sciobj></sciobj> tags.
Args : The string that holds the attributes for <sciobj>.
Returns : Data structure holding the values parsed between
the <sciobj></sciobj> tags.
Note : Method(s) that call(s) this method : _process
Method(s) that this method calls :
_helper_store_attribute_list , _process_contig
=cut
sub _process_sciobj {
my ($self, $attribute_line) = @_;
my $sciobj;
$self->_helper_store_attribute_list($attribute_line, \$sciobj);
my $line = $self->_readline;
# Zero or more <contig>
while ($line =~ /<contig\s?(.*?)\s?>/) {
my $contig = $self->_process_contig(\$line, $1);
push @{$sciobj->{'contig'}}, $contig;
# print "line in _process_sciobj: $line\n";
# $line changes value within the subs called in this sub (_process_contig).
}
return $sciobj;
}
# ==================================================================================
=head2 _process_contig
Title : _process_contig
Usage : $self->_process_contig
Function : Parses the data between the <contig></contig> tags.
Args : 2 scalars:
- reference to a scalar holding the line to be parsed.
- scalar holding the attributes for the <contig> tag
to be parsed.
Returns : Data structure holding the values parsed between
the <contig></contig> tags.
Note : Method(s) that call(s) this method : _process_sciobj
Method(s) that this method calls :
_helper_store_attribute_list, _one_tag , _process_fragment_order
=cut
sub _process_contig {
my ($self, $line, $attribute_line) = @_;
my $contig;
$self->_helper_store_attribute_list($attribute_line, \$contig);
$$line = $self->_readline;
# One <db_id>:
$self->_one_tag($line, \$contig, 'db_id');
# Zero or more <fragment_order>
$self->_process_fragment_order($line, \$contig);
return $contig;
}
# ==================================================================================
=head2 _process_fragment_order
Title : _process_fragment_order
Usage : $self->_process_fragment_order
Function : Parses the data between the <fragment_order></fragment_order> tags.
Args : 2 scalars:
- reference to a scalar holding the value of the line to be parsed.
- reference to a data structure to store the <fragment_order> data.
Returns : Nothing.
Note : Method(s) that call(s) this method : _process_contig
Method(s) that this method calls :
_helper_store_attribute_list , _process_fragment_orientation
=cut
sub _process_fragment_order {
my ($self, $line, $data_structure) = @_;
# Because I'm passing a reference to a data structure, I don't need to return it
# after values have been added.
while ($$line =~ /<fragment_order\s?(.*?)\s?>/) {
my $fragment_order;
$self->_helper_store_attribute_list($1, \$fragment_order);
# Store the attribute(s) for <fragment_order> into the
# $fragment_order data structure.
$$line = $self->_readline;
# One or more <fragment_orientation>
$self->_process_fragment_orientation($line, \$fragment_order);
# Don't forget: $line is a reference to a scalar.
push @{$$data_structure->{'fragment_order'}}, $fragment_order;
# Store the data between <fragment_order></fragment_order>
# in $$data_structure.
}
return;
}
# ==================================================================================
=head2 _process_fragment_orientation
Title : _process_fragment_orientation
Usage : $self->_process_fragment_orientation
Function : Parses the data between the <fragment_orientation> and
</fragment_orientation> tags.
Args : 2 scalars:
- reference to a scalar holding the value of the line to be parsed.
- reference to a data structure to store the <fragment_orientation> data.
Returns : Nothing.
Note : Method(s) that call(s) this method : _process_fragment_order
Method(s) that this method calls : _helper_store_attribute_list ,
_process_bio_sequence
=cut
sub _process_fragment_orientation {
my ($self, $line, $data_structure) = @_;
# counter to determine the number of iterations within this while loop.
my $count = 0;
# One or more <fragment_orientation>
while ($$line =~ /<fragment_orientation\s?(.*?)\s?>/) {
my $fragment_orientation;
$self->_helper_store_attribute_list($1, \$fragment_orientation);
$$line = $self->_readline;
# One <bio_sequence>
$$line =~ /<bio_sequence\s?(.*?)\s?>/;
# Process the data between <bio_sequence></bio_sequence>
my $bio_sequence = $self->_process_bio_sequence($line, $1);
$fragment_orientation->{'bio_sequence'} = $bio_sequence;
push @{$$data_structure->{'fragment_orientation'}}, $fragment_orientation;
++$count;
}
$self->throw("Error: Missing <fragment_orientation> tag. Got this: $$line\n\n")
if $count == 0;
return;
}
# ==================================================================================
=head2 _process_bio_sequence
Title : _process_bio_sequence
Usage : $self->_process_bio_sequence
Function : Parses the data between the <bio_sequence></bio_sequence> tags.
Args : 2 scalars:
- reference to a scalar holding the value of the line to be parsed.
- scalar holding the value of the attributes for <bio_sequence>
Returns : data structure holding the values between <bio_sequence></bio_sequence>
Note : Method(s) that call(s) this method : _process_fragment_orientation
Method(s) that this method calls : _helper_store_attribute_list ,
_one_tag , _question_mark_tag , _star_tag , _process_alt_ids ,
_process_xrefs , _process_sequence_map
=cut
sub _process_bio_sequence {
my ($self, $line, $attribute_line) = @_;
my $bio_sequence;
$self->_helper_store_attribute_list($attribute_line, \$bio_sequence);
$$line = $self->_readline;
# One <db_id>.
$self->_one_tag($line, \$bio_sequence, 'db_id');
# Zero or one <note>.
$self->_question_mark_tag($line, \$bio_sequence, 'note');
# Zero or more <description>
$self->_question_mark_tag($line, \$bio_sequence, 'description');
# Zero or more <keyword>
$self->_star_tag($line, \$bio_sequence, 'keyword');
# Zero or one <sequence>
$self->_question_mark_tag($line, \$bio_sequence, 'sequence');
# Zero or one <alt_ids>
# NOT IMPLEMENTED!!!!
#if ($line =~ /<alt_ids>/){ # NOT DONE YET!
# my $alt_ids;
# $bio_sequence->{'alt_ids'} = $self->_process_alt_ids(\$alt_ids);
#}
# Zero or one <xrefs>
if ($$line =~ /<xrefs\s?(.*?)\s?>/) {
my $xrefs = $self->_process_xrefs($line, \$bio_sequence);
$bio_sequence->{'xrefs'} = $xrefs || 'null';
}
# Zero or more <sequence_map>
if ($$line =~ /<sequence_map\s?(.*?)\s?>/) {
my $sequence_map = $self->_process_sequence_map($line);
push @{$bio_sequence->{'sequence_map'}}, $sequence_map;
}
# print Data::Dumper->Dump([$bio_sequence]); exit;
return $bio_sequence;
}
# ==================================================================================
=head2 _process_xrefs
Title : _process_xrefs
Usage : $self->_process_xrefs
Function : Parse the data between the <xrefs></xrefs> tags.
Args : reference to a scalar holding the value of the line to be parsed.
Return : Nothing.
Note : Method(s) that call(s) this method: _process_bio_sequence
Method(s) that this method calls: _one_tag , _process_xref
=cut
sub _process_xrefs {
my ($self, $line) = @_;
my $xrefs;
$$line = $self->_readline;
# One or more <db_id> or <xref> within <xrefs></xrefs>. Check if
# to see if there's at least one.
if ($$line =~ /<db_id|xref\s?(.*?)\s?>/) {
while ($$line =~ /<(db_id|xref)\s?(.*?)\s?>/) {
if ($1 eq "db_id") {
my $db_id;
$self->_one_tag($line, \$db_id, 'db_id');
push @{$xrefs->{'db_id'}}, $db_id;
} elsif ($1 eq "xref") {
my $xref;
$self->_process_xref($line, \$xref);
push @{$xrefs->{'xref'}}, $xref;
} else {
$self->throw("Error: Tag type should be one of db_id or xref! Got this: $$line\n\n");
}
} # close while loop
if ($$line =~ /<\/xrefs>/) {
$$line = $self->_readline; # get the next line to be _processed by the next sub.
return $xrefs;
} else {
$self->throw("Error: Missing </xrefs> tag. Got this: $$line\n\n");
}
} else {
$self->throw("Error: Missing <db_id> or <xref> tag. Got this: $$line\n\n");
}
return;
}
# ==================================================================================
=head2 _process_xref
Title : _process_xref
Usage : $self->_process_xref
Function : Parses the data between the <xref></xref> tags.
Args : 2 scalars:
- reference to a scalar holding the value of the line to be parsed.
- reference to a data structure to store the <xref> data.
Returns : Nothing.
Note : Method(s) that call(s) this method : _process_xrefs (note the 's' in 'xrefs')
Method(s) that this method calls : _helper_store_attribute_list , _star_tag
=cut
sub _process_xref {
my ($self, $line, $xref) = @_;
$$line = $self->_readline;
# One <db_id>
if ($$line =~ /<db_id\s?(.*?)\s?>/) {
$self->_helper_store_attribute_list($1, $xref);
} else {
$self->throw("Error: Missing <db_id> tag. Got this: $$line\n\n");
}
# Zero or more <xref_property>
$self->_star_tag($line, $xref, 'xref_propery');
return;
}
# ==================================================================================
=head2 _process_sequence_map
Title : _process_sequence_map
Usage : $self->_process_sequence_map
Function : Parses the data between the <sequence_map></sequence_map> tags.
Args : Reference to scalar holding the line to be parsed.
Returns : Data structure that holds the values that were parsed.
Note : Method(s) that call(s) this method : _process_bio_sequence
Method(s) that this method calls : _helper_store_attribute_list ,
_question_mark_tag , _process_annotations
=cut
sub _process_sequence_map {
my ($self, $line) = @_;
my $sequence_map;
# Zero or more <sequence_map>
while ($$line =~ /<sequence_map\s?(.*?)\s?>/) {
$self->_helper_store_attribute_list($1, \$sequence_map) if defined $1;
$$line = $self->_readline;
# Zero or one <note>
$self->_question_mark_tag($line, \$sequence_map, 'note');
# NOT IMPLEMENTED!!!
#if ($$line =~ /<computations\?(.*?)\s?>/){
# # $self->_process_computations();
#}
# Zero or one <annotations>
if ($$line =~ /<annotations\s?(.*?)\s?>/) {
my $annotations = $self->_process_annotations($line);
$sequence_map->{'annotations'} = $annotations;
}
} # closes the while loop
# Match closing tag:
if ($$line =~ /<\/sequence_map>/) {
return $sequence_map;
} else {
$self->throw("Error: Missing </sequence_map> tag. Got this: $$line\n\n");
}
}
# ==================================================================================
=head2 _process_annotations
Title : _process_annotations
Usage : $self->_process_annotations
Function : Parse the data between the <annotations></annotations> tags.
Args : Reference to scalar holding the line to be parsed.
Returns : Data structure that holds the values that were parsed.
Note : Method(s) that call(s) this method : _process_sequence_map
Method(s) that this method calls : _process_seq_feature
=cut
sub _process_annotations {
my ($self, $line) = @_;
# ( seq_feature | gene | comp_result )+
my $annotations;
$$line = $self->_readline;
my $count = 0; # counter to keep track of number of iterations in the loop.
# One or more of these:
while ($$line =~ /<(seq_feature|gene|comp_result)\s?(.*?)\s?>/) {
if ($$line =~ /<seq_feature\s?(.*?)\s?>/) {
my $seq_feature = $self->_process_seq_feature($line, $1);
push @{$annotations->{'seq_feature'}}, $seq_feature;
} elsif ($$line =~ /<gene\s?(.*?)\s?>/) {
# gene
} elsif ($$line =~ /<comp_result\s?(.*?)\s?>/) {
# comp_result
}
++$count;
} # closes the while loop.
$self->throw("Error: Missing <seq_feature> tag. Got: $$line\n\n") if $count == 0;
# Match closing tag:
if ($$line =~ /<\/annotations/) {
$$line = $self->_readline; # get the next line to be _processed by the next sub.
return $annotations;
} else {
$self->throw("Error: Missing </annotations> tag. Got this: $$line\n\n");
}
}
# ==================================================================================
=head2 _process_seq_feature
Title : _process_seq_feature
Usage : $self->_process_seq_feature
Function : Parses the data between the <seq_feature></seq_feature> tag.
Args : 2 scalars:
- Reference to scalar holding the line to be parsed.
- Scalar holding the attributes for <seq_feature>.
Returns : Data structure holding the values parsed.
Note : Method(s) that call(s) this method: _process_annotations
Method(s) that this method calls: _helper_store_attribute_list ,
_process_classification , _question_mark_tag , _one_tag ,
_process_evidence , _process_qualifier , _process_seq_feature ,
_process_related_annot
=cut
sub _process_seq_feature {
my ($self, $line, $attribute_line) = @_;
my $seq_feature;
$self->_helper_store_attribute_list($attribute_line, \$seq_feature);
$$line = $self->_readline;
# Zero or more <classification>
$self->_process_classification($line, \$seq_feature);
# Zero or one <note>
$self->_question_mark_tag($line, \$seq_feature, 'note');
# One <seq_location>
$self->_one_tag($line, \$seq_feature, 'seq_location');
# Zero or one <xrefs>
$self->_question_mark_tag($line, \$seq_feature, 'xrefs');
# Zero or one <evidence>
$self->_process_evidence($line, \$seq_feature);
# Zero or more <qualifier>
$self->_process_qualifier($line, \$seq_feature);
# Zero or more <seq_feature>. A <seq_feature> tag within a <seq_feature> tag? Oh, well. Whatever...
while ($$line =~ /<seq_feature\s?(.*?)\s?>/) {
$self->_process_seq_feature($line, $1);
$$line = $self->_readline;
}
# Zero or more <related_annot>
while ($$line =~ /<related_annot\s?(.*?)\s?>/) {
$self->_process_related_annot($line, $1);
$$line = $self->_readline;
}
# Match the closing tag:
if ($$line =~ /<\/seq_feature>/) {
$$line = $self->_readline; # for the next sub...
return $seq_feature;
} else {
$self->throw("Error. Missing </seq_feature> tag. Got this: $$line\n");
}
}
# ==================================================================================
=head2 _process_qualifier
Title : _process_qualifier
Usage : $self->_process_qualifier
Function : Parse the data between the <qualifier></qualifier> tags.
Args : 2 scalars:
- reference to a scalar holding the value of the line to be parsed.
- reference to a data structure to store the <qualifer> data.
Returns : Nothing.
Note : Method(s) that call(s) this method : _process_seq_feature
Method(s) that this method calls : _star_tag
=cut
sub _process_qualifier {
my ($self, $line, $data_structure) = @_;
my $qualifier;
$self->_star_tag($line, \$qualifier, 'qualifier');
push @{$$data_structure->{'qualifier'}},$qualifier;
return;
# No need to return the data structure since its reference was what was modified.
}
# ==================================================================================
=head2 _process_classification
Title : _process_classification
Usage : $self->_process_classification
Function: Parse the data between the <classification></classification> tags.
Args : 2 scalars:
- reference to a scalar holding the value of the line to be parsed.
- reference to a data structure to store the <qualifer> data.
Returns : Nothing.
Note : Method(s) that call(s) this method: _process_seq_feature
Method(s) that this method calls: _helper_store_attribute_list ,
_question_mark_tag , _star_tag, _process_evidence
=cut
sub _process_classification { # NOT IN USE.
my ($self, $line, $data_structure) = @_;
my $classification = $$data_structure->{'classification'};
while ($$line =~ /<classification\s?(.*?)\s?>/) {
$self->_helper_store_attribute_list($1, \$classification);
# Zero or one <description>
$self->_question_mark_tag($line, \$classification, 'description');
# Zero or more <id_alias>
$self->_star_tag($line, \$classification, 'id_alias');
# Zero or one <evidence>
$self->_process_evidence($line, \$classification);
}
}
# ==================================================================================
sub _process_evidence { # NOT done.
my ($self, $line, $data_structure) = @_;
if ($$line =~ /<evidence>/) {
$$line = $self->_readline;
# One or more <element_id> OR One or more <comp_result>
while ($$line =~ /<(element_id|comp_result)\s?(.*?)\s?>/) {
if ($$line =~ /<element_id\s?(.*?)\s?>/) {
my $element_id;
$self->_plus_tag($line, \$element_id, 'element_id');
push @{$$data_structure->{'element_id'}}, $element_id;
} elsif ($$line =~ /<comp_result\s?(.*?)\s?>/) {
my $comp_result;
$self->_process_comp_result($line, \$comp_result, $1);
push @{$$data_structure->{'comp_result'}}, $comp_result;
}
$$line = $self->_readline;
}
}
}
# ==================================================================================
sub _process_comp_result { # NOT IN USE.
my ($self, $line, $comp_result, $attribute_line) = @_;
$self->_helper_store_attribute_list($attribute_line, $comp_result);
$$line = $self->_readline;
# Zero or one <note>
$self->_question_mark_tag($line, $comp_result, 'note');
# Zero or one <match_desc>
$self->_question_mark_tag($line, $comp_result, 'match_desc');
# Zero or one <match_align>
$self->_question_mark_tag($line, $comp_result, 'match_align');
# Zero or one <query_region>
$self->_process_query_region($line, $comp_result);
# Zero or one <match_region>
$self->_process_match_region($line, $comp_result);
# Zero or more <result_property>
$self->_star_tag($line, $comp_result, 'result_property');
# Zero or more <result_group>
$self->_process_result_group($line, $comp_result);
# Zero or more <related_annot>
$self->_process_related_annot($line, $comp_result);
}
# ==================================================================================
sub _process_related_annot { # NOT IN USE.
my ($self, $line, $data_structure) = @_;
while ($$line =~ /<related_annot\s?(.*?)\s?>/) {
my $related_annot;
# Zero or one <related_annot>
$self->_helper_store_attribute_list($1, \$related_annot);
$$line = $self->_readline;
# One or more <element_id>
my $element_id_count = 0;
while ($$line =~ /<element_id\s?(.*?)\s?>/) {
my $element_id;
$self->_helper_store_attribute_list($1, \$element_id);
push @{$related_annot->{'element_id'}}, $element_id;
$$line = $self->_readline;
++$element_id_count;
}
if ($element_id_count == 0) {
$self->throw("Error. Missing <element_id> tag. Got: $$line");
}
# Zero or more <sci_property>
$self->_star_tag($line, \$related_annot, 'sci_property');
# while ($$line =~ /<sci_property\s?(.*?)\s?>/){
#
# }
push @{$data_structure->{'related_annot'}}, $related_annot;
unless ($$line =~ /<\/related_annot>/){
$self->throw("Error. Missing </related_tag>. Got: $$line\n");
}
}
}
# ==================================================================================
sub _process_result_group { # NOT IN USE.
my ($self, $line, $data_structure) = @_;
while ($$line =~ /<result_group\s?(.*?)\s?>/) {
my $result_group = $$data_structure->{'result_group'};
$self->_helper_store_attribute_list($1, \$result_group);
my $count = 0;
$$line = $self->_readline;
while ($$line =~ /<comp_result\s?(.*?)\s?>/) {
# one or more <comp_result>
$self->_process_comp_result(\$line, \$result_group, $1);
$$line = $self->_readline;
++$count;
}
$self->throw("Error. No <comp_result></comp_result> tag! Got this: $$line")
if $count == 0;
# in the last iteration in the inner while loop, $line will
# have a value of the closing tag of 'result_group'
if ($line =~ /<\/result_group>/) {
$$line = $self->_readline;
} else {
$self->throw("Error. No </result_tag>! Got this: $$line");
}
}
}
# ==================================================================================
sub _process_match_region { # NOT IN USE.
my ($self, $line, $data_structure) = @_;
my $match_region = $data_structure->{'match_region'};
if ($$line =~ /<match_region\s?(.*?)\s?>(.*?)>/) {
$self->_helper_store_attribute_line($1, \$match_region);
$$line = $self->_readline;
# Zero or one db_id | element_id | bio_sequence
if ($$line =~ /<db_id\s?(.*?)\s?>(.*?)<\/db_id>/) {
$self->_question_mark_tag($line, \$match_region, 'db_id');
} elsif ($$line =~ /<element_id\s?(.*?)\s?>/) { # empty...
$self->_question_mark_tag($line, \$match_region, 'element_id');
} elsif ($$line =~ /<bio_sequence\s?(.*?)\s?>/) {
$match_region->{'bio_sequence'} = $self->_process_bio_sequence($line, $1);
}
$$line = $self->_readline;
if ($$line =~ /<\/match_region>/o) {
$$line = $self->_readline; # get the next line to be _processed by the next sub
return;
} else {
$self->throw("No closing tag </match_region>! Got this: $$line\n");
}
}
}
# ==================================================================================
sub _process_query_region { # NOT IN USE.
my ($self, $line, $data_structure) = @_;
my $query_region = $data_structure->{'query_region'};
if ($$line =~ /<query_region\s?(.*?)\s?>/) {
$self->_helper_store_attribute_list($1, \$query_region);
$$line = $self->_readline;
# Zero or one <db_id>
$self->_question_mark_tag($line, \$query_region, 'db_id');
if ($$line =~ /<\/query_region>/) {
$$line = $self->_readline; # get the next line to _process.
return;
} else {
$self->throw("No closing tag </query_region>. Got this: $$line\n");
}