2 use CXGN
::DB
::Connection
;
4 use CXGN
::DB
::SQLWrappers
;
5 package CXGN
::Accession
;
13 Gets accession data from the sgn.accession and sgn.accession_names tables.
15 Note: will be soon deprecated in favor of the chado stock table.
19 Takes an accession id or an accession name and returns a new accession object.
20 With no accession id or name, it creates an empty accession object.
22 john binns - John Binns <zombieite@gmail.com>
25 Code and POD style reformatting by Lukas.
30 This class implements the following methods:
37 Takes an accession id or an accession name and returns a new accession object. With no accession id or name, it creates an empty accession object.
40 my $accession=CXGN::Accession->new($dbh,$accession_name);
46 my($dbh,$accession)=@_;
47 unless(CXGN
::DB
::Connection
::is_valid_dbh
($dbh)){die"Invalid DBH.";}
48 my $self=bless({},$class);
52 if($accession=~/^\d+$/) {
53 $id_query=$self->{dbh
}->prepare('SELECT accession_id FROM accession WHERE accession_id=?');
56 $accession = '%'.$accession.'%';
57 $id_query=$self->{dbh
}->prepare('SELECT accession_id FROM accession_names WHERE accession_name ilike ?');
59 $id_query->execute($accession);
60 ($self->{accession_id
})=$id_query->fetchrow_array();
61 if($self->{accession_id
}) {
62 my $accession_query=$self->{dbh
}->prepare('SELECT organism.organism_id,organism_name,common_name.common_name_id,
63 common_name.common_name,accession.common_name, accession.accession_name_id,
64 accession_names.accession_name, accession.chado_organism_id
66 LEFT JOIN accession_names USING (accession_name_id)
67 LEFT JOIN organism ON (accession.organism_id=organism.organism_id)
68 LEFT JOIN common_name USING (common_name_id)
69 WHERE accession.accession_id=?'
72 $accession_query->execute($self->{accession_id
});
73 ($self->{organism_id
},
74 $self->{organism_name
},
75 $self->{organism_common_name_id
},
76 $self->{organism_common_name
},
77 $self->{accession_common_name
},
78 $self->{preferred_name_id
},
79 $self->{preferred_name
},
80 $self->{chado_organism_id
})=$accession_query->fetchrow_array();
82 my $aliases_query=$self->{dbh
}->prepare('SELECT accession_name
84 WHERE accession_id=? AND accession_name!=?'
86 $aliases_query->execute($self->{accession_id
},$self->{preferred_name
});
87 while(my($alias)=$aliases_query->fetchrow_array)
89 push(@aliases,$alias);
91 $self->{aliases
}=\
@aliases;
100 =head2 all_accessions
102 Usage: my %hash = CXGN::Accession->all_accessions($dbh);
103 Desc: class method that returns all the accessions
104 as a hash of class_ids and accession names.
105 Author: added by Lukas 10/2009
113 my $q = "SELECT accession_id, organism_name, accession_name FROM sgn.accession join sgn.accession_names using(accession_id) join sgn.organism using(organism_id)";
114 my $h = $dbh->prepare($q);
117 while (my ($accession_id, $organism_name, $accession_name) = $h->fetchrow_array()) {
118 $hash{$accession_id} = "$organism_name ($accession_name)";
127 my $id=$accession->accession_id();
133 return $self->{accession_id
};
136 =head2 preferred_name
138 my $accession_name=$accession->preferred_name();
146 ($self->{preferred_name
})=@_;
148 return $self->{preferred_name
};
153 my @aliases=@{$accession->other_names()};
159 return @
{$self->{aliases
}};
162 =head2 accession_common_name
164 my $acn=$accession->accession_common_name();
168 sub accession_common_name
{
171 ($self->{accession_common_name
})=@_;
173 return $self->{accession_common_name
};
176 =head2 chado_organism_id
178 my $acn=$accession->chado_organism_id();
182 sub chado_organism_id
{
185 ($self->{chado_organism_id
})=@_;
187 return $self->{chado_organism_id
};
192 my $org_name=$accession->organism_name();
200 ($self->{organism_name
})=@_;
202 return $self->{organism_name
};
205 =head2 organism_common_name
207 my $org_cn=$accession->organism_common_name();
211 sub organism_common_name
{
215 ($self->{organism_common_name
})=@_;
217 return $self->{organism_common_name
};
222 my $verbose_name = $accession->verbose_name();
228 my $verbose_name=$self->{organism_name
}." ".$self->{preferred_name
};
229 $verbose_name=CXGN
::Tools
::Text
::abbr_latin
($verbose_name);
230 $verbose_name=~s/ \(.*\)//;
231 return $verbose_name;
234 =head2 extra_verbose_name
236 my $xvn=$accession->extra_verbose_name();
240 sub extra_verbose_name
{
242 my @extra_verbose_name;
243 if($self->{organism_common_name
}) {
244 push(@extra_verbose_name,"<b>".$self->{organism_common_name
}."</b>");
246 if($self->{organism_name
}) {
247 push(@extra_verbose_name,$self->{organism_name
});
249 # if($self->{accession_common_name})
251 # push(@extra_verbose_name,$self->{accession_common_name});
253 if($self->{preferred_name
}) {
254 push(@extra_verbose_name,$self->{preferred_name
});
256 if(@
{$self->{aliases
}}[0]) {
257 push(@extra_verbose_name,'('.join(', ',@
{$self->{aliases
}}).')');
259 my $extra_verbose_name=join(' ',@extra_verbose_name);
260 $extra_verbose_name=CXGN
::Tools
::Text
::abbr_latin
($extra_verbose_name);
261 return $extra_verbose_name;