Search in sources :

Example 1 with Sample

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;
}
Also used : Run(com.hartwig.api.model.Run) Logger(org.slf4j.Logger) Status(com.hartwig.api.model.Status) LoggerFactory(org.slf4j.LoggerFactory) RunApi(com.hartwig.api.RunApi) OnlyOne(com.hartwig.api.helpers.OnlyOne) SampleSet(com.hartwig.api.model.SampleSet) SampleType(com.hartwig.api.model.SampleType) List(java.util.List) ApiException(com.hartwig.ApiException) SetApi(com.hartwig.api.SetApi) CreateRun(com.hartwig.api.model.CreateRun) Optional(java.util.Optional) SampleApi(com.hartwig.api.SampleApi) Sample(com.hartwig.api.model.Sample) Ini(com.hartwig.api.model.Ini) SampleSet(com.hartwig.api.model.SampleSet) CreateRun(com.hartwig.api.model.CreateRun) Sample(com.hartwig.api.model.Sample) Run(com.hartwig.api.model.Run) CreateRun(com.hartwig.api.model.CreateRun) ApiException(com.hartwig.ApiException)

Example 2 with Sample

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();
}
Also used : SampleSet(com.hartwig.api.model.SampleSet) Sample(com.hartwig.api.model.Sample)

Example 3 with Sample

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();
}
Also used : Run(com.hartwig.api.model.Run) Logger(org.slf4j.Logger) Optional.ofNullable(java.util.Optional.ofNullable) PipelineState(com.hartwig.pipeline.PipelineState) LoggerFactory(org.slf4j.LoggerFactory) RunApi(com.hartwig.api.RunApi) StagedOutputPublisher(com.hartwig.pipeline.transfer.staged.StagedOutputPublisher) SampleType(com.hartwig.api.model.SampleType) List(java.util.List) RunSet(com.hartwig.api.model.RunSet) Optional(java.util.Optional) SampleApi(com.hartwig.api.SampleApi) Sample(com.hartwig.api.model.Sample) PipelineStatus(com.hartwig.pipeline.execution.PipelineStatus) Collections(java.util.Collections) RunSet(com.hartwig.api.model.RunSet) Sample(com.hartwig.api.model.Sample)

Aggregations

Sample (com.hartwig.api.model.Sample)3 RunApi (com.hartwig.api.RunApi)2 SampleApi (com.hartwig.api.SampleApi)2 Run (com.hartwig.api.model.Run)2 SampleSet (com.hartwig.api.model.SampleSet)2 SampleType (com.hartwig.api.model.SampleType)2 List (java.util.List)2 Optional (java.util.Optional)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ApiException (com.hartwig.ApiException)1 SetApi (com.hartwig.api.SetApi)1 OnlyOne (com.hartwig.api.helpers.OnlyOne)1 CreateRun (com.hartwig.api.model.CreateRun)1 Ini (com.hartwig.api.model.Ini)1 RunSet (com.hartwig.api.model.RunSet)1 Status (com.hartwig.api.model.Status)1 PipelineState (com.hartwig.pipeline.PipelineState)1 PipelineStatus (com.hartwig.pipeline.execution.PipelineStatus)1 StagedOutputPublisher (com.hartwig.pipeline.transfer.staged.StagedOutputPublisher)1