}
public static CursorTrack loadTrack(String peakFile) throws IOException {
AsciiFeatureCodec codec = (AsciiFeatureCodec) CodecFactory.getCodec(new ResourceLocator(peakFile), null);
// if(codec == null) {
// // TODO -- inform user
// System.out.println("Skipping " + peakFile);
// return null;
// }
// EncodePeakCodec codec = new EncodePeakCodec();
Map<String, List<BasicFeature>> featureMap = new HashMap<String, List<BasicFeature>>();
BufferedReader br = null;
TrackProperties props = null;
try {
br = ParsingUtils.openBufferedReader(peakFile);
String nextLine;
while ((nextLine = br.readLine()) != null) {
if (nextLine.startsWith("track")) {
props = new TrackProperties();
ParsingUtils.parseTrackLine(nextLine, props);
} else {
BasicFeature f = (BasicFeature) codec.decode(nextLine);
if (f != null) {
String chr = f.getChr();
List<BasicFeature> featureList = featureMap.get(chr);
if (featureList == null) {
featureList = new ArrayList<BasicFeature>();
featureMap.put(chr, featureList);
}
featureList.add(f);
}
}
}
} finally {
if (br != null) br.close();
}
for (List<BasicFeature> featureList : featureMap.values()) {
Collections.sort(featureList, new Comparator<BasicFeature>() {
@Override
public int compare(BasicFeature o1, BasicFeature o2) {
return o1.getStart() - o2.getStart();
}
});
}
CursorTrack track = new CursorTrack(featureMap, codec.getFeatureType());
String trackName = (new File(peakFile)).getName();
Color trackColor = null;
if (props != null) {
trackColor = props.getColor();
trackName = props.getName();