| 1 | ######### | ||
| 2 | # Author: Jessica Severin | ||
| 3 | # Maintainer: Jessica Severin | ||
| 4 | # Created: 2008-08-27 | ||
| 5 | # Last Modified: $Date: 2008/10/29 10:22:15 $ | ||
| 6 | # | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | Bio::Das::ProServer::SourceAdaptor::edgeexpress | ||
| 11 | Auto-config ProServer that talks with an EdgeExpress database | ||
| 12 | |||
| 13 | =head1 VERSION | ||
| 14 | |||
| 15 | $LastChangedRevision: 2 $ | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | An auto-config ProServer that talks with an EdgeExpress database | ||
| 20 | - auto-configs segments and sources from the database | ||
| 21 | - Builds simple DAS features from the EdgeExpress database | ||
| 22 | - uses EdgeExpress perl API for enhanced speed and smart caching | ||
| 23 | |||
| 24 | =head1 DESCRIPTION | ||
| 25 | |||
| 26 | =head2 capabilities | ||
| 27 | |||
| 28 | =head1 DIAGNOSTICS | ||
| 29 | |||
| 30 | =head1 CONFIGURATION AND ENVIRONMENT | ||
| 31 | |||
| 32 | [my_eedb] | ||
| 33 | state = on | ||
| 34 | adaptor = edgeexpress | ||
| 35 | transport = edgeexpress | ||
| 36 | eedb_url = mysql://<user>:<pass>@<host>:<port optional>/<database_name> | ||
| 37 | assembly = <assembly name as used in the eeDB> #eeDB is multi_species, each DAS source is not | ||
| 38 | description = description of the EdgeExpressDB this is configured for | ||
| 39 | |||
| 40 | =head1 DEPENDENCIES | ||
| 41 | |||
| 42 | ProServer | ||
| 43 | Bio::Das::ProServer::SourceAdaptor | ||
| 44 | |||
| 45 | EdgeExpress | ||
| 46 | EEDB::FeatureSource; | ||
| 47 | EEDB::Feature; | ||
| 48 | EEDB::Assembly; | ||
| 49 | EEDB::Chrom; | ||
| 50 | |||
| 51 | =head1 INCOMPATIBILITIES | ||
| 52 | |||
| 53 | =head1 BUGS AND LIMITATIONS | ||
| 54 | |||
| 55 | =head1 AUTHOR | ||
| 56 | |||
| 57 | Jessica Severin <severin@gsc.riken.jp>. | ||
| 58 | |||
| 59 | =head1 LICENSE AND COPYRIGHT | ||
| 60 | |||
| 61 | =head1 APPENDIX | ||
| 62 | |||
| 63 | The rest of the documentation details each of the object methods. | ||
| 64 | Internal methods are usually preceded with a _ | ||
| 65 | |||
| 66 | =head1 SUBROUTINES/METHODS | ||
| 67 | |||
| 68 | =cut | ||
| 69 | |||
| 70 | package Bio::Das::ProServer::SourceAdaptor::edgeexpress; | ||
| 71 | use strict; | ||
| 72 | use warnings; | ||
| 73 | |||
| 74 | use EEDB::FeatureSource; | ||
| 75 | use EEDB::Feature; | ||
| 76 | use EEDB::Assembly; | ||
| 77 | use EEDB::Chrom; | ||
| 78 | |||
| 79 | use base qw(Bio::Das::ProServer::SourceAdaptor); | ||
| 80 | |||
| 81 | our $VERSION = do { my @r = (q$Revision: 1.10 $ =~ /\d+/mxg); sprintf '%d.'.'%03d' x $#r, @r }; | ||
| 82 | |||
| 83 | sub capabilities { | ||
| 84 | return { | ||
| 85 | features => '1.0', | ||
| 86 | types => '1.0', | ||
| 87 | entry_points => '1.0' | ||
| 88 | }; | ||
| 89 | } | ||
| 90 | |||
| 91 | #################################### | ||
| 92 | |||
| 93 | sub build_entry_points { | ||
| 94 | my $self = shift; | ||
| 95 | #printf("edgeexpress::build_entry_points called\n"); | ||
| 96 | |||
| 97 | my $asm = $self->config->{'assembly'}; | ||
| 98 | |||
| 99 | my $chroms = EEDB::Chrom->fetch_all_by_assembly_name($self->transport->database, $asm); | ||
| 100 | my @segments; | ||
| 101 | foreach my $chrom (sort {$b->chrom_length <=> $a->chrom_length} @$chroms) { | ||
| 102 | my $segment = { | ||
| 103 | 'segment' => $chrom->chrom_name, | ||
| 104 | 'length' => $chrom->chrom_length, | ||
| 105 | #'start' => $ | ||
| 106 | #'stop' => $ | ||
| 107 | #'ori' => $ | ||
| 108 | 'subparts' => 'yes' | ||
| 109 | }; | ||
| 110 | push @segments, $segment; | ||
| 111 | } | ||
| 112 | return @segments; | ||
| 113 | } | ||
| 114 | |||
| 115 | |||
| 116 | sub known_segments { | ||
| 117 | my $self = shift; | ||
| 118 | #printf("edgeexpress::known_segments called\n"); | ||
| 119 | |||
| 120 | my $asm = $self->config->{'assembly'}; | ||
| 121 | |||
| 122 | my $chroms = EEDB::Chrom->fetch_all_by_assembly_name($self->transport->database, $asm); | ||
| 123 | my @segments; | ||
| 124 | foreach my $chrom (sort {$a->chrom_name cmp $b->chrom_name} @$chroms) { | ||
| 125 | push @segments, $chrom->chrom_name; | ||
| 126 | } | ||
| 127 | return @segments; | ||
| 128 | } | ||
| 129 | |||
| 130 | |||
| 131 | ############################### | ||
| 132 | |||
| 133 | sub das_types { | ||
| 134 | my ($self, $opts) = @_; | ||
| 135 | printf("\nhijack das_types before going back to superclass\n"); | ||
| 136 | print($opts, "\n"); | ||
| 137 | foreach my $key (keys(%$opts)) { | ||
| 138 | printf(" %s => %s\n", $key, $opts->{$key}); | ||
| 139 | } | ||
| 140 | |||
| 141 | #first clear from last feature request | ||
| 142 | $self->{'feature_filter_type'} = undef; | ||
| 143 | if($opts->{'type'}) { | ||
| 144 | $self->{'feature_filter_type'} = $opts->{'type'}; | ||
| 145 | } | ||
| 146 | return $self->SUPER::das_types($opts); | ||
| 147 | } | ||
| 148 | |||
| 149 | sub build_types { | ||
| 150 | my ($self, @args) = @_; | ||
| 151 | |||
| 152 | #printf("build_types\n"); | ||
| 153 | my $type_filter = $self->{'feature_filter_type'}; | ||
| 154 | |||
| 155 | my @return_types = (); | ||
| 156 | my $fsrcs = EEDB::FeatureSource->fetch_all($self->transport->database); | ||
| 157 | foreach my $fsrc (@$fsrcs) { | ||
| 158 | next unless($fsrc->is_active and $fsrc->is_active eq 'y'); | ||
| 159 | next unless($fsrc->is_visible and $fsrc->is_visible eq 'y'); | ||
| 160 | next if(defined($type_filter) and ($type_filter ne $fsrc->name)); | ||
| 161 | $fsrc->display_info; | ||
| 162 | |||
| 163 | if(scalar @args) { | ||
| 164 | for (@args) { | ||
| 165 | my ($seg, $start, $end) = @{$_}{qw(segment start end)}; | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | my $type = { | ||
| 170 | 'count' => $fsrc->get_feature_count, | ||
| 171 | 'type' => $fsrc->name, | ||
| 172 | 'category' => $fsrc->category, | ||
| 173 | 'description' => $fsrc->comments, | ||
| 174 | # 'method' => $ | ||
| 175 | # 'c_ontology' => $ | ||
| 176 | # 'evidence' => $ | ||
| 177 | # 'e_ontology' => $ | ||
| 178 | 'count' => $fsrc->get_feature_count | ||
| 179 | }; | ||
| 180 | |||
| 181 | push @return_types, $type; | ||
| 182 | |||
| 183 | } | ||
| 184 | return @return_types; | ||
| 185 | } | ||
| 186 | |||
| 187 | |||
| 188 | ############################### | ||
| 189 | |||
| 190 | sub das_features { | ||
| 191 | my ($self, $opts) = @_; | ||
| 192 | |||
| 193 | #printf("\nhijack das_features before going back to superclass\n"); | ||
| 194 | #print($opts, "\n"); | ||
| 195 | #foreach my $key (keys(%$opts)) { | ||
| 196 | # printf(" %s => %s\n", $key, $opts->{$key}); | ||
| 197 | #} | ||
| 198 | |||
| 199 | #first clear from last feature request | ||
| 200 | $self->{'feature_filter_type'} = ''; | ||
| 201 | $self->{'wiggle_plot'} = undef; | ||
| 202 | if($opts->{'type'}) { | ||
| 203 | if($opts->{'type'} =~/(.*)\.wig/) { | ||
| 204 | $self->{'feature_filter_type'} = $1; | ||
| 205 | $self->{'wiggle_plot'} = 1; | ||
| 206 | } else { | ||
| 207 | $self->{'feature_filter_type'} = $opts->{'type'}; | ||
| 208 | } | ||
| 209 | } | ||
| 210 | return $self->SUPER::das_features($opts); | ||
| 211 | } | ||
| 212 | |||
| 213 | |||
| 214 | sub build_features { | ||
| 215 | my ($self, $opts) = @_; | ||
| 216 | |||
| 217 | my $type = $self->{'feature_filter_type'}; | ||
| 218 | my $wiggle = $self->{'wiggle_plot'}; | ||
| 219 | my $segment = $opts->{segment}; | ||
| 220 | my $start = $opts->{start}; | ||
| 221 | my $end = $opts->{end}; | ||
| 222 | my $dsn = $self->{dsn}; | ||
| 223 | |||
| 224 | my $asm = $self->config->{'assembly'}; | ||
| 225 | |||
| 226 | printf("edgeexpress::build_features called\n"); | ||
| 227 | if($type) { printf("type = [%s]\n", $type); } | ||
| 228 | if($wiggle) { printf("wiggle\n"); } | ||
| 229 | if($dsn) { printf("dsn = [%s]\n", $dsn); } | ||
| 230 | |||
| 231 | my $fsrc = EEDB::FeatureSource->fetch_by_name($self->transport->database, $type); | ||
| 232 | my $features = EEDB::Feature->fetch_all_named_region($self->transport->database, $asm, $segment, $start, $end, $fsrc); | ||
| 233 | |||
| 234 | my @rtn_features; | ||
| 235 | foreach my $feature (@$features) { | ||
| 236 | next unless($feature->feature_source->is_active and $feature->feature_source->is_active eq 'y'); | ||
| 237 | next unless($feature->feature_source->is_visible and $feature->feature_source->is_visible eq 'y'); | ||
| 238 | my $das_feature = { | ||
| 239 | id => $feature->id, | ||
| 240 | label => $feature->primary_name, | ||
| 241 | type => $feature->feature_source->name, | ||
| 242 | method => $feature->feature_source->category, | ||
| 243 | start => $feature->chrom_start, | ||
| 244 | end => $feature->chrom_end, | ||
| 245 | ori => $feature->strand, | ||
| 246 | #note => $row->{note}, | ||
| 247 | #link => $row->{link}, | ||
| 248 | }; | ||
| 249 | if($wiggle) { | ||
| 250 | $das_feature->{score} = $feature->significance; | ||
| 251 | } | ||
| 252 | push @rtn_features, $das_feature; | ||
| 253 | } | ||
| 254 | return @rtn_features; | ||
| 255 | } | ||
| 256 | |||
| 257 | |||
| 258 | 1; | ||
| 259 | __END__ |