use of com.compomics.util.parameters.identification.advanced.GeneParameters in project peptide-shaker by compomics.
the class FileImporter method importGenes.
/**
* Imports the gene information for this project.
*/
public void importGenes() {
ProteinGeneDetailsProvider geneFactory = new ProteinGeneDetailsProvider();
try {
geneFactory.initialize(PeptideShaker.getJarFilePath());
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "An error occurred while loading the gene mappings.", "Gene Mapping File Error", JOptionPane.ERROR_MESSAGE);
}
GeneParameters geneParameters = identificationParameters.getGeneParameters();
geneMaps = geneFactory.getGeneMaps(geneParameters, fastaSummary, sequenceProvider, proteinDetailsProvider, waitingHandler);
}
use of com.compomics.util.parameters.identification.advanced.GeneParameters 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.parameters.identification.advanced.GeneParameters 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();
}
}
use of com.compomics.util.parameters.identification.advanced.GeneParameters 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();
}
}
}
Aggregations