Skip to content

Commit

Permalink
add -includeEvery option to LogCombiner #84
Browse files Browse the repository at this point in the history
  • Loading branch information
rbouckaert committed Jul 14, 2024
1 parent 095aca7 commit 4cabf06
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
41 changes: 27 additions & 14 deletions src/beastfx/app/tools/LogCombiner.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class LogCombiner extends LogAnalyser {
DecimalFormat format = new DecimalFormat("#.############E0", new DecimalFormatSymbols(Locale.US));

// resample the log files to this frequency (the original sampling frequency must be a factor of this value)
int m_nResample = -1;
int m_nResample = -1, includeEvery = -1;

private void parseArgs(String[] args) {
int i = 0;
Expand Down Expand Up @@ -85,6 +85,9 @@ private void parseArgs(String[] args) {
} else if (args[i].equals("-resample")) {
m_nResample = Integer.parseInt(args[i + 1]);
i += 2;
} else if (args[i].equals("-includeEvery")) {
includeEvery = Integer.parseInt(args[i + 1]);
i += 2;
} else if (args[i].equals("-renumber")) {
m_nSampleInterval = 1;
i++;
Expand All @@ -94,6 +97,9 @@ private void parseArgs(String[] args) {
}
}
}
if (m_nResample > 0 && includeEvery > 0) {
throw new IllegalArgumentException("Only one of -resample and -includeEvery may be specified, not both");
}
} catch (IllegalArgumentException e) {
throw e;
} catch (Exception e) {
Expand Down Expand Up @@ -181,10 +187,13 @@ protected long readLogFile(String fileName, int burnInPercentage, long state) th
long logState = Long.parseLong(strs[0]);
if (m_nSampleInterval < 0 && prevLogState >= 0) {
// need to renumber
if (m_nResample < 0) {
if (m_nResample < 0 && includeEvery <= 0) {
m_nSampleInterval = (int) (logState - prevLogState);
} else {
} else if (m_nResample >= 0){
m_nSampleInterval = m_nResample;
} else { // includeEvery > 0
m_nSampleInterval = includeEvery * (int) (logState - prevLogState);
m_nResample = m_nSampleInterval;
}
}
prevLogState = logState;
Expand Down Expand Up @@ -303,10 +312,13 @@ protected long readTreeLogFile(String fileName, int burnInPercentage, long state
long logState = Long.parseLong(str2);
if (m_nSampleInterval < 0 && prevLogState >= 0) {
// need to renumber
if (m_nResample < 0) {
if (m_nResample < 0 && includeEvery <= 0) {
m_nSampleInterval = (int) (logState - prevLogState);
} else {
} else if (m_nResample >= 0){
m_nSampleInterval = m_nResample;
} else { // includeEvery > 0
m_nSampleInterval = includeEvery * (int) (logState - prevLogState);
m_nResample = m_nSampleInterval;
}
}
prevLogState = logState;
Expand Down Expand Up @@ -479,15 +491,16 @@ private static String getUsage() {
return "Usage: LogCombiner -log <file> -n <int> [<options>]\n" +
"combines multiple (trace or tree) log files into a single log file.\n" +
"options:\n" +
"-log <file> specify the name of the log file, each log file must be specified with separate -log option\n" +
"-o <output.log> specify log file to write into (default output is stdout)\n" +
"-b <burnin> specify the number PERCENTAGE of lines in the log file considered to be burnin (default 10)\n" +
"-dir <directory> specify particle directory -- used for particle filtering in BEASTLabs only -- if defined only one log must be specified and the -n option specified\n" +
"-n <int> specify the number of particles, ignored if -dir is not defined\n" +
"-resample <int> specify number of states to resample\n" +
"-decimal flag to indicate numbers should converted from scientific into decimal format\n" +
"-renumber flag to indicate output states should be renumbered\n" +
"-help print this message\n";
"-log <file> specify the name of the log file, each log file must be specified with separate -log option\n" +
"-o <output.log> specify log file to write into (default output is stdout)\n" +
"-b <burnin> specify the number PERCENTAGE of lines in the log file considered to be burnin (default 10)\n" +
"-dir <directory> specify particle directory -- used for particle filtering in BEASTLabs only -- if defined only one log must be specified and the -n option specified\n" +
"-n <int> specify the number of particles, ignored if -dir is not defined\n" +
"-resample <int> specify number of states to resample (only use when not using `includeEvery`)\n" +
"-includeEvery <int> specify number of states to be include (only use when not using `resample`)\n" +
"-decimal flag to indicate numbers should converted from scientific into decimal format\n" +
"-renumber flag to indicate output states should be renumbered\n" +
"-help print this message\n";
}

private void printTitle(String aboutString) {
Expand Down
23 changes: 17 additions & 6 deletions src/beastfx/app/tools/LogCombinerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


import beast.base.core.ProgramStatus;
import beastfx.app.util.Alert;
import beastfx.app.util.FXUtils;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
Expand Down Expand Up @@ -48,8 +49,11 @@ public class LogCombinerController implements Initializable {
@FXML
public CheckBox renumberOutput;

//@FXML
//public CheckBox resampleCheck;

@FXML
public CheckBox resampleCheck;
public ComboBox<String> resampleCombo;

@FXML
public TextField resampleText;
Expand Down Expand Up @@ -92,8 +96,10 @@ public void initialize(URL location, ResourceBundle resources) {


resampleText.setDisable(true);
resampleCheck.setOnAction(e -> {
resampleText.setDisable(!resampleCheck.isSelected());
resampleCombo.setItems(FXCollections.observableArrayList(new String[] {"No resampling", "Resample states at lower frequency", "Include every"}));
resampleCombo.getSelectionModel().select(0);
resampleCombo.setOnAction(e -> {
resampleText.setDisable(resampleCombo.getSelectionModel().getSelectedIndex() == 0);
});

addButton.setOnAction(e-> {
Expand Down Expand Up @@ -251,12 +257,17 @@ public boolean renumberOutputStates() {
return renumberOutput.isSelected();
}

public boolean isResampling() {
return resampleCheck.isSelected();
public int resampleComboState() {
return resampleCombo.getSelectionModel().getSelectedIndex();
}

public int getResampleFrequency() {
return Integer.parseInt(resampleText.getText());
try {
return Integer.parseInt(resampleText.getText());
} catch (NumberFormatException e) {
Alert.showMessageDialog(null, "Could not read the number in the resample field: " + e.getMessage());
throw new RuntimeException(e);
}
}

public String getOutputFileName() {
Expand Down
7 changes: 6 additions & 1 deletion src/beastfx/app/tools/LogCombinerDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,13 @@ protected void createDialog() {
if (!controller.renumberOutputStates()) {
combiner.m_nSampleInterval = -1;
}
if (controller.isResampling()) {
switch (controller.resampleComboState()) {
case 1:
combiner.m_nResample = controller.getResampleFrequency();
break;
case 2:
combiner.includeEvery = controller.getResampleFrequency();
break;
}

String[] inputFiles = controller.getFileNames();
Expand Down
4 changes: 4 additions & 0 deletions src/beastfx/app/tools/logcombiner.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
<ComboBox fx:id="fileTypeCombo" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<CheckBox fx:id="decimalCheck" mnemonicParsing="false" text="Convert numbers from scientific to decimal notation" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<CheckBox fx:id="renumberOutput" mnemonicParsing="false" text="Renumber output states" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label fx:id="resampleLabel" text="Resample strategy:" GridPane.columnIndex="0" GridPane.rowIndex="5" />
<ComboBox fx:id="resampleCombo" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<!--
<CheckBox fx:id="resampleCheck" mnemonicParsing="false" text="Resample states at lower frequency:" GridPane.columnIndex="1" GridPane.rowIndex="5" />
-->
<TextField fx:id="resampleText" GridPane.columnIndex="2" GridPane.rowIndex="5" />
<Label text="Select input files:" GridPane.rowIndex="6" />
<TableView fx:id="filesTable" prefHeight="800.0" prefWidth="600.0" GridPane.columnSpan="3" GridPane.rowIndex="7">
Expand Down

0 comments on commit 4cabf06

Please sign in to comment.