entry : COUNTERS.entrySet()) {
+ long value = entry.getValue().get();
+ try {
+ persistLastValue(entry.getKey(), value);
+ } catch (DaoException ex) {
+ LOG.warn(
+ "Failed to persist sequence {} with value {} during shutdown.",
+ entry.getKey(),
+ value,
+ ex);
+ }
+ }
+ }
+
+ public static void resetCounters() {
+ COUNTERS.clear();
+ SEQUENCE_TABLE_READY.set(false);
+ }
+
+}
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/ClickHouseBulkLoader.java b/src/main/java/org/mskcc/cbio/portal/dao/ClickHouseBulkLoader.java
new file mode 100644
index 00000000..e9122125
--- /dev/null
+++ b/src/main/java/org/mskcc/cbio/portal/dao/ClickHouseBulkLoader.java
@@ -0,0 +1,248 @@
+/*
+ * Copyright (c) 2015 Memorial Sloan-Kettering Cancer Center.
+ *
+ * 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. The software and documentation provided hereunder
+ * is on an "as is" basis, and Memorial Sloan-Kettering Cancer Center has no
+ * obligations to provide maintenance, support, updates, enhancements or
+ * modifications. In no event shall Memorial Sloan-Kettering Cancer Center be
+ * liable to any party for direct, indirect, special, incidental or
+ * consequential damages, including lost profits, arising out of the use of this
+ * software and its documentation, even if Memorial Sloan-Kettering Cancer
+ * Center has been advised of the possibility of such damage.
+ */
+
+/*
+ * This file is part of cBioPortal.
+ *
+ * cBioPortal is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package org.mskcc.cbio.portal.dao;
+
+import org.mskcc.cbio.portal.dao.DaoException;
+import org.mskcc.cbio.portal.util.ProgressMonitor;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Minimal bulk loader that buffers rows in memory and streams them to ClickHouse via
+ * TSVWithNames over the existing JDBC connection. This replaces the previous legacy
+ * LOAD DATA LOCAL INFILE implementation.
+ *
+ * The loader keeps the public API intact so that the various DAO classes do not need to
+ * change their interaction pattern.
+ */
+public class ClickHouseBulkLoader {
+
+ private static final Map BULK_LOADERS = new LinkedHashMap<>();
+
+ private static boolean bulkLoad = false;
+ private static boolean relaxedMode = false;
+
+ private final String tableName;
+ private final List pendingRecords = new ArrayList<>();
+ private String[] fieldNames = null;
+
+ private ClickHouseBulkLoader(String tableName) {
+ this.tableName = tableName;
+ }
+
+ public static ClickHouseBulkLoader getClickHouseBulkLoader(String tableName) {
+ return BULK_LOADERS.computeIfAbsent(tableName, ClickHouseBulkLoader::new);
+ }
+
+ public static int flushAll() throws DaoException {
+ int totalInserted = 0;
+ for (ClickHouseBulkLoader loader : BULK_LOADERS.values()) {
+ totalInserted += loader.flushPendingRecords();
+ }
+ BULK_LOADERS.clear();
+ return totalInserted;
+ }
+
+ private int flushPendingRecords() throws DaoException {
+ if (pendingRecords.isEmpty()) {
+ return 0;
+ }
+
+ final int expectedRows = pendingRecords.size();
+ Connection con = null;
+ PreparedStatement stmt = null;
+ try {
+ con = JdbcUtil.getDbConnection(ClickHouseBulkLoader.class);
+ List columns = resolveColumnNames(con);
+ validateRecordWidths(columns.size());
+
+ byte[] payload = buildTsvPayload(columns);
+ stmt = con.prepareStatement(buildInsertStatement(columns));
+ stmt.setBinaryStream(1, new ByteArrayInputStream(payload));
+
+ int rowsInserted = stmt.executeUpdate();
+ if (rowsInserted <= 0) {
+ rowsInserted = expectedRows;
+ }
+ ProgressMonitor.setCurrentMessage(" --> records inserted into `" + tableName + "` table: " + rowsInserted);
+
+ if (!relaxedMode && rowsInserted != expectedRows) {
+ throw new DaoException("DB Error: only " + rowsInserted + " of the " + expectedRows
+ + " records were inserted in `" + tableName + "`.");
+ }
+
+ pendingRecords.clear();
+ return rowsInserted;
+ } catch (SQLException | IOException exception) {
+ throw new DaoException(exception);
+ } finally {
+ JdbcUtil.closeAll(ClickHouseBulkLoader.class, con, stmt, null);
+ }
+ }
+
+ private String buildInsertStatement(List columnNames) {
+ final String columnsClause = columnNames.isEmpty() ? "" : " (" + String.join(",", columnNames) + ")";
+ return "INSERT INTO " + tableName + columnsClause + " FORMAT TSVWithNames";
+ }
+
+ private List resolveColumnNames(Connection con) throws SQLException, DaoException {
+ if (fieldNames != null) {
+ return Arrays.asList(fieldNames);
+ }
+
+ try (PreparedStatement stmt = con.prepareStatement("DESCRIBE TABLE " + tableName);
+ ResultSet rs = stmt.executeQuery()) {
+ List columns = new ArrayList<>();
+ while (rs.next()) {
+ columns.add(rs.getString("name"));
+ }
+ if (columns.isEmpty()) {
+ throw new DaoException("DB Error: unable to resolve columns for `" + tableName + "`.");
+ }
+ return columns;
+ }
+ }
+
+ private void validateRecordWidths(int columnCount) throws DaoException {
+ for (String[] record : pendingRecords) {
+ if (record.length != columnCount) {
+ throw new DaoException("DB Error: record column count (" + record.length + ") does not match expected column count ("
+ + columnCount + ") for `" + tableName + "`.");
+ }
+ }
+ }
+
+ private byte[] buildTsvPayload(List columnNames) throws DaoException, IOException {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ writeRow(buffer, columnNames);
+ for (String[] record : pendingRecords) {
+ writeRow(buffer, record);
+ }
+ return buffer.toByteArray();
+ }
+
+ private void writeRow(ByteArrayOutputStream buffer, List values) throws IOException {
+ for (int i = 0; i < values.size(); i++) {
+ if (i > 0) {
+ buffer.write('\t');
+ }
+ buffer.write(escapeTsvValue(values.get(i)).getBytes(StandardCharsets.UTF_8));
+ }
+ buffer.write('\n');
+ }
+
+ private void writeRow(ByteArrayOutputStream buffer, String[] values) throws DaoException, IOException {
+ if (values == null) {
+ throw new DaoException("DB Error: encountered null record while preparing bulk insert for `" + tableName + "`.");
+ }
+ for (int i = 0; i < values.length; i++) {
+ if (i > 0) {
+ buffer.write('\t');
+ }
+ buffer.write(escapeTsvValue(values[i]).getBytes(StandardCharsets.UTF_8));
+ }
+ buffer.write('\n');
+ }
+
+ public void insertRecord(String... fieldValues) {
+ if (fieldValues.length == 0) {
+ return;
+ }
+ pendingRecords.add(fieldValues);
+ }
+
+ public static boolean isBulkLoad() {
+ return bulkLoad;
+ }
+
+ public static void bulkLoadOn() {
+ bulkLoad = true;
+ }
+
+ public static void bulkLoadOff() {
+ bulkLoad = false;
+ }
+
+ public static void relaxedModeOn() {
+ relaxedMode = true;
+ }
+
+ public static void relaxedModeOff() {
+ relaxedMode = false;
+ }
+
+ public void setFieldNames(String[] fieldNames) {
+ this.fieldNames = fieldNames;
+ }
+
+ private String escapeTsvValue(String value) {
+ if (value == null || "\\N".equals(value)) {
+ return "\\N";
+ }
+
+ StringBuilder builder = new StringBuilder(value.length());
+ for (int i = 0; i < value.length(); i++) {
+ char ch = value.charAt(i);
+ switch (ch) {
+ case '\\':
+ builder.append("\\\\");
+ break;
+ case '\t':
+ builder.append("\\t");
+ break;
+ case '\n':
+ builder.append("\\n");
+ break;
+ case '\r':
+ builder.append("\\r");
+ break;
+ default:
+ builder.append(ch);
+ break;
+ }
+ }
+ return builder.toString();
+ }
+}
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoAlleleSpecificCopyNumber.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoAlleleSpecificCopyNumber.java
index 100c9ed4..8cb51faa 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoAlleleSpecificCopyNumber.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoAlleleSpecificCopyNumber.java
@@ -32,7 +32,7 @@
package org.mskcc.cbio.portal.dao;
-import org.mskcc.cbio.portal.model.AlleleSpecificCopyNumber;
+import org.mskcc.cbio.portal.model.*;
/**
* Data access object for Mutation table
@@ -40,11 +40,11 @@
public final class DaoAlleleSpecificCopyNumber {
public static int addAlleleSpecificCopyNumber(AlleleSpecificCopyNumber ascn) throws DaoException {
- if (!MySQLbulkLoader.isBulkLoad()) {
- throw new DaoException("You have to turn on MySQLbulkLoader in order to insert allele specific copy numbers");
+ if (!ClickHouseBulkLoader.isBulkLoad()) {
+ throw new DaoException("You have to turn on ClickHouseBulkLoader in order to insert allele specific copy numbers");
} else {
int result = 1;
- MySQLbulkLoader.getMySQLbulkLoader("allele_specific_copy_number").insertRecord(
+ ClickHouseBulkLoader.getClickHouseBulkLoader("allele_specific_copy_number").insertRecord(
resolveValueToString(ascn.getMutationEventId()),
resolveValueToString(ascn.getGeneticProfileId()),
resolveValueToString(ascn.getSampleId()),
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoCancerStudy.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoCancerStudy.java
index dc1b5fe7..5e775a8a 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoCancerStudy.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoCancerStudy.java
@@ -32,23 +32,24 @@
package org.mskcc.cbio.portal.dao;
+import org.apache.commons.lang3.StringUtils;
+import org.mskcc.cbio.portal.model.CancerStudy;
+import org.mskcc.cbio.portal.model.CancerStudyTags;
+import org.mskcc.cbio.portal.model.ReferenceGenome;
+import org.mskcc.cbio.portal.model.TypeOfCancer;
+
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.commons.lang3.StringUtils;
-import org.mskcc.cbio.portal.model.CancerStudy;
-import org.mskcc.cbio.portal.model.CancerStudyTags;
-import org.mskcc.cbio.portal.model.ReferenceGenome;
-import org.mskcc.cbio.portal.model.TypeOfCancer;
/**
* Analogous to and replaces the old DaoCancerType. A CancerStudy has a NAME and
@@ -61,6 +62,8 @@
*/
public final class DaoCancerStudy {
+ private static final int DELETE_BATCH_SIZE = 500;
+
public static enum Status {
UNAVAILABLE,
AVAILABLE
@@ -70,6 +73,7 @@ public static enum Status {
private static final Map cacheDateByInternalId = new HashMap();
private static final Map byStableId = new HashMap();
private static final Map byInternalId = new HashMap();
+ private static final String CANCER_STUDY_SEQUENCE = "seq_cancer_study";
static {
reCacheAll();
@@ -214,7 +218,7 @@ public static void setImportDate(Integer internalId) throws DaoException {
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoCancerStudy.class);
- pstmt = con.prepareStatement("UPDATE cancer_study set IMPORT_DATE = NOW() where cancer_study_id = ?");
+ pstmt = con.prepareStatement("UPDATE cancer_study set import_date = now() where cancer_study_id = ?");
pstmt.setInt(1, internalId);
pstmt.executeUpdate();
} catch (SQLException e) {
@@ -234,10 +238,10 @@ public static java.util.Date getImportDate(String stableCancerStudyId, Integer .
try {
con = JdbcUtil.getDbConnection(DaoCancerStudy.class);
if (internalId.length > 0) {
- pstmt = con.prepareStatement("SELECT IMPORT_DATE FROM cancer_study where cancer_study_id = ?");
+ pstmt = con.prepareStatement("SELECT import_date FROM cancer_study where cancer_study_id = ?");
pstmt.setInt(1, internalId[0]);
} else {
- pstmt = con.prepareStatement("SELECT IMPORT_DATE FROM cancer_study where cancer_study_identifier = ?");
+ pstmt = con.prepareStatement("SELECT import_date FROM cancer_study where cancer_study_identifier = ?");
pstmt.setString(1, stableCancerStudyId);
}
rs = pstmt.executeQuery();
@@ -304,41 +308,38 @@ public static void addCancerStudy(CancerStudy cancerStudy, boolean overwrite) th
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoCancerStudy.class);
+ long cancerStudyId = ClickHouseAutoIncrement.nextId(CANCER_STUDY_SEQUENCE);
pstmt = con.prepareStatement("INSERT INTO cancer_study " +
- "( `CANCER_STUDY_IDENTIFIER`, `NAME`, "
- + "`DESCRIPTION`, `PUBLIC`, `TYPE_OF_CANCER_ID`, "
- + "`PMID`, `CITATION`, `GROUPS`, `STATUS`,`REFERENCE_GENOME_ID`, `IMPORT_DATE` ) VALUES (?,?,?,?,?,?,?,?,?,?,NOW())",
- Statement.RETURN_GENERATED_KEYS);
- pstmt.setString(1, stableId);
- pstmt.setString(2, cancerStudy.getName());
- pstmt.setString(3, cancerStudy.getDescription());
- pstmt.setBoolean(4, cancerStudy.isPublicStudy());
- pstmt.setString(5, cancerStudy.getTypeOfCancerId());
- pstmt.setString(6, cancerStudy.getPmid());
- pstmt.setString(7, cancerStudy.getCitation());
+ "( `cancer_study_id`, `cancer_study_identifier`, `name`, "
+ + "`description`, `public`, `type_of_cancer_id`, "
+ + "`pmid`, `citation`, `groups`, `status`,`reference_genome_id`, `import_date` ) VALUES (?,?,?,?,?,?,?,?,?,?,?,NOW())");
+ pstmt.setLong(1, cancerStudyId);
+ pstmt.setString(2, stableId);
+ pstmt.setString(3, cancerStudy.getName());
+ pstmt.setString(4, cancerStudy.getDescription());
+ pstmt.setBoolean(5, cancerStudy.isPublicStudy());
+ pstmt.setString(6, cancerStudy.getTypeOfCancerId());
+ pstmt.setString(7, cancerStudy.getPmid());
+ pstmt.setString(8, cancerStudy.getCitation());
Set groups = cancerStudy.getGroups();
if (groups==null) {
- pstmt.setString(8, null);
+ pstmt.setString(9, null);
} else {
- pstmt.setString(8, StringUtils.join(groups, ";"));
+ pstmt.setString(9, StringUtils.join(groups, ";"));
}
//status is UNAVAILABLE until other data is loaded for this study. Once all is loaded, the
//data loading process can set this to AVAILABLE:
//TODO - use this field in parts of the system that build up the list of studies to display in home page:
- pstmt.setInt(9, Status.UNAVAILABLE.ordinal());
+ pstmt.setInt(10, Status.UNAVAILABLE.ordinal());
try {
ReferenceGenome referenceGenome = DaoReferenceGenome.getReferenceGenomeByGenomeName(cancerStudy.getReferenceGenome());
- pstmt.setInt(10, referenceGenome.getReferenceGenomeId());
+ pstmt.setInt(11, referenceGenome.getReferenceGenomeId());
}
catch (NullPointerException e) {
throw new DaoException("Unsupported reference genome");
}
pstmt.executeUpdate();
- rs = pstmt.getGeneratedKeys();
- if (rs.next()) {
- int autoId = rs.getInt(1);
- cancerStudy.setInternalId(autoId);
- }
+ cancerStudy.setInternalId((int)cancerStudyId);
cacheCancerStudy(cancerStudy, new java.util.Date());
} catch (SQLException e) {
throw new DaoException(e);
@@ -356,7 +357,7 @@ public static void addCancerStudyTags(CancerStudyTags cancerStudyTags) throws Da
try {
con = JdbcUtil.getDbConnection(DaoCancerStudy.class);
pstmt = con.prepareStatement("INSERT INTO cancer_study_tags " +
- "( `CANCER_STUDY_ID`,`TAGS` ) VALUES (?,?)");
+ "( `cancer_study_id`,`tags` ) VALUES (?,?)");
pstmt.setInt(1, cancerStudyTags.getCancerStudyId());
pstmt.setString(2, cancerStudyTags.getTags());
pstmt.executeUpdate();
@@ -441,10 +442,8 @@ public static void deleteAllRecords() throws DaoException {
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoCancerStudy.class);
- JdbcUtil.disableForeignKeyCheck(con);
pstmt = con.prepareStatement("TRUNCATE TABLE cancer_study");
pstmt.executeUpdate();
- JdbcUtil.enableForeignKeyCheck(con);
} catch (SQLException e) {
throw new DaoException(e);
} finally {
@@ -488,47 +487,6 @@ public static Set getFreshGroups(int internalCancerStudyId) throws DaoEx
}
}
- /**
- * Calls deleteCancerStudyByCascade() if cancer study exists by stable id.
- * @param cancerStudyStableId
- * @throws DaoException
- */
- public static void deleteCancerStudyByCascade(String cancerStudyStableId) throws DaoException {
- CancerStudy study = getCancerStudyByStableId(cancerStudyStableId);
- if (study != null) {
- deleteCancerStudyByCascade(study.getInternalId());
- }
- }
-
- /**
- * Deletes a cancer study by internal id from db with foreign key constraints enforced.
- * @param internalCancerStudyId
- * @throws DaoException
- */
- public static void deleteCancerStudyByCascade(int internalCancerStudyId) throws DaoException {
- Connection con = null;
- PreparedStatement pstmt = null;
- ResultSet rs = null;
- try {
- con = JdbcUtil.getDbConnection(DaoCancerStudy.class);
- pstmt = con.prepareStatement("DELETE FROM cancer_study WHERE cancer_study_id = ?");
- pstmt.setInt(1, internalCancerStudyId);
- int rows = pstmt.executeUpdate();
- // throw dao exception if no rows affected by update
- if (rows == 0) {
- throw new DaoException("deleteCancerStudyByCascade() failed: No rows affected");
- }
- removeCancerStudyFromCache(internalCancerStudyId);
- } catch (SQLException e) {
- throw new DaoException(e);
- } finally {
- JdbcUtil.closeAll(DaoCancerStudy.class, con, pstmt, rs);
- }
- purgeUnreferencedRecordsAfterDeletionOfStudy();
- reCacheAll();
- System.out.println("deleted study:\nID: "+internalCancerStudyId);
- }
-
/**
* Deletes the Specified Cancer Study.
* This method uses a large set of database operations to progressively delete all associated
@@ -545,37 +503,6 @@ public static void deleteCancerStudyByCascade(int internalCancerStudyId) throws
* @deprecated
*/
public static void deleteCancerStudy(int internalCancerStudyId) throws DaoException {
- String[] deleteStudyStatements = {
- "DELETE FROM sample_cna_event WHERE GENETIC_PROFILE_ID IN (SELECT GENETIC_PROFILE_ID FROM genetic_profile WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM genetic_alteration WHERE GENETIC_PROFILE_ID IN (SELECT GENETIC_PROFILE_ID FROM genetic_profile WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM genetic_profile_samples WHERE GENETIC_PROFILE_ID IN (SELECT GENETIC_PROFILE_ID FROM genetic_profile WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM sample_profile WHERE GENETIC_PROFILE_ID IN (SELECT GENETIC_PROFILE_ID FROM genetic_profile WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM mutation WHERE GENETIC_PROFILE_ID IN (SELECT GENETIC_PROFILE_ID FROM genetic_profile WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM alteration_driver_annotation WHERE GENETIC_PROFILE_ID IN (SELECT GENETIC_PROFILE_ID FROM genetic_profile WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM mutation_count_by_keyword WHERE GENETIC_PROFILE_ID IN (SELECT GENETIC_PROFILE_ID FROM genetic_profile WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM clinical_attribute_meta WHERE CANCER_STUDY_ID=?",
- "DELETE FROM resource_definition WHERE CANCER_STUDY_ID=?",
- "DELETE FROM resource_study WHERE INTERNAL_ID=?",
- "DELETE FROM clinical_event_data WHERE CLINICAL_EVENT_ID IN (SELECT CLINICAL_EVENT_ID FROM clinical_event WHERE PATIENT_ID IN (SELECT INTERNAL_ID FROM patient WHERE CANCER_STUDY_ID=?))",
- "DELETE FROM clinical_event WHERE PATIENT_ID IN (SELECT INTERNAL_ID FROM patient WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM sample_list_list WHERE LIST_ID IN (SELECT LIST_ID FROM sample_list WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM clinical_sample WHERE INTERNAL_ID IN (SELECT INTERNAL_ID FROM sample WHERE PATIENT_ID IN (SELECT INTERNAL_ID FROM patient WHERE CANCER_STUDY_ID=?))",
- "DELETE FROM resource_sample WHERE INTERNAL_ID IN (SELECT INTERNAL_ID FROM sample WHERE PATIENT_ID IN (SELECT INTERNAL_ID FROM patient WHERE CANCER_STUDY_ID=?))",
- "DELETE FROM copy_number_seg WHERE CANCER_STUDY_ID=?",
- "DELETE FROM copy_number_seg_file WHERE CANCER_STUDY_ID=?",
- "DELETE FROM sample WHERE PATIENT_ID IN (SELECT INTERNAL_ID FROM patient WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM clinical_patient WHERE INTERNAL_ID IN (SELECT INTERNAL_ID FROM patient WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM resource_patient WHERE INTERNAL_ID IN (SELECT INTERNAL_ID FROM patient WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM patient WHERE CANCER_STUDY_ID=?",
- "DELETE FROM sample_list WHERE CANCER_STUDY_ID=?",
- "DELETE FROM structural_variant WHERE GENETIC_PROFILE_ID IN (SELECT GENETIC_PROFILE_ID FROM genetic_profile WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM genetic_profile_link WHERE REFERRED_GENETIC_PROFILE_ID IN (select GENETIC_PROFILE_ID FROM genetic_profile where CANCER_STUDY_ID=?)",
- "DELETE FROM genetic_profile WHERE CANCER_STUDY_ID=?",
- "DELETE FROM gistic_to_gene WHERE GISTIC_ROI_ID IN (SELECT GISTIC_ROI_ID FROM gistic WHERE CANCER_STUDY_ID=?)",
- "DELETE FROM gistic WHERE CANCER_STUDY_ID=?",
- "DELETE FROM mut_sig WHERE CANCER_STUDY_ID=?",
- "DELETE FROM cancer_study WHERE CANCER_STUDY_ID=?;"
- };
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
@@ -584,14 +511,58 @@ public static void deleteCancerStudy(int internalCancerStudyId) throws DaoExcept
DaoGenericAssay.checkAndDeleteGenericAssayMetaInStudy(internalCancerStudyId);
con = JdbcUtil.getDbConnection(DaoCancerStudy.class);
- for (String statementString : deleteStudyStatements) {
- pstmt = con.prepareStatement(statementString);
- if (statementString.contains("?")) {
- pstmt.setInt(1, internalCancerStudyId);
- }
- pstmt.executeUpdate();
- pstmt.close();
- }
+ List geneticProfileIds = collectIds(con,
+ "SELECT genetic_profile_id FROM genetic_profile WHERE cancer_study_id=?", internalCancerStudyId);
+ List patientIds = collectIds(con,
+ "SELECT internal_id FROM patient WHERE cancer_study_id=?", internalCancerStudyId);
+ List sampleIds = collectIds(con,
+ "SELECT internal_id FROM sample WHERE patient_id IN (SELECT internal_id FROM patient WHERE cancer_study_id=?)",
+ internalCancerStudyId);
+ List sampleListIds = collectIds(con,
+ "SELECT list_id FROM sample_list WHERE cancer_study_id=?", internalCancerStudyId);
+ List clinicalEventIds = collectIds(con,
+ "SELECT clinical_event_id FROM clinical_event WHERE patient_id IN (SELECT internal_id FROM patient WHERE cancer_study_id=?)",
+ internalCancerStudyId);
+ List gisticIds = collectIds(con,
+ "SELECT gistic_roi_id FROM gistic WHERE cancer_study_id=?", internalCancerStudyId);
+
+ deleteByIds(con, "DELETE FROM sample_cna_event WHERE genetic_profile_id IN ", geneticProfileIds);
+ deleteByIds(con, "DELETE FROM genetic_alteration WHERE genetic_profile_id IN ", geneticProfileIds);
+ deleteByIds(con, "DELETE FROM genetic_profile_samples WHERE genetic_profile_id IN ", geneticProfileIds);
+ deleteByIds(con, "DELETE FROM sample_profile WHERE genetic_profile_id IN ", geneticProfileIds);
+ deleteByIds(con, "DELETE FROM mutation WHERE genetic_profile_id IN ", geneticProfileIds);
+ deleteByIds(con, "DELETE FROM alteration_driver_annotation WHERE genetic_profile_id IN ", geneticProfileIds);
+ deleteByIds(con, "DELETE FROM mutation_count_by_keyword WHERE genetic_profile_id IN ", geneticProfileIds);
+ deleteByIds(con, "DELETE FROM structural_variant WHERE genetic_profile_id IN ", geneticProfileIds);
+ deleteByIds(con, "DELETE FROM genetic_profile_link WHERE referred_genetic_profile_id IN ", geneticProfileIds);
+
+ deleteByIds(con, "DELETE FROM gistic_to_gene WHERE gistic_roi_id IN ", gisticIds);
+
+ deleteByIds(con, "DELETE FROM clinical_event_data WHERE clinical_event_id IN ", clinicalEventIds);
+ deleteByIds(con, "DELETE FROM clinical_event WHERE clinical_event_id IN ", clinicalEventIds);
+
+ deleteByIds(con, "DELETE FROM sample_list_list WHERE list_id IN ", sampleListIds);
+
+ deleteByIds(con, "DELETE FROM clinical_sample WHERE internal_id IN ", sampleIds);
+ deleteByIds(con, "DELETE FROM resource_sample WHERE internal_id IN ", sampleIds);
+
+ deleteByIds(con, "DELETE FROM sample WHERE internal_id IN ", sampleIds);
+ deleteByIds(con, "DELETE FROM clinical_patient WHERE internal_id IN ", patientIds);
+ deleteByIds(con, "DELETE FROM resource_patient WHERE internal_id IN ", patientIds);
+
+ deleteByStudyId(con, "DELETE FROM clinical_attribute_meta WHERE cancer_study_id=?", internalCancerStudyId);
+ deleteByStudyId(con, "DELETE FROM resource_definition WHERE cancer_study_id=?", internalCancerStudyId);
+ deleteByStudyId(con, "DELETE FROM resource_study WHERE internal_id=?", internalCancerStudyId);
+ deleteByStudyId(con, "DELETE FROM cancer_study_tags WHERE cancer_study_id=?", internalCancerStudyId);
+ deleteByStudyId(con, "DELETE FROM copy_number_seg WHERE cancer_study_id=?", internalCancerStudyId);
+ deleteByStudyId(con, "DELETE FROM copy_number_seg_file WHERE cancer_study_id=?", internalCancerStudyId);
+ deleteByStudyId(con, "DELETE FROM patient WHERE cancer_study_id=?", internalCancerStudyId);
+ deleteByStudyId(con, "DELETE FROM sample_list WHERE cancer_study_id=?", internalCancerStudyId);
+ deleteByStudyId(con, "DELETE FROM genetic_profile WHERE cancer_study_id=?", internalCancerStudyId);
+ deleteByStudyId(con, "DELETE FROM gistic WHERE cancer_study_id=?", internalCancerStudyId);
+ deleteByStudyId(con, "DELETE FROM mut_sig WHERE cancer_study_id=?", internalCancerStudyId);
+ deleteByStudyId(con, "DELETE FROM cancer_study WHERE cancer_study_id=?", internalCancerStudyId);
+
removeCancerStudyFromCache(internalCancerStudyId);
} catch (SQLException e) {
throw new DaoException(e);
@@ -609,9 +580,9 @@ public static void deleteCancerStudy(int internalCancerStudyId) throws DaoExcept
*/
public static void purgeUnreferencedRecordsAfterDeletionOfStudy() throws DaoException {
String[] deleteStudyStatements = {
- "DELETE FROM cna_event WHERE NOT EXISTS (SELECT * FROM sample_cna_event WHERE sample_cna_event.CNA_EVENT_ID = cna_event.CNA_EVENT_ID)",
- "DELETE FROM mutation_event WHERE NOT EXISTS (SELECT * FROM mutation WHERE mutation.MUTATION_EVENT_ID = mutation_event.MUTATION_EVENT_ID)"
- };
+ "DELETE FROM cna_event WHERE cna_event_id NOT IN (SELECT DISTINCT cna_event_id FROM sample_cna_event)",
+ "DELETE FROM mutation_event WHERE mutation_event_id NOT IN (SELECT DISTINCT mutation_event_id FROM mutation)"
+ };
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
@@ -629,23 +600,65 @@ public static void purgeUnreferencedRecordsAfterDeletionOfStudy() throws DaoExce
}
}
+ private static List collectIds(Connection con, String sql, int cancerStudyId) throws SQLException {
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
+ List ids = new ArrayList<>();
+ try {
+ pstmt = con.prepareStatement(sql);
+ pstmt.setInt(1, cancerStudyId);
+ rs = pstmt.executeQuery();
+ while (rs.next()) {
+ ids.add(rs.getInt(1));
+ }
+ } finally {
+ JdbcUtil.closeAll(DaoCancerStudy.class, null, pstmt, rs);
+ }
+ return ids;
+ }
+
+ private static void deleteByStudyId(Connection con, String sql, int cancerStudyId) throws SQLException {
+ try (PreparedStatement pstmt = con.prepareStatement(sql)) {
+ pstmt.setInt(1, cancerStudyId);
+ pstmt.executeUpdate();
+ }
+ }
+
+ private static void deleteByIds(Connection con, String sqlPrefix, List ids) throws SQLException {
+ if (ids.isEmpty()) {
+ return;
+ }
+ for (int start = 0; start < ids.size(); start += DELETE_BATCH_SIZE) {
+ int end = Math.min(start + DELETE_BATCH_SIZE, ids.size());
+ List chunk = ids.subList(start, end);
+ String placeholders = String.join(",", Collections.nCopies(chunk.size(), "?"));
+ try (PreparedStatement pstmt = con.prepareStatement(sqlPrefix + "(" + placeholders + ")")) {
+ int idx = 1;
+ for (Integer id : chunk) {
+ pstmt.setInt(idx++, id);
+ }
+ pstmt.executeUpdate();
+ }
+ }
+ }
+
/**
* Extracts Cancer Study JDBC Results.
*/
private static CancerStudy extractCancerStudy(ResultSet rs) throws DaoException {
try {
- CancerStudy cancerStudy = new CancerStudy(rs.getString("NAME"),
- rs.getString("DESCRIPTION"),
- rs.getString("CANCER_STUDY_IDENTIFIER"),
- rs.getString("TYPE_OF_CANCER_ID"),
- rs.getBoolean("PUBLIC"));
- cancerStudy.setPmid(rs.getString("PMID"));
- cancerStudy.setCitation(rs.getString("CITATION"));
- cancerStudy.setGroupsInUpperCase(rs.getString("GROUPS"));
- cancerStudy.setInternalId(rs.getInt("CANCER_STUDY_ID"));
- cancerStudy.setImportDate(rs.getDate("IMPORT_DATE"));
+ CancerStudy cancerStudy = new CancerStudy(rs.getString("name"),
+ rs.getString("description"),
+ rs.getString("cancer_study_identifier"),
+ rs.getString("type_of_cancer_id"),
+ rs.getBoolean("public"));
+ cancerStudy.setPmid(rs.getString("pmid"));
+ cancerStudy.setCitation(rs.getString("citation"));
+ cancerStudy.setGroupsInUpperCase(rs.getString("groups"));
+ cancerStudy.setInternalId(rs.getInt("cancer_study_id"));
+ cancerStudy.setImportDate(rs.getDate("import_date"));
cancerStudy.setReferenceGenome(DaoReferenceGenome.getReferenceGenomeByInternalId(
- rs.getInt("REFERENCE_GENOME_ID")).getGenomeName());
+ rs.getInt("reference_genome_id")).getGenomeName());
return cancerStudy;
} catch (SQLException e) {
throw new DaoException(e);
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoClinicalAttributeMeta.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoClinicalAttributeMeta.java
index c9863d7a..5b8db51f 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoClinicalAttributeMeta.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoClinicalAttributeMeta.java
@@ -52,13 +52,13 @@ public static int addDatum(ClinicalAttribute attr) throws DaoException {
con = JdbcUtil.getDbConnection(DaoClinicalAttributeMeta.class);
pstmt = con.prepareStatement
("INSERT INTO clinical_attribute_meta(" +
- "`ATTR_ID`," +
- "`DISPLAY_NAME`," +
- "`DESCRIPTION`," +
- "`DATATYPE`," +
- "`PATIENT_ATTRIBUTE`," +
- "`PRIORITY`," +
- "`CANCER_STUDY_ID`)" +
+ "`attr_id`," +
+ "`display_name`," +
+ "`description`," +
+ "`datatype`," +
+ "`patient_attribute`," +
+ "`priority`," +
+ "`cancer_study_id`)" +
" VALUES(?,?,?,?,?,?,?)");
pstmt.setString(1, attr.getAttrId());
pstmt.setString(2, attr.getDisplayName());
@@ -76,13 +76,13 @@ public static int addDatum(ClinicalAttribute attr) throws DaoException {
}
private static ClinicalAttribute unpack(ResultSet rs) throws SQLException {
- return new ClinicalAttribute(rs.getString("ATTR_ID"),
- rs.getString("DISPLAY_NAME"),
- rs.getString("DESCRIPTION"),
- rs.getString("DATATYPE"),
- rs.getBoolean("PATIENT_ATTRIBUTE"),
- rs.getString("PRIORITY"),
- rs.getInt("CANCER_STUDY_ID"));
+ return new ClinicalAttribute(rs.getString("attr_id"),
+ rs.getString("display_name"),
+ rs.getString("description"),
+ rs.getString("datatype"),
+ rs.getBoolean("patient_attribute"),
+ rs.getString("priority"),
+ rs.getInt("cancer_study_id"));
}
public static ClinicalAttribute getDatum(String attrId, Integer cancerStudyId) throws DaoException {
@@ -104,8 +104,8 @@ public static List getDatum(Collection attrIds, Integ
try {
con = JdbcUtil.getDbConnection(DaoClinicalAttributeMeta.class);
- pstmt = con.prepareStatement("SELECT * FROM clinical_attribute_meta WHERE ATTR_ID IN ('"
- + StringUtils.join(attrIds,"','")+"') AND CANCER_STUDY_ID=" + String.valueOf(cancerStudyId));
+ pstmt = con.prepareStatement("SELECT * FROM clinical_attribute_meta WHERE attr_id IN ('"
+ + StringUtils.join(attrIds,"','")+"') AND cancer_study_id=" + String.valueOf(cancerStudyId));
rs = pstmt.executeQuery();
@@ -132,7 +132,7 @@ public static List getDatum(Collection attrIds) throw
try {
con = JdbcUtil.getDbConnection(DaoClinicalAttributeMeta.class);
- pstmt = con.prepareStatement("SELECT * FROM clinical_attribute_meta WHERE ATTR_ID IN ('"
+ pstmt = con.prepareStatement("SELECT * FROM clinical_attribute_meta WHERE attr_id IN ('"
+ StringUtils.join(attrIds,"','")+"')");
rs = pstmt.executeQuery();
@@ -173,8 +173,8 @@ private static List getDataByCancerStudyId(int cancerStudyId)
ResultSet rs = null;
PreparedStatement pstmt = null;
- String sql = ("SELECT DISTINCT ATTR_ID FROM clinical_attribute_meta"
- + " WHERE CANCER_STUDY_ID = " + String.valueOf(cancerStudyId));
+ String sql = ("SELECT DISTINCT attr_id FROM clinical_attribute_meta"
+ + " WHERE cancer_study_id = " + String.valueOf(cancerStudyId));
Set attrIds = new HashSet();
try {
@@ -183,7 +183,7 @@ private static List getDataByCancerStudyId(int cancerStudyId)
rs = pstmt.executeQuery();
while(rs.next()) {
- attrIds.add(rs.getString("ATTR_ID"));
+ attrIds.add(rs.getString("attr_id"));
}
} catch (SQLException e) {
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoClinicalData.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoClinicalData.java
index d00df0d1..57e6ab7d 100755
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoClinicalData.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoClinicalData.java
@@ -32,8 +32,6 @@
package org.mskcc.cbio.portal.dao;
-import java.sql.*;
-import java.util.*;
import org.apache.commons.lang3.StringUtils;
import org.mskcc.cbio.portal.model.CancerStudy;
import org.mskcc.cbio.portal.model.ClinicalAttribute;
@@ -43,6 +41,20 @@
import org.mskcc.cbio.portal.model.Sample;
import org.mskcc.cbio.portal.util.InternalIdUtil;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* Data Access Object for `clinical` table
*
@@ -53,12 +65,12 @@ public final class DaoClinicalData {
public static final String SAMPLE_ATTRIBUTES_TABLE = "clinical_sample";
public static final String PATIENT_ATTRIBUTES_TABLE = "clinical_patient";
- private static final String SAMPLE_ATTRIBUTES_INSERT = "INSERT INTO " + SAMPLE_ATTRIBUTES_TABLE + "(`INTERNAL_ID`,`ATTR_ID`,`ATTR_VALUE`) VALUES(?,?,?)";
- private static final String PATIENT_ATTRIBUTES_INSERT = "INSERT INTO " + PATIENT_ATTRIBUTES_TABLE + "(`INTERNAL_ID`,`ATTR_ID`,`ATTR_VALUE`) VALUES(?,?,?)";
+ private static final String SAMPLE_ATTRIBUTES_INSERT = "INSERT INTO " + SAMPLE_ATTRIBUTES_TABLE + "(`internal_id`,`attr_id`,`attr_value`) VALUES(?,?,?)";
+ private static final String PATIENT_ATTRIBUTES_INSERT = "INSERT INTO " + PATIENT_ATTRIBUTES_TABLE + "(`internal_id`,`attr_id`,`attr_value`) VALUES(?,?,?)";
- private static final String SAMPLE_ATTRIBUTES_DELETE = "DELETE FROM " + SAMPLE_ATTRIBUTES_TABLE + " WHERE `INTERNAL_ID` = ?";
+ private static final String SAMPLE_ATTRIBUTES_DELETE = "DELETE FROM " + SAMPLE_ATTRIBUTES_TABLE + " WHERE `internal_id` = ?";
- private static final String PATIENT_ATTRIBUTES_DELETE = "DELETE FROM " + PATIENT_ATTRIBUTES_TABLE + " WHERE `INTERNAL_ID` = ?";
+ private static final String PATIENT_ATTRIBUTES_DELETE = "DELETE FROM " + PATIENT_ATTRIBUTES_TABLE + " WHERE `internal_id` = ?";
private static final Map sampleAttributes = new HashMap();
private static final Map patientAttributes = new HashMap();
@@ -87,7 +99,7 @@ private static void cacheAttributes(String table, Map cache)
pstmt = con.prepareStatement("SELECT * FROM " + table);
rs = pstmt.executeQuery();
while (rs.next()) {
- cache.put(rs.getString("ATTR_ID"), rs.getString("ATTR_ID"));
+ cache.put(rs.getString("attr_id"), rs.getString("attr_id"));
}
}
catch (SQLException e) {
@@ -113,8 +125,8 @@ public static int addPatientDatum(int internalPatientId, String attrId, String a
public static int addDatum(String query, String tableName,
int internalId, String attrId, String attrVal) throws DaoException
{
- if (MySQLbulkLoader.isBulkLoad()) {
- MySQLbulkLoader.getMySQLbulkLoader(tableName).insertRecord(Integer.toString(internalId),
+ if (ClickHouseBulkLoader.isBulkLoad()) {
+ ClickHouseBulkLoader.getClickHouseBulkLoader(tableName).insertRecord(Integer.toString(internalId),
attrId,
attrVal);
return 1;
@@ -191,7 +203,7 @@ private static ClinicalData getDatum(int internalCancerStudyId, String table, in
con = JdbcUtil.getDbConnection(DaoClinicalData.class);
pstmt = con.prepareStatement("SELECT * FROM " + table +
- " WHERE INTERNAL_ID=? AND ATTR_ID=?");
+ " WHERE internal_id=? AND attr_id=?");
pstmt.setInt(1, internalId);
pstmt.setString(2, attrId);
@@ -225,7 +237,7 @@ private static List getDataByInternalIds(int internalCancerStudyId
ResultSet rs = null;
List clinicals = new ArrayList();
- String sql = ("SELECT * FROM " + table + " WHERE `INTERNAL_ID` IN " +
+ String sql = ("SELECT * FROM " + table + " WHERE `internal_id` IN " +
"(" + generateIdsSql(internalIds) + ")");
try {
@@ -404,9 +416,12 @@ public static void removeSampleAttributesData(Set sampleInternalIds, St
Connection con = null;
PreparedStatement pstmt = null;
try {
+ if (sampleInternalIds.isEmpty()) {
+ return;
+ }
con = JdbcUtil.getDbConnection(DaoClinicalData.class);
pstmt = con.prepareStatement("DELETE FROM " + SAMPLE_ATTRIBUTES_TABLE
- + " WHERE `ATTR_ID` = ? AND `INTERNAL_ID` IN ("
+ + " WHERE `attr_id` = ? AND `internal_id` IN ("
+ String.join(",", Collections.nCopies(sampleInternalIds.size(), "?"))
+ ")");
int parameterIndex = 1;
@@ -452,9 +467,9 @@ private static List getDataByInternalIds(int internalCancerStudyId
List clinicals = new ArrayList();
- String sql = ("SELECT * FROM " + table + " WHERE `INTERNAL_ID` IN " +
+ String sql = ("SELECT * FROM " + table + " WHERE `internal_id` IN " +
"(" + generateIdsSql(internalIds) + ") " +
- " AND ATTR_ID IN ('"+ StringUtils.join(attributeIds, "','")+"') ");
+ " AND attr_id IN ('"+ StringUtils.join(attributeIds, "','")+"') ");
try {
con = JdbcUtil.getDbConnection(DaoClinicalData.class);
@@ -484,13 +499,13 @@ public static List getDataByAttributeIds(int internalCancerStudyId
con = JdbcUtil.getDbConnection(DaoClinicalData.class);
pstmt = con.prepareStatement("SELECT * FROM clinical_patient WHERE" +
- " ATTR_ID IN ('" + StringUtils.join(attributeIds, "','") +"') ");
+ " attr_id IN ('" + StringUtils.join(attributeIds, "','") +"') ");
List patients = getPatientIdsByCancerStudy(internalCancerStudyId);
rs = pstmt.executeQuery();
while(rs.next()) {
- Integer patientId = rs.getInt("INTERNAL_ID");
+ Integer patientId = rs.getInt("internal_id");
if (patients.contains(patientId)) {
clinicals.add(extract(PATIENT_ATTRIBUTES_TABLE, internalCancerStudyId, rs));
}
@@ -508,11 +523,11 @@ public static List getDataByAttributeIds(int internalCancerStudyId
private static ClinicalData extract(String table, int internalCancerStudyId, ResultSet rs) throws SQLException {
// get
- String stableId = getStableIdFromInternalId(table, rs.getInt("INTERNAL_ID"));
+ String stableId = getStableIdFromInternalId(table, rs.getInt("internal_id"));
return new ClinicalData(internalCancerStudyId,
stableId,
- rs.getString("ATTR_ID"),
- rs.getString("ATTR_VALUE"));
+ rs.getString("attr_id"),
+ rs.getString("attr_value"));
}
private static String getStableIdFromInternalId(String table, int internalId)
@@ -664,8 +679,8 @@ private static List getIdsByAttribute(int cancerStudyId, String paramNa
try{
con = JdbcUtil.getDbConnection(DaoClinicalData.class);
- pstmt = con.prepareStatement ("SELECT INTERNAL_ID FROM `" + tableName + "`"
- + " WHERE ATTR_ID=? AND ATTR_VALUE=?");
+ pstmt = con.prepareStatement ("SELECT internal_id FROM `" + tableName + "`"
+ + " WHERE attr_id=? AND attr_value=?");
pstmt.setString(1, paramName);
pstmt.setString(2, paramValue);
rs = pstmt.executeQuery();
@@ -674,7 +689,7 @@ private static List getIdsByAttribute(int cancerStudyId, String paramNa
while (rs.next())
{
- ids.add(rs.getInt("INTERNAL_ID"));
+ ids.add(rs.getInt("internal_id"));
}
return ids;
@@ -695,10 +710,10 @@ public static Map> getCancerTypeInfoBySamples(List s
try{
con = JdbcUtil.getDbConnection(DaoClinicalData.class);
pstmt = con.prepareStatement("select " +
- "distinct ATTR_VALUE as attributeValue, " +
- "ATTR_ID as attributeID from clinical_sample " +
- "where ATTR_ID in (?, ?) and INTERNAL_ID in (" +
- "select INTERNAL_ID from sample where STABLE_ID in ('"
+ "distinct attr_value as attributeValue, " +
+ "attr_id as attributeID from clinical_sample " +
+ "where attr_id in (?, ?) and internal_id in (" +
+ "select internal_id from sample where stable_id in ('"
+ StringUtils.join(samplesList,"','")+"'))");
pstmt.setString(1, ClinicalAttribute.CANCER_TYPE);
pstmt.setString(2, ClinicalAttribute.CANCER_TYPE_DETAILED);
@@ -738,4 +753,45 @@ public static void removePatientAttributesData(int internalPatientId) throws Dao
JdbcUtil.closeAll(DaoClinicalData.class, con, pstmt, rs);
}
}
+
+ private static List> getExistingAttributes(String tableName, List> internalPatientIdAttributes) throws DaoException {
+ if (internalPatientIdAttributes.isEmpty()) {
+ return Collections.emptyList();
+ }
+ Connection con = null;
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
+
+ try {
+ con = JdbcUtil.getDbConnection(DaoClinicalData.class);
+ pstmt = con.prepareStatement("SELECT internal_id, attr_id FROM `"
+ + tableName + "` WHERE (internal_id, attr_id) IN ("
+ + String.join(",", Collections.nCopies(internalPatientIdAttributes.size(), "(?, ?)")) + ")");
+ int parameterIndex = 1;
+ for (Map.Entry entry : internalPatientIdAttributes) {
+ pstmt.setInt(parameterIndex++, entry.getKey());
+ pstmt.setString(parameterIndex++, entry.getValue());
+ }
+ rs = pstmt.executeQuery();
+
+ List> result = new ArrayList<>();
+ while (rs.next()) {
+ result.add(Map.entry(rs.getInt("internal_id"), rs.getString("attr_id")));
+ }
+
+ return result;
+ } catch (SQLException e) {
+ throw new DaoException(e);
+ } finally {
+ JdbcUtil.closeAll(DaoClinicalData.class, con, pstmt, rs);
+ }
+ }
+
+ public static List> getExistingPatientAttributes(List> internalPatientIdAttributes) throws DaoException {
+ return getExistingAttributes(PATIENT_ATTRIBUTES_TABLE, internalPatientIdAttributes);
+ }
+
+ public static List> getExistingSampleAttributes(List> internalPatientIdAttributes) throws DaoException {
+ return getExistingAttributes(SAMPLE_ATTRIBUTES_TABLE, internalPatientIdAttributes);
+ }
}
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoClinicalEvent.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoClinicalEvent.java
index b7501e6f..44620f7b 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoClinicalEvent.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoClinicalEvent.java
@@ -51,11 +51,11 @@ public final class DaoClinicalEvent {
private DaoClinicalEvent() {}
public static int addClinicalEvent(ClinicalEvent clinicalEvent) {
- if (!MySQLbulkLoader.isBulkLoad()) {
+ if (!ClickHouseBulkLoader.isBulkLoad()) {
throw new IllegalStateException("Only bulk load mode is allowed for importing clinical events");
}
- MySQLbulkLoader.getMySQLbulkLoader("clinical_event").insertRecord(
+ ClickHouseBulkLoader.getClickHouseBulkLoader("clinical_event").insertRecord(
Long.toString(clinicalEvent.getClinicalEventId()),
Integer.toString(clinicalEvent.getPatientId()),
clinicalEvent.getStartDate().toString(),
@@ -68,7 +68,7 @@ public static int addClinicalEvent(ClinicalEvent clinicalEvent) {
private static int addClinicalEventData(ClinicalEvent clinicalEvent) {
long eventId = clinicalEvent.getClinicalEventId();
for (Map.Entry entry : clinicalEvent.getEventData().entrySet()) {
- MySQLbulkLoader.getMySQLbulkLoader("clinical_event_data").insertRecord(
+ ClickHouseBulkLoader.getClickHouseBulkLoader("clinical_event_data").insertRecord(
Long.toString(eventId),
entry.getKey(),
entry.getValue()
@@ -92,9 +92,9 @@ public static List getClinicalEvent(int patientId, String eventTy
// get events first
if (eventType==null) {
- pstmt = con.prepareStatement("SELECT * FROM clinical_event WHERE PATIENT_ID=?");
+ pstmt = con.prepareStatement("SELECT * FROM clinical_event WHERE patient_id=?");
} else {
- pstmt = con.prepareStatement("SELECT * FROM clinical_event WHERE PATIENT_ID=? AND EVENT_TYPE=?");
+ pstmt = con.prepareStatement("SELECT * FROM clinical_event WHERE patient_id=? AND event_type=?");
}
pstmt.setInt(1, patientId);
if (eventType!=null) {
@@ -112,13 +112,13 @@ public static List getClinicalEvent(int patientId, String eventTy
// get data then
if (!clinicalEvents.isEmpty()) {
- pstmt = con.prepareStatement("SELECT * FROM clinical_event_data WHERE CLINICAL_EVENT_ID IN ("
+ pstmt = con.prepareStatement("SELECT * FROM clinical_event_data WHERE clinical_event_id IN ("
+ StringUtils.join(clinicalEvents.keySet(), ",") + ")");
rs = pstmt.executeQuery();
while (rs.next()) {
- long eventId = rs.getLong("CLINICAL_EVENT_ID");
- clinicalEvents.get(eventId).addEventDatum(rs.getString("KEY"), rs.getString("VALUE"));
+ long eventId = rs.getLong("clinical_event_id");
+ clinicalEvents.get(eventId).addEventDatum(rs.getString("key"), rs.getString("value"));
}
}
@@ -132,11 +132,11 @@ public static List getClinicalEvent(int patientId, String eventTy
private static ClinicalEvent extractClinicalEvent(ResultSet rs) throws SQLException {
ClinicalEvent clinicalEvent = new ClinicalEvent();
- clinicalEvent.setClinicalEventId(rs.getLong("CLINICAL_EVENT_ID"));
- clinicalEvent.setPatientId(rs.getInt("PATIENT_ID"));
- clinicalEvent.setStartDate(JdbcUtil.readLongFromResultSet(rs, "START_DATE"));
- clinicalEvent.setStopDate(JdbcUtil.readLongFromResultSet(rs, "STOP_DATE"));
- clinicalEvent.setEventType(rs.getString("EVENT_TYPE"));
+ clinicalEvent.setClinicalEventId(rs.getLong("clinical_event_id"));
+ clinicalEvent.setPatientId(rs.getInt("patient_id"));
+ clinicalEvent.setStartDate(JdbcUtil.readLongFromResultSet(rs, "start_date"));
+ clinicalEvent.setStopDate(JdbcUtil.readLongFromResultSet(rs, "stop_date"));
+ clinicalEvent.setEventType(rs.getString("event_type"));
return clinicalEvent;
}
@@ -147,7 +147,7 @@ public static long getLargestClinicalEventId() throws DaoException {
try {
con = JdbcUtil.getDbConnection(DaoClinicalEvent.class);
pstmt = con.prepareStatement
- ("SELECT MAX(`CLINICAL_EVENT_ID`) FROM `clinical_event`");
+ ("SELECT max(`clinical_event_id`) FROM `clinical_event`");
rs = pstmt.executeQuery();
return rs.next() ? rs.getLong(1) : 0;
} catch (SQLException e) {
@@ -170,7 +170,7 @@ public static boolean timeEventsExistForPatient(int patientId) throws DaoExcepti
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoCopyNumberSegment.class);
- pstmt = con.prepareStatement("SELECT EXISTS(SELECT 1 FROM `clinical_event` WHERE `PATIENT_ID`=?)");
+ pstmt = con.prepareStatement("SELECT EXISTS(SELECT 1 FROM `clinical_event` WHERE `patient_id`=?)");
pstmt.setInt(1, patientId);
rs = pstmt.executeQuery();
return rs.next() && rs.getInt(1)==1;
@@ -188,12 +188,12 @@ public static void deleteByCancerStudyId(int cancerStudyId) throws DaoException
try {
con = JdbcUtil.getDbConnection(DaoClinicalEvent.class);
- pstmt = con.prepareStatement("DELETE FROM clinical_event_data WHERE CLINICAL_EVENT_ID IN "
- + "(SELECT CLINICAL_EVENT_ID FROM clinical_event WHERE PATIENT_ID in (SELECT INTERNAL_ID FROM patient where CANCER_STUDY_ID=?))");
+ pstmt = con.prepareStatement("DELETE FROM clinical_event_data WHERE clinical_event_id IN "
+ + "(SELECT clinical_event_id FROM clinical_event WHERE patient_id in (SELECT internal_id FROM patient where cancer_study_id=?))");
pstmt.setInt(1, cancerStudyId);
pstmt.executeUpdate();
- pstmt = con.prepareStatement("DELETE FROM clinical_event WHERE PATIENT_ID in (SELECT INTERNAL_ID FROM patient where CANCER_STUDY_ID=?)");
+ pstmt = con.prepareStatement("DELETE FROM clinical_event WHERE patient_id in (SELECT internal_id FROM patient where cancer_study_id=?)");
pstmt.setInt(1, cancerStudyId);
pstmt.executeUpdate();
} catch (SQLException e) {
@@ -210,7 +210,12 @@ public static void deleteByPatientId(int patientId) throws DaoException {
try {
con = JdbcUtil.getDbConnection(DaoClinicalEvent.class);
- pstmt = con.prepareStatement("DELETE FROM clinical_event WHERE clinical_event.PATIENT_ID = ?");
+ pstmt = con.prepareStatement("DELETE FROM clinical_event_data WHERE clinical_event_id IN (" +
+ "SELECT clinical_event_id FROM clinical_event WHERE patient_id = ?)");
+ pstmt.setInt(1, patientId);
+ pstmt.executeUpdate();
+ pstmt.close();
+ pstmt = con.prepareStatement("DELETE FROM clinical_event WHERE patient_id = ?");
pstmt.setInt(1, patientId);
pstmt.executeUpdate();
} catch (SQLException e) {
@@ -226,12 +231,10 @@ public static void deleteAllRecords() throws DaoException {
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoClinicalData.class);
- JdbcUtil.disableForeignKeyCheck(con);
pstmt = con.prepareStatement("TRUNCATE TABLE clinical_event_data");
pstmt.executeUpdate();
pstmt = con.prepareStatement("TRUNCATE TABLE clinical_event");
pstmt.executeUpdate();
- JdbcUtil.enableForeignKeyCheck(con);
} catch (SQLException e) {
throw new DaoException(e);
} finally {
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoCnaEvent.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoCnaEvent.java
index fa8fa7e0..4cf0facd 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoCnaEvent.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoCnaEvent.java
@@ -43,11 +43,13 @@
* @author jgao
*/
public final class DaoCnaEvent {
+
+ private static final String CNA_EVENT_SEQUENCE = "seq_cna_event";
private DaoCnaEvent() {}
public static void addCaseCnaEvent(CnaEvent cnaEvent, boolean newCnaEvent) throws DaoException {
- if (!MySQLbulkLoader.isBulkLoad()) {
- throw new DaoException("You have to turn on MySQLbulkLoader in order to insert sample_cna_event");
+ if (!ClickHouseBulkLoader.isBulkLoad()) {
+ throw new DaoException("You have to turn on ClickHouseBulkLoader in order to insert sample_cna_event");
}
else {
long eventId = cnaEvent.getEventId();
@@ -57,7 +59,7 @@ public static void addCaseCnaEvent(CnaEvent cnaEvent, boolean newCnaEvent) throw
cnaEvent.setEventId(eventId);
}
- MySQLbulkLoader.getMySQLbulkLoader("sample_cna_event").insertRecord(
+ ClickHouseBulkLoader.getClickHouseBulkLoader("sample_cna_event").insertRecord(
Long.toString(eventId),
Integer.toString(cnaEvent.getSampleId()),
Integer.toString(cnaEvent.getCnaProfileId()),
@@ -72,8 +74,8 @@ public static void addCaseCnaEvent(CnaEvent cnaEvent, boolean newCnaEvent) throw
&& !cnaEvent.getDriverTiersFilter().isEmpty()
&& !cnaEvent.getDriverTiersFilter().toLowerCase().equals("na"))
) {
- MySQLbulkLoader
- .getMySQLbulkLoader("alteration_driver_annotation")
+ ClickHouseBulkLoader
+ .getClickHouseBulkLoader("alteration_driver_annotation")
.insertRecord(
Long.toString(eventId),
Integer.toString(cnaEvent.getCnaProfileId()),
@@ -97,25 +99,23 @@ public static void addCaseCnaEvent(CnaEvent cnaEvent, boolean newCnaEvent) throw
private static long addCnaEventDirectly(CnaEvent cnaEvent) throws DaoException {
Connection con = null;
PreparedStatement pstmt = null;
- ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoCnaEvent.class);
+ long newId = ClickHouseAutoIncrement.nextId(CNA_EVENT_SEQUENCE);
pstmt = con.prepareStatement
("INSERT INTO cna_event (" +
- "`ENTREZ_GENE_ID`," +
- "`ALTERATION` )" +
- " VALUES(?,?)", Statement.RETURN_GENERATED_KEYS);
- pstmt.setLong(1, cnaEvent.getEntrezGeneId());
- pstmt.setInt(2, cnaEvent.getAlteration());
+ "`cna_event_id`, `entrez_gene_id`," +
+ "`alteration` )" +
+ " VALUES(?,?,?)");
+ pstmt.setLong(1, newId);
+ pstmt.setLong(2, cnaEvent.getEntrezGeneId());
+ pstmt.setInt(3, cnaEvent.getAlteration());
pstmt.executeUpdate();
- rs = pstmt.getGeneratedKeys();
- rs.next();
- long newId = rs.getLong(1);
return newId;
} catch (SQLException e) {
throw new DaoException(e);
} finally {
- JdbcUtil.closeAll(DaoCnaEvent.class, con, pstmt, rs);
+ JdbcUtil.closeAll(DaoCnaEvent.class, con, pstmt, null);
}
}
@@ -124,21 +124,33 @@ public static void removeSampleCnaEvents(int cnaProfileId, List sampleI
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
+ if (sampleIds.isEmpty()) {
+ return;
+ }
+ String placeholders = String.join(",", Collections.nCopies(sampleIds.size(), "?"));
con = JdbcUtil.getDbConnection(DaoCnaEvent.class);
- pstmt = con.prepareStatement
- ("DELETE sample_cna_event, alteration_driver_annotation" +
- " FROM sample_cna_event" +
- " LEFT JOIN alteration_driver_annotation ON alteration_driver_annotation.`ALTERATION_EVENT_ID` = sample_cna_event.`CNA_EVENT_ID`" +
- " AND alteration_driver_annotation.`SAMPLE_ID` = sample_cna_event.`SAMPLE_ID`" +
- " AND alteration_driver_annotation.`GENETIC_PROFILE_ID` = sample_cna_event.`GENETIC_PROFILE_ID`" +
- " WHERE sample_cna_event.`GENETIC_PROFILE_ID` = ? AND sample_cna_event.`SAMPLE_ID` IN (" +
- String.join(",", Collections.nCopies(sampleIds.size(), "?"))
- + ")");
+ pstmt = con.prepareStatement(
+ "DELETE FROM alteration_driver_annotation " +
+ "WHERE `genetic_profile_id` = ? AND `sample_id` IN (" + placeholders + ") " +
+ "AND `alteration_event_id` IN (SELECT `cna_event_id` FROM sample_cna_event WHERE `genetic_profile_id` = ? AND `sample_id` IN (" + placeholders + "))");
int parameterIndex = 1;
pstmt.setInt(parameterIndex++, cnaProfileId);
for (Integer sampleId : sampleIds) {
pstmt.setInt(parameterIndex++, sampleId);
}
+ pstmt.setInt(parameterIndex++, cnaProfileId);
+ for (Integer sampleId : sampleIds) {
+ pstmt.setInt(parameterIndex++, sampleId);
+ }
+ pstmt.executeUpdate();
+ pstmt.close();
+ pstmt = con.prepareStatement(
+ "DELETE FROM sample_cna_event WHERE `genetic_profile_id` = ? AND `sample_id` IN (" + placeholders + ")");
+ parameterIndex = 1;
+ pstmt.setInt(parameterIndex++, cnaProfileId);
+ for (Integer sampleId : sampleIds) {
+ pstmt.setInt(parameterIndex++, sampleId);
+ }
pstmt.executeUpdate();
} catch (SQLException e) {
throw new DaoException(e);
@@ -163,15 +175,15 @@ public static Map> getSamplesWithAlterations(String concatEven
try {
con = JdbcUtil.getDbConnection(DaoCnaEvent.class);
String sql = "SELECT * FROM sample_cna_event"
- + " WHERE `CNA_EVENT_ID` IN ("
+ + " WHERE `cna_event_id` IN ("
+ concatEventIds + ")";
pstmt = con.prepareStatement(sql);
Map> map = new HashMap> ();
rs = pstmt.executeQuery();
while (rs.next()) {
- Sample sample = DaoSample.getSampleById(rs.getInt("SAMPLE_ID"));
- long eventId = rs.getLong("CNA_EVENT_ID");
+ Sample sample = DaoSample.getSampleById(rs.getInt("sample_id"));
+ long eventId = rs.getLong("cna_event_id");
Set events = map.get(sample);
if (events == null) {
events = new HashSet();
@@ -196,26 +208,25 @@ public static List getCnaEvents(List sampleIds, Collection events = new ArrayList();
@@ -231,15 +242,15 @@ public static List getCnaEvents(List sampleIds, Collection getAllCnaEvents() throws DaoException {
while (rs.next()) {
try {
CnaEvent.Event event = new CnaEvent.Event();
- event.setEventId(rs.getLong("CNA_EVENT_ID"));
- event.setEntrezGeneId(rs.getLong("ENTREZ_GENE_ID"));
- event.setAlteration(rs.getInt("ALTERATION"));
+ event.setEventId(rs.getLong("cna_event_id"));
+ event.setEntrezGeneId(rs.getLong("entrez_gene_id"));
+ event.setAlteration(rs.getShort("alteration"));
events.add(event);
} catch (IllegalArgumentException e) {
e.printStackTrace();
@@ -287,13 +298,13 @@ public static Map> countSamplesWithCNAGenes(
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoCnaEvent.class);
- String sql = "SELECT `ENTREZ_GENE_ID`, `ALTERATION`, count(*)"
+ String sql = "SELECT `entrez_gene_id`, `alteration`, count(*)"
+ " FROM sample_cna_event, cna_event"
- + " WHERE `GENETIC_PROFILE_ID`=" + profileId
- + " and sample_cna_event.`CNA_EVENT_ID`=cna_event.`CNA_EVENT_ID`"
- + " and `ENTREZ_GENE_ID` IN ("
+ + " WHERE `genetic_profile_id`=" + profileId
+ + " and sample_cna_event.`cna_event_id`=cna_event.`cna_event_id`"
+ + " and `entrez_gene_id` IN ("
+ concatEntrezGeneIds
- + ") GROUP BY `ENTREZ_GENE_ID`, `ALTERATION`";
+ + ") GROUP BY `entrez_gene_id`, `alteration`";
pstmt = con.prepareStatement(sql);
Map> map = new HashMap>();
@@ -332,11 +343,11 @@ public static Map countSamplesWithCnaEvents(String concatEventIds
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoCnaEvent.class);
- String sql = "SELECT `CNA_EVENT_ID`, count(*) FROM sample_cna_event"
- + " WHERE `GENETIC_PROFILE_ID`=" + profileId
- + " and `CNA_EVENT_ID` IN ("
+ String sql = "SELECT `cna_event_id`, count(*) FROM sample_cna_event"
+ + " WHERE `genetic_profile_id`=" + profileId
+ + " and `cna_event_id` IN ("
+ concatEventIds
- + ") GROUP BY `CNA_EVENT_ID`";
+ + ") GROUP BY `cna_event_id`";
pstmt = con.prepareStatement(sql);
Map map = new HashMap();
@@ -362,8 +373,8 @@ public static Set getAlteredGenes(String concatEventIds)
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoCnaEvent.class);
- String sql = "SELECT DISTINCT ENTREZ_GENE_ID FROM cna_event "
- + "WHERE CNA_EVENT_ID in ("
+ String sql = "SELECT DISTINCT entrez_gene_id FROM cna_event "
+ + "WHERE cna_event_id in ("
+ concatEventIds
+ ")";
pstmt = con.prepareStatement(sql);
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoCopyNumberSegment.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoCopyNumberSegment.java
index 5f81737f..42d97192 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoCopyNumberSegment.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoCopyNumberSegment.java
@@ -50,10 +50,10 @@ public final class DaoCopyNumberSegment {
private DaoCopyNumberSegment() {}
public static int addCopyNumberSegment(CopyNumberSegment seg) throws DaoException {
- if (!MySQLbulkLoader.isBulkLoad()) {
- throw new DaoException("You have to turn on MySQLbulkLoader in order to insert mutations");
+ if (!ClickHouseBulkLoader.isBulkLoad()) {
+ throw new DaoException("You have to turn on ClickHouseBulkLoader in order to insert mutations");
} else {
- MySQLbulkLoader.getMySQLbulkLoader("copy_number_seg").insertRecord(
+ ClickHouseBulkLoader.getClickHouseBulkLoader("copy_number_seg").insertRecord(
Long.toString(seg.getSegId()),
Integer.toString(seg.getCancerStudyId()),
Integer.toString(seg.getSampleId()),
@@ -77,21 +77,29 @@ public static int addCopyNumberSegment(CopyNumberSegment seg) throws DaoExceptio
*/
public static void createFractionGenomeAlteredClinicalData(int cancerStudyId, Set sampleIds, boolean updateMode) throws DaoException {
+ if (!ClickHouseBulkLoader.isBulkLoad()) {
+ throw new DaoException("You have to turn on ClickHouseBulkLoader in order to insert Fraction Genome Altered");
+ }
+
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoCopyNumberSegment.class);
pstmt = con.prepareStatement(
- "SELECT `SAMPLE_ID`, IF((SELECT SUM(`END`-`START`) FROM copy_number_seg " +
- "AS c2 WHERE c2.`CANCER_STUDY_ID` = c1.`CANCER_STUDY_ID` AND c2.`SAMPLE_ID` = c1.`SAMPLE_ID` AND " +
- "ABS(c2.`SEGMENT_MEAN`) >= 0.2) IS NULL, 0, (SELECT SUM(`END`-`START`) FROM copy_number_seg " +
- "AS c2 WHERE c2.`CANCER_STUDY_ID` = c1.`CANCER_STUDY_ID` AND c2.`SAMPLE_ID` = c1.`SAMPLE_ID` AND " +
- "ABS(c2.`SEGMENT_MEAN`) >= 0.2) / SUM(`END`-`START`)) AS `VALUE` FROM `copy_number_seg` AS c1 , `cancer_study` " +
- "WHERE c1.`CANCER_STUDY_ID` = cancer_study.`CANCER_STUDY_ID` AND cancer_study.`CANCER_STUDY_ID`=? " +
- (sampleIds == null ? "" : ("AND `SAMPLE_ID` IN ("+ String.join(",", Collections.nCopies(sampleIds.size(), "?")) + ") "))
- +"GROUP BY cancer_study.`CANCER_STUDY_ID` , `SAMPLE_ID` HAVING SUM(`END`-`START`) > 0;");
+ "SELECT c1.`sample_id`, " +
+ "CASE WHEN SUM(c1.`end` - c1.`start`) > 0 THEN " +
+ "ROUND(SUM(CASE WHEN ABS(c1.`segment_mean`) >= ? THEN (c1.`end` - c1.`start`) ELSE 0 END) * 1.0 / " +
+ "SUM(c1.`end` - c1.`start`), 4) " +
+ "ELSE 0 END AS `value` " +
+ "FROM `copy_number_seg` AS c1 " +
+ "INNER JOIN `cancer_study` ON c1.`cancer_study_id` = cancer_study.`cancer_study_id` " +
+ "WHERE cancer_study.`cancer_study_id`=? " +
+ (sampleIds == null ? "" : ("AND c1.`sample_id` IN (" + String.join(",", Collections.nCopies(sampleIds.size(), "?")) + ") ")) +
+ "GROUP BY cancer_study.`cancer_study_id`, c1.`sample_id` " +
+ "HAVING SUM(c1.`end` - c1.`start`) > 0");
int parameterIndex = 1;
+ pstmt.setDouble(parameterIndex++, FRACTION_GENOME_ALTERED_CUTOFF);
pstmt.setInt(parameterIndex++, cancerStudyId);
if (sampleIds != null) {
for (Integer sampleId : sampleIds) {
@@ -131,7 +139,7 @@ public static long getLargestId() throws DaoException {
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement
- ("SELECT MAX(`SEG_ID`) FROM `copy_number_seg`");
+ ("SELECT max(`seg_id`) FROM `copy_number_seg`");
rs = pstmt.executeQuery();
return rs.next() ? rs.getLong(1) : 0;
} catch (SQLException e) {
@@ -161,19 +169,19 @@ public static List getSegmentForSamples(
con = JdbcUtil.getDbConnection(DaoCopyNumberSegment.class);
pstmt = con.prepareStatement
("SELECT * FROM copy_number_seg"
- + " WHERE `SAMPLE_ID` IN "+ concatSampleIds
- + " AND `CANCER_STUDY_ID`="+cancerStudyId);
+ + " WHERE `sample_id` IN "+ concatSampleIds
+ + " AND `cancer_study_id`="+cancerStudyId);
rs = pstmt.executeQuery();
while (rs.next()) {
CopyNumberSegment seg = new CopyNumberSegment(
- rs.getInt("CANCER_STUDY_ID"),
- rs.getInt("SAMPLE_ID"),
- rs.getString("CHR"),
- rs.getLong("START"),
- rs.getLong("END"),
- rs.getInt("NUM_PROBES"),
- rs.getDouble("SEGMENT_MEAN"));
- seg.setSegId(rs.getLong("SEG_ID"));
+ rs.getInt("cancer_study_id"),
+ rs.getInt("sample_id"),
+ rs.getString("chr"),
+ rs.getLong("start"),
+ rs.getLong("end"),
+ rs.getInt("num_probes"),
+ rs.getDouble("segment_mean"));
+ seg.setSegId(rs.getLong("seg_id"));
segs.add(seg);
}
return segs;
@@ -222,18 +230,18 @@ private static Map getCopyNumberAlteredLength(Collection
try {
con = JdbcUtil.getDbConnection(DaoCopyNumberSegment.class);
if (cutoff>0) {
- sql = "SELECT `SAMPLE_ID`, SUM(`END`-`START`)"
+ sql = "SELECT `sample_id`, sum(`end`-`start`)"
+ " FROM `copy_number_seg`"
- + " WHERE `CANCER_STUDY_ID`="+cancerStudyId
- + " AND ABS(`SEGMENT_MEAN`)>=" + cutoff
- + " AND `SAMPLE_ID` IN ('" + StringUtils.join(sampleIds,"','") +"')"
- + " GROUP BY `SAMPLE_ID`";
+ + " WHERE `cancer_study_id`="+cancerStudyId
+ + " AND abs(`segment_mean`)>=" + cutoff
+ + " AND `sample_id` IN ('" + StringUtils.join(sampleIds,"','") +"')"
+ + " GROUP BY `sample_id`";
} else {
- sql = "SELECT `SAMPLE_ID`, SUM(`END`-`START`)"
+ sql = "SELECT `sample_id`, sum(`end`-`start`)"
+ " FROM `copy_number_seg`"
- + " WHERE `CANCER_STUDY_ID`="+cancerStudyId
- + " AND `SAMPLE_ID` IN ('" + StringUtils.join(sampleIds,"','") +"')"
- + " GROUP BY `SAMPLE_ID`";
+ + " WHERE `cancer_study_id`="+cancerStudyId
+ + " AND `sample_id` IN ('" + StringUtils.join(sampleIds,"','") +"')"
+ + " GROUP BY `sample_id`";
}
pstmt = con.prepareStatement(sql);
@@ -264,7 +272,7 @@ public static boolean segmentDataExistForCancerStudy(int cancerStudyId) throws D
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoCopyNumberSegment.class);
- pstmt = con.prepareStatement("SELECT EXISTS (SELECT 1 FROM `copy_number_seg` WHERE `CANCER_STUDY_ID`=?)");
+ pstmt = con.prepareStatement("SELECT EXISTS (SELECT 1 FROM `copy_number_seg` WHERE `cancer_study_id`=?)");
pstmt.setInt(1, cancerStudyId);
rs = pstmt.executeQuery();
return rs.next() && rs.getInt(1)==1;
@@ -289,7 +297,7 @@ public static boolean segmentDataExistForSample(int cancerStudyId, int sampleId)
try {
con = JdbcUtil.getDbConnection(DaoCopyNumberSegment.class);
pstmt = con.prepareStatement("SELECT EXISTS(SELECT 1 FROM `copy_number_seg`"
- + " WHERE `CANCER_STUDY_ID`=? AND `SAMPLE_ID`=?");
+ + " WHERE `cancer_study_id`=? AND `sample_id`=?");
pstmt.setInt(1, cancerStudyId);
pstmt.setInt(2, sampleId);
rs = pstmt.executeQuery();
@@ -310,8 +318,8 @@ public static void deleteSegmentDataForSamples(int cancerStudyId, Set
try {
con = JdbcUtil.getDbConnection(DaoCopyNumberSegment.class);
pstmt = con.prepareStatement("DELETE FROM `copy_number_seg`" +
- " WHERE `CANCER_STUDY_ID`= ?" +
- " AND `SAMPLE_ID` IN (" + String.join(",", Collections.nCopies(sampleIds.size(), "?"))
+ " WHERE `cancer_study_id`= ?" +
+ " AND `sample_id` IN (" + String.join(",", Collections.nCopies(sampleIds.size(), "?"))
+ ")");
int parameterIndex = 1;
pstmt.setInt(parameterIndex++, cancerStudyId);
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoCopyNumberSegmentFile.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoCopyNumberSegmentFile.java
index 41e5ef3a..3bd687fd 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoCopyNumberSegmentFile.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoCopyNumberSegmentFile.java
@@ -36,32 +36,30 @@
import org.mskcc.cbio.portal.model.CopyNumberSegmentFile;
public final class DaoCopyNumberSegmentFile {
+ private static final String COPY_NUMBER_SEG_FILE_SEQUENCE = "seq_copy_number_seg_file";
private DaoCopyNumberSegmentFile() {}
public static int addCopyNumberSegmentFile(CopyNumberSegmentFile copySegFile) throws DaoException
{
Connection con = null;
PreparedStatement pstmt = null;
- ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoCopyNumberSegmentFile.class);
+ long fileId = ClickHouseAutoIncrement.nextId(COPY_NUMBER_SEG_FILE_SEQUENCE);
pstmt = con.prepareStatement
- ("INSERT INTO copy_number_seg_file (`CANCER_STUDY_ID`, `REFERENCE_GENOME_ID`, `DESCRIPTION`,`FILENAME`)"
- + " VALUES (?,?,?,?)", Statement.RETURN_GENERATED_KEYS);
- pstmt.setInt(1, copySegFile.cancerStudyId);
- pstmt.setString(2, copySegFile.referenceGenomeId.toString());
- pstmt.setString(3, copySegFile.description);
- pstmt.setString(4, copySegFile.filename);
+ ("INSERT INTO copy_number_seg_file (`seg_file_id`, `cancer_study_id`, `reference_genome_id`, `description`,`filename`)"
+ + " VALUES (?,?,?,?,?)");
+ pstmt.setLong(1, fileId);
+ pstmt.setInt(2, copySegFile.cancerStudyId);
+ pstmt.setString(3, copySegFile.referenceGenomeId.toString());
+ pstmt.setString(4, copySegFile.description);
+ pstmt.setString(5, copySegFile.filename);
pstmt.executeUpdate();
- rs = pstmt.getGeneratedKeys();
- if (rs.next()) {
- return rs.getInt(1);
- }
- return -1;
+ return (int) fileId;
} catch (SQLException e) {
throw new DaoException(e);
} finally {
- JdbcUtil.closeAll(DaoCopyNumberSegmentFile.class, con, pstmt, rs);
+ JdbcUtil.closeAll(DaoCopyNumberSegmentFile.class, con, pstmt, null);
}
}
@@ -72,16 +70,16 @@ public static CopyNumberSegmentFile getCopyNumberSegmentFile(int cancerStudyId)
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoCopyNumberSegmentFile.class);
- pstmt = con.prepareStatement("SELECT * from copy_number_seg_file WHERE `CANCER_STUDY_ID` = ?");
+ pstmt = con.prepareStatement("SELECT * from copy_number_seg_file WHERE `cancer_study_id` = ?");
pstmt.setInt(1, cancerStudyId);
rs = pstmt.executeQuery();
if (rs.next()) {
CopyNumberSegmentFile cnsf = new CopyNumberSegmentFile();
- cnsf.segFileId = rs.getInt("SEG_FILE_ID");
+ cnsf.segFileId = rs.getInt("seg_file_id");
cnsf.cancerStudyId = cancerStudyId;
- cnsf.referenceGenomeId = CopyNumberSegmentFile.ReferenceGenomeId.valueOf(rs.getString("REFERENCE_GENOME_ID"));
- cnsf.description = rs.getString("DESCRIPTION");
- cnsf.filename = rs.getString("FILENAME");
+ cnsf.referenceGenomeId = CopyNumberSegmentFile.ReferenceGenomeId.valueOf(rs.getString("reference_genome_id"));
+ cnsf.description = rs.getString("description");
+ cnsf.filename = rs.getString("filename");
if (rs.next()) {
throw new SQLException("More than one row was returned.");
}
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoGene.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoGene.java
index b5c0352b..90efc36c 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoGene.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoGene.java
@@ -86,13 +86,13 @@ public static int updateGene(CanonicalGene gene) throws DaoException {
//when it is called in a process that may update a gene more than once
//(e.g. the ImportGeneData updates some of the fields based on one
// input file and other fields based on another input file):
- setBulkLoadAtEnd = MySQLbulkLoader.isBulkLoad();
- MySQLbulkLoader.bulkLoadOff();
+ setBulkLoadAtEnd = ClickHouseBulkLoader.isBulkLoad();
+ ClickHouseBulkLoader.bulkLoadOff();
int rows = 0;
con = JdbcUtil.getDbConnection(DaoGene.class);
pstmt = con.prepareStatement
- ("UPDATE gene SET `HUGO_GENE_SYMBOL`=?, `TYPE`=? WHERE `ENTREZ_GENE_ID`=?");
+ ("UPDATE gene SET `hugo_gene_symbol`=?, `type`=? WHERE `entrez_gene_id`=?");
pstmt.setString(1, gene.getHugoGeneSymbolAllCaps());
pstmt.setString(2, gene.getType());
pstmt.setLong(3, gene.getEntrezGeneId());
@@ -107,7 +107,7 @@ public static int updateGene(CanonicalGene gene) throws DaoException {
} finally {
if (setBulkLoadAtEnd) {
//reset to original state:
- MySQLbulkLoader.bulkLoadOn();
+ ClickHouseBulkLoader.bulkLoadOn();
}
JdbcUtil.closeAll(DaoGene.class, con, pstmt, rs);
}
@@ -144,7 +144,7 @@ public static int addOrUpdateGene(CanonicalGene gene) throws DaoException {
//add gene, referring to this genetic entity
con = JdbcUtil.getDbConnection(DaoGene.class);
pstmt = con.prepareStatement
- ("INSERT INTO gene (`GENETIC_ENTITY_ID`, `ENTREZ_GENE_ID`,`HUGO_GENE_SYMBOL`,`TYPE`) "
+ ("INSERT INTO gene (`genetic_entity_id`, `entrez_gene_id`,`hugo_gene_symbol`,`type`) "
+ "VALUES (?,?,?,?)");
pstmt.setInt(1, geneticEntityId);
pstmt.setLong(2, gene.getEntrezGeneId());
@@ -180,11 +180,11 @@ public static int addOrUpdateGene(CanonicalGene gene) throws DaoException {
* @throws DaoException Database Error.
*/
public static int addGeneAliases(CanonicalGene gene) throws DaoException {
- if (MySQLbulkLoader.isBulkLoad()) {
- // write to the temp file maintained by the MySQLbulkLoader
+ if (ClickHouseBulkLoader.isBulkLoad()) {
+ // write to the temp file maintained by the ClickHouseBulkLoader
Set aliases = gene.getAliases();
for (String alias : aliases) {
- MySQLbulkLoader.getMySQLbulkLoader("gene_alias").insertRecord(
+ ClickHouseBulkLoader.getClickHouseBulkLoader("gene_alias").insertRecord(
Long.toString(gene.getEntrezGeneId()),
alias);
@@ -204,7 +204,7 @@ public static int addGeneAliases(CanonicalGene gene) throws DaoException {
for (String alias : aliases) {
if (!existingAliases.contains(alias)) {
pstmt = con.prepareStatement("INSERT INTO gene_alias "
- + "(`ENTREZ_GENE_ID`,`GENE_ALIAS`) VALUES (?,?)");
+ + "(`entrez_gene_id`,`gene_alias`) VALUES (?,?)");
pstmt.setLong(1, gene.getEntrezGeneId());
pstmt.setString(2, alias);
rows += pstmt.executeUpdate();
@@ -234,7 +234,7 @@ private static CanonicalGene getGene(long entrezGeneId) throws DaoException {
try {
con = JdbcUtil.getDbConnection(DaoGene.class);
pstmt = con.prepareStatement
- ("SELECT * FROM gene WHERE ENTREZ_GENE_ID = ?");
+ ("SELECT * FROM gene WHERE entrez_gene_id = ?");
pstmt.setLong(1, entrezGeneId);
rs = pstmt.executeQuery();
if (rs.next()) {
@@ -261,12 +261,12 @@ private static Set getAliases(long entrezGeneId) throws DaoException {
try {
con = JdbcUtil.getDbConnection(DaoGene.class);
pstmt = con.prepareStatement
- ("SELECT * FROM gene_alias WHERE ENTREZ_GENE_ID = ?");
+ ("SELECT * FROM gene_alias WHERE entrez_gene_id = ?");
pstmt.setLong(1, entrezGeneId);
rs = pstmt.executeQuery();
Set aliases = new HashSet();
while (rs.next()) {
- aliases.add(rs.getString("GENE_ALIAS"));
+ aliases.add(rs.getString("gene_alias"));
}
return aliases;
} catch (SQLException e) {
@@ -287,13 +287,13 @@ private static Map> getAllAliases() throws DaoException {
rs = pstmt.executeQuery();
Map> map = new HashMap>();
while (rs.next()) {
- Long entrez = rs.getLong("ENTREZ_GENE_ID");
+ Long entrez = rs.getLong("entrez_gene_id");
Set aliases = map.get(entrez);
if (aliases==null) {
aliases = new HashSet();
map.put(entrez, aliases);
}
- aliases.add(rs.getString("GENE_ALIAS"));
+ aliases.add(rs.getString("gene_alias"));
}
return map;
} catch (SQLException e) {
@@ -321,12 +321,12 @@ public static ArrayList getAllGenes() throws DaoException {
("SELECT * FROM gene");
rs = pstmt.executeQuery();
while (rs.next()) {
- int geneticEntityId = rs.getInt("GENETIC_ENTITY_ID");
- long entrezGeneId = rs.getInt("ENTREZ_GENE_ID");
+ int geneticEntityId = rs.getInt("genetic_entity_id");
+ long entrezGeneId = rs.getInt("entrez_gene_id");
Set aliases = mapAliases.get(entrezGeneId);
CanonicalGene gene = new CanonicalGene(geneticEntityId, entrezGeneId,
- rs.getString("HUGO_GENE_SYMBOL"), aliases);
- gene.setType(rs.getString("TYPE"));
+ rs.getString("hugo_gene_symbol"), aliases);
+ gene.setType(rs.getString("type"));
geneList.add(gene);
}
return geneList;
@@ -352,7 +352,7 @@ private static CanonicalGene getGene(String hugoGeneSymbol) throws DaoException
try {
con = JdbcUtil.getDbConnection(DaoGene.class);
pstmt = con.prepareStatement
- ("SELECT * FROM gene WHERE HUGO_GENE_SYMBOL = ?");
+ ("SELECT * FROM gene WHERE hugo_gene_symbol = ?");
pstmt.setString(1, hugoGeneSymbol);
rs = pstmt.executeQuery();
if (rs.next()) {
@@ -368,12 +368,12 @@ private static CanonicalGene getGene(String hugoGeneSymbol) throws DaoException
}
private static CanonicalGene extractGene(ResultSet rs) throws SQLException, DaoException {
- int geneticEntityId = rs.getInt("GENETIC_ENTITY_ID");
- long entrezGeneId = rs.getInt("ENTREZ_GENE_ID");
+ int geneticEntityId = rs.getInt("genetic_entity_id");
+ long entrezGeneId = rs.getInt("entrez_gene_id");
Set aliases = getAliases(entrezGeneId);
CanonicalGene gene = new CanonicalGene(geneticEntityId, entrezGeneId,
- rs.getString("HUGO_GENE_SYMBOL"), aliases);
- gene.setType(rs.getString("TYPE"));
+ rs.getString("hugo_gene_symbol"), aliases);
+ gene.setType(rs.getString("type"));
return gene;
}
@@ -391,7 +391,7 @@ public static int getCount() throws DaoException {
try {
con = JdbcUtil.getDbConnection(DaoGene.class);
pstmt = con.prepareStatement
- ("SELECT COUNT(*) FROM gene");
+ ("SELECT count(*) FROM gene");
rs = pstmt.executeQuery();
if (rs.next()) {
return rs.getInt(1);
@@ -417,7 +417,7 @@ public static void deleteGene(long entrezGeneId) throws DaoException {
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoGene.class);
- pstmt = con.prepareStatement("DELETE FROM gene WHERE ENTREZ_GENE_ID=?");
+ pstmt = con.prepareStatement("DELETE FROM gene WHERE entrez_gene_id=?");
pstmt.setLong(1, entrezGeneId);
pstmt.executeUpdate();
} catch (SQLException e) {
@@ -438,7 +438,7 @@ public static void deleteGeneAlias(long entrezGeneId) throws DaoException {
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoGene.class);
- pstmt = con.prepareStatement("DELETE FROM gene_alias WHERE ENTREZ_GENE_ID=?");
+ pstmt = con.prepareStatement("DELETE FROM gene_alias WHERE entrez_gene_id=?");
pstmt.setLong(1, entrezGeneId);
pstmt.executeUpdate();
} catch (SQLException e) {
@@ -461,10 +461,8 @@ public static void deleteAllRecords() throws DaoException {
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoGene.class);
- JdbcUtil.disableForeignKeyCheck(con);
pstmt = con.prepareStatement("TRUNCATE TABLE gene");
pstmt.executeUpdate();
- JdbcUtil.enableForeignKeyCheck(con);
} catch (SQLException e) {
throw new DaoException(e);
} finally {
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoGenePanel.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoGenePanel.java
index b7efd650..0139de54 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoGenePanel.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoGenePanel.java
@@ -40,10 +40,14 @@
import org.mskcc.cbio.portal.util.GenePanelUtil;
import org.mskcc.cbio.portal.util.GenePanelUtil.Pair;
+import static org.mskcc.cbio.portal.util.GenePanelUtil.getAddRemove;
+
/**
* @author heinsz
*/
public class DaoGenePanel {
+
+ private static final String GENE_PANEL_SEQUENCE = "seq_gene_panel";
private static final Map genePanelMap = initMap();
/**
@@ -84,9 +88,9 @@ private static Map extractGenePanelMap(ResultSet rs) throws D
try {
while (rs.next()) {
GenePanel gp = new GenePanel();
- gp.setInternalId(rs.getInt("INTERNAL_ID"));
- gp.setStableId(rs.getString("STABLE_ID"));
- gp.setDescription(rs.getString("DESCRIPTION"));
+ gp.setInternalId(rs.getInt("internal_id"));
+ gp.setStableId(rs.getString("stable_id"));
+ gp.setDescription(rs.getString("description"));
gp.setGenes(extractGenePanelGenes(gp.getInternalId()));
genePanelMap.put(gp.getStableId(), gp);
}
@@ -103,7 +107,7 @@ private static Set extractGenePanelGenes(Integer genePanelId) thr
HashSet toReturn = new HashSet<>();
try {
con = JdbcUtil.getDbConnection(DaoGenePanel.class);
- pstmt = con.prepareStatement("SELECT * FROM gene_panel_list where INTERNAL_ID = ?");
+ pstmt = con.prepareStatement("SELECT * FROM gene_panel_list where internal_id = ?");
pstmt.setInt(1, genePanelId);
rs = pstmt.executeQuery();
DaoGeneOptimized daoGeneOpt = DaoGeneOptimized.getInstance();
@@ -142,26 +146,23 @@ public static void addGenePanel(String stableId, String description, Set
try {
con = JdbcUtil.getDbConnection(DaoGenePanel.class);
for (CanonicalGene canonicalGene : canonicalGenes) {
- pstmt = con.prepareStatement("INSERT INTO gene_panel_list (`INTERNAL_ID`, `GENE_ID`) VALUES (?,?)");
+ pstmt = con.prepareStatement("INSERT INTO gene_panel_list (`internal_id`, `gene_id`) VALUES (?,?)");
pstmt.setInt(1, internalId);
pstmt.setLong(2, canonicalGene.getEntrezGeneId());
pstmt.executeUpdate();
@@ -195,7 +196,7 @@ public static void deleteGenePanel(GenePanel genePanel) throws DaoException {
PreparedStatement pstmt = null;
try {
con = JdbcUtil.getDbConnection(DaoGenePanel.class);
- pstmt = con.prepareStatement("DELETE from gene_panel WHERE INTERNAL_ID = ?");
+ pstmt = con.prepareStatement("DELETE from gene_panel WHERE internal_id = ?");
pstmt.setInt(1, genePanel.getInternalId());
pstmt.executeUpdate();
genePanelMap.remove(genePanel.getStableId());
@@ -232,7 +233,7 @@ public static void updateGenePanel(GenePanel genePanel, Set incom
* @throws DaoException
*/
public static void updatePreview(GenePanel genePanel, Set incoming) throws DaoException {
- Pair pair = GenePanelUtil.getAddRemove(incoming, extractGenePanelGenes(genePanel.getInternalId()));
+ Pair pair = getAddRemove(incoming, extractGenePanelGenes(genePanel.getInternalId()));
String add = pair.add.stream()
.map(CanonicalGene::toString)
.collect(Collectors.joining(", "));
@@ -280,13 +281,13 @@ private static void updateGenePanelGeneList(Integer internalId, Set toAdd = pair.add;
Set toRemove = pair.remove;
// Add and remove genes from specified gene panel
for (CanonicalGene canonicalGene : toAdd) {
- pstmt = con.prepareStatement("INSERT INTO gene_panel_list (`INTERNAL_ID`, `GENE_ID`) VALUES (?,?)");
+ pstmt = con.prepareStatement("INSERT INTO gene_panel_list (`internal_id`, `gene_id`) VALUES (?,?)");
pstmt.setInt(1, internalId);
pstmt.setLong(2, canonicalGene.getEntrezGeneId());
pstmt.executeUpdate();
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoGenericAssay.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoGenericAssay.java
index c14efa3f..a14aa14c 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoGenericAssay.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoGenericAssay.java
@@ -19,7 +19,7 @@ public static void setGenericEntityProperty(Integer entityId, String name, Strin
try {
con = JdbcUtil.getDbConnection(DaoGeneticEntity.class);
- pstmt = con.prepareStatement("INSERT INTO generic_entity_properties (`GENETIC_ENTITY_ID`, `NAME`, `VALUE`) "
+ pstmt = con.prepareStatement("INSERT INTO generic_entity_properties (`genetic_entity_id`, `name`, `value`) "
+ "VALUES(?,?,?)");
if (entityId == null) {
return;
@@ -43,7 +43,7 @@ public static void setGenericEntityPropertiesUsingBatch(List map = new HashMap<>();
while(rs.next()) {
- map.put(rs.getString("NAME"), rs.getString("VALUE"));
+ map.put(rs.getString("name"), rs.getString("value"));
}
GenericAssayMeta genericAssayMeta = new GenericAssayMeta(entity.getEntityType(), entity.getStableId(), map);
return genericAssayMeta;
@@ -108,7 +108,7 @@ public static void deleteGenericEntityPropertiesByEntityId(Integer entityId) thr
try {
con = JdbcUtil.getDbConnection(DaoGeneticEntity.class);
- pstmt = con.prepareStatement("DELETE FROM generic_entity_properties WHERE GENETIC_ENTITY_ID=?");
+ pstmt = con.prepareStatement("DELETE FROM generic_entity_properties WHERE genetic_entity_id=?");
if (entityId == null) {
return;
}
@@ -128,13 +128,13 @@ public static boolean geneticEntitiesOnlyExistInSingleStudy(int geneticProfileId
try {
con = JdbcUtil.getDbConnection(DaoGeneticEntity.class);
- pstmt = con.prepareStatement("SELECT DISTINCT CANCER_STUDY_ID FROM genetic_profile WHERE GENETIC_PROFILE_ID IN (SELECT GENETIC_PROFILE_ID FROM genetic_alteration WHERE GENETIC_ENTITY_ID IN (SELECT GENETIC_ENTITY_ID FROM genetic_alteration WHERE GENETIC_PROFILE_ID=?))");
+ pstmt = con.prepareStatement("SELECT DISTINCT cancer_study_id FROM genetic_profile WHERE genetic_profile_id IN (SELECT genetic_profile_id FROM genetic_alteration WHERE genetic_entity_id IN (SELECT genetic_entity_id FROM genetic_alteration WHERE genetic_profile_id=?))");
pstmt.setInt(1, geneticProfileId);
rs = pstmt.executeQuery();
List studies = new ArrayList();
while(rs.next()) {
- studies.add(rs.getInt("CANCER_STUDY_ID"));
+ studies.add(rs.getInt("cancer_study_id"));
}
// check if entities only exist in single study
return studies.size() == 1;
@@ -159,8 +159,8 @@ public static void checkAndDeleteGenericAssayMetaInStudy(int internalCancerStudy
for (GeneticProfile profile : genericAssayProfiles) {
if (DaoGenericAssay.geneticEntitiesOnlyExistInSingleStudy(profile.getGeneticProfileId())) {
- deleteGenericAssayStatements.add(Pair.of(profile.getGeneticProfileId(), "DELETE FROM generic_entity_properties WHERE GENETIC_ENTITY_ID IN (SELECT GENETIC_ENTITY_ID FROM genetic_alteration WHERE GENETIC_PROFILE_ID=?)"));
- deleteGenericAssayStatements.add(Pair.of(profile.getGeneticProfileId(), "DELETE FROM genetic_entity WHERE ID IN (SELECT GENETIC_ENTITY_ID FROM genetic_alteration WHERE GENETIC_PROFILE_ID=?)"));
+ deleteGenericAssayStatements.add(Pair.of(profile.getGeneticProfileId(), "DELETE FROM generic_entity_properties WHERE genetic_entity_id IN (SELECT genetic_entity_id FROM genetic_alteration WHERE genetic_profile_id=?)"));
+ deleteGenericAssayStatements.add(Pair.of(profile.getGeneticProfileId(), "DELETE FROM genetic_entity WHERE id IN (SELECT genetic_entity_id FROM genetic_alteration WHERE genetic_profile_id=?)"));
}
}
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneset.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneset.java
index 65f5fee1..4f186ec0 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneset.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneset.java
@@ -50,6 +50,8 @@
public class DaoGeneset {
+ private static final String GENESET_SEQUENCE = "seq_geneset";
+
private DaoGeneset() {
}
@@ -70,20 +72,18 @@ public static Geneset addGeneset(Geneset geneset) throws DaoException {
geneset.setGeneticEntityId(geneticEntityId);
con = JdbcUtil.getDbConnection(DaoGeneset.class);
- pstmt = con.prepareStatement("INSERT INTO geneset "
- + "(`GENETIC_ENTITY_ID`, `EXTERNAL_ID`, `NAME`, `DESCRIPTION`, `REF_LINK`) "
- + "VALUES(?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS);
- pstmt.setInt(1, geneset.getGeneticEntityId());
- pstmt.setString(2, geneset.getExternalId());
- pstmt.setString(3, geneset.getName());
- pstmt.setString(4, geneset.getDescription());
- pstmt.setString(5, geneset.getRefLink());
+ long genesetId = ClickHouseAutoIncrement.nextId(GENESET_SEQUENCE);
+ pstmt = con.prepareStatement("INSERT INTO geneset "
+ + "(`id`, `genetic_entity_id`, `external_id`, `name`, `description`, `ref_link`) "
+ + "VALUES(?,?,?,?,?,?)");
+ pstmt.setLong(1, genesetId);
+ pstmt.setInt(2, geneset.getGeneticEntityId());
+ pstmt.setString(3, geneset.getExternalId());
+ pstmt.setString(4, geneset.getName());
+ pstmt.setString(5, geneset.getDescription());
+ pstmt.setString(6, geneset.getRefLink());
pstmt.executeUpdate();
- //get the auto generated key:
- rs = pstmt.getGeneratedKeys();
- rs.next();
- int newId = rs.getInt(1);
- geneset.setId(newId);
+ geneset.setId((int) genesetId);
return geneset;
}
@@ -96,7 +96,7 @@ public static Geneset addGeneset(Geneset geneset) throws DaoException {
}
/**
- * Prepares a list of Gene records from Geneset object to be added to database via MySQLbulkLoader.
+ * Prepares a list of Gene records from Geneset object to be added to database via ClickHouseBulkLoader.
* @param geneset
* @return number of records where entrez gene id is found in db
*/
@@ -114,8 +114,8 @@ public static int addGenesetGenesToBulkLoader(Geneset geneset) {
continue;
}
// use this code if bulk loading
- // write to the temp file maintained by the MySQLbulkLoader
- MySQLbulkLoader.getMySQLbulkLoader("geneset_gene").insertRecord(
+ // write to the temp file maintained by the ClickHouseBulkLoader
+ ClickHouseBulkLoader.getClickHouseBulkLoader("geneset_gene").insertRecord(
Integer.toString(geneset.getId()),
Long.toString(entrezGeneId));
rows ++;
@@ -137,14 +137,14 @@ public static List getGenesetGenes(Geneset geneset) throws DaoExc
try {
con = JdbcUtil.getDbConnection(DaoGeneset.class);
- pstmt = con.prepareStatement("SELECT * FROM geneset_gene WHERE GENESET_ID = ?");
+ pstmt = con.prepareStatement("SELECT * FROM geneset_gene WHERE geneset_id = ?");
pstmt.setInt(1, geneset.getId());
rs = pstmt.executeQuery();
// get list of entrez gene ids for geneset record
Set entrezGeneIds = new HashSet();
while (rs.next()) {
- entrezGeneIds.add(rs.getLong("ENTREZ_GENE_ID"));
+ entrezGeneIds.add(rs.getLong("entrez_gene_id"));
}
// get list of genes by entrez gene ids
@@ -176,7 +176,7 @@ public static Geneset getGenesetByExternalId(String externalId) throws DaoExcept
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoGeneset.class);
- pstmt = con.prepareStatement("SELECT * FROM geneset WHERE `EXTERNAL_ID` = ?");
+ pstmt = con.prepareStatement("SELECT * FROM geneset WHERE `external_id` = ?");
pstmt.setString(1, externalId);
rs = pstmt.executeQuery();
@@ -227,12 +227,12 @@ public static List getAllGenesets() throws DaoException {
* @throws DaoException
*/
private static Geneset extractGeneset(ResultSet rs) throws SQLException, DaoException {
- Integer id = rs.getInt("ID");
- Integer geneticEntityId = rs.getInt("GENETIC_ENTITY_ID");
- String externalId = rs.getString("EXTERNAL_ID");
- String name = rs.getString("NAME");
- String description = rs.getString("DESCRIPTION");
- String refLink = rs.getString("REF_LINK");
+ Integer id = rs.getInt("id");
+ Integer geneticEntityId = rs.getInt("genetic_entity_id");
+ String externalId = rs.getString("external_id");
+ String name = rs.getString("name");
+ String description = rs.getString("description");
+ String refLink = rs.getString("ref_link");
Geneset geneset = new Geneset();
geneset.setId(id);
@@ -254,12 +254,12 @@ public static Set getGenesetGeneticEntityIds() throws DaoException {
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoGeneset.class);
- pstmt = con.prepareStatement("SELECT ID FROM genetic_entity WHERE ENTITY_TYPE = 'GENESET'");
+ pstmt = con.prepareStatement("SELECT id FROM genetic_entity WHERE entity_type = 'geneset'");
rs = pstmt.executeQuery();
Set geneticEntities = new HashSet();
while (rs.next()) {
- geneticEntities.add(rs.getLong("ID"));
+ geneticEntities.add(rs.getLong("id"));
}
return geneticEntities;
@@ -277,8 +277,8 @@ public static Set getGenesetGeneticEntityIds() throws DaoException {
* @throws DaoException
*/
public static boolean checkUsage(Integer geneticEntityId) throws DaoException {
- String SQL = "SELECT COUNT(DISTINCT `CANCER_STUDY_ID`) FROM genetic_profile " +
- "WHERE `GENETIC_PROFILE_ID` IN (SELECT `GENETIC_PROFILE_ID` FROM genetic_alteration WHERE `GENETIC_ENTITY_ID` = ?)";
+ String SQL = "SELECT count(DISTINCT `cancer_study_id`) FROM genetic_profile " +
+ "WHERE `genetic_profile_id` IN (SELECT `genetic_profile_id` FROM genetic_alteration WHERE `genetic_entity_id` = ?)";
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
@@ -302,8 +302,8 @@ public static boolean checkUsage(Integer geneticEntityId) throws DaoException {
public static void updateGeneset(Geneset geneset, boolean updateGenesetGenes) throws DaoException {
String SQL = "UPDATE geneset SET " +
- "`NAME` = ?, `DESCRIPTION` = ?, `REF_LINK` = ?" +
- "WHERE `ID` = ?";
+ "`name` = ?, `description` = ?, `ref_link` = ?" +
+ "WHERE `id` = ?";
Connection con = null;
PreparedStatement pstmt = null;
@@ -338,7 +338,7 @@ private static void deleteGenesetGeneticEntityRecords() throws DaoException {
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoGeneset.class);
- pstmt = con.prepareStatement("DELETE FROM genetic_entity WHERE ENTITY_TYPE = 'GENESET'");
+ pstmt = con.prepareStatement("DELETE FROM genetic_entity WHERE entity_type = 'geneset'");
pstmt.executeUpdate();
} catch (SQLException e) {
throw new DaoException(e);
@@ -360,7 +360,7 @@ private static void deleteGenesetGeneticProfiles() throws DaoException {
connection = JdbcUtil.getDbConnection(DaoGeneset.class);
// Prepare statement
- preparedStatement = connection.prepareStatement("DELETE FROM genetic_profile WHERE GENETIC_ALTERATION_TYPE = 'GENESET_SCORE'");
+ preparedStatement = connection.prepareStatement("DELETE FROM genetic_profile WHERE genetic_alteration_type = 'geneset_score'");
// Execute statement
preparedStatement.executeUpdate();
@@ -379,17 +379,28 @@ private static void deleteGenesetGeneticProfiles() throws DaoException {
*/
private static void deleteGenesetGeneticProfileLinks() throws DaoException {
Connection connection = null;
- PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
+ PreparedStatement preparedStatement = null;
try {
connection = JdbcUtil.getDbConnection(DaoGeneset.class);
-
- // Prepare statement: DELETE genetic_profile_link which are pointing to a profile of type to GENESET_SCORE
- preparedStatement = connection.prepareStatement("DELETE FROM genetic_profile_link WHERE REFERRED_GENETIC_PROFILE_ID IN "
- + "(SELECT GENETIC_PROFILE_ID FROM genetic_profile WHERE GENETIC_ALTERATION_TYPE = 'GENESET_SCORE')");
-
- // Execute statement
- preparedStatement.executeUpdate();
+ List genesetProfiles = collectGenesetProfileIds(connection);
+ if (genesetProfiles.isEmpty()) {
+ return;
+ }
+ final int batchSize = 500;
+ for (int start = 0; start < genesetProfiles.size(); start += batchSize) {
+ int end = Math.min(start + batchSize, genesetProfiles.size());
+ List chunk = genesetProfiles.subList(start, end);
+ String placeholders = String.join(",", Collections.nCopies(chunk.size(), "?"));
+ JdbcUtil.closeAll(DaoGeneset.class, null, preparedStatement, null);
+ preparedStatement = connection.prepareStatement(
+ "DELETE FROM genetic_profile_link WHERE referred_genetic_profile_id IN (" + placeholders + ")");
+ int parameterIndex = 1;
+ for (Integer id : chunk) {
+ preparedStatement.setInt(parameterIndex++, id);
+ }
+ preparedStatement.executeUpdate();
+ }
}
catch (SQLException e) {
throw new DaoException(e);
@@ -397,7 +408,24 @@ private static void deleteGenesetGeneticProfileLinks() throws DaoException {
finally {
JdbcUtil.closeAll(DaoGeneset.class, connection, preparedStatement, resultSet);
}
- }
+ }
+
+ private static List collectGenesetProfileIds(Connection connection) throws SQLException {
+ List ids = new ArrayList<>();
+ PreparedStatement preparedStatement = null;
+ ResultSet rs = null;
+ try {
+ preparedStatement = connection.prepareStatement(
+ "SELECT genetic_profile_id FROM genetic_profile WHERE genetic_alteration_type = 'GENESET_SCORE'");
+ rs = preparedStatement.executeQuery();
+ while (rs.next()) {
+ ids.add(rs.getInt(1));
+ }
+ } finally {
+ JdbcUtil.closeAll(DaoGeneset.class, null, preparedStatement, rs);
+ }
+ return ids;
+ }
/**
* Deletes all records from 'geneset' table in database and records in related tables.
@@ -410,7 +438,7 @@ private static void deleteAllGenesetRecords() throws DaoException {
try {
con = JdbcUtil.getDbConnection(DaoGeneset.class);
- pstmt = con.prepareStatement("DELETE FROM geneset");
+ pstmt = con.prepareStatement("TRUNCATE TABLE geneset");
pstmt.executeUpdate();
}
catch (SQLException e) {
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoGenesetHierarchyLeaf.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoGenesetHierarchyLeaf.java
index 9b3fe2c1..37bb50de 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoGenesetHierarchyLeaf.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoGenesetHierarchyLeaf.java
@@ -51,7 +51,7 @@ public static void addGenesetHierarchyLeaf(GenesetHierarchyLeaf genesetHierarchy
// Prepare SQL statement
preparedStatement = connection.prepareStatement("INSERT INTO geneset_hierarchy_leaf "
- + "(`NODE_ID`, `GENESET_ID`) VALUES(?,?)");
+ + "(`node_id`, `geneset_id`) VALUES(?,?)");
// Fill in statement
preparedStatement.setInt(1, genesetHierarchyLeaf.getNodeId());
@@ -77,7 +77,7 @@ public static List getGenesetHierarchyLeafsByGenesetId(int
connection = JdbcUtil.getDbConnection(DaoGenesetHierarchyLeaf.class);
// Prepare SQL statement
- preparedStatement = connection.prepareStatement("SELECT * FROM geneset_hierarchy_leaf WHERE GENESET_ID = ?");
+ preparedStatement = connection.prepareStatement("SELECT * FROM geneset_hierarchy_leaf WHERE geneset_id = ?");
preparedStatement.setInt(1, genesetId);
// Execute statement
@@ -87,8 +87,8 @@ public static List getGenesetHierarchyLeafsByGenesetId(int
while (resultSet.next()) {
GenesetHierarchyLeaf genesetHierarchyLeaf = new GenesetHierarchyLeaf();
- genesetHierarchyLeaf.setNodeId(resultSet.getInt("NODE_ID"));
- genesetHierarchyLeaf.setGenesetId(resultSet.getInt("GENESET_ID"));
+ genesetHierarchyLeaf.setNodeId(resultSet.getInt("node_id"));
+ genesetHierarchyLeaf.setGenesetId(resultSet.getInt("geneset_id"));
genesetHierarchyLeafs.add(genesetHierarchyLeaf);
}
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoGenesetHierarchyNode.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoGenesetHierarchyNode.java
index e13b5838..ac923436 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoGenesetHierarchyNode.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoGenesetHierarchyNode.java
@@ -31,7 +31,9 @@
import org.mskcc.cbio.portal.model.GenesetHierarchy;
public class DaoGenesetHierarchyNode {
-
+
+ private static final String GENESET_HIERARCHY_SEQUENCE = "seq_geneset_hierarchy_node";
+
private DaoGenesetHierarchyNode() {
}
@@ -42,7 +44,6 @@ private DaoGenesetHierarchyNode() {
public static void addGenesetHierarchy(GenesetHierarchy genesetHierarchy) throws DaoException {
Connection connection = null;
PreparedStatement preparedStatement = null;
- ResultSet resultSet = null;
try {
// Open connection to database
@@ -50,29 +51,28 @@ public static void addGenesetHierarchy(GenesetHierarchy genesetHierarchy) throws
// Prepare SQL statement
preparedStatement = connection.prepareStatement("INSERT INTO geneset_hierarchy_node "
- + "(`NODE_NAME`, `PARENT_ID`) VALUES(?,?)", Statement.RETURN_GENERATED_KEYS);
+ + "(`node_id`, `node_name`, `parent_id`) VALUES(?,?,?)");
+ long nodeId = ClickHouseAutoIncrement.nextId(GENESET_HIERARCHY_SEQUENCE);
+ preparedStatement.setLong(1, nodeId);
// Fill in statement
- preparedStatement.setString(1, genesetHierarchy.getNodeName());
+ preparedStatement.setString(2, genesetHierarchy.getNodeName());
if (genesetHierarchy.getParentId() == 0) {
- preparedStatement.setNull(2, java.sql.Types.INTEGER);
+ preparedStatement.setNull(3, java.sql.Types.INTEGER);
} else {
- preparedStatement.setInt(2, genesetHierarchy.getParentId());
+ preparedStatement.setInt(3, genesetHierarchy.getParentId());
}
// Execute statement
preparedStatement.executeUpdate();
// Get the auto generated key, which is the Node ID:
- resultSet = preparedStatement.getGeneratedKeys();
- if (resultSet.next()) {
- genesetHierarchy.setNodeId(resultSet.getInt(1));
- }
+ genesetHierarchy.setNodeId((int) nodeId);
} catch (SQLException e) {
throw new DaoException(e);
} finally {
- JdbcUtil.closeAll(DaoGenesetHierarchyNode.class, connection, preparedStatement, resultSet);
+ JdbcUtil.closeAll(DaoGenesetHierarchyNode.class, connection, preparedStatement, null);
}
}
@@ -118,7 +118,7 @@ public static void deleteAllGenesetHierarchyRecords() throws DaoException {
ResultSet resultSet = null;
try {
connection = JdbcUtil.getDbConnection(DaoGenesetHierarchyNode.class);
- preparedStatement = connection.prepareStatement("DELETE FROM geneset_hierarchy_node");
+ preparedStatement = connection.prepareStatement("TRUNCATE TABLE geneset_hierarchy_node");
preparedStatement.executeUpdate();
} catch (SQLException e) {
throw new DaoException(e);
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticAlteration.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticAlteration.java
index efc92ea1..48cb5144 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticAlteration.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticAlteration.java
@@ -111,9 +111,9 @@ public int addGeneticAlterationsForGeneticEntity(int geneticProfileId, int genet
valueBuffer.append(value).append(DELIM);
}
- if (MySQLbulkLoader.isBulkLoad() ) {
- // write to the temp file maintained by the MySQLbulkLoader
- MySQLbulkLoader.getMySQLbulkLoader("genetic_alteration").insertRecord(Integer.toString( geneticProfileId ),
+ if (ClickHouseBulkLoader.isBulkLoad() ) {
+ // write to the temp file maintained by the ClickHouseBulkLoader
+ ClickHouseBulkLoader.getClickHouseBulkLoader("genetic_alteration").insertRecord(Integer.toString( geneticProfileId ),
Integer.toString( geneticEntityId ), valueBuffer.toString());
// return 1 because normal insert will return 1 if no error occurs
return 1;
@@ -125,10 +125,8 @@ public int addGeneticAlterationsForGeneticEntity(int geneticProfileId, int genet
try {
con = JdbcUtil.getDbConnection(DaoGeneticAlteration.class);
- pstmt = con.prepareStatement
- ("INSERT INTO genetic_alteration (GENETIC_PROFILE_ID, " +
- " GENETIC_ENTITY_ID," +
- " `VALUES`) "
+ pstmt = con.prepareStatement(
+ "INSERT INTO genetic_alteration (genetic_profile_id, genetic_entity_id, `values`) "
+ "VALUES (?,?,?)");
pstmt.setInt(1, geneticProfileId);
pstmt.setLong(2, geneticEntityId);
@@ -227,19 +225,23 @@ public HashMap> getGeneticAlterationMapForEntit
}
try {
con = JdbcUtil.getDbConnection(DaoGeneticAlteration.class);
- if (geneticEntityIds == null) {
- pstmt = con.prepareStatement("SELECT * FROM genetic_alteration WHERE"
- + " GENETIC_PROFILE_ID = " + geneticProfileId);
+ if (geneticEntityIds == null || geneticEntityIds.isEmpty()) {
+ pstmt = con.prepareStatement("SELECT * FROM genetic_alteration WHERE genetic_profile_id = ?");
+ pstmt.setInt(1, geneticProfileId);
} else {
- pstmt = con.prepareStatement("SELECT * FROM genetic_alteration WHERE"
- + " GENETIC_PROFILE_ID = " + geneticProfileId
- + " AND GENETIC_ENTITY_ID IN ("+StringUtils.join(geneticEntityIds, ",")+")");
+ String placeholders = String.join(",", Collections.nCopies(geneticEntityIds.size(), "?"));
+ pstmt = con.prepareStatement("SELECT * FROM genetic_alteration WHERE genetic_profile_id = ? AND genetic_entity_id IN (" + placeholders + ")");
+ pstmt.setInt(1, geneticProfileId);
+ int index = 2;
+ for (Integer geneticEntityId : geneticEntityIds) {
+ pstmt.setInt(index++, geneticEntityId);
+ }
}
rs = pstmt.executeQuery();
while (rs.next()) {
HashMap mapSampleValue = new HashMap();
- int geneticEntityId = rs.getInt("GENETIC_ENTITY_ID");
- String values = rs.getString("VALUES");
+ int geneticEntityId = rs.getInt("genetic_entity_id");
+ String values = rs.getString("values");
String[] valueParts = values.split(DELIM, -1);
int valuesLength = valueParts.length;
boolean hasMeaninglessTrailingDelimiter = valuesLength - orderedSampleList.size() == 1 && valueParts[valuesLength - 1].isEmpty();
@@ -250,7 +252,7 @@ public HashMap> getGeneticAlterationMapForEntit
if (valuesLength != orderedSampleList.size()) {
throw new IllegalStateException(
"Data inconsistency detected: The length of the values for genetic profile with Id = "
- + geneticProfileId + " and genetic entity with ID = " + geneticEntityId
+ + geneticProfileId + " and genetic entity with id = " + geneticEntityId
+ " (" + valuesLength + " elements) does not match the expected length of the sample list ("
+ orderedSampleList.size() + " elements).");
}
@@ -299,14 +301,12 @@ public static ArrayList getProcessedAlterationData(
try {
con = JdbcUtil.getDbConnection(DaoGeneticAlteration.class);
- pstmt = con.prepareStatement("SELECT * FROM genetic_alteration WHERE"
- + " GENETIC_PROFILE_ID = " + geneticProfileId
- + " LIMIT 3000 OFFSET " + offSet);
-
+ pstmt = con.prepareStatement("SELECT * FROM genetic_alteration WHERE genetic_profile_id = ? LIMIT 3000 OFFSET " + offSet);
+ pstmt.setInt(1, geneticProfileId);
rs = pstmt.executeQuery();
while (rs.next()) {
- long entrezGeneId = DaoGeneOptimized.getEntrezGeneId(rs.getInt("GENETIC_ENTITY_ID"));
- String valuesString = rs.getString("VALUES");
+ long entrezGeneId = DaoGeneOptimized.getEntrezGeneId(rs.getInt("genetic_entity_id"));
+ String valuesString = rs.getString("values");
if (valuesString.endsWith(DELIM)) {
valuesString = valuesString.substring(0, valuesString.length() - DELIM.length());
}
@@ -342,12 +342,12 @@ public Set getGenesInProfile(int geneticProfileId) throws DaoExce
try {
con = JdbcUtil.getDbConnection(DaoGeneticAlteration.class);
pstmt = con.prepareStatement
- ("SELECT * FROM genetic_alteration WHERE GENETIC_PROFILE_ID = ?");
+ ("SELECT * FROM genetic_alteration WHERE genetic_profile_id = ?");
pstmt.setInt(1, geneticProfileId);
rs = pstmt.executeQuery();
while (rs.next()) {
- Long entrezGeneId = DaoGeneOptimized.getEntrezGeneId(rs.getInt("GENETIC_ENTITY_ID"));
+ Long entrezGeneId = DaoGeneOptimized.getEntrezGeneId(rs.getInt("genetic_entity_id"));
geneList.add(daoGene.getGene(entrezGeneId));
}
return geneList;
@@ -373,12 +373,12 @@ public static Set getEntityIdsInProfile(int geneticProfileId) throws Da
try {
con = JdbcUtil.getDbConnection(DaoGeneticAlteration.class);
pstmt = con.prepareStatement
- ("SELECT * FROM genetic_alteration WHERE GENETIC_PROFILE_ID = ?");
+ ("SELECT * FROM genetic_alteration WHERE genetic_profile_id = ?");
pstmt.setInt(1, geneticProfileId);
rs = pstmt.executeQuery();
while (rs.next()) {
- int geneticEntityId = rs.getInt("GENETIC_ENTITY_ID");
+ int geneticEntityId = rs.getInt("genetic_entity_id");
geneticEntityList.add(geneticEntityId);
}
return geneticEntityList;
@@ -402,7 +402,7 @@ public static int getGenesCountInProfile(int geneticProfileId) throws DaoExcepti
try {
con = JdbcUtil.getDbConnection(DaoGeneticAlteration.class);
pstmt = con.prepareStatement
- ("SELECT COUNT(*) FROM genetic_alteration WHERE GENETIC_PROFILE_ID = ?");
+ ("SELECT count(*) FROM genetic_alteration WHERE genetic_profile_id = ?");
pstmt.setInt(1, geneticProfileId);
rs = pstmt.executeQuery();
if (rs.next()) {
@@ -428,7 +428,7 @@ public int getCount() throws DaoException {
try {
con = JdbcUtil.getDbConnection(DaoGeneticAlteration.class);
pstmt = con.prepareStatement
- ("SELECT COUNT(*) FROM genetic_alteration");
+ ("SELECT count(*) FROM genetic_alteration");
rs = pstmt.executeQuery();
if (rs.next()) {
return rs.getInt(1);
@@ -453,8 +453,7 @@ public void deleteAllRecordsInGeneticProfile(long geneticProfileId) throws DaoEx
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoGeneticAlteration.class);
- pstmt = con.prepareStatement("DELETE from " +
- "genetic_alteration WHERE GENETIC_PROFILE_ID=?");
+ pstmt = con.prepareStatement("DELETE from genetic_alteration WHERE genetic_profile_id=?");
pstmt.setLong(1, geneticProfileId);
pstmt.executeUpdate();
} catch (SQLException e) {
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticEntity.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticEntity.java
index d614bbc1..8f2ed303 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticEntity.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticEntity.java
@@ -17,7 +17,7 @@ private DaoGeneticEntity() {
}
private enum SqlAction {
- INSERT, UPDATE, SELECT, DELETE
+ UPDATE, SELECT, DELETE
}
/**
@@ -30,15 +30,23 @@ private enum SqlAction {
public static GeneticEntity addNewGeneticEntity(GeneticEntity geneticEntity) throws DaoException {
- DbContainer container = executeSQLstatment(
- SqlAction.INSERT,
- "INSERT INTO genetic_entity (`ENTITY_TYPE`, `STABLE_ID`) "
- + "VALUES(?,?)",
- geneticEntity.getEntityType(),
- geneticEntity.getStableId()
- );
-
- geneticEntity.setId(container.getId());
+ Connection con = null;
+ PreparedStatement pstmt = null;
+ try {
+ con = JdbcUtil.getDbConnection(DaoGeneticEntity.class);
+ long entityId = ClickHouseAutoIncrement.nextId("seq_genetic_entity");
+ pstmt = con.prepareStatement("INSERT INTO genetic_entity (`id`, `entity_type`, `stable_id`) "
+ + "VALUES(?,?,?)");
+ pstmt.setLong(1, entityId);
+ pstmt.setString(2, geneticEntity.getEntityType());
+ pstmt.setString(3, geneticEntity.getStableId());
+ pstmt.executeUpdate();
+ geneticEntity.setId((int) entityId);
+ } catch (SQLException e) {
+ throw new DaoException(e);
+ } finally {
+ JdbcUtil.closeAll(DaoGeneticEntity.class, con, pstmt, null);
+ }
return geneticEntity;
}
@@ -50,7 +58,7 @@ public static GeneticEntity addNewGeneticEntity(GeneticEntity geneticEntity) thr
* @throws DaoException
*/
public static GeneticEntity getGeneticEntityByStableId(String stableId) throws DaoException {
- DbContainer container = executeSQLstatment(SqlAction.SELECT, "SELECT * FROM genetic_entity WHERE `STABLE_ID` = ?", stableId);
+ DbContainer container = executeSQLstatment(SqlAction.SELECT, "SELECT * FROM genetic_entity WHERE `stable_id` = ?", stableId);
return container.getGeneticEntity();
}
@@ -59,7 +67,7 @@ public static GeneticEntity getGeneticEntityByStableId(String stableId) throws D
* @param id genetic_entity id
*/
public static GeneticEntity getGeneticEntityById(int id) throws DaoException {
- DbContainer container = executeSQLstatment(SqlAction.SELECT, "SELECT * FROM genetic_entity WHERE ID = ?", String.valueOf(id));
+ DbContainer container = executeSQLstatment(SqlAction.SELECT, "SELECT * FROM genetic_entity WHERE id = ?", String.valueOf(id));
return container.getGeneticEntity();
}
@@ -96,9 +104,9 @@ public static List getAllGeneticEntities() throws DaoException {
*/
private static GeneticEntity extractGeneticEntity(ResultSet rs) throws SQLException, DaoException {
- Integer id = rs.getInt("ID");
- String stableId = rs.getString("STABLE_ID");
- String entityType = rs.getString("ENTITY_TYPE");
+ Integer id = rs.getInt("id");
+ String stableId = rs.getString("stable_id");
+ String entityType = rs.getString("entity_type");
GeneticEntity geneticEntity = new GeneticEntity(id, entityType, stableId);
@@ -107,8 +115,8 @@ private static GeneticEntity extractGeneticEntity(ResultSet rs) throws SQLExcept
/**
* Helper method for retrieval of a geneticEntity record from the database
- * @param action type of MySQL operation
- * @param statement MySQL statement
+ * @param action type of SQL operation
+ * @param statement SQL statement
* @param keys Series of values used in the statement (order is important)
* @return Object return data from
* @throws DaoException
@@ -120,24 +128,13 @@ private static DbContainer executeSQLstatment(SqlAction action, String statement
try {
con = JdbcUtil.getDbConnection(DaoGeneticEntity.class);
- // for insert statements the number of affected records is returned
- // this requires the RETURN_GENERATED_KEYS to be set for insert statements.
- int switchGetGeneratedKeys = PreparedStatement.NO_GENERATED_KEYS;
- if (action == SqlAction.INSERT)
- switchGetGeneratedKeys = PreparedStatement.RETURN_GENERATED_KEYS;
-
- pstmt = con.prepareStatement(statement, switchGetGeneratedKeys);
+ pstmt = con.prepareStatement(statement);
int cnt = 1;
for (int i = 0; i < keys.length; i++)
pstmt.setString(cnt++, keys[i]);
switch(action) {
- case INSERT:
- pstmt.executeUpdate();
- rs = pstmt.getGeneratedKeys();
- rs.next();
- return new DbContainer(rs.getInt(1));
case SELECT:
rs = pstmt.executeQuery();
if (rs.next()) {
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticProfile.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticProfile.java
index dce69a95..f7fdc961 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticProfile.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticProfile.java
@@ -42,6 +42,7 @@
import java.util.Map;
import org.mskcc.cbio.portal.model.shared.GeneticAlterationType;
import org.mskcc.cbio.portal.model.GeneticProfile;
+import org.slf4j.Logger;
/**
* Analogous to and replaces the old DaoCancerType. A CancerStudy has a NAME and
@@ -51,8 +52,9 @@
* Data access object for Genetic Profile table
*/
public final class DaoGeneticProfile {
+ private static final Logger log = org.slf4j.LoggerFactory.getLogger(DaoGeneticProfile.class);
private DaoGeneticProfile() {}
-
+ private static final String GENETIC_PROFILE_SEQUENCE = "seq_genetic_profile";
private static final Map byStableId = new HashMap();
private static final Map byInternalId = new HashMap();
private static final Map> byStudy = new HashMap>();
@@ -70,6 +72,7 @@ public static synchronized void reCache() {
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoGeneticProfile.class);
+ log.info("Connection obtained for recaching genetic_profile: " + con);
pstmt = con.prepareStatement
("SELECT * FROM genetic_profile");
@@ -97,46 +100,54 @@ private static void cacheGeneticProfile(GeneticProfile profile) {
}
public static int addGeneticProfile(GeneticProfile profile) throws DaoException {
+ //FIXME: this cast may cause problems in the future
+ profile.setGeneticProfileId((int) ClickHouseAutoIncrement.nextId(GENETIC_PROFILE_SEQUENCE));
+ log.info("Assigned genetic profile ID " + profile.getGeneticProfileId() +
+ " to stable ID " + profile.getStableId());
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int rows = 0;
try {
con = JdbcUtil.getDbConnection(DaoGeneticProfile.class);
+ log.info("Connection obtained for inserting genetic_profile: " + con);
pstmt = con.prepareStatement
- ("INSERT INTO genetic_profile (`STABLE_ID`, `CANCER_STUDY_ID`, "+
- "`GENETIC_ALTERATION_TYPE`, `DATATYPE`, `NAME`, `DESCRIPTION`, "+
- "`SHOW_PROFILE_IN_ANALYSIS_TAB`, `PIVOT_THRESHOLD`, `SORT_ORDER`, `GENERIC_ASSAY_TYPE`, `PATIENT_LEVEL`) " +
- "VALUES (?,?,?,?,?,?,?,?,?,?,?)");
- pstmt.setString(1, profile.getStableId());
- pstmt.setInt(2, profile.getCancerStudyId());
- pstmt.setString(3, profile.getGeneticAlterationType().name());
- pstmt.setString(4, profile.getDatatype());
- pstmt.setString(5, profile.getProfileName());
- pstmt.setString(6, profile.getProfileDescription());
- pstmt.setBoolean(7, profile.showProfileInAnalysisTab());
+ ("INSERT INTO genetic_profile (`genetic_profile_id`, `stable_id`, `cancer_study_id`, "+
+ "`genetic_alteration_type`, `datatype`, `name`, `description`, "+
+ "`show_profile_in_analysis_tab`, `pivot_threshold`, `sort_order`, `generic_assay_type`, `patient_level`) " +
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");
+
+ int index = 1;
+ pstmt.setInt(index++, profile.getGeneticProfileId());
+ pstmt.setString(index++, profile.getStableId());
+ pstmt.setInt(index++, profile.getCancerStudyId());
+ pstmt.setString(index++, profile.getGeneticAlterationType().name());
+ pstmt.setString(index++, profile.getDatatype());
+ pstmt.setString(index++, profile.getProfileName());
+ pstmt.setString(index++, profile.getProfileDescription());
+ pstmt.setBoolean(index++, profile.showProfileInAnalysisTab());
- // `pivot_threshold_value` and `value_sort_order` `GENERIC_ASSAY_TYPE` fields are geneirc assay data specific.
+ // `pivot_threshold_value` and `value_sort_order` `generic_assay_type` fields are geneirc assay data specific.
// These fields are set to null when not present in profile object.
if (profile.getPivotThreshold() == null) {
- pstmt.setNull(8, java.sql.Types.FLOAT);
+ pstmt.setNull(index++, java.sql.Types.FLOAT);
} else {
- pstmt.setFloat(8, profile.getPivotThreshold());
+ pstmt.setFloat(index++, profile.getPivotThreshold());
}
if (profile.getSortOrder() == null) {
- pstmt.setNull(9, java.sql.Types.INTEGER);
+ pstmt.setNull(index++, java.sql.Types.INTEGER);
} else {
- pstmt.setString(9, profile.getSortOrder());
+ pstmt.setString(index++, profile.getSortOrder());
}
if (profile.getGenericAssayType() == null) {
- pstmt.setNull(10, java.sql.Types.VARCHAR);
+ pstmt.setNull(index++, java.sql.Types.VARCHAR);
} else {
- pstmt.setString(10, profile.getGenericAssayType());
+ pstmt.setString(index++, profile.getGenericAssayType());
}
// default value is false
- pstmt.setBoolean(11, profile.getPatientLevel());
+ pstmt.setBoolean(index++, profile.getPatientLevel());
rows = pstmt.executeUpdate();
@@ -166,8 +177,8 @@ public static boolean updateNameAndDescription (int geneticProfileId, String nam
boolean ret = false;
try {
con = JdbcUtil.getDbConnection(DaoGeneticProfile.class);
- pstmt = con.prepareStatement("UPDATE genetic_profile SET NAME=?, DESCRIPTION=? " +
- "WHERE GENETIC_PROFILE_ID=?");
+ pstmt = con.prepareStatement("UPDATE genetic_profile SET name=?, description=? " +
+ "WHERE genetic_profile_id=?");
pstmt.setString(1, name);
pstmt.setString(2, description);
pstmt.setInt(3, geneticProfileId);
@@ -195,8 +206,8 @@ public static boolean updateDatatype(
boolean ret;
try {
con = JdbcUtil.getDbConnection(DaoGeneticProfile.class);
- pstmt = con.prepareStatement("UPDATE genetic_profile SET DATATYPE=? " +
- "WHERE GENETIC_PROFILE_ID=?");
+ pstmt = con.prepareStatement("UPDATE genetic_profile SET datatype=? " +
+ "WHERE genetic_profile_id=?");
pstmt.setString(1, datatype);
pstmt.setInt(2, geneticProfileId);
ret = pstmt.executeUpdate() > 0;
@@ -217,7 +228,7 @@ public static int deleteGeneticProfile(GeneticProfile profile) throws DaoExcepti
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoGeneticProfile.class);
- pstmt = con.prepareStatement("DELETE FROM genetic_profile WHERE STABLE_ID = ?");
+ pstmt = con.prepareStatement("DELETE FROM genetic_profile WHERE stable_id = ?");
pstmt.setString(1, profile.getStableId());
rows = pstmt.executeUpdate();
} catch (SQLException e) {
@@ -261,29 +272,29 @@ public static int getCount() {
private static GeneticProfile extractGeneticProfile(ResultSet rs) throws SQLException {
GeneticProfile profileType = new GeneticProfile();
- profileType.setStableId(rs.getString("STABLE_ID"));
+ profileType.setStableId(rs.getString("stable_id"));
- profileType.setCancerStudyId(rs.getInt("CANCER_STUDY_ID"));
- profileType.setProfileName(rs.getString("NAME"));
- profileType.setProfileDescription(rs.getString("DESCRIPTION"));
+ profileType.setCancerStudyId(rs.getInt("cancer_study_id"));
+ profileType.setProfileName(rs.getString("name"));
+ profileType.setProfileDescription(rs.getString("description"));
try {
- profileType.setShowProfileInAnalysisTab(rs.getBoolean("SHOW_PROFILE_IN_ANALYSIS_TAB"));
+ profileType.setShowProfileInAnalysisTab(rs.getBoolean("show_profile_in_analysis_tab"));
} catch (SQLException e) {
profileType.setShowProfileInAnalysisTab(true);
}
- profileType.setGeneticAlterationType(GeneticAlterationType.valueOf(rs.getString("GENETIC_ALTERATION_TYPE")));
- profileType.setDatatype(rs.getString("DATATYPE"));
- profileType.setGeneticProfileId(rs.getInt("GENETIC_PROFILE_ID"));
- if (rs.getFloat("PIVOT_THRESHOLD") != 0) {
- profileType.setPivotThreshold(rs.getFloat("PIVOT_THRESHOLD"));
+ profileType.setGeneticAlterationType(GeneticAlterationType.valueOf(rs.getString("genetic_alteration_type")));
+ profileType.setDatatype(rs.getString("datatype"));
+ profileType.setGeneticProfileId(rs.getInt("genetic_profile_id"));
+ if (rs.getFloat("pivot_threshold") != 0) {
+ profileType.setPivotThreshold(rs.getFloat("pivot_threshold"));
}
- if (rs.getString("SORT_ORDER") != null && ! rs.getString("SORT_ORDER").equals("") ) {
- profileType.setSortOrder(rs.getString("SORT_ORDER"));
+ if (rs.getString("sort_order") != null && ! rs.getString("sort_order").equals("") ) {
+ profileType.setSortOrder(rs.getString("sort_order"));
}
- if (rs.getString("GENERIC_ASSAY_TYPE") != null && ! rs.getString("GENERIC_ASSAY_TYPE").equals("") ) {
- profileType.setGenericAssayType(rs.getString("GENERIC_ASSAY_TYPE"));
+ if (rs.getString("generic_assay_type") != null && ! rs.getString("generic_assay_type").equals("") ) {
+ profileType.setGenericAssayType(rs.getString("generic_assay_type"));
}
- profileType.setPatientLevel(rs.getBoolean("PATIENT_LEVEL"));
+ profileType.setPatientLevel(rs.getBoolean("patient_level"));
return profileType;
}
@@ -306,10 +317,8 @@ public static void deleteAllRecords() throws DaoException {
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoGeneticProfile.class);
- JdbcUtil.disableForeignKeyCheck(con);
pstmt = con.prepareStatement("TRUNCATE TABLE genetic_profile");
pstmt.executeUpdate();
- JdbcUtil.enableForeignKeyCheck(con);
} catch (SQLException e) {
throw new DaoException(e);
} finally {
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticProfileLink.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticProfileLink.java
index 8caddeb1..b0830ffd 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticProfileLink.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticProfileLink.java
@@ -50,7 +50,7 @@ public static void addGeneticProfileLink(GeneticProfileLink geneticProfileLink)
// Prepare SQL statement
preparedStatement = connection.prepareStatement("INSERT INTO genetic_profile_link "
- + "(REFERRING_GENETIC_PROFILE_ID, REFERRED_GENETIC_PROFILE_ID, REFERENCE_TYPE) VALUES(?,?,?)");
+ + "(referring_genetic_profile_id, referred_genetic_profile_id, reference_type) VALUES(?,?,?)");
// Fill in statement
preparedStatement.setInt(1, geneticProfileLink.getReferringGeneticProfileId());
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticProfileSamples.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticProfileSamples.java
index a598f458..eeaf3565 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticProfileSamples.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneticProfileSamples.java
@@ -67,8 +67,8 @@ public static int addGeneticProfileSamples(int geneticProfileId, List o
try {
con = JdbcUtil.getDbConnection(DaoGeneticProfileSamples.class);
pstmt = con.prepareStatement
- ("INSERT INTO genetic_profile_samples (`GENETIC_PROFILE_ID`, " +
- "`ORDERED_SAMPLE_LIST`) "+ "VALUES (?,?)");
+ ("INSERT INTO genetic_profile_samples (`genetic_profile_id`, " +
+ "`ordered_sample_list`) "+ "VALUES (?,?)");
pstmt.setInt(1, geneticProfileId);
pstmt.setString(2, orderedSampleListBuf.toString());
return pstmt.executeUpdate();
@@ -93,8 +93,7 @@ public static void deleteAllSamplesInGeneticProfile(int geneticProfileId) throws
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoGeneticProfileSamples.class);
- pstmt = con.prepareStatement("DELETE from " +
- "genetic_profile_samples WHERE GENETIC_PROFILE_ID=?");
+ pstmt = con.prepareStatement("DELETE from genetic_profile_samples WHERE genetic_profile_id=?");
pstmt.setLong(1, geneticProfileId);
pstmt.executeUpdate();
} catch (SQLException e) {
@@ -117,11 +116,11 @@ public static ArrayList getOrderedSampleList(int geneticProfileId) thr
try {
con = JdbcUtil.getDbConnection(DaoGeneticProfileSamples.class);
pstmt = con.prepareStatement
- ("SELECT * FROM genetic_profile_samples WHERE GENETIC_PROFILE_ID = ?");
+ ("SELECT * FROM genetic_profile_samples WHERE genetic_profile_id = ?");
pstmt.setInt(1, geneticProfileId);
rs = pstmt.executeQuery();
if (rs.next()) {
- String orderedSampleList = rs.getString("ORDERED_SAMPLE_LIST");
+ String orderedSampleList = rs.getString("ordered_sample_list");
// Split, based on DELIM token
String[] parts = orderedSampleList.split(DELIM);
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoGistic.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoGistic.java
index 778db35e..cacc90ab 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoGistic.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoGistic.java
@@ -61,6 +61,7 @@ public class DaoGistic {
*/
private static final Logger log = LoggerFactory.getLogger(DaoGistic.class);
+ private static final String GISTIC_SEQUENCE = "seq_gistic";
public static void addGistic(Gistic gistic) throws DaoException, validationException {
if (gistic == null) {
@@ -76,38 +77,34 @@ public static void addGistic(Gistic gistic) throws DaoException, validationExcep
try {
con = JdbcUtil.getDbConnection(DaoGistic.class);
// insert into SQL gistic table
+ long roiId = ClickHouseAutoIncrement.nextId(GISTIC_SEQUENCE);
pstmt = con.prepareStatement
- ("INSERT INTO gistic (`CANCER_STUDY_ID`," +
- "`CHROMOSOME`, " +
- "`CYTOBAND`, " +
- "`WIDE_PEAK_START`, " +
- "`WIDE_PEAK_END`, " +
- "`Q_VALUE`, " +
- "`AMP`) " +
- "VALUES (?,?,?,?,?,?,?)",
- Statement.RETURN_GENERATED_KEYS);
-
- pstmt.setInt(1, gistic.getCancerStudyId());
- pstmt.setInt(2, gistic.getChromosome()) ;
- pstmt.setString(3, gistic.getCytoband());
- pstmt.setInt(4, gistic.getPeakStart());
- pstmt.setInt(5, gistic.getPeakEnd());
- pstmt.setDouble(6, gistic.getqValue());
- pstmt.setBoolean(7, gistic.getAmp());
+ ("INSERT INTO gistic (`gistic_roi_id`, `cancer_study_id`," +
+ "`chromosome`, " +
+ "`cytoband`, " +
+ "`wide_peak_start`, " +
+ "`wide_peak_end`, " +
+ "`q_value`, " +
+ "`amp`) " +
+ "VALUES (?,?,?,?,?,?,?,?)");
+
+ pstmt.setLong(1, roiId);
+ pstmt.setInt(2, gistic.getCancerStudyId());
+ pstmt.setInt(3, gistic.getChromosome()) ;
+ pstmt.setString(4, gistic.getCytoband());
+ pstmt.setInt(5, gistic.getPeakStart());
+ pstmt.setInt(6, gistic.getPeakEnd());
+ pstmt.setDouble(7, gistic.getqValue());
+ pstmt.setBoolean(8, gistic.getAmp());
pstmt.executeUpdate();
- // insert into SQL gistic_to_gene table
- rs = pstmt.getGeneratedKeys();
- if (rs.next()) {
- int autoId = rs.getInt(1);
- gistic.setInternalId(autoId);
- }
+ gistic.setInternalId((int) roiId);
addGisticGenes(gistic, con);
} catch (SQLException e) {
throw new DaoException(e);
} finally {
- JdbcUtil.closeAll(DaoGistic.class, con, pstmt, rs);
+ JdbcUtil.closeAll(DaoGistic.class, con, pstmt, null);
}
}
@@ -129,8 +126,8 @@ private static void addGisticGenes(Gistic gistic, Connection con) throws DaoExce
// if this is the case, we are going to simply skip over this gene
if (g.getEntrezGeneId() != -1) {
pstmt = con.prepareStatement
- ("INSERT INTO gistic_to_gene (`GISTIC_ROI_ID`," +
- "`ENTREZ_GENE_ID`)" +
+ ("INSERT INTO gistic_to_gene (`gistic_roi_id`," +
+ "`entrez_gene_id`)" +
"VALUES (?,?)");
pstmt.setInt(1, gistic.getInternalId());
@@ -176,28 +173,28 @@ private static Gistic extractGistic(Connection con, ResultSet rs) throws DaoExce
try {
- int id = rs.getInt("GISTIC_ROI_ID");
+ int id = rs.getInt("gistic_roi_id");
- pstmt = con.prepareStatement("SELECT * FROM gistic_to_gene WHERE GISTIC_ROI_ID = ?");
+ pstmt = con.prepareStatement("SELECT * FROM gistic_to_gene WHERE gistic_roi_id = ?");
pstmt.setInt(1, id);
_rs = pstmt.executeQuery();
while ( _rs.next() ) {
- long entrez = _rs.getLong("ENTREZ_GENE_ID");
+ long entrez = _rs.getLong("entrez_gene_id");
CanonicalGene gene = DaoGeneOptimized.getInstance().getGene(entrez);
genes.add(gene);
}
// create gistic return object
- gistic = new Gistic(rs.getInt("CANCER_STUDY_ID"),
- rs.getInt("CHROMOSOME") ,
- rs.getString("CYTOBAND") ,
- rs.getInt("WIDE_PEAK_START"),
- rs.getInt("WIDE_PEAK_END"),
- rs.getFloat("Q_VALUE") ,
+ gistic = new Gistic(rs.getInt("cancer_study_id"),
+ rs.getInt("chromosome") ,
+ rs.getString("cytoband") ,
+ rs.getInt("wide_peak_start"),
+ rs.getInt("wide_peak_end"),
+ rs.getFloat("q_value") ,
genes,
- rs.getBoolean("AMP"));
+ rs.getBoolean("amp"));
} catch (SQLException e) {
throw new DaoException(e);
@@ -224,9 +221,9 @@ public static ArrayList getGisticByROI(int chromosome, int peakStart, in
try {
con = JdbcUtil.getDbConnection(DaoGistic.class);
- pstmt = con.prepareStatement("SELECT * FROM gistic WHERE CHROMOSOME = ? " +
- "AND WIDE_PEAK_START = ? " +
- "AND WIDE_PEAK_END = ?");
+ pstmt = con.prepareStatement("SELECT * FROM gistic WHERE chromosome = ? " +
+ "AND wide_peak_start = ? " +
+ "AND wide_peak_end = ?");
pstmt.setInt(1, chromosome);
pstmt.setInt(2, peakStart);
@@ -261,7 +258,7 @@ public static ArrayList getAllGisticByCancerStudyId(int cancerStudyId) t
try {
con = JdbcUtil.getDbConnection(DaoGistic.class);
- pstmt = con.prepareStatement("SELECT * FROM gistic WHERE CANCER_STUDY_ID = ? ");
+ pstmt = con.prepareStatement("SELECT * FROM gistic WHERE cancer_study_id = ? ");
pstmt.setInt(1, cancerStudyId);
rs = pstmt.executeQuery();
@@ -294,7 +291,7 @@ public static int countGistic(int cancerStudy) throws DaoException {
try {
con = JdbcUtil.getDbConnection(DaoGistic.class);
pstmt = con.prepareStatement
- ("SELECT count(*) FROM gistic WHERE CANCER_STUDY_ID = ?");
+ ("SELECT count(*) FROM gistic WHERE cancer_study_id = ?");
pstmt.setInt(1, cancerStudy);
rs = pstmt.executeQuery();
@@ -352,11 +349,11 @@ public static void deleteGistic(int gisticInternalId) throws DaoException {
try {
con = JdbcUtil.getDbConnection(DaoGistic.class);
- pstmt = con.prepareStatement("DELETE from gistic_to_gene WHERE GISTIC_ROI_ID=?");
+ pstmt = con.prepareStatement("DELETE from gistic_to_gene WHERE gistic_roi_id=?");
pstmt.setInt(1, gisticInternalId);
pstmt.executeUpdate();
- pstmt = con.prepareStatement("DELETE from gistic WHERE GISTIC_ROI_ID=?");
+ pstmt = con.prepareStatement("DELETE from gistic WHERE gistic_roi_id=?");
pstmt.setInt(1, gisticInternalId);
pstmt.executeUpdate();
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoInfo.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoInfo.java
index dba1df6d..f76368e3 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoInfo.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoInfo.java
@@ -56,7 +56,7 @@ public static synchronized void setVersion() {
("SELECT * FROM info");
rs = pstmt.executeQuery();
if (rs.next()) {
- version = rs.getString("DB_SCHEMA_VERSION");
+ version = rs.getString("db_schema_version");
}
} catch (SQLException e) {
e.printStackTrace();
@@ -98,7 +98,7 @@ public static void setGenesetVersion(String genesetVersion) throws DaoException
connection = JdbcUtil.getDbConnection(DaoInfo.class);
// Prepare SQL statement
- preparedStatement = connection.prepareStatement("UPDATE info set GENESET_VERSION = ?");
+ preparedStatement = connection.prepareStatement("ALTER TABLE info UPDATE geneset_version = ? WHERE 1");
preparedStatement.setString(1, genesetVersion);
// Execute statement
@@ -132,7 +132,7 @@ public static String getGenesetVersion() throws DaoException {
// Extract version from result
if (resultSet.next()) {
- genesetVersion = resultSet.getString("GENESET_VERSION");
+ genesetVersion = resultSet.getString("geneset_version");
}
return genesetVersion;
} catch (SQLException e) {
@@ -153,7 +153,7 @@ public static void clearVersion() throws DaoException {
try {
con = JdbcUtil.getDbConnection(DaoInfo.class);
- pstmt = con.prepareStatement("UPDATE info set GENESET_VERSION = NULL");
+ pstmt = con.prepareStatement("ALTER TABLE info UPDATE geneset_version = NULL WHERE 1");
pstmt.executeUpdate();
}
catch (SQLException e) {
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoMutSig.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoMutSig.java
index 66df4f9c..b26183c5 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoMutSig.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoMutSig.java
@@ -67,9 +67,9 @@ public static int addMutSig(MutSig mutSig) throws DaoException {
CanonicalGene gene = mutSig.getCanonicalGene();
- if (MySQLbulkLoader.isBulkLoad()) {
- // write to the temp file maintained by the MySQLbulkLoader
- MySQLbulkLoader.getMySQLbulkLoader("mut_sig").insertRecord(Integer.toString(mutSig.getCancerType()),
+ if (ClickHouseBulkLoader.isBulkLoad()) {
+ // write to the temp file maintained by the ClickHouseBulkLoader
+ ClickHouseBulkLoader.getClickHouseBulkLoader("mut_sig").insertRecord(Integer.toString(mutSig.getCancerType()),
Long.toString(gene.getEntrezGeneId()),
Integer.toString(mutSig.getRank()),
Integer.toString(mutSig.getNumBasesCovered()),
@@ -89,13 +89,13 @@ public static int addMutSig(MutSig mutSig) throws DaoException {
con = JdbcUtil.getDbConnection(DaoMutSig.class);
pstmt = con.prepareStatement
- ("INSERT INTO mut_sig (`CANCER_STUDY_ID`," +
- "`ENTREZ_GENE_ID`, " +
- "`RANK`, " +
+ ("INSERT INTO mut_sig (`cancer_study_id`," +
+ "`entrez_gene_id`, " +
+ "`rank`, " +
"`NumBasesCovered`, " +
"`NumMutations`, " +
- "`P_Value`, " +
- "`Q_Value`) " +
+ "`p_value`, " +
+ "`q_value`) " +
"VALUES (?,?,?,?,?,?,?)");
pstmt.setInt(1, mutSig.getCancerType());
@@ -136,7 +136,7 @@ public static MutSig getMutSig(String hugoGeneSymbol, int cancerStudy) throws Da
try {
con = JdbcUtil.getDbConnection(DaoMutSig.class);
pstmt = con.prepareStatement
- ("SELECT * FROM mut_sig WHERE ENTREZ_GENE_ID = ? AND CANCER_STUDY_ID = ?");
+ ("SELECT * FROM mut_sig WHERE entrez_gene_id = ? AND cancer_study_id = ?");
pstmt.setLong(1, entrezGeneID);
pstmt.setInt(2, cancerStudy);
rs = pstmt.executeQuery();
@@ -161,13 +161,13 @@ public static MutSig getMutSig(Long entrezGeneID, int cancerStudy) throws DaoExc
try {
con = JdbcUtil.getDbConnection(DaoMutSig.class);
pstmt = con.prepareStatement
- ("SELECT * FROM mut_sig WHERE ENTREZ_GENE_ID = ? AND CANCER_STUDY_ID = ?");
+ ("SELECT * FROM mut_sig WHERE entrez_gene_id = ? AND cancer_study_id = ?");
pstmt.setLong(1, entrezGeneID);
pstmt.setInt(2, cancerStudy);
rs = pstmt.executeQuery();
if (rs.next()) {
//first go into gene database, and make a Canonical Gene Object with
- CanonicalGene gene = daoGene.getGene(rs.getLong("ENTREZ_GENE_ID"));
+ CanonicalGene gene = daoGene.getGene(rs.getLong("entrez_gene_id"));
return DaoMutSig.assignMutSig(gene, rs);
} else {
return null;
@@ -189,12 +189,12 @@ public static ArrayList getAllMutSig(int cancerStudy) throws DaoExceptio
try {
con = JdbcUtil.getDbConnection(DaoMutSig.class);
pstmt = con.prepareStatement
- ("SELECT * FROM mut_sig WHERE CANCER_STUDY_ID = ?");
+ ("SELECT * FROM mut_sig WHERE cancer_study_id = ?");
pstmt.setInt(1, cancerStudy);
rs = pstmt.executeQuery();
while (rs.next()) {
- CanonicalGene gene = daoGene.getGene(rs.getLong("ENTREZ_GENE_ID"));
+ CanonicalGene gene = daoGene.getGene(rs.getLong("entrez_gene_id"));
MutSig mutSig = DaoMutSig.assignMutSig(gene, rs);
mutSigList.add(mutSig);
}
@@ -216,7 +216,7 @@ public static int countMutSig(int cancerStudy) throws DaoException {
try {
con = JdbcUtil.getDbConnection(DaoMutSig.class);
pstmt = con.prepareStatement
- ("SELECT count(*) FROM mut_sig WHERE CANCER_STUDY_ID = ?");
+ ("SELECT count(*) FROM mut_sig WHERE cancer_study_id = ?");
pstmt.setInt(1, cancerStudy);
rs = pstmt.executeQuery();
@@ -242,12 +242,12 @@ public static ArrayList getAllMutSig(int cancerStudy, double qValueThres
try {
con = JdbcUtil.getDbConnection(DaoMutSig.class);
pstmt = con.prepareStatement
- ("SELECT * FROM mut_sig WHERE CANCER_STUDY_ID = ? AND Q_Value < ?");
+ ("SELECT * FROM mut_sig WHERE cancer_study_id = ? AND q_value < ?");
pstmt.setInt(1, cancerStudy);
pstmt.setDouble(2,qValueThreshold);
rs = pstmt.executeQuery();
while (rs.next()) {
- CanonicalGene gene = daoGene.getGene(rs.getLong("ENTREZ_GENE_ID"));
+ CanonicalGene gene = daoGene.getGene(rs.getLong("entrez_gene_id"));
MutSig mutSig = DaoMutSig.assignMutSig(gene, rs);
mutSigList.add(mutSig);
}
@@ -277,13 +277,13 @@ public static void deleteAllRecords() throws DaoException {
private static MutSig assignMutSig(CanonicalGene gene, ResultSet rs)
throws SQLException, DaoException {
- return new MutSig(rs.getInt("CANCER_STUDY_ID"),
+ return new MutSig(rs.getInt("cancer_study_id"),
gene,
- rs.getInt("RANK"),
+ rs.getInt("rank"),
rs.getInt("NumBasesCovered"),
- rs.getInt("numMutations"),
- rs.getFloat("P_Value"),
- rs.getFloat("Q_Value"));
+ rs.getInt("NumMutations"),
+ rs.getFloat("p_value"),
+ rs.getFloat("q_value"));
}
/**
diff --git a/src/main/java/org/mskcc/cbio/portal/dao/DaoMutation.java b/src/main/java/org/mskcc/cbio/portal/dao/DaoMutation.java
index 011783eb..1ae48f26 100644
--- a/src/main/java/org/mskcc/cbio/portal/dao/DaoMutation.java
+++ b/src/main/java/org/mskcc/cbio/portal/dao/DaoMutation.java
@@ -32,9 +32,7 @@
package org.mskcc.cbio.portal.dao;
-import java.sql.*;
-import java.util.*;
-import java.util.regex.*;
+import org.apache.commons.collections4.MapIterator;
import org.apache.commons.collections4.keyvalue.MultiKey;
import org.apache.commons.collections4.map.MultiKeyMap;
import org.apache.commons.collections4.MapIterator;
@@ -48,18 +46,34 @@
import org.mskcc.cbio.portal.model.Sample;
import org.mskcc.cbio.portal.util.MutationKeywordUtils;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* Data access object for Mutation table
*/
public final class DaoMutation {
public static final String NAN = "NaN";
private static final String MUTATION_COUNT_ATTR_ID = "MUTATION_COUNT";
- private static final String DELETE_ALTERATION_DRIVER_ANNOTATION = "DELETE from alteration_driver_annotation WHERE GENETIC_PROFILE_ID=? and SAMPLE_ID=?";
- private static final String DELETE_MUTATION = "DELETE from mutation WHERE GENETIC_PROFILE_ID=? and SAMPLE_ID=?";
+ private static final String DELETE_ALTERATION_DRIVER_ANNOTATION = "DELETE from alteration_driver_annotation WHERE genetic_profile_id=? and sample_id=?";
+ private static final String DELETE_MUTATION = "DELETE from mutation WHERE genetic_profile_id=? and sample_id=?";
public static int addMutation(ExtendedMutation mutation, boolean newMutationEvent) throws DaoException {
- if (!MySQLbulkLoader.isBulkLoad()) {
- throw new DaoException("You have to turn on MySQLbulkLoader in order to insert mutations");
+ if (!ClickHouseBulkLoader.isBulkLoad()) {
+ throw new DaoException("You have to turn on ClickHouseBulkLoader in order to insert mutations");
} else {
int result = 1;
if (newMutationEvent) {
@@ -74,7 +88,7 @@ public static int addMutation(ExtendedMutation mutation, boolean newMutationEven
(mutation.getDriverTiersFilter() != null
&& !mutation.getDriverTiersFilter().isEmpty()
&& !mutation.getDriverTiersFilter().toLowerCase().equals("na"))) {
- MySQLbulkLoader.getMySQLbulkLoader("alteration_driver_annotation").insertRecord(
+ ClickHouseBulkLoader.getClickHouseBulkLoader("alteration_driver_annotation").insertRecord(
Long.toString(mutation.getMutationEventId()),
Integer.toString(mutation.getGeneticProfileId()),
Integer.toString(mutation.getSampleId()),
@@ -85,7 +99,7 @@ public static int addMutation(ExtendedMutation mutation, boolean newMutationEven
);
}
- MySQLbulkLoader.getMySQLbulkLoader("mutation").insertRecord(
+ ClickHouseBulkLoader.getClickHouseBulkLoader("mutation").insertRecord(
Long.toString(mutation.getMutationEventId()),
Integer.toString(mutation.getGeneticProfileId()),
Integer.toString(mutation.getSampleId()),
@@ -122,9 +136,9 @@ public static int addMutation(ExtendedMutation mutation, boolean newMutationEven
public static int addMutationEvent(ExtendedMutation.MutationEvent event) throws DaoException {
// use this code if bulk loading
- // write to the temp file maintained by the MySQLbulkLoader
+ // write to the temp file maintained by the ClickHouseBulkLoader
String keyword = MutationKeywordUtils.guessOncotatorMutationKeyword(event.getProteinChange(), event.getMutationType());
- MySQLbulkLoader.getMySQLbulkLoader("mutation_event").insertRecord(
+ ClickHouseBulkLoader.getClickHouseBulkLoader("mutation_event").insertRecord(
Long.toString(event.getMutationEventId()),
Long.toString(event.getGene().getEntrezGeneId()),
event.getChr(),
@@ -151,7 +165,8 @@ public static int addMutationEvent(ExtendedMutation.MutationEvent event) throws
public static void createMutationCountClinicalData(GeneticProfile geneticProfile) throws DaoException {
Connection con = null;
- PreparedStatement pstmt = null;
+ PreparedStatement deleteStmt = null;
+ PreparedStatement insertStmt = null;
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
@@ -163,47 +178,42 @@ public static void createMutationCountClinicalData(GeneticProfile geneticProfile
DaoClinicalAttributeMeta.addDatum(attr);
}
- /*
- * Add MUTATION_COUNT for each sample by checking number of
- * mutations for the given genetic profile.
- *
- * We do not add the MUTATION_COUNT clinical data for the sample if
- * it's not profiled. If it *is* profiled but there are 0
- * mutations, add a MUTATION_COUNT with 0 value record. Do not
- * include germline when counting mutations.
- *
- * Use REPLACE (conditional INSERT/UPDATE) which inserts
- * new counts if they don't exist and overwrites them if they do.
- * This is necessary for when the mutation data is split over
- * multiple files with same profile id. Note that since
- * clinical_sample has a key contraint on INTERNAL_ID and ATTR_ID,
- * there can only be one MUTATION_COUNT record for each sample, so
- * we assume each sample is in only one MUTATION_EXTENDED profile.
- */
- pstmt = con.prepareStatement(
- "REPLACE `clinical_sample` " +
- "SELECT sample_profile.`SAMPLE_ID`, 'MUTATION_COUNT', COUNT(DISTINCT mutation_event.`CHR`, mutation_event.`START_POSITION`, " +
- "mutation_event.`END_POSITION`, mutation_event.`REFERENCE_ALLELE`, mutation_event.`TUMOR_SEQ_ALLELE`) AS MUTATION_COUNT " +
+ String mutationCountSelect =
+ "SELECT sample_profile.`sample_id`, 'MUTATION_COUNT', count(DISTINCT mutation_event.`chr`, mutation_event.`start_position`, " +
+ "mutation_event.`end_position`, mutation_event.`reference_allele`, mutation_event.`tumor_seq_allele`) AS MUTATION_COUNT " +
"FROM `sample_profile` " +
- "LEFT JOIN mutation ON mutation.`SAMPLE_ID` = sample_profile.`SAMPLE_ID` " +
- "AND ( mutation.`MUTATION_STATUS` <> 'GERMLINE' OR mutation.`MUTATION_STATUS` IS NULL ) " +
- "LEFT JOIN mutation_event ON mutation.`MUTATION_EVENT_ID` = mutation_event.`MUTATION_EVENT_ID` " +
- "INNER JOIN genetic_profile ON genetic_profile.`GENETIC_PROFILE_ID` = sample_profile.`GENETIC_PROFILE_ID` " +
- "WHERE genetic_profile.`GENETIC_ALTERATION_TYPE` = 'MUTATION_EXTENDED' " +
- "AND genetic_profile.`GENETIC_PROFILE_ID`=? " +
- "GROUP BY sample_profile.`GENETIC_PROFILE_ID` , sample_profile.`SAMPLE_ID`;");
- pstmt.setInt(1, geneticProfile.getGeneticProfileId());
- pstmt.executeUpdate();
+ "LEFT JOIN mutation ON mutation.`sample_id` = sample_profile.`sample_id` " +
+ "AND ( UPPER(mutation.`mutation_status`) <> 'GERMLINE' OR mutation.`mutation_status` IS NULL ) " +
+ "LEFT JOIN mutation_event ON mutation.`mutation_event_id` = mutation_event.`mutation_event_id` " +
+ "INNER JOIN genetic_profile ON genetic_profile.`genetic_profile_id` = sample_profile.`genetic_profile_id` " +
+ "WHERE genetic_profile.`genetic_alteration_type` = 'MUTATION_EXTENDED' " +
+ "AND genetic_profile.`genetic_profile_id`=? " +
+ "GROUP BY sample_profile.`genetic_profile_id` , sample_profile.`sample_id`";
+
+ deleteStmt = con.prepareStatement(
+ "ALTER TABLE clinical_sample "
+ + "DELETE WHERE attr_id = 'MUTATION_COUNT' "
+ + "AND internal_id IN (SELECT sample_id FROM sample_profile WHERE genetic_profile_id = ?) "
+ );
+ deleteStmt.setInt(1, geneticProfile.getGeneticProfileId());
+ deleteStmt.executeUpdate();
+
+ insertStmt = con.prepareStatement(
+ "INSERT INTO clinical_sample " + mutationCountSelect
+ );
+ insertStmt.setInt(1, geneticProfile.getGeneticProfileId());
+ insertStmt.executeUpdate();
} catch (SQLException e) {
throw new DaoException(e);
} finally {
- JdbcUtil.closeAll(DaoMutation.class, con, pstmt, rs);
+ JdbcUtil.closeAll(DaoMutation.class, null, deleteStmt, null);
+ JdbcUtil.closeAll(DaoMutation.class, con, insertStmt, rs);
}
}
public static void calculateMutationCountByKeyword(int geneticProfileId) throws DaoException {
- if (!MySQLbulkLoader.isBulkLoad()) {
- throw new DaoException("You have to turn on MySQLbulkLoader in order to update mutation counts by keyword");
+ if (!ClickHouseBulkLoader.isBulkLoad()) {
+ throw new DaoException("You have to turn on ClickHouseBulkLoader in order to update mutation counts by keyword");
} else {
MultiKeyMap mutationEventKeywordCountMap = getMutationEventKeywordCountByGeneticProfileId(geneticProfileId); // mutation event keyword -> entrez id -> keyword count
Map geneCountMap = getGeneCountByGeneticProfileId(geneticProfileId); // entrez id -> gene count
@@ -215,7 +225,7 @@ public static void calculateMutationCountByKeyword(int geneticProfileId) throws
Long entrezGeneId = Long.valueOf(mk.getKey(1).toString());
String keywordCount = it.getValue().toString();
Integer geneCount = geneCountMap.get(entrezGeneId);
- MySQLbulkLoader.getMySQLbulkLoader("mutation_count_by_keyword").insertRecord(
+ ClickHouseBulkLoader.getClickHouseBulkLoader("mutation_count_by_keyword").insertRecord(
Integer.toString(geneticProfileId),
mutationEventKeyword,
Long.toString(entrezGeneId),
@@ -234,10 +244,10 @@ public static MultiKeyMap getMutationEventKeywordCountByGeneticProfileId(int gen
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
- "SELECT mutation_event.`KEYWORD`, mutation_event.`ENTREZ_GENE_ID`, IF(mutation_event.`KEYWORD` IS NULL, 0, COUNT(DISTINCT(mutation.SAMPLE_ID))) AS KEYWORD_COUNT " +
- "FROM mutation_event JOIN mutation on mutation.`MUTATION_EVENT_ID` = mutation_event.`MUTATION_EVENT_ID` " +
- "WHERE mutation.`GENETIC_PROFILE_ID` = ? " +
- "GROUP BY mutation_event.`KEYWORD`, mutation_event.`ENTREZ_GENE_ID`;"
+ "SELECT mutation_event.`keyword`, mutation_event.`entrez_gene_id`, if(mutation_event.`keyword` IS NULL, 0, count(DISTINCT(mutation.sample_id))) AS keyword_count " +
+ "FROM mutation_event JOIN mutation on mutation.`mutation_event_id` = mutation_event.`mutation_event_id` " +
+ "WHERE mutation.`genetic_profile_id` = ? " +
+ "GROUP BY mutation_event.`keyword`, mutation_event.`entrez_gene_id`"
);
pstmt.setInt(1, geneticProfileId);
rs = pstmt.executeQuery();
@@ -260,13 +270,13 @@ public static Map getGeneCountByGeneticProfileId(int geneticProfi
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
- "SELECT ENTREZ_GENE_ID AS `ENTREZ_GENE_ID`, COUNT(DISTINCT(SAMPLE_ID)) AS `GENE_COUNT`" +
- " FROM mutation WHERE GENETIC_PROFILE_ID = ? " +
- "GROUP BY ENTREZ_GENE_ID;");
+ "SELECT entrez_gene_id AS `entrez_gene_id`, count(DISTINCT(sample_id)) AS `gene_count`" +
+ " FROM mutation WHERE genetic_profile_id = ? " +
+ "GROUP BY entrez_gene_id");
pstmt.setInt(1, geneticProfileId);
rs = pstmt.executeQuery();
while (rs.next()) {
- geneCountByGeneticProfileId.put(rs.getLong("ENTREZ_GENE_ID"), rs.getInt("GENE_COUNT"));
+ geneCountByGeneticProfileId.put(rs.getLong("entrez_gene_id"), rs.getInt("gene_count"));
}
return geneCountByGeneticProfileId;
} catch (SQLException e) {
@@ -277,7 +287,7 @@ public static Map getGeneCountByGeneticProfileId(int geneticProfi
}
/**
- * Used by GeneticAlterationUtil (which is used by GetProfileData). This use comes out of an
+ * Used by GeneticAlterationUtil (which is used by GetProfileData via webservice.do). This use comes out of an
* effort to discontinue the use of the business module.
*/
public static ArrayList getMutations (int geneticProfileId, Collection targetSampleList,
@@ -290,9 +300,9 @@ public static ArrayList getMutations (int geneticProfileId, Co
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
"SELECT * FROM mutation " +
- "INNER JOIN mutation_event ON mutation.MUTATION_EVENT_ID=mutation_event.MUTATION_EVENT_ID " +
- "WHERE SAMPLE_ID IN ('" + org.apache.commons.lang3.StringUtils.join(targetSampleList, "','") +
- "') AND GENETIC_PROFILE_ID = ? AND mutation.ENTREZ_GENE_ID = ?");
+ "INNER JOIN mutation_event ON mutation.mutation_event_id=mutation_event.mutation_event_id " +
+ "WHERE sample_id IN ('" + org.apache.commons.lang3.StringUtils.join(targetSampleList, "','") +
+ "') AND genetic_profile_id = ? AND mutation.entrez_gene_id = ?");
pstmt.setInt(1, geneticProfileId);
pstmt.setLong(2, entrezGeneId);
rs = pstmt.executeQuery();
@@ -321,16 +331,16 @@ public static HashMap getSimplifiedMutations (int geneticProfileId, Collection getMutations (int geneticProfileId, in
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
"SELECT * FROM mutation " +
- "INNER JOIN mutation_event ON mutation.MUTATION_EVENT_ID=mutation_event.MUTATION_EVENT_ID " +
- "WHERE SAMPLE_ID = ? AND GENETIC_PROFILE_ID = ? AND mutation.ENTREZ_GENE_ID = ?");
+ "INNER JOIN mutation_event ON mutation.mutation_event_id=mutation_event.mutation_event_id " +
+ "WHERE sample_id = ? AND genetic_profile_id = ? AND mutation.entrez_gene_id = ?");
pstmt.setInt(1, sampleId);
pstmt.setInt(2, geneticProfileId);
pstmt.setLong(3, entrezGeneId);
@@ -391,11 +401,11 @@ public static Set getGenesInProfile(int geneticProfileId) throws
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
- "SELECT DISTINCT ENTREZ_GENE_ID FROM mutation WHERE GENETIC_PROFILE_ID = ?");
+ "SELECT DISTINCT entrez_gene_id FROM mutation WHERE genetic_profile_id = ?");
pstmt.setInt(1, geneticProfileId);
rs = pstmt.executeQuery();
while (rs.next()) {
- geneSet.add(daoGene.getGene(rs.getLong("ENTREZ_GENE_ID")));
+ geneSet.add(daoGene.getGene(rs.getLong("entrez_gene_id")));
}
} catch (SQLException e) {
throw new DaoException(e);
@@ -418,8 +428,8 @@ public static ArrayList getMutations (long entrezGeneId) throw
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
"SELECT * FROM mutation " +
- "INNER JOIN mutation_event ON mutation.MUTATION_EVENT_ID=mutation_event.MUTATION_EVENT_ID " +
- "WHERE mutation.ENTREZ_GENE_ID = ?");
+ "INNER JOIN mutation_event ON mutation.mutation_event_id=mutation_event.mutation_event_id " +
+ "WHERE mutation.entrez_gene_id = ?");
pstmt.setLong(1, entrezGeneId);
rs = pstmt.executeQuery();
while (rs.next()) {
@@ -447,8 +457,8 @@ public static ArrayList getMutations (long entrezGeneId, Strin
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
"SELECT * FROM mutation_event " +
- "INNER JOIN mutation ON mutation.MUTATION_EVENT_ID=mutation_event.MUTATION_EVENT_ID " +
- "WHERE mutation.ENTREZ_GENE_ID = ? AND PROTEIN_CHANGE = ?");
+ "INNER JOIN mutation ON mutation.mutation_event_id=mutation_event.mutation_event_id " +
+ "WHERE mutation.entrez_gene_id = ? AND protein_change = ?");
pstmt.setLong(1, entrezGeneId);
pstmt.setString(2, aminoAcidChange);
rs = pstmt.executeQuery();
@@ -477,8 +487,8 @@ public static ArrayList getMutations (int geneticProfileId, Li
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
"SELECT * FROM mutation " +
- "INNER JOIN mutation_event ON mutation.MUTATION_EVENT_ID=mutation_event.MUTATION_EVENT_ID " +
- "WHERE GENETIC_PROFILE_ID = ? AND SAMPLE_ID in ('"+ StringUtils.join(sampleIds, "','")+"')");
+ "INNER JOIN mutation_event ON mutation.mutation_event_id=mutation_event.mutation_event_id " +
+ "WHERE genetic_profile_id = ? AND sample_id in ('"+ StringUtils.join(sampleIds, "','")+"')");
pstmt.setInt(1, geneticProfileId);
rs = pstmt.executeQuery();
while (rs.next()) {
@@ -505,7 +515,7 @@ public static boolean hasAlleleFrequencyData (int geneticProfileId, int sampleId
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
"SELECT EXISTS (SELECT 1 FROM mutation " +
- "WHERE GENETIC_PROFILE_ID = ? AND SAMPLE_ID = ? AND TUMOR_ALT_COUNT>=0 AND TUMOR_REF_COUNT>=0)");
+ "WHERE genetic_profile_id = ? AND sample_id = ? AND tumor_alt_count>=0 AND tumor_ref_count>=0)");
pstmt.setInt(1, geneticProfileId);
pstmt.setInt(2, sampleId);
rs = pstmt.executeQuery();
@@ -532,8 +542,8 @@ public static ArrayList getMutations (long entrezGeneId, Strin
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
"SELECT * FROM mutation, mutation_event " +
- "WHERE mutation.MUTATION_EVENT_ID=mutation_event.MUTATION_EVENT_ID " +
- "AND mutation.ENTREZ_GENE_ID = ? AND PROTEIN_CHANGE = ? AND SAMPLE_ID <> ?");
+ "WHERE mutation.mutation_event_id=mutation_event.mutation_event_id " +
+ "AND mutation.entrez_gene_id = ? AND protein_change = ? AND sample_id <> ?");
pstmt.setLong(1, entrezGeneId);
pstmt.setString(2, aminoAcidChange);
pstmt.setInt(3, excludeSampleId);
@@ -566,8 +576,8 @@ public static ArrayList getMutations (int geneticProfileId,
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
"SELECT * FROM mutation " +
- "INNER JOIN mutation_event ON mutation.MUTATION_EVENT_ID=mutation_event.MUTATION_EVENT_ID " +
- "WHERE GENETIC_PROFILE_ID = ? AND mutation.ENTREZ_GENE_ID = ?");
+ "INNER JOIN mutation_event ON mutation.mutation_event_id=mutation_event.mutation_event_id " +
+ "WHERE genetic_profile_id = ? AND mutation.entrez_gene_id = ?");
pstmt.setInt(1, geneticProfileId);
pstmt.setLong(2, entrezGeneId);
rs = pstmt.executeQuery();
@@ -592,7 +602,7 @@ public static ArrayList getAllMutations () throws DaoException
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
"SELECT * FROM mutation " +
- "INNER JOIN mutation_event ON mutation.MUTATION_EVENT_ID=mutation_event.MUTATION_EVENT_ID");
+ "INNER JOIN mutation_event ON mutation.mutation_event_id=mutation_event.mutation_event_id");
rs = pstmt.executeQuery();
while (rs.next()) {
ExtendedMutation mutation = extractMutation(rs);
@@ -624,8 +634,8 @@ public static ArrayList getAllMutations (int geneticProfileId)
con = JdbcUtil.getDbConnection(DaoMutation.class);
pstmt = con.prepareStatement(
"SELECT * FROM mutation " +
- "INNER JOIN mutation_event ON mutation.MUTATION_EVENT_ID=mutation_event.MUTATION_EVENT_ID " +
- "WHERE mutation.GENETIC_PROFILE_ID = ?");
+ "INNER JOIN mutation_event ON mutation.mutation_event_id=mutation_event.mutation_event_id " +
+ "WHERE mutation.genetic_profile_id = ?");
pstmt.setInt(1, geneticProfileId);
rs = pstmt.executeQuery();
while (rs.next()) {
@@ -640,10 +650,6 @@ public static ArrayList getAllMutations (int geneticProfileId)
return mutationList;
}
- /**
- * @deprecated We believe that this method is no longer called by any part of the codebase, and it will soon be deleted.
- */
- @Deprecated
public static Set getAllMutationEvents() throws DaoException {
Connection con = null;
PreparedStatement pstmt = null;
@@ -665,51 +671,13 @@ public static Set getAllMutationEvents() throws
return events;
}
- /*
- * Returns an existing MutationEvent record from the database or null.
- */
- public static ExtendedMutation.MutationEvent getMutationEvent(ExtendedMutation.MutationEvent event) throws DaoException {
- Connection con = null;
- PreparedStatement pstmt = null;
- ResultSet rs = null;
- try {
- con = JdbcUtil.getDbConnection(DaoMutation.class);
- pstmt = con.prepareStatement("SELECT * from mutation_event WHERE" +
- " `ENTREZ_GENE_ID`=?" +
- " AND `CHR`=?" +
- " AND `START_POSITION`=?" +
- " AND `END_POSITION`=?" +
- " AND `TUMOR_SEQ_ALLELE`=?" +
- " AND `PROTEIN_CHANGE`=?" +
- " AND `MUTATION_TYPE`=?");
- pstmt.setLong(1, event.getGene().getEntrezGeneId());
- pstmt.setString(2, event.getChr());
- pstmt.setLong(3, event.getStartPosition());
- pstmt.setLong(4, event.getEndPosition());
- pstmt.setString(5, event.getTumorSeqAllele());
- pstmt.setString(6, event.getProteinChange());
- pstmt.setString(7, event.getMutationType());
- rs = pstmt.executeQuery();
- if (rs.next()) {
- return extractMutationEvent(rs);
- }
- else {
- return null;
- }
- } catch (SQLException e) {
- throw new DaoException(e);
- } finally {
- JdbcUtil.closeAll(DaoMutation.class, con, pstmt, rs);
- }
- }
-
public static long getLargestMutationEventId() throws DaoException {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
- pstmt = con.prepareStatement("SELECT MAX(`MUTATION_EVENT_ID`) FROM `mutation_event`");
+ pstmt = con.prepareStatement("SELECT max(`mutation_event_id`) FROM `mutation_event`");
rs = pstmt.executeQuery();
return rs.next() ? rs.getLong(1) : 0;
} catch (SQLException e) {
@@ -722,39 +690,39 @@ public static long getLargestMutationEventId() throws DaoException {
private static ExtendedMutation extractMutation(ResultSet rs) throws SQLException, DaoException {
try {
ExtendedMutation mutation = new ExtendedMutation(extractMutationEvent(rs));
- mutation.setGeneticProfileId(rs.getInt("GENETIC_PROFILE_ID"));
- mutation.setSampleId(rs.getInt("SAMPLE_ID"));
- mutation.setSequencingCenter(rs.getString("CENTER"));
- mutation.setSequencer(rs.getString("SEQUENCER"));
- mutation.setMutationStatus(rs.getString("MUTATION_STATUS"));
- mutation.setValidationStatus(rs.getString("VALIDATION_STATUS"));
- mutation.setTumorSeqAllele1(rs.getString("TUMOR_SEQ_ALLELE1"));
- mutation.setTumorSeqAllele2(rs.getString("TUMOR_SEQ_ALLELE2"));
- mutation.setMatchedNormSampleBarcode(rs.getString("MATCHED_NORM_SAMPLE_BARCODE"));
- mutation.setMatchNormSeqAllele1(rs.getString("MATCH_NORM_SEQ_ALLELE1"));
- mutation.setMatchNormSeqAllele2(rs.getString("MATCH_NORM_SEQ_ALLELE2"));
- mutation.setTumorValidationAllele1(rs.getString("TUMOR_VALIDATION_ALLELE1"));
- mutation.setTumorValidationAllele2(rs.getString("TUMOR_VALIDATION_ALLELE2"));
- mutation.setMatchNormValidationAllele1(rs.getString("MATCH_NORM_VALIDATION_ALLELE1"));
- mutation.setMatchNormValidationAllele2(rs.getString("MATCH_NORM_VALIDATION_ALLELE2"));
- mutation.setVerificationStatus(rs.getString("VERIFICATION_STATUS"));
- mutation.setSequencingPhase(rs.getString("SEQUENCING_PHASE"));
- mutation.setSequenceSource(rs.getString("SEQUENCE_SOURCE"));
- mutation.setValidationMethod(rs.getString("VALIDATION_METHOD"));
- mutation.setScore(rs.getString("SCORE"));
- mutation.setBamFile(rs.getString("BAM_FILE"));
+ mutation.setGeneticProfileId(rs.getInt("genetic_profile_id"));
+ mutation.setSampleId(rs.getInt("sample_id"));
+ mutation.setSequencingCenter(rs.getString("center"));
+ mutation.setSequencer(rs.getString("sequencer"));
+ mutation.setMutationStatus(rs.getString("mutation_status"));
+ mutation.setValidationStatus(rs.getString("validation_status"));
+ mutation.setTumorSeqAllele1(rs.getString("tumor_seq_allele1"));
+ mutation.setTumorSeqAllele2(rs.getString("tumor_seq_allele2"));
+ mutation.setMatchedNormSampleBarcode(rs.getString("matched_norm_sample_barcode"));
+ mutation.setMatchNormSeqAllele1(rs.getString("match_norm_seq_allele1"));
+ mutation.setMatchNormSeqAllele2(rs.getString("match_norm_seq_allele2"));
+ mutation.setTumorValidationAllele1(rs.getString("tumor_validation_allele1"));
+ mutation.setTumorValidationAllele2(rs.getString("tumor_validation_allele2"));
+ mutation.setMatchNormValidationAllele1(rs.getString("match_norm_validation_allele1"));
+ mutation.setMatchNormValidationAllele2(rs.getString("match_norm_validation_allele2"));
+ mutation.setVerificationStatus(rs.getString("verification_status"));
+ mutation.setSequencingPhase(rs.getString("sequencing_phase"));
+ mutation.setSequenceSource(rs.getString("sequence_source"));
+ mutation.setValidationMethod(rs.getString("validation_method"));
+ mutation.setScore(rs.getString("score"));
+ mutation.setBamFile(rs.getString("bam_file"));
// the following checks/set of null is to maintain
// behavior with MutationRepositoryLegacy (mybatis) behavior
// whose use is being retired in this PR
- mutation.setTumorAltCount(rs.getInt("TUMOR_ALT_COUNT"));
+ mutation.setTumorAltCount(rs.getInt("tumor_alt_count"));
if (rs.wasNull()) mutation.setTumorAltCount(null);
- mutation.setTumorRefCount(rs.getInt("TUMOR_REF_COUNT"));
+ mutation.setTumorRefCount(rs.getInt("tumor_ref_count"));
if (rs.wasNull()) mutation.setTumorRefCount(null);
- mutation.setNormalAltCount(rs.getInt("NORMAL_ALT_COUNT"));
+ mutation.setNormalAltCount(rs.getInt("normal_alt_count"));
if (rs.wasNull()) mutation.setNormalAltCount(null);
- mutation.setNormalRefCount(rs.getInt("NORMAL_REF_COUNT"));
+ mutation.setNormalRefCount(rs.getInt("normal_ref_count"));
if (rs.wasNull()) mutation.setNormalRefCount(null);
- mutation.setAnnotationJson(rs.getString("ANNOTATION_JSON"));
+ mutation.setAnnotationJson(rs.getString("annotation_json"));
return mutation;
}
catch(NullPointerException e) {
@@ -764,30 +732,30 @@ private static ExtendedMutation extractMutation(ResultSet rs) throws SQLExceptio
private static ExtendedMutation.MutationEvent extractMutationEvent(ResultSet rs) throws SQLException, DaoException {
ExtendedMutation.MutationEvent event = new ExtendedMutation.MutationEvent();
- event.setMutationEventId(rs.getLong("MUTATION_EVENT_ID"));
- long entrezId = rs.getLong("mutation_event.ENTREZ_GENE_ID");
+ event.setMutationEventId(rs.getLong("mutation_event_id"));
+ long entrezId = rs.getLong("entrez_gene_id");
DaoGeneOptimized aDaoGene = DaoGeneOptimized.getInstance();
CanonicalGene gene = aDaoGene.getGene(entrezId);
event.setGene(gene);
- event.setChr(rs.getString("CHR"));
- event.setStartPosition(rs.getLong("START_POSITION"));
- event.setEndPosition(rs.getLong("END_POSITION"));
- event.setProteinChange(rs.getString("PROTEIN_CHANGE"));
- event.setMutationType(rs.getString("MUTATION_TYPE"));
- event.setNcbiBuild(rs.getString("NCBI_BUILD"));
- event.setStrand(rs.getString("STRAND"));
- event.setVariantType(rs.getString("VARIANT_TYPE"));
- event.setDbSnpRs(rs.getString("DB_SNP_RS"));
- event.setDbSnpValStatus(rs.getString("DB_SNP_VAL_STATUS"));
- event.setReferenceAllele(rs.getString("REFERENCE_ALLELE"));
- event.setRefseqMrnaId(rs.getString("REFSEQ_MRNA_ID"));
- event.setCodonChange(rs.getString("CODON_CHANGE"));
- event.setUniprotAccession(rs.getString("UNIPROT_ACCESSION"));
- event.setProteinPosStart(rs.getInt("PROTEIN_POS_START"));
- event.setProteinPosEnd(rs.getInt("PROTEIN_POS_END"));
- event.setCanonicalTranscript(rs.getBoolean("CANONICAL_TRANSCRIPT"));
- event.setTumorSeqAllele(rs.getString("TUMOR_SEQ_ALLELE"));
- event.setKeyword(rs.getString("KEYWORD"));
+ event.setChr(rs.getString("chr"));
+ event.setStartPosition(rs.getLong("start_position"));
+ event.setEndPosition(rs.getLong("end_position"));
+ event.setProteinChange(rs.getString("protein_change"));
+ event.setMutationType(rs.getString("mutation_type"));
+ event.setNcbiBuild(rs.getString("ncbi_build"));
+ event.setStrand(rs.getString("strand"));
+ event.setVariantType(rs.getString("variant_type"));
+ event.setDbSnpRs(rs.getString("db_snp_rs"));
+ event.setDbSnpValStatus(rs.getString("db_snp_val_status"));
+ event.setReferenceAllele(rs.getString("reference_allele"));
+ event.setRefseqMrnaId(rs.getString("refseq_mrna_id"));
+ event.setCodonChange(rs.getString("codon_change"));
+ event.setUniprotAccession(rs.getString("uniprot_accession"));
+ event.setProteinPosStart(rs.getInt("protein_pos_start"));
+ event.setProteinPosEnd(rs.getInt("protein_pos_end"));
+ event.setCanonicalTranscript(rs.getBoolean("canonical_transcript"));
+ event.setTumorSeqAllele(rs.getString("tumor_seq_allele"));
+ event.setKeyword(rs.getString("keyword"));
return event;
}
@@ -801,7 +769,7 @@ public static int getCount() throws DaoException {
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
- pstmt = con.prepareStatement("SELECT COUNT(*) FROM mutation");
+ pstmt = con.prepareStatement("SELECT count(*) FROM mutation");
rs = pstmt.executeQuery();
if (rs.next()) {
return rs.getInt(1);
@@ -836,13 +804,13 @@ public static Map> getSMGs(int profileId, Collection0?(" HAVING COUNT(*)>="+thresholdRecurrence):"") +
" ORDER BY count_per_nt DESC" +
(thresholdNumGenes>0?(" LIMIT 0,"+thresholdNumGenes):"");
@@ -878,8 +846,8 @@ public static int countMutationEvents(int profileId) throws DaoException {
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
- String sql = "SELECT count(DISTINCT `SAMPLE_ID`, `MUTATION_EVENT_ID`) FROM mutation" +
- " WHERE `GENETIC_PROFILE_ID`=" + profileId;
+ String sql = "SELECT count(DISTINCT `sample_id`, `mutation_event_id`) FROM mutation" +
+ " WHERE `genetic_profile_id`=" + profileId;
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next()) {
@@ -923,15 +891,15 @@ public static Map> getSamplesWithMutations(String concatEvent
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
- String sql = "SELECT `SAMPLE_ID`, `MUTATION_EVENT_ID` FROM mutation" +
- " WHERE `MUTATION_EVENT_ID` IN (" +
+ String sql = "SELECT `sample_id`, `mutation_event_id` FROM mutation" +
+ " WHERE `mutation_event_id` IN (" +
concatEventIds + ")";
pstmt = con.prepareStatement(sql);
Map> map = new HashMap> ();
rs = pstmt.executeQuery();
while (rs.next()) {
- int sampleId = rs.getInt("SAMPLE_ID");
- long eventId = rs.getLong("MUTATION_EVENT_ID");
+ int sampleId = rs.getInt("sample_id");
+ long eventId = rs.getLong("mutation_event_id");
Set events = map.get(sampleId);
if (events == null) {
events = new HashSet();
@@ -975,17 +943,17 @@ public static Map> getSimilarSamplesWithMutationsByKeywords(
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
- String sql = "SELECT `SAMPLE_ID`, `GENETIC_PROFILE_ID`, me1.`MUTATION_EVENT_ID`" +
+ String sql = "SELECT `sample_id`, `genetic_profile_id`, me1.`mutation_event_id`" +
" FROM mutation cme, mutation_event me1, mutation_event me2" +
- " WHERE me1.`MUTATION_EVENT_ID` IN ("+ concatEventIds + ")" +
- " AND me1.`KEYWORD`=me2.`KEYWORD`" +
- " AND cme.`MUTATION_EVENT_ID`=me2.`MUTATION_EVENT_ID`";
+ " WHERE me1.`mutation_event_id` IN ("+ concatEventIds + ")" +
+ " AND me1.`keyword`=me2.`keyword`" +
+ " AND cme.`mutation_event_id`=me2.`mutation_event_id`";
pstmt = con.prepareStatement(sql);
Map> map = new HashMap> ();
rs = pstmt.executeQuery();
while (rs.next()) {
- Sample sample = DaoSample.getSampleById(rs.getInt("SAMPLE_ID"));
- long eventId = rs.getLong("MUTATION_EVENT_ID");
+ Sample sample = DaoSample.getSampleById(rs.getInt("sample_id"));
+ long eventId = rs.getLong("mutation_event_id");
Set events = map.get(sample);
if (events == null) {
events = new HashSet();
@@ -1021,15 +989,15 @@ public static Map> getSimilarSamplesWithMutatedGenes(
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
- String sql = "SELECT `SAMPLE_ID`, `GENETIC_PROFILE_ID`, `ENTREZ_GENE_ID`" +
+ String sql = "SELECT `sample_id`, `genetic_profile_id`, `entrez_gene_id`" +
" FROM mutation" +
- " WHERE `ENTREZ_GENE_ID` IN ("+ StringUtils.join(entrezGeneIds,",") + ")";
+ " WHERE `entrez_gene_id` IN ("+ StringUtils.join(entrezGeneIds,",") + ")";
pstmt = con.prepareStatement(sql);
Map> map = new HashMap> ();
rs = pstmt.executeQuery();
while (rs.next()) {
- Sample sample = DaoSample.getSampleById(rs.getInt("SAMPLE_ID"));
- long entrez = rs.getLong("ENTREZ_GENE_ID");
+ Sample sample = DaoSample.getSampleById(rs.getInt("sample_id"));
+ long entrez = rs.getLong("entrez_gene_id");
Set genes = map.get(sample);
if (genes == null) {
genes = new HashSet();
@@ -1074,11 +1042,11 @@ public static Map countSamplesWithMutationEvents(String concatEve
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
- String sql = "SELECT `MUTATION_EVENT_ID`, count(DISTINCT `SAMPLE_ID`) FROM mutation" +
- " WHERE `GENETIC_PROFILE_ID`=" + profileId +
- " AND `MUTATION_EVENT_ID` IN (" +
+ String sql = "SELECT `mutation_event_id`, count(DISTINCT `sample_id`) FROM mutation" +
+ " WHERE `genetic_profile_id`=" + profileId +
+ " AND `mutation_event_id` IN (" +
concatEventIds +
- ") GROUP BY `MUTATION_EVENT_ID`";
+ ") GROUP BY `mutation_event_id`";
pstmt = con.prepareStatement(sql);
Map map = new HashMap();
rs = pstmt.executeQuery();
@@ -1119,12 +1087,12 @@ public static Map countSamplesWithMutatedGenes(String concatEntre
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
- String sql = "SELECT ENTREZ_GENE_ID, count(DISTINCT SAMPLE_ID)" +
+ String sql = "SELECT entrez_gene_id, count(DISTINCT sample_id)" +
" FROM mutation" +
- " WHERE GENETIC_PROFILE_ID=" + profileId +
- " AND ENTREZ_GENE_ID IN (" +
+ " WHERE genetic_profile_id=" + profileId +
+ " AND entrez_gene_id IN (" +
concatEntrezGeneIds +
- ") GROUP BY `ENTREZ_GENE_ID`";
+ ") GROUP BY `entrez_gene_id`";
pstmt = con.prepareStatement(sql);
Map map = new HashMap();
rs = pstmt.executeQuery();
@@ -1152,13 +1120,13 @@ public static Map countSamplesWithKeywords(Collection k
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoMutation.class);
- String sql = "SELECT KEYWORD, count(DISTINCT SAMPLE_ID)" +
+ String sql = "SELECT keyword, count(DISTINCT sample_id)" +
" FROM mutation, mutation_event" +
- " WHERE GENETIC_PROFILE_ID=" + profileId +
- " AND mutation.MUTATION_EVENT_ID=mutation_event.MUTATION_EVENT_ID" +
- " AND KEYWORD IN ('" +
+ " WHERE genetic_profile_id=" + profileId +
+ " AND mutation.mutation_event_id=mutation_event.mutation_event_id" +
+ " AND keyword IN ('" +
StringUtils.join(keywords,"','") +
- "') GROUP BY `KEYWORD`";
+ "') GROUP BY `keyword`";
pstmt = con.prepareStatement(sql);
Map map = new HashMap();
rs = pstmt.executeQuery();
@@ -1189,11 +1157,11 @@ public static Collection