public static List<FeatureTrack> loadTracks( Iterable<Feature> features, ResourceLocator locator, Genome genome, TrackProperties trackProperties) { FeatureCollectionSource source = new FeatureCollectionSource(features, genome); // Load into FeatureDB for searching if (IGV.hasInstance() || Globals.isTesting()) { Set<String> chrs = source.getChrs(); for (String chr : chrs) { List<Feature> feats = source.getFeatures(chr); for (Feature f : feats) { if (f instanceof NamedFeature) { FeatureDB.addFeature((NamedFeature) f); } } } } FeatureTrack track = new FeatureTrack(locator, source); track.setName(locator.getTrackName()); track.setRendererClass(IGVFeatureRenderer.class); track.setHeight(45); if (trackProperties != null) { track.setProperties(trackProperties); } List<FeatureTrack> tracks = new ArrayList(); tracks.add(track); return tracks; }
/** * Load all features in this file. * * @param reader * @param maxLines * @return */ public List<org.broad.tribble.Feature> loadFeatures(BufferedReader reader, int maxLines) { List<org.broad.tribble.Feature> features = new ArrayList<org.broad.tribble.Feature>(); String nextLine = null; int nLines = 0; try { while ((nextLine = reader.readLine()) != null) { nextLine = nextLine.trim(); if (nextLine.length() == 0) continue; nLines++; if ((maxLines > 0) && (nLines > maxLines)) { break; } try { if (nextLine.startsWith("#")) { if (nextLine.startsWith("#type")) { String[] tokens = Globals.equalPattern.split(nextLine); if (tokens.length > 1) { try { // TODO: type is not currently used, is there any reason to keep this? TrackType type = TrackType.valueOf(tokens[1]); } catch (Exception e) { log.error("Error converting track type: " + tokens[1]); } } } else if (nextLine.startsWith("#track")) { TrackProperties tp = new TrackProperties(); ParsingUtils.parseTrackLine(nextLine, tp); setTrackProperties(tp); if (tp.isGffTags()) { gffTags = true; } } else if (nextLine.startsWith("#coords")) { try { String[] tokens = Globals.equalPattern.split(nextLine); startBase = Integer.parseInt(tokens[1]); } catch (Exception e) { log.error("Error parsing coords line: " + nextLine, e); } } else if (nextLine.startsWith("#gffTags")) { gffTags = true; } } else { Feature feature = parseLine(nextLine); if (feature != null) { features.add(feature); } } } catch (NumberFormatException e) { // Expected condition -- for example comments. don't log as it slows down // the parsing and is not useful information. } } } catch (java.io.EOFException e) { // This exception is due to a known bug with java zip library. Not // in general a real error, and nothing we can do about it in any // event. return features; } catch (Exception e) { if (nextLine != null && nLines != 0) { throw new ParserException(e.getMessage(), e, nLines, nextLine); } else { throw new RuntimeException(e); } } // TODO -- why is this test here? This will break igvtools processing of expression files // if (IGV.hasInstance() || Globals.isTesting()) { FeatureDB.addFeatures(features); // } return features; }