6 Functions for accessing ogranism names and their identifiers
17 =head2 get_all_organisms
19 Usage: my ($names_ref, $ids_ref) = CXGN::Tools::Organism::get_all_organisms($dbh, %return_hash_flag);
20 Desc: This is a static function. Retrieves distinct organism names and IDs from sgn.common_name
21 Ret: Returns two arrayrefs. One array contains all the
22 organism names, and the other all the organism ids
23 with corresponding array indices
24 or a hash {common_name}=common_name_id if 2nd argument is provided
26 Args: a database handle, a boolean (optional)
32 package CXGN
::Tools
::Organism
;
40 sub get_all_organisms
{
42 my $return_hash = shift;
43 #this query should be changed to work with chado's organism table after sgn.common_name is replaced with it.
44 my $query = "SELECT common_name, common_name_id
45 FROM sgn.common_name ORDER BY upper(common_name) desc";
46 my $sth = $dbh->prepare($query);
51 while (my($common_name, $common_name_id) = $sth->fetchrow_array()) {
52 push @names, $common_name;
53 push @ids, $common_name_id;
54 $common_names{$common_name}= $common_name_id;
56 return %common_names if $return_hash;
57 return (\
@names, \
@ids);
61 =head2 get_existing_organisms
63 Usage: my ($names_ref, $ids_ref) = CXGN::Tools::Organism::get_existing_organisms($dbh , return_hash_flag);
64 Desc: This is a static function. Selects the distinct organism names and their IDs from phenome.locus.
65 Useful for populating a unique drop-down menu with only the organism names that exist in the table.
66 Ret: Returns two arrayrefs. One array contains all the
67 organism names, and the other all the organism ids with corresponding array indices.
68 or a hash {common_name}=common_name_id if 2nd argument is provided
69 Args: a database handle, and a boolean (optional)
75 sub get_existing_organisms
{
77 my $return_hash = shift;
78 my $query = "SELECT distinct(common_name), common_name_id FROM phenome.locus
79 JOIN sgn.common_name using(common_name_id)
80 WHERE obsolete = 'f'";
81 my $sth = $dbh->prepare($query);
86 while (my($common_name, $common_name_id) = $sth->fetchrow_array()) {
87 push @names, $common_name;
88 push @ids, $common_name_id;
89 $common_names{$common_name}= $common_name_id;
91 return %common_names if $return_hash;
92 return (\
@names, \
@ids);
95 =head2 get_all_populations
97 Usage: my ($names_ref, $ids_ref) = CXGN::Tools::Organism::get_all_populations($dbh);
98 Desc: This is a static function. Retrieves distinct population names and IDs from phenome.population
99 Ret: Returns two arrayrefs. One array contains all the
100 population names, and the other all the population ids
101 with corresponding array indices.
102 Args: a database handle
108 sub get_all_populations
{
111 my $query = "SELECT name, population_id
112 FROM phenome.population";
113 my $sth = $dbh->prepare($query);
117 while (my($name, $population_id) = $sth->fetchrow_array()) {
119 push @ids, $population_id;
121 return (\
@names, \
@ids);
125 =head2 organism_id_specie
127 Usage: $id = CXGN::Tools::Organism::organism_id_specie($dbh, $specie);
128 Desc: retrieves the organism id from sgn.organism
130 Args: db handle, specie name (eg. solanum lycopersicum)
131 Side Effects: access db
136 sub organism_id_specie
{
140 print STDERR
"specie_tax: $specie\n";
142 my $sth = $dbh->prepare("SELECT organism_id
144 WHERE specie_tax ILIKE ?"
146 $sth->execute($specie);
148 while (my $id_1 = $sth->fetchrow_array()) {