Example #1
0
  public void loadTable(Reader in) throws IOException, FormatException {
    table = new ArrayList<Entry>(InitNumEntries);

    String line = null;
    LineNumberReader input = new LineNumberReader(in);

    line = input.readLine();
    if (line == null) throw new FormatException("Empty sample sheet");
    // Verify that heading is as expected, ignoring quotes and case
    if (!line.replaceAll("\"", "").toLowerCase().startsWith(ExpectedHeading))
      throw new FormatException(
          "Unexpected heading!  Expected:\n" + ExpectedHeading + "\nFound:\n" + line);

    line = input.readLine();
    while (line != null) {
      insertRecord(line);
      line = input.readLine();
    }

    if (table.size() > 1) {
      // Check for duplicates barcodes in the same lane
      // start by sorting the table by lane
      Collections.sort(
          table,
          new Comparator<Entry>() {
            @Override
            public int compare(Entry a, Entry b) {
              return a.getLane() - b.getLane();
            }
          });
      HashSet<String> samplesInLane = new HashSet<String>();
      int currentLane = table.get(0).getLane();
      for (Entry e : table) // table is an ArrayList of Entries
      {
        if (e.getLane() == currentLane) {
          if (samplesInLane.contains(e.getIndex()))
            throw new FormatException(
                "index " + e.getIndex() + " appears twice for the same lane " + currentLane);
          else samplesInLane.add(e.getIndex());
        } else {
          // lane change
          samplesInLane.clear();
          samplesInLane.add(e.getIndex());
          currentLane = e.getLane();
        }
      }
    }
  }
Example #2
0
  public Set<String> getSamplesInLane(int lane) {
    if (lane <= 0) throw new IllegalArgumentException("Invalid negative lane number " + lane);

    HashSet<String> samples = new HashSet<String>(table.size() / 8);
    for (Entry e : this) {
      if (lane == e.getLane()) samples.add(e.getSampleId());
    }

    return samples;
  }