Search in sources :

Example 1 with LinkedMskimpactCaseRecord

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

the class LinkedMskimpactCaseReader method loadExistingLinkedIds.

private void loadExistingLinkedIds() {
    File stagingFile = new File(stagingDirectory, cvrUtilities.CORRESPONDING_ID_FILE);
    if (!stagingFile.exists()) {
        LOG.warn("File does not exist - skipping data loading from linked ARCHER samples file: " + stagingFile.getName());
        return;
    }
    LOG.info("Loading linked ARCHER sample data from: " + stagingFile.getName());
    DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(DelimitedLineTokenizer.DELIMITER_TAB);
    DefaultLineMapper<LinkedMskimpactCaseRecord> mapper = new DefaultLineMapper<>();
    mapper.setLineTokenizer(tokenizer);
    mapper.setFieldSetMapper(new LinkedImpactCaseFieldSetMapper());
    FlatFileItemReader<LinkedMskimpactCaseRecord> reader = new FlatFileItemReader<>();
    reader.setResource(new FileSystemResource(stagingFile));
    reader.setLineMapper(mapper);
    reader.setLinesToSkip(1);
    reader.open(new ExecutionContext());
    try {
        LinkedMskimpactCaseRecord to_add;
        while ((to_add = reader.read()) != null) {
            // only add samples that are not in the new dmp sample list
            if (!cvrSampleListUtil.getNewDmpSamples().contains(to_add.getSAMPLE_ID())) {
                compiledLinkedIdsMap.put(to_add.getSAMPLE_ID(), to_add);
            }
            // keep a backup in case JSON returned dropped all "linked_mskimpact_case" data
            existingLinkedIdsMap.put(to_add.getSAMPLE_ID(), to_add);
        }
    } catch (Exception e) {
        LOG.error("Error reading linked ARCHER sample data from file: " + stagingFile.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) DefaultLineMapper(org.springframework.batch.item.file.mapping.DefaultLineMapper) LinkedMskimpactCaseRecord(org.cbioportal.cmo.pipelines.cvr.model.staging.LinkedMskimpactCaseRecord) FileSystemResource(org.springframework.core.io.FileSystemResource)

Example 2 with LinkedMskimpactCaseRecord

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

the class LinkedMskimpactCaseReader method loadNewLinkedIds.

private void loadNewLinkedIds() {
    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()) {
        String linkedId = result.getMetaData().getLinkedMskimpactCase();
        if (!Strings.isNullOrEmpty(linkedId) && !linkedId.equals("NA")) {
            compiledLinkedIdsMap.put(result.getMetaData().getDmpSampleId(), new LinkedMskimpactCaseRecord(result.getMetaData().getDmpSampleId(), linkedId));
        }
    }
}
Also used : LinkedMskimpactCaseRecord(org.cbioportal.cmo.pipelines.cvr.model.staging.LinkedMskimpactCaseRecord)

Example 3 with LinkedMskimpactCaseRecord

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

the class LinkedImpactCaseFieldSetMapper method mapFieldSet.

@Override
public LinkedMskimpactCaseRecord mapFieldSet(FieldSet fs) throws BindException {
    LinkedMskimpactCaseRecord record = new LinkedMskimpactCaseRecord();
    List<String> fields = LinkedMskimpactCaseRecord.getFieldNames();
    for (int i = 0; i < fields.size(); i++) {
        String field = fields.get(i);
        try {
            record.getClass().getMethod("set" + field, String.class).invoke(record, fs.readString(i));
        } catch (Exception e) {
            if (e.getClass().equals(NoSuchMethodException.class)) {
                log.info("No set method exists for " + field);
            }
        }
    }
    return record;
}
Also used : LinkedMskimpactCaseRecord(org.cbioportal.cmo.pipelines.cvr.model.staging.LinkedMskimpactCaseRecord) BindException(org.springframework.validation.BindException)

Aggregations

LinkedMskimpactCaseRecord (org.cbioportal.cmo.pipelines.cvr.model.staging.LinkedMskimpactCaseRecord)3 FlatFileItemReader (org.springframework.batch.item.file.FlatFileItemReader)1 DefaultLineMapper (org.springframework.batch.item.file.mapping.DefaultLineMapper)1 DelimitedLineTokenizer (org.springframework.batch.item.file.transform.DelimitedLineTokenizer)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1 BindException (org.springframework.validation.BindException)1