Skip to content

Commit

Permalink
working on generating documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuson committed Mar 12, 2024
1 parent bbd5312 commit 6ba53e7
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 200 deletions.
6 changes: 3 additions & 3 deletions src/main/java/splitstree6/io/nexus/GenomesNexusInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public class GenomesNexusInput extends NexusIOBase implements INexusInput<Genome
[FILES={YES|NO}]
;]
MATRIX
[label] [accession] length {sequence | [#parts] length {sequence|{file:.. offset}} .. length {sequence|{file offset}}},
...
[label] [accession] length {sequence | [#parts] length {sequence|{file:.. offset}} .. length {sequence|{file offset}}}
[label] [accession] length {sequence | [#parts] length {sequence|{file:.. offset}} .. length {sequence|{file offset}}},
...
[label] [accession] length {sequence | [#parts] length {sequence|{file:.. offset}} .. length {sequence|{file offset}}}
;]
END;
""";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/splitstree6/io/nexus/TaxaNexusInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public class TaxaNexusInput extends NexusIOBase {

public static final String DESCRIPTION = """
This block maintains the list of all taxa in the analysis.
There is a fixed number (nTax) of taxa and each has an id 1..nTax and label associated with it.
There is a fixed number (nTax) of taxa and each has an id 1..nTax and an unique label.
Optionally, an info string can be provided for each taxon.
Optionally, a display label can be provided for each taxon. This many include certain HTML tags
Also, a display label may be provided for each taxon. This can include certain HTML tags
that are used to render the label.
""";

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/splitstree6/io/nexus/TraitsNexusInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public class TraitsNexusInput extends NexusIOBase implements INexusInput<TraitsB
END;
""";

public static final String DESCRIPTION = """
This block contains traits associated with the input taxa. Each trait has a label,
optional latitude and longitude, and a value, which can either be a number or a string.
""";

public String getSyntax() {
return SYNTAX;
}
Expand Down Expand Up @@ -101,13 +106,13 @@ public List<String> parse(NexusStreamParser np, TaxaBlock taxaBlock, TraitsBlock
throw new IOExceptionWithLineNumber("Format 'no labels' invalid because no taxLabels given in TAXA block", np.lineno());

final var separator = np.findIgnoreCase(formatTokens, "separator=", StringUtils.toString(TraitsNexusFormat.Separator.values(), " "), "");
if (separator.length() > 0) {
if (!separator.isEmpty()) {
format.setOptionSeparator(separator);
}

format.setOptionMissingCharacter(Character.toLowerCase(np.findIgnoreCase(formatTokens, "missing=", null, '?')));

if (formatTokens.size() != 0)
if (!formatTokens.isEmpty())
throw new IOExceptionWithLineNumber("Unexpected in FORMAT: '" + StringUtils.toString(formatTokens, " ") + "'", np.lineno());
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/splitstree6/io/readers/ImportManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import jloda.util.Basic;
import splitstree6.data.SplitsBlock;
import splitstree6.data.TreesBlock;
import splitstree6.io.readers.characters.StockholmReader;
import splitstree6.io.utils.DataReaderBase;
import splitstree6.io.utils.IDataReaderNoAutoDetect;
import splitstree6.workflow.DataBlock;
Expand All @@ -45,7 +46,7 @@ public synchronized static ImportManager getInstance() {
private ImportManager() {
readers.add(new splitstree6.io.readers.characters.FastAReader());
readers.add(new splitstree6.io.readers.characters.MSFReader());
readers.add(new splitstree6.io.readers.characters.StockholmImporter());
readers.add(new StockholmReader());
readers.add(new splitstree6.io.readers.characters.NexusReader());
readers.add(new splitstree6.io.readers.characters.PhylipReader());
readers.add(new splitstree6.io.readers.distances.NexusReader());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* StockholmImporter.java Copyright (C) 2024 Daniel H. Huson
* StockholmReader.java Copyright (C) 2024 Daniel H. Huson
*
* (Some files contain contributions from other authors, who are then mentioned separately.)
*
Expand Down Expand Up @@ -32,9 +32,9 @@

import static splitstree6.io.readers.characters.FastAReader.checkIfCharactersValid;

public class StockholmImporter extends CharactersReader {
public class StockholmReader extends CharactersReader {

public StockholmImporter() {
public StockholmReader() {
setFileExtensions("stk", "sto", "stockholm");
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/splitstree6/main/SplitsTree6.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public static void main(String[] args) {
SplashScreen.setVersionString(ProgramProperties.getProgramVersion());
SplashScreen.setImageResourceName("SplitsTree6-splash.png");


try {
parseArguments(args);
} catch (Throwable th) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/splitstree6/window/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import jloda.fx.selection.SetSelectionModel;
import jloda.fx.util.MemoryUsage;
import jloda.fx.util.ProgramProperties;
import jloda.fx.util.RunAfterAWhile;
import jloda.fx.util.StatementFilter;
import jloda.fx.window.IMainWindow;
import jloda.fx.window.MainWindowManager;
Expand All @@ -53,6 +54,7 @@
import splitstree6.view.alignment.AlignmentView;
import splitstree6.workflow.Workflow;
import splitstree6.workflowtree.WorkflowTreeView;
import splitstree6.xtra.latex.MenusToLaTeX;

import java.io.IOException;
import java.util.Objects;
Expand Down Expand Up @@ -143,6 +145,11 @@ public MainWindow() {
name.set("Untitled");

presenter = new MainWindowPresenter(this);

if (true) {
var obj = new Object();
RunAfterAWhile.applyInFXThread(obj, () -> System.out.println(MenusToLaTeX.apply(controller.getMenuBar())));
}
}

@Override
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/splitstree6/window/MainWindowController.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ public class MainWindowController {
@FXML
private MenuItem gotoLineMenuItem;

@FXML
private MenuItem preferencesMenuItem;

@FXML
private MenuItem selectAllMenuItem;

Expand Down Expand Up @@ -752,10 +749,6 @@ public MenuItem getGotoLineMenuItem() {
return gotoLineMenuItem;
}

public MenuItem getPreferencesMenuItem() {
return preferencesMenuItem;
}

public MenuItem getSelectAllMenuItem() {
return selectAllMenuItem;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/splitstree6/window/MainWindowPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,6 @@ private void setupCommonMenuItems(MainWindow mainWindow, MainWindowController co

// controller.getGotoLineMenuItem().setOnAction(null);

controller.getPreferencesMenuItem().setOnAction(null);

controller.getSelectAllMenuItem().setOnAction(e -> mainWindow.getTaxonSelectionModel().selectAll(mainWindow.getWorkflow().getWorkingTaxaBlock().getTaxa()));
controller.getSelectAllMenuItem().disableProperty().bind(mainWindow.emptyProperty());

Expand Down
29 changes: 5 additions & 24 deletions src/main/java/splitstree6/xtra/latex/AlgorithmsToLaTeX.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,15 @@
import java.util.HashMap;
import java.util.List;

import static splitstree6.xtra.latex.IOToLaTeX.FOOTER;
import static splitstree6.xtra.latex.IOToLaTeX.HEADER;

/**
* outputs a LaTeX document containing a description of all algorithms
* Daniel Huson, 3.2024
*/
public class AlgorithmsToLaTeX {
public static void main(String[] args) {
var header = """
\\documentclass{article}
\\usepackage{graphicx}
\\usepackage{hyperref}
\\usepackage{fullpage}
\\usepackage{parskip}\s
\\title{SplitsTree Community Edition - Algorithms}
\\author{Daniel H. Huson and Dave Bryant}
\\date{March 2024}
\\begin{document}
\\maketitle
\\section{Algorithms}
""";

var footer = """
\\end{document}
""";
var ordering = List.of("Characters Block", "Distances Block", "Splits Block", "Trees Block", "Network Block", "View Block", "Report Block");

var fromLineMap = new HashMap<String, List<String>>();
Expand Down Expand Up @@ -107,7 +88,7 @@ public static void main(String[] args) {
}
}

System.out.println(header);
System.out.println(HEADER);

if (true) {
System.out.println("\\section{List of algorithms sorted by input}\n\n");
Expand All @@ -132,7 +113,7 @@ public static void main(String[] args) {
}
}
}
System.out.println(footer);
System.out.println(FOOTER);

}
}
54 changes: 54 additions & 0 deletions src/main/java/splitstree6/xtra/latex/BlocksToLaTeX.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* BlocksToLaTeX.java Copyright (C) 2024 Daniel H. Huson
*
* (Some files contain contributions from other authors, who are then mentioned separately.)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package splitstree6.xtra.latex;

import splitstree6.io.nexus.*;

import static splitstree6.xtra.latex.IOToLaTeX.FOOTER;
import static splitstree6.xtra.latex.IOToLaTeX.HEADER;

public class BlocksToLaTeX {
public static void main(String[] args) {

System.out.println(HEADER +
"\\section{Main data blocks and their `Nexus format' syntax}\n\n" +
output("Taxa block", TaxaNexusInput.DESCRIPTION, TaxaNexusInput.SYNTAX) +
output("Traits block", TraitsNexusInput.DESCRIPTION, TraitsNexusInput.SYNTAX) +
output("Characters block", CharactersNexusInput.DESCRIPTION, CharactersNexusInput.SYNTAX) +
output("Distances block", DistancesNexusInput.DESCRIPTION, DistancesNexusInput.SYNTAX) +
output("Trees block", TreesNexusInput.DESCRIPTION, TreesNexusInput.SYNTAX) +
output("Splits block", SplitsNexusInput.DESCRIPTION, SplitsNexusInput.SYNTAX) +
output("Network block", NetworkNexusInput.DESCRIPTION, NetworkNexusInput.SYNTAX) +
output("View block", ViewNexusInput.DESCRIPTION, ViewNexusInput.SYNTAX) +
output("Algorithms block", AlgorithmNexusInput.DESCRIPTION, AlgorithmNexusInput.SYNTAX) +
output("Report block", ReportNexusInput.DESCRIPTION, ReportNexusInput.SYNTAX) +
output("Sets block", SetsNexusInput.DESCRIPTION, SetsNexusInput.SYNTAX) +
output("SplitsTree6 block", SplitsTree6NexusInput.DESCRIPTION, SplitsTree6NexusInput.SYNTAX) +
output("Genomes block", GenomesNexusInput.DESCRIPTION, GenomesNexusInput.SYNTAX) +
FOOTER);
}

public static String output(String name, String description, String syntax) {
return "\\subsection{%s}\n%n%s%n".formatted(name, description.replaceAll("\t", " ")) +
"{\\footnotesize\\begin{verbatim}\n" +
syntax.replaceAll("\t", " ") +
"\\end{verbatim}}\n\n";
}
}
24 changes: 8 additions & 16 deletions src/main/java/splitstree6/xtra/latex/IOToLaTeX.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* NexusToLaTeX.java Copyright (C) 2024 Daniel H. Huson
* BlocksToLaTeX.java Copyright (C) 2024 Daniel H. Huson
*
* (Some files contain contributions from other authors, who are then mentioned separately.)
*
Expand Down Expand Up @@ -29,29 +29,21 @@
import java.lang.reflect.InvocationTargetException;

public class IOToLaTeX {
public static void main(String[] args) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
var header = """
public static final String HEADER = """
\\documentclass{article}
\\usepackage{graphicx}
\\usepackage{hyperref}
\\usepackage{fullpage}
\\usepackage{parskip}\s
\\title{SplitsTree Community Edition - Importers}
\\author{Daniel H. Huson and Dave Bryant}
\\date{March 2024}
\\begin{document}
\\maketitle
""";

var footer = """
\\end{document}
""";
public static final String FOOTER = "\n\\end{document}\n";

System.out.println(header);
public static void main(String[] args) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
System.out.println(HEADER);

System.out.println("\\section{Supported import formats}\n");

Expand All @@ -72,7 +64,7 @@ public static void main(String[] args) throws InvocationTargetException, NoSuchM
outputExporters(NetworkBlock.class) +
outputExporters(GenomesBlock.class));

System.out.println(footer);
System.out.println(FOOTER);
}

public static String outputImporters(Class<? extends DataBlock> clazz) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
Expand All @@ -96,7 +88,7 @@ public static String outputExporters(Class<? extends DataBlock> clazz) throws No
var exportManager = ExportManager.getInstance();
var formats = exportManager.getExporters(clazz).stream().map(ReaderWriterBase::getName).filter(n -> !n.equals("PlainText")).toList();

buf.append("Can import %s data in the following formats: %s.%n%n"
buf.append("Can export %s data in the following formats: %s.%n%n"
.formatted(blockName, StringUtils.toString(formats, ", ")));
return buf.toString();
}
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/splitstree6/xtra/latex/MenusToLaTeX.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* MenusToLaTeX.java Copyright (C) 2024 Daniel H. Huson
*
* (Some files contain contributions from other authors, who are then mentioned separately.)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package splitstree6.xtra.latex;

import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.SeparatorMenuItem;

/**
* write out all items in the menu bar in LaTeX
*/
public class MenusToLaTeX {
public static String apply(MenuBar menuBar) {
var buf = new StringBuilder("\\section{The main menu bar}\n\n");
for (var menu : menuBar.getMenus()) {
buf.append(applyRec(menu, 0));
}
return buf.toString();
}

public static String applyRec(Menu menu, int level) {
var buf = new StringBuilder();
if (level == 0) {
buf.append("\\subsection{The %s menu}%n%n%n".formatted(menu.getText()));
buf.append("This menu has the following items:\n\n");
} else {
buf.append("This %s-menu has the following items:\n\n".formatted("sub".repeat(level)));
}
buf.append("\\begin{itemize}\n");
for (var item : menu.getItems()) {
if (!(item instanceof SeparatorMenuItem)) {
if (item instanceof Menu subMenu) {
applyRec(subMenu, level + 1);
} else {
var text = item.getText();
if (item.getUserData() != null)
text += " - " + item.getUserData().toString();
buf.append("\\item %s%n".formatted(text));
}
}
}
buf.append("\\end{itemize}\n\n");
return buf.toString();
}
}
Loading

0 comments on commit 6ba53e7

Please sign in to comment.