Skip to content

Commit

Permalink
Make sample name API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Nov 16, 2023
1 parent ccf1ea3 commit 4b5863c
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public abstract class AbstractMeasurementInfo implements IMeasurementInfo {

private static final long serialVersionUID = 4247159773898302230L;
private static final long serialVersionUID = 4247159773898302231L;
private static final Logger logger = Logger.getLogger(AbstractMeasurementInfo.class);
//
private static final String OPERATOR = "Operator";
Expand All @@ -36,6 +36,7 @@ public abstract class AbstractMeasurementInfo implements IMeasurementInfo {
private static final String MISC_INFO_SEPARATED = "Misc Info Separated";
private static final String SHORT_INFO = "Short Info";
private static final String DETAILED_INFO = "Detailed Info";
private static final String SAMPLE_NAME = "Sample Name";
private static final String SAMPLE_GROUP = "Sample Group";
private static final String BARCODE = "Barcode";
private static final String BARCODE_TYPE = "Barcode Type";
Expand All @@ -56,6 +57,7 @@ public AbstractMeasurementInfo() {
headerMap.put(MISC_INFO_SEPARATED, "");
headerMap.put(SHORT_INFO, "");
headerMap.put(DETAILED_INFO, "");
headerMap.put(SAMPLE_NAME, "");
headerMap.put(SAMPLE_GROUP, "");
headerMap.put(BARCODE, "");
headerMap.put(BARCODE_TYPE, "");
Expand Down Expand Up @@ -231,6 +233,22 @@ public void setDetailedInfo(String detailedInfo) {
}
}

@Override
public String getSampleName() {

return getHeaderData(SAMPLE_NAME);
}

@Override
public void setSampleName(String sampleName) {

if(sampleName != null) {
putHeaderData(SAMPLE_NAME, sampleName);
} else {
putHeaderData(SAMPLE_NAME, "");
}
}

@Override
public String getSampleGroup() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class FilteredMeasurement<FilteredType extends IMeasurement, ConfigType>
private String sampleWeightUnit;
private String barcodeType;
private String barcode;
private String sampleName;
private String sampleGroup;
private String shortInfo;
private String miscInfoSeparated;
Expand Down Expand Up @@ -296,6 +297,21 @@ public void setDetailedInfo(String detailedInfo) {
this.detailedInfo = detailedInfo;
}

@Override
public String getSampleName() {

if(sampleName != null) {
return sampleName;
}
return measurement.getSampleName();
}

@Override
public void setSampleName(String sampleName) {

this.sampleName = sampleName;
}

@Override
public String getSampleGroup() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public interface IMeasurementInfo extends Serializable {

void setDetailedInfo(String detailedInfo);

String getSampleName();

void setSampleName(String sampleName);

String getSampleGroup();

void setSampleGroup(String sampleGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public IChromatogramMSD read(File file, IProgressMonitor monitor) throws IOExcep
chromatogram = new VendorChromatogram();
//
AdminType admin = mzData.getDescription().getAdmin();
chromatogram.setDataName(admin.getSampleName());
chromatogram.setSampleName(admin.getSampleName());
for(PersonType contact : admin.getContact()) {
String contactDetails = String.join(", ", contact.getName(), contact.getInstitution(), contact.getContactInfo());
if(chromatogram.getOperator().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public IChromatogramMSD read(File file, IProgressMonitor monitor) throws IOExcep
chromatogram = new VendorChromatogram();
//
AdminType admin = mzData.getDescription().getAdmin();
chromatogram.setDataName(admin.getSampleName());
chromatogram.setSampleName(admin.getSampleName());
for(PersonType contact : admin.getContact()) {
String contactDetails = String.join(", ", contact.getName(), contact.getInstitution(), contact.getContactInfo());
if(chromatogram.getOperator().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public IChromatogramMSD read(File file, IProgressMonitor monitor) throws IOExcep
SampleListType sampleList = mzML.getSampleList();
if(sampleList != null) {
for(SampleType sample : sampleList.getSample()) {
chromatogram.setDataName(sample.getName());
chromatogram.setSampleName(sample.getName());
}
}
for(InstrumentConfigurationType instrument : mzML.getInstrumentConfigurationList().getInstrumentConfiguration()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public IChromatogramMSD read(File file, IProgressMonitor monitor) throws IOExcep
SampleListType sampleList = mzML.getSampleList();
if(sampleList != null) {
for(SampleType sample : sampleList.getSample()) {
chromatogram.setDataName(sample.getName());
chromatogram.setSampleName(sample.getName());
}
}
for(InstrumentConfigurationType instrument : mzML.getInstrumentConfigurationList().getInstrumentConfiguration()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void readExperiment(IVendorPlate vendorPlate, Rdml rdml) throws InvalidP
IdReferencesType sample = react.getSample();
IWell well = new Well();
well.setPosition(calculateCoordinate(w + 1, pcrFormatType));
well.putHeaderData(IWell.SAMPLE_ID, sample.getId());
well.setSampleName(sample.getId());
Channel channel = createChannel(rdml);
for(DataType data : react.getData()) {
for(DpAmpCurveType adp : data.getAdp()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void readExperiment(IVendorPlate vendorPlate, Rdml rdml) throws InvalidP
IdReferencesType sample = react.getSample();
IWell well = new Well();
well.setPosition(calculateCoordinate(w + 1, pcrFormatType));
well.putHeaderData(IWell.SAMPLE_ID, sample.getId());
well.setSampleName(sample.getId());
Channel channel = createChannel(rdml);
for(DataType data : react.getData()) {
for(DpAmpCurveType adp : data.getAdp()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ private void readExperiment(IVendorPlate vendorPlate, Rdml rdml) throws InvalidP
IdReferencesType sample = react.getSample();
IWell well = new Well();
well.setPosition(calculateCoordinate(w + 1, pcrFormatType));
well.putHeaderData(IWell.SAMPLE_ID, sample.getId());
well.setSampleName(sample.getId());
Channel channel = createChannel(rdml);
for(DataType data : react.getData()) {
for(DpAmpCurveType adp : data.getAdp()) {
channel.getFluorescence().add((double)adp.getFluor());
}
}
well.getChannels().put(0, channel);
well.putHeaderData(IWell.SAMPLE_SUBSET, "Default");
well.putHeaderData(IWell.SAMPLE_SUBSET, "Default"); // TODO: should be optional
vendorPlate.getWells().add(well);
w++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

public interface IWell extends Comparable<IWell>, IMeasurement {

String SAMPLE_ID = "Sample ID";
String TARGET_NAME = "Target Name";
String TARGET_TYPE = "Target Type";
String SAMPLE_SUBSET = "Sample Subset";
Expand Down Expand Up @@ -53,8 +52,6 @@ public interface IWell extends Comparable<IWell>, IMeasurement {

Map<Integer, IChannel> getChannels();

String getSampleId();

String getSampleSubset();

SampleType getSampleType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class Well extends AbstractMeasurement implements IWell {

public Well() {

addProtectedKey(SAMPLE_ID);
addProtectedKey(TARGET_NAME);
addProtectedKey(SAMPLE_SUBSET);
addProtectedKey(SAMPLE_TYPE);
Expand All @@ -46,7 +45,7 @@ public String getLabel() {
if(isEmptyMeasurement()) {
return getPosition().toString();
} else {
return getPosition().toString() + ": " + getSampleId();
return getPosition().toString() + ": " + getSampleName();
}
}

Expand Down Expand Up @@ -120,12 +119,6 @@ public int compareTo(IWell well) {
}
}

@Override
public String getSampleId() {

return getHeaderDataOrDefault(SAMPLE_ID, "").trim();
}

@Override
public String getSampleSubset() {

Expand Down Expand Up @@ -173,7 +166,7 @@ public void setTargetType(TargetType targetType) {
@Override
public boolean isEmptyMeasurement() {

return ("".equals(getSampleId().trim()) || "_".equals(getSampleId().trim()));
return ("".equals(getSampleName().trim()) || "_".equals(getSampleName().trim()));
}

@Override
Expand Down Expand Up @@ -236,7 +229,6 @@ public IWell makeDeepCopy() {
for(Entry<Integer, IChannel> set : channels.entrySet()) {
well.getChannels().put(set.getKey(), set.getValue().makeDeepCopy());
}
well.putHeaderData(SAMPLE_ID, getSampleId());
well.putHeaderData(TARGET_NAME, getTargetName());
well.putHeaderData(SAMPLE_SUBSET, getSampleSubset());
well.putHeaderData(SAMPLE_TYPE, getSampleType().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void generateVirtualChannels(Set<IWell> wells, String targetSubset) {
continue;
}
Pattern pattern = Pattern.compile(virtualChannel.getSample(), Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(well.getSampleId());
Matcher matcher = pattern.matcher(well.getSampleName());
if(!matcher.find()) {
continue;
}
Expand Down Expand Up @@ -176,7 +176,7 @@ void generateVirtualChannels(Set<IWell> wells, String targetSubset) {
continue;
}
Pattern pattern = Pattern.compile(wellMapping.getSample(), Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(well.getSampleId());
Matcher matcher = pattern.matcher(well.getSampleName());
if(!matcher.find()) {
continue;
}
Expand All @@ -202,7 +202,7 @@ void generateVirtualChannels(Set<IWell> wells, String targetSubset) {
targetChannel.setCrossingPoint(virtualCrossingPoint);
}
if(well.getChannels().containsKey(target - 1)) {
logger.warn("Channel " + target + " for " + well.getSampleId() + " is already defined. Skipping.");
logger.warn("Channel " + target + " for " + well.getSampleName() + " is already defined. Skipping.");
}
well.getChannels().putIfAbsent(target - 1, targetChannel);
}
Expand All @@ -224,7 +224,7 @@ void printResults(IPlate plate, String targetSubset, CSVPrinter csvPrinter) thro
continue;
}
Pattern pattern = Pattern.compile(wellMapping.getSample(), Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(well.getSampleId());
Matcher matcher = pattern.matcher(well.getSampleName());
if(!matcher.find()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ private void printResultTable(IPlate plate, String targetSubset, XSSFSheet sheet
String sampleSubset = dataMap.getOrDefault(IWell.SAMPLE_SUBSET, "");
if(isSubsetMatch(sampleSubset, targetSubset)) {
XSSFRow data = sheet.createRow(sheet.getLastRowNum() + 1);
String sampleNumber = dataMap.getOrDefault(IWell.SAMPLE_ID, "");
String sampleName = well.getSampleName();
String request = "";
if(separator != null && !separator.isEmpty()) {
String[] sampleSplit = sampleNumber.split(separator);
sampleNumber = sampleSplit[0];
String[] sampleSplit = sampleName.split(separator);
sampleName = sampleSplit[0];
if(sampleSplit.length > 1) {
request = sampleSplit[1];
}
Expand All @@ -186,7 +186,7 @@ private void printResultTable(IPlate plate, String targetSubset, XSSFSheet sheet
positionCell.setCellValue(position.getRow() + position.getColumn());
positionCell.setCellStyle(style);
XSSFCell sampleNumberCell = data.createCell(1);
sampleNumberCell.setCellValue(sampleNumber);
sampleNumberCell.setCellValue(sampleName);
sampleNumberCell.setCellStyle(style);
XSSFCell requestCell = data.createCell(2);
requestCell.setCellValue(request);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 Lablicate GmbH.
* Copyright (c) 2021, 2023 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -20,9 +20,9 @@ public class WellComparator implements Comparator<IWell> {
@Override
public int compare(IWell firstWell, IWell secondWell) {

if(firstWell.getSampleId().equals(secondWell.getSampleId())) {
if(firstWell.getSampleName().equals(secondWell.getSampleName())) {
return firstWell.getPosition().compareTo(secondWell.getPosition());
}
return firstWell.getSampleId().compareTo(secondWell.getSampleId());
return firstWell.getSampleName().compareTo(secondWell.getSampleName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private void printResultTable(IPlate plate, String targetSubset, PrintWriter pri
if(isSubsetMatch(sampleSubset, targetSubset)) {
printWriter.print(position.getRow() + position.getColumn());
printWriter.print(TAB);
printWriter.print(well.getSampleId());
printWriter.print(well.getSampleName());
printWriter.print(TAB);
printWriter.print(well.getSampleSubset());
printWriter.print(TAB);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2021 Lablicate GmbH.
* Copyright (c) 2019, 2023 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -197,7 +197,7 @@ private void showWellDetails(IWell well) {
StringBuilder builder = new StringBuilder();
String sampleSubset = well.getSampleSubset();
String targetName = well.getTargetName();
builder.append(well.getSampleId());
builder.append(well.getSampleName());
if(!well.isEmptyMeasurement()) {
builder.append(" | ");
builder.append(sampleSubset.equals("") ? "--" : sampleSubset);
Expand Down Expand Up @@ -262,4 +262,4 @@ private void highlightComposite(PCRWell pcrWellHighlight) {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public String getWellInfo(IWell well) {
} else {
if(well.isActiveSubset()) {
StringBuilder builder = new StringBuilder();
builder.append(well.getSampleId());
builder.append(well.getSampleName());
appendHeaderInfo(well, builder);
appendCrossingPointInfo(well, builder);
text = builder.toString();
Expand Down

0 comments on commit 4b5863c

Please sign in to comment.