« blib/lib/Bio/Graphics/Browser2/PluginSet.pm
↑ Summary
lib/Bio/Graphics/Browser2/Render/Slave/AWS_Balancer.pm »
| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Bio::DB::GFF::Aggregator::waba_alignment -- A WABA alignment | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | use Bio::DB::GFF; | ||
| 8 | |||
| 9 | # Open the sequence database | ||
| 10 | my $db = Bio::DB::GFF->new( -adaptor => 'dbi:mysql', | ||
| 11 | -dsn => 'dbi:mysql:elegans42', | ||
| 12 | -aggregator => ['waba_alignment'], | ||
| 13 | ); | ||
| 14 | # fetch the synthetic feature type "waba_alignment" | ||
| 15 | my @waba = $db->features('waba_alignment'); | ||
| 16 | |||
| 17 | ------------------------------------------------------------------------------------- | ||
| 18 | Aggregator method: waba_alignment | ||
| 19 | Main method: -none | ||
| 20 | Sub methods: nucleotide_match:waba_weak nucleotide_match:waba_strong | ||
| 21 | nucleotide_match::waba_coding | ||
| 22 | ------------------------------------------------------------------------------------- | ||
| 23 | |||
| 24 | =head1 DESCRIPTION | ||
| 25 | |||
| 26 | Bio::DB::GFF::Aggregator::waba_alignment handles the type of | ||
| 27 | alignments produced by Jim Kent's WABA program, and was written to be | ||
| 28 | compatible with the C elegans GFF files. It aggregates the following | ||
| 29 | feature types into an aggregate type of "waba_alignment": | ||
| 30 | |||
| 31 | nucleotide_match:waba_weak | ||
| 32 | nucleotide_match:waba_strong | ||
| 33 | nucleotide_match:waba_coding | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | package Bio::DB::GFF::Aggregator::waba_alignment; | ||
| 38 | |||
| 39 | use strict; | ||
| 40 | use Bio::DB::GFF::Aggregator; | ||
| 41 | use constant CONTINUITY_BIN => 5000; | ||
| 42 | |||
| 43 | use vars qw($VERSION @ISA); | ||
| 44 | @ISA = qw(Bio::DB::GFF::Aggregator); | ||
| 45 | |||
| 46 | $VERSION = '0.20'; | ||
| 47 | |||
| 48 | =head2 method | ||
| 49 | |||
| 50 | Title : method | ||
| 51 | Usage : $aggregator->method | ||
| 52 | Function: return the method for the composite object | ||
| 53 | Returns : the string "waba_alignment" | ||
| 54 | Args : none | ||
| 55 | Status : Public | ||
| 56 | |||
| 57 | =cut | ||
| 58 | |||
| 59 | sub method { 'waba_alignment' } | ||
| 60 | |||
| 61 | =head2 part_names | ||
| 62 | |||
| 63 | Title : part_names | ||
| 64 | Usage : $aggregator->part_names | ||
| 65 | Function: return the methods for the sub-parts | ||
| 66 | Returns : the list "nucleotide_match:waba_weak", "nucleotide_match:waba_strong" and "nucleotide_match:waba_coding" | ||
| 67 | Args : none | ||
| 68 | Status : Public | ||
| 69 | |||
| 70 | =cut | ||
| 71 | |||
| 72 | sub part_names { | ||
| 73 | return qw( | ||
| 74 | nucleotide_match:waba_weak | ||
| 75 | nucleotide_match:waba_strong | ||
| 76 | nucleotide_match:waba_coding | ||
| 77 | ); | ||
| 78 | } | ||
| 79 | |||
| 80 | # we modify the aggregate method so that significant breaks in continuity | ||
| 81 | # result in distinct groups. This is done by binning the absolute difference | ||
| 82 | # between the source and target coordinates. Mostly contiguous | ||
| 83 | sub aggregate { | ||
| 84 | my $self = shift; | ||
| 85 | my $features = shift; | ||
| 86 | my $factory = shift; | ||
| 87 | |||
| 88 | my $meth = $self->method; | ||
| 89 | my $main_method = $self->get_main_name; | ||
| 90 | my $matchsub = $self->match_sub($factory) or return; | ||
| 91 | my $passthru = $self->passthru_sub($factory); | ||
| 92 | |||
| 93 | my (%aggregates,@result); | ||
| 94 | for my $feature (@$features) { | ||
| 95 | if ($feature->group && $matchsub->($feature)) { | ||
| 96 | my $bin = get_bin($feature); | ||
| 97 | if ($main_method && lc $feature->method eq lc $main_method) { | ||
| 98 | $aggregates{$feature->group,$feature->ref,$bin}{base} ||= $feature->clone; | ||
| 99 | } else { | ||
| 100 | push @{$aggregates{$feature->group,$feature->ref,$bin}{subparts}},$feature; | ||
| 101 | } | ||
| 102 | push @result,$feature if $passthru && $passthru->($feature); | ||
| 103 | |||
| 104 | } else { | ||
| 105 | push @result,$feature; | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | # aggregate components | ||
| 110 | my $pseudo_method = $self->get_method; | ||
| 111 | my $require_whole_object = $self->require_whole_object; | ||
| 112 | foreach (keys %aggregates) { | ||
| 113 | if ($require_whole_object && $self->components) { | ||
| 114 | next unless $aggregates{$_}{base} && $aggregates{$_}{subparts}; | ||
| 115 | } | ||
| 116 | my $base = $aggregates{$_}{base}; | ||
| 117 | unless ($base) { # no base, so create one | ||
| 118 | my $first = $aggregates{$_}{subparts}[0]; | ||
| 119 | $base = $first->clone; # to inherit parent coordinate system, etc | ||
| 120 | $base->score(undef); | ||
| 121 | $base->phase(undef); | ||
| 122 | } | ||
| 123 | $base->method($pseudo_method); | ||
| 124 | $base->source('waba') if $pseudo_method eq $meth; | ||
| 125 | $base->add_subfeature($_) foreach @{$aggregates{$_}{subparts}}; | ||
| 126 | $base->adjust_bounds; | ||
| 127 | $base->compound(1); # set the compound flag | ||
| 128 | push @result,$base; | ||
| 129 | } | ||
| 130 | @$features = @result; | ||
| 131 | } | ||
| 132 | |||
| 133 | sub get_bin { | ||
| 134 | my $feature = shift; | ||
| 135 | my $target = $feature->target or return 0; | ||
| 136 | my ($start,$end) = ($target->start,$target->end); | ||
| 137 | my $distance = $end > $start ? $target->start-$feature->start : $target->start+$feature->start; | ||
| 138 | return int(abs($distance)/CONTINUITY_BIN); | ||
| 139 | } | ||
| 140 | |||
| 141 | 1; | ||
| 142 | __END__ |