/** * * @author rli */ package oligo3; import java.io.File; import java.io.IOException; import java.util.Properties; public class Params { static int input_file_mode = 2; static int sequence_validation = 0; static int ORF_components = 1; static int minimum_ORF_length = 66; static int oligo_probe_length = 60; static float remove_similarity = 0.01f; static float eliminate_homology = 0.0f; static String parameters_file = "parameters.lst"; static String input_genes_file = "input-genes.ffn"; static String output_genes_file = "output-genes.ffn"; static String out_overlaps_file = "overlap-genes.tdt"; static String ORF_stats_file = "orf-stats.txt"; static String ORF_tags_file = "orf-tags.txt"; static String ORF_start_codons = "atg,gtg,ttg,ctg,att"; static String ORF_id_prefix = ""; static Properties params = new Properties(); public static final String workdir = System.getProperty("user.dir"); static String input_files_dir = workdir; static String output_files_dir = workdir; static String usage ="\nUsage: java -jar OliGo3.jar [switches]\n\nSwitches:\n" + "\n-p \n-f \n-h \n"; // Load parameters from parameters_file if it is used. public static void loadParams() throws IOException { if (InputFile.OpenOkay(workdir, parameters_file)) { // Read parameters set in parameters_file and override defaults. try { params.load(InputFile.br); } catch (IOException e) { System.err.println("I/O File Load Error: " + e.getMessage()); } catch (IllegalArgumentException e) { System.err.println("Illegal Argument Error: " + e.getMessage()); } // Parse and validate loaded parameters // Filenames except output have format requirements String s = ""; if ((s = getParam("input_file_mode", "^[123]$"))!= null) { input_file_mode = Integer.parseInt(s); } if ((s = getParam("sequence_validation", "^[01]$"))!= null) { sequence_validation = Integer.parseInt(s); } if ((s = getParam("ORF_components", "^[123]$"))!= null) { ORF_components = Integer.parseInt(s); } if ((s = getParam("minimum_ORF_length", "^\\d{2,}$"))!= null) { minimum_ORF_length = Integer.parseInt(s); } if ((s = getParam("oligo_probe_length", "^\\d{2}$"))!= null) { oligo_probe_length = Integer.parseInt(s); } if ((s = getParam("remove_similarity", "^0?\\.\\d+$"))!= null) { remove_similarity = Float.parseFloat(s); } if ((s = getParam("eliminate_homology", "^0?\\.\\d+$"))!= null) { eliminate_homology = Float.parseFloat(s); } if ((s = getParam("input_files_dir", ""))!= null) { input_files_dir = s; } if (!ParseOptions.flag) { if ((s=getParam("input_genes_file","^\\w[\\w\\s\\(\\)\\.,-]*[\\w\\)]*$"))!=null) { input_genes_file = s; }} if ((s = getParam("output_files_dir", ""))!= null) { output_files_dir = s; } if ((s = getParam("output_genes_file", ".+"))!= null) { output_genes_file = s; } if ((s = getParam("out_overlaps_file", ".+"))!= null) { out_overlaps_file = s; } if ((s = getParam("ORF_stats_file", ".+"))!= null) { ORF_stats_file = s; } if ((s = getParam("ORF_tags_file", ".+"))!= null) { ORF_tags_file = s; } // Read in a comma-separated list of strings into ORF_start_codons if ((s = getParam("ORF_start_codons", ".+"))!= null) { ORF_start_codons = s; } // Parse and validate ORF start codons fetched from either file or default if (!ORF_start_codons.matches("(?i)^(?:[acgt]{3},)*[acgt]{3}$")) { System.out.println(ORF_start_codons + ": Invalid start codons!"); System.exit(1); } if ((s = params.getProperty("ORF_id_prefix"))== null) { System.out.println("The property key ORF_id_prefix is not found."); System.exit(1); } else if (!s.equals("")) { if (s.trim().length() < 5) { //Up to 4 characters ORF_id_prefix = s.trim(); } else { System.out.println(s + ": has invalid prefix length!"); System.exit(1); } } // End of loading and validating parameters } } public static String getParam(String p, String v) throws IOException { String s = ""; if ((s = params.getProperty(p))== null) { System.out.println("The property key " + p + " is not found."); System.exit(1); } else if (s.equals("")) { System.out.println("The property key " + p + " has no value." + "\nThe default value is used instead.\n"); } else if (p.endsWith("dir")) { // Check and validate the directory of input/output files File d = new File(s); if (!d.exists()) { System.out.println("The directory: " + s + " does not exist."); System.exit(1); } else if (!d.isDirectory()) { System.out.println("The path: " + s + " is not a directory."); System.exit(1); } else { return s.trim(); } } else { if (s.trim().matches(v)) { return s.trim(); } else { System.out.println(s + ": Invalid parameter!"); System.exit(1); } } return null; } public static void printParams() { System.out.println("\nThis program will run based on the following settings:\n" + "\nparameters_file = " + parameters_file + "\ninput_file_mode = " + input_file_mode + "\ninput_files_dir = " + input_files_dir + "\ninput_genes_file = " + input_genes_file + "\noutput_files_dir = " + output_files_dir + "\noutput_genes_file = " + output_genes_file + "\nout_overlaps_file = " + out_overlaps_file + "\norf_stats_file = " + ORF_stats_file + "\norf_tags_file = " + ORF_tags_file + "\norf_id_prefix = " + ORF_id_prefix + "\nsequence_validation = " + sequence_validation + "\norf_start_codons = " + ORF_start_codons + "\norf_components = " + ORF_components + "\nminimum_orf_length = " + minimum_ORF_length + "\noligo_probe_length = " + oligo_probe_length + "\nremove_similarity = " + remove_similarity + "\neliminate_homology = " + eliminate_homology + "\n\nType in -h for help and make your own settings in parameters.lst.\n"); } }