@Override protected List<AlignmentFile> getAlignmentFiles(int currentIter) { // sort input file alphabetically to look nicer File inputDirectory = new File(this.inputDirectory); File[] listOfFiles = inputDirectory.listFiles(); Arrays.sort(listOfFiles, new NaturalOrderFilenameComparator()); List<AlignmentFile> alignmentDataList = new ArrayList<AlignmentFile>(); List<Feature> allFeatures = new ArrayList<Feature>(); // load feature data for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { File myFile = listOfFiles[i]; String filename = myFile.getName(); String path = myFile.getPath(); String extension = filename.substring(filename.lastIndexOf('.') + 1); // ignore other crap files in the directory if (!"txt".equals(extension)) { continue; } List<Feature> features = new ArrayList<Feature>(); try { features = this.loadFeatures(path); } catch (ValidityException e) { e.printStackTrace(); } catch (ParsingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } AlignmentFile alignmentData = new AlignmentFile(i, myFile, features); if (verbose) { System.out.println( "Load " + filename + " with " + alignmentData.getFeaturesCount() + " features"); } alignmentDataList.add(alignmentData); allFeatures.addAll(alignmentData.getFeatures()); } } this.alignmentFiles = alignmentDataList; return alignmentDataList; }
@Override protected GroundTruth getGroundTruth() { if (this.gtPath == null) { return null; } // store only features present in files that we're aligning List<FeatureGroup> groundTruthEntries = new ArrayList<FeatureGroup>(); Scanner in = null; try { // build a map from filename -> the actual feature data Map<String, AlignmentFile> alignmentDataMap = new HashMap<String, AlignmentFile>(); for (AlignmentFile data : this.alignmentFiles) { alignmentDataMap.put(data.getFilenameWithoutExtension(), data); } Map<Integer, String> tempMap = new HashMap<Integer, String>(); File inputFile = new File(this.gtPath); in = new Scanner(inputFile); int groupID = 1; while (in.hasNextLine()) { String line = in.nextLine(); Scanner lineSplitter = new Scanner(line); while (lineSplitter.hasNext()) { String firstToken = lineSplitter.next(); if (">".equals(firstToken)) { int fileIdx = lineSplitter.nextInt(); String filename = lineSplitter.next(); tempMap.put(fileIdx, filename); } else if ("#".equals(firstToken)) { FeatureGroup gtFeatures = new FeatureGroup(groupID); while (lineSplitter.hasNext()) { int fileIdx = lineSplitter.nextInt(); int peakIdx = lineSplitter.nextInt(); String filename = tempMap.get(fileIdx); AlignmentFile data = alignmentDataMap.get(filename); if (data != null) { Feature featureFromData = data.getFeatureByPeakID(peakIdx); assert featureFromData != null : "fileIdx " + fileIdx + " peakIdx " + peakIdx; gtFeatures.addFeature(featureFromData); } } groupID++; // new groupID for every line in ground truth // don't need this .. ? // if (gtFeatures.getFeatureCount() > 1) { groundTruthEntries.add(gtFeatures); // } } } lineSplitter.close(); } // close main while loop } catch (FileNotFoundException e) { e.printStackTrace(); } finally { if (in != null) { in.close(); } } System.out.println("Load ground truth = " + groundTruthEntries.size() + " rows"); // System.out.println("Retaining only entries size >= 2 = " + groundTruthEntries.size() + " // rows"); Iterator<FeatureGroup> it = groundTruthEntries.iterator(); while (it.hasNext()) { FeatureGroup gg = it.next(); if (gg.getFeatureCount() < 2) { it.remove(); } } GroundTruth groundTruth = new GroundTruth(groundTruthEntries, gtCombinationSize, verbose); return groundTruth; }