1 package CXGN
::Tools
::RestrictionEnzyme
;
3 use CXGN
::DB
::Connection
;
7 CXGN::Tools::RestrictionEnzyme
11 Abstract representation for pulling information about restriction enzymes
12 from SGN database. Will work in concert with CXGN::Tools::Sequence
13 to find restriction sites.
17 C. Carpita <ccarpita@gmail.com>
21 #GLOBAL CLASS VARIABLES
24 #Prepared statement references:
25 our ($ALL_ENZ_NAME_Q);
26 our ($VALID_ENZ_NAME_Q, $ENZ_SEQ_Q);
37 die "Must call this function on the class and send a DBH argument\n" unless ref($dbh);
44 if($DBH->can("add_search_path")){
45 $DBH->add_search_path("sgn");
48 $DBH->do("set search_path=sgn");
51 $ALL_ENZ_NAME_Q = $DBH->prepare("
52 SELECT DISTINCT enzyme_name
56 SELECT DISTINCT enzyme_id
57 FROM enzyme_restriction_sites
58 WHERE restriction_site IS NOT NULL
63 $VALID_ENZ_NAME_Q = $DBH->prepare("
68 SELECT DISTINCT enzyme_id
69 FROM enzyme_restriction_sites
70 WHERE restriction_site IS NOT NULL
76 $ENZ_SEQ_Q = $DBH->prepare("
77 SELECT restriction_site
78 FROM enzyme_restriction_sites
84 AND restriction_site IS NOT NULL
88 sub preload_valid_names
{
90 $ALL_ENZ_NAME_Q->execute();
91 while(my $row = $ALL_ENZ_NAME_Q->fetchrow_hashref){
92 my $enzyme_name = $row->{enzyme_name
};
93 $VALID_NAMES{$enzyme_name} = 1;
99 print STDERR
"$class is creating SGN database handle...\n";
100 my $dbh = CXGN
::DB
::Connection
->new("sgn");
101 $class->setDBH($dbh);
106 Ex: my @enzymes = CXGN::Tools::Enzyme::all_enzymes();
108 Returns an array of all enzyme objects, created from
109 the enzyme tables in the database.
115 $class->createDBH() unless ref($DBH);
116 $class->preload_valid_names() unless keys(%VALID_NAMES);
118 foreach my $name (keys %VALID_NAMES){
119 my $enzyme = $class->new($name);
120 push(@enzymes, $enzyme);
128 Usage: my $enzyme = CXGN::Tools::Enzyme->new("hindIII");
129 Auto-fetches the matching sequences from the database,
130 dies if the name is not valid. Use eval{} tags to avoid
137 my $self = bless {}, $class;
141 #You can provide a different DBH to use instead of the
142 #class global, which we use to prepare queries efficiently
145 die "No enzyme name provided\n" unless $name;
152 $class->createDBH() unless ref($DBH);
155 $self->{match_seqs
} = [];
156 $self->check_name_valid();
157 $self->fetch_match_seqs();
162 =head1 INSTANCE METHODS
169 return $self->{name
} unless $name;
170 $self->{name
} = $name;
173 sub check_name_valid
{
175 my $name = $self->name();
176 __PACKAGE__
->preload_valid_names() unless defined %VALID_NAMES;
177 die "Name of enzyme ($name) not valid, or no restriction site identified\n" unless $VALID_NAMES{$name};
180 sub fetch_match_seqs
{
182 $ENZ_SEQ_Q->execute($self->name());
183 while(my ($seq) = $ENZ_SEQ_Q->fetchrow_array){
184 push(@
{$self->{match_seqs
}}, $seq);