public Bed2Bar(String[] args) { try { processArgs(args); // load Window[] for (int i = 0; i < bedFiles.length; i++) { bedFile = bedFiles[i]; System.out.println("Parsing " + bedFile.getName()); bedLinesHash = Bed.parseBedFile(bedFile, true, false); if (bedLinesHash == null || bedLinesHash.size() == 0) { System.out.println("Problem parsing bed file, skipping!"); continue; } barDirectory = IO.makeDirectory(bedFile, ""); File bedOutFile = new File(Misc.removeExtension(bedFile.toString()) + "_" + threshold + "_Filt.bed"); bedOut = new PrintWriter(new FileWriter(bedOutFile)); makeStairStepBarFiles(); } bedOut.close(); System.out.println("\nDone!\n"); } catch (IOException e) { e.printStackTrace(); } }
/** This method will process each argument and assign new varibles */ public void processArgs(String[] args) { File file = null; Pattern pat = Pattern.compile("-[a-z]"); for (int i = 0; i < args.length; i++) { String lcArg = args[i].toLowerCase(); Matcher mat = pat.matcher(lcArg); if (mat.matches()) { char test = args[i].charAt(1); try { switch (test) { case 'f': file = new File(args[i + 1]); i++; break; case 'v': genomeVersion = args[i + 1]; i++; break; case 's': sumScores = true; break; case 't': threshold = Float.parseFloat(args[++i]); break; case 'h': printDocs(); System.exit(0); default: Misc.printExit("\nError, unknown option! " + mat.group()); } } catch (Exception e) { System.out.print("\nSorry, something doesn't look right with this parameter: -" + test); System.out.println(); System.exit(0); } } } if (file == null || file.exists() == false) Misc.printErrAndExit("Problem finding your bed files!\n"); // pull files File[][] tot = new File[3][]; tot[0] = IO.extractFiles(file, ".bed"); tot[1] = IO.extractFiles(file, ".bed.zip"); tot[2] = IO.extractFiles(file, ".bed.gz"); bedFiles = IO.collapseFileArray(tot); if (bedFiles == null || bedFiles.length == 0) Misc.printErrAndExit("Problem finding your xxx.bed(.zip/.gz OK) files!\n"); // genome version if (genomeVersion == null) Misc.printErrAndExit( "Please enter a genome version (e.g. H_sapiens_Mar_2006, see http://genome.ucsc.edu/FAQ/FAQreleases\n"); }