use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator in project peptide-shaker by compomics.
the class QCPanel method getProteinDataset.
/**
* Returns the dataset to use for the protein QC plot.
*/
private void getProteinDataset() {
progressDialog.setPrimaryProgressCounterIndeterminate(false);
progressDialog.setMaxPrimaryProgressCounter(peptideShakerGUI.getIdentification().getProteinIdentification().size());
progressDialog.setValue(0);
IdentificationFeaturesGenerator identificationFeaturesGenerator = peptideShakerGUI.getIdentificationFeaturesGenerator();
maxValue = Double.MIN_VALUE;
validatedValues = new ArrayList<>();
validatedDoubtfulValues = new ArrayList<>();
nonValidatedValues = new ArrayList<>();
validatedDecoyValues = new ArrayList<>();
nonValidatedDecoyValues = new ArrayList<>();
ProteinMatchesIterator proteinMatchesIterator = peptideShakerGUI.getIdentification().getProteinMatchesIterator(progressDialog);
ProteinMatch proteinMatch;
while ((proteinMatch = proteinMatchesIterator.next()) != null) {
long proteinKey = proteinMatch.getKey();
if (progressDialog.isRunCanceled()) {
break;
}
double value = 0;
if (proteinNumberValidatedPeptidesJRadioButton.isSelected()) {
value = identificationFeaturesGenerator.getNValidatedPeptides(proteinKey);
} else if (proteinSpectrumCountingScoreJRadioButton.isSelected()) {
value = identificationFeaturesGenerator.getSpectrumCounting(proteinKey);
} else if (proteinSequenceCoverageJRadioButton.isSelected()) {
HashMap<Integer, Double> sequenceCoverage = peptideShakerGUI.getIdentificationFeaturesGenerator().getSequenceCoverage(proteinKey);
Double sequenceCoverageConfident = 100 * sequenceCoverage.get(MatchValidationLevel.confident.getIndex());
Double sequenceCoverageDoubtful = 100 * sequenceCoverage.get(MatchValidationLevel.doubtful.getIndex());
value = sequenceCoverageConfident + sequenceCoverageDoubtful;
} else if (proteinSequenceLengthJRadioButton.isSelected()) {
String proteinSequence = peptideShakerGUI.getSequenceProvider().getSequence(proteinMatch.getLeadingAccession());
value = proteinSequence.length();
}
PSParameter proteinParameter = (PSParameter) proteinMatch.getUrParam(PSParameter.dummy);
if (!proteinParameter.getHidden()) {
if (value > maxValue) {
maxValue = value;
}
if (!proteinMatch.isDecoy()) {
if (proteinParameter.getMatchValidationLevel().isValidated()) {
if (proteinParameter.getMatchValidationLevel() == MatchValidationLevel.confident) {
validatedValues.add(value);
} else {
validatedDoubtfulValues.add(value);
}
} else {
nonValidatedValues.add(value);
}
}
}
progressDialog.increasePrimaryProgressCounter();
}
}
use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator in project peptide-shaker by compomics.
the class OverviewPanel method updateSequenceCoverage.
/**
* Updates the sequence coverage panel.
*
* @param proteinAccession the protein accession
* @param updateProtein if true, force a complete recreation of the plot
*/
private void updateSequenceCoverage(long proteinKey, String proteinAccession, boolean updateProtein) {
// @TODO: should be in a separate thread that is possible to cancel if the selection changes
try {
// only need to redo this if the protein changes
if (updateProtein || !proteinAccession.equalsIgnoreCase(currentProteinAccession) || coverage == null) {
updateProteinSequenceCoveragePanelTitle(proteinAccession);
updatePtmCoveragePlot(proteinAccession);
updatePeptideVariationsCoveragePlot(proteinAccession);
}
currentProteinAccession = proteinAccession;
SearchParameters searchParameters = peptideShakerGUI.getIdentificationParameters().getSearchParameters();
ArrayList<Integer> selectedPeptideStart = new ArrayList<>();
int selectionLength = 0;
if (peptideTable.getSelectedRow() != -1) {
SelfUpdatingTableModel tableModel = (SelfUpdatingTableModel) peptideTable.getModel();
int peptideIndex = tableModel.getViewIndex(peptideTable.getSelectedRow());
long peptideKey = peptideKeys[peptideIndex];
PeptideMatch peptideMatch = peptideShakerGUI.getIdentification().getPeptideMatch(peptideKey);
String peptideSequence = peptideMatch.getPeptide().getSequence();
selectionLength = peptideSequence.length();
try {
for (int startIndex : peptideMatch.getPeptide().getProteinMapping().get(currentProteinAccession)) {
selectedPeptideStart.add(startIndex);
}
} catch (Exception e) {
// ignore errors due to the user switching too quickly between rows. seems to solve themselves anyway
}
}
IdentificationFeaturesGenerator identificationFeaturesGenerator = peptideShakerGUI.getIdentificationFeaturesGenerator();
int[] validationCoverage;
if (coverageShowAllPeptidesJRadioButtonMenuItem.isSelected()) {
validationCoverage = identificationFeaturesGenerator.getAACoverage(proteinKey);
} else {
validationCoverage = identificationFeaturesGenerator.estimateAACoverage(proteinKey, coverageShowEnzymaticPeptidesOnlyJRadioButtonMenuItem.isSelected());
}
double minHeight = 0.2, maxHeight = 1;
NonSymmetricalNormalDistribution peptideLengthDistribution = peptideShakerGUI.getMetrics().getPeptideLengthDistribution();
if (peptideLengthDistribution != null) {
double medianLength = peptideLengthDistribution.getMean();
maxHeight = (1 - minHeight) * peptideLengthDistribution.getProbabilityAt(medianLength);
}
double[] coverageLikelihood = identificationFeaturesGenerator.getCoverableAA(proteinKey);
double[] coverageHeight = new double[coverageLikelihood.length];
for (int i = 0; i < coverageLikelihood.length; i++) {
double p = coverageLikelihood[i];
coverageHeight[i] = minHeight + p / maxHeight;
}
HashMap<Integer, Color> colors = new HashMap<>();
colors.put(MatchValidationLevel.confident.getIndex(), peptideShakerGUI.getSparklineColor());
colors.put(MatchValidationLevel.doubtful.getIndex(), peptideShakerGUI.getUtilitiesUserParameters().getSparklineColorDoubtful());
colors.put(MatchValidationLevel.not_validated.getIndex(), peptideShakerGUI.getSparklineColorNonValidated());
colors.put(MatchValidationLevel.none.getIndex(), peptideShakerGUI.getSparklineColorNotFound());
int userSelectionIndex = 0;
while (colors.containsKey(userSelectionIndex)) {
userSelectionIndex++;
}
// @TODO: use non hard coded value
colors.put(userSelectionIndex, Color.blue);
int[] coverageColor = validationCoverage.clone();
for (int aaStart : selectedPeptideStart) {
for (int aa = aaStart; aa < aaStart + selectionLength; aa++) {
coverageColor[aa] = userSelectionIndex;
}
}
// Dirty fix until the width of the sparkline can change
int transparentIndex = userSelectionIndex + 1;
colors.put(userSelectionIndex + 1, new Color(0, 0, 0, 0));
for (int aa = 0; aa < coverageHeight.length; aa++) {
if (coverageColor[aa] == MatchValidationLevel.none.getIndex()) {
if (coverageLikelihood[aa] < 0.01 || !coverageShowPossiblePeptidesJCheckBoxMenuItem.isSelected()) {
// NOTE: if the fix is removed, make sure that this line is kept!!!
coverageColor[aa] = transparentIndex;
}
}
}
// create the coverage plot
ArrayList<JSparklinesDataSeries> sparkLineDataSeriesCoverage = ProteinSequencePanel.getSparkLineDataSeriesCoverage(coverageHeight, coverageColor, colors);
HashMap<Integer, ArrayList<ResidueAnnotation>> proteinTooltips = peptideShakerGUI.getDisplayFeaturesGenerator().getResidueAnnotation(proteinKey, peptideShakerGUI.getIdentificationParameters().getSequenceMatchingParameters(), identificationFeaturesGenerator, peptideShakerGUI.getMetrics(), peptideShakerGUI.getIdentification(), coverageShowAllPeptidesJRadioButtonMenuItem.isSelected(), searchParameters, coverageShowEnzymaticPeptidesOnlyJRadioButtonMenuItem.isSelected());
// Dirty fix for a bloc-level annotation
HashMap<Integer, ArrayList<ResidueAnnotation>> blocTooltips = new HashMap<>();
int aaCpt = 0, blocCpt = 0;
for (JSparklinesDataSeries jSparklinesDataSeries : sparkLineDataSeriesCoverage) {
double sparkLineLength = jSparklinesDataSeries.getData().get(0);
ArrayList<ResidueAnnotation> blocAnnotation = new ArrayList<>();
for (int j = 0; j < sparkLineLength; j++, aaCpt++) {
ArrayList<ResidueAnnotation> aaAnnotation = proteinTooltips.get(aaCpt);
if (aaAnnotation != null) {
for (ResidueAnnotation residueAnnotation : aaAnnotation) {
if (!blocAnnotation.contains(residueAnnotation)) {
blocAnnotation.add(residueAnnotation);
}
}
}
}
blocTooltips.put(blocCpt, blocAnnotation);
blocCpt++;
}
proteinSequencePanel = new ProteinSequencePanel(Color.WHITE);
coverageChart = proteinSequencePanel.getSequencePlot(this, new JSparklinesDataset(sparkLineDataSeriesCoverage), blocTooltips, true, true);
// make sure that the range is the same for all the sequence annotation charts
coverageChart.getChart().addChangeListener(new ChartChangeListener() {
@Override
public void chartChanged(ChartChangeEvent cce) {
if (ptmChart != null) {
Range range = ((CategoryPlot) coverageChart.getChart().getPlot()).getRangeAxis().getRange();
((CategoryPlot) ptmChart.getChart().getPlot()).getRangeAxis().setRange(range);
ptmChart.revalidate();
ptmChart.repaint();
}
if (peptideVariationsChart != null) {
Range range = ((CategoryPlot) coverageChart.getChart().getPlot()).getRangeAxis().getRange();
((CategoryPlot) peptideVariationsChart.getChart().getPlot()).getRangeAxis().setRange(range);
peptideVariationsChart.revalidate();
peptideVariationsChart.repaint();
}
}
});
sequenceCoverageInnerPanel.removeAll();
sequenceCoverageInnerPanel.add(coverageChart);
sequenceCoverageInnerPanel.revalidate();
sequenceCoverageInnerPanel.repaint();
} catch (ClassCastException e) {
// ignore @TODO: this should not happen, but can happen if the table does not update fast enough for the filtering
}
}
use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator in project peptide-shaker by compomics.
the class OverviewPanel method updatePeptideSelection.
/**
* Updates the peptide selection according to the currently selected
* protein.
*
* @param row the row index of the protein
*/
private void updatePeptideSelection(int proteinIndex) {
if (proteinIndex != -1) {
this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
Identification identification = peptideShakerGUI.getIdentification();
IdentificationFeaturesGenerator identificationFeaturesGenerator = peptideShakerGUI.getIdentificationFeaturesGenerator();
long proteinMatchKey = proteinKeys[proteinIndex];
ProteinMatch proteinMatch = identification.getProteinMatch(proteinMatchKey);
String accession = proteinMatch.getLeadingAccession();
peptideKeys = identificationFeaturesGenerator.getSortedPeptideKeys(proteinMatchKey);
// update the table model
if (peptideTable.getModel() instanceof PeptideTableModel && ((PeptideTableModel) peptideTable.getModel()).isInstantiated()) {
((PeptideTableModel) peptideTable.getModel()).updateDataModel(identification, identificationFeaturesGenerator, peptideShakerGUI.getDisplayFeaturesGenerator(), accession, peptideKeys);
((PeptideTableModel) peptideTable.getModel()).setSelfUpdating(true);
((PeptideTableModel) peptideTable.getModel()).resetSorting(new ProgressDialogX(peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true));
} else {
PeptideTableModel peptideTableModel = new PeptideTableModel(identification, identificationFeaturesGenerator, peptideShakerGUI.getDisplayFeaturesGenerator(), accession, peptideKeys, peptideShakerGUI.getDisplayParameters().showScores(), peptideShakerGUI.getExceptionHandler());
peptideTable.setModel(peptideTableModel);
}
setPeptideTableProperties();
showSparkLines(peptideShakerGUI.showSparklines());
((DefaultTableModel) peptideTable.getModel()).fireTableDataChanged();
int maxPeptideSpectra = peptideShakerGUI.getIdentificationFeaturesGenerator().getMaxNSpectra();
((JSparklinesArrayListBarChartTableCellRenderer) peptideTable.getColumn("#Spectra").getCellRenderer()).setMaxValue(maxPeptideSpectra);
String tempSequence = peptideShakerGUI.getSequenceProvider().getSequence(proteinMatch.getLeadingAccession());
peptideTable.getColumn("Start").setCellRenderer(new JSparklinesMultiIntervalChartTableCellRenderer(PlotOrientation.HORIZONTAL, (double) tempSequence.length(), ((double) tempSequence.length()) / 50, peptideShakerGUI.getSparklineColor()));
((JSparklinesMultiIntervalChartTableCellRenderer) peptideTable.getColumn("Start").getCellRenderer()).showReferenceLine(true, 0.02, Color.BLACK);
((JSparklinesMultiIntervalChartTableCellRenderer) peptideTable.getColumn("Start").getCellRenderer()).showNumberAndChart(true, TableProperties.getLabelWidth() - 10);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
updateSelection(true);
updatePeptidePanelTitle();
} catch (Exception e) {
// Exception generally thrown at startup
e.printStackTrace();
}
}
});
this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
}
}
use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator in project peptide-shaker by compomics.
the class OverviewPanel method updatePsmPanelTitle.
/**
* Updates the PSM panel title with the number of validated/confident
*/
public void updatePsmPanelTitle() {
SelfUpdatingTableModel tableModel = (SelfUpdatingTableModel) peptideTable.getModel();
IdentificationFeaturesGenerator identificationFeaturesGenerator = peptideShakerGUI.getIdentificationFeaturesGenerator();
int peptideIndex = tableModel.getViewIndex(peptideTable.getSelectedRow());
long peptideKey = peptideKeys[peptideIndex];
int nValidatedPsms = identificationFeaturesGenerator.getNValidatedSpectraForPeptide(peptideKey);
int nConfidentPsms = identificationFeaturesGenerator.getNConfidentSpectraForPeptide(peptideKey);
int nPsms = psmTable.getRowCount();
String title = PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "Peptide Spectrum Matches (";
if (nConfidentPsms > 0) {
title += nValidatedPsms + "/" + nPsms + " - " + nConfidentPsms + " confident, " + (nValidatedPsms - nConfidentPsms) + " doubtful";
} else {
title += nValidatedPsms + "/" + nPsms;
}
title += ")" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING;
((TitledBorder) psmsPanel.getBorder()).setTitle(title);
psmsPanel.repaint();
}
use of com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator in project peptide-shaker by compomics.
the class FollowUpExportDialog method exportFasta.
/**
* Export proteins.
*
* @param accessionsOnly if true, only accession numbers are exported
*/
private void exportFasta(boolean accessionsOnly) {
// get the file to send the output to
final File selectedFile;
if (accessionsOnly) {
selectedFile = peptideShakerGUI.getUserSelectedFile("proteins.txt", ".txt", "Supported formats: text format (.txt)", "Select Destination File", false);
} else {
selectedFile = peptideShakerGUI.getUserSelectedFile("proteins.fasta", ".fasta", "Supported formats: FASTA format (.fasta)", "Select Destination File", false);
}
final boolean finalAccessionsOnly = accessionsOnly;
if (selectedFile != null) {
progressDialog = new ProgressDialogX(this, peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true);
progressDialog.setPrimaryProgressCounterIndeterminate(true);
progressDialog.setTitle("Exporting. Please Wait...");
new Thread(new Runnable() {
public void run() {
try {
progressDialog.setVisible(true);
} catch (IndexOutOfBoundsException e) {
// ignore
}
}
}, "ProgressDialog").start();
new Thread("ExportThread") {
@Override
public void run() {
try {
SequenceProvider sequenceProvider = peptideShakerGUI.getSequenceProvider();
FastaExport.ExportType exportType = finalAccessionsOnly ? FastaExport.ExportType.getTypeFromIndex(proteinExportCmb1.getSelectedIndex()) : FastaExport.ExportType.getTypeFromIndex(proteinExportCmb2.getSelectedIndex());
IdentificationFeaturesGenerator identificationFeaturesGenerator = peptideShakerGUI.getIdentificationFeaturesGenerator();
progressDialog.setPrimaryProgressCounterIndeterminate(false);
if (exportType == FastaExport.ExportType.non_validated) {
progressDialog.setMaxPrimaryProgressCounter(sequenceProvider.getAccessions().size());
} else {
progressDialog.setMaxPrimaryProgressCounter(identificationFeaturesGenerator.getNValidatedProteins());
}
FastaExport.export(selectedFile, sequenceProvider, peptideShakerGUI.getIdentification(), exportType, progressDialog, finalAccessionsOnly);
boolean processCancelled = progressDialog.isRunCanceled();
progressDialog.setRunFinished();
if (!processCancelled) {
JOptionPane.showMessageDialog(FollowUpExportDialog.this, "Identified proteins exported to " + selectedFile.getPath() + ".", "Export Complete", JOptionPane.INFORMATION_MESSAGE);
}
} catch (Exception e) {
progressDialog.setRunFinished();
e.printStackTrace();
JOptionPane.showMessageDialog(FollowUpExportDialog.this, "An error occurred when exporting the data.", "Export Failed", JOptionPane.ERROR_MESSAGE);
}
}
}.start();
}
}
Aggregations