Skip to content
Snippets Groups Projects
Commit 6ba0e848 authored by Graham McVicker's avatar Graham McVicker
Browse files

Updated for new schema. fetch_all_by_Slice now handles non-chromosomal slices.

parent 7d6e031c
No related branches found
No related tags found
No related merge requests found
......@@ -51,60 +51,112 @@ use vars '@ISA';
sub fetch_all_by_Slice {
my ($self, $slice ) = @_;
my $slice_start = $slice->chr_start();
my $slice_end = $slice->chr_end();
my %SNPS = qw( 12 dbSNP 13 WI 14 HGBASE 15 TSC-CSHL 16 ANO );
my $QUERY = "select internal_id, chr_start, chr_end, chr_strand, type, range_type,
validated, alleles, snpclass, mapweight, ambiguity, source,
id_refsnp, id_wi, id_hgbase, id_tsc, id_ano
FROM snp
WHERE chr_name = ? AND chr_start >= ? and chr_start <= ? AND chr_end >= ?";
my $sth = $self->prepare( $QUERY );
eval {
$sth->execute($slice->chr_name(), $slice_start - 500 , $slice_end, $slice_start);
};
return [] if $@;
my @snps = ();
my %link_hash;
my $link;
my @snps;
my $from_strand = $slice->strand();
# wherever this slice is, it needs to be converted to
# a toplevel slices since all snps in the lite database
# are stored on toplevel seqregions
my @projection = @{$slice->project('toplevel')};
my $link_col_idx = 12;
my @link_dbs = ('dbSNP', 'WI', 'HGBASE', 'TSC-CSHL', 'ANO');
$self->{'link_cache'} ||= {};
foreach my $segment (@projection) {
my $from_start = $segment->from_start();
my $from_end = $segment->from_end();
my $top_slice = $segment->to_Slice();
my $top_slice_start = $top_slice->start();
my $top_slice_end = $top_slice->end();
my $top_slice_strand = $top_slice->strand();
my $sth = $self->prepare
("SELECT internal_id, chr_start, chr_end, chr_strand, type, " .
" range_type, validated, alleles, snpclass, mapweight, ".
" ambiguity, source, id_refsnp, id_wi, id_hgbase, id_tsc, " .
" id_ano " .
"FROM snp " .
"WHERE chr_name = ? " .
"AND chr_start >= ? " .
"AND chr_start <= ? " .
"AND chr_end >= ?");
$sth->execute($top_slice->seq_region_name(),
$top_slice_start - 500,
$top_slice_end,
$top_slice_start);
while(my $arrayref = $sth->fetchrow_arrayref()) {
my @links = ();
# loop over the last columns of the row to retrieve a single external
# database link for each column
for(my $i = 0; $i < scalar(@link_dbs); $i++) {
my $link_id = $arrayref->[$link_col_idx + $i];
next if(!$link_id);
my $link_db = $link_dbs[$i];
my $link = $self->{'link_cache'}->{"$link_db:$link_id"};
if(!$link) {
$link = Bio::EnsEMBL::DBEntry->new_fast
({'_dbname' => $link_db,
'_primary_id' => $link_id});
$self->{'link_cache'}->{"$link_db:$link_id"};
}
push @links, $link;
}
#create a snp object through a fast (hacky) constructor
my $status = $arrayref->[6];
$status =~ s/-/ /;
if($status && $status ne 'no info') {
$status = "proven $status";
} else {
$status = 'suspected';
}
# coordinates must be adjusted so that they are first
# relative to the start of the top level slice (rather than absolute)
# and then adjusted so they are relative to the start of the
# original requested slice (w/ from_start)
my($start,$end,$strand);
if($top_slice_strand == 1) {
$start = $arrayref->[1] - $top_slice_start + $from_start;
$end = $arrayref->[2] - $top_slice_start + $from_start;
$strand = $arrayref->[3];
} else {
$start = $top_slice_end - $arrayref->[2] + $from_start;
$end = $top_slice_end - $arrayref->[1] + $from_start;
$strand = $arrayref->[3] * -1;
}
push @snps, Bio::EnsEMBL::SNP->new_fast
({ 'dbID' => $arrayref->[0],
'_gsf_start' => $start,
'_gsf_end' => $end,
'_snp_strand' => $strand,
'_gsf_score' => 1,
'_type' => $arrayref->[4],
'_range_type' => $arrayref->[5],
'_validated' => $arrayref->[6],
'status' => $status,
'alleles' => $arrayref->[7],
'_ambiguity_code' => $arrayref->[10],
'_snpclass' => $arrayref->[8],
'_mapweight' => $arrayref->[9],
'_source' => $arrayref->[11],
'_source_tag' => $arrayref->[11],
'link' => \@links });
while(my $arrayref = $sth->fetchrow_arrayref()) {
my @links = ();
foreach( sort keys %SNPS ) {
my $V = $arrayref->[ $_ ];
if( $V && $V ne '' ) {
unless($link = $link_hash{"$SNPS{$_}:$V"}) {
$link_hash{"$SNPS{$_}:$V"} = $link = Bio::EnsEMBL::DBEntry->new_fast( {'_dbname' => $SNPS{$_}, '_primary_id' => $V });
}
push @links, $link;
}
}
#create a snp object through a fast (hacky) constructor
my $STATUS = $arrayref->[6];
$STATUS =~s/-/ /;
$STATUS = ( $STATUS && $STATUS ne 'no info' ) ? "proven $STATUS" : 'suspected';
my $snp = Bio::EnsEMBL::SNP->new_fast(
{ 'dbID' => $arrayref->[0],
'_gsf_start' => $arrayref->[1] - $slice_start + 1,
'_gsf_end' => $arrayref->[2] - $slice_start + 1,
'_snp_strand' => $arrayref->[3],
'_gsf_score' => 1,
'_type' => $arrayref->[4],
'_range_type' => $arrayref->[5],
'_validated' => $arrayref->[6],
'status' => $STATUS,
'alleles' => $arrayref->[7],
'_ambiguity_code' => $arrayref->[10],
'_snpclass' => $arrayref->[8],
'_mapweight' => $arrayref->[9],
'_source' => $arrayref->[11],
'_source_tag' => $arrayref->[11],
'link' => \@links });
push @snps, $snp;
}
return \@snps;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment