When is it Reasonable to Reuse a Name?
November 03, 2009
tool.Blast != pipeline.tool.Blast
In our bio-informatics pipeline, we have a lot of pipeline steps that
run external tools, such as Blast (Basic Local Alignment Search
Tool). We have a very nice template for doing this.
We have a Runner step that writes out the files for the tool and then
constructs a command string which is run in a shell. It is followed by
a Parser step that reads in the tool's output file and creates
alignment objects, which are passed down to the Featurizer step, which
turns them into Hibernate objects for persistance in the database.
We generally encapsulate these three steps in a sub-pipeline, kinda
like this:
package pipeline.tool;
class Blast extends Pipeline {
public void start() {
subpipeline.add(new Runner());
subpipeline.add(new Parser());
subpipeline.add(new Featurizer());
}
Something that a lot of my peers do is to use the same name for the
tool as they do for the pipeline step.
class Runner extends PipelineStep {
tool.Blast tool;
public void process(Input input) {
File p = FastaWriter.writeSequences(input.getProteinSequences());
File g = FastaWriter.writeSequences(input.getGenomeSequences());
tool = new tool.Blast(p, g);
File output = tool.run();
callback.call(output);
}
}
and the tool looks something like this:
package tool;
class Blast extends Tool {
...
public File run() {
File output = File.createTempFile();
String command = "/home/tools/blast -i " + p + " -d " + g + " o "+ output;
runCommand(command);
return output;
}
}
The upshot of this is that we have two classes, both named Blast, a
tool, tool.Blast and a pipeline step, pipeline.tool.Blast.
The good thing about this is that we always get a short, succicent,
and meaningful name. The bad part is that when the classes are large,
it is easy to get lost in the middle and you're not entirely certain
which class you're looking at.
Now I, as you can probably guess, eschew such abbreviations and use
more expressive (and longer) names. I'd name these BlastTool and
BlastStep.
How do you view this?
Has this ever been a problem for you? Or has it made programming
easier?
-Bil