use of com.hartwig.api.model.Sample in project platinum by hartwigmedical.
the class ApiRerun method create.
Long create(final String sampleId) {
try {
List<Sample> samples = sampleApi.list(null, null, null, null, SampleType.TUMOR, sampleId);
for (Sample sample : samples) {
Optional<SampleSet> maybeSampleSet = OnlyOne.ofNullable(setApi.list(null, sample.getId(), true), SampleSet.class);
if (maybeSampleSet.isPresent()) {
SampleSet sampleSet = maybeSampleSet.get();
if (runApi.list(null, null, sampleSet.getId(), null, null, null, null, null).stream().anyMatch(r1 -> r1.getStatus().equals(Status.VALIDATED))) {
return OnlyOne.ofNullable(runApi.list(null, Ini.RERUN_INI, sampleSet.getId(), version, version, null, null, null), Run.class).filter(r -> !r.getStatus().equals(Status.INVALIDATED)).map(r -> {
LOGGER.info("Using existing run for sample [{}] id [{}]", sampleId, r.getId());
return r.getId();
}).orElseGet(() -> {
final Long id = runApi.create(new CreateRun().bucket(bucket).cluster("gcp").context("RESEARCH").ini(Ini.RERUN_INI).version(version).status(Status.PENDING).setId(sampleSet.getId())).getId();
LOGGER.info("Created API run for sample [{}] id [{}]", sampleId, id);
return id;
});
}
}
}
} catch (Exception e) {
LOGGER.error("Unable to create run for [{}] reason [{}]", sampleId, e.getMessage());
return null;
}
return null;
}
use of com.hartwig.api.model.Sample in project pipeline5 by hartwigmedical.
the class ResearchMetadataApi method get.
@Override
public SomaticRunMetadata get() {
List<Sample> possibleTumors = sampleApi.list(null, null, null, null, SampleType.TUMOR, biopsyName);
SampleSet set = possibleTumors.stream().flatMap(sample -> setApi.list(null, sample.getId(), true).stream()).collect(Collectors.toList()).stream().max(Comparator.comparing(SampleSet::getName)).orElseThrow(() -> new IllegalStateException(String.format("No viable set found for biopsy [%s]", biopsyName)));
Sample ref = OnlyOne.of(sampleApi.list(null, null, null, set.getId(), SampleType.REF, null), Sample.class);
Sample tumor = OnlyOne.of(sampleApi.list(null, null, null, set.getId(), SampleType.TUMOR, null), Sample.class);
return SomaticRunMetadata.builder().bucket(arguments.outputBucket()).set(set.getName()).maybeTumor(singleSample(tumor, SingleSampleRunMetadata.SampleType.TUMOR, set.getName())).maybeReference(singleSample(ref, SingleSampleRunMetadata.SampleType.REFERENCE, set.getName())).build();
}
use of com.hartwig.api.model.Sample in project pipeline5 by hartwigmedical.
the class DiagnosticSomaticMetadataApi method get.
@Override
public SomaticRunMetadata get() {
String runBucket = ofNullable(run.getBucket()).orElseThrow();
RunSet set = run.getSet();
List<Sample> samplesBySet = sampleApi.list(null, null, null, set.getId(), null, null);
return SomaticRunMetadata.builder().bucket(runBucket).set(set.getName()).maybeReference(find(SampleType.REF, samplesBySet).map(referenceSample -> toMetadata(referenceSample, run, SingleSampleRunMetadata.SampleType.REFERENCE, anonymizer))).maybeTumor(find(SampleType.TUMOR, samplesBySet).map(referenceSample1 -> toMetadata(referenceSample1, run, SingleSampleRunMetadata.SampleType.TUMOR, anonymizer))).build();
}
Aggregations