<commit_before>/*
 * Copyright (c) 2016 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/>.
*/

package org.mskcc.cbio.portal.scripts;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mskcc.cbio.portal.dao.DaoCancerStudy;
import org.mskcc.cbio.portal.dao.DaoCnaEvent;
import org.mskcc.cbio.portal.dao.DaoException;
import org.mskcc.cbio.portal.dao.DaoGeneOptimized;
import org.mskcc.cbio.portal.dao.DaoGeneticProfile;
import org.mskcc.cbio.portal.dao.DaoMutation;
import org.mskcc.cbio.portal.dao.DaoSample;
import org.mskcc.cbio.portal.model.CancerStudy;
import org.mskcc.cbio.portal.model.CanonicalGene;
import org.mskcc.cbio.portal.model.CnaEvent;
import org.mskcc.cbio.portal.model.ExtendedMutation;
import org.mskcc.cbio.portal.util.ConsoleUtil;
import org.mskcc.cbio.portal.util.ImportDataUtil;
import org.mskcc.cbio.portal.util.ProgressMonitor;
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;

/**
 * @author <NAME> <EMAIL>
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/applicationContext-dao.xml" })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional
public class TestImportProfileData {

	int studyId;
	int geneticProfileId;
	
    @Before
    public void setUp() throws DaoException {
        ProgressMonitor.setConsoleMode(false);
        loadGenes();
    }
	
	@Rule
	public ExpectedException exception = ExpectedException.none();

	@Test
	public void testImportMutationsFile() throws Exception {
        String[] args = {
        		"--data","target/test-classes/data_mutations_extended.txt",
        		"--meta","target/test-classes/meta_mutations_extended.txt",
        		"--loadMode", "bulkLoad"
        		};
        ImportProfileData runner = new ImportProfileData(args);
        runner.run();
        //This test is to check if the ImportProfileData class indeed adds the study stable Id in front of the 
        //dataset study id (e.g. studyStableId + "_breast_mutations"):
        String studyStableId = "study_tcga_pub";
		studyId = DaoCancerStudy.getCancerStudyByStableId(studyStableId).getInternalId();
		int sampleId = DaoSample.getSampleByCancerStudyAndSampleId(studyId, "TCGA-AA-3664-01").getInternalId();

        geneticProfileId = DaoGeneticProfile.getGeneticProfileByStableId(studyStableId + "_breast_mutations").getGeneticProfileId();
        validateMutationAminoAcid (geneticProfileId, sampleId, 54407, "T433A");  
        
	}
	
	
	@Test
	public void testImportCNAFile() throws Exception {
		
		//genes in this test:
        DaoGeneOptimized daoGene = DaoGeneOptimized.getInstance();
	    daoGene.addGene(new CanonicalGene(999999672, "TESTBRCA1"));
	    daoGene.addGene(new CanonicalGene(999999675, "TESTBRCA2"));
		
        String[] args = {
        		"--data","src/test/resources/data_CNA_sample.txt",
        		"--meta","src/test/resources/meta_CNA.txt" ,
        		"--noprogress",
        		"--loadMode", "bulkLoad"
        		};
        
        String[] sampleIds = {"TCGA-02-0001-01","TCGA-02-0003-01","TCGA-02-0004-01","TCGA-02-0006-01"};
        
        //This test is to check if the ImportProfileData class indeed adds the study stable Id in front of the 
        //dataset study id (e.g. studyStableId + "_breast_mutations"):
        String studyStableId = "study_tcga_pub";
        CancerStudy study = DaoCancerStudy.getCancerStudyByStableId(studyStableId); 
		studyId = study.getInternalId();
		
		//will be needed when relational constraints are active:
        ImportDataUtil.addPatients(sampleIds, study);<commit_msg>Reference TestImportProfileData data files from source folder<commit_after>/*
 * Copyright (c) 2016 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/>.
*/

package org.mskcc.cbio.portal.scripts;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mskcc.cbio.portal.dao.DaoCancerStudy;
import org.mskcc.cbio.portal.dao.DaoCnaEvent;
import org.mskcc.cbio.portal.dao.DaoException;
import org.mskcc.cbio.portal.dao.DaoGeneOptimized;
import org.mskcc.cbio.portal.dao.DaoGeneticProfile;
import org.mskcc.cbio.portal.dao.DaoMutation;
import org.mskcc.cbio.portal.dao.DaoSample;
import org.mskcc.cbio.portal.model.CancerStudy;
import org.mskcc.cbio.portal.model.CanonicalGene;
import org.mskcc.cbio.portal.model.CnaEvent;
import org.mskcc.cbio.portal.model.ExtendedMutation;
import org.mskcc.cbio.portal.util.ConsoleUtil;
import org.mskcc.cbio.portal.util.ImportDataUtil;
import org.mskcc.cbio.portal.util.ProgressMonitor;
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;

/**
 * @author <NAME> <EMAIL>
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/applicationContext-dao.xml" })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional
public class TestImportProfileData {

	int studyId;
	int geneticProfileId;
	
    @Before
    public void setUp() throws DaoException {
        ProgressMonitor.setConsoleMode(false);
        loadGenes();
    }
	
	@Rule
	public ExpectedException exception = ExpectedException.none();

	@Test
	public void testImportMutationsFile() throws Exception {
        String[] args = {
                "--data","src/test/resources/data_mutations_extended.txt",
                "--meta","src/test/resources/meta_mutations_extended.txt",
                "--loadMode", "bulkLoad"
        };
        ImportProfileData runner = new ImportProfileData(args);
        runner.run();
        //This test is to check if the ImportProfileData class indeed adds the study stable Id in front of the 
        //dataset study id (e.g. studyStableId + "_breast_mutations"):
        String studyStableId = "study_tcga_pub";
		studyId = DaoCancerStudy.getCancerStudyByStableId(studyStableId).getInternalId();
		int sampleId = DaoSample.getSampleByCancerStudyAndSampleId(studyId, "TCGA-AA-3664-01").getInternalId();

        geneticProfileId = DaoGeneticProfile.getGeneticProfileByStableId(studyStableId + "_breast_mutations").getGeneticProfileId();
        validateMutationAminoAcid (geneticProfileId, sampleId, 54407, "T433A");  
    }

	@Test
	public void testImportCNAFile() throws Exception {
		
		//genes in this test:
        DaoGeneOptimized daoGene = DaoGeneOptimized.getInstance();
	    daoGene.addGene(new CanonicalGene(999999672, "TESTBRCA1"));
	    daoGene.addGene(new CanonicalGene(999999675, "TESTBRCA2"));
		
        String[] args = {
                "--data","src/test/resources/data_CNA_sample.txt",
                "--meta","src/test/resources/meta_CNA.txt" ,
                "--noprogress",
                "--loadMode", "bulkLoad"
        };

        String[] sampleIds = {"TCGA-02-0001-01","TCGA-02-0003-01","TCGA-02-0004-01","TCGA-02-0006-01"};

        //This test is to check if the ImportProfileData class indeed adds the study stable Id in front of the 
        //dataset study id (e.g. studyStableId + "_breast_mutations"):
        String studyStableId = "study_tcga_pub";
        CancerStudy study = DaoCancerStudy.getCancerStudyByStableId(studyStableId); 
		studyId = study.getInternalId();
		
		//will be needed when relational constraints are active:
        ImportDataUtil.addPatients(sampleIds, study);
{'fraction_non_alphanumeric': 0.10367927445120066, 'fraction_numerical': 0.015459136349582603, 'mean_word_length': 3.9258883248730965, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5014454', 'n_tokens_mistral': 3149, 'n_tokens_neox': 2978, 'n_words': 703}