//Read back in the data which bedtools output
BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
List<Feature> featuresList = new ArrayList<Feature>();
//TODO This cast is here as a reminder that we want to use AsciiFeatureCodec
IGVBEDCodec codec = (IGVBEDCodec) CodecFactory.getCodec(".bed", null);
String line;
Feature feat;
int numCols0 = tempFiles.get(fiNames[0]);
int numCols1 = tempFiles.get(fiNames[1]);
while ((line = in.readLine()) != null) {
//System.out.println(line);
String[] tokens = line.split("\t");
if (operation.getCmd().contains("-split")) {
//When we split, the returned feature still has the exons
//We don't want to plot them all a zillion times
tokens = Arrays.copyOfRange(tokens, 0, Math.min(6, tokens.length));
}
if (operation == Operation.WINDOW || operation == Operation.CLOSEST) {
String[] closest = Arrays.copyOfRange(tokens, numCols0, numCols0 + numCols1);
//If not found, bedtools returns -1 for positions
if (closest[1].trim().equalsIgnoreCase("-1")) {
continue;
}
feat = codec.decode(closest);
} else if (operation == Operation.MULTIINTER) {
//We only look at regions common to ALL inputs
//Columns: chr \t start \t \end \t # of files which contained this feature \t comma-separated list files +many more
int numRegions = Integer.parseInt(tokens[3]);
if (numRegions < sources.length) {
continue;
}
String[] intersection = Arrays.copyOf(tokens, 3);
feat = codec.decode(intersection);
} else {
feat = codec.decode(tokens);
}
featuresList.add(feat);
}
in.close();