(updated August 2005)
If you want to write your own module, probably most important is to examine some example module code. Find a module that does an analogous task, and base your module on that. It is true that you can create a module by subclassing MesquiteModule and overriding a few methods, but likely it won't do much useful. It will be particularly helpful to examine existing modules for examples of how to structure the doCommand and getSnapshot methods, but also for more specialized methods for particular duty classes.
These might be the steps in making a module.
Below is code for a small example module, one that returns the number of taxa in the tree. A more complex module showing a window is described here.
/** Note: the getNumber and getResultString methods will probably be soon eliminated from NumberForTree modules */ package mesquite.basic.NumberOfTaxa; import mesquite.lib.*; //Where most Mesquite library classes are defined import mesquite.lib.duties.*; //Where NumberForTree is defined /**A little module that can counts the number of terminal taxa in a tree. Usually not to useful, but serves to demonstrate NumberForTree modules*/ public class NumberOfTaxa extends NumberForTree { MesquiteNumber nt; /**The standard substitute for a constructor (NOTE: do not use constructors for Mesquite modules). This method is called when a module is hired and is to be started up. Basic initialization should happen here, just as in a constructor.*/ /* Overrides method of MesquiteModule */ public boolean startJob(String arguments, Object condition, CommandRecord commandRec, boolean hiredByName) { nt= new MesquiteNumber(); return true; } /**Required by NumberForTree; called in case module needs to initialize anything (e.g. querying user for details) before calculations start in earnest.*/ /* Overrides method of MesquiteModule */ public void initialize(Tree tree, CommandRecord commandRec)() { } /**The main calculating method for NumberForTree modules. The tree for which a number is to be calculated is passed as a parameter, as is a number wrapper class to receive the result. The boolean "scripting" indicates whether the request comes in the context of a script being executed.*/ public void calculateNumber(Tree tree, MesquiteNumber result, MesquiteNumber resultString, CommandRecord commandRec) { if (result==null) return; nt.setValue(tree.numberOfTerminalsInClade(tree.getRoot())); result.setValue(nt); if (resultString != null) resultString.setValue("Number of terminal taxa in tree: " + nt); } /**Returns an explanation of what the module does.*/ /* Overrides method of MesquiteModule */ public String getParameters() { return "Number of taxa in tree"; } /**Returns the name of the module.*/ /* Overrides method of MesquiteModule */ public String getName() { return "Number of Taxa"; } /**Returns the version of the module.*/ /* Overrides method of MesquiteModule */ public String getVersion() { return "1.0"; } /**Returns an explanation of what the module does.*/ /* Overrides method of MesquiteModule */ public String getExplanation() { return "Counts the number of taxa in a tree." ; } }