Skip to content

Commit

Permalink
Add importer and integration test for structural variant data
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander Tan authored and rnugraha committed May 31, 2018
1 parent c78c697 commit 1c26cd6
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 81 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Copyright (c) 2018 The Hyve B.V.
* This code is licensed under the GNU Affero General Public License (AGPL),
* version 3, or (at your option) any later version.
*/

/*
* 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 <http://www.gnu.org/licenses/>.
*/

/*
* @author Sander Tan
*/

package org.mskcc.cbio.portal.scripts;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mskcc.cbio.portal.dao.*;
import org.mskcc.cbio.portal.model.*;
import org.mskcc.cbio.portal.util.*;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;
import static org.junit.Assert.*;
import java.io.*;
import java.sql.*;

/**
* Test class to test functionality of ImportStructralVariantData
*/
@SuppressWarnings("deprecation")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/applicationContext-dao.xml" })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional
public class TestImportStructuralVariantData{
int studyId;
int geneticProfileId;

/**
* Extracts StructuralVariant record from ResultSet.
* @param rs
* @return StructuralVariant record
* @throws SQLException
* @throws DaoException
*/
private StructuralVariant extractStructuralVariant(ResultSet rs) throws SQLException, DaoException {
StructuralVariant structuralVariant = new StructuralVariant();
structuralVariant.setGeneticProfileId(rs.getInt("GENETIC_PROFILE_ID"));
structuralVariant.setSampleIdInternal(rs.getInt("SAMPLE_ID"));
structuralVariant.setSite1EntrezGeneId(rs.getLong("SITE1_ENTREZ_GENE_ID"));
structuralVariant.setSite1EnsemblTranscriptId(rs.getString("SITE1_ENSEMBL_TRANSCRIPT_ID"));
structuralVariant.setSite1Exon(rs.getInt("SITE1_EXON"));
structuralVariant.setSite1Chromosome(rs.getString("SITE1_CHROMOSOME"));
structuralVariant.setSite1Position(rs.getInt("SITE1_POSITION"));
structuralVariant.setSite1Description(rs.getString("SITE1_DESCRIPTION"));
structuralVariant.setSite2EntrezGeneId(rs.getLong("SITE2_ENTREZ_GENE_ID"));
structuralVariant.setSite2EnsemblTranscriptId(rs.getString("SITE2_ENSEMBL_TRANSCRIPT_ID"));
structuralVariant.setSite2Exon(rs.getInt("SITE2_EXON"));
structuralVariant.setSite2Chromosome(rs.getString("SITE2_CHROMOSOME"));
structuralVariant.setSite2Position(rs.getInt("SITE2_POSITION"));
structuralVariant.setSite2Description(rs.getString("SITE2_DESCRIPTION"));
structuralVariant.setSite2EffectOnFrame(rs.getString("SITE2_EFFECT_ON_FRAME"));
structuralVariant.setNcbiBuild(rs.getString("NCBI_BUILD"));
structuralVariant.setDnaSupport(rs.getString("DNA_SUPPORT"));
structuralVariant.setRnaSupport(rs.getString("RNA_SUPPORT"));
structuralVariant.setNormalReadCount(rs.getInt("NORMAL_READ_COUNT"));
structuralVariant.setTumorReadCount(rs.getInt("TUMOR_READ_COUNT"));
structuralVariant.setNormalVariantCount(rs.getInt("NORMAL_VARIANT_COUNT"));
structuralVariant.setTumorVariantCount(rs.getInt("TUMOR_VARIANT_COUNT"));
structuralVariant.setNormalPairedEndReadCount(rs.getInt("NORMAL_PAIRED_END_READ_COUNT"));
structuralVariant.setTumorPairedEndReadCount(rs.getInt("TUMOR_PAIRED_END_READ_COUNT"));
structuralVariant.setNormalSplitReadCount(rs.getInt("NORMAL_SPLIT_READ_COUNT"));
structuralVariant.setTumorSplitReadCount(rs.getInt("TUMOR_SPLIT_READ_COUNT"));
structuralVariant.setAnnotation(rs.getString("ANNOTATION"));
structuralVariant.setBreakpointType(rs.getString("BREAKPOINT_TYPE"));
structuralVariant.setCenter(rs.getString("CENTER"));
structuralVariant.setConnectionType(rs.getString("CONNECTION_TYPE"));
structuralVariant.setEventInfo(rs.getString("EVENT_INFO"));
structuralVariant.setVariantClass(rs.getString("CLASS"));
structuralVariant.setLength(rs.getInt("LENGTH"));
structuralVariant.setComments(rs.getString("COMMENTS"));
structuralVariant.setExternalAnnotation(rs.getString("EXTERNAL_ANNOTATION"));
structuralVariant.setDriverFilter(rs.getString("DRIVER_FILTER"));
structuralVariant.setDriverFilterAnn(rs.getString("DRIVER_FILTER_ANNOTATION"));
structuralVariant.setDriverTiersFilter(rs.getString("DRIVER_TIERS_FILTER"));
structuralVariant.setDriverTiersFilterAnn(rs.getString("DRIVER_TIERS_FILTER_ANNOTATION"));
return structuralVariant;
}

@Before
public void setUp() throws DaoException
{
studyId = DaoCancerStudy.getCancerStudyByStableId("study_tcga_pub").getInternalId();
geneticProfileId = DaoGeneticProfile.getGeneticProfileByStableId("study_tcga_pub_structural_variants").getGeneticProfileId();
}

@Test
public void testImportStructuralVariantData() throws DaoException, IOException {
ProgressMonitor.setConsoleMode(false);

// Load test structural variants
File file = new File("src/test/resources/data_structural_variants.txt");
ImportStructuralVariantData importer = new ImportStructuralVariantData(file, geneticProfileId, null);
importer.importData();
MySQLbulkLoader.flushAll();

// Retrieve all imported structural variants
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = JdbcUtil.getDbConnection(DaoGeneset.class);
pstmt = con.prepareStatement("SELECT * FROM structural_variant");
rs = pstmt.executeQuery();

// Test first structural variant entry
rs.next();
StructuralVariant structuralVariant = extractStructuralVariant(rs);
assertEquals("KIAA1549-BRAF.K16B10.COSF509_2", structuralVariant.getSite2Description());

// Test second structural variant entry
rs.next();
structuralVariant = extractStructuralVariant(rs);
assertEquals("ENST00000318522", structuralVariant.getSite1EnsemblTranscriptId());
}
catch (SQLException e) {
throw new DaoException(e);
}
finally {
JdbcUtil.closeAll(DaoGeneset.class, con, pstmt, rs);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;
import org.cbioportal.model.GenesetMolecularData;
import org.cbioportal.model.StructuralVariant;
import org.cbioportal.service.GenesetDataService;
import org.cbioportal.service.StructuralVariantService;
import org.mskcc.cbio.portal.dao.DaoGeneset;


Expand Down Expand Up @@ -130,7 +132,7 @@ public void testLoadStudyEs0() throws Throwable {
}
}
//check that there are only warnings for empty positions in fake data:
assertEquals(1, countWarnings);
assertEquals(0, countWarnings);

//check that ALL data really got into DB correctly. In the spirit of integration tests,
//we want to query via the same service layer as the one used by the web API here.
Expand Down Expand Up @@ -163,10 +165,22 @@ public void testLoadStudyEs0() throws Throwable {
List<DBGeneticProfile> geneticProfiles = geneticProfileMapperLegacy.getGeneticProfiles(geneticProfileStableIds);
assertEquals(geneticProfiles.size(), 0);

//===== Check STRUCTURAL VARIANT data ========
// 7 structural variant events are importerted, using 11 unique genes, over 2 samples
geneticProfileStableIds = new ArrayList<String>(Arrays.asList("study_es_0_structural_variants", "study_es_0_structural_variants"));
List<Integer> entrezGeneIds = new ArrayList<Integer>(Arrays.asList(57670, 673, 8031, 5979, 27436, 238, 7113, 2078, 1956, 238, 5774));
List<String> sampleIds = new ArrayList<String>(Arrays.asList("TCGA-A2-A04P-01", "TCGA-A1-A0SB-01"));

StructuralVariantService structuralVariantService = applicationContext.getBean(StructuralVariantService.class);
List<StructuralVariant> structuralVariants = structuralVariantService.fetchStructuralVariants(geneticProfileStableIds, entrezGeneIds, sampleIds);

// Check if all 7 structural variants are imported
assertEquals(7, structuralVariants.size());

//===== Check CNA data ========
geneticProfileStableIds = new ArrayList<String>();
geneticProfileStableIds.add("study_es_0_gistic");
List<String> hugoGeneSymbols = new ArrayList<String>(Arrays.asList("ACAP3","AGRN","ATAD3A","ATAD3B","ATAD3C","AURKAIP1","ERCC5"));
ArrayList<String> hugoGeneSymbols = new ArrayList<String>(Arrays.asList("ACAP3","AGRN","ATAD3A","ATAD3B","ATAD3C","AURKAIP1","ERCC5"));
List<DBProfileData> cnaProfileData = apiService.getGeneticProfileData(geneticProfileStableIds, hugoGeneSymbols, null, null);
//there is data for 7 genes x 778 samples:
assertEquals(7*778, cnaProfileData.size());
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/resources/integrationTestScript.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<value>--data</value>
<value>src/test/resources/genesets/study_es_0_genesets.gmt</value>
<value>--new-version</value>
<value>1</value>
<value>msigdb_6.1</value>
</list>

<!-- #2 Remove study if exists -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ Hugo_Symbol Entrez_Gene_Id Center Tumor_Sample_Barcode Fusion DNA_support RNA_su
FGFR3 2261 saturn TEST-A2B8-01 TMPRSS2-ERG fusion yes yes unknown unknown
ERBB2 2064 jupiter TEST-A2FF-01 Fusion2 yes yes unknown unknown
ERBB2 2064 uranus TCGA-GI-A2C8-01 ERBB2-TEST Fusion yes yes unknown frameshift
TP53 7157 uranus TCGA-GI-A2C8-01 TP53-TEST Fusion yes yes unknown frameshift
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ source_stable_id: gsva_scores
profile_name: Pvalues of GSVA scores on oncogenic signatures gene sets
profile_description: Pvalues GSVA scores using mRNA expression data
data_filename: data_gsva_pvalues.txt
geneset_def_version: 1
geneset_def_version: msigdb_6.1
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ profile_name: GSVA scores on oncogenic signatures gene sets
profile_description: GSVA scores using mRNA expression data
data_filename: data_gsva_scores.txt
show_profile_in_analysis_tab: true
geneset_def_version: 1
geneset_def_version: msigdb_6.1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class StructuralVariantMyBatisRepository implements StructuralVariantRepo
public List<StructuralVariant> fetchStructuralVariants(List<String> molecularProfileIds,
List<Integer> entrezGeneIds, List<String> sampleIds) {

if (molecularProfileIds.size() != sampleIds.size()) {
throw new RuntimeException("molecularProfileIds list and sampleIds list should be the same length.");
}

return structuralVariantMapper.fetchStructuralVariants(molecularProfileIds,
entrezGeneIds, sampleIds);
}
Expand Down

0 comments on commit 1c26cd6

Please sign in to comment.