コード例 #1
0
ファイル: RowFilterMethodTest.java プロジェクト: dyrlund/msdk
  @SuppressWarnings("null")
  @Test
  public void testOrbitrap() throws MSDKException {

    // Create the data structures
    final DataPointStore dataStore = DataPointStoreFactory.getMemoryDataStore();

    // Import the file
    File inputFile = new File(TEST_DATA_PATH + "orbitrap_300-600mz.mzML");
    Assert.assertTrue("Cannot read test data", inputFile.canRead());
    MzMLFileImportMethod importer = new MzMLFileImportMethod(inputFile);
    RawDataFile rawFile = importer.execute();
    Assert.assertNotNull(rawFile);
    Assert.assertEquals(1.0, importer.getFinishedPercentage(), 0.0001);

    // Ion 1
    List<IonAnnotation> ionAnnotations = new ArrayList<IonAnnotation>();
    IonAnnotation ion1 = MSDKObjectBuilder.getSimpleIonAnnotation();
    ion1.setExpectedMz(332.56);
    ion1.setAnnotationId("Feature 332.56");
    ion1.setChromatographyInfo(
        MSDKObjectBuilder.getChromatographyInfo1D(SeparationType.LC, (float) 772.8));
    ionAnnotations.add(ion1);

    // Ion 2
    IonAnnotation ion2 = MSDKObjectBuilder.getSimpleIonAnnotation();
    ion2.setExpectedMz(508.004);
    ion2.setAnnotationId("Feature 508.004");
    ion2.setChromatographyInfo(
        MSDKObjectBuilder.getChromatographyInfo1D(SeparationType.LC, (float) 868.8));
    ionAnnotations.add(ion2);

    // Ion 3
    IonAnnotation ion3 = MSDKObjectBuilder.getSimpleIonAnnotation();
    ion3.setExpectedMz(362.102);
    ion3.setAnnotationId("Feature 362.102");
    ion3.setChromatographyInfo(
        MSDKObjectBuilder.getChromatographyInfo1D(SeparationType.LC, (float) 643.2));
    ionAnnotations.add(ion3);

    // Variables
    final MZTolerance mzTolerance = new MZTolerance(0.003, 5.0);
    final RTTolerance rtTolerance = new RTTolerance(3, false);
    final Double intensityTolerance = 0.10d;
    final Double noiseLevel = 5000d;

    TargetedDetectionMethod chromBuilder =
        new TargetedDetectionMethod(
            ionAnnotations,
            rawFile,
            dataStore,
            mzTolerance,
            rtTolerance,
            intensityTolerance,
            noiseLevel);
    final List<Chromatogram> chromatograms = chromBuilder.execute();
    Assert.assertEquals(1.0, chromBuilder.getFinishedPercentage(), 0.0001);
    Assert.assertNotNull(chromatograms);
    Assert.assertEquals(3, chromatograms.size());

    // Create a new feature table
    FeatureTable featureTable = MSDKObjectBuilder.getFeatureTable("orbitrap_300-600mz", dataStore);
    Sample sample = MSDKObjectBuilder.getSimpleSample("orbitrap_300-600mz");

    ChromatogramToFeatureTableMethod tableBuilder =
        new ChromatogramToFeatureTableMethod(chromatograms, featureTable, sample);
    tableBuilder.execute();

    // 1. Filter parameters
    boolean filterByMz = true;
    boolean filterByRt = true;
    boolean filterByDuration = true;
    boolean filterByCount = true;
    boolean filterByIsotopes = true;
    boolean filterByIonAnnotation = true;
    boolean requireAnnotation = false;
    boolean removeDuplicates = false;
    boolean duplicateRequireSameID = true;
    Range<Double> mzRange = Range.closed(300.0, 600.0);
    Range<Double> rtRange = Range.closed(600.0, 900.0); // Seconds
    Range<Double> durationRange = Range.closed(0.0, 47.0); // Seconds
    final MZTolerance duplicateMzTolerance = new MZTolerance(0.003, 5.0);
    final RTTolerance duplicateRtTolerance = new RTTolerance(0.2, false);
    int minCount = 1;
    int minIsotopes = 1;
    String ionAnnotation = null;
    String nameSuffix = "-rowFiltered";

    // 1. Filter the rows
    RowFilterMethod filterMethod =
        new RowFilterMethod(
            featureTable,
            dataStore,
            nameSuffix,
            filterByMz,
            filterByRt,
            filterByDuration,
            filterByCount,
            filterByIsotopes,
            filterByIonAnnotation,
            requireAnnotation,
            mzRange,
            rtRange,
            durationRange,
            minCount,
            minIsotopes,
            ionAnnotation,
            removeDuplicates,
            duplicateMzTolerance,
            duplicateRtTolerance,
            duplicateRequireSameID);
    filterMethod.execute();
    Assert.assertEquals(1.0, filterMethod.getFinishedPercentage(), 0.0001);

    // 1. Verify data
    FeatureTable filteredTable = filterMethod.getResult();
    Assert.assertNotNull(filteredTable);
    Assert.assertEquals(3, filteredTable.getRows().size());

    // 2. Filter parameters
    mzRange = Range.closed(350.0, 600.0);
    durationRange = Range.closed(46.0, 47.0); // Seconds

    // 2. Filter the features
    filterMethod =
        new RowFilterMethod(
            featureTable,
            dataStore,
            nameSuffix,
            filterByMz,
            filterByRt,
            filterByDuration,
            filterByCount,
            filterByIsotopes,
            filterByIonAnnotation,
            requireAnnotation,
            mzRange,
            rtRange,
            durationRange,
            minCount,
            minIsotopes,
            ionAnnotation,
            removeDuplicates,
            duplicateMzTolerance,
            duplicateRtTolerance,
            duplicateRequireSameID);
    filterMethod.execute();
    Assert.assertEquals(1.0, filterMethod.getFinishedPercentage(), 0.0001);

    // 2. Verify data
    filteredTable = filterMethod.getResult();
    Assert.assertNotNull(filteredTable);
    Assert.assertEquals(1, filteredTable.getRows().size());

    // 3. Filter parameters
    minCount = 2;

    // 3. Filter the features
    filterMethod =
        new RowFilterMethod(
            filteredTable,
            dataStore,
            nameSuffix,
            filterByMz,
            filterByRt,
            filterByDuration,
            filterByCount,
            filterByIsotopes,
            filterByIonAnnotation,
            requireAnnotation,
            mzRange,
            rtRange,
            durationRange,
            minCount,
            minIsotopes,
            ionAnnotation,
            removeDuplicates,
            duplicateMzTolerance,
            duplicateRtTolerance,
            duplicateRequireSameID);
    filterMethod.execute();
    Assert.assertEquals(1.0, filterMethod.getFinishedPercentage(), 0.0001);

    // 3. Verify data
    filteredTable = filterMethod.getResult();
    Assert.assertNotNull(filteredTable);
    Assert.assertEquals(0, filteredTable.getRows().size());

    featureTable.dispose();
    filteredTable.dispose();
  }
コード例 #2
0
  @Override
  public void runModule(
      @Nonnull MZmineProject project,
      @Nonnull ParameterSet parameters,
      @Nonnull Collection<Task<?>> tasks) {

    // Boolean values
    Boolean filterByDuration = parameters.getParameter(FeatureFilterParameters.duration).getValue();
    Boolean filterByArea = parameters.getParameter(FeatureFilterParameters.area).getValue();
    Boolean filterByHeight = parameters.getParameter(FeatureFilterParameters.height).getValue();
    Boolean filterByDataPoints =
        parameters.getParameter(FeatureFilterParameters.dataPoints).getValue();
    Boolean filterByFWHM = parameters.getParameter(FeatureFilterParameters.fwhm).getValue();
    Boolean filterByTailingFactor =
        parameters.getParameter(FeatureFilterParameters.tailingFactor).getValue();
    Boolean filterByAsymmetryFactor =
        parameters.getParameter(FeatureFilterParameters.asymmetryFactor).getValue();

    // Default values
    if (filterByDuration == null) filterByDuration = false;
    if (filterByArea == null) filterByArea = false;
    if (filterByHeight == null) filterByHeight = false;
    if (filterByDataPoints == null) filterByDataPoints = false;
    if (filterByFWHM == null) filterByFWHM = false;
    if (filterByTailingFactor == null) filterByTailingFactor = false;
    if (filterByAsymmetryFactor == null) filterByAsymmetryFactor = false;

    // Embedded values
    final Range<Double> durationRange =
        parameters.getParameter(FeatureFilterParameters.duration).getEmbeddedParameter().getValue();
    final Range<Double> areaRange =
        parameters.getParameter(FeatureFilterParameters.area).getEmbeddedParameter().getValue();
    final Range<Double> heightRange =
        parameters.getParameter(FeatureFilterParameters.height).getEmbeddedParameter().getValue();
    final Range<Integer> dataPointsRange =
        parameters
            .getParameter(FeatureFilterParameters.dataPoints)
            .getEmbeddedParameter()
            .getValue();
    final Range<Double> fwhmRange =
        parameters.getParameter(FeatureFilterParameters.fwhm).getEmbeddedParameter().getValue();
    final Range<Double> tailingFactorRange =
        parameters
            .getParameter(FeatureFilterParameters.tailingFactor)
            .getEmbeddedParameter()
            .getValue();
    final Range<Double> asymmetryFactorRange =
        parameters
            .getParameter(FeatureFilterParameters.asymmetryFactor)
            .getEmbeddedParameter()
            .getValue();

    // Other values
    final FeatureTablesSelection featureTables =
        parameters.getParameter(FeatureFilterParameters.featureTables).getValue();
    final Boolean removeOldTable =
        parameters.getParameter(FeatureFilterParameters.removeOldTable).getValue();
    final String nameSuffix =
        parameters.getParameter(FeatureFilterParameters.nameSuffix).getValue();

    if (featureTables == null || featureTables.getMatchingFeatureTables().isEmpty()) {
      MZmineGUI.displayMessage("Feature filter module started with no feature table selected.");
      logger.warn("Feature filter module started with no feature table selected.");
      return;
    }

    // Check if at least one filter is selected
    if (!filterByDuration
        && !filterByArea
        && !filterByHeight
        && !filterByDataPoints
        && !filterByFWHM
        && !filterByTailingFactor
        && !filterByAsymmetryFactor) {
      MZmineGUI.displayMessage("Feature filter module started with no filter selected.");
      logger.warn("Feature filter module started with no filter selected.");
      return;
    }

    // Add a task for each feature table
    for (FeatureTable featureTable : featureTables.getMatchingFeatureTables()) {

      // Create the data structures
      DataPointStore dataStore = DataPointStoreFactory.getMemoryDataStore();

      // New feature filter task
      FeatureFilterMethod method =
          new FeatureFilterMethod(
              featureTable,
              dataStore,
              filterByDuration,
              filterByArea,
              filterByHeight,
              filterByDataPoints,
              filterByFWHM,
              filterByTailingFactor,
              filterByAsymmetryFactor,
              durationRange,
              areaRange,
              heightRange,
              dataPointsRange,
              fwhmRange,
              tailingFactorRange,
              asymmetryFactorRange,
              nameSuffix);

      MSDKTask newTask =
          new MSDKTask("Filtering features in tables", featureTable.getName(), method);

      // Add the feature table to the project
      newTask.setOnSucceeded(
          e -> {
            FeatureTable newFeatureTable = method.getResult();
            project.addFeatureTable(newFeatureTable);

            // If selected, remove old feature table
            if (removeOldTable != null && removeOldTable) {
              project.removeFeatureTable(featureTable);
            }
          });

      // Add the task to the queue
      tasks.add(newTask);
    }
  }