Search in sources :

Example 1 with BackgroundSpeciesDialog

use of com.compomics.util.gui.parameters.identification.advanced.BackgroundSpeciesDialog in project peptide-shaker by compomics.

the class PeptideShakerGUI method speciesJMenuItemActionPerformed.

// GEN-LAST:event_exportProjectMenuItemActionPerformed
/**
 * Open the species selection dialog.
 *
 * @param evt
 */
private void speciesJMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
    try {
        IdentificationParameters identificationParameters = getIdentificationParameters();
        GeneParameters geneParameters = identificationParameters.getGeneParameters();
        FastaSummary fastaSummary = FastaSummary.getSummary(getProjectDetails().getFastaFile(), identificationParameters.getFastaParameters(), null);
        BackgroundSpeciesDialog backgroundSpeciesDialog = new BackgroundSpeciesDialog(this, geneParameters, fastaSummary);
        if (!backgroundSpeciesDialog.isCanceled()) {
            geneParameters = backgroundSpeciesDialog.getGeneParameters();
            identificationParameters.setGeneParameters(geneParameters);
            if (allTabsJTabbedPane.getSelectedIndex() == GO_ANALYSIS_TAB_INDEX) {
                goPanel.updateMappings();
            } else {
                updateNeeded.put(GO_ANALYSIS_TAB_INDEX, true);
            }
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, new String[] { "FASTA Import Error.", "File " + getProjectDetails().getFastaFile() + " could not be imported." }, "FASTA Import Error", JOptionPane.WARNING_MESSAGE);
        e.printStackTrace();
    }
}
Also used : GeneParameters(com.compomics.util.parameters.identification.advanced.GeneParameters) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) FastaSummary(com.compomics.util.experiment.io.biology.protein.FastaSummary) ConnectException(java.net.ConnectException) UnknownHostException(java.net.UnknownHostException) BackgroundSpeciesDialog(com.compomics.util.gui.parameters.identification.advanced.BackgroundSpeciesDialog)

Example 2 with BackgroundSpeciesDialog

use of com.compomics.util.gui.parameters.identification.advanced.BackgroundSpeciesDialog in project peptide-shaker by compomics.

the class GOEAPanel method displayResults.

/**
 * Update the GO mappings.
 */
public void displayResults() {
    if (peptideShakerGUI.getIdentification() != null) {
        GeneMaps geneMaps = peptideShakerGUI.getGeneMaps();
        if (geneMaps.hasGoMappings()) {
            progressDialog = new ProgressDialogX(peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true);
            progressDialog.setTitle("Getting GO Mappings. Please Wait...");
            progressDialog.setPrimaryProgressCounterIndeterminate(true);
            new Thread(new Runnable() {

                public void run() {
                    try {
                        progressDialog.setVisible(true);
                    } catch (IndexOutOfBoundsException e) {
                    // ignore
                    }
                }
            }, "ProgressDialog").start();
            new Thread("GoThread") {

                @Override
                public void run() {
                    // clear old table
                    DefaultTableModel dm = (DefaultTableModel) goMappingsTable.getModel();
                    dm.getDataVector().removeAllElements();
                    dm.fireTableDataChanged();
                    TreeMap<String, Integer> datasetGoTermUsage = new TreeMap<>();
                    try {
                        progressDialog.setTitle("Importing GO (1/3). Please Wait...");
                        GoMapping backgroundGoMapping = new GoMapping();
                        Integer taxon = null;
                        IdentificationParameters identificationParameters = peptideShakerGUI.getIdentificationParameters();
                        GeneParameters genePreferences = identificationParameters.getGeneParameters();
                        if (genePreferences != null) {
                            taxon = genePreferences.getBackgroundSpecies();
                        }
                        if (taxon == null) {
                            FastaSummary fastaSummary = FastaSummary.getSummary(peptideShakerGUI.getProjectDetails().getFastaFile(), identificationParameters.getFastaParameters(), progressDialog);
                            BackgroundSpeciesDialog backgroundSpeciesDialog = new BackgroundSpeciesDialog(peptideShakerGUI, genePreferences, fastaSummary);
                            if (!backgroundSpeciesDialog.isCanceled()) {
                                genePreferences = backgroundSpeciesDialog.getGeneParameters();
                                identificationParameters.setGeneParameters(genePreferences);
                                taxon = genePreferences.getBackgroundSpecies();
                            }
                        }
                        if (taxon != null) {
                            SpeciesFactory speciesFactory = SpeciesFactory.getInstance();
                            String ensemblDatasetName = speciesFactory.getEnsemblDataset(taxon);
                            File goMappingFile = ProteinGeneDetailsProvider.getGoMappingFile(ensemblDatasetName);
                            backgroundGoMapping.loadMappingsFromFile(goMappingFile, progressDialog);
                            GoDomains goDomains = new GoDomains();
                            File goDomainsFile = ProteinGeneDetailsProvider.getGoDomainsFile();
                            goDomains.laodMappingFromFile(goDomainsFile, progressDialog);
                            Identification identification = peptideShakerGUI.getIdentification();
                            progressDialog.setTitle("Getting GO Mappings (2/3). Please Wait...");
                            progressDialog.setPrimaryProgressCounterIndeterminate(false);
                            progressDialog.setMaxPrimaryProgressCounter(identification.getProteinIdentification().size());
                            progressDialog.setValue(0);
                            int totalNumberOfGoMappedProteinsInProject = 0;
                            ProteinMatchesIterator proteinMatchesIterator = identification.getProteinMatchesIterator(progressDialog);
                            ProteinMatch proteinMatch;
                            while ((proteinMatch = proteinMatchesIterator.next()) != null) {
                                PSParameter psParameter = (PSParameter) proteinMatch.getUrParam(PSParameter.dummy);
                                if (psParameter.getMatchValidationLevel().isValidated() && !proteinMatch.isDecoy() && !psParameter.getHidden()) {
                                    String mainMatch = proteinMatch.getLeadingAccession();
                                    HashSet<String> goTerms = backgroundGoMapping.getGoAccessions(mainMatch);
                                    if (goTerms != null && !goTerms.isEmpty()) {
                                        totalNumberOfGoMappedProteinsInProject++;
                                        for (String goTerm : goTerms) {
                                            Integer usage = datasetGoTermUsage.get(goTerm);
                                            if (usage == null) {
                                                usage = 0;
                                            }
                                            datasetGoTermUsage.put(goTerm, usage + 1);
                                        }
                                    }
                                }
                                if (progressDialog.isRunCanceled()) {
                                    return;
                                }
                                progressDialog.increasePrimaryProgressCounter();
                            }
                            ArrayList<String> termNamesMapped = backgroundGoMapping.getSortedTermNames();
                            int nBackgroundProteins = backgroundGoMapping.getProteinToGoMap().size();
                            progressDialog.setTitle("Creating GO Plots (3/3). Please Wait...");
                            progressDialog.setValue(0);
                            progressDialog.setMaxPrimaryProgressCounter(termNamesMapped.size());
                            // update the table
                            Double maxLog2Diff = 0.0;
                            ArrayList<Integer> indexes = new ArrayList<>();
                            ArrayList<Double> pValues = new ArrayList<>();
                            // display the number of go mapped proteins
                            goProteinCountLabel.setText("[GO Proteins: Ensembl: " + nBackgroundProteins + ", Project: " + totalNumberOfGoMappedProteinsInProject + "]");
                            boolean goDomainChanged = false;
                            for (String goTermName : termNamesMapped) {
                                if (progressDialog.isRunCanceled()) {
                                    break;
                                }
                                String goAccession = backgroundGoMapping.getTermAccession(goTermName);
                                Integer frequencyBackground = backgroundGoMapping.getProteinAccessions(goAccession).size();
                                Integer frequencyDataset = 0;
                                Double percentDataset = 0.0;
                                if (datasetGoTermUsage.get(goAccession) != null) {
                                    frequencyDataset = datasetGoTermUsage.get(goAccession);
                                    percentDataset = ((double) frequencyDataset) * 100 / totalNumberOfGoMappedProteinsInProject;
                                }
                                Double percentAll = ((double) frequencyBackground) * 100 / nBackgroundProteins;
                                Double pValue = new HypergeometricDistributionImpl(// population size
                                nBackgroundProteins, // number of successes
                                frequencyBackground, // sample size
                                totalNumberOfGoMappedProteinsInProject).probability(frequencyDataset);
                                Double log2Diff = Math.log(percentDataset / percentAll) / Math.log(2);
                                if (!log2Diff.isInfinite() && Math.abs(log2Diff) > maxLog2Diff) {
                                    maxLog2Diff = Math.abs(log2Diff);
                                }
                                String goDomain = goDomains.getTermDomain(goAccession);
                                if (goDomain == null) {
                                    // URL to the JSON file for the given GO term
                                    URL u = new URL("https://www.ebi.ac.uk/QuickGO/services/ontology/go/terms/" + goAccession);
                                    JsonMarshaller jsonMarshaller = new JsonMarshaller();
                                    QuickGoTerm result = (QuickGoTerm) jsonMarshaller.fromJson(QuickGoTerm.class, u);
                                    // get the domain
                                    for (DummyResults tempResult : result.results) {
                                        goDomain = tempResult.aspect;
                                    }
                                    // add the domain to the list
                                    goDomains.addDomain(goAccession, goDomain);
                                    goDomainChanged = true;
                                }
                                // add the data points for the first data series
                                ArrayList<Double> dataAll = new ArrayList<>();
                                dataAll.add(percentAll);
                                ArrayList<Double> dataDataset = new ArrayList<>();
                                dataDataset.add(percentDataset);
                                // create a JSparklineDataSeries
                                JSparklinesDataSeries sparklineDataseriesAll = new JSparklinesDataSeries(dataAll, Color.RED, "All");
                                JSparklinesDataSeries sparklineDataseriesDataset = new JSparklinesDataSeries(dataDataset, peptideShakerGUI.getSparklineColor(), "Dataset");
                                // add the data series to JSparklineDataset
                                ArrayList<JSparklinesDataSeries> sparkLineDataSeries = new ArrayList<>();
                                sparkLineDataSeries.add(sparklineDataseriesAll);
                                sparkLineDataSeries.add(sparklineDataseriesDataset);
                                JSparklinesDataset dataset = new JSparklinesDataset(sparkLineDataSeries);
                                pValues.add(pValue);
                                indexes.add(goMappingsTable.getRowCount());
                                ((DefaultTableModel) goMappingsTable.getModel()).addRow(new Object[] { goMappingsTable.getRowCount() + 1, peptideShakerGUI.getDisplayFeaturesGenerator().addGoLink(goAccession), goTermName, goDomain, percentAll, percentDataset, dataset, new ValueAndBooleanDataPoint(log2Diff, false), pValue, true });
                                progressDialog.increasePrimaryProgressCounter();
                            }
                            if (indexes.isEmpty()) {
                                progressDialog.setRunCanceled();
                            }
                            int significantCounter = 0;
                            double significanceLevel = 0.05;
                            if (onePercentRadioButton.isSelected()) {
                                significanceLevel = 0.01;
                            }
                            if (!progressDialog.isRunCanceled()) {
                                ((DefaultTableModel) goMappingsTable.getModel()).fireTableDataChanged();
                                // correct the p-values for multiple testing using benjamini-hochberg
                                sortPValues(pValues, indexes);
                                ((ValueAndBooleanDataPoint) ((DefaultTableModel) goMappingsTable.getModel()).getValueAt(indexes.get(0), goMappingsTable.getColumn("Log2 Diff").getModelIndex())).setSignificant(pValues.get(0) < significanceLevel);
                                ((DefaultTableModel) goMappingsTable.getModel()).setValueAt(new XYDataPoint(pValues.get(0), pValues.get(0)), indexes.get(0), goMappingsTable.getColumn("p-value").getModelIndex());
                                if (pValues.get(0) < significanceLevel) {
                                    significantCounter++;
                                }
                                for (int i = 1; i < pValues.size(); i++) {
                                    if (progressDialog.isRunCanceled()) {
                                        break;
                                    }
                                    double tempPvalue = pValues.get(i) * pValues.size() / (pValues.size() - i);
                                    // have to check if the correction results in a p-value bigger than 1
                                    if (tempPvalue > 1) {
                                        tempPvalue = 1;
                                    }
                                    ((ValueAndBooleanDataPoint) ((DefaultTableModel) goMappingsTable.getModel()).getValueAt(indexes.get(i), goMappingsTable.getColumn("Log2 Diff").getModelIndex())).setSignificant(tempPvalue < significanceLevel);
                                    ((DefaultTableModel) goMappingsTable.getModel()).setValueAt(new XYDataPoint(tempPvalue, tempPvalue), indexes.get(i), goMappingsTable.getColumn("p-value").getModelIndex());
                                    if (tempPvalue < significanceLevel) {
                                        significantCounter++;
                                    }
                                }
                            }
                            if (!progressDialog.isRunCanceled()) {
                                ((TitledBorder) mappingsPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "Gene Ontology Mappings (" + significantCounter + "/" + goMappingsTable.getRowCount() + ")" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
                                mappingsPanel.repaint();
                                progressDialog.setPrimaryProgressCounterIndeterminate(true);
                                // set the preferred size of the accession column
                                Integer width = ProteinTableModel.getPreferredAccessionColumnWidth(goMappingsTable, goMappingsTable.getColumn("GO Accession").getModelIndex(), 6, peptideShakerGUI.getMetrics().getMaxProteinAccessionLength());
                                if (width != null) {
                                    goMappingsTable.getColumn("GO Accession").setMinWidth(width);
                                    goMappingsTable.getColumn("GO Accession").setMaxWidth(width);
                                } else {
                                    goMappingsTable.getColumn("GO Accession").setMinWidth(15);
                                    goMappingsTable.getColumn("GO Accession").setMaxWidth(Integer.MAX_VALUE);
                                }
                                maxLog2Diff = Math.ceil(maxLog2Diff);
                                goMappingsTable.getColumn("Log2 Diff").setCellRenderer(new JSparklinesBarChartTableCellRenderer(PlotOrientation.HORIZONTAL, -maxLog2Diff, maxLog2Diff, Color.RED, peptideShakerGUI.getSparklineColor(), Color.lightGray, 0));
                                ((JSparklinesBarChartTableCellRenderer) goMappingsTable.getColumn("Log2 Diff").getCellRenderer()).showNumberAndChart(true, TableProperties.getLabelWidth());
                                // update the plots
                                updateGoPlots();
                                // enable the contextual export options
                                exportMappingsJButton.setEnabled(true);
                                exportPlotsJButton.setEnabled(true);
                                peptideShakerGUI.setUpdated(PeptideShakerGUI.GO_ANALYSIS_TAB_INDEX, true);
                            }
                            if (goDomainChanged && goDomainsFile.exists()) {
                                goDomains.saveMapping(goDomainsFile);
                            }
                            progressDialog.setRunFinished();
                        }
                    } catch (Exception e) {
                        progressDialog.setRunFinished();
                        peptideShakerGUI.catchException(e);
                    }
                }
            }.start();
        }
    }
}
Also used : JSparklinesDataset(no.uib.jsparklines.data.JSparklinesDataset) DefaultTableModel(javax.swing.table.DefaultTableModel) Identification(com.compomics.util.experiment.identification.Identification) FastaSummary(com.compomics.util.experiment.io.biology.protein.FastaSummary) URL(java.net.URL) GeneParameters(com.compomics.util.parameters.identification.advanced.GeneParameters) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) JSparklinesBarChartTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesBarChartTableCellRenderer) GoDomains(com.compomics.util.experiment.biology.genes.go.GoDomains) XYDataPoint(no.uib.jsparklines.data.XYDataPoint) GeneMaps(com.compomics.util.experiment.biology.genes.GeneMaps) ProteinMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.ProteinMatchesIterator) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) JsonMarshaller(com.compomics.util.io.json.JsonMarshaller) ValueAndBooleanDataPoint(no.uib.jsparklines.data.ValueAndBooleanDataPoint) BackgroundSpeciesDialog(com.compomics.util.gui.parameters.identification.advanced.BackgroundSpeciesDialog) HypergeometricDistributionImpl(org.apache.commons.math.distribution.HypergeometricDistributionImpl) SpeciesFactory(com.compomics.util.experiment.biology.taxonomy.SpeciesFactory) GoMapping(com.compomics.util.experiment.biology.genes.go.GoMapping) JSparklinesDataSeries(no.uib.jsparklines.data.JSparklinesDataSeries) ProgressDialogX(com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) DummyResults(eu.isas.peptideshaker.gui.tabpanels.GOEAPanel.QuickGoTerm.DummyResults)

Aggregations

FastaSummary (com.compomics.util.experiment.io.biology.protein.FastaSummary)2 BackgroundSpeciesDialog (com.compomics.util.gui.parameters.identification.advanced.BackgroundSpeciesDialog)2 IdentificationParameters (com.compomics.util.parameters.identification.IdentificationParameters)2 GeneParameters (com.compomics.util.parameters.identification.advanced.GeneParameters)2 GeneMaps (com.compomics.util.experiment.biology.genes.GeneMaps)1 GoDomains (com.compomics.util.experiment.biology.genes.go.GoDomains)1 GoMapping (com.compomics.util.experiment.biology.genes.go.GoMapping)1 SpeciesFactory (com.compomics.util.experiment.biology.taxonomy.SpeciesFactory)1 Identification (com.compomics.util.experiment.identification.Identification)1 ProteinMatch (com.compomics.util.experiment.identification.matches.ProteinMatch)1 ProteinMatchesIterator (com.compomics.util.experiment.identification.matches_iterators.ProteinMatchesIterator)1 PSParameter (com.compomics.util.experiment.identification.peptide_shaker.PSParameter)1 ProgressDialogX (com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX)1 JsonMarshaller (com.compomics.util.io.json.JsonMarshaller)1 DummyResults (eu.isas.peptideshaker.gui.tabpanels.GOEAPanel.QuickGoTerm.DummyResults)1 ConnectException (java.net.ConnectException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 DefaultTableModel (javax.swing.table.DefaultTableModel)1 JSparklinesDataSeries (no.uib.jsparklines.data.JSparklinesDataSeries)1