コード例 #1
0
  private boolean checkCodingCountAttributes(final DatabaseRegistryEntry dbre) {
    boolean result = true;

    Connection con = dbre.getConnection();
    String code = (dbre.getType() == DatabaseType.SANGER_VEGA) ? "KnwnPCCount" : "coding_cnt";

    SqlTemplate t = DBUtils.getSqlTemplate(dbre);
    String sql =
        "select distinct g.seq_region_id from gene g where g.biotype = ? and g.seq_region_id not in (select distinct g.seq_region_id from gene g, seq_region_attrib sa, attrib_type at where g.seq_region_id = sa.seq_region_id and sa.attrib_type_id = at.attrib_type_id and at.code in (?,?))";
    List<String> toplevel =
        t.queryForDefaultObjectList(sql, String.class, "protein_coding", "LRG", "non_ref");

    sql =
        "select distinct g.seq_region_id from gene g, seq_region_attrib sa, attrib_type at where g.seq_region_id = sa.seq_region_id and sa.attrib_type_id = at.attrib_type_id and code =? ";
    List<String> known = t.queryForDefaultObjectList(sql, String.class, code);

    Set<String> missing = new HashSet<String>(toplevel);
    missing.removeAll(known);

    if (missing.isEmpty()) {
      ReportManager.correct(
          this,
          con,
          "All seq_regions with protein_coding genes have a coding_cnt attribute associated with them");
    } else {
      String msg =
          String.format(
              "%s regions with protein_coding genes do not have the coding_cnt attribute associated",
              missing.size());
      ReportManager.problem(this, con, msg);
      result = false;
    }

    return result;
  }
  protected int fetchToplevelSeqRegionCount() {

    List<Integer> numSeqRegionsList =
        sqlTemplateTestDb.queryForDefaultObjectList(
            "select count(*) from seq_region join seq_region_attrib using (seq_region_id) join attrib_type using (attrib_type_id) where code='toplevel'",
            Integer.class);

    assertLengthIsOne(numSeqRegionsList);
    Integer numSeqRegions = numSeqRegionsList.get(0);
    return numSeqRegions;
  }
  @Override
  protected boolean runTest(DatabaseRegistryEntry dbre) {

    init(dbre);

    List<Integer> allSpeciesIds =
        sqlTemplateTestDb.queryForDefaultObjectList(
            "select distinct species_id from meta where species_id is not null", Integer.class);

    if (allSpeciesIds.size() == 0) {
      ReportManager.problem(this, testDbConn, "No species configured!");
    }

    boolean allSpeciesPassed = true;

    for (int speciesId : allSpeciesIds) {
      allSpeciesPassed &= runTestForSpecies(dbre, speciesId);
    }

    return allSpeciesPassed;
  }
  /**
   * @param sqlTemplateTestDb
   * @param metaKey
   * @return
   */
  protected String fetchSingleMetaValueFor(
      final SqlTemplate sqlTemplateTestDb, int speciesId, String metaKey) {

    String sql =
        "select meta_value from meta where meta.meta_key = '"
            + metaKey
            + "' and species_id="
            + speciesId;

    List<String> metaValueList = sqlTemplateTestDb.queryForDefaultObjectList(sql, String.class);

    if (metaValueList.size() > 1) {
      throw new RuntimeException(
          "Got more than one meta_value for metaKey " + metaKey + ". Expected only one!\n" + sql);
    }
    if (metaValueList.size() == 0) {
      throw new RuntimeException("Metakey " + metaKey + " is missing in the meta table!\n" + sql);
    }

    String metaValue = metaValueList.get(0);

    return metaValue;
  }