Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduction of Cursor code to optimization memory usage of CoExpression Service #6834

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public interface MolecularDataRepository {
List<GeneMolecularAlteration> getGeneMolecularAlterations(String molecularProfileId, List<Integer> entrezGeneIds,
String projection);

@Cacheable(cacheNames = "GeneralRepositoryCache", condition = "@cacheEnabledConfig.getEnabled()")
Iterable<GeneMolecularAlteration> getGeneMolecularAlterationsIterable(String molecularProfileId, List<Integer> entrezGeneIds,
String projection);

@Cacheable(cacheNames = "GeneralRepositoryCache", condition = "@cacheEnabledConfig.getEnabled()")
List<GeneMolecularAlteration> getGeneMolecularAlterationsInMultipleMolecularProfiles(List<String> molecularProfileIds,
List<Integer> entrezGeneIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.cbioportal.model.TreatmentMolecularAlteration;

import java.util.List;
import org.apache.ibatis.cursor.Cursor;

public interface MolecularDataMapper {

Expand All @@ -14,6 +15,9 @@ public interface MolecularDataMapper {
List<GeneMolecularAlteration> getGeneMolecularAlterations(String molecularProfileId, List<Integer> entrezGeneIds,
String projection);

Cursor<GeneMolecularAlteration> getGeneMolecularAlterationsIter(String molecularProfileId, List<Integer> entrezGeneIds,
String projection);

List<GeneMolecularAlteration> getGeneMolecularAlterationsInMultipleMolecularProfiles(List<String> molecularProfileIds,
List<Integer> entrezGeneIds, String projection);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public List<GeneMolecularAlteration> getGeneMolecularAlterations(String molecula
return molecularDataMapper.getGeneMolecularAlterations(molecularProfileId, entrezGeneIds, projection);
}

@Override
// In order to return a cursor/iterator to the service layer, we need a transaction setup in the service
// layer. Currently, the bottom stackframe is CoExpressionService:getCoExpressions. It is there where
// you will find the transaction created.
public Iterable<GeneMolecularAlteration> getGeneMolecularAlterationsIterable(String molecularProfileId,
List<Integer> entrezGeneIds, String projection) {

return molecularDataMapper.getGeneMolecularAlterationsIter(molecularProfileId, entrezGeneIds, projection);
}

@Override
public List<GeneMolecularAlteration> getGeneMolecularAlterationsInMultipleMolecularProfiles(List<String> molecularProfileIds,
List<Integer> entrezGeneIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,36 @@
</where>
</select>

<!-- This routine is a copy of getGeneMolecularAlterations above. This copy is necessary because
it is backing a corresponding method in MolecularDataMapper.java which returns a Cursor as
opposed to a List. This method should be kept in sync with getGeneMolecularAlterations above.
(Attempts where made to share getGeneMolecularAlterations between methods in MolecularDataMapper.java
all of which have failed).
-->
<select id="getGeneMolecularAlterationsIter" resultType="org.cbioportal.model.GeneMolecularAlteration">
SELECT
gene.ENTREZ_GENE_ID AS entrezGeneId,
genetic_alteration.VALUES AS "values"
<if test="projection == 'DETAILED'">
,
<include refid="org.cbioportal.persistence.mybatis.GeneMapper.select">
<property name="prefix" value="gene."/>
</include>
</if>
FROM genetic_alteration
INNER JOIN genetic_profile ON genetic_alteration.GENETIC_PROFILE_ID = genetic_profile.GENETIC_PROFILE_ID
INNER JOIN gene ON genetic_alteration.GENETIC_ENTITY_ID = gene.GENETIC_ENTITY_ID
<where>
genetic_profile.STABLE_ID = #{molecularProfileId}
<if test="entrezGeneIds != null and !entrezGeneIds.isEmpty()">
AND gene.ENTREZ_GENE_ID IN
<foreach item="item" collection="entrezGeneIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
</select>

<select id="getGeneMolecularAlterationsInMultipleMolecularProfiles" resultType="org.cbioportal.model.GeneMolecularAlteration">
SELECT
gene.ENTREZ_GENE_ID AS entrezGeneId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

Expand All @@ -18,10 +19,10 @@
@ContextConfiguration("/testContextDatabase.xml")
@Configurable
public class MolecularDataMyBatisRepositoryTest {

@Autowired
private MolecularDataMyBatisRepository molecularDataMyBatisRepository;

@Test
public void getCommaSeparatedSampleIdsOfMolecularProfile() throws Exception {

Expand All @@ -48,20 +49,43 @@ public void getGeneMolecularAlterations() throws Exception {
List<Integer> entrezGeneIds = new ArrayList<>();
entrezGeneIds.add(207);
entrezGeneIds.add(208);

List<GeneMolecularAlteration> result = molecularDataMyBatisRepository.getGeneMolecularAlterations("study_tcga_pub_gistic",
entrezGeneIds, "SUMMARY");


getGeneMolecularAlterationsCommonTest(result);
}

@Test
@Transactional(readOnly=true)
public void getGeneMolecularAlterationsIterable() throws Exception {

List<Integer> entrezGeneIds = new ArrayList<>();
entrezGeneIds.add(207);
entrezGeneIds.add(208);

List<GeneMolecularAlteration> result = new ArrayList<>();
Iterable<GeneMolecularAlteration> gmaItr = molecularDataMyBatisRepository.getGeneMolecularAlterationsIterable("study_tcga_pub_gistic",
entrezGeneIds, "SUMMARY");
for (GeneMolecularAlteration gma : gmaItr) {
result.add(gma);
}

getGeneMolecularAlterationsCommonTest(result);
}

private void getGeneMolecularAlterationsCommonTest(List<GeneMolecularAlteration> result) {

Assert.assertEquals(2, result.size());
GeneMolecularAlteration molecularAlteration1 = result.get(0);
Assert.assertEquals((Integer) 207, molecularAlteration1.getEntrezGeneId());
String[] expected = {"-0.4674","-0.6270","-1.2266","-1.2479","-1.2262","0.6962","-0.3338","-0.1264","0.7559","-1.1267","-0.5893",
"-1.1546","-1.0027","-1.3157",""};
"-1.1546","-1.0027","-1.3157",""};
Assert.assertArrayEquals(expected, molecularAlteration1.getSplitValues());
GeneMolecularAlteration molecularAlteration2 = result.get(1);
Assert.assertEquals((Integer) 208, molecularAlteration2.getEntrezGeneId());
String[] expected2 = {"1.4146","-0.0662","-0.8585","-1.6576","-0.3552","-0.8306","0.8102","0.1146","0.3498","0.0349","0.4927",
"-0.8665","-0.4754","-0.7221",""};
"-0.8665","-0.4754","-0.7221",""};
Assert.assertArrayEquals(expected2, molecularAlteration2.getSplitValues());
}

Expand All @@ -71,11 +95,11 @@ public void getGeneMolecularAlterationsInMultipleMolecularProfiles() throws Exce
List<Integer> entrezGeneIds = new ArrayList<>();
entrezGeneIds.add(207);
entrezGeneIds.add(208);

List<GeneMolecularAlteration> result = molecularDataMyBatisRepository
.getGeneMolecularAlterationsInMultipleMolecularProfiles(Arrays.asList("study_tcga_pub_gistic", "study_tcga_pub_mrna"),
entrezGeneIds, "SUMMARY");

Assert.assertEquals(3, result.size());
GeneMolecularAlteration molecularAlteration1 = result.get(0);
Assert.assertEquals((Integer) 207, molecularAlteration1.getEntrezGeneId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@

public interface MolecularDataService {

List<GeneMolecularData> getMolecularData(String molecularProfileId, String sampleListId,
List<Integer> entrezGeneIds, String projection)
List<GeneMolecularData> getMolecularData(String molecularProfileId, String sampleListId,
List<Integer> entrezGeneIds, String projection)
throws MolecularProfileNotFoundException;

BaseMeta getMetaMolecularData(String molecularProfileId, String sampleListId, List<Integer> entrezGeneIds)
BaseMeta getMetaMolecularData(String molecularProfileId, String sampleListId, List<Integer> entrezGeneIds)
throws MolecularProfileNotFoundException;
List<GeneMolecularData> fetchMolecularData(String molecularProfileId, List<String> sampleIds,
List<Integer> entrezGeneIds, String projection)

List<GeneMolecularData> fetchMolecularData(String molecularProfileId, List<String> sampleIds,
List<Integer> entrezGeneIds, String projection)
throws MolecularProfileNotFoundException;

BaseMeta fetchMetaMolecularData(String molecularProfileId, List<String> sampleIds, List<Integer> entrezGeneIds)
BaseMeta fetchMetaMolecularData(String molecularProfileId, List<String> sampleIds, List<Integer> entrezGeneIds)
throws MolecularProfileNotFoundException;

List<GeneMolecularAlteration> getMolecularAlterations(String molecularProfileId, List<Integer> entrezGeneIds,
String projection) throws MolecularProfileNotFoundException;
Iterable<GeneMolecularAlteration> getMolecularAlterations(String molecularProfileId, List<Integer> entrezGeneIds,
String projection) throws MolecularProfileNotFoundException;

Integer getNumberOfSamplesInMolecularProfile(String molecularProfileId);

List<GeneMolecularData> getMolecularDataInMultipleMolecularProfiles(List<String> molecularProfileIds,
List<String> sampleIds, List<Integer> entrezGeneIds,
List<GeneMolecularData> getMolecularDataInMultipleMolecularProfiles(List<String> molecularProfileIds,
List<String> sampleIds, List<Integer> entrezGeneIds,
String projection);

BaseMeta getMetaMolecularDataInMultipleMolecularProfiles(List<String> molecularProfileIds, List<String> sampleIds,
Expand Down