use of com.compomics.util.experiment.biology.genes.GeneMaps in project peptide-shaker by compomics.
the class GOEAPanel method updateProteinTable.
/**
* Update the protein table.
*/
private void updateProteinTable() {
// @TODO: order the proteins in some way?
if (goMappingsTable.getSelectedRow() != -1) {
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.setPrimaryProgressCounterIndeterminate(true);
progressDialog.setTitle("Loading Protein Data. Please Wait...");
new Thread(new Runnable() {
public void run() {
try {
progressDialog.setVisible(true);
} catch (IndexOutOfBoundsException e) {
// ignore
}
}
}, "ProgressDialog").start();
new Thread("DisplayThread") {
@Override
public void run() {
try {
// clear the old data
DefaultTableModel dm = (DefaultTableModel) proteinTable.getModel();
dm.getDataVector().removeAllElements();
dm.fireTableDataChanged();
// get the selected go accession number
String selectedGoAccession = (String) goMappingsTable.getValueAt(goMappingsTable.getSelectedRow(), goMappingsTable.getColumn("GO Accession").getModelIndex());
// remove the html tags
selectedGoAccession = selectedGoAccession.substring(selectedGoAccession.lastIndexOf("GTerm?id=") + "GTerm?id=".length(), selectedGoAccession.lastIndexOf("\"><font"));
// get the list of matching proteins
GeneMaps geneMaps = peptideShakerGUI.getGeneMaps();
HashSet<String> goProteins = geneMaps.getProteinsForGoTerm(selectedGoAccession);
Identification identification = peptideShakerGUI.getIdentification();
ArrayList<Long> proteinKeys = new ArrayList<>(goProteins.size());
HashMap<String, HashSet<Long>> proteinMap = identification.getProteinMap();
for (String goProtein : goProteins) {
HashSet<Long> tempKeys = proteinMap.get(goProtein);
if (tempKeys != null) {
proteinKeys.addAll(tempKeys);
}
}
// update the table
if (proteinTable.getModel() instanceof ProteinGoTableModel) {
((ProteinGoTableModel) proteinTable.getModel()).updateDataModel(proteinKeys);
} else {
ProteinGoTableModel proteinTableModel = new ProteinGoTableModel(peptideShakerGUI.getIdentification(), peptideShakerGUI.getProteinDetailsProvider(), peptideShakerGUI.getIdentificationFeaturesGenerator(), peptideShakerGUI.getDisplayFeaturesGenerator(), proteinKeys, peptideShakerGUI.getDisplayParameters().showScores());
proteinTable.setModel(proteinTableModel);
}
setProteinGoTableProperties();
((DefaultTableModel) proteinTable.getModel()).fireTableDataChanged();
if (proteinTable.getRowCount() > 0) {
// get the number of confident and doubtful matches
int nConfident = 0;
int nDoubtful = 0;
for (long proteinKey : proteinKeys) {
PSParameter psParameter = (PSParameter) (identification.getProteinMatch(proteinKey)).getUrParam(PSParameter.dummy);
MatchValidationLevel level = psParameter.getMatchValidationLevel();
if (level == MatchValidationLevel.confident) {
nConfident++;
} else if (level == MatchValidationLevel.doubtful) {
nDoubtful++;
}
}
String title = PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "Gene Ontology Enrichment Analysis - " + goMappingsTable.getValueAt(goMappingsTable.getSelectedRow(), goMappingsTable.getColumn("GO Term").getModelIndex()) + " (";
try {
if (nConfident > 0) {
title += (nConfident + nDoubtful) + "/" + proteinKeys.size() + " - " + nConfident + " confident, " + nDoubtful + " doubtful";
} else {
title += proteinKeys.size();
}
} catch (Exception eNValidated) {
peptideShakerGUI.catchException(eNValidated);
}
title += ")" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING;
((TitledBorder) plotPanel.getBorder()).setTitle(title);
plotPanel.repaint();
proteinTable.setRowSelectionInterval(0, 0);
proteinTable.scrollRectToVisible(proteinTable.getCellRect(0, 0, false));
// update the protein selection
ProteinGoTableModel proteinGoTableModel = (ProteinGoTableModel) proteinTable.getModel();
int selectedGroupIndex = proteinTable.convertRowIndexToModel(proteinTable.getSelectedRow());
long proteinGroupKey = proteinGoTableModel.getProteins().get(selectedGroupIndex);
peptideShakerGUI.setSelectedItems(proteinGroupKey, NO_KEY, null, null);
proteinTableKeyReleased(null);
}
progressDialog.setRunFinished();
} catch (Exception e) {
progressDialog.setRunFinished();
peptideShakerGUI.catchException(e);
}
}
}.start();
}
}
use of com.compomics.util.experiment.biology.genes.GeneMaps in project peptide-shaker by compomics.
the class FileImporter method importFiles.
/**
* Imports the identifications from the files.
*
* @param idFiles the identification files
*
* @return 0 if success, 1 if not
*/
public int importFiles(ArrayList<File> idFiles) {
ArrayList<File> sortedIdFiles = idFiles.stream().collect(Collectors.groupingBy(File::getName, TreeMap::new, Collectors.toList())).values().stream().flatMap(List::stream).distinct().collect(Collectors.toCollection(ArrayList::new));
try {
importSequences(identificationParameters.getSequenceMatchingParameters(), identificationParameters.getSearchParameters(), identificationParameters.getFastaParameters(), identificationParameters.getPeptideVariantsParameters(), waitingHandler, exceptionHandler);
if (waitingHandler.isRunCanceled()) {
return 1;
}
GeneParameters geneParameters = identificationParameters.getGeneParameters();
if (geneParameters.getUseGeneMapping()) {
waitingHandler.setSecondaryProgressCounterIndeterminate(true);
waitingHandler.appendReport("Importing gene mappings.", true, true);
importGenes();
} else {
geneMaps = new GeneMaps();
}
if (waitingHandler.isRunCanceled()) {
return 1;
}
waitingHandler.setSecondaryProgressCounterIndeterminate(true);
waitingHandler.appendReport("Establishing local database connection.", true, true);
waitingHandler.increasePrimaryProgressCounter();
if (!waitingHandler.isRunCanceled()) {
waitingHandler.appendReport("Reading identification files.", true, true);
for (File idFile : sortedIdFiles) {
importPsms(idFile);
if (waitingHandler.isRunCanceled()) {
return 1;
}
}
if (nRetained == 0) {
waitingHandler.appendReport("No identification results.", true, true);
waitingHandler.setRunCanceled();
return 1;
}
// get the total number of spectra
int nSpectra = 0;
for (String spectrumFileName : identification.getFractions()) {
nSpectra += spectrumProvider.getSpectrumTitles(spectrumFileName).length;
}
waitingHandler.appendReport("File import completed. " + nPSMs + " first hits imported (" + nTotal + " total) from " + nSpectra + " spectra.", true, true);
waitingHandler.appendReport("[" + nRetained + " first hits passed the initial filtering]", true, true);
}
} catch (OutOfMemoryError error) {
System.out.println("<CompomicsError>PeptideShaker ran out of memory! See the PeptideShaker log for details.</CompomicsError>");
System.err.println("Ran out of memory!");
System.err.println("Memory given to the Java virtual machine: " + Runtime.getRuntime().maxMemory() + ".");
System.err.println("Memory used by the Java virtual machine: " + Runtime.getRuntime().totalMemory() + ".");
System.err.println("Free memory in the Java virtual machine: " + Runtime.getRuntime().freeMemory() + ".");
Runtime.getRuntime().gc();
waitingHandler.appendReportEndLine();
waitingHandler.appendReport("Ran out of memory!", true, true);
waitingHandler.setRunCanceled();
if (waitingHandler instanceof WaitingDialog) {
JOptionPane.showMessageDialog((WaitingDialog) waitingHandler, JOptionEditorPane.getJOptionEditorPane("PeptideShaker used up all the available memory and had to be stopped.<br>" + "Memory boundaries are changed in the the Welcome Dialog (Settings<br>" + "& Help > Settings > Java Memory Settings) or in the Edit menu (Edit<br>" + "Java Options). See also <a href=\"https://compomics.github.io/projects/compomics-utilities/wiki/JavaTroubleShooting.html\">JavaTroubleShooting</a>."), "Out Of Memory", JOptionPane.ERROR_MESSAGE);
}
error.printStackTrace();
return 1;
} catch (Exception e) {
waitingHandler.setRunCanceled();
System.out.println("<CompomicsError>PeptideShaker processing failed. See the PeptideShaker log for details.</CompomicsError>");
if (e instanceof NullPointerException) {
waitingHandler.appendReport("An error occurred while loading the identification files.", true, true);
waitingHandler.appendReport("Please see the error log (Help Menu > Bug Report) for details.", true, true);
} else if (FrameExceptionHandler.getExceptionType(e).equalsIgnoreCase("Protein not found")) {
waitingHandler.appendReport("An error occurred while loading the identification files:", true, true);
waitingHandler.appendReport(e.getLocalizedMessage(), true, true);
waitingHandler.appendReport("Please see https://compomics.github.io/projects/searchgui/wiki/DatabaseHelp.html.", true, true);
} else {
waitingHandler.appendReport("An error occurred while loading the identification files:", true, true);
waitingHandler.appendReport(e.getLocalizedMessage(), true, true);
}
e.printStackTrace();
System.err.println("Free memory: " + Runtime.getRuntime().freeMemory());
return 1;
}
return 0;
}
use of com.compomics.util.experiment.biology.genes.GeneMaps in project peptide-shaker by compomics.
the class AnnotationPanel method updateBasicProteinAnnotation.
// End of variables declaration//GEN-END:variables
/**
* Updates the basic protein annotation information.
*
* @param aAccessionNumber the new accession number
*/
public void updateBasicProteinAnnotation(String aAccessionNumber) {
// only update if new accession number
if (aAccessionNumber != null && !aAccessionNumber.equals(NO_KEY) && !currentAccessionNumber.equalsIgnoreCase(aAccessionNumber)) {
currentAccessionNumber = aAccessionNumber;
accessionNumberJTextField.setText(currentAccessionNumber);
ProteinDetailsProvider proteinDetailsProvider = peptideShakerGUI.getProteinDetailsProvider();
String simpleDescription = proteinDetailsProvider.getSimpleDescription(aAccessionNumber);
String geneName = proteinDetailsProvider.getGeneName(aAccessionNumber);
String taxonomy = proteinDetailsProvider.getTaxonomy(aAccessionNumber);
ProteinDatabase proteinDatabase = proteinDetailsProvider.getProteinDatabase(aAccessionNumber);
proteinDescriptionTextArea.setText(simpleDescription);
geneNameJTextField.setText(geneName);
if (geneName != null) {
GeneMaps geneMaps = peptideShakerGUI.getGeneMaps();
chromosomeJTextField.setText(geneMaps.getChromosome(geneName));
} else {
chromosomeJTextField.setText(null);
}
taxonomyJTextField.setText(taxonomy);
databaseJTextField.setText(proteinDatabase.getFullName());
}
}
use of com.compomics.util.experiment.biology.genes.GeneMaps 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();
}
}
}
use of com.compomics.util.experiment.biology.genes.GeneMaps in project peptide-shaker by compomics.
the class MatchesValidator method validateIdentifications.
/**
* This method validates the identification matches of an identification
* object. Target Decoy thresholds must be set.
*
* @param identification The identification class containing the matches to
* validate.
* @param metrics If provided, metrics on fractions will be saved while
* iterating the matches.
* @param geneMaps The gene maps.
* @param inputMap The target decoy map of all search engine scores.
* @param waitingHandler The waiting handler displaying progress to the user
* and allowing canceling the process.
* @param exceptionHandler The handler for exceptions.
* @param identificationFeaturesGenerator The identification features
* generator computing information about the identification matches.
* @param sequenceProvider The protein sequence provider.
* @param proteinDetailsProvider The protein details provider.
* @param spectrumProvider The spectrum provider.
* @param identificationParameters The identification parameters.
* @param projectType The project type.
* @param processingParameters The processing parameters.
*
* @throws java.lang.InterruptedException exception thrown if a thread gets
* interrupted
* @throws java.util.concurrent.TimeoutException exception thrown if the
* operation times out
*/
public void validateIdentifications(Identification identification, Metrics metrics, InputMap inputMap, WaitingHandler waitingHandler, ExceptionHandler exceptionHandler, IdentificationFeaturesGenerator identificationFeaturesGenerator, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, SpectrumProvider spectrumProvider, GeneMaps geneMaps, IdentificationParameters identificationParameters, ProjectType projectType, ProcessingParameters processingParameters) throws InterruptedException, TimeoutException {
IdMatchValidationParameters validationParameters = identificationParameters.getIdValidationParameters();
waitingHandler.setWaitingText("Finding FDR Thresholds. Please Wait...");
for (int algorithm : inputMap.getInputAlgorithms()) {
TargetDecoyMap targetDecoyMap = inputMap.getTargetDecoyMap(algorithm);
TargetDecoyResults currentResults = targetDecoyMap.getTargetDecoyResults();
currentResults.setInputType(1);
currentResults.setUserInput(validationParameters.getDefaultPsmFDR());
currentResults.setFdrLimit(validationParameters.getDefaultPsmFDR());
targetDecoyMap.getTargetDecoySeries().getFDRResults(currentResults);
}
TargetDecoyResults currentResults = psmMap.getTargetDecoyResults();
currentResults.setInputType(1);
currentResults.setUserInput(validationParameters.getDefaultPsmFDR());
currentResults.setFdrLimit(validationParameters.getDefaultPsmFDR());
psmMap.getTargetDecoySeries().getFDRResults(currentResults);
waitingHandler.setSecondaryProgressCounterIndeterminate(false);
currentResults = peptideMap.getTargetDecoyResults();
currentResults.setInputType(1);
currentResults.setUserInput(validationParameters.getDefaultPeptideFDR());
currentResults.setFdrLimit(validationParameters.getDefaultPeptideFDR());
peptideMap.getTargetDecoySeries().getFDRResults(currentResults);
currentResults = proteinMap.getTargetDecoyResults();
currentResults.setInputType(1);
currentResults.setUserInput(validationParameters.getDefaultProteinFDR());
currentResults.setFdrLimit(validationParameters.getDefaultProteinFDR());
proteinMap.getTargetDecoySeries().getFDRResults(currentResults);
ValidationQcParameters validationQCParameters = validationParameters.getValidationQCParameters();
waitingHandler.setWaitingText("Match Validation and Quality Control. Please Wait...");
waitingHandler.setSecondaryProgressCounterIndeterminate(false);
waitingHandler.resetSecondaryProgressCounter();
waitingHandler.setMaxSecondaryProgressCounter(identification.getProteinIdentification().size() + identification.getPeptideIdentification().size() + 2 * identification.getSpectrumIdentificationSize());
// validate the spectrum matches
if (inputMap != null) {
inputMap.resetAdvocateContributions();
}
AnnotationParameters annotationParameters = identificationParameters.getAnnotationParameters();
double intensityLimit = annotationParameters.getAnnotationIntensityLimit();
annotationParameters.setIntensityLimit(0);
ExecutorService pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
SpectrumMatchesIterator psmIterator = identification.getSpectrumMatchesIterator(waitingHandler);
ArrayList<PsmValidatorRunnable> psmRunnables = new ArrayList<>(processingParameters.getnThreads());
for (int i = 1; i <= processingParameters.getnThreads(); i++) {
PsmValidatorRunnable runnable = new PsmValidatorRunnable(psmIterator, identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, identificationParameters, waitingHandler, exceptionHandler, inputMap, false, true);
pool.submit(runnable);
psmRunnables.add(runnable);
}
if (waitingHandler.isRunCanceled()) {
pool.shutdownNow();
return;
}
pool.shutdown();
if (!pool.awaitTermination(identification.getSpectrumIdentificationSize(), TimeUnit.MINUTES)) {
throw new TimeoutException("Spectrum matches validation timed out. Please contact the developers.");
}
// combine the precursor mz deviations from the different threads into one map
HashMap<String, ArrayList<Double>> precursorMzDeviations = new HashMap<>(identification.getSpectrumIdentification().size());
for (PsmValidatorRunnable runnable : psmRunnables) {
for (String spectrumFileName : runnable.getThreadPrecursorMzDeviations().keySet()) {
ArrayList<Double> threadPrecursorMzDeviations = runnable.getThreadPrecursorMzDeviations().get(spectrumFileName);
ArrayList<Double> filePrecursorMzDeviations = precursorMzDeviations.get(spectrumFileName);
if (filePrecursorMzDeviations != null) {
filePrecursorMzDeviations.addAll(threadPrecursorMzDeviations);
} else {
precursorMzDeviations.put(spectrumFileName, threadPrecursorMzDeviations);
}
}
}
for (String spectrumFileName : precursorMzDeviations.keySet()) {
double[] precursorMzDeviationsFile = precursorMzDeviations.get(spectrumFileName).stream().mapToDouble(a -> a).toArray();
if (precursorMzDeviationsFile.length >= 100) {
Arrays.sort(precursorMzDeviationsFile);
identificationFeaturesGenerator.setMassErrorDistribution(spectrumFileName, precursorMzDeviationsFile);
} else {
// There are not enough precursors, disable probabilistic precursor filter
if (validationQCParameters.getPsmFilters() != null) {
for (Filter filter : validationQCParameters.getPsmFilters()) {
PsmFilter psmFilter = (PsmFilter) filter;
if (psmFilter.getItemsNames().contains(AssumptionFilterItem.precrusorMzErrorStat.name)) {
psmFilter.removeFilterItem(AssumptionFilterItem.precrusorMzErrorStat.name);
SearchParameters searchParameters = identificationParameters.getSearchParameters();
if (searchParameters.isPrecursorAccuracyTypePpm()) {
psmFilter.setFilterItem(AssumptionFilterItem.precrusorMzErrorPpm.name, FilterItemComparator.lowerOrEqual, searchParameters.getPrecursorAccuracy());
} else {
psmFilter.setFilterItem(AssumptionFilterItem.precrusorMzErrorDa.name, FilterItemComparator.lowerOrEqual, searchParameters.getPrecursorAccuracy());
}
}
AssumptionFilter assumptionFilter = psmFilter.getAssumptionFilter();
if (assumptionFilter.getItemsNames().contains(AssumptionFilterItem.precrusorMzErrorStat.name)) {
assumptionFilter.removeFilterItem(AssumptionFilterItem.precrusorMzErrorStat.name);
SearchParameters searchParameters = identificationParameters.getSearchParameters();
if (searchParameters.isPrecursorAccuracyTypePpm()) {
assumptionFilter.setFilterItem(AssumptionFilterItem.precrusorMzErrorPpm.name, FilterItemComparator.lowerOrEqual, searchParameters.getPrecursorAccuracy());
} else {
assumptionFilter.setFilterItem(AssumptionFilterItem.precrusorMzErrorDa.name, FilterItemComparator.lowerOrEqual, searchParameters.getPrecursorAccuracy());
}
}
}
}
}
}
pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
psmIterator = identification.getSpectrumMatchesIterator(waitingHandler);
for (int i = 1; i <= processingParameters.getnThreads(); i++) {
PsmValidatorRunnable runnable = new PsmValidatorRunnable(psmIterator, identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, identificationParameters, waitingHandler, exceptionHandler, inputMap, true, false);
pool.submit(runnable);
}
if (waitingHandler.isRunCanceled()) {
pool.shutdownNow();
return;
}
pool.shutdown();
if (!pool.awaitTermination(identification.getSpectrumIdentificationSize(), TimeUnit.MINUTES)) {
throw new TimeoutException("Spectrum matches validation timed out. Please contact the developers.");
}
annotationParameters.setIntensityLimit(intensityLimit);
if (projectType == ProjectType.peptide || projectType == ProjectType.protein) {
// validate the peptides
pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
ArrayList<PeptideValidatorRunnable> peptideRunnables = new ArrayList<>(processingParameters.getnThreads());
PeptideMatchesIterator peptideMatchesIterator = identification.getPeptideMatchesIterator(waitingHandler);
for (int i = 1; i <= processingParameters.getnThreads(); i++) {
PeptideValidatorRunnable runnable = new PeptideValidatorRunnable(peptideMatchesIterator, identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, identificationParameters, waitingHandler, exceptionHandler, metrics);
pool.submit(runnable);
peptideRunnables.add(runnable);
}
if (waitingHandler.isRunCanceled()) {
pool.shutdownNow();
return;
}
pool.shutdown();
if (!pool.awaitTermination(identification.getPeptideIdentification().size(), TimeUnit.MINUTES)) {
throw new InterruptedException("Peptide matches validation timed out. Please contact the developers.");
}
HashMap<String, Integer> validatedTotalPeptidesPerFraction = new HashMap<>();
ArrayList<Double> validatedPeptideLengths = new ArrayList<>();
for (PeptideValidatorRunnable runnable : peptideRunnables) {
HashMap<String, Integer> threadValidatedTotalPeptidesPerFraction = runnable.getValidatedTotalPeptidesPerFraction();
for (String fraction : threadValidatedTotalPeptidesPerFraction.keySet()) {
Integer nValidated = validatedTotalPeptidesPerFraction.get(fraction);
if (nValidated == null) {
nValidated = 0;
}
nValidated += threadValidatedTotalPeptidesPerFraction.get(fraction);
validatedTotalPeptidesPerFraction.put(fraction, nValidated);
}
validatedPeptideLengths.addAll(runnable.getValidatedPeptideLengths());
}
if (validatedPeptideLengths.size() >= 100) {
NonSymmetricalNormalDistribution lengthDistribution = NonSymmetricalNormalDistribution.getRobustNonSymmetricalNormalDistribution(validatedPeptideLengths);
metrics.setPeptideLengthDistribution(lengthDistribution);
}
metrics.setTotalPeptidesPerFraction(validatedTotalPeptidesPerFraction);
if (projectType == ProjectType.protein) {
// validate the proteins
pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
ProteinMatchesIterator proteinMatchesIterator = identification.getProteinMatchesIterator(waitingHandler);
ArrayList<ProteinValidatorRunnable> proteinRunnables = new ArrayList<>(processingParameters.getnThreads());
for (int i = 1; i <= processingParameters.getnThreads(); i++) {
ProteinValidatorRunnable runnable = new ProteinValidatorRunnable(proteinMatchesIterator, identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, metrics, identificationParameters, waitingHandler, exceptionHandler);
pool.submit(runnable);
proteinRunnables.add(runnable);
}
if (waitingHandler.isRunCanceled()) {
pool.shutdownNow();
return;
}
pool.shutdown();
if (!pool.awaitTermination(identification.getProteinIdentification().size(), TimeUnit.MINUTES)) {
throw new InterruptedException("Protein matches validation timed out. Please contact the developers.");
}
long[] validatedTargetProteinKeys = proteinRunnables.stream().flatMap(runnable -> runnable.getValidatedProteinMatches().stream()).mapToLong(a -> a).toArray();
metrics.setValidatedTargetProteinKeys(validatedTargetProteinKeys);
}
}
}
Aggregations