Changeset 5468


Ignore:
Timestamp:
09/14/09 11:11:08 (11 years ago)
Author:
melissa
Message:

Do not group multiple plates together.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/in/MIASReader.java

    r5466 r5468  
    6060  // -- Fields -- 
    6161 
    62   /** TIFF files - indexed by plate, well, and file. */ 
    63   private String[][][] tiffs; 
     62  /** TIFF files - indexed by well and file. */ 
     63  private String[][] tiffs; 
    6464 
    6565  /** Delegate readers. */ 
    66   private MinimalTiffReader[][][] readers; 
     66  private MinimalTiffReader[][] readers; 
    6767 
    6868  /** Path to file containing analysis results for all plates. */ 
     
    7171  private Vector<AnalysisFile> analysisFiles; 
    7272 
    73   private int[][] wellNumber; 
    74   private int[][] plateAndWell; 
     73  private int[] wellNumber; 
    7574 
    7675  private int tileRows, tileCols; 
     
    8079  private int[] bpp; 
    8180 
    82   private Vector<String> plateDirs; 
    83   private Vector<String> plateFiles; 
     81  private String templateFile; 
    8482 
    8583  /** Cached tile buffer to avoid re-allocations when reading tiles. */ 
     
    135133  public byte[][] get8BitLookupTable() throws FormatException, IOException { 
    136134    FormatTools.assertId(currentId, true, 1); 
    137     if (readers == null || readers[0][0][0].getCurrentFile() == null) { 
     135    if (readers == null || readers[0][0].getCurrentFile() == null) { 
    138136      return null; 
    139137    } 
    140     return readers[0][0][0].get8BitLookupTable(); 
     138    return readers[0][0].get8BitLookupTable(); 
    141139  } 
    142140 
     
    144142  public short[][] get16BitLookupTable() throws FormatException, IOException { 
    145143    FormatTools.assertId(currentId, true, 1); 
    146     if (readers == null || readers[0][0][0].getCurrentFile() == null) { 
     144    if (readers == null || readers[0][0].getCurrentFile() == null) { 
    147145      return null; 
    148146    } 
    149     return readers[0][0][0].get16BitLookupTable(); 
     147    return readers[0][0].get16BitLookupTable(); 
    150148  } 
    151149 
     
    158156    FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); 
    159157 
    160     int well = getWellNumber(getSeries()); 
    161     int plate = getPlateNumber(getSeries()); 
    162  
    163158    if (tileRows == 1 && tileCols == 1) { 
    164       readers[plate][well][no].setId(tiffs[plate][well][no]); 
    165       readers[plate][well][no].openBytes(0, buf, x, y, w, h); 
     159      readers[getSeries()][no].setId(tiffs[getSeries()][no]); 
     160      readers[getSeries()][no].openBytes(0, buf, x, y, w, h); 
    166161      return buf; 
    167162    } 
     
    184179 
    185180        int tileIndex = (no * tileRows + row) * tileCols + col; 
    186         tileBuf = getTile(plate, well, no, row, col, intersection); 
     181        tileBuf = getTile(getSeries(), no, row, col, intersection); 
    187182 
    188183        int rowLen = tileBuf.length / intersection.height; 
     
    210205    FormatTools.assertId(currentId, true, 1); 
    211206    Vector<String> files = new Vector<String>(); 
    212     int well = getWellNumber(getSeries()); 
    213     int plate = getPlateNumber(getSeries()); 
     207 
    214208    if (!noPixels) { 
    215       files.addAll(Arrays.asList(tiffs[plate][well])); 
     209      files.addAll(Arrays.asList(tiffs[getSeries()])); 
    216210    } 
    217211 
    218212    for (AnalysisFile file : analysisFiles) { 
    219       if ((file.plate == plate || file.plate < 0) && 
    220         (file.well == well || file.well < 0)) 
    221       { 
     213      if (file.plate <= 0 && (file.well == getSeries() || file.well < 0)) { 
    222214        files.add(file.filename); 
    223215      } 
    224216    } 
    225217 
    226     if (plateFiles != null && plate < plateFiles.size()) { 
    227       files.add(plateFiles.get(plate)); 
    228     } 
     218    if (templateFile != null) files.add(templateFile); 
    229219    return files.toArray(new String[files.size()]); 
    230220  } 
     
    234224    super.close(fileOnly); 
    235225    if (readers != null) { 
    236       for (MinimalTiffReader[][] wells : readers) { 
    237         for (MinimalTiffReader[] images : wells) { 
    238           for (MinimalTiffReader r : images) { 
    239             if (r != null) r.close(fileOnly); 
    240           } 
     226      for (MinimalTiffReader[] images : readers) { 
     227        for (MinimalTiffReader r : images) { 
     228          if (r != null) r.close(fileOnly); 
    241229        } 
    242230      } 
     
    250238      wellNumber = null; 
    251239      tileWidth = tileHeight = 0; 
    252       plateDirs = null; 
    253240      wellColumns = 0; 
    254241      bpp = null; 
    255       plateAndWell = null; 
    256       plateFiles = null; 
    257242      cachedTileBuffer = null; 
     243      templateFile = null; 
    258244    } 
    259245  } 
     
    266252    super.initFile(id); 
    267253 
    268     // TODO : initFile currently accepts a constituent TIFF file. 
    269     // Consider allowing the top level experiment directory to be passed in 
    270  
    271     plateDirs = new Vector<String>(); 
    272     plateFiles = new Vector<String>(); 
    273254    analysisFiles = new Vector<AnalysisFile>(); 
    274255 
     
    307288 
    308289    Location baseFile = new Location(id).getAbsoluteFile(); 
    309     Location experiment = 
    310       baseFile.getParentFile().getParentFile().getParentFile(); 
    311  
    312     String experimentName = experiment.getName(); 
    313     if (experimentName.length() == 3 || (experimentName.length() > 3 && 
    314       experimentName.replaceAll("\\d", "").startsWith("-"))) 
     290    Location plate = baseFile.getParentFile().getParentFile(); 
     291 
     292    String plateName = plate.getName(); 
     293    if (!(plateName.length() == 3 || (plateName.length() > 3 && 
     294      plateName.replaceAll("\\d", "").startsWith("-")))) 
    315295    { 
    316       experiment = experiment.getParentFile(); 
    317       experimentName = experiment.getName(); 
    318     } 
    319  
     296      plate = plate.getParentFile(); 
     297      plateName = plate.getName(); 
     298    } 
     299 
     300    int plateNumber = Integer.parseInt(plateName.substring(0, 3)); 
     301 
     302    Location experiment = plate.getParentFile(); 
    320303    String[] directories = experiment.list(true); 
    321304    Arrays.sort(directories); 
     
    333316          } 
    334317          else if (result.startsWith("NEO_PlateOutput_")) { 
    335             String plateIndex = result.substring(16, 19); 
    336             AnalysisFile af = new AnalysisFile(); 
    337             af.filename = file.getAbsolutePath(); 
    338             af.plate = Integer.parseInt(plateIndex) - 1; 
    339             analysisFiles.add(af); 
    340           } 
    341         } 
    342       } 
    343       else if (f.isDirectory()) { 
    344         // plate directories should start with 3 digits 
    345         try { 
    346           int plateIndex = Integer.parseInt(dir.substring(0, 3)); 
    347           plateDirs.add(dir); 
    348         } 
    349         catch (NumberFormatException e) { } 
    350       } 
    351     } 
    352  
    353     int nPlates = plateDirs.size(); 
    354     debug("Found " + nPlates + " plates."); 
    355  
    356     tiffs = new String[nPlates][][]; 
    357     readers = new MinimalTiffReader[nPlates][][]; 
    358  
    359     int[][] zCount = new int[nPlates][]; 
    360     int[][] cCount = new int[nPlates][]; 
    361     int[][] tCount = new int[nPlates][]; 
    362     String[][] order = new String[nPlates][]; 
    363     wellNumber = new int[nPlates][]; 
    364  
    365     for (int i=0; i<nPlates; i++) { 
    366       String plate = plateDirs.get(i); 
    367       Location plateDir = new Location(experiment, plate); 
    368       String[] list = plateDir.list(true); 
    369       Arrays.sort(list); 
    370       Vector<String> wellDirectories = new Vector<String>(); 
    371       for (String dir : list) { 
    372         Location f = new Location(plateDir, dir); 
    373         if (f.getName().startsWith("Well") || f.getName().length() == 4) { 
    374           // directory name is valid, but we need to make sure that the 
    375           // directory contains a TIFF or a subdirectory 
    376           String[] wellList = f.list(true); 
    377           if (wellList != null) { 
    378             boolean validWell = false; 
    379             for (String potentialTIFF : wellList) { 
    380               if (potentialTIFF.toLowerCase().endsWith(".tif") || 
    381                 new Location(f, potentialTIFF).isDirectory()) { 
    382                 validWell = true; 
    383                 break; 
    384               } 
    385             } 
    386             if (validWell) wellDirectories.add(f.getAbsolutePath()); 
    387           } 
    388         } 
    389         else if (f.getName().equals("results")) { 
    390           String[] resultsList = f.list(true); 
    391           for (String result : resultsList) { 
    392             // exclude proprietary program state files 
    393             if (!result.endsWith(".sav") && !result.endsWith(".dsv")) { 
    394               Location r = new Location(f, result); 
     318            int plateIndex = Integer.parseInt(result.substring(16, 19)); 
     319            if (plateIndex == plateNumber) { 
    395320              AnalysisFile af = new AnalysisFile(); 
    396               af.filename = r.getAbsolutePath(); 
    397               af.plate = i; 
    398               if (result.toLowerCase().startsWith("well")) { 
    399                 af.well = Integer.parseInt(result.substring(4, 8)) - 1; 
    400               } 
     321              af.filename = file.getAbsolutePath(); 
     322              af.plate = 0; 
    401323              analysisFiles.add(af); 
    402324            } 
    403325          } 
    404326        } 
    405         else if (f.getName().equals("Nugenesistemplate.txt")) { 
    406           plateFiles.add(f.getAbsolutePath()); 
    407         } 
    408       } 
    409       debug("Plate " + i + " has " + wellDirectories.size() + " wells."); 
    410       readers[i] = new MinimalTiffReader[wellDirectories.size()][]; 
    411       tiffs[i] = new String[wellDirectories.size()][]; 
    412       zCount[i] = new int[wellDirectories.size()]; 
    413       cCount[i] = new int[wellDirectories.size()]; 
    414       tCount[i] = new int[wellDirectories.size()]; 
    415       order[i] = new String[wellDirectories.size()]; 
    416       wellNumber[i] = new int[wellDirectories.size()]; 
    417  
    418       for (int j=0; j<wellDirectories.size(); j++) { 
    419         Location well = new Location(wellDirectories.get(j)); 
    420         String wellName = well.getName().replaceAll("Well", ""); 
    421         wellNumber[i][j] = Integer.parseInt(wellName) - 1; 
    422  
    423         String[] tiffFiles = well.list(true); 
    424         Vector<String> tmpFiles = new Vector<String>(); 
    425         for (String tiff : tiffFiles) { 
    426           String name = tiff.toLowerCase(); 
    427           if (name.endsWith(".tif") || name.endsWith(".tiff")) { 
    428             tmpFiles.add(new Location(well, tiff).getAbsolutePath()); 
     327      } 
     328    } 
     329 
     330    String[] list = plate.list(true); 
     331    Arrays.sort(list); 
     332    Vector<String> wellDirectories = new Vector<String>(); 
     333    for (String dir : list) { 
     334      Location f = new Location(plate, dir); 
     335      if (f.getName().startsWith("Well") || f.getName().length() == 4) { 
     336        // directory name is valid, but we need to make sure that the 
     337        // directory contains a TIFF or a subdirectory 
     338        String[] wellList = f.list(true); 
     339        if (wellList != null) { 
     340          boolean validWell = false; 
     341          for (String potentialTIFF : wellList) { 
     342            if (potentialTIFF.toLowerCase().endsWith(".tif") || 
     343              new Location(f, potentialTIFF).isDirectory()) { 
     344              validWell = true; 
     345              break; 
     346            } 
    429347          } 
    430         } 
    431  
    432         if (tmpFiles.size() == 0) { 
    433           debug("No TIFFs in well directory " + wellDirectories.get(j)); 
    434           // no TIFFs in the well directory, so there are probably channel 
    435           // directories which contain the TIFFs 
    436           for (String dir : tiffFiles) { 
    437             Location file = new Location(well, dir); 
    438             if (dir.length() == 1 && file.isDirectory()) { 
    439               cCount[i][j]++; 
    440  
    441               String[] tiffs = file.list(true); 
    442               for (String tiff : tiffs) { 
    443                 String name = tiff.toLowerCase(); 
    444                 if (name.endsWith(".tif") || name.endsWith(".tiff")) { 
    445                   tmpFiles.add(new Location(file, tiff).getAbsolutePath()); 
    446                 } 
     348          if (validWell) wellDirectories.add(f.getAbsolutePath()); 
     349        } 
     350      } 
     351      else if (f.getName().equals("results")) { 
     352        String[] resultsList = f.list(true); 
     353        for (String result : resultsList) { 
     354          // exclude proprietary program state files 
     355          if (!result.endsWith(".sav") && !result.endsWith(".dsv")) { 
     356            Location r = new Location(f, result); 
     357            AnalysisFile af = new AnalysisFile(); 
     358            af.filename = r.getAbsolutePath(); 
     359            af.plate = 0; 
     360            if (result.toLowerCase().startsWith("well")) { 
     361              af.well = Integer.parseInt(result.substring(4, 8)) - 1; 
     362            } 
     363            analysisFiles.add(af); 
     364          } 
     365        } 
     366      } 
     367      else if (f.getName().equals("Nugenesistemplate.txt")) { 
     368        templateFile = f.getAbsolutePath(); 
     369      } 
     370    } 
     371 
     372    debug("Found " + wellDirectories.size() + " wells."); 
     373 
     374    readers = new MinimalTiffReader[wellDirectories.size()][]; 
     375    tiffs = new String[wellDirectories.size()][]; 
     376    int[] zCount = new int[wellDirectories.size()]; 
     377    int[] cCount = new int[wellDirectories.size()]; 
     378    int[] tCount = new int[wellDirectories.size()]; 
     379    String[] order = new String[wellDirectories.size()]; 
     380    wellNumber = new int[wellDirectories.size()]; 
     381 
     382    for (int j=0; j<wellDirectories.size(); j++) { 
     383      Location well = new Location(wellDirectories.get(j)); 
     384      String wellName = well.getName().replaceAll("Well", ""); 
     385      wellNumber[j] = Integer.parseInt(wellName) - 1; 
     386 
     387      String[] tiffFiles = well.list(true); 
     388      Vector<String> tmpFiles = new Vector<String>(); 
     389      for (String tiff : tiffFiles) { 
     390        String name = tiff.toLowerCase(); 
     391        if (name.endsWith(".tif") || name.endsWith(".tiff")) { 
     392          tmpFiles.add(new Location(well, tiff).getAbsolutePath()); 
     393        } 
     394      } 
     395 
     396      if (tmpFiles.size() == 0) { 
     397        debug("No TIFFs in well directory " + wellDirectories.get(j)); 
     398        // no TIFFs in the well directory, so there are probably channel 
     399        // directories which contain the TIFFs 
     400        for (String dir : tiffFiles) { 
     401          Location file = new Location(well, dir); 
     402          if (dir.length() == 1 && file.isDirectory()) { 
     403            cCount[j]++; 
     404 
     405            String[] tiffs = file.list(true); 
     406            for (String tiff : tiffs) { 
     407              String name = tiff.toLowerCase(); 
     408              if (name.endsWith(".tif") || name.endsWith(".tiff")) { 
     409                tmpFiles.add(new Location(file, tiff).getAbsolutePath()); 
    447410              } 
    448411            } 
    449412          } 
    450413        } 
    451  
    452         tiffFiles = tmpFiles.toArray(new String[0]); 
    453  
    454         Location firstTiff = new Location(tiffFiles[0]); 
    455  
    456         FilePattern fp = new FilePattern( 
    457           firstTiff.getName(), firstTiff.getParentFile().getAbsolutePath()); 
    458         String[] blocks = fp.getPrefixes(); 
    459         BigInteger[] firstNumber = fp.getFirst(); 
    460         BigInteger[] lastNumber = fp.getLast(); 
    461         BigInteger[] step = fp.getStep(); 
    462  
    463         order[i][j] = "XY"; 
    464  
    465         for (int block=blocks.length - 1; block>=0; block--) { 
    466           blocks[block] = blocks[block].toLowerCase(); 
    467           blocks[block] = 
    468             blocks[block].substring(blocks[block].lastIndexOf("_") + 1); 
    469  
    470           BigInteger tmp = lastNumber[block].subtract(firstNumber[block]); 
    471           tmp = tmp.add(BigInteger.ONE).divide(step[block]); 
    472           int count = tmp.intValue(); 
    473  
    474           if (blocks[block].equals("z")) { 
    475             zCount[i][j] = count; 
    476             order[i][j] += "Z"; 
     414      } 
     415 
     416      tiffFiles = tmpFiles.toArray(new String[0]); 
     417 
     418      Location firstTiff = new Location(tiffFiles[0]); 
     419 
     420      FilePattern fp = new FilePattern( 
     421        firstTiff.getName(), firstTiff.getParentFile().getAbsolutePath()); 
     422      String[] blocks = fp.getPrefixes(); 
     423      BigInteger[] firstNumber = fp.getFirst(); 
     424      BigInteger[] lastNumber = fp.getLast(); 
     425      BigInteger[] step = fp.getStep(); 
     426 
     427      order[j] = "XY"; 
     428 
     429      for (int block=blocks.length - 1; block>=0; block--) { 
     430        blocks[block] = blocks[block].toLowerCase(); 
     431        blocks[block] = 
     432          blocks[block].substring(blocks[block].lastIndexOf("_") + 1); 
     433 
     434        BigInteger tmp = lastNumber[block].subtract(firstNumber[block]); 
     435        tmp = tmp.add(BigInteger.ONE).divide(step[block]); 
     436        int count = tmp.intValue(); 
     437 
     438        if (blocks[block].equals("z")) { 
     439          zCount[j] = count; 
     440          order[j] += "Z"; 
     441        } 
     442        else if (blocks[block].equals("t")) { 
     443          tCount[j] = count; 
     444          order[j] += "T"; 
     445        } 
     446        else if (blocks[block].equals("mode")) { 
     447          cCount[j] = count; 
     448          order[j] += "C"; 
     449        } 
     450        else if (blocks[block].equals("im")) tileRows = count; 
     451        else if (blocks[block].equals("")) tileCols = count; 
     452        else if (blocks[block].replaceAll("\\d", "").length() == 0) { 
     453          if (block == 3) tileRows = count; 
     454          else if (block == 2) tileCols = count; 
     455          else if (block == 1) { 
     456            zCount[j] = count; 
     457            order[j] += "Z"; 
    477458          } 
    478           else if (blocks[block].equals("t")) { 
    479             tCount[i][j] = count; 
    480             order[i][j] += "T"; 
     459          else if (block == 0) { 
     460            tCount[j] = count; 
     461            order[j] += "T"; 
    481462          } 
    482           else if (blocks[block].equals("mode")) { 
    483             cCount[i][j] = count; 
    484             order[i][j] += "C"; 
    485           } 
    486           else if (blocks[block].equals("im")) tileRows = count; 
    487           else if (blocks[block].equals("")) tileCols = count; 
    488           else if (blocks[block].replaceAll("\\d", "").length() == 0) { 
    489             if (block == 3) tileRows = count; 
    490             else if (block == 2) tileCols = count; 
    491             else if (block == 1) { 
    492               zCount[i][j] = count; 
    493               order[i][j] += "Z"; 
    494             } 
    495             else if (block == 0) { 
    496               tCount[i][j] = count; 
    497               order[i][j] += "T"; 
    498             } 
    499           } 
    500           else { 
    501             throw new FormatException("Unsupported block '" + blocks[block]); 
    502           } 
    503         } 
    504  
    505         Arrays.sort(tiffFiles); 
    506         tiffs[i][j] = tiffFiles; 
    507         debug("Well " + j + " in plate " + i + " has " + 
    508           tiffFiles.length + " files."); 
    509         readers[i][j] = new MinimalTiffReader[tiffFiles.length]; 
    510         for (int k=0; k<tiffFiles.length; k++) { 
    511           readers[i][j][k] = new MinimalTiffReader(); 
    512         } 
     463        } 
     464        else { 
     465          throw new FormatException("Unsupported block '" + blocks[block]); 
     466        } 
     467      } 
     468 
     469      Arrays.sort(tiffFiles); 
     470      tiffs[j] = tiffFiles; 
     471      debug("Well " + j + " has " + tiffFiles.length + " files."); 
     472      readers[j] = new MinimalTiffReader[tiffFiles.length]; 
     473      for (int k=0; k<tiffFiles.length; k++) { 
     474        readers[j][k] = new MinimalTiffReader(); 
    513475      } 
    514476    } 
     
    518480    status("Populating core metadata"); 
    519481 
    520     int nSeries = 0; 
    521     for (int i=0; i<tiffs.length; i++) { 
    522       nSeries += tiffs[i].length; 
    523     } 
     482    int nSeries = tiffs.length; 
    524483 
    525484    core = new CoreMetadata[nSeries]; 
    526485    bpp = new int[nSeries]; 
    527     plateAndWell = new int[nSeries][2]; 
    528486 
    529487    if (readers.length == 0) { 
    530       throw new FormatException("No plates were found."); 
    531     } 
    532     else if (readers[0].length == 0) { 
    533       throw new FormatException("No wells were found in the first plate."); 
     488      throw new FormatException("No wells were found."); 
    534489    } 
    535490 
    536491    // assume that all wells have the same width, height, and pixel type 
    537     readers[0][0][0].setId(tiffs[0][0][0]); 
    538     tileWidth = readers[0][0][0].getSizeX(); 
    539     tileHeight = readers[0][0][0].getSizeY(); 
     492    readers[0][0].setId(tiffs[0][0]); 
     493    tileWidth = readers[0][0].getSizeX(); 
     494    tileHeight = readers[0][0].getSizeY(); 
    540495 
    541496    if (tileCols == 0) tileCols = 1; 
     
    543498 
    544499    for (int i=0; i<core.length; i++) { 
    545       Arrays.fill(plateAndWell[i], -1); 
    546500      core[i] = new CoreMetadata(); 
    547501 
    548       int plate = getPlateNumber(i); 
    549       int well = getWellNumber(i); 
    550  
    551       core[i].sizeZ = zCount[plate][well]; 
    552       core[i].sizeC = cCount[plate][well]; 
    553       core[i].sizeT = tCount[plate][well]; 
     502      core[i].sizeZ = zCount[i]; 
     503      core[i].sizeC = cCount[i]; 
     504      core[i].sizeT = tCount[i]; 
    554505 
    555506      if (core[i].sizeZ == 0) core[i].sizeZ = 1; 
     
    559510      core[i].sizeX = tileWidth * tileCols; 
    560511      core[i].sizeY = tileHeight * tileRows; 
    561       core[i].pixelType = readers[0][0][0].getPixelType(); 
    562       core[i].sizeC *= readers[0][0][0].getSizeC(); 
    563       core[i].rgb = readers[0][0][0].isRGB(); 
    564       core[i].littleEndian = readers[0][0][0].isLittleEndian(); 
    565       core[i].interleaved = readers[0][0][0].isInterleaved(); 
    566       core[i].indexed = readers[0][0][0].isIndexed(); 
    567       core[i].falseColor = readers[0][0][0].isFalseColor(); 
    568       core[i].dimensionOrder = order[plate][well]; 
     512      core[i].pixelType = readers[0][0].getPixelType(); 
     513      core[i].sizeC *= readers[0][0].getSizeC(); 
     514      core[i].rgb = readers[0][0].isRGB(); 
     515      core[i].littleEndian = readers[0][0].isLittleEndian(); 
     516      core[i].interleaved = readers[0][0].isInterleaved(); 
     517      core[i].indexed = readers[0][0].isIndexed(); 
     518      core[i].falseColor = readers[0][0].isFalseColor(); 
     519      core[i].dimensionOrder = order[i]; 
    569520 
    570521      if (core[i].dimensionOrder.indexOf("Z") == -1) { 
     
    578529      } 
    579530 
    580       core[i].imageCount = core[i].sizeZ * core[i].sizeT * cCount[plate][well]; 
     531      core[i].imageCount = core[i].sizeZ * core[i].sizeT * cCount[i]; 
    581532      if (core[i].imageCount == 0) { 
    582533        core[i].imageCount = 1; 
     
    588539 
    589540    status("Populating metadata hashtable"); 
    590  
    591     wellColumns = 1; 
    592541 
    593542    if (resultFile != null) { 
     
    640589    MetadataTools.populatePixels(store, this, true); 
    641590 
    642     store.setExperimentID("Experiment:" + experimentName, 0); 
     591    store.setExperimentID("Experiment:" + experiment.getName(), 0); 
    643592    store.setExperimentType("Other", 0); 
    644593 
    645594    // populate SPW metadata 
    646     for (int plate=0; plate<tiffs.length; plate++) { 
    647       store.setPlateColumnNamingConvention("1", plate); 
    648       store.setPlateRowNamingConvention("A", plate); 
    649  
    650       parseTemplateFile(store, plate); 
    651  
    652       String plateDir = plateDirs.get(plate); 
    653       plateDir = plateDir.substring(plateDir.indexOf("-") + 1); 
    654       store.setPlateName(plateDir, plate); 
    655       store.setPlateExternalIdentifier(plateDir, plate); 
    656  
    657       int nWells = tiffs[plate].length; 
    658       // HACK: if we don't have the analysis file, we don't how many 
    659       // rows/columns are in the plate 
    660       // 
    661       // assume that a 96 well plate is 8x12, and a 384 well plate is 16x24 
    662       if (wellColumns == 0) { 
    663         if (nWells == 96) { 
    664           wellColumns = 12; 
    665         } 
    666         else if (nWells == 384) { 
    667           wellColumns = 24; 
    668         } 
    669         else { 
    670           warn("Could not determine the plate dimensions."); 
    671           wellColumns = 24; 
    672         } 
    673       } 
    674  
    675       for (int well=0; well<nWells; well++) { 
    676         int wellIndex = wellNumber[plate][well]; 
    677  
    678         int row = wellIndex / wellColumns; 
    679         int wellCol = (well % wellColumns) + 1; 
    680  
    681         store.setWellRow(new Integer(row), plate, wellIndex); 
    682         store.setWellColumn(new Integer(wellCol - 1), plate, wellIndex); 
    683  
    684         int series = getSeriesNumber(plate, well); 
    685         String imageID = MetadataTools.createLSID("Image", series); 
    686         store.setWellSampleImageRef(imageID, plate, wellIndex, 0); 
    687         store.setWellSampleIndex(new Integer(series), plate, wellIndex, 0); 
    688  
    689         // populate Image/Pixels metadata 
    690         store.setImageExperimentRef("Experiment:" + experimentName, series); 
    691         char wellRow = (char) ('A' + row); 
    692  
    693         store.setImageID(imageID, series); 
    694         store.setImageName("Plate #" + plate + ", Well " + wellRow + wellCol, 
    695           series); 
    696  
    697         String instrumentID = MetadataTools.createLSID("Instrument", series); 
    698         store.setInstrumentID(instrumentID, series); 
    699         store.setImageInstrumentRef(instrumentID, series); 
    700  
    701         MetadataTools.setDefaultCreationDate(store, id, series); 
    702       } 
     595    store.setPlateColumnNamingConvention("1", 0); 
     596    store.setPlateRowNamingConvention("A", 0); 
     597 
     598    parseTemplateFile(store); 
     599 
     600    plateName = plateName.substring(plateName.indexOf("-") + 1); 
     601    store.setPlateName(plateName, 0); 
     602    store.setPlateExternalIdentifier(plateName, 0); 
     603 
     604    int nWells = tiffs.length; 
     605    // HACK: if we don't have the analysis file, we don't how many 
     606    // rows/columns are in the plate 
     607    // 
     608    // assume that a 96 well plate is 8x12, and a 384 well plate is 16x24 
     609    if (wellColumns == 0) { 
     610      if (nWells == 96) { 
     611        wellColumns = 12; 
     612      } 
     613      else if (nWells == 384) { 
     614        wellColumns = 24; 
     615      } 
     616      else { 
     617        warn("Could not determine the plate dimensions."); 
     618        wellColumns = 24; 
     619      } 
     620    } 
     621 
     622    for (int well=0; well<nWells; well++) { 
     623      int wellIndex = wellNumber[well]; 
     624 
     625      int row = wellIndex / wellColumns; 
     626      int wellCol = (wellIndex % wellColumns) + 1; 
     627 
     628      store.setWellRow(new Integer(row), 0, well); 
     629      store.setWellColumn(new Integer(wellCol - 1), 0, well); 
     630 
     631      String imageID = MetadataTools.createLSID("Image", well); 
     632      store.setWellSampleImageRef(imageID, 0, well, 0); 
     633      store.setWellSampleIndex(new Integer(well), 0, well, 0); 
     634 
     635      // populate Image/Pixels metadata 
     636      store.setImageExperimentRef("Experiment:" + experiment.getName(), well); 
     637      char wellRow = (char) ('A' + row); 
     638 
     639      store.setImageID(imageID, well); 
     640      store.setImageName("Well " + wellRow + wellCol, well); 
     641 
     642      String instrumentID = MetadataTools.createLSID("Instrument", 0); 
     643      store.setInstrumentID(instrumentID, 0); 
     644      store.setImageInstrumentRef(instrumentID, well); 
     645 
     646      MetadataTools.setDefaultCreationDate(store, id, well); 
    703647    } 
    704648 
     
    711655 
    712656      int[] position = getPositionFromFile(file); 
    713       int series = getSeriesNumber(position[0], position[1]); 
     657      int well = position[0]; 
    714658 
    715659      if (name.endsWith("detail.txt")) { 
     
    726670 
    727671        for (int j=start+1; j<lines.length; j++) { 
    728           populateROI(columnNames, lines[j].split("\t"), series, 
    729             j - start - 1, position[2], position[3], store); 
     672          populateROI(columnNames, lines[j].split("\t"), well, 
     673            j - start - 1, position[1], position[2], store); 
    730674        } 
    731675      } 
     
    733677        // original color for each channel is stored in 
    734678        // results/Well<nnnn>_mode<n>_z<nnn>_t<nnn>_AllModesOverlay.tif 
    735         if (colors[position[4]] != null) continue; 
     679        if (colors[position[3]] != null) continue; 
    736680        try { 
    737           colors[position[4]] = getChannelColorFromFile(file); 
     681          colors[position[3]] = getChannelColorFromFile(file); 
    738682        } 
    739683        catch (IOException e) { } 
    740         if (colors[position[4]] == null) continue; 
     684        if (colors[position[3]] == null) continue; 
    741685 
    742686        for (int s=0; s<getSeriesCount(); s++) { 
    743687          store.setChannelComponentColorDomain( 
    744             colors[position[4]], s, position[4], 0); 
     688            colors[position[3]], s, position[3], 0); 
    745689        } 
    746690      } 
     
    766710    if (colorMap == null) return null; 
    767711 
    768     int[] position = getPositionFromFile(file); 
    769  
    770712    int nEntries = colorMap.length / 3; 
    771713    int max = Integer.MIN_VALUE; 
     
    794736 
    795737  /** 
    796    * Returns an array of length 5 that contains the plate, well, time point, 
     738   * Returns an array of length 5 that contains the well, time point, 
    797739   * Z and channel indices corresponding to the given analysis file. 
    798740   */ 
    799741  private int[] getPositionFromFile(String file) { 
    800     int[] position = new int[5]; 
    801  
    802     Location plate = new Location(file).getParentFile().getParentFile(); 
    803     if (file.endsWith(".tif")) plate = plate.getParentFile(); 
    804     String plateName = plate.getName(); 
    805  
    806     position[0] = plateDirs.indexOf(plateName); 
     742    int[] position = new int[4]; 
    807743 
    808744    file = file.substring(file.lastIndexOf(File.separator) + 1); 
    809745    String wellIndex = file.substring(4, file.indexOf("_")); 
    810     position[1] = Integer.parseInt(wellIndex) - 1; 
     746    position[0] = Integer.parseInt(wellIndex) - 1; 
    811747 
    812748    int tIndex = file.indexOf("_t") + 2; 
    813749    String t = file.substring(tIndex, file.indexOf("_", tIndex)); 
    814     position[2] = Integer.parseInt(t); 
     750    position[1] = Integer.parseInt(t); 
    815751 
    816752    int zIndex = file.indexOf("_z") + 2; 
    817753    String zValue = file.substring(zIndex, file.indexOf("_", zIndex)); 
    818     position[3] = Integer.parseInt(zValue); 
     754    position[2] = Integer.parseInt(zValue); 
    819755 
    820756    int cIndex = file.indexOf("mode") + 4; 
    821757    String cValue = file.substring(cIndex, file.indexOf("_", cIndex)); 
    822     position[4] = Integer.parseInt(cValue) - 1; 
     758    position[3] = Integer.parseInt(cValue) - 1; 
    823759 
    824760    return position; 
     
    854790  } 
    855791 
    856   /** Retrieve the series corresponding to the given plate and well. */ 
    857   private int getSeriesNumber(int plate, int well) { 
    858     int series = 0; 
    859     for (int i=0; i<plate; i++) { 
    860       series += tiffs[i].length; 
    861     } 
    862     return series + well; 
    863   } 
    864  
    865   /** Retrieve the well to which this series belongs. */ 
    866   private int getWellNumber(int series) { 
    867     if (plateAndWell[series][1] == -1) { 
    868       plateAndWell[series] = getPlateAndWell(series); 
    869     } 
    870     return plateAndWell[series][1]; 
    871   } 
    872  
    873   /** Retrieve the plate to which this series belongs. */ 
    874   private int getPlateNumber(int series) { 
    875     if (plateAndWell[series][0] == -1) { 
    876       plateAndWell[series] = getPlateAndWell(series); 
    877     } 
    878     return plateAndWell[series][0]; 
    879   } 
    880  
    881   /** Retrieve a two element array containing the plate and well indices. */ 
    882   private int[] getPlateAndWell(int series) { 
    883     // NB: Don't use FormatTools.rasterToPosition(...), because each plate 
    884     // could have a different number of wells. 
    885     int wellNumber = series; 
    886     int plateNumber = 0; 
    887     while (wellNumber >= tiffs[plateNumber].length) { 
    888       wellNumber -= tiffs[plateNumber].length; 
    889       plateNumber++; 
    890     } 
    891     return new int[] {plateNumber, wellNumber}; 
    892   } 
    893  
    894   private byte[] getTile(int plate, int well, int no, int row, int col, 
     792  private byte[] getTile(int well, int no, int row, int col, 
    895793    Region intersection) throws FormatException, IOException 
    896794  { 
     
    900798    int tileIndex = (no * tileRows + row) * tileCols + col; 
    901799 
    902     readers[plate][well][tileIndex].setId(tiffs[plate][well][tileIndex]); 
     800    readers[well][tileIndex].setId(tiffs[well][tileIndex]); 
    903801    int bpp = FormatTools.getBytesPerPixel(getPixelType()); 
    904802    int ch = getRGBChannelCount(); 
     
    907805      cachedTileBuffer = new byte[bufferSize]; 
    908806    } 
    909     byte[] buf = readers[plate][well][tileIndex].openBytes(0, cachedTileBuffer, 
     807    byte[] buf = readers[well][tileIndex].openBytes(0, cachedTileBuffer, 
    910808      intersection.x, intersection.y, intersection.width, intersection.height); 
    911809    return buf; 
    912810  } 
    913811 
    914   /** 
    915    * Parse metadata from the Nugenesistemplate.txt file associated with the 
    916    * given plate. 
    917    */ 
    918   private void parseTemplateFile(MetadataStore store, int plate) 
    919     throws IOException 
    920   { 
    921     if (plate >= plateFiles.size()) return; 
     812  /** Parse metadata from the Nugenesistemplate.txt file. */ 
     813  private void parseTemplateFile(MetadataStore store) throws IOException { 
     814    if (templateFile == null) return; 
    922815 
    923816    Float physicalSizeX = null, physicalSizeY = null, exposure = null; 
     
    925818    String date = null; 
    926819 
    927     String templateFile = plateFiles.get(plate); 
    928820    String data = DataTools.readFile(templateFile); 
    929821    String[] lines = data.split("\r\n"); 
     
    936828 
    937829        if (key.equals("Barcode")) { 
    938           store.setPlateExternalIdentifier(value, plate); 
     830          store.setPlateExternalIdentifier(value, 0); 
    939831        } 
    940832        else if (key.equals("Carrier")) { 
    941           store.setPlateName(value, plate); 
     833          store.setPlateName(value, 0); 
    942834        } 
    943835        else if (key.equals("Pixel_X")) { 
     
    948840        } 
    949841        else if (key.equals("Objective_ID")) { 
    950           store.setObjectiveModel(value, plate, 0); 
     842          store.setObjectiveModel(value, 0, 0); 
    951843        } 
    952844        else if (key.equals("Magnification")) { 
    953845          int mag = (int) Float.parseFloat(value); 
    954           store.setObjectiveNominalMagnification(new Integer(mag), plate, 0); 
     846          store.setObjectiveNominalMagnification(new Integer(mag), 0, 0); 
    955847        } 
    956848        else if (key.startsWith("Mode_")) { 
     
    969861    } 
    970862 
    971     for (int well=0; well<tiffs[plate].length; well++) { 
    972       int series = getSeriesNumber(plate, well); 
     863    for (int well=0; well<tiffs.length; well++) { 
    973864      if (physicalSizeX != null) { 
    974         store.setDimensionsPhysicalSizeX(physicalSizeX, series, 0); 
     865        store.setDimensionsPhysicalSizeX(physicalSizeX, well, 0); 
    975866      } 
    976867      if (physicalSizeY != null) { 
    977         store.setDimensionsPhysicalSizeY(physicalSizeY, series, 0); 
     868        store.setDimensionsPhysicalSizeY(physicalSizeY, well, 0); 
    978869      } 
    979870      for (int c=0; c<channelNames.size(); c++) { 
    980871        if (c < getEffectiveSizeC()) { 
    981           store.setLogicalChannelName(channelNames.get(c), series, c); 
     872          store.setLogicalChannelName(channelNames.get(c), well, c); 
    982873        } 
    983874      } 
    984875      date = DateTools.formatDate(date, "dd/MM/yyyy HH:mm:ss"); 
    985       store.setImageCreationDate(date, series); 
     876      store.setImageCreationDate(date, well); 
    986877 
    987878      for (int i=0; i<getImageCount(); i++) { 
    988         store.setPlaneTimingExposureTime(exposure, series, 0, i); 
     879        store.setPlaneTimingExposureTime(exposure, well, 0, i); 
    989880      } 
    990881    } 
Note: See TracChangeset for help on using the changeset viewer.