Search in sources :

Example 6 with ComboParameter

use of net.sf.mzmine.parameters.parametertypes.ComboParameter in project mzmine2 by mzmine.

the class ScatterPlotAxisSelection method generateOptionsForPeakList.

static ScatterPlotAxisSelection[] generateOptionsForPeakList(PeakList peakList) {
    Vector<ScatterPlotAxisSelection> options = new Vector<ScatterPlotAxisSelection>();
    for (RawDataFile dataFile : peakList.getRawDataFiles()) {
        ScatterPlotAxisSelection newOption = new ScatterPlotAxisSelection(dataFile);
        options.add(newOption);
    }
    for (UserParameter<?, ?> parameter : MZmineCore.getProjectManager().getCurrentProject().getParameters()) {
        if (!(parameter instanceof ComboParameter))
            continue;
        Object[] possibleValues = ((ComboParameter<?>) parameter).getChoices();
        for (Object value : possibleValues) {
            ScatterPlotAxisSelection newOption = new ScatterPlotAxisSelection(parameter, value);
            options.add(newOption);
        }
    }
    return options.toArray(new ScatterPlotAxisSelection[0]);
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Vector(java.util.Vector) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Example 7 with ComboParameter

use of net.sf.mzmine.parameters.parametertypes.ComboParameter in project mzmine2 by mzmine.

the class ScanSelectionComponent method actionPerformed.

public void actionPerformed(ActionEvent event) {
    Object src = event.getSource();
    if (src == setButton) {
        SimpleParameterSet paramSet;
        ExitCode exitCode;
        Window parent = (Window) SwingUtilities.getAncestorOfClass(Window.class, this);
        final IntRangeParameter scanNumParameter = new IntRangeParameter("Scan number", "Range of included scan numbers", false, scanNumberRange);
        final IntegerParameter baseFilteringIntegerParameter = new IntegerParameter("Base Filtering Integer", "Enter an integer for which every multiple of that integer in the list will be filtered. (Every Nth element will be shown)", this.baseFilteringInteger, false);
        final RTRangeParameter rtParameter = new RTRangeParameter(false);
        if (scanRTRange != null)
            rtParameter.setValue(scanRTRange);
        final IntegerParameter msLevelParameter = new IntegerParameter("MS level", "MS level", msLevel, false);
        final StringParameter scanDefinitionParameter = new StringParameter("Scan definition", "Include only scans that match this scan definition. You can use wild cards, e.g. *FTMS*", scanDefinition, false);
        final String[] polarityTypes = { "Any", "+", "-" };
        final ComboParameter<String> polarityParameter = new ComboParameter<>("Polarity", "Include only scans of this polarity", polarityTypes);
        if ((polarity == PolarityType.POSITIVE) || (polarity == PolarityType.NEGATIVE))
            polarityParameter.setValue(polarity.asSingleChar());
        final String[] spectraTypes = { "Any", "Centroided", "Profile", "Thresholded" };
        final ComboParameter<String> spectrumTypeParameter = new ComboParameter<>("Spectrum type", "Include only spectra of this type", spectraTypes);
        if (spectrumType != null) {
            switch(spectrumType) {
                case CENTROIDED:
                    spectrumTypeParameter.setValue(spectraTypes[1]);
                    break;
                case PROFILE:
                    spectrumTypeParameter.setValue(spectraTypes[2]);
                    break;
                case THRESHOLDED:
                    spectrumTypeParameter.setValue(spectraTypes[3]);
                    break;
            }
        }
        paramSet = new SimpleParameterSet(new Parameter[] { scanNumParameter, baseFilteringIntegerParameter, rtParameter, msLevelParameter, scanDefinitionParameter, polarityParameter, spectrumTypeParameter });
        exitCode = paramSet.showSetupDialog(parent, true);
        if (exitCode == ExitCode.OK) {
            scanNumberRange = paramSet.getParameter(scanNumParameter).getValue();
            this.baseFilteringInteger = paramSet.getParameter(baseFilteringIntegerParameter).getValue();
            scanRTRange = paramSet.getParameter(rtParameter).getValue();
            msLevel = paramSet.getParameter(msLevelParameter).getValue();
            scanDefinition = paramSet.getParameter(scanDefinitionParameter).getValue();
            final int selectedPolarityIndex = Arrays.asList(polarityTypes).indexOf(paramSet.getParameter(polarityParameter).getValue());
            switch(selectedPolarityIndex) {
                case 1:
                    polarity = PolarityType.POSITIVE;
                    break;
                case 2:
                    polarity = PolarityType.NEGATIVE;
                    break;
                default:
                    polarity = null;
                    break;
            }
            final int selectedSpectraTypeIndex = Arrays.asList(spectraTypes).indexOf(paramSet.getParameter(spectrumTypeParameter).getValue());
            switch(selectedSpectraTypeIndex) {
                case 1:
                    spectrumType = MassSpectrumType.CENTROIDED;
                    break;
                case 2:
                    spectrumType = MassSpectrumType.PROFILE;
                    break;
                case 3:
                    spectrumType = MassSpectrumType.THRESHOLDED;
                    break;
                default:
                    spectrumType = null;
                    break;
            }
        }
    }
    if (src == clearButton) {
        scanNumberRange = null;
        baseFilteringInteger = null;
        scanRTRange = null;
        polarity = null;
        spectrumType = null;
        msLevel = null;
        scanDefinition = null;
    }
    updateRestrictionList();
}
Also used : Window(java.awt.Window) IntegerParameter(net.sf.mzmine.parameters.parametertypes.IntegerParameter) StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) RTRangeParameter(net.sf.mzmine.parameters.parametertypes.ranges.RTRangeParameter) IntRangeParameter(net.sf.mzmine.parameters.parametertypes.ranges.IntRangeParameter) ExitCode(net.sf.mzmine.util.ExitCode) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter) Parameter(net.sf.mzmine.parameters.Parameter) StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) IntRangeParameter(net.sf.mzmine.parameters.parametertypes.ranges.IntRangeParameter) RTRangeParameter(net.sf.mzmine.parameters.parametertypes.ranges.RTRangeParameter) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter) IntegerParameter(net.sf.mzmine.parameters.parametertypes.IntegerParameter)

Example 8 with ComboParameter

use of net.sf.mzmine.parameters.parametertypes.ComboParameter in project mzmine2 by mzmine.

the class ProjectParametersSetupDialog method setupTableModel.

private void setupTableModel() {
    tablemodelParameterValues = new ParameterTableModel(dataFiles, parameterValues);
    tableParameterValues.setModel(tablemodelParameterValues);
    for (int columnIndex = 0; columnIndex < (tablemodelParameterValues.getColumnCount() - 1); columnIndex++) {
        UserParameter<?, ?> parameter = tablemodelParameterValues.getParameter(columnIndex + 1);
        if (parameter instanceof ComboParameter) {
            Object[] choices = ((ComboParameter<?>) parameter).getChoices();
            tableParameterValues.getColumnModel().getColumn(columnIndex + 1).setCellEditor(new DefaultCellEditor(new JComboBox<Object>(choices)));
        }
    }
}
Also used : JComboBox(javax.swing.JComboBox) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 9 with ComboParameter

use of net.sf.mzmine.parameters.parametertypes.ComboParameter in project mzmine2 by mzmine.

the class MzTabExportTask method run.

public void run() {
    setStatus(TaskStatus.PROCESSING);
    // Shall export several files?
    boolean substitute = fileName.getPath().contains(plNamePattern);
    // Total number of rows
    for (PeakList peakList : peakLists) {
        totalRows += peakList.getNumberOfRows();
    }
    // Process feature lists
    for (PeakList peakList : peakLists) {
        File curFile = fileName;
        try {
            // Filename
            if (substitute) {
                // Cleanup from illegal filename characters
                String cleanPlName = peakList.getName().replaceAll("[^a-zA-Z0-9.-]", "_");
                // Substitute
                String newFilename = fileName.getPath().replaceAll(Pattern.quote(plNamePattern), cleanPlName);
                curFile = new File(newFilename);
            }
            // Open file
            FileWriter writer;
            try {
                writer = new FileWriter(curFile);
            } catch (Exception e) {
                setStatus(TaskStatus.ERROR);
                setErrorMessage("Could not open file " + curFile + " for writing.");
                return;
            }
            // Metadata
            Metadata mtd = new Metadata();
            mtd.setMZTabMode(MZTabDescription.Mode.Summary);
            mtd.setMZTabType(MZTabDescription.Type.Quantification);
            mtd.setDescription(peakList.getName());
            mtd.addSoftwareParam(1, new CVParam("MS", "MS:1002342", "MZmine", MZmineCore.getMZmineVersion()));
            mtd.setSmallMoleculeQuantificationUnit(new CVParam("PRIDE", "PRIDE:0000330", "Arbitrary quantification unit", null));
            mtd.addSmallMoleculeSearchEngineScoreParam(1, new CVParam("MS", "MS:1001153", "search engine specific score", null));
            mtd.addFixedModParam(1, new CVParam("MS", "MS:1002453", "No fixed modifications searched", null));
            mtd.addVariableModParam(1, new CVParam("MS", "MS:1002454", "No variable modifications searched", null));
            // Create stable columns
            MZTabColumnFactory factory = MZTabColumnFactory.getInstance(Section.Small_Molecule);
            factory.addDefaultStableColumns();
            // Add optional columns which have stable order
            factory.addURIOptionalColumn();
            factory.addBestSearchEngineScoreOptionalColumn(SmallMoleculeColumn.BEST_SEARCH_ENGINE_SCORE, 1);
            final RawDataFile[] rawDataFiles = peakList.getRawDataFiles();
            int fileCounter = 0;
            for (RawDataFile file : rawDataFiles) {
                fileCounter++;
                /**
                 * TO DO: Add path to original imported raw file to MZmine and write it out here instead
                 */
                // MS run location
                MsRun msRun = new MsRun(fileCounter);
                msRun.setLocation(new URL("file:///" + file.getName()));
                mtd.addMsRun(msRun);
                mtd.addAssayMsRun(fileCounter, msRun);
                // Add samples to study variable assay
                for (UserParameter<?, ?> p : project.getParameters()) {
                    Assay assay = mtd.getAssayMap().get(fileCounter);
                    for (StudyVariable studyVariable : mtd.getStudyVariableMap().values()) {
                        if (studyVariable.getDescription().equals(String.valueOf(p) + ": " + String.valueOf(project.getParameterValue(p, file)))) {
                            mtd.addStudyVariableAssay(studyVariable.getId(), assay);
                        }
                    }
                }
                // Additional columns
                factory.addAbundanceOptionalColumn(new Assay(fileCounter));
                factory.addOptionalColumn(new Assay(fileCounter), "peak_mz", String.class);
                factory.addOptionalColumn(new Assay(fileCounter), "peak_rt", String.class);
                factory.addOptionalColumn(new Assay(fileCounter), "peak_height", String.class);
            }
            // Variable descriptions
            int parameterCounter = 0;
            for (UserParameter<?, ?> p : project.getParameters()) {
                for (Object e : ((ComboParameter<?>) p).getChoices()) {
                    parameterCounter++;
                    mtd.addStudyVariableDescription(parameterCounter, String.valueOf(p) + ": " + String.valueOf(e));
                    StudyVariable studyVariable = new StudyVariable(parameterCounter);
                    factory.addAbundanceOptionalColumn(studyVariable);
                }
            }
            // Write to file
            BufferedWriter out = new BufferedWriter(writer);
            out.write(mtd.toString());
            out.write(newLine);
            out.write(factory.toString());
            out.write(newLine);
            // Write data rows
            for (PeakListRow peakListRow : peakList.getRows()) {
                // Cancel?
                if (isCanceled()) {
                    return;
                }
                PeakIdentity peakIdentity = peakListRow.getPreferredPeakIdentity();
                if (exportall || peakIdentity != null) {
                    SmallMolecule sm = new SmallMolecule(factory, mtd);
                    if (peakIdentity != null) {
                        // Identity information
                        String identifier = escapeString(peakIdentity.getPropertyValue("ID"));
                        String database = peakIdentity.getPropertyValue("Identification method");
                        String formula = peakIdentity.getPropertyValue("Molecular formula");
                        String description = escapeString(peakIdentity.getPropertyValue("Name"));
                        String url = peakIdentity.getPropertyValue("URL");
                        if (identifier != null) {
                            sm.setIdentifier(identifier);
                        }
                        if (database != null) {
                            sm.setDatabase(database);
                        }
                        if (formula != null) {
                            sm.setChemicalFormula(formula);
                        }
                        if (description != null) {
                            sm.setDescription(description);
                        }
                        if (url != null) {
                            sm.setURI(url);
                        }
                    }
                    Double rowMZ = peakListRow.getAverageMZ();
                    int rowCharge = peakListRow.getRowCharge();
                    String rowRT = String.valueOf(peakListRow.getAverageRT());
                    if (rowMZ != null) {
                        sm.setExpMassToCharge(rowMZ);
                    }
                    if (rowCharge > 0) {
                        sm.setCharge(rowCharge);
                    }
                    if (rowRT != null) {
                        sm.setRetentionTime(rowRT);
                    }
                    int dataFileCount = 0;
                    for (RawDataFile dataFile : rawDataFiles) {
                        dataFileCount++;
                        Feature peak = peakListRow.getPeak(dataFile);
                        if (peak != null) {
                            String peakMZ = String.valueOf(peak.getMZ());
                            String peakRT = String.valueOf(String.valueOf(peak.getRT()));
                            String peakHeight = String.valueOf(peak.getHeight());
                            Double peakArea = peak.getArea();
                            sm.setOptionColumnValue(new Assay(dataFileCount), "peak_mz", peakMZ);
                            sm.setOptionColumnValue(new Assay(dataFileCount), "peak_rt", peakRT);
                            sm.setOptionColumnValue(new Assay(dataFileCount), "peak_height", peakHeight);
                            sm.setAbundanceColumnValue(new Assay(dataFileCount), peakArea);
                        }
                    }
                    out.write(sm.toString());
                    out.write(newLine);
                }
            }
            out.flush();
            out.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            setStatus(TaskStatus.ERROR);
            setErrorMessage("Could not export feature list to file " + curFile + ": " + e.getMessage());
            return;
        }
    }
    if (getStatus() == TaskStatus.PROCESSING)
        setStatus(TaskStatus.FINISHED);
}
Also used : FileWriter(java.io.FileWriter) Metadata(uk.ac.ebi.pride.jmztab.model.Metadata) CVParam(uk.ac.ebi.pride.jmztab.model.CVParam) Feature(net.sf.mzmine.datamodel.Feature) URL(java.net.URL) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter) BufferedWriter(java.io.BufferedWriter) Assay(uk.ac.ebi.pride.jmztab.model.Assay) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) MsRun(uk.ac.ebi.pride.jmztab.model.MsRun) StudyVariable(uk.ac.ebi.pride.jmztab.model.StudyVariable) MZTabColumnFactory(uk.ac.ebi.pride.jmztab.model.MZTabColumnFactory) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SmallMolecule(uk.ac.ebi.pride.jmztab.model.SmallMolecule) PeakList(net.sf.mzmine.datamodel.PeakList) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) File(java.io.File)

Example 10 with ComboParameter

use of net.sf.mzmine.parameters.parametertypes.ComboParameter in project mzmine2 by mzmine.

the class UserParameterOpenHandler_2_5 method startElement.

/**
 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String,
 *      java.lang.String, org.xml.sax.Attributes)
 */
public void startElement(String namespaceURI, String lName, String qName, Attributes attrs) throws SAXException {
    if (canceled)
        throw new SAXException("Parsing canceled");
    // <PARAMETERS>
    if (qName.equals(UserParameterElementName_2_5.PARAMETERS.getElementName())) {
        String count = attrs.getValue(UserParameterElementName_2_5.COUNT.getElementName());
        totalParams = Integer.parseInt(count);
    }
    // <PARAMETER>
    if (qName.equals(UserParameterElementName_2_5.PARAMETER.getElementName())) {
        String name = attrs.getValue(UserParameterElementName_2_5.NAME.getElementName());
        String type = attrs.getValue(UserParameterElementName_2_5.TYPE.getElementName());
        if (type.equals(DoubleParameter.class.getSimpleName())) {
            currentParameter = new DoubleParameter(name, null);
        } else if (type.equals(StringParameter.class.getSimpleName())) {
            currentParameter = new StringParameter(name, null);
        } else if (type.equals(ComboParameter.class.getSimpleName())) {
            currentParameter = new ComboParameter<String>(name, null, new String[0]);
        } else {
            throw new SAXException("Unknown parameter type: " + type);
        }
        logger.finest("Loading parameter " + name);
        currentOptions.clear();
        currentValues.clear();
    }
    // <VALUE>
    if (qName.equals(UserParameterElementName_2_5.VALUE.getElementName())) {
        currentDataFileID = attrs.getValue(UserParameterElementName_2_5.DATA_FILE.getElementName());
    }
}
Also used : StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) SAXException(org.xml.sax.SAXException) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Aggregations

ComboParameter (net.sf.mzmine.parameters.parametertypes.ComboParameter)11 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)6 DoubleParameter (net.sf.mzmine.parameters.parametertypes.DoubleParameter)6 StringParameter (net.sf.mzmine.parameters.parametertypes.StringParameter)4 SAXException (org.xml.sax.SAXException)4 Parameter (net.sf.mzmine.parameters.Parameter)2 SimpleParameterSet (net.sf.mzmine.parameters.impl.SimpleParameterSet)2 ExitCode (net.sf.mzmine.util.ExitCode)2 Color (java.awt.Color)1 Window (java.awt.Window)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 URL (java.net.URL)1 Vector (java.util.Vector)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 JComboBox (javax.swing.JComboBox)1 Feature (net.sf.mzmine.datamodel.Feature)1 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)1 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)1