@@ -0,0 +1,3222 @@
+/*%0A  Copyright (C) 2003 EBI, GRL%0A %0A  This library is free software; you can redistribute it and/or%0A  modify it under the terms of the GNU Lesser General Public%0A  License as published by the Free Software Foundation; either%0A  version 2.1 of the License, or (at your option) any later version.%0A %0A  This library is distributed in the hope that it will be useful,%0A  but WITHOUT ANY WARRANTY; without even the implied warranty of%0A  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A  Lesser General Public License for more details.%0A %0A  You should have received a copy of the GNU Lesser General Public%0A  License along with this library; if not, write to the Free Software%0A  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA%0A */%0A%0Apackage org.ensembl.healthcheck.testcase;%0A%0Aimport java.sql.*;%0A%0Aimport org.ensembl.healthcheck.*;%0A%0Aimport org.ensembl.healthcheck.util.*;%0A%0A/**%0A * An EnsEMBL Healthcheck test case that looks for broken foreign-key relationships.%0A */%0A%0Apublic class ComparaSpeciesNameConsistancyTestCase extends EnsTestCase %7B%0A  %0A    /**%0A     * Create an OrphanTestCase that applies to a specific set of databases.%0A     */%0A    public ComparaSpeciesNameConsistancyTestCase() %7B%0A      databaseRegexp = %22%5Eensembl_compara_.*%22;%0A      addToGroup(%22compara_db_constraints%22);%0A      setDescription(%22Check for species name inconsistancies in ensembl_compara databases.%22);%0A    %7D%0A    %0A    public TestResult run() %7B%0A%09%0A%09boolean result = true;%0A%09%0A%09DatabaseConnectionIterator it = getDatabaseConnectionIterator();%0A%09int orphans = 0;%0A%09%0A%09while (it.hasNext()) %7B%0A%09    %0A%09    Connection con = (Connection)it.next();%0A            %0A%09    // check genome_db table has %3E 0 rows%0A            if ( countRowsInTable(con, %22genome_db%22) == 0) %7B%0A                result = false;%0A                ReportManager.problem(this, con, %22genome_db table is empty%22);%0A            %7D else %7B%0A                ReportManager.correct(this, con, %22genome_db table has data%22);%0A            %7D%0A            %0A            // check taxon table has %3E 0 rows%0A            if ( countRowsInTable(con, %22taxon%22) == 0) %7B%0A                result = false;%0A                ReportManager.problem(this, con, %22taxon table is empty%22);%0A            %7D else %7B%0A                ReportManager.correct(this, con, %22taxon table has data%22);%0A            %7D%0A%0A            String sql =  %22select gdb.taxon_id from taxon tx, genome_db gdb where tx.taxon_id=gdb.taxon_id and gdb.name != concat(tx.genus,%5C%22 %5C%22,tx.species)%22;%0A            %0A            String%5B%5D taxon_ids = getColumnValues(con, sql);%0A%0A            if (taxon_ids.length %3E 0) %7B%0A                result = false;%0A                ReportManager.problem(this, con, %22Cases where genome_db and taxon table do not shared the same species names%22);%0A                for( int i = 0 ; i%3Ctaxon_ids.length; i++ ) %7B%0A                    ReportManager.problem( this, con, %22 taxon_id %22 + taxon_ids%5Bi%5D + %22 have different species name between genome_db and taxon tables%22 );%0A                %7D%0A            %7D else %7B%0A                ReportManager.correct(this, con, %22genome_db and taxon table share the same species names%22);%0A            %7D%0A%09%7D%0A%09%0A%09return new TestResult(getShortTestName(), result);%0A%09%0A    %7D%0A    %0A%7D // ComparaSpeciesNameConsistancyTestCase%0A

Check that genus and species between genome_db and taxon tables are consistent