Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show comments for NGS and ProteomicsMeasurements #962

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ public void updateMethod(NGSMethodMetadata methodMetadata) {
setMethod(methodMetadata);
}

/**
* Convenience method to query if the measurement was derived from a pooled sample.
*
* @return true, if the measurement was performed on a pooled sample, else returns false
* @since 1.0.0
*/
public boolean isPooledSampleMeasurement() {
return specificMetadata.size() > 1;
}


public MeasurementCode measurementCode() {
return this.measurementCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,6 @@ public int hashCode() {
return measurementId != null ? measurementId.hashCode() : 0;
}

public Optional<String> comment() {
return Optional.empty();
}

public Optional<String> technicalReplicateName() {
return Optional.ofNullable(technicalReplicateName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import java.util.Objects;
import java.util.Optional;
import life.qbic.projectmanagement.domain.model.sample.SampleId;

/**
Expand Down Expand Up @@ -80,8 +81,8 @@ public String fractionName() {
return fractionName;
}

public String comment() {
return comment;
public Optional<String> comment() {
return comment.isBlank() ? Optional.empty() : Optional.of(comment);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
@PermitAll
public class MeasurementDetailsComponent extends PageArea implements Serializable {

public static final String CLICKABLE = "clickable";
@Serial
private static final long serialVersionUID = 5086686432247130622L;
private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm";
public static final String CLICKABLE = "clickable";
private final TabSheet registeredMeasurementsTabSheet = new TabSheet();
private final MultiSelectLazyLoadingGrid<NGSMeasurement> ngsMeasurementGrid = new MultiSelectLazyLoadingGrid<>();
private final MultiSelectLazyLoadingGrid<ProteomicsMeasurement> proteomicsMeasurementGrid = new MultiSelectLazyLoadingGrid<>();
Expand Down Expand Up @@ -156,7 +156,7 @@ private void resetTabsInTabsheet() {
}

private void addMeasurementTab(GridLazyDataView<?> gridLazyDataView) {
if(gridLazyDataView.getItems().findAny().isEmpty()) {
if (gridLazyDataView.getItems().findAny().isEmpty()) {
return;
}
if (gridLazyDataView.getItem(0) instanceof ProteomicsMeasurement) {
Expand Down Expand Up @@ -186,18 +186,18 @@ private void createNGSMeasurementGrid() {
.setAutoWidth(true)
.setFlexGrow(0);
ngsMeasurementGrid.addComponentColumn(measurement -> {
if (measurement.samplePoolGroup().isEmpty()) {
if (!measurement.isPooledSampleMeasurement()) {
return new Span(
String.join(" ", groupSampleInfoIntoCodeAndLabel(measurement.measuredSamples())));
}
MeasurementPooledSamplesDialog measurementPooledSamplesDialog = new MeasurementPooledSamplesDialog(
measurement);
Icon expandIcon = VaadinIcon.EXPAND_SQUARE.create();
expandIcon.addClassName("expand-icon");
Span expandSpan = new Span(new Span("Pooled sample"), expandIcon);
expandSpan.addClassNames("sample-column-cell", CLICKABLE);
expandSpan.addClickListener(event -> measurementPooledSamplesDialog.open());
return expandSpan;
return createNGSPooledSampleComponent(measurement);
})
.setTooltipGenerator(measurement -> {
if (!measurement.isPooledSampleMeasurement()) {
return String.join(" ", groupSampleInfoIntoCodeAndLabel(measurement.measuredSamples()));
} else {
return "";
}
})
.setHeader("Samples")
.setAutoWidth(true);
Expand Down Expand Up @@ -242,6 +242,28 @@ private void createNGSMeasurementGrid() {
ngsMeasurement -> asClientLocalDateTime(ngsMeasurement.registrationDate())
.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)))
.setAutoWidth(true);
ngsMeasurementGrid.addComponentColumn(measurement -> {
if (!measurement.isPooledSampleMeasurement()) {
Span singularComment = new Span();
singularComment.setText(
measurement.specificMeasurementMetadata().stream().findFirst().orElseThrow().comment()
.orElse(""));
return singularComment;
} else {
return createNGSPooledSampleComponent(measurement);
}
})
.setHeader("Comment")
.setTooltipGenerator(measurement -> {
if (!measurement.isPooledSampleMeasurement()) {
return measurement.specificMeasurementMetadata().stream().findFirst().orElseThrow()
.comment()
.orElse("");
} else {
return "";
}
})
.setAutoWidth(true);
GridLazyDataView<NGSMeasurement> ngsGridDataView = ngsMeasurementGrid.setItems(query -> {
List<SortOrder> sortOrders = query.getSortOrders().stream().map(
it -> new SortOrder(it.getSorted(), it.getDirection().equals(SortDirection.ASCENDING)))
Expand Down Expand Up @@ -281,16 +303,15 @@ private void createProteomicsGrid() {
return new Span(
String.join(" ", groupSampleInfoIntoCodeAndLabel(measurement.measuredSamples())));
}
MeasurementPooledSamplesDialog measurementPooledSamplesDialog = new MeasurementPooledSamplesDialog(
measurement);
Icon expandIcon = VaadinIcon.EXPAND_SQUARE.create();
expandIcon.addClassName("expand-icon");
Span expandSpan = new Span(new Span("Pooled sample"), expandIcon);
expandSpan.addClassNames("sample-column-cell", CLICKABLE);
expandSpan.addClickListener(event -> measurementPooledSamplesDialog.open());
return expandSpan;
return createProteomicsPooledSampleComponent(measurement);
})
.setHeader("Samples")
.setTooltipGenerator(measurement -> {
if (!measurement.isPooledSampleMeasurement()) {
return String.join(" ", groupSampleInfoIntoCodeAndLabel(measurement.measuredSamples()));
}
return "";
})
.setAutoWidth(true);
proteomicsMeasurementGrid.addComponentColumn(
proteomicsMeasurement -> renderOrganisation(proteomicsMeasurement.organisation()))
Expand Down Expand Up @@ -339,21 +360,37 @@ private void createProteomicsGrid() {
.setTooltipGenerator(measurement -> asClientLocalDateTime(measurement.registrationDate())
.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)))
.setAutoWidth(true);
proteomicsMeasurementGrid.addColumn(measurement -> measurement.comment().orElse(""))
proteomicsMeasurementGrid.addComponentColumn(measurement -> {
if (!measurement.isPooledSampleMeasurement()) {
Span singularComment = new Span();
singularComment.setText(
measurement.specificMetadata().stream().findFirst().orElseThrow().comment().orElse(""));
return singularComment;
} else {
return createProteomicsPooledSampleComponent(measurement);
}
})
.setHeader("Comment")
.setTooltipGenerator(measurement -> measurement.comment().orElse(""))
.setTooltipGenerator(measurement -> {
if (!measurement.isPooledSampleMeasurement()) {
return measurement.specificMetadata().stream().findFirst().orElseThrow().comment()
.orElse("");
} else {
return "";
}
})
.setAutoWidth(true);
GridLazyDataView<ProteomicsMeasurement> proteomicsGridDataView = proteomicsMeasurementGrid.setItems(
query -> {
List<SortOrder> sortOrders = query.getSortOrders().stream().map(
it -> new SortOrder(it.getSorted(),
it.getDirection().equals(SortDirection.ASCENDING)))
.collect(Collectors.toList());
sortOrders.add(SortOrder.of("measurementCode").ascending());
return measurementService.findProteomicsMeasurements(searchTerm,
context.experimentId().orElseThrow(),
query.getOffset(), query.getLimit(), sortOrders, context.projectId().orElseThrow())
.stream();
sortOrders.add(SortOrder.of("measurementCode").ascending());
return measurementService.findProteomicsMeasurements(searchTerm,
context.experimentId().orElseThrow(),
query.getOffset(), query.getLimit(), sortOrders, context.projectId().orElseThrow())
.stream();

});
proteomicsGridDataView
Expand All @@ -365,6 +402,28 @@ private void createProteomicsGrid() {
measurementsGridDataViews.add(proteomicsGridDataView);
}

private Span createProteomicsPooledSampleComponent(ProteomicsMeasurement measurement) {
MeasurementPooledSamplesDialog measurementPooledSamplesDialog = new MeasurementPooledSamplesDialog(
measurement);
Icon expandIcon = VaadinIcon.EXPAND_SQUARE.create();
expandIcon.addClassName("expand-icon");
Span expandSpan = new Span(new Span("Pooled sample"), expandIcon);
expandSpan.addClassNames("sample-column-cell", CLICKABLE);
expandSpan.addClickListener(event -> measurementPooledSamplesDialog.open());
return expandSpan;
}

private Span createNGSPooledSampleComponent(NGSMeasurement measurement) {
MeasurementPooledSamplesDialog measurementPooledSamplesDialog = new MeasurementPooledSamplesDialog(
measurement);
Icon expandIcon = VaadinIcon.EXPAND_SQUARE.create();
expandIcon.addClassName("expand-icon");
Span expandSpan = new Span(new Span("Pooled sample"), expandIcon);
expandSpan.addClassNames("sample-column-cell", CLICKABLE);
expandSpan.addClickListener(event -> measurementPooledSamplesDialog.open());
return expandSpan;
}

private void updateSelectedMeasurementsInfo(boolean isFromClient) {
listeners.forEach(listener -> listener.onComponentEvent(
new MeasurementSelectionChangedEvent(this, isFromClient)));
Expand Down Expand Up @@ -473,6 +532,54 @@ public MeasurementSelectionChangedEvent(MeasurementDetailsComponent source,
}
}

public static class MeasurementTechnologyTab extends Tab {

private final Span countBadge;
private final Span technologyNameComponent;
private final String technology;

public MeasurementTechnologyTab(String technology, int measurementCount) {
this.technology = technology;
technologyNameComponent = new Span();
this.countBadge = createBadge();
Span sampleCountComponent = new Span();
sampleCountComponent.add(countBadge);
this.add(technologyNameComponent, sampleCountComponent);
setTechnologyName(technology);
setMeasurementCount(measurementCount);
addClassName("tab-with-count");
}

/**
* Helper method for creating a badge.
*/
private static Span createBadge() {
Tag tag = new Tag(String.valueOf(0));
tag.setTagColor(TagColor.CONTRAST);
return tag;
}

public String getTabLabel() {
return technology;
}

/**
* Setter method for specifying the number of measurements of the technology type shown in this
* component
*
* @param measurementCount number of samples associated with the experiment shown in this
* component
*/
public void setMeasurementCount(int measurementCount) {
countBadge.setText(String.valueOf(measurementCount));
}

public void setTechnologyName(String technologyName) {
this.technologyNameComponent.setText(technologyName);
}

}

public class MeasurementPooledSamplesDialog extends Dialog {

/**
Expand Down Expand Up @@ -542,6 +649,10 @@ private void setPooledProteomicSampleDetails(
.setHeader("Measurement Label")
.setTooltipGenerator(ProteomicsSpecificMeasurementMetadata::label)
.setAutoWidth(true);
sampleDetailsGrid.addColumn(metadata -> metadata.comment().orElse(""))
.setHeader("comment")
.setTooltipGenerator(metadata -> metadata.comment().orElse(""))
.setAutoWidth(true);
sampleDetailsGrid.setItems(proteomicsSpecificMeasurementMetadata);
add(sampleDetailsGrid);
}
Expand Down Expand Up @@ -611,51 +722,4 @@ private Span pooledMeasurementEntry(String propertyLabel, String propertyValue)
}
}

public static class MeasurementTechnologyTab extends Tab {

private final Span countBadge;
private final Span technologyNameComponent;
private final String technology;

public MeasurementTechnologyTab(String technology, int measurementCount) {
this.technology = technology;
technologyNameComponent = new Span();
this.countBadge = createBadge();
Span sampleCountComponent = new Span();
sampleCountComponent.add(countBadge);
this.add(technologyNameComponent, sampleCountComponent);
setTechnologyName(technology);
setMeasurementCount(measurementCount);
addClassName("tab-with-count");
}

public String getTabLabel() {
return technology;
}

/**
* Helper method for creating a badge.
*/
private static Span createBadge() {
Tag tag = new Tag(String.valueOf(0));
tag.setTagColor(TagColor.CONTRAST);
return tag;
}

/**
* Setter method for specifying the number of measurements of the technology type shown in
* this component
*
* @param measurementCount number of samples associated with the experiment shown in this component
*/
public void setMeasurementCount(int measurementCount) {
countBadge.setText(String.valueOf(measurementCount));
}

public void setTechnologyName(String technologyName) {
this.technologyNameComponent.setText(technologyName);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static ProteomicsMeasurementEntry convertProteomicsMeasurement(
measurement.lcmsMethod(),
measurement.labelType(),
specificMeasurementMetadata.label(),
specificMeasurementMetadata.comment());
specificMeasurementMetadata.comment().orElse(""));
}

private static NGSMeasurementEntry convertNGSMeasurement(NGSMeasurement measurement,
Expand Down
Loading