use of org.cbioportal.cmo.pipelines.cvr.model.staging.CVRSegRecord in project cmo-pipelines by knowledgesystems.
the class CVRSegDataReader method open.
@Override
public void open(ExecutionContext ec) throws ItemStreamException {
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);
}
// only read from seg file if exists
File segFile = new File(stagingDirectory, studyId + cvrUtilities.SEG_FILE);
if (!segFile.exists()) {
log.error("File does not exist - skipping data loading from SEG file: " + segFile.getName());
} else {
log.info("Loading SEG data from: " + segFile.getName());
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(DelimitedLineTokenizer.DELIMITER_TAB);
DefaultLineMapper<CVRSegRecord> mapper = new DefaultLineMapper<>();
mapper.setLineTokenizer(tokenizer);
mapper.setFieldSetMapper(new CVRSegFieldSetMapper());
FlatFileItemReader<CVRSegRecord> reader = new FlatFileItemReader<>();
reader.setResource(new FileSystemResource(segFile));
reader.setLineMapper(mapper);
reader.setLinesToSkip(1);
reader.open(ec);
try {
CVRSegRecord to_add;
while ((to_add = reader.read()) != null && to_add.getID() != null) {
if (!cvrSampleListUtil.getNewDmpSamples().contains(to_add.getID())) {
cvrSegRecords.add(to_add);
}
}
} catch (Exception e) {
log.error("Error loading data from SEG file: " + segFile.getName());
throw new ItemStreamException(e);
}
reader.close();
}
// merge cvr SEG data existing SEG data and new data from CVR
for (CVRMergedResult result : cvrData.getResults()) {
CVRSegData cvrSegData = result.getSegData();
if (cvrSegData.getSegData() == null) {
continue;
}
HashMap<Integer, String> indexMap = new HashMap<>();
boolean first = true;
String id = result.getMetaData().getDmpSampleId();
for (List<String> segData : cvrSegData.getSegData()) {
if (first) {
for (int i = 0; i < segData.size(); i++) {
indexMap.put(i, segData.get(i));
}
first = false;
} else {
CVRSegRecord cvrSegRecord = new CVRSegRecord();
for (int i = 0; i < segData.size(); i++) {
cvrSegRecord.setID(id);
// dots in source; replaced for method
String field = indexMap.get(i).replace(".", "_");
try {
cvrSegRecord.getClass().getMethod("set" + field, String.class).invoke(cvrSegRecord, segData.get(i));
} catch (Exception e) {
log.warn("No such method 'set" + field + "' for CVRSegRecord");
}
}
cvrSegRecords.add(cvrSegRecord);
}
}
}
}
use of org.cbioportal.cmo.pipelines.cvr.model.staging.CVRSegRecord in project cmo-pipelines by knowledgesystems.
the class CVRSegFieldSetMapper method mapFieldSet.
@Override
public CVRSegRecord mapFieldSet(FieldSet fs) throws BindException {
CVRSegRecord record = new CVRSegRecord();
List<String> fields = CVRSegRecord.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;
}
Aggregations