KaryotypeBandAdaptor.pm 4.12 KB
Newer Older
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
#
# Ensembl module for Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor
#
# Cared for by James Stalker <jws@sanger.ac.uk>
#
# Copyright James Stalker
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor

=head1 SYNOPSIS

Give standard usage here

=head1 DESCRIPTION

Database adaptor to provide access to KaryotypeBand objects

=head1 AUTHOR

James Stalker

This modules is part of the Ensembl project http://www.ensembl.org

=head1 CONTACT

Email jws@sanger.ac.uk

=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::EnsEMBL::DBSQL::KaryotypeBandAdaptor;
use vars qw(@ISA);
Web Admin's avatar
Web Admin committed
46
use Bio::EnsEMBL::KaryotypeBand;
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
use strict;

# Object preamble - inherits from Bio::Root::RootI

use Bio::EnsEMBL::DBSQL::BaseAdaptor;

@ISA = qw(Bio::EnsEMBL::DBSQL::BaseAdaptor);

# inherit new from BaseAdaptor


=head2 fetch_by_chromosome_position

 Title   : fetch_by_chromosome_position
 Usage   : $band_obj = $kary_adp->fetch_by_chromosome_position('chr1',10000);
 Function: Retrieves a KaryotypeBand obj by its chromosome ('chrN' notation)
           and its absolute "golden-path" position on that chromosome.
 Example :
 Returns : A KaryotypeBand object
 Args    : Chromosome id (chrN notation) and position in absolute basepairs

=cut

sub fetch_by_chromosome_position{
    my ($self,$chr,$position) = @_;

    $self->throw("Need both chromosome and position") unless defined $position;

    my $sth = $self->prepare("	SELECT	chr_start,
					chr_end,
					band,
					stain
				FROM	karyotype 
				WHERE	chr_name = '$chr'
				AND	$position <= chr_end 
				AND	$position > chr_start 
			     ");

    $sth->execute;
    my ($chr_start,$chr_end,$band,$stain) = $sth->fetchrow_array;

    return undef unless defined $band;

    my $band_obj = Bio::EnsEMBL::KaryotypeBand->new();
    $band_obj->name($band);
    $band_obj->chromosome($chr);
    $band_obj->start($chr_start);
    $band_obj->end($chr_end);
    $band_obj->stain($stain);

    return $band_obj;
}




=head2 fetch_by_chromosome_name

 Title   : fetch_by_chromosome_name
 Usage   : $band_obj = $kary_adp->fetch_by_chromosome_name('chr1','q23.1');
 Function: Retrieves a KaryotypeBand obj by its chromosome ('chrN' notation)
           and its band name (e.g. 'q23.1').
 Example :
 Returns : A KaryotypeBand object
 Args    : Chromosome id (chrN notation) and band name 

=cut

sub fetch_by_chromosome_name{
    my ($self,$chr,$name) = @_;

    $self->throw("Need both chromosome and name") unless defined $name;

    my $sth = $self->prepare("	SELECT	chr_start,
					chr_end,
					stain
				FROM	karyotype 
				WHERE	chr_name = '$chr' 
				AND	band = '$name'
			     ");

    $sth->execute;
    my ($chr_start,$chr_end,$stain) = $sth->fetchrow_array;

Web Admin's avatar
Web Admin committed
131
    return undef unless defined $chr_start;
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

    my $band_obj = Bio::EnsEMBL::KaryotypeBand->new();
    $band_obj->name($name);
    $band_obj->chromosome($chr);
    $band_obj->start($chr_start);
    $band_obj->end($chr_end);
    $band_obj->stain($stain);

    return $band_obj;
}




=head2 fetch_all_by_chromosome

 Title   : fetch_all_by_chromosome
 Usage   : @band_obj = $kary_adp->fetch_all_by_chromosome('chr1');
 Function: Retrieves all KaryotypeBand objects on a chromosome ('chrN' notation)
 Example :
 Returns : An array of KaryotypeBand objects
 Args    : Chromosome id (chrN notation) 

=cut

sub fetch_all_by_chromosome{
    my ($self,$chr) = @_;

    $self->throw("Need a chromosome") unless defined $chr;

    my $sth = $self->prepare("	SELECT	chr_start,
					chr_end,
					band,
					stain
				FROM	karyotype 
				WHERE	chr_name = '$chr' 
			     ");

    $sth->execute;
    my ($chr_start,$chr_end,$band,$stain);
    $sth->bind_columns($chr_start,$chr_end,$band,$stain);
    
    my @bands;

    while ($sth->fetch()){
	my $band_obj = Bio::EnsEMBL::KaryotypeBand->new();
Web Admin's avatar
Web Admin committed
178
	$band_obj->name($band);
179
180
181
182
183
184
185
186
187
188
189
190
	$band_obj->chromosome($chr);
	$band_obj->start($chr_start);
	$band_obj->end($chr_end);
	$band_obj->stain($stain);

	push @bands,$band_obj;
    }

    return @bands;
}

1;