Repository navigation
Expand file tree
/
Copy pathEGlite.pm
More file actions
868 lines (781 loc) · 23.5 KB
/
Copy pathEGlite.pm
File metadata and controls
868 lines (781 loc) · 23.5 KB
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
package EGlite;
use strict;
use overload '""' => '_overload';
###############################################################################
# EGlite
###############################################################################
sub new {
my ($class, $fh) = @_;
if (ref $fh !~ /GLOB/)
{die "EGlite error: new expects a GLOB reference not $fh\n"}
my $this = bless {};
$this->{FH} = $fh;
$this->{LASTLINE} = "";
if (my $status = $this->_parseHeader) {
# there are alignments
$this->{REPORT_DONE} = 0;
if ($status == 64) { # empty report
return $status;
}
die if not defined $this->{GENOME};
die if not defined $this->{EST};
if ($this->_parseAlignment) {
# there is alignment
$this->{REPORT_DONE} = 1;
} else {
return 0;
}
}
else {
# empty report
$this->{REPORT_DONE} = 1;
return 0;
}
return $this;
}
sub genome {shift->{GENOME}}
sub est {shift->{EST}}
sub score {shift->{SCORE}}
sub pi {shift->{PI}}
sub alignment {shift->{ALIGNMENT}}
sub gb {shift->{GENOME_BEGIN}}
sub ge {shift->{GENOME_END}}
sub eb {shift->{EST_BEGIN}}
sub ee {shift->{EST_END}}
sub genomeBegin {shift->{GENOME_BEGIN}}
sub genomeEnd {shift->{GENOME_END}}
sub estBegin {shift->{EST_BEGIN}}
sub estEnd {shift->{EST_END}}
sub genomeDirection {shift->{GEN_DIRECTION}}
sub estDirection {shift->{EST_DIRECTION}}
sub geneOrientation {shift->{SPLICE_DIRECTION}}
sub map_est_to_genome {
my ($this, $pos) = @_;
my $element_ref = $this->{ELEMENTS};
my @elements = @$element_ref;
if ($#elements < 0) {
return -1;
}
if ($pos < $this->eb || $pos > $this->ee) {
print "$pos in est is not found in alignment\n";
return -1;
}
foreach my $element (@elements) {
if ($pos >= $element->eb && $pos <= $element->ee) {
return $element->map_est_to_genome($pos);
}
}
print "I shouldn't be here. Tell Mani!\n";
return -1;
}
sub map_genome_to_est {
my ($this, $pos) = @_;
my $element_ref = $this->{ELEMENTS};
my @elements = @$element_ref;
if ($#elements < 0) {
return -1;
}
if ($pos < $this->gb || $pos > $this->ge) {
print "$pos in genome is not found in alignment\n";
return -1;
}
foreach my $element (@elements) {
if ($pos >= $element->gb && $pos <= $element->ge) {
return $element->map_genome_to_est($pos);
}
}
print "I shouldn't be here. Tell Mani!\n";
return -1;
}
sub countElements {
my ($this) = @_;
my $elements = $this->{ELEMENTS};
my @elements = @$elements;
return $#elements + 1;
}
sub hasMoreElements {
my ($this) = @_;
my $buf = $this->{ELEMENTSBUFFER};
my @buf = @$buf;
if( defined $buf[0]){
return 1;
}else{
return 0;
}
}
sub hasIntron {
my ($this) = @_;
my $elements = $this->{ELEMENTS};
if ($#$elements <= 1) {
return 0;
} else {
return 1;
}
}
sub nextElement {
my ($this) = @_;
# $this->_fastForward or return 0;
my $buffer = $this->{ELEMENTSBUFFER};
my $element = shift (@$buffer);
return 0 unless defined $element;
$this->{ELEMENTSBUFFER} = $buffer;
return $element;
}
sub resetElements {
my ($this) = @_;
my $elements = $this->{ELEMENTS};
my @elements = @$elements;
my @buffer = @elements;
$this->{ELEMENTSBUFFER} = \@buffer;
#print $this->{ELEMENTSBUFFER}, "\n", $this->{ELEMENTS}, "\n";
return 0 unless defined \@buffer;
return 1;
}
sub _parseHeader {
my ($this) = @_;
my $FH = $this->{FH};
my @introns = ();
my @exons = ();
my @elements = ();
my @buffer = ();
while(<$FH>) {
if ($_ =~ /Note Best alignment is between (reversed|forward) est and (reversed|forward) genome, (but|and) splice\s+sites imply\s+(forward gene|REVERSED GENE)/ ) {
$this->{EST_DIRECTION} = $1;
$this->{GEN_DIRECTION} = $2;
if ($4 eq "forward gene") {
$this->{SPLICE_DIRECTION} = '+';
} elsif ($4 eq "REVERSED GENE") {
$this->{SPLICE_DIRECTION} = '-';
} else {
die "Unknown gene orientation found in alignment: $4\n";
}
}
elsif ($_ =~ /^Exon\s/) {
my (undef, $score, $pi, $gb, $ge, $genome, $eb, $ee, $est) = split (/\s+/);
my $exon = EGlite::Exon::new( GENOME=>$genome,
EST=>$est,
GB=>$gb,
'GE'=>$ge,
EB=>$eb,
EE=>$ee,
SCORE=>$score,
PI=>$pi,
DIRECTION=>".",
PARENT=>$this);
push @exons, $exon;
push @elements, $exon;
$this->{LAST_EST_BASE} = $ee; # Track intron position in EST coordinates
}
elsif ($_ =~ /^Span\s/) {
my (undef, $score, $pi, $gb, $ge, undef, $eb, $ee, undef) = split (/\s+/);
$this->{GENOME_BEGIN} = $gb;
$this->{GENOME_END} = $ge;
$this->{EST_BEGIN} = $eb;
$this->{EST_END} = $ee;
$this->{SCORE} = $score;
$this->{PI} = $pi;
}
elsif ($_ =~ /^(.)Intron\s/) {
my $direction = $1;
my (undef, $score, $pi, $gb, $ge, $genome) = split (/\s+/);
my ($eb, $ee) = ($this->{LAST_EST_BASE} + 1, $this->{LAST_EST_BASE});
my $intron = EGlite::Intron::new( GENOME=>$genome,
GB=>$gb,
'GE'=>$ge,
EB=>$eb,
EE=>$ee,
SCORE=>$score,
PI=>$pi,
DIRECTION=>$direction,
PARENT=>$this);
push @introns, $intron;
push @elements, $intron;
}
elsif ($_ =~ /^(.+)\s+vs\s+(.+):/) {
$this->{LASTLINE} = $_;
$this->{GENOME} = $1;
$this->{EST} = $2;
$this->{EXONS} = \@exons;
$this->{INTRONS} = \@introns;
$this->{ELEMENTS} = \@elements;
$this->resetElements; # Sets ELEMENTBUFFER
return 1;
}
elsif ($_ =~ /^Alignment Score: (\d+)/) {
$this->{LASTLINE} = $_;
$this->{REPORT_DONE} = 1;
$this->{SCORE} = $1;
return 64; # there's nothing in the report
}
}
return 0 unless (defined $this->{GENOME} && defined $this->{EST});
}
sub _parseAlignment {
my ($this) = @_;
return 0 if $this->{ALIGN_ALL_PARSED};
my $est = $this->{EST};
my $genome = $this->{GENOME};
my $FH = $this->{FH};
#######################
# get alignment lines #
#######################
my @algnline;
while(<$FH>) {
die if /^BLAST/;
#print "$_";
if ($_ =~ /^WARNING:|^NOTE:|^ERROR:|^FATAL:/) {
while(<$FH>) {last if $_ !~ /\S/}
}
elsif ($_ !~ /\S/) {next}
elsif ($_ =~ /^EXIT CODE/) {last}
elsif ($_ =~ /^Alignment\s+Score:\s+([0-9\-\.]+)\s+$/) {
$this->{LASTLINE} = $_;
$this->{SCORE} = $1;
$this->{ALIGN_ALL_PARSED} = 1;
#print "In Last Line\n";
last;
}
#elsif ($_ =~ /^\s*($genome)\s+\d+\s+/) {}
elsif ($_ =~ /^\s*(\S+)\s+\d+\s+/) {
#print "In genome";
if ($1 eq $genome){
push @algnline, $_; # store the genome line
my $l1 = <$FH>; # either alignment line or est line
#if ($l1 =~ /^\s*($est)\s+\d+\s+/) {
if ($l1 =~ /^\s*(\S+)\s+\d+\s+/) {
if ($1 eq $est){
push @algnline, ""; # dummy line, this is a -noseq option
push @algnline, $l1; # so store a fake alignment and real sbjct
next;
}
}
push @algnline, $l1; # grab/store the alignment line
my $l2 = <$FH>; push @algnline, $l2; # grab/store the est line
}
}
}
#########################
# parse alignment lines #
#########################
my ($gl, $el, $as) = ("", "", "");
my ($gb, $ge, $eb, $ee) = (0,0,0,0);
my (@GL, @EL, @AS); # for better memory management
# handle lines in sets of 3: genome, alignment, est
for(my $i=0;$i<@algnline;$i+=3) {
#print "In..";
###############################
# parse the genome line
###############################
$algnline[$i] =~ /^\s*(\S+)\s+(\d+)\s+(\S+)\s+(\d+)/;
if ($1 ne $genome){ return 0;}
return 0 unless defined $4;
$gl = $3; $gb = $2 unless $gb; $ge = $4;
my $number = $2; # Catch the est_genome glitch that has 6 char width for coordinates
###############################
# parse the alignment line
###############################
# Found a bug where there was one base "C" in the alignment
# and the name of the sequence had a C in it too. So index()
# picked up the C in the name. So I have to make sure that
# index() starts after $gb
my $offset = index($algnline[$i], $gl, index($algnline[$i], $number, 0));
# est_genome has hardcoded 6 char width for coordinates which breaks here.
if (length($number) > 6) {
$offset -= (length($number) - 6);
}
if ($algnline[$i+1]) {
$as = substr($algnline[$i+1], $offset, CORE::length($gl));
}
###############################
# parse the est line
###############################
$algnline[$i+2] =~ /^\s*(\S+)\s+(\d+)\s+(\S+)\s+(\d+)/;
if ($1 ne $est){ return 0;}
return 0 unless defined $4;
$el = $3; $eb = $2 unless $eb; $ee = $4;
$gl =~ s/[^ATGCNatgcn\-\.]//;
push @GL, $gl; push @EL, $el; push @AS, $as;
#print "PARSER:\n$gl\n$as\n$el\n";
}
########################
# the Alignment object #
########################
$gl = join("", @GL);
$el = join("", @EL);
$as = join("", @AS);
#print "$gl\n$as\n$el\n";
my $ggaps = $gl =~ tr/-/-/;
my $egaps = $el =~ tr/-/-/;
my $match = $as;
$match =~ s/[^|]//g;
$match = length $match;
my $positive = "";
my $length = 0;
my $alignment = EGlite::Alignment::new( $this->{SCORE}, $match, $positive, $length,
$gb, $ge, $eb, $ee, $gl, $el, $as, $ggaps, $egaps);
my $alignmentbuf = EGlite::Alignment::new( $this->{SCORE}, $match, $positive, $length,
$gb, $ge, $eb, $ee, $gl, $el, $as, $ggaps, $egaps);
$this->{ALIGNMENT} = $alignment;
my $locus;
$this->resetElements;
my $elements = $this->{ELEMENTS};
while (my $element = $this->nextElement) {
if ($element->type eq "EXON") {
$locus = index( $alignmentbuf->ea, ".");
if ($locus == -1) { $locus = length $alignmentbuf->ea;}
} elsif ($element->type eq "INTRON") {
$alignmentbuf->ea =~ /\.+(\S+)/;
my $next_exon = $1;
if (defined $next_exon){
$locus = index( $alignmentbuf->ea, $next_exon);
}
if ($locus == -1) { warn "Possible error in nextElement()\n"; }
} else {die "Unexpected element\n";}
# print $alignmentbuf->ea."\n";
# print $alignmentbuf->as."\n";
# print $alignmentbuf->ga."\n";
my $ea = substr( $alignmentbuf->ea, 0, $locus);
my $as = substr( $alignmentbuf->as, 0, $locus);
my $ga = substr( $alignmentbuf->ga, 0, $locus);
$alignmentbuf->setEA( substr( $alignmentbuf->ea, $locus));
$alignmentbuf->setAS( substr( $alignmentbuf->as, $locus));
$alignmentbuf->setGA( substr( $alignmentbuf->ga, $locus));
$element->setEA( $ea);
$element->setAS( $as);
$element->setGA( $ga);
#print "alignment:\n$ga\n$as\n$ea\n";
shift @$elements;
push @$elements, $element;
}
$this->resetElements;
return 1;
}
sub _fastForward {
my ($this) = @_;
return 0 if $this->{REPORT_DONE};
return 1 if $this->{LASTLINE} =~ /^>/;
if ($this->{LASTLINE} =~ /^Parameters|^\s+Database:/) {
$this->{REPORT_DONE} = 1;
return 1;
}
my $FH = $this->{FH};
while(<$FH>) {
die if /^BLAST/;
if ($_ =~ /^>|^Parameters|^\s+Database:/) {
$this->{LASTLINE} = $_;
$this->{REPORT_DONE} = 1;
return 1;
}
}
warn "Possible parse error in _fastForward in EGlite.pm\n";
}
sub _overload {
my ($this) = @_;
return $this->{GENOME} . " vs. " . $this->{EST};
}
###############################################################################
# EGlite::Element
###############################################################################
package EGlite::Element;
use overload '""' => 'name';
sub new {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
my $self = { @_ }; # Remaining args become attributes
bless($self, $class); # Bestow objecthood
$self->{HSP_ALL_PARSED} = 0;
return $self;
}
# ($self->{GENOME}, $self->{EST}, $self->{GB}, $self->{GE}, $self->{EB}, $self->{EE}, $self->{SCORE}, $self->{PI},
# $self->{PARENT}) = @_;
sub name {
my $self = shift;
return $self->{GENOME}." vs ".$self->{PARENT}->{EST};
}
sub length {
my $self = shift;
return $self->{GE} - $self->{GB} + 1;
}
sub type {shift->{TYPE}}
sub genome {shift->{GENOME}}
sub est {shift->{PARENT}->{EST}}
sub genomeBegin {shift->{GB}}
sub genomeEnd {shift->{GE}}
sub estBegin {shift->{EB}}
sub estEnd {shift->{EE}}
sub genomeAlignment {shift->{GL}}
sub estAlignment {shift->{EL}}
sub alignmentString {shift->{AS}}
sub direction {shift->{DIRECTION}}
sub gb {shift->{GB}}
sub ge {shift->{GE}}
sub eb {shift->{EB}}
sub ee {shift->{EE}}
sub ga {shift->{GL}}
sub ea {shift->{EL}}
sub as {shift->{AS}}
sub score {shift->{SCORE}}
sub pi {shift->{PI}}
sub setEA {
my $self = shift;
$self->{EL} = shift;
}
sub setAS {
my $self = shift;
$self->{AS} = shift;
}
sub setGA {
my $self = shift;
$self->{GL} = shift;
}
sub alignment {
my $self = shift;
return $self->{GL}."\n".$self->{AS}."\n".$self->{EL};
}
sub strval {
my $self = shift;
my $string = sprintf "%9d %s %9d\n%9s %s %9s", $self->gb, $self->ga, $self->ge, " ", $self->as, " ";
if ($self->type eq "EXON") {
$string = sprintf "%s\n%9d %s %9d", $string, $self->eb, $self->ea, $self->ee;
}
return $string;
}
sub map_est_to_genome {
my ($element, $pos) = @_;
if ($element->type ne "EXON") {
print "Cannot map an intron from est coordinates to genome coordinates\n";
return -1;
}
my $offset = $pos - $element->eb;
my @genome = split(//, $element->ga);
my @est = split(//, $element->ea);
my $moved = -1;
my $upper_bound = -1;
if ($pos < $element->eb || $pos > $element->ee) {
print "$pos Out of range:".$element->est."\n";
return -1;
}
for (my $i = 0; $i < scalar(@est); $i++) {
if ($est[$i] ne "-") {
$moved++;
}
if ($moved == $offset) {
$upper_bound = $i;
$moved = $i;
#print "moved=$moved; upper_bound=$upper_bound; est=$est[$moved]\n";
last; # Hit the position
}
}
if ($upper_bound == -1) {
print "Cannot find $pos\n";
return -1;
}
for (my $j = 0; $j <= $upper_bound ; $j++) {
if ($genome[$j] eq "-") {
$moved--;
}
}
#print "moved=$moved; upper_bound=$upper_bound; genome=$genome[$moved]\n";
if ($genome[$upper_bound] eq "-") {
$moved += 0.5;
warn "$element: EST POSITION $pos MAPS TO A GAP IN GENOME\n";
}
return ($element->gb + $moved);
}
sub map_genome_to_est {
my ($element, $pos) = @_;
if ($element->type ne "EXON") {
print "Cannot map $pos in intron from genome coordinates to est coordinates\n";
return -1;
}
my $offset = $pos - $element->gb;
my @genome = split(//, $element->ga);
my @est = split(//, $element->ea);
my $moved = -1;
my $upper_bound = -1;
if ($pos < $element->gb || $pos > $element->ge) {
print "$pos Out of range:".$element->genome."\n";
return -1;
}
for (my $i = 0; $i < scalar(@genome); $i++) {
if ($genome[$i] ne "-") {
$moved++;
}
if ($moved == $offset) {
$upper_bound = $i;
$moved = $i;
#print "moved=$moved; upper_bound=$upper_bound; genome=$genome[$moved]\n";
last; # Hit the position
}
}
if ($upper_bound == -1) {
print "Cannot find $pos\n";
return -1;
}
for (my $j = 0; $j <= $upper_bound ; $j++) {
if ($est[$j] eq "-") {
$moved--;
}
}
#print "moved=$moved; upper_bound=$upper_bound; genome=$genome[$moved]\n";
if ($est[$upper_bound] eq "-") {
$moved += 0.5;
warn "$element: GENOME POSITION $pos MAPS TO A GAP IN EST\n";
}
return ($element->eb + $moved);
}
###############################################################################
# EGlite::Exon
###############################################################################
package EGlite::Exon;
our @ISA = "EGlite::Element";
sub new {
my $self = EGlite::Element->new(@_, TYPE => "EXON");
#($self->{GENOME}, $self->{EST}, $self->{GB}, $self->{GE}, $self->{EB}, $self->{EE}, $self->{SCORE}, $self->{PI},
# $self->{PARENT}, "EXON") = @_;
$self->{HSP_ALL_PARSED} = 0;
return $self;
}
###############################################################################
# EGlite::Intron
###############################################################################
package EGlite::Intron;
our @ISA = "EGlite::Element";
sub new {
my $self = EGlite::Element->new(@_, TYPE => "INTRON");
$self->{HSP_ALL_PARSED} = 0;
return $self;
}
sub est {
my $self = shift;
return $self->{PARENT}->{EST};
}
###############################################################################
# EGlite::Alignment
###############################################################################
package EGlite::Alignment;
use overload '""' => '_overload';
sub new {
my $alignment = bless {};
($alignment->{SCORE},
$alignment->{MATCH}, $alignment->{POSITIVE}, $alignment->{LENGTH},
$alignment->{GB}, $alignment->{GE}, $alignment->{EB}, $alignment->{EE},
$alignment->{GL}, $alignment->{EL}, $alignment->{AS}, $alignment->{GG}, $alignment->{EG}) = @_;
$alignment->{PERCENT} = 0; #int(1000 * $alignment->{MATCH}/$alignment->{LENGTH})/10;
return $alignment;
}
sub _overload {
my $alignment = shift;
return $alignment->ga."\n".$alignment->as."\n".$alignment->ea;
}
sub score {shift->{SCORE}}
sub percent {shift->{PERCENT}}
sub match {shift->{MATCH}}
sub length {shift->{LENGTH}}
sub genomeBegin {shift->{GB}}
sub genomeEnd {shift->{GE}}
sub estBegin {shift->{EB}}
sub estEnd {shift->{EE}}
sub genomeAlignment {shift->{GL}}
sub estAlignment {shift->{EL}}
sub alignmentString {shift->{AS}}
sub genomeGaps {shift->{GG}}
sub estGaps {shift->{EG}}
sub gb {shift->{GB}}
sub ge {shift->{GE}}
sub eb {shift->{EB}}
sub ee {shift->{EE}}
sub ga {shift->{GL}}
sub ea {shift->{EL}}
sub as {shift->{AS}}
sub gg {shift->{GG}}
sub eg {shift->{EG}}
sub setEA {
my $self = shift;
$self->{EL} = shift;
}
sub setAS {
my $self = shift;
$self->{AS} = shift;
}
sub setGA {
my $self = shift;
$self->{GL} = shift;
}
###############################################################################
# EGlite::Multi
###############################################################################
package EGlite::Multi;
sub new {
my ($class, $fh) = @_;
if (ref $fh !~ /GLOB/)
{die "EGlite error: new expects a GLOB reference not $fh\n"}
my $this = bless {};
$this->{FH} = $fh;
return $this;
}
sub nextReport {
my ($this) = @_;
my $FH = $this->{FH};
my $blast = new EGlite($this->{FH});
return $blast;
}
1;
__END__
=head1 NAME
EGlite - Lightweight est2genome parser
=head1 SYNOPSIS
use EGlite;
# single E2G report
my $report = new EGlite(\*STDIN);
$report->genome;
$report->est;
$report->score;
$report->pi;
$report->alignment;
$report->genomeBegin;
$report->genomeEnd;
$report->estBegin;
$report->estEnd;
$report->genomeDirection;
$report->estDirection;
$report->gb;
$report->ge;
$report->eb;
$report->ee;
$report->hasIntron;
$report->countElements;
$report->map_est_to_genome;
if( $report->hasIntron) {
#do something with introns
if (my $alignment = $report->alignment) {
$alignment->score;
$alignment->percent;
$alignment->match;
$alignment->length;
$alignment->genomeBegin;
$alignment->genomeEnd;
$alignment->estBegin;
$alignment->estEnd;
$alignment->genomeAlignment;
$alignment->estAlignment;
$alignment->alignmentString;
$alignment->genomeGaps;
$alignment->estGaps;
}
}
while(my $element = $report->nextElement) {
$element->name;
$element->length;
$element->type; #"EXON" or "INTRON"
$element->genome;
$element->est;
$element->genomeBegin;
$element->genomeEnd;
$element->estBegin;
$element->estEnd;
$element->genomeAlignment;
$element->estAlignment;
$element->alignmentString;
$element->gb;
$element->ge;
$element->eb;
$element->ee;
$element->ga;
$element->ea;
$element->as;
$element->score;
$element->pi;
$element->map_est_to_genome;# Map a base in EST (inside this element) to genomic coordinate
# (Returns n+0.5 if the EST base is in a genomic gap after n)
}
$report->resetElements;
while($report->hasMoreElements) {
my $element = $report->nextElement;
}
$report->resetElements;
my $count = $report->countElements;
for( my $i=0; $i < $count; $i++){
my $element = $report->nextElement;
}
# multiple (concatenated) E2G reports
my $multiple_report = new EGlite::Multi(\*STDIN);
while(my $report = $multiple_report->nextReport) {
while(my $element = $report->nextElement) {
#whatever
}
}
=head1 DESCRIPTION
EGlite is a (pseudo-)lightweight package for parsing est2genome reports.
est2genome is a program to align Expressed Sequence Tags (EST) against a
genomic sequence. The output gives detailed positional information about
(potential) exons and introns supported by the EST sequence. EGlite parses
this output and provides a handle on the relevant and required information.
=head2 Object
EGlite has three kinds of objects, the report, the element, and the alignment.
The element has two subtypes: exon and intron. To create a new report, you
pass a filehandle reference to the EGlite constructor.
my $report = new EGlite(\*STDIN); # or any other filehandle
The report has many attributes and methods.
$report->genome; # genomic sequence name
$report->est; # EST sequence name
$report->score; # Score of the overall alignment
$report->pi; # Percentage identity in the overall alignment
$report->alignment; # The alignment object
$report->genomeBegin; # The start co-ordinate of the genomic alignment
$report->genomeEnd; # The end co-ordinate of the genomic alignment
$report->estBegin; # The start co-ordinate of the EST alignment
$report->estEnd; # The end co-ordinate of the EST alignment
$report->genomeDirection;
$report->estDirection;
$report->gb;
$report->ge;
$report->eb;
$report->ee;
$report->hasIntron; # Does the alignment contain an intron?
$report->resetElements; # Resets the pointer of current element to the first element
$report->hasMoreElements; # Does the alignment has more elements?
$report->nextElement; # Next element in the alignment
$report->map_est_to_genome;# Map a base in EST to genomic coordinate
# (Returns -1 in case of error)
# (Returns n+0.5 if the EST base is in a genomic gap after n)
my $alignment = $report->alignment;
print "$alignment";
The output of such code might look like this:
agcag-t
| || |
atcatct
The traditional access through a lightweight parser is using:
while(my $element = $report->nextElement) {
#do something with $element
}
Alternatively,
$report->resetElements;
while($report->hasMoreElements) {
my $element = $report->nextElement;
}
or
$report->resetElements;
my $count = $report->countElements;
for( my $i=0; $i < $count; $i++){
my $element = $report->nextElement;
}
give you more control over the iterations. You can stop the iteration
at your convenience using these two constructs.
=head2 Concatenated est2genome reports
You can step through multiple est2genome reports if you have a file of concatenated
est2genome reports using the following construct.
my $multiple_report = new EGlite::Multi(\*STDIN);
while(my $report = $multiple_report->nextReport) {
while(my $element = $report->nextElement) {
}
}
=head1 AUTHOR
Manimozhiyan Arumugam (mozhiyan@cse.wustl.edu)
=head1 ACKNOWLEDGEMENTS
This program was adapted from Ian Korf's BPlite.pm.
This software was developed at the Computational Genomics Laboratory at Washington
Univeristy, St. Louis, MO.
=head1 DISCLAIMER
This software is provided "as is" without warranty of any kind.
=cut