add experimental genotype search class.
[phenome.git] / bin / flag_obsolet_annot.pl
blob8f598a81db9180dace0f59a663dd38ab00fa387b
2 =head1 NAME
4 flag_obsolete_annot.pl
6 =head1 DESCRIPTION
8 Usage: perl flag_obsolete_annot.pl -H dbhost -D dbname -o outfile [-v]
10 parameters
12 =over 6
14 =item -H
16 hostname for database [required]
18 =item -D
20 database name [required]
22 =item -v
24 verbose output
26 =item -d
28 db name of the controlled vocabulary
30 =item -o
32 output file
34 =item -t
36 test mode
38 =back
41 The script looks for locus and individual ontology annotations in the database and prints out a
42 list of annotations that require updating since the cvterms were obsoleted.
43 Ususally running this script is a good idea after updating cvterms in the database (see sgn-tools/phenome/load_cvterms.pl)
44 and prior to submitting an ontology association file to PO/GO.
46 =head1 AUTHOR
48 Naama Menda <nm249@cornell.edu>
50 =head1 VERSION AND DATE
52 Version 0.1, February 2008.
54 =cut
57 #! /usr/bin/perl
58 use strict;
60 use Getopt::Std;
62 use CXGN::Phenome::Locus;
63 use CXGN::Phenome::Individual;
64 use CXGN::Chado::Organism;
66 use CXGN::DB::InsertDBH;
67 use CXGN::Chado::Dbxref;
68 use CXGN::Chado::Cvterm;
69 use CXGN::Chado::Ontology;
70 use CXGN::Chado::Relationship;
72 our ($opt_H, $opt_D, $opt_v, $opt_o, $opt_d, $opt_t);
74 #getopts('F:d:H:o:n:vD:t');
75 getopts('H:o:d:vD:t');
76 my $dbhost = $opt_H;
77 my $dbname = $opt_D;
79 if (!$dbhost && !$dbname) { die "Need -D dbname and -H hostname arguments.\n"; }
81 my $error = 0; # keep track of input errors (in command line switches).
82 if (!$opt_D) {
83 print STDERR "Option -D required. Must be a valid database name.\n";
84 $error=1;
89 my $file = $opt_o;
91 if (!$file) {
92 print STDERR "A file is required as a command line argument.\n";
93 $error=1;
97 die "Some required command lines parameters not set. Aborting.\n" if $error;
100 open (OUT, ">$opt_o") ||die "can't open error file $file for writting.\n" ;
103 my $dbh = CXGN::DB::InsertDBH->new( { dbhost=>$dbhost,
104 dbname=>$dbname,
105 } );
108 print STDERR "Connected to database $dbname on host $dbhost.\n";
109 my @locus_annot= CXGN::Phenome::Locus->get_annotations_by_db($dbh, $opt_d);
111 my $count=0;
112 my $u_count =0;
113 print STDERR "Reading annotations from database..\n";
115 eval {
116 foreach my $annot(@locus_annot) {
118 my $locus_id= $annot->get_locus_id();
119 print STDERR "locus_id = $locus_id\n";
120 print STDERR "." if !$opt_v;
121 my $locus= CXGN::Phenome::Locus->new($dbh,$locus_id);
122 my $locus_name = $locus->get_locus_name();
123 my $dbxref=CXGN::Chado::Dbxref->new($dbh, $annot->get_dbxref_id);
125 my $cvterm = $dbxref->get_cvterm();
126 my $cvterm_name=$cvterm->get_cvterm_name();
127 my $accession = $dbxref->get_accession();
128 my $is_obsolete= $cvterm->get_obsolete();
129 my @alt_ids = $cvterm->get_alt_id();
130 print STDERR "alt_ids = @alt_ids\n\n";
132 if ($is_obsolete) {
133 $count++;
134 print STDERR "Locus $locus_name (id=$locus_id) has obsolete annotation: $accession:$cvterm_name\n";
135 print OUT "Locus $locus_name (id=$locus_id) has obsolete annotation: $accession:$cvterm_name\n";
137 if (@alt_ids) {
138 $u_count++;
139 $annot->update_annotation($alt_ids[0]);
140 print STDERR "*Updated annotation to $alt_ids[0]!\n";
141 print OUT "*Updated annotation to $alt_ids[0]\n";
142 }else {
143 print STDERR "!did not find alternative cvterm for this obsolete annotation! $cvterm_name\n";
144 print OUT "!did not find alternative cvterm for this obsolete annotation! $cvterm_name\n";
150 print STDERR "Found $count obsolete annotations for SGN loci, $u_count annotations were updated.\n printed out file $file... Done.\n";
152 my @pheno_annot= CXGN::Phenome::Individual->get_annotations_by_db($dbh, $opt_d);
154 $count= 0;
155 $u_count=0;
156 print STDERR "Reading annotations from SGN individual database..\n";
157 foreach my $annot(@pheno_annot) {
159 print STDERR "." if !$opt_v;
160 my $ind_id= $annot->get_individual_id();
161 my $ind= CXGN::Phenome::Individual->new($dbh,$ind_id);
162 my $ind_name=$ind->get_name();
163 my $dbxref=CXGN::Chado::Dbxref->new($dbh, $annot->get_dbxref_id());
164 my $cvterm=$dbxref->get_cvterm();
165 my $cvterm_name=$cvterm->get_cvterm_name();
166 my $accession = $dbxref->get_accession();
167 my $is_obsolete=$cvterm->get_obsolete();
168 my @alt_ids = $cvterm->get_alt_id();
170 if ($is_obsolete) {
171 $count++;
172 print STDERR "Individual $ind_name (id=$ind_id) has obsolete annotation: $accession:$cvterm_name\n";
173 print STDERR "Individual $ind_name (id=$ind_id) has obsolete annotation: $accession:$cvterm_name\n";
174 if (@alt_ids) {
175 $u_count++;
176 $annot->update_annotation($alt_ids[0]);
177 print STDERR "*Updated annotation to $alt_ids[0]!\n";
178 print OUT "*Updated annotation to $alt_ids[0]\n";
179 }else {
180 print STDERR "!did not find alternative cvterm for this obsolete annotation! $cvterm_name\n";
181 print OUT "!did not find alternative cvterm for this obsolete annotation! $cvterm_name\n";
186 if ($@ || ($opt_t)) {
187 print STDERR "Either running as trial mode (-t) or AN ERROR OCCURRED: $@\n";
188 print OUT "Either running as trial mode (-t) or AN ERROR OCCURRED: $@\n" if $opt_o;
190 $dbh->rollback();
191 exit(0);
193 else { $dbh->commit(); }
196 close OUT;
198 print STDERR "Found $count obsolete annotations for SGN individuals, $u_count annotations were updated.\n printed into out file $file... Done.\n";