(updated April 2000)
If you want to write your own module, probably most important is to examine some example module code. It is true that you can create a module by subclassing Mesquite module 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, boolean scripting, boolean hiredByName) {
nt= new MesquiteNumber();
return true;
}
/**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, boolean scripting) {
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 getBriefParameters() {
return "Number of taxa in tree";
}
/**Returns an explanation of what the module does.*/
/* Overrides method of MesquiteModule */
public String getName() {
return "Number of Taxa";
}
/**Returns an explanation of what the module does.*/
/* Overrides method of MesquiteModule */
public String getVersion() {
return "0.9";
}
/**Returns an explanation of what the module does.*/
/* Overrides method of MesquiteModule */
public String getExplanation() {
return "Counts the number of taxa in a tree." ;
}
}