System.out.println("Error: No output file specified"); //$NON-NLS-1$
return;
}
try {
ProbeMakerPlugIn pm = new ProbeMakerPlugIn();
ErrorHandler callback = new CommandLineErrorCallback();
//Check for and load the settings file
File settingsFile = new File(args[1]);
if (!settingsFile.exists()) {
System.out.println("Error: Could not find settings file: " + args[1]); //$NON-NLS-1$
return;
}
//Check for and load the target file
File targetFile = new File(args[2]);
if (!targetFile.exists()) {
System.out.println("Error: Could not find target file: " + args[2]); //$NON-NLS-1$
return;
}
//Check for and load the target file
File outputFile = new File(args[3]);
System.out.println("Reading settings"); //$NON-NLS-1$
Properties props = new Properties();
props.load(new FileInputStream(settingsFile));
Map<String, String> vars = new HashMap<String, String>();
for (Object key : props.keySet()) {
String keyString = (String) key;
if (keyString.startsWith("$")) {
vars.put(keyString.substring(1), props.get(key).toString());
}
}
Map<String,String> transformedProps = new HashMap<String, String>();
final String prefix = "probemaker.design.";
Pattern pattern = Pattern.compile("\\$\\{(.*?)\\}");
for (Iterator<?> i = props.keySet().iterator();i.hasNext();) {
String key = (String) i.next();
if (key.startsWith(prefix)) {
String shortKey = key.substring(prefix.length());
String valueString = (String) props.get(key);
Matcher m = pattern.matcher(valueString);
String parsed = valueString;
while (m.find()) {
String varName = m.group(1);
String variableValue = vars.get(varName);
parsed = parsed.replace("${"+varName+"}", variableValue);
}
transformedProps.put(shortKey, parsed);
}
}
Settings s = new Settings();
s.addDesignerProperties(transformedProps);
System.out.println("Done"); //$NON-NLS-1$
System.out.println("Creating project"); //$NON-NLS-1$
Project p = new Project("Unnamed",s); //$NON-NLS-1$
pm.setProject(p);
String accClassName = props.getProperty("probemaker.acceptor");
String selClassName = props.getProperty("probemaker.selector");
String formatClassName = props.getProperty("probemaker.targetInputFormat");
String outputClassName = props.getProperty("probemaker.probeOutputFormat");
String targetClassName = props.getProperty("probemaker.targetType");
if (accClassName == null) {
System.out.println("No acceptor specified"); //$NON-NLS-1$
return;
}
if (selClassName == null) {
System.out.println("No selector specified"); //$NON-NLS-1$
return;
}
if (formatClassName == null) {
System.out.println("No input format specified"); //$NON-NLS-1$
return;
}
ProbeAcceptor acceptor = (ProbeAcceptor) Class.forName(accClassName).newInstance();
//Check if acceptor requires parameters
if (acceptor instanceof ParameterPlugIn) {
ParameterPlugIn paAcceptor = (ParameterPlugIn) acceptor;
DataDescriptor[] dds = paAcceptor.getDataDescriptors();
if (dds != null) {
for (int d = 0;d<dds.length;d++) {
DataDescriptor dd = dds[d];
String string = props.getProperty("probemaker.acceptor." + dd.getKey());
paAcceptor.setData(dd.getKey(), string);
}
}
}
System.out.println(" Acceptor is: " + acceptor.getClass().getName()); //$NON-NLS-1$
ProbeSelector selector = (ProbeSelector) Class.forName(selClassName).newInstance();
if (selector instanceof ParameterPlugIn) {
ParameterPlugIn paSelector = (ParameterPlugIn) selector;
DataDescriptor[] dds = paSelector.getDataDescriptors();
if (dds != null) {
for (int d = 0;d<dds.length;d++) {
DataDescriptor dd = dds[d];
String string = props.getProperty("probemaker.selector." + dd.getKey());
paSelector.setData(dd.getKey(), string);
}
}
}
System.out.println(" Selector is: " + selector.getClass().getName()); //$NON-NLS-1$
SequenceDBDataReader format = (SequenceDBDataReader) Class.forName(formatClassName).newInstance();
if (format instanceof ParameterPlugIn) {
ParameterPlugIn paFormat = (ParameterPlugIn) selector;
DataDescriptor[] dds = paFormat.getDataDescriptors();
if (dds != null) {
for (int d = 0;d<dds.length;d++) {
DataDescriptor dd = dds[d];
String string = props.getProperty("probemaker.targetInputFormat." + dd.getKey());
paFormat.setData(dd.getKey(), string);
}
}
}
if (outputClassName == null) {
outputClassName = DefaultTextTableFormatter.class.getName();
}
Class<?> outputClass = Class.forName(outputClassName);
TextTableFormatter<Probe> outputformatter = (TextTableFormatter<Probe>) outputClass.newInstance();
if (targetClassName == null) {
System.err.println("ERROR: Must specify a probemaker.targetType"); //$NON-NLS-1$
return;
}
Class<?> targetClass = Class.forName(targetClassName);
SequenceBuilder<? extends ProbeMakerTarget> seqBuilder = (SequenceBuilder<? extends ProbeMakerTarget>) targetClass.getMethod("getSequenceBuilder",(Class[])null).invoke(null,(Object[]) null); //$NON-NLS-1$
System.out.println(" Format is: " + format.getClass().getName()); //$NON-NLS-1$
System.out.println(" Target type is: " + targetClass.getName()); //$NON-NLS-1$
System.out.println(" Output format is: " + outputClass.getName()); //$NON-NLS-1$
TargetInputFormat<? extends ProbeMakerTarget> tif = new DefaultTargetInputFormat("Input format",format,null,seqBuilder,ListSequenceDB.getDefaultBuilder()); //$NON-NLS-1$
System.out.println(" Loading tag libs"); //$NON-NLS-1$
int ti = 0;
List<TagLibrary> libs = new ArrayList<TagLibrary>();
while (props.containsKey("probemaker.taglibrary."+ti)) {
String taglibString = props.getProperty("probemaker.taglibrary."+ti);
String[] split = taglibString.split(":");
byte mode = Byte.parseByte(split[0]);
String libFileName = split[1];
File libFile = new File(libFileName);
if (!libFile.getAbsolutePath().equals(libFile.getPath())) {
libFile = new File(settingsFile.getAbsoluteFile().getParentFile(),libFile.getPath());
}
DefiniteSequenceDB<NucleotideSequence> tagseqs = SequenceIO.readSequenceDB(new FileReader(libFile), new FastaDBFormat<NucleotideSequence>(), null, ListSequenceDB.getDefaultBuilder(),new SimpleDNASequenceBuilder());
TagLibrary lib = new DefaultTagLibrary(tagseqs,"taglib"+ti); //$NON-NLS-1$
lib.setMode(mode);
libs.add(lib);
ti++;
}
TagLibrary[] libraries = libs.toArray(new TagLibrary[libs.size()]);
int[] order = new int[libraries.length];
for (int i = 0;i<order.length;i++) order[i] = i;
TagSettings tagSettings = new DefaultTagSettings(libraries,order);
p.setTagSettings(tagSettings);
System.out.println(" Loading targets"); //$NON-NLS-1$
new TargetIOTask(p,callback,new Reader[] { new FileReader(targetFile) },tif).run();
System.out.println("Done"); //$NON-NLS-1$
File logPath = new File(""); //$NON-NLS-1$
System.out.println("Writing log to: " + logPath); //$NON-NLS-1$
//Probe design settings
boolean append = false;
//Create and start the ProbeDesignerRunner
TagAllocator ta = (TagAllocator) ProbeMakerPlugIn.defaultTagAllocatorClass.newInstance();
TSSConstructor tsc = (TSSConstructor) ProbeMakerPlugIn.defaultTSSConstructorClass.newInstance();
ta.addParameters(s.getDesignParameters());
tsc.addParameters(s.getDesignParameters());
ProbeDesigner pd = new DefaultProbeDesigner(ta);
TSSPairDesigner td = new DefaultTSSPairDesigner(tsc);
NamingScheme namer = new DefaultNamingScheme();
DesignLogWriter log = new TextDesignLogWriter(new FileWriter(new File(logPath, p.getName() + ".designlog")));
ProbeDesignTask runner = pm.getProbeDesignTask(append,false,log,namer,acceptor,selector,pd, td, callback);
runner.timing = true;
runner.verbose = true;
System.out.println("Starting design of " + runner.getMaxProgress() + " probe groups"); //$NON-NLS-1$ //$NON-NLS-2$
runner.run();
//Print result data
System.out.println("Design completed in " + runner.getTotalTime()/1000 + " seconds"); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println("Generated " + runner.getCandidatesGenerated() + " candidates"); //$NON-NLS-1$ //$NON-NLS-2$
DefiniteSequenceDB<Probe> db = pm.project.getProbes();
for (byte b = ProbeMakerConstants.GOOD_QUALITY;b>=ProbeMakerConstants.BAD_QUALITY;b--) {
System.out.println(ProbeSummarizer.getQualityCount(db,b) + " probes of " + //$NON-NLS-1$
ProbeMakerConstants.qualityStrings[b] + " quality"); //$NON-NLS-1$
}
SequenceIO.writeSequenceDB(new FileWriter(outputFile),pm.project.getProbes(),new TextTableDBFormat<Probe>(outputformatter),null);
}
catch (Exception e) {
System.err.println("An exception was caught:\n" + e.getMessage()); //$NON-NLS-1$
e.printStackTrace();
}
catch (Error er) {
System.err.println("An error was caught:\n" + er.getMessage()); //$NON-NLS-1$
er.printStackTrace();
}
}
else if (args[0].equals("-p")) { //$NON-NLS-1$
System.out.println("Running ProbeMaker with project file"); //$NON-NLS-1$
if (args.length < 2) {
System.out.println("Error: No project file specified"); //$NON-NLS-1$
return;
}
try {
ProbeMakerPlugIn pm = new ProbeMakerPlugIn();
ErrorHandler callback = new CommandLineErrorCallback();
//Check for and load the project file
File projectFile = new File(args[1]);
if (!projectFile.exists()) {
System.out.println("Error: Could not find project file: " + args[1]); //$NON-NLS-1$