Search in sources :

Example 1 with CVRClinicalRecord

use of org.cbioportal.cmo.pipelines.cvr.model.staging.CVRClinicalRecord in project cmo-pipelines by knowledgesystems.

the class CVRUtilities method calculateAgeAtSeqReportedYearsForPatient.

/**
 * Calculates the age at seq report for a list of CVRClinical records given a patient age
 * and the reference calculation date.
 * @param referenceCalculationDate
 * @param records
 * @param patientAge
 * @throws ParseException
 */
public void calculateAgeAtSeqReportedYearsForPatient(Date referenceCalculationDate, List<CVRClinicalRecord> records, String patientAge) throws ParseException {
    for (CVRClinicalRecord record : records) {
        if (record.getSEQ_DATE() != null && !record.getSEQ_DATE().isEmpty() && !record.getSEQ_DATE().equals("NA")) {
            Date cvrDateSequenced = CVR_DATE_FORMAT.parse(record.getSEQ_DATE());
            // We know age of patient now from darwin, and the time at which the patient was sequenced.
            // The age of the patient when sequenced is therefore AGE_NOW - YEARS_SINCE_SEQUENCING
            // This converts the date arithmetic from miliseconds to years.
            // 1000ms -> 1s, 60s -> 1m, 60m -> 1h, 24h -> 1d, 365.2422d -> 1y
            Double diffYears = (referenceCalculationDate.getTime() - cvrDateSequenced.getTime()) / 1000L / 60L / 60L / 24L / 365.2422;
            Double ageAtSeqReport = Math.ceil(Integer.parseInt(patientAge) - diffYears);
            if (ageAtSeqReport > 90) {
                record.setAGE_AT_SEQ_REPORTED_YEARS(">90");
            } else {
                record.setAGE_AT_SEQ_REPORTED_YEARS(String.valueOf(ageAtSeqReport.intValue()));
            }
        } else {
            record.setAGE_AT_SEQ_REPORTED_YEARS("NA");
        }
    }
}
Also used : CVRClinicalRecord(org.cbioportal.cmo.pipelines.cvr.model.staging.CVRClinicalRecord)

Example 2 with CVRClinicalRecord

use of org.cbioportal.cmo.pipelines.cvr.model.staging.CVRClinicalRecord in project cmo-pipelines by knowledgesystems.

the class CVRClinicalDataReader method processJsonFile.

private void processJsonFile() {
    CVRData cvrData = new CVRData();
    // load cvr data from cvr_data.json file
    File cvrFile = new File(privateDirectory, CVRUtilities.CVR_FILE);
    try {
        cvrData = cvrUtilities.readJson(cvrFile);
    } catch (IOException e) {
        log.error("Error reading file: " + cvrFile.getName());
        throw new ItemStreamException(e);
    }
    for (CVRMergedResult result : cvrData.getResults()) {
        CVRClinicalRecord record = new CVRClinicalRecord(result.getMetaData(), wholeSlideViewerBaseURL, studyId);
        List<CVRClinicalRecord> records = patientToRecordMap.getOrDefault(record.getPATIENT_ID(), new ArrayList<CVRClinicalRecord>());
        records.add(record);
        patientToRecordMap.put(record.getPATIENT_ID(), records);
        clinicalRecords.add(record);
    }
}
Also used : CVRClinicalRecord(org.cbioportal.cmo.pipelines.cvr.model.staging.CVRClinicalRecord)

Example 3 with CVRClinicalRecord

use of org.cbioportal.cmo.pipelines.cvr.model.staging.CVRClinicalRecord in project cmo-pipelines by knowledgesystems.

the class CVRClinicalDataReader method processClinicalFile.

private void processClinicalFile(ExecutionContext ec) {
    File mskimpactClinicalFile = new File(stagingDirectory, clinicalFilename);
    if (!mskimpactClinicalFile.exists()) {
        log.error("File does not exist - skipping data loading from clinical file: " + mskimpactClinicalFile.getName());
        return;
    }
    log.info("Loading clinical data from: " + mskimpactClinicalFile.getName());
    DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(DelimitedLineTokenizer.DELIMITER_TAB);
    DefaultLineMapper<CVRClinicalRecord> mapper = new DefaultLineMapper<>();
    mapper.setLineTokenizer(tokenizer);
    mapper.setFieldSetMapper(new CVRClinicalFieldSetMapper());
    FlatFileItemReader<CVRClinicalRecord> reader = new FlatFileItemReader<>();
    reader.setResource(new FileSystemResource(mskimpactClinicalFile));
    reader.setLineMapper(mapper);
    reader.setLinesToSkip(1);
    reader.open(ec);
    try {
        CVRClinicalRecord to_add;
        while ((to_add = reader.read()) != null) {
            if (!cvrSampleListUtil.getNewDmpSamples().contains(to_add.getSAMPLE_ID()) && to_add.getSAMPLE_ID() != null) {
                clinicalRecords.add(to_add);
                cvrSampleListUtil.addPortalSample(to_add.getSAMPLE_ID());
                List<CVRClinicalRecord> records = patientToRecordMap.getOrDefault(to_add.getPATIENT_ID(), new ArrayList<CVRClinicalRecord>());
                records.add(to_add);
                patientToRecordMap.put(to_add.getPATIENT_ID(), records);
            }
        }
    } catch (Exception e) {
        log.error("Error reading data from clinical file: " + mskimpactClinicalFile.getName());
        throw new ItemStreamException(e);
    } finally {
        reader.close();
    }
}
Also used : DelimitedLineTokenizer(org.springframework.batch.item.file.transform.DelimitedLineTokenizer) FlatFileItemReader(org.springframework.batch.item.file.FlatFileItemReader) CVRClinicalRecord(org.cbioportal.cmo.pipelines.cvr.model.staging.CVRClinicalRecord) DefaultLineMapper(org.springframework.batch.item.file.mapping.DefaultLineMapper) FileSystemResource(org.springframework.core.io.FileSystemResource)

Example 4 with CVRClinicalRecord

use of org.cbioportal.cmo.pipelines.cvr.model.staging.CVRClinicalRecord in project cmo-pipelines by knowledgesystems.

the class GMLClinicalTasklet method loadClinicalDataGmlPatientSampleMapping.

private void loadClinicalDataGmlPatientSampleMapping(File clinicalFile) throws Exception {
    // load clinical file and create patient-sample mapping
    if (!clinicalFile.exists()) {
        throw new ItemStreamException("Could not find clinical file: " + clinicalFile.getName());
    } else {
        LOG.info("Loading clinical data from: " + clinicalFile.getName());
        DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(DelimitedLineTokenizer.DELIMITER_TAB);
        DefaultLineMapper<CVRClinicalRecord> mapper = new DefaultLineMapper<>();
        mapper.setLineTokenizer(tokenizer);
        mapper.setFieldSetMapper(new CVRClinicalFieldSetMapper());
        FlatFileItemReader<CVRClinicalRecord> reader = new FlatFileItemReader<>();
        reader.setResource(new FileSystemResource(clinicalFile));
        reader.setLineMapper(mapper);
        reader.setLinesToSkip(1);
        reader.open(new ExecutionContext());
        CVRClinicalRecord to_add;
        while ((to_add = reader.read()) != null) {
            cvrSampleListUtil.updateGmlPatientSampleMap(to_add.getPATIENT_ID(), to_add.getSAMPLE_ID());
            clinicalRecords.add(to_add);
            cvrSampleListUtil.addPortalSample(to_add.getSAMPLE_ID());
        }
        reader.close();
    }
    // updates portalSamplesNotInDmpList and dmpSamplesNotInPortal sample lists
    // portalSamples list is only updated if threshold check for max num samples to remove passes
    cvrSampleListUtil.updateSampleLists();
    updateSamplesRemovedList();
}
Also used : DelimitedLineTokenizer(org.springframework.batch.item.file.transform.DelimitedLineTokenizer) FlatFileItemReader(org.springframework.batch.item.file.FlatFileItemReader) ExecutionContext(org.springframework.batch.item.ExecutionContext) CVRClinicalRecord(org.cbioportal.cmo.pipelines.cvr.model.staging.CVRClinicalRecord) DefaultLineMapper(org.springframework.batch.item.file.mapping.DefaultLineMapper) FileSystemResource(org.springframework.core.io.FileSystemResource) ItemStreamException(org.springframework.batch.item.ItemStreamException)

Example 5 with CVRClinicalRecord

use of org.cbioportal.cmo.pipelines.cvr.model.staging.CVRClinicalRecord in project cmo-pipelines by knowledgesystems.

the class CVRClinicalRecordTest method testSampleTypeNull.

@Test
public void testSampleTypeNull() throws Exception {
    CVRClinicalRecord record = new CVRClinicalRecord();
    String sampleType = record.resolveSampleType(null);
    Assert.assertTrue(sampleType.isEmpty());
}
Also used : CVRClinicalRecord(org.cbioportal.cmo.pipelines.cvr.model.staging.CVRClinicalRecord) Test(org.junit.Test)

Aggregations

CVRClinicalRecord (org.cbioportal.cmo.pipelines.cvr.model.staging.CVRClinicalRecord)10 FlatFileItemReader (org.springframework.batch.item.file.FlatFileItemReader)3 DefaultLineMapper (org.springframework.batch.item.file.mapping.DefaultLineMapper)3 DelimitedLineTokenizer (org.springframework.batch.item.file.transform.DelimitedLineTokenizer)3 FileSystemResource (org.springframework.core.io.FileSystemResource)3 Test (org.junit.Test)2 MskimpactAge (org.cbioportal.cmo.pipelines.cvr.model.staging.MskimpactAge)1 MskimpactSeqDate (org.cbioportal.cmo.pipelines.cvr.model.staging.MskimpactSeqDate)1 ExecutionContext (org.springframework.batch.item.ExecutionContext)1 ItemStreamException (org.springframework.batch.item.ItemStreamException)1 BindException (org.springframework.validation.BindException)1