コード例 #1
0
ファイル: Meta.java プロジェクト: Ensembl/ensj-healthcheck
  /** Check that the schema_version in the meta table is present and matches the database name. */
  private boolean checkSchemaVersionDBName(DatabaseRegistryEntry dbre) {

    boolean result = true;
    // get version from database name
    String dbNameVersion = dbre.getSchemaVersion();
    logger.finest("Schema version from database name: " + dbNameVersion);

    // get version from meta table
    Connection con = dbre.getConnection();

    if (dbNameVersion == null) {
      ReportManager.warning(this, con, "Can't deduce schema version from database name.");
      return false;
    }

    String schemaVersion =
        DBUtils.getRowColumnValue(
            con, "SELECT meta_value FROM meta WHERE meta_key='schema_version'");
    logger.finest("schema_version from meta table: " + schemaVersion);

    if (schemaVersion == null || schemaVersion.length() == 0) {

      ReportManager.problem(this, con, "No schema_version entry in meta table");
      return false;

    } else if (!schemaVersion.matches("[0-9]+")) {

      ReportManager.problem(this, con, "Meta schema_version " + schemaVersion + " is not numeric");
      return false;

    } else if (!dbNameVersion.equals(schemaVersion) && !isSangerVega) { // do
      // not
      // report
      // for
      // sangervega

      ReportManager.problem(
          this,
          con,
          "Meta schema_version "
              + schemaVersion
              + " does not match version inferred from database name ("
              + dbNameVersion
              + ")");
      return false;

    } else {

      ReportManager.correct(
          this,
          con,
          "schema_version " + schemaVersion + " matches database name version " + dbNameVersion);
    }
    return result;
  }
コード例 #2
0
  /** Check that all chromomes have > 0 markers_map_locations and marker_features. */
  private boolean checkAllChromosomesHaveMarkers(Connection con) {

    boolean result = true;

    // find all the chromosomes, and for each one check that it has some
    // markers
    // note a "chromosome" is assumed to be a seq_region that is:
    // - on the top-level co-ordinate system and
    // - doesn't have and _ or . in the name and
    // - has a seq_region name of less than 3 characters
    // - doesn't have a name starting with "Un" or "MT"

    // get top level co-ordinate system ID
    String sql = "SELECT coord_system_id FROM coord_system WHERE rank=1 LIMIT 1";

    String s = DBUtils.getRowColumnValue(con, sql);

    if (s.length() == 0) {
      System.err.println(
          "Error: can't get top-level co-ordinate system for " + DBUtils.getShortDatabaseName(con));
      return false;
    }

    int topLevelCSID = Integer.parseInt(s);

    try {

      // check each top-level seq_region (up to a limit) to see how many
      // marker_map_locations and marker features there are
      Statement stmt = con.createStatement();

      ResultSet rs =
          stmt.executeQuery(
              "SELECT * FROM seq_region WHERE coord_system_id="
                  + topLevelCSID
                  + " AND name NOT LIKE '%\\_%' AND name NOT LIKE '%.%' AND name NOT LIKE 'Un%' AND name NOT LIKE 'MT%' AND LENGTH(name) < 3 ORDER BY name");

      int numTopLevel = 0;

      while (rs.next() && numTopLevel++ < MAX_TOP_LEVEL) {

        long seqRegionID = rs.getLong("seq_region_id");
        String seqRegionName = rs.getString("name");

        // check marker_map_locations
        logger.fine("Counting marker_map_locations on chromosome " + seqRegionName);

        sql =
            "SELECT COUNT(*) FROM marker_map_location WHERE chromosome_name='"
                + seqRegionName
                + "'";
        int rows = DBUtils.getRowCount(con, sql);
        if (rows == 0) {

          ReportManager.problem(
              this,
              con,
              "Chromosome "
                  + seqRegionName
                  + " (seq_region_id "
                  + seqRegionID
                  + ") has no entries in marker_map_location");
          result = false;

        } else {

          ReportManager.correct(
              this, con, "Chromosome " + seqRegionName + " has " + rows + " marker_map_locations");
        }

        // check marker_features
        logger.fine("Counting marker_features on chromosome " + seqRegionName);
        sql = "SELECT COUNT(*) FROM marker_feature WHERE seq_region_id=" + seqRegionID;
        rows = DBUtils.getRowCount(con, sql);
        if (rows == 0) {

          ReportManager.problem(
              this,
              con,
              "Chromosome "
                  + seqRegionName
                  + " (seq_region_id "
                  + seqRegionID
                  + ") has no marker_features");
          result = false;

        } else {

          ReportManager.correct(
              this, con, "Chromosome " + seqRegionName + " has " + rows + " marker_features");
        }
      }

      rs.close();
      stmt.close();

      if (numTopLevel == MAX_TOP_LEVEL) {
        logger.warning("Only checked first " + numTopLevel + " seq_regions");
      }

    } catch (SQLException se) {
      se.printStackTrace();
    }

    return result;
  }