/*
 Copyright (C) 2004 EBI, GRL
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.ensembl.healthcheck.testcase.generic;

import java.sql.Connection;

import org.ensembl.healthcheck.DatabaseRegistryEntry;
import org.ensembl.healthcheck.DatabaseType;
import org.ensembl.healthcheck.ReportManager;
import org.ensembl.healthcheck.testcase.SingleDatabaseTestCase;

/**
 * Check that there are no null values in the mismatches column of the
 * affy_features table.
 */

public class AffyMismatches extends SingleDatabaseTestCase {

	/**
	 * Check the assembly_exception table.
	 */
	public AffyMismatches() {
		addToGroup("post_genebuild");
		addToGroup("release");
		setDescription("Check that there are no null values in the mismatches column of the affy_features table");
	}

	/**
	 * This applies to all core schema databases apart from 'core'
	 */
	public void types() {

		removeAppliesToType(DatabaseType.EST);
		removeAppliesToType(DatabaseType.VEGA);
	}

	/**
	 * Run the test.
	 * 
	 * @param dbre
	 *            The database to use.
	 * @return Result.
	 */
	public boolean run(DatabaseRegistryEntry dbre) {

		boolean result = true;

		Connection con = dbre.getConnection();

		int rows = getRowCount(con, "SELECT COUNT(*) FROM affy_feature WHERE mismatches IS NULL");
		if (rows > 0) {
			result = false;
			ReportManager.problem(this, con, "affy_features table has " + rows
					+ " with null mismatches");
		}

		if (result) {
			ReportManager.correct(this, con, "No null mismatches in affy_feature");
		}

		return result;

	}

} // AffyMismatches

@@ -822,16 +822,48 @@
 nection;
+%0Aimport java.text.DecimalFormat;
 %0A%0Aimport
@@ -1894,13 +1894,120 @@
 %0A%0A%09%09
-int r
+DecimalFormat df = new DecimalFormat(%22000.0%25%22);%0A%0A%09%09int rows = countRowsInTable(con, %22affy_feature%22);%0A%09%09int nullR
 ows 
@@ -2024,17 +2024,21 @@
 unt(con,
- 
+%0A%09%09%09%09
 %22SELECT 
@@ -2098,17 +2098,21 @@
 ;%0A%09%09if (
-r
+nullR
 ows %3E 0)
@@ -2133,16 +2133,67 @@
  false;%0A
+%09%09%09float pc = (rows %3E 0) ? (nullRows / rows) : 0;%0A%0A
 %09%09%09Repor
@@ -2283,16 +2283,40 @@
 smatches
+ (%22 + df.format(pc) + %22)
 %22);%0A%09%09%7D%0A
@@ -2367,17 +2367,22 @@
 is, con,
- 
+%0A%09%09%09%09%09
 %22No null

Add %age of null rows to output