Skip to content

Commit d634ee2

Browse files
committed
Start work on functional GUI for empty input sheets
1 parent de2a11d commit d634ee2

20 files changed

Lines changed: 564 additions & 161 deletions

src/main/java/org/awdevelopment/smithlab/args/Arguments.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.awdevelopment.smithlab.args.exceptions.*;
44
import org.awdevelopment.smithlab.config.ConfigDefault;
55
import org.awdevelopment.smithlab.config.Mode;
6+
import org.awdevelopment.smithlab.config.SampleLabelingType;
67
import org.awdevelopment.smithlab.config.SortOption;
78
import org.awdevelopment.smithlab.data.Condition;
89
import org.awdevelopment.smithlab.data.Strain;
@@ -26,13 +27,14 @@ public class Arguments {
2627
private String outputFileName = ConfigDefault.OUTPUT_FILENAME;
2728
private File inputFile = ConfigDefault.INPUT_FILE;
2829
private SortOption outputSorting = ConfigDefault.SORT_OPTION;
29-
private short replicateNumber = ConfigDefault.NUMBER_OF_REPLICATES;
30+
private byte replicateNumber = ConfigDefault.NUMBER_OF_REPLICATES;
3031
private String emptyInputSheetName = ConfigDefault.EMPTY_INPUT_SHEET_NAME;
3132
private Set<Condition> conditions = ConfigDefault.CONDITIONS;
3233
private Set<Strain> strains = ConfigDefault.STRAINS;
33-
private Set<Short> days = ConfigDefault.DAYS;
34-
private short numDays = ConfigDefault.NUM_DAYS;
34+
private Set<Byte> days = ConfigDefault.DAYS;
35+
private byte numDays = ConfigDefault.NUM_DAYS;
3536
private boolean includeBaselineColumn = ConfigDefault.INCLUDE_BASELINE_COLUMN;
37+
private SampleLabelingType sampleLabelingType = ConfigDefault.SAMPLE_LABELING_TYPE;
3638

3739
public Arguments(String[] args, LoggerHelper logger) {
3840
this.LOGGER = logger;
@@ -97,7 +99,7 @@ private void parseArguments(String[] args, boolean suppliedOutputFileName) throw
9799
case "--number-of-replicates", "-r" -> {
98100
checkIfHasNextArgument(args, i);
99101
checkReplicateNumber(args, i);
100-
this.replicateNumber = Short.parseShort(args[i + 1]);
102+
this.replicateNumber = Byte.parseByte(args[i + 1]);
101103
i++;
102104
}
103105
case "--conditions" -> {
@@ -134,7 +136,7 @@ private void parseArguments(String[] args, boolean suppliedOutputFileName) throw
134136
}
135137
if (!days.isEmpty() && numDays != 0) {
136138
LOGGER.atWarn("Both --days and --number-of-days were provided. --number-of-days will be ignored.");
137-
numDays = (short) days.size();
139+
numDays = (byte) days.size();
138140
} else if (days.isEmpty() && numDays > 0) {
139141
LOGGER.atInfo("Number of days provided: " + numDays);
140142
}
@@ -172,21 +174,29 @@ else if (outputFileName.equals(inputFile.getPath())) {
172174
}
173175
}
174176

175-
private short readNumDays(String arg) {
177+
private byte readNumDays(String arg) {
176178
try {
177-
return Short.parseShort(arg);
179+
long numDays = Long.parseLong(arg);
180+
if (numDays <= 0) {
181+
LOGGER.atError("Number of days must be greater than 0: " + arg);
182+
return -1;
183+
} else if (numDays >= 128) {
184+
LOGGER.atError("Number of days must be less than 128: " + arg);
185+
return -1;
186+
}
187+
else return (byte) numDays;
178188
} catch (NumberFormatException e) {
179-
LOGGER.atError("Invalid number of days: " + arg);
189+
LOGGER.atError("Invalid number of days: \"" + arg + "\" - must be a positive integer < 128");
180190
return -1;
181191
}
182192
}
183193

184-
private Set<Short> readDays(String arg) {
185-
Set<Short> days = new HashSet<>();
194+
private Set<Byte> readDays(String arg) {
195+
Set<Byte> days = new HashSet<>();
186196
String[] dayStrings = arg.split(",");
187197
for (String dayString : dayStrings) {
188198
try {
189-
short day = Short.parseShort(dayString);
199+
byte day = Byte.parseByte(dayString);
190200
days.add(day);
191201
} catch (NumberFormatException e) {
192202
LOGGER.atError("Invalid day: " + dayString);
@@ -228,7 +238,7 @@ private Mode getModeFromArgument(String arg) {
228238

229239
private void checkReplicateNumber(String[] args, int i) {
230240
try {
231-
int numberOfReplicates = Short.parseShort(args[i + 1]);
241+
long numberOfReplicates = Long.parseLong(args[i + 1]);
232242
if (numberOfReplicates <= 0) {
233243
throw new InvalidReplicateNumberException(LESS_THAN_ZERO);
234244
} else if (numberOfReplicates > 100) {
@@ -349,7 +359,7 @@ public File getInputFile() {
349359
return inputFile;
350360
}
351361

352-
public short getReplicateNumber() {
362+
public byte getReplicateNumber() {
353363
return replicateNumber;
354364
}
355365

@@ -374,9 +384,11 @@ public SortOption getOutputSorting() {
374384

375385
public Set<Strain> getStrains() { return strains; }
376386

377-
public Set<Short> getDays() { return days; }
387+
public Set<Byte> getDays() { return days; }
378388

379-
public short getNumDays() { return numDays; }
389+
public byte getNumDays() { return numDays; }
380390

381391
public Boolean getIncludeBaselineColumn() { return includeBaselineColumn; }
392+
393+
public SampleLabelingType getSampleLabelingType() { return sampleLabelingType; }
382394
}

src/main/java/org/awdevelopment/smithlab/config/Config.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ public class Config {
1616
private final ConfigEntry<OutputType> outputType;
1717
private final ConfigEntry<Boolean> writeToDifferentFile;
1818
private final ConfigEntry<SortOption> sortOption;
19-
private final ConfigEntry<Short> numberOfReplicates;
19+
private final ConfigEntry<Byte> numberOfReplicates;
2020
private final ConfigEntry<String> emptyInputSheetName;
2121
private final ConfigEntry<Boolean> GUI;
2222
private final ConfigEntry<Set<Condition>> conditions;
2323
private final ConfigEntry<Set<Strain>> strains;
24-
private final ConfigEntry<Set<Short>> days;
25-
private final ConfigEntry<Short> numDays;
24+
private final ConfigEntry<Set<Byte>> days;
25+
private final ConfigEntry<Byte> numDays;
2626
private final ConfigEntry<Boolean> includeBaselineColumn;
27+
private final ConfigEntry<SampleLabelingType> sampleLabelingType;
2728

2829
public Config() {
2930
this.numberOfReplicates = new ConfigEntry<>(ConfigOption.NUMBER_OF_REPLICATES, ConfigDefault.NUMBER_OF_REPLICATES);
@@ -40,6 +41,7 @@ public Config() {
4041
this.days = new ConfigEntry<>(ConfigOption.DAYS, ConfigDefault.DAYS);
4142
this.numDays = new ConfigEntry<>(ConfigOption.NUM_DAYS, ConfigDefault.NUM_DAYS);
4243
this.includeBaselineColumn = new ConfigEntry<>(ConfigOption.INCLUDE_BASELINE_COLUMN, ConfigDefault.INCLUDE_BASELINE_COLUMN);
44+
this.sampleLabelingType = new ConfigEntry<>(ConfigOption.SAMPLE_LABELING_TYPE, ConfigDefault.SAMPLE_LABELING_TYPE);
4345
}
4446

4547
public Config(Arguments arguments) {
@@ -57,6 +59,7 @@ public Config(Arguments arguments) {
5759
this.days = new ConfigEntry<>(ConfigOption.DAYS, arguments.getDays());
5860
this.numDays = new ConfigEntry<>(ConfigOption.NUM_DAYS, arguments.getNumDays());
5961
this.includeBaselineColumn = new ConfigEntry<>(ConfigOption.INCLUDE_BASELINE_COLUMN, arguments.getIncludeBaselineColumn());
62+
this.sampleLabelingType = new ConfigEntry<>(ConfigOption.SAMPLE_LABELING_TYPE, arguments.getSampleLabelingType());
6063
}
6164

6265
public File inputFile() {
@@ -79,7 +82,7 @@ public boolean writeToDifferentFile() {
7982
return writeToDifferentFile.value();
8083
}
8184

82-
public short numReplicates() { return numberOfReplicates.value(); }
85+
public byte numReplicates() { return numberOfReplicates.value(); }
8386

8487
public SortOption sortOption() { return sortOption.value(); }
8588

@@ -91,12 +94,14 @@ public boolean writeToDifferentFile() {
9194

9295
public Set<Strain> strains() { return strains.value(); }
9396

94-
public Set<Short> days() { return days.value(); }
97+
public Set<Byte> days() { return days.value(); }
9598

96-
public short numDays() { return numDays.value(); }
99+
public byte numDays() { return numDays.value(); }
97100

98101
public boolean includeBaselineColumn() { return includeBaselineColumn.value(); }
99102

103+
public SampleLabelingType sampleLabelingType() { return sampleLabelingType.value(); }
104+
100105
public void setOutputType(OutputType outputType) { this.outputType.setValue(outputType); }
101106

102107
public void setInputFile(File inputFile) { this.inputFile.setValue(inputFile); }
@@ -107,7 +112,7 @@ public boolean writeToDifferentFile() {
107112

108113
public void setWriteToDifferentFile(boolean writeToDifferentFile) { this.writeToDifferentFile.setValue(writeToDifferentFile); }
109114

110-
public void setNumberOfReplicates(short numberOfReplicates) { this.numberOfReplicates.setValue(numberOfReplicates); }
115+
public void setNumberOfReplicates(byte numberOfReplicates) { this.numberOfReplicates.setValue(numberOfReplicates); }
111116

112117
public void setSortOption(SortOption sortOption) { this.sortOption.setValue(sortOption); }
113118

@@ -121,11 +126,13 @@ public boolean writeToDifferentFile() {
121126

122127
public void addStrain(Strain strain) { this.strains.value().add(strain); }
123128

124-
public void addDay(short day) { this.days.value().add(day); }
129+
public void addDay(byte day) { this.days.value().add(day); }
125130

126-
public void setDays(Set<Short> days) { this.days.setValue(days); }
131+
public void setDays(Set<Byte> days) { this.days.setValue(days); }
127132

128-
public void setNumDays(short numDays) { this.numDays.setValue(numDays); }
133+
public void setNumDays(byte numDays) { this.numDays.setValue(numDays); }
129134

130135
public void setIncludeBaselineColumn(boolean includeBaselineColumn) { this.includeBaselineColumn.setValue(includeBaselineColumn); }
136+
137+
public void setSampleLabelingType(SampleLabelingType sampleLabelingType) { this.sampleLabelingType.setValue(sampleLabelingType); }
131138
}

src/main/java/org/awdevelopment/smithlab/config/ConfigDefault.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010

1111
public class ConfigDefault {
1212

13-
public static final Short NUM_DAYS = 0;
13+
public static final byte NUM_DAYS = 0;
1414
private static final String DEFAULT_FILENAME = "Spreadsheet Formatter Output.xlsx";
1515
public static final OutputType OUTPUT_TYPE = OutputType.BOTH;
1616
public static final String OUTPUT_FILENAME = DEFAULT_FILENAME;
1717
public static final Mode MODE = Mode.GENERATE_OUTPUT_SHEETS;
1818
public static final boolean WRITE_TO_DIFFERENT_FILE = true;
1919
public static final SortOption SORT_OPTION = SortOption.SAMPLE_NUMBER;
2020
public static final File INPUT_FILE = null;
21-
public static final short NUMBER_OF_REPLICATES = 4;
21+
public static final byte NUMBER_OF_REPLICATES = 4;
2222
public static final String EMPTY_INPUT_SHEET_NAME = DEFAULT_FILENAME;
2323
public static final Set<Condition> CONDITIONS = new HashSet<>();
2424
public static final Set<Strain> STRAINS = new HashSet<>();
25-
public static final Set<Short> DAYS = new HashSet<>();
25+
public static final Set<Byte> DAYS = new HashSet<>();
2626
public static final boolean INCLUDE_BASELINE_COLUMN = true;
27+
public static final SampleLabelingType SAMPLE_LABELING_TYPE = SampleLabelingType.CONDITION;
2728

2829
}

src/main/java/org/awdevelopment/smithlab/config/ConfigOption.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ public enum ConfigOption {
1515
STRAINS,
1616
DAYS,
1717
NUM_DAYS,
18-
INCLUDE_BASELINE_COLUMN;
18+
INCLUDE_BASELINE_COLUMN,
19+
SAMPLE_LABELING_TYPE;
1920
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.awdevelopment.smithlab.config;
2+
3+
public enum SampleLabelingType {
4+
CONDITION,
5+
STRAIN,
6+
CONDITION_AND_STRAIN;
7+
}

src/main/java/org/awdevelopment/smithlab/data/experiment/EmptyExperiment.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@
88

99
public class EmptyExperiment extends AbstractExperiment {
1010

11-
private final short numReplicates;
12-
private final short[] days;
13-
private final short numDays;
11+
private final byte numReplicates;
12+
private final byte[] days;
13+
private final byte numDays;
1414
private final boolean usingNumDays;
1515

16-
public EmptyExperiment(Set<Strain> strains, Set<Condition> conditions, short numReplicates, short[] days, short numDays) throws NoDaysException {
16+
public EmptyExperiment(Set<Strain> strains, Set<Condition> conditions, byte numReplicates, byte[] days, byte numDays) throws NoDaysException {
1717
super(conditions, strains);
1818
this.numReplicates = numReplicates;
1919
if (numDays <= 0 && days.length == 0) throw new NoDaysException();
2020
else {
2121
usingNumDays = numDays > 0;
2222
if (usingNumDays) {
23-
this.days = new short[numDays];
23+
this.days = new byte[numDays];
2424
this.numDays = numDays;
2525
} else {
2626
this.days = days;
27-
this.numDays = (short) days.length;
27+
this.numDays = (byte) days.length;
2828
}
2929
}
3030
}
3131

32-
public short getNumReplicates() { return numReplicates; }
32+
public byte getNumReplicates() { return numReplicates; }
3333
public boolean hasNoDays() { return days.length == 0 && !usingNumDays; }
34-
public short[] getDays() { return days; }
35-
public short getNumDays() { return numDays; }
34+
public byte[] getDays() { return days; }
35+
public byte getNumDays() { return numDays; }
3636
public boolean usingNumDays() { return usingNumDays; }
3737
}

src/main/java/org/awdevelopment/smithlab/gui/FXMLResourceType.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,13 @@ private static String getPath(FXMLResourceType fxmlResource) {
1414
case TIMEPOINTS -> "/fxml/timepoints.fxml";
1515
};
1616
}
17+
18+
public String getWindowTitle() {
19+
return switch (this) {
20+
case APPLICATION -> "Smith Lab Data Entry Automator";
21+
case CONDITIONS -> "Conditions";
22+
case STRAINS -> "Strains";
23+
case TIMEPOINTS -> "Timepoints";
24+
};
25+
}
1726
}
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
package org.awdevelopment.smithlab.gui;
22

33
import javafx.stage.Stage;
4+
import org.awdevelopment.smithlab.config.Config;
5+
import org.awdevelopment.smithlab.gui.controllers.AbstractLabelController;
46
import org.awdevelopment.smithlab.logging.LoggerHelper;
57

68
public class SceneLoader {
79

8-
private static final String STAGE_TITLE = "Smith Lab Data Entry Automator";
9-
1010
public static void loadScene(Stage stage, FXMLResourceType fxmlResourceType, LoggerHelper logger) {
1111
FXMLResource fxmlResource = FXMLResourceLoader.load(fxmlResourceType, logger);
1212
fxmlResource.controller().setLogger(logger);
13-
stage.setTitle(STAGE_TITLE);
13+
stage.setTitle(fxmlResourceType.getWindowTitle());
14+
stage.setScene(fxmlResource.scene());
15+
stage.show();
16+
}
17+
18+
public static AbstractLabelController loadScene(Stage stage, FXMLResourceType fxmlResourceType, LoggerHelper logger, Config config) {
19+
FXMLResource fxmlResource = FXMLResourceLoader.load(fxmlResourceType, logger);
20+
fxmlResource.controller().setLogger(logger);
21+
((AbstractLabelController) fxmlResource.controller()).setConfig(config);
22+
stage.setTitle(fxmlResourceType.getWindowTitle());
1423
stage.setScene(fxmlResource.scene());
1524
stage.show();
25+
return (AbstractLabelController) fxmlResource.controller();
1626
}
1727
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.awdevelopment.smithlab.gui.controllers;
2+
3+
import org.awdevelopment.smithlab.config.Config;
4+
5+
public class AbstractLabelController extends AbstractController {
6+
7+
private Config config;
8+
9+
public AbstractLabelController() { super(); }
10+
11+
public void setConfig(Config config) {
12+
this.config = config;
13+
}
14+
15+
public Config config() {
16+
return config;
17+
}
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.awdevelopment.smithlab.gui.controllers;
2+
3+
public class ConditionsController extends AbstractLabelController {
4+
public ConditionsController() { super(); }
5+
}

0 commit comments

Comments
 (0)