Search in sources :

Example 1 with LociImporter

use of loci.plugins.LociImporter in project bioformats by openmicroscopy.

the class Mass_Importer method run.

public void run(String arg) {
    // prompt user for directory to process
    DirectoryChooser dc = new DirectoryChooser("Bio-Formats Mass Importer");
    String dirPath = dc.getDirectory();
    // create a list of files we have already processed
    HashSet<String> done = new HashSet<String>();
    // list of files to actually open with Bio-Formats Importer
    ArrayList<String> filesToOpen = new ArrayList<String>();
    // process all files in the chosen directory
    File dir = new File(dirPath);
    File[] files = dir.listFiles();
    IJ.showStatus("Scanning directory");
    // image reader object, for testing whether a file is in a supported format
    try (ImageReader tester = new ImageReader()) {
        for (int i = 0; i < files.length; i++) {
            String id = files[i].getAbsolutePath();
            IJ.showProgress((double) i / files.length);
            // skip files that have already been processed
            if (done.contains(id))
                continue;
            // skip unsupported files
            if (!tester.isThisType(id, false))
                continue;
            // use FilePattern to group files with similar names
            String name = files[i].getName();
            FilePattern fp = new FilePattern(name, dirPath);
            // get a list of all files part of this group, and mark them as done
            String[] used = fp.getFiles();
            for (int j = 0; j < used.length; j++) done.add(used[j]);
            filesToOpen.add(id);
        }
    } catch (IOException e) {
        IJ.error("Sorry, an error while closing ImageReader: " + e.getMessage());
    }
    IJ.showProgress(1.0);
    IJ.showStatus("");
    // confirm that user wants to proceed in opening the file groups
    int numToOpen = filesToOpen.size();
    if (numToOpen == 0) {
        IJ.showMessage("No file groups found.");
        return;
    }
    String groups = numToOpen == 1 ? "1 file group" : (numToOpen + " file groups");
    YesNoCancelDialog confirm = new YesNoCancelDialog(IJ.getInstance(), "Bio-Formats Mass Importer", "Found " + groups + " in directory '" + dirPath + "'; proceed?");
    if (!confirm.yesPressed())
        return;
    // launch the Bio-Formats Importer plugin to open each group of files
    for (int i = 0; i < numToOpen; i++) {
        String id = (String) filesToOpen.get(i);
        String params = "location=[Local machine] " + "windowless=true " + "groupFiles=true " + "id=[" + id + "] ";
        new LociImporter().run(params);
    }
    IJ.showStatus("");
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) LociImporter(loci.plugins.LociImporter) YesNoCancelDialog(ij.gui.YesNoCancelDialog) FilePattern(loci.formats.FilePattern) ImageReader(loci.formats.ImageReader) File(java.io.File) DirectoryChooser(ij.io.DirectoryChooser) HashSet(java.util.HashSet)

Example 2 with LociImporter

use of loci.plugins.LociImporter in project bioformats by openmicroscopy.

the class Importer method main.

// -- Main method --
/**
 * Main method, for testing.
 */
public static void main(String[] args) {
    new ImageJ(null);
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < args.length; i++) {
        if (i > 0)
            sb.append(" ");
        sb.append(args[i]);
    }
    new LociImporter().run(sb.toString());
}
Also used : ImageJ(ij.ImageJ) LociImporter(loci.plugins.LociImporter)

Aggregations

LociImporter (loci.plugins.LociImporter)2 ImageJ (ij.ImageJ)1 YesNoCancelDialog (ij.gui.YesNoCancelDialog)1 DirectoryChooser (ij.io.DirectoryChooser)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 FilePattern (loci.formats.FilePattern)1 ImageReader (loci.formats.ImageReader)1