Changeset 5239


Ignore:
Timestamp:
Feb 9, 2010, 1:27:41 PM (13 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1457: Add support for BFS importer to manual transform creator

The manual transform plug-in can now import BFS files. All files need to be in a directory in the BASE file system. The user should select the metadata file and the other files will be found automatically.

Please run updatedb.sh before testing this.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/DataFileType.java

    r4791 r5239  
    116116  */
    117117  public static String BASEFILE_MATRIX = "basefile.matrix";
     118 
     119  /**
     120    The external ID for the file type representing a BFS
     121    metadata file. The metadata file may reference additional
     122    files.
     123    @since 2.15
     124  */
     125  public static String BFS_METADATA = "bfs.metadata";
    118126 
    119127  /**
  • trunk/src/core/net/sf/basedb/core/Install.java

    r5214 r5239  
    781781        "A matrix BASEFile with spot data",
    782782        Item.BIOASSAYSET, null, spotDataType, null, null);
     783      DataFileTypeData bfsMetadataFile = createDataFileType(
     784          DataFileType.BFS_METADATA, "BFS metadata file",
     785          "The metadata file of a BASE file set. The metadata " +
     786          "file may reference additional files in the [files] section.",
     787          Item.BIOASSAYSET, null, spotDataType, null, null);
    783788      DataFileTypeData mevTdmsFile = createDataFileType(
    784789        DataFileType.MEV_TDMS, "MeV TDMS",
  • trunk/src/plugins/core/net/sf/basedb/plugins/ManualTransformCreator.java

    r5216 r5239  
    3333import net.sf.basedb.core.DataFileType;
    3434import net.sf.basedb.core.DbControl;
     35import net.sf.basedb.core.Directory;
    3536import net.sf.basedb.core.File;
    3637import net.sf.basedb.core.FileParameterType;
    3738import net.sf.basedb.core.FileSet;
     39import net.sf.basedb.core.InvalidDataException;
    3840import net.sf.basedb.core.Item;
    3941import net.sf.basedb.core.ItemNotFoundException;
     
    6163import net.sf.basedb.core.query.Restrictions;
    6264import net.sf.basedb.util.basefile.BaseFileParser;
     65import net.sf.basedb.util.bfs.BaseInputStreamLocator;
     66import net.sf.basedb.util.bfs.GenericExtraFileImporter;
     67import net.sf.basedb.util.bfs.MetadataParser;
    6368import net.sf.basedb.util.importer.spotdata.BaseFileImporter;
     69import net.sf.basedb.util.importer.spotdata.BfsImporter;
    6470
    6571/**
     
    7884  private RequestInformation configurePlugin;
    7985  private List<PluginParameter<?>> toolParameters;
     86 
     87  private List<String> importableFileTypes = Arrays.asList(
     88        DataFileType.BASEFILE_MATRIX,
     89        DataFileType.BASEFILE_SERIAL,
     90        DataFileType.BFS_METADATA);
    8091 
    8192  public ManualTransformCreator()
     
    144155      if (importSpotData)
    145156      {
    146         File file = getBaseFile();
    147         if (file == null)
    148         {
    149           throw new ItemNotFoundException("No serial or matrix BASEfile selected");
    150         }
    151         BaseFileImporter importer = new BaseFileImporter();
    152         BaseFileParser parser = importer.getBaseFileParser();
    153         if (!useBase1ColumnNames)
    154         {
    155           parser.setRedefinedColumnName("spots", "position", "Position");
    156           parser.setRedefinedColumnName("spots", "reporter", "Internal id");
    157           for (int ch = 1; ch <= source.getRawDataType().getChannels(); ++ch)
     157        String fileType = getImportFileType();
     158        if (fileType == null)
     159        {
     160          throw new ItemNotFoundException("You have not selected a file to import from");
     161        }
     162        File file = (File)job.getValue("file." + fileType);
     163        file = File.getById(dc, file.getId());
     164        if (fileType.startsWith("basefile."))
     165        {
     166          BaseFileImporter importer = new BaseFileImporter();
     167          BaseFileParser parser = importer.getBaseFileParser();
     168          if (!useBase1ColumnNames)
    158169          {
    159             parser.setRedefinedColumnName("spots", "intensity" + ch, "Ch " + ch);
     170            parser.setRedefinedColumnName("spots", "position", "Position");
     171            parser.setRedefinedColumnName("spots", "reporter", "Internal id");
     172            for (int ch = 1; ch <= source.getRawDataType().getChannels(); ++ch)
     173            {
     174              parser.setRedefinedColumnName("spots", "intensity" + ch, "Ch " + ch);
     175            }
    160176          }
    161         }
    162         importer.setDbControl(dc);
    163         importer.setSourceFile(file);
    164         importer.setProgressReporter(progress);
    165         importer.setTransformation(t);
    166         child = importer.doImport();
     177          importer.setDbControl(dc);
     178          importer.setSourceFile(file);
     179          importer.setProgressReporter(progress);
     180          importer.setTransformation(t);
     181          child = importer.doImport();
     182        }
     183        else if (fileType.startsWith("bfs."))
     184        {
     185          Directory dir = file.getDirectory();
     186          BfsImporter importer = new BfsImporter();
     187          importer.setDbControl(dc);
     188          importer.setMetadataParser(MetadataParser.create(file));
     189          importer.setInputStreamLocator(new BaseInputStreamLocator(dc, dir));
     190          importer.setExtraFileImporter(new GenericExtraFileImporter(dc, dir, false));
     191          importer.setProgressReporter(progress);
     192          importer.setTransformation(t);
     193          child = importer.doImport();
     194        }
     195        else
     196        {
     197          throw new InvalidDataException("Unknown file type: " + fileType);
     198        }
    167199      }
    168200      if (child == null)
     
    192224            fs.setMember(file, ft);
    193225          }
    194           fs.validate(dc, true);
    195         }
     226        }
     227        fs.validate(dc, true);
    196228      }
    197229      if (allowMoreFiles)
     
    287319      if (importSpotData)
    288320      {
    289         File file = getBaseFile();
    290         if (file == null)
    291         {
    292           response.setError("No serial or matrix BASEfile selected", null);
     321        String fileType = getImportFileType();
     322        if (fileType == null)
     323        {
     324          response.setError("You have not selected a file to import from", null);
    293325        }
    294326        else
     
    354386      BioAssaySet source = getCurrentBioAssaySet(dc);
    355387     
     388      // Check if any of the used file types can be imported
     389      boolean hasImportableFileType = false;
    356390      boolean hasBaseFileType = false;
    357391      for (DataFileType dft : fileTypes)
    358392      {
    359393        String fileTypeId = dft.getExternalId();
    360         if (DataFileType.BASEFILE_SERIAL.equals(fileTypeId) ||
    361           DataFileType.BASEFILE_MATRIX.equals(fileTypeId))
    362         {
    363           hasBaseFileType = true;
     394        if (fileTypeId.startsWith("basefile.")) hasBaseFileType = true;
     395        if (importableFileTypes.contains(fileTypeId))
     396        {
     397          hasImportableFileType = true;
    364398          break;
    365399        }
     
    370404      parameters.add(getSourceBioAssaySetParameter(null, null));
    371405     
    372       if (hasDbData || hasBaseFileType)
     406      if (hasDbData || hasImportableFileType)
    373407      {
    374408        List<String> options = new ArrayList<String>();
    375         if (hasBaseFileType) options.add("import");
     409        if (hasImportableFileType) options.add("import");
    376410        if (hasDbData) options.add("keep");
    377411        options.add("none");
     
    381415          "Select the procedure for creating in-databaes spot data for the " +
    382416          "child bioassay set:\n\n" +
    383           "import = import spot data from a serial or matrix BASEfile " +
    384           "(this option is only available if the tool generates a BASEfile)\n" +
     417          "import = import spot data from the selected file(s) " +
     418          "(this option is only available if the tool generates a BASEfile or " +
     419          "BFS data)\n" +
    385420          "keep = keep the spot data from the parent bioassay set\n" +
    386421          "none = do not create any spot data in the database",
     
    392427            "columnNames",
    393428            "Column names",
    394             "If you have selected Spot data=importer, you may specify which " +
     429            "If you have selected Spot data=import, you may specify which " +
    395430            "type of BASEfile you have:\n\n" +
    396431            "base1 = The file uses BASE 1 column names\n" +
     
    574609  }
    575610 
    576   private File getBaseFile()
    577   {
    578     File file = (File)job.getValue("file." + DataFileType.BASEFILE_MATRIX);
    579     if (file == null)
    580     {
    581       file = (File)job.getValue("file." + DataFileType.BASEFILE_SERIAL);
    582     }
    583     return file;
     611  private String getImportFileType()
     612  {
     613    for (String fileType : importableFileTypes)
     614    {
     615      if (job.getValue("file." + fileType) != null) return fileType;
     616    }
     617    return null;
    584618  }
    585619}
Note: See TracChangeset for help on using the changeset viewer.