<commit_before>/*
 * 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;
import org.ensembl.healthcheck.util.DBUtils;

/**
 * Check that feature co-ords make sense.
 */
public class ProteinFeatures extends SingleDatabaseTestCase {

    /**
     * Creates a new instance of CheckFeatureCoordsTestCase
     */
    public ProteinFeatures() {
        setDescription("Check that protein annotation feature coords make sense and that all translations exist in the database");
        addToGroup("post_genebuild");
        addToGroup("release");
    }

    /**
     * This only applies to core and Vega databases.
     */
    public void types() {

        removeAppliesToType(DatabaseType.OTHERFEATURES);

    }
    
    /**
     * Iterate over each affected database and perform various checks.
     * @param dbre
     *          The database to use.
     * @return true if the test passes.
     */
    public boolean run(DatabaseRegistryEntry dbre) {

        boolean result = true;

        Connection con = dbre.getConnection();

        logger.info("Checking protein features for " + DBUtils.getShortDatabaseName(con) + " ...");
        int rows = getRowCount(con, "SELECT COUNT(*) FROM protein_feature WHERE seq_start > seq_end");
        if (rows > 0) {
            result = false;
            ReportManager.problem(this, con, rows + " protein features have seq_start > seq_end");
        } else {
            ReportManager.correct(this, con, "No protein features where seq_start > seq_end");
        }

        logger.info("Checking protein features for " + DBUtils.getShortDatabaseName(con) + " ...");
        rows = getRowCount(con, "SELECT COUNT(*) from protein_feature WHERE seq_start < 0");
        if (rows > 0) {
            ReportManager.problem(this, con, rows + " protein features have seq_start < 0");
        } else {
            ReportManager.correct(this, con, "No protein features where seq_start < 0");
        }

        logger.info("Checking protein features for " + DBUtils.getShortDatabaseName(con) + " ...");
        rows = getRowCount(con, "SELECT COUNT(*) FROM protein_feature WHERE hit_start < 0");
        if (rows > 0) {
            ReportManager.problem(this, con, rows + " protein features have hit_start < 0");
        } else {
            ReportManager.correct(this, con, "No protein features where hit_start < 0");
        }

        logger.info("Checking protein features for " + DBUtils.getShortDatabaseName(con) + " ...");
        rows = getRowCount(con, "SELECT COUNT(*) from protein_feature WHERE hit_start > hit_end");
        if (rows > 0) {
            result = false;
            ReportManager.problem(this, con, rows + " protein features have hit_start > hit_end");
        } else {
            ReportManager.correct(this, con, "No protein features where hit_start > hit_end");
        }

        return result;

    } // run

} // ProteinFeatures<commit_msg>Only complain if mre than 1000 features have errors.<commit_after>/*
 * 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;
import org.ensembl.healthcheck.util.DBUtils;

/**
 * Check that feature co-ords make sense.
 */
public class ProteinFeatures extends SingleDatabaseTestCase {

	private static int THRESHOLD = 1000;
	
    /**
     * Creates a new instance of CheckFeatureCoordsTestCase
     */
    public ProteinFeatures() {
        setDescription("Check that protein annotation feature coords make sense and that all translations exist in the database");
        addToGroup("post_genebuild");
        addToGroup("release");
    }

    /**
     * This only applies to core and Vega databases.
     */
    public void types() {

        removeAppliesToType(DatabaseType.OTHERFEATURES);

    }
    
    /**
     * Iterate over each affected database and perform various checks.
     * @param dbre
     *          The database to use.
     * @return true if the test passes.
     */
    public boolean run(DatabaseRegistryEntry dbre) {

        boolean result = true;

        Connection con = dbre.getConnection();

        logger.info("Checking protein features for " + DBUtils.getShortDatabaseName(con) + " ...");
        int rows = getRowCount(con, "SELECT COUNT(*) FROM protein_feature WHERE seq_start > seq_end");
        if (rows > THRESHOLD) {
            result = false;
            ReportManager.problem(this, con, rows + " protein features have seq_start > seq_end");
        } else {
            ReportManager.correct(this, con, "No protein features where seq_start > seq_end");
        }

        logger.info("Checking protein features for " + DBUtils.getShortDatabaseName(con) + " ...");
        rows = getRowCount(con, "SELECT COUNT(*) from protein_feature WHERE seq_start < 0");
        if (rows > THRESHOLD) {
            ReportManager.problem(this, con, rows + " protein features have seq_start < 0");
        } else {
            ReportManager.correct(this, con, "No protein features where seq_start < 0");
        }

        logger.info("Checking protein features for " + DBUtils.getShortDatabaseName(con) + " ...");
        rows = getRowCount(con, "SELECT COUNT(*) FROM protein_feature WHERE hit_start < 0");
        if (rows > THRESHOLD) {
            ReportManager.problem(this, con, rows + " protein features have hit_start < 0");
        } else {
            ReportManager.correct(this, con, "No protein features where hit_start < 0");
        }

        logger.info("Checking protein features for " + DBUtils.getShortDatabaseName(con) + " ...");
        rows = getRowCount(con, "SELECT COUNT(*) from protein_feature WHERE hit_start > hit_end");
        if (rows > THRESHOLD) {
            result = false;
            ReportManager.problem(this, con, rows + " protein features have hit_start > hit_end");
        } else {
            ReportManager.correct(this, con, "No protein features where hit_start > hit_end");
        }

        return result;

    } // run

} // ProteinFeatures
{'fraction_non_alphanumeric': 0.09380128771619745, 'fraction_numerical': 0.008079787905567478, 'mean_word_length': 2.8700537371763555, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1792370', 'n_tokens_mistral': 2210, 'n_tokens_neox': 2085, 'n_words': 734}