use of com.compomics.util.io.json.JsonMarshaller in project peptide-shaker by compomics.
the class PSExportFactory method saveFactory.
/**
* Saves the factory in the user folder.
*
* @param psExportFactory the instance of the factory to save
*
* @throws IOException exception thrown whenever an error occurred while
* saving the PSExportFactory
*/
public static void saveFactory(PSExportFactory psExportFactory) throws IOException {
File factoryFile = new File(JSON_FILE);
if (!factoryFile.getParentFile().exists()) {
factoryFile.getParentFile().mkdir();
}
JsonMarshaller jsonMarshaller = new ExportFactoryMarshaller();
jsonMarshaller.saveObjectToJson(psExportFactory, factoryFile);
}
use of com.compomics.util.io.json.JsonMarshaller in project peptide-shaker by compomics.
the class PSExportFactory method loadFromFile.
/**
* Loads an export factory from a file. The file must be an export of the
* factory in the json format.
*
* @param file the file to load
*
* @return the export factory saved in file
*
* @throws IOException exception thrown whenever an error occurred while
* loading the file
*/
public static PSExportFactory loadFromFile(File file) throws IOException {
JsonMarshaller jsonMarshaller = new ExportFactoryMarshaller();
PSExportFactory result = (PSExportFactory) jsonMarshaller.fromJson(PSExportFactory.class, file);
return result;
}
use of com.compomics.util.io.json.JsonMarshaller 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