<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 java.sql.ResultSet;
import java.sql.Statement;

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

/**
 * An EnsEMBL Healthcheck test case which checks all exon of a gene are on the same strand and in the correct order in their
 * transcript.
 */

public class ExonStrandOrder extends SingleDatabaseTestCase {

	private static final int TRANSCRIPT_WARN_LENGTH = 2000000;

	/**
	 * Constructor.
	 */
	public ExonStrandOrder() {

		addToGroup("post_genebuild");
		addToGroup("release");
		
		setHintLongRunning(true);
		setTeamResponsible(Team.GENEBUILD);

	}

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

		removeAppliesToType(DatabaseType.OTHERFEATURES);
		removeAppliesToType(DatabaseType.RNASEQ);

	}

	/**
	 * Check strand order of exons.
	 * 
	 * @param dbre
	 *          The database to use.
	 * @return Result.
	 */

	public boolean run(DatabaseRegistryEntry dbre) {

		boolean result = true;

		int singleExonTranscripts = 0, transcriptCount = 0;

		String sql = "SELECT g.gene_id, g.seq_region_start, g.seq_region_end, g.seq_region_strand, tr.transcript_id, tr.seq_region_start, tr.seq_region_end, tr.seq_region_strand,e.exon_id, e.seq_region_start, e.seq_region_end, e.seq_region_strand, et.rank,  g.stable_id, tr.stable_id "
				+ "FROM   gene g, transcript tr, exon_transcript et, exon e "
				+ "WHERE  e.exon_id = et.exon_id "
				+ "AND    et.transcript_id = tr.transcript_id "
				+ "AND    tr.gene_id = g.gene_id " + "ORDER BY et.transcript_id, et.rank";
/*

The sql is:

SELECT 
	g.gene_id, 
	g.seq_region_start, 
	g.seq_region_end, 
	g.seq_region_strand, 
	tr.transcript_id, 
	tr.seq_region_start, 
	tr.seq_region_end, 
	tr.seq_region_strand,
	e.exon_id, 
	e.seq_region_start, 
	e.seq_region_end, 
	e.seq_region_strand, 
	et.rank, 
	gsi.stable_id, 
	tsi.stable_id
FROM   
	gene g, 
	transcript tr, 
	exon_transcript et, 
	exon e, 
	gene_stable_id gsi, 
	transcript_stable_id tsi 
WHERE  
	e.exon_id = et.exon_id 
	AND    et.transcript_id = tr.transcript_id  
	AND    tr.gene_id = g.gene_id 
	AND    g.gene_id = gsi.gene_id  
	AND    tr.transcript_id=tsi.transcript_id 
ORDER BY 
	et.transcript_id, et.rank

 */
		Connection con = dbre.getConnection();
		try {
			Statement stmt = con.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
			stmt.setFetchSize(Integer.MIN_VALUE);
			ResultSet rs = stmt.executeQuery(sql);

			long lastTranscriptID = -1;
			long lastExonStart = -1;
			long lastExonEnd = -1;
			long lastExonStrand = -2;
			long lastExonID = -1;
			int lastExonRank = 0;

			// ResultSet is ordered by transcript ID and rank, so we can loop through
			// and look at the grouped exons for each transcript
			while (rs.next()) {

				long geneID = rs.getLong(1);
				// long geneStart = rs.getLong(2);
				// long geneEnd = rs.getLong(3);
				// int geneStrand = rs.getInt(4);
				long transcriptID = rs.getLong(5);
				long transcriptStart = rs.getLong(6);
				long transcriptEnd = rs.getLong(7);
				int transcriptStrand = rs.getInt(8);
				long exonID = rs.getLong(9);
				long exonStart = rs.getLong(10);
				long exonEnd = rs.getLong(11);
				int exonStrand = rs.getInt(12);
				int exonRank = rs.getInt(13);
				String geneStableID = rs.getString(14);
				String transcriptStableID = rs.getString(15);

				if (geneStableID.equalsIgnoreCase("CG32491")) {
					continue;
				}<commit_msg>If you have a String literal & want to compare it to another String which may be null you should do it like "my_literal".equalsIgnoreCase(str) which gets around any null issues<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 java.sql.ResultSet;
import java.sql.Statement;

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

/**
 * An EnsEMBL Healthcheck test case which checks all exon of a gene are on the same strand and in the correct order in their
 * transcript.
 */

public class ExonStrandOrder extends SingleDatabaseTestCase {

	private static final int TRANSCRIPT_WARN_LENGTH = 2000000;

	/**
	 * Constructor.
	 */
	public ExonStrandOrder() {

		addToGroup("post_genebuild");
		addToGroup("release");
		
		setHintLongRunning(true);
		setTeamResponsible(Team.GENEBUILD);

	}

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

		removeAppliesToType(DatabaseType.OTHERFEATURES);
		removeAppliesToType(DatabaseType.RNASEQ);

	}

	/**
	 * Check strand order of exons.
	 * 
	 * @param dbre
	 *          The database to use.
	 * @return Result.
	 */

	public boolean run(DatabaseRegistryEntry dbre) {

		boolean result = true;

		int singleExonTranscripts = 0, transcriptCount = 0;

		String sql = "SELECT g.gene_id, g.seq_region_start, g.seq_region_end, g.seq_region_strand, tr.transcript_id, tr.seq_region_start, tr.seq_region_end, tr.seq_region_strand,e.exon_id, e.seq_region_start, e.seq_region_end, e.seq_region_strand, et.rank,  g.stable_id, tr.stable_id "
				+ "FROM   gene g, transcript tr, exon_transcript et, exon e "
				+ "WHERE  e.exon_id = et.exon_id "
				+ "AND    et.transcript_id = tr.transcript_id "
				+ "AND    tr.gene_id = g.gene_id " + "ORDER BY et.transcript_id, et.rank";
/*

The sql is:

SELECT 
	g.gene_id, 
	g.seq_region_start, 
	g.seq_region_end, 
	g.seq_region_strand, 
	tr.transcript_id, 
	tr.seq_region_start, 
	tr.seq_region_end, 
	tr.seq_region_strand,
	e.exon_id, 
	e.seq_region_start, 
	e.seq_region_end, 
	e.seq_region_strand, 
	et.rank, 
	gsi.stable_id, 
	tsi.stable_id
FROM   
	gene g, 
	transcript tr, 
	exon_transcript et, 
	exon e, 
	gene_stable_id gsi, 
	transcript_stable_id tsi 
WHERE  
	e.exon_id = et.exon_id 
	AND    et.transcript_id = tr.transcript_id  
	AND    tr.gene_id = g.gene_id 
	AND    g.gene_id = gsi.gene_id  
	AND    tr.transcript_id=tsi.transcript_id 
ORDER BY 
	et.transcript_id, et.rank

 */
		Connection con = dbre.getConnection();
		try {
			Statement stmt = con.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
			stmt.setFetchSize(Integer.MIN_VALUE);
			ResultSet rs = stmt.executeQuery(sql);

			long lastTranscriptID = -1;
			long lastExonStart = -1;
			long lastExonEnd = -1;
			long lastExonStrand = -2;
			long lastExonID = -1;
			int lastExonRank = 0;

			// ResultSet is ordered by transcript ID and rank, so we can loop through
			// and look at the grouped exons for each transcript
			while (rs.next()) {

				long geneID = rs.getLong(1);
				// long geneStart = rs.getLong(2);
				// long geneEnd = rs.getLong(3);
				// int geneStrand = rs.getInt(4);
				long transcriptID = rs.getLong(5);
				long transcriptStart = rs.getLong(6);
				long transcriptEnd = rs.getLong(7);
				int transcriptStrand = rs.getInt(8);
				long exonID = rs.getLong(9);
				long exonStart = rs.getLong(10);
				long exonEnd = rs.getLong(11);
				int exonStrand = rs.getInt(12);
				int exonRank = rs.getInt(13);
				String geneStableID = rs.getString(14);
				String transcriptStableID = rs.getString(15);

				if ("CG32491".equalsIgnoreCase(geneStableID)) {
					continue;
				}
{'fraction_non_alphanumeric': 0.09467325645249863, 'fraction_numerical': 0.013399231191652938, 'mean_word_length': 3.6293848500254193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4332968', 'n_tokens_mistral': 3514, 'n_tokens_neox': 3008, 'n_words': 852}