Skip to content

Commit

Permalink
Merge pull request #5891 from pughlab/multiple-genome-build-5652
Browse files Browse the repository at this point in the history
support multiple reference genomes 2nd try
  • Loading branch information
inodb committed Jul 17, 2019
2 parents de44419 + a46a54a commit 484a7b9
Show file tree
Hide file tree
Showing 113 changed files with 2,886 additions and 514 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
<result property="entrezGeneId" column="ENTREZ_GENE_ID"/>
<result property="hugoGeneSymbol" column="HUGO_GENE_SYMBOL"/>
<result property="type" column="TYPE"/>
<result property="cytoband" column="CYTOBAND"/>
</resultMap>

<resultMap id="geneticProfileResultMap" type="org.cbioportal.model.MolecularProfile">
Expand Down Expand Up @@ -128,8 +127,7 @@
gene_panel.DESCRIPTION as description,
gene.ENTREZ_GENE_ID as entrezGeneId,
gene.HUGO_GENE_SYMBOL as hugoGeneSymbol,
gene.TYPE as type,
gene.CYTOBAND as cytoband
gene.TYPE as type
from gene_panel
left join gene_panel_list on gene_panel.INTERNAL_ID = gene_panel_list.INTERNAL_ID
left join gene on gene_panel_list.GENE_ID = gene.ENTREZ_GENE_ID
Expand All @@ -149,8 +147,7 @@
select
gene.ENTREZ_GENE_ID,
gene.HUGO_GENE_SYMBOL,
gene.TYPE,
gene.CYTOBAND
gene.TYPE
from gene
<where>
gene.HUGO_GENE_SYMBOL = #{symbol}
Expand All @@ -162,8 +159,7 @@
select
gene.ENTREZ_GENE_ID,
gene.HUGO_GENE_SYMBOL,
gene.TYPE,
gene.CYTOBAND
gene.TYPE
from gene
<where>
gene.ENTREZ_GENE_ID = #{geneId}
Expand All @@ -174,8 +170,7 @@
select
gene.ENTREZ_GENE_ID,
gene.HUGO_GENE_SYMBOL,
gene.TYPE,
gene.CYTOBAND
gene.TYPE
from gene_alias
inner join gene on gene_alias.ENTREZ_GENE_ID = gene.ENTREZ_GENE_ID
<where>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
DESCRIPTION as description,
PMID as pmid,
CITATION as citation,
GROUPS as groups,
`GROUPS` as `groups`,
CANCER_STUDY_ID as internal_id
from cancer_study
where CANCER_STUDY_IDENTIFIER in <foreach item="item" collection="study_ids" open="(" separator="," close=")">#{item}</foreach>
Expand Down
47 changes: 30 additions & 17 deletions core/src/main/java/org/mskcc/cbio/portal/dao/DaoCancerStudy.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static synchronized void reCache() {
CancerStudy cancerStudy = extractCancerStudy(rs);
cacheCancerStudy(cancerStudy, new java.util.Date());
}
} catch (SQLException e) {
} catch (SQLException | DaoException e) {
e.printStackTrace();
} finally {
JdbcUtil.closeAll(DaoCancerStudy.class, con, pstmt, rs);
Expand Down Expand Up @@ -298,7 +298,7 @@ public static void addCancerStudy(CancerStudy cancerStudy, boolean overwrite) th
pstmt = con.prepareStatement("INSERT INTO cancer_study " +
"( `CANCER_STUDY_IDENTIFIER`, `NAME`, "
+ "`DESCRIPTION`, `PUBLIC`, `TYPE_OF_CANCER_ID`, "
+ "`PMID`, `CITATION`, `GROUPS`, `SHORT_NAME`, `STATUS`, `IMPORT_DATE` ) VALUES (?,?,?,?,?,?,?,?,?,?,?)",
+ "`PMID`, `CITATION`, `GROUPS`, `SHORT_NAME`, `STATUS`, `IMPORT_DATE`,`REFERENCE_GENOME_ID` ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",
Statement.RETURN_GENERATED_KEYS);
pstmt.setString(1, stableId);
pstmt.setString(2, cancerStudy.getName());
Expand All @@ -319,6 +319,13 @@ public static void addCancerStudy(CancerStudy cancerStudy, boolean overwrite) th
//TODO - use this field in parts of the system that build up the list of studies to display in home page:
pstmt.setInt(10, Status.UNAVAILABLE.ordinal());
pstmt.setDate(11, java.sql.Date.valueOf(LocalDate.now()));
try {
ReferenceGenome referenceGenome = DaoReferenceGenome.getReferenceGenomeByGenomeName(cancerStudy.getReferenceGenome());
pstmt.setInt(12, referenceGenome.getReferenceGenomeId());
}
catch (NullPointerException e) {
throw new DaoException("Unsupported reference genome");
}
pstmt.executeUpdate();
rs = pstmt.getGeneratedKeys();
if (rs.next()) {
Expand Down Expand Up @@ -356,7 +363,7 @@ public static void addCancerStudyTags(CancerStudyTags cancerStudyTags) throws Da
/**
* Return the cancerStudy identified by the internal cancer study ID, if it exists.
*
* @param cancerStudyID Internal (int) Cancer Study ID.
* @param internalId Internal (int) Cancer Study ID.
* @return Cancer Study Object, or null if there's no such study.
*/
public static CancerStudy getCancerStudyByInternalId(int internalId) throws DaoException {
Expand All @@ -366,7 +373,7 @@ public static CancerStudy getCancerStudyByInternalId(int internalId) throws DaoE
/**
* Returns the cancerStudy identified by the stable identifier, if it exists.
*
* @param cancerStudyStableId Cancer Study Stable ID.
* @param stableId Cancer Study Stable ID.
* @return the CancerStudy, or null if there's no such study.
*/
public static CancerStudy getCancerStudyByStableId(String stableId) throws DaoException {
Expand Down Expand Up @@ -612,19 +619,25 @@ public static void purgeUnreferencedRecordsAfterDeletionOfStudy() throws DaoExce
/**
* Extracts Cancer Study JDBC Results.
*/
private static CancerStudy extractCancerStudy(ResultSet rs) throws SQLException {
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.setShortName(rs.getString("SHORT_NAME"));
cancerStudy.setInternalId(rs.getInt("CANCER_STUDY_ID"));
cancerStudy.setImportDate(rs.getDate("IMPORT_DATE"));
return cancerStudy;
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.setShortName(rs.getString("SHORT_NAME"));
cancerStudy.setInternalId(rs.getInt("CANCER_STUDY_ID"));
cancerStudy.setImportDate(rs.getDate("IMPORT_DATE"));
cancerStudy.setReferenceGenome(DaoReferenceGenome.getReferenceGenomeByInternalId(
rs.getInt("REFERENCE_GENOME_ID")).getGenomeName());
return cancerStudy;
} catch (SQLException e) {
throw new DaoException(e);
}
}

private static boolean studyNeedsRecaching(String stableId, Integer ... internalId) {
Expand Down
12 changes: 4 additions & 8 deletions core/src/main/java/org/mskcc/cbio/portal/dao/DaoGene.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ public static int updateGene(CanonicalGene gene) throws DaoException {
int rows = 0;
con = JdbcUtil.getDbConnection(DaoGene.class);
pstmt = con.prepareStatement
("UPDATE gene SET `HUGO_GENE_SYMBOL`=?, `TYPE`=?,`CYTOBAND`=? 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.setString(3, gene.getCytoband());
pstmt.setLong(4, gene.getEntrezGeneId());
pstmt.setLong(3, gene.getEntrezGeneId());
rows += pstmt.executeUpdate();
if (rows != 1) {
ProgressMonitor.logWarning("No change for " + gene.getEntrezGeneId() + " " + gene.getHugoGeneSymbolAllCaps() + "? Code " + rows);
Expand Down Expand Up @@ -143,13 +142,12 @@ 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`,`CYTOBAND`) "
+ "VALUES (?,?,?,?,?)");
("INSERT INTO gene (`GENETIC_ENTITY_ID`, `ENTREZ_GENE_ID`,`HUGO_GENE_SYMBOL`,`TYPE`) "
+ "VALUES (?,?,?,?)");
pstmt.setInt(1, geneticEntityId);
pstmt.setLong(2, gene.getEntrezGeneId());
pstmt.setString(3, gene.getHugoGeneSymbolAllCaps());
pstmt.setString(4, gene.getType());
pstmt.setString(5, gene.getCytoband());
rows += pstmt.executeUpdate();

} else {
Expand Down Expand Up @@ -326,7 +324,6 @@ public static ArrayList<CanonicalGene> getAllGenes() throws DaoException {
Set<String> aliases = mapAliases.get(entrezGeneId);
CanonicalGene gene = new CanonicalGene(geneticEntityId, entrezGeneId,
rs.getString("HUGO_GENE_SYMBOL"), aliases);
gene.setCytoband(rs.getString("CYTOBAND"));
gene.setType(rs.getString("TYPE"));
geneList.add(gene);
}
Expand Down Expand Up @@ -374,7 +371,6 @@ private static CanonicalGene extractGene(ResultSet rs) throws SQLException, DaoE
Set<String> aliases = getAliases(entrezGeneId);
CanonicalGene gene = new CanonicalGene(geneticEntityId, entrezGeneId,
rs.getString("HUGO_GENE_SYMBOL"), aliases);
gene.setCytoband(rs.getString("CYTOBAND"));
gene.setType(rs.getString("TYPE"));

return gene;
Expand Down
30 changes: 7 additions & 23 deletions core/src/main/java/org/mskcc/cbio/portal/dao/DaoGeneOptimized.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public CanonicalGene getGene(long entrezId) {
/**
* Gets Gene By Entrez Gene ID.
*
* @param entrezId Entrez Gene ID.
* @param geneticEntityId Gene Entity ID.
* @return Canonical Gene Object.
*/
public CanonicalGene getGeneByEntityId(int geneticEntityId) {
Expand Down Expand Up @@ -335,23 +335,8 @@ public List<CanonicalGene> guessGene(String geneId, String chr) {

List<CanonicalGene> genes = geneAliasMap.get(geneId.toUpperCase());
if (genes!=null) {
if (chr==null) {
return Collections.unmodifiableList(genes);
}

String nchr = normalizeChr(chr);

List<CanonicalGene> ret = new ArrayList<CanonicalGene>();
for (CanonicalGene cg : genes) {
String gchr = getChrFromCytoband(cg.getCytoband());
if (gchr==null // TODO: should we exlude this?
|| gchr.equals(nchr)) {
ret.add(cg);
}
}
return ret;
return Collections.unmodifiableList(genes);
}

return Collections.emptyList();
}

Expand Down Expand Up @@ -407,7 +392,7 @@ private static String getChrFromCytoband(String cytoband) {
* @return a gene that can be non-ambiguously determined, or null if cannot.
*/
public CanonicalGene getNonAmbiguousGene(String geneId) {
return getNonAmbiguousGene(geneId, null);
return getNonAmbiguousGene(geneId, true);
}

/**
Expand All @@ -417,19 +402,18 @@ public CanonicalGene getNonAmbiguousGene(String geneId) {
* @return a gene that can be non-ambiguously determined, or null if cannot.
*/
public CanonicalGene getNonAmbiguousGene(String geneId, String chr) {
return getNonAmbiguousGene(geneId, chr, true);
return getNonAmbiguousGene(geneId, true);
}

/**
* Look for gene that can be non-ambiguously determined
* @param geneId an Entrez Gene ID or HUGO symbol or gene alias
* @param chr chromosome
* @param issueWarning if true and gene is not ambiguous,
* @param issueWarning if true and gene is not ambiguous,
* print all the Entrez Ids corresponding to the geneId provided
* @return a gene that can be non-ambiguously determined, or null if cannot.
*/
public CanonicalGene getNonAmbiguousGene(String geneId, String chr, boolean issueWarning) {
List<CanonicalGene> genes = guessGene(geneId, chr);
public CanonicalGene getNonAmbiguousGene(String geneId, boolean issueWarning) {
List<CanonicalGene> genes = guessGene(geneId);
if (genes.isEmpty()) {
return null;
}
Expand Down

0 comments on commit 484a7b9

Please sign in to comment.