From 08a1543e95df781b547eac2ce487b036f5a51343 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Fri, 12 Feb 2010 15:32:10 +0000 Subject: [PATCH] Added BD Pathway reader, courtesy of Shawn Garbett. Closes #389. --- .../src/loci/formats/in/BDReader.java | 371 ++++++++++++++++++ .../bio-formats/src/loci/formats/readers.txt | 3 + 2 files changed, 374 insertions(+) create mode 100644 components/bio-formats/src/loci/formats/in/BDReader.java diff --git a/components/bio-formats/src/loci/formats/in/BDReader.java b/components/bio-formats/src/loci/formats/in/BDReader.java new file mode 100644 index 00000000000..3d335560033 --- /dev/null +++ b/components/bio-formats/src/loci/formats/in/BDReader.java @@ -0,0 +1,371 @@ +// +// BDReader.java +// + +/* +OME Bio-Formats package for reading and converting biological file formats. +Copyright (C) 2005-@year@ UW-Madison LOCI and Glencoe Software, Inc. +Copyright (C) 2009-@year@ Vanderbilt Integrative Cancer Center. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package loci.formats.in; + +import java.io.*; +import java.util.*; + +import loci.common.DataTools; +import loci.common.Location; +import loci.common.RandomAccessInputStream; +import loci.common.XMLTools; +import loci.common.IniList; +import loci.common.IniParser; +import loci.formats.CoreMetadata; +import loci.formats.FormatException; +import loci.formats.FormatReader; +import loci.formats.FormatTools; +import loci.formats.MetadataTools; +import loci.formats.meta.FilterMetadata; +import loci.formats.meta.MetadataStore; +import loci.formats.tiff.IFD; +import loci.formats.tiff.TiffParser; + +/** + * BDReader is the file format reader for BD Pathway datasets. + * + *
Source code:
+ *
Trac, + * SVN
+ * + * @author Shawn Garbett Shawn.Garbett a t Vanderbilt.edu + */ +public class BDReader extends FormatReader { + + // -- Constants -- + private static final String EXPERIMENT_FILE = "Experiment.exp"; + private static final String[] META_EXT = {"drt","dye","exp","plt"}; + + // -- Fields -- + private Vector metadataFiles = new Vector(); + private Vector channelNames = new Vector(); + private Vector wellLabels = new Vector(); + private String plateName; + private String[] tiffs; + private MinimalTiffReader reader; + + // -- Constructor -- + + /** Constructs a new ScanR reader. */ + public BDReader() { + super("BD Pathway", new String[] {"exp", "tif"}); + domains = new String[] {FormatTools.HCS_DOMAIN}; + suffixSufficient = false; + } + + // -- IFormatReader API methods -- + + /* @see loci.formats.IFormatReader#isThisType(String, boolean) */ + public boolean isThisType(String name, boolean open) { + String id = new Location(name).getAbsolutePath(); + try { + id = locateExperimentFile(id); + } + catch (FormatException f) { + return false; + } + catch (IOException f) { + return false; + } + + if (id.endsWith(EXPERIMENT_FILE)) { return true; } + + return super.isThisType(name, open); + } + + /* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */ + public boolean isThisType(RandomAccessInputStream stream) throws IOException { + TiffParser p = new TiffParser(stream); + IFD ifd = p.getFirstIFD(); + if (ifd == null) return false; + + String software = ifd.getIFDTextValue(IFD.SOFTWARE); + + return software.trim().startsWith("MATROX Imaging Library"); + } + + /* @see loci.formats.IFormatReader#getSeriesUsedFiles(boolean) */ + public String[] getSeriesUsedFiles(boolean noPixels) { + FormatTools.assertId(currentId, true, 1); + + Vector files = new Vector(); + for (String file : metadataFiles) { + if (file != null) files.add(file); + } + + if (!noPixels && tiffs != null) { + int offset = getSeries() * getImageCount(); + for (int i = 0; i uniqueRows = new Vector(); + Vector uniqueColumns = new Vector(); + + for (String well : wellLabels) { + String row = well.substring(0, 1).trim(); + String column = well.substring(1, 3).trim(); + + if (!uniqueRows.contains(row) && row.length() > 0) uniqueRows.add(row); + if (!uniqueColumns.contains(column) && column.length() > 0) { + uniqueColumns.add(column); + } + } + + int nSlices = getSizeZ() == 0 ? 1 : getSizeZ(); + int nTimepoints = getSizeT(); + int nWells = wellLabels.size(); + int nChannels = getSizeC() == 0 ? channelNames.size() : getSizeC(); + if (nChannels == 0) nChannels = 1; + + tiffs = getTiffs(dir.getAbsoluteFile().toString()); + + // [] files = new String[nChannels * nWells * nTimepoints * nSlices]; + + reader = new MinimalTiffReader(); + reader.setId(tiffs[0]); + + int sizeX = reader.getSizeX(); + int sizeY = reader.getSizeY(); + int pixelType = reader.getPixelType(); + boolean rgb = reader.isRGB(); + boolean interleaved = reader.isInterleaved(); + boolean indexed = reader.isIndexed(); + boolean littleEndian = reader.isLittleEndian(); + + reader.close(); + + for (int i=0; i files = new LinkedList(); + FileFilter wellDirFilter = new FileFilter() { + public boolean accept(File file) { + return file.isDirectory() && file.getName().startsWith("Well "); + } + }; + FileFilter tiffFilter = new FileFilter() { + public boolean accept(File file) { + return file.getName().matches(".* - n\\d\\d\\d\\d\\d\\d\\.tif"); + } + }; + + File[] dirs = (new File(dir)).listFiles(wellDirFilter); + + Arrays.sort(dirs); + + for (File well : dirs) { + File[] found = well.listFiles(tiffFilter); + Arrays.sort(found); + for (File file : found) { + files.add(file.getAbsolutePath()); + } + } + + return files.toArray(new String[files.size()]); + } +} diff --git a/components/bio-formats/src/loci/formats/readers.txt b/components/bio-formats/src/loci/formats/readers.txt index 92afd79f8ba..1e1dee4132a 100644 --- a/components/bio-formats/src/loci/formats/readers.txt +++ b/components/bio-formats/src/loci/formats/readers.txt @@ -68,6 +68,7 @@ loci.formats.in.ARFReader # arf loci.formats.in.CellomicsReader # c01 loci.formats.in.LiFlimReader # fli loci.formats.in.TargaReader # tga +loci.formats.in.OxfordInstrumentsReader # top loci.formats.in.FakeReader # fake # multi-extension messes @@ -79,6 +80,7 @@ loci.formats.in.ICSReader # ics, ids loci.formats.in.PerkinElmerReader # rec, ano, csv, htm, tim, zpo, 2, 3, ... loci.formats.in.AmiraReader # am, amiramesh, grey, hx, labels, ... loci.formats.in.ScanrReader # dat, xml, tif +loci.formats.in.BDReader # exp, tif # standard PIC reader must go last (it accepts any PIC) loci.formats.in.BioRadReader # pic @@ -115,6 +117,7 @@ loci.formats.in.ImprovisionTiffReader # tif loci.formats.in.MetamorphTiffReader # tif loci.formats.in.NikonTiffReader # tif loci.formats.in.OMETiffReader # tif +loci.formats.in.PhotoshopTiffReader # tif # standard TIFF reader must go last (it accepts any TIFF) loci.formats.in.TiffDelegateReader # tif, tiff