int currentRow = selectedRows[row];
SelfUpdatingTableModel tableModel = (SelfUpdatingTableModel) proteinTable.getModel();
int proteinIndex = tableModel.getViewIndex(currentRow);
String proteinKey = proteinKeys.get(proteinIndex);
ProteinMatch proteinMatch = peptideShakerGUI.getIdentification().getProteinMatch(proteinKey);
try {
peptideKeys = peptideShakerGUI.getIdentificationFeaturesGenerator().getSortedPeptideKeys(proteinKey);
} catch (Exception e) {
peptideShakerGUI.catchException(e);
try {
// Let's try without order
peptideKeys = proteinMatch.getPeptideMatchesKeys();
} catch (Exception e1) {
peptideShakerGUI.catchException(e1);
// ok you are really unlucky... Just hope the GUI holds...
peptideKeys = new ArrayList<String>();
}
}
// get the current protein and protein sequence
Protein currentProtein = sequenceFactory.getProtein(proteinMatch.getMainMatch());
String currentProteinSequence = sequenceFactory.getProtein(proteinMatch.getMainMatch()).getSequence();
int[][] coverage = new int[fileNames.size()][currentProteinSequence.length() + 1];
// get the chart data
for (int i = 0; i < fileNames.size(); i++) {
String fraction = fileNames.get(i);
for (int j = 0; j < peptideKeys.size(); j++) {
String peptideKey = peptideKeys.get(j);
try {
psParameter = (PSParameter) peptideShakerGUI.getIdentification().getPeptideMatchParameter(peptideKey, psParameter);
if (psParameter.getFractions() != null && psParameter.getFractions().contains(fraction)) {
if (psParameter.getMatchValidationLevel().isValidated()) {
String peptideSequence = Peptide.getSequence(peptideKey);
boolean includePeptide = false;
if (coverageShowAllPeptidesJRadioButtonMenuItem.isSelected()) {
includePeptide = true;
} else if (coverageShowEnzymaticPeptidesOnlyJRadioButtonMenuItem.isSelected()) {
includePeptide = currentProtein.isEnzymaticPeptide(peptideSequence,
peptideShakerGUI.getSearchParameters().getEnzyme(),
peptideShakerGUI.getSequenceMatchingPreferences());
} else if (coverageShowTruncatedPeptidesOnlyJRadioButtonMenuItem.isSelected()) {
includePeptide = !currentProtein.isEnzymaticPeptide(peptideSequence,
peptideShakerGUI.getSearchParameters().getEnzyme(),
peptideShakerGUI.getSequenceMatchingPreferences());
}
if (includePeptide && selectedRows.length == 1) {
AminoAcidPattern aminoAcidPattern = new AminoAcidPattern(peptideSequence);
for (int startIndex : aminoAcidPattern.getIndexes(currentProteinSequence, peptideShakerGUI.getSequenceMatchingPreferences())) {
int peptideTempStart = startIndex -1;
int peptideTempEnd = peptideTempStart + peptideSequence.length();
for (int k = peptideTempStart; k < peptideTempEnd; k++) {
coverage[i][k]++;
}
}
}
}
}
} catch (Exception e) {
peptideShakerGUI.catchException(e);
}
}
}
psParameter = new PSParameter();
psParameter = (PSParameter) peptideShakerGUI.getIdentification().getProteinMatchParameter(proteinKey, psParameter);
for (int i = 0; i < fileNames.size(); i++) {
String fraction = fileNames.get(i);
psParameter = (PSParameter) peptideShakerGUI.getIdentification().getProteinMatchParameter(proteinKey, psParameter);
if (selectedRows.length == 1) {
peptidePlotDataset.addValue(psParameter.getFractionValidatedPeptides(fraction), "Validated Peptides", "" + (i + 1));
} else {
peptidePlotDataset.addValue(psParameter.getFractionValidatedPeptides(fraction), proteinMatch.getMainMatch()
+ ": " + sequenceFactory.getHeader(proteinMatch.getMainMatch()).getSimpleProteinDescription(), "" + (i + 1));
}
}
double longestFileName = "Fraction".length();
// update the coverage table
if (selectedRows.length == 1) {
DefaultTableModel coverageTableModel = (DefaultTableModel) coverageTable.getModel();
coverageTableModel.getDataVector().removeAllElements();
for (int i = 0; i < fileNames.size(); i++) {
// create the coverage plot
ArrayList<JSparklinesDataSeries> sparkLineDataSeriesCoverage = new ArrayList<JSparklinesDataSeries>();
for (int j = 0; j < currentProteinSequence.length(); j++) {
boolean covered = coverage[i][j] > 0;
int sequenceCounter = 1;
if (covered) {
while (j + 1 < coverage[0].length && coverage[i][j + 1] > 0) {
sequenceCounter++;
j++;
}
} else {
while (j + 1 < coverage[0].length && coverage[i][j + 1] == 0) {
sequenceCounter++;
j++;
}
}
ArrayList<Double> data = new ArrayList<Double>();
data.add(new Double(sequenceCounter));
JSparklinesDataSeries sparklineDataseries;
if (covered) {
sparklineDataseries = new JSparklinesDataSeries(data, peptideShakerGUI.getSparklineColor(), null);
} else {
sparklineDataseries = new JSparklinesDataSeries(data, new Color(0, 0, 0, 0), null);
}
sparkLineDataSeriesCoverage.add(sparklineDataseries);
}
ChartPanel coverageChart = new ProteinSequencePanel(Color.WHITE).getSequencePlot(this, new JSparklinesDataset(sparkLineDataSeriesCoverage),
new HashMap<Integer, ArrayList<ResidueAnnotation>>(), true, true);
((DefaultTableModel) coverageTable.getModel()).addRow(new Object[]{(i + 1), fileNames.get(i), coverageChart});
if (fileNames.get(i).length() > longestFileName) {
longestFileName = fileNames.get(i).length();
}
}
}
// set the preferred size of the fraction name column in the coverage table
Integer width = peptideShakerGUI.getPreferredColumnWidth(coverageTable, coverageTable.getColumn("Fraction").getModelIndex(), 6);
if (width != null) {
coverageTable.getColumn("Fraction").setMinWidth(width);
coverageTable.getColumn("Fraction").setMaxWidth(width);
} else {
coverageTable.getColumn("Fraction").setMinWidth(15);
coverageTable.getColumn("Fraction").setMaxWidth(Integer.MAX_VALUE);
}
// get the psms per fraction
for (int i = 0; i < fileNames.size(); i++) {
String fraction = fileNames.get(i);
psParameter = (PSParameter) peptideShakerGUI.getIdentification().getProteinMatchParameter(proteinKey, psParameter);
if (selectedRows.length == 1) {
spectrumPlotDataset.addValue(psParameter.getFractionValidatedSpectra(fraction), "Validated Spectra", "" + (i + 1));
intensityPlotDataset.addValue(psParameter.getPrecursorIntensitySummedPerFraction(fraction), "Summed Intensity", "" + (i + 1));
} else {
spectrumPlotDataset.addValue(psParameter.getFractionValidatedSpectra(fraction), proteinMatch.getMainMatch()
+ ": " + sequenceFactory.getHeader(proteinMatch.getMainMatch()).getSimpleProteinDescription(), "" + (i + 1));
intensityPlotDataset.addValue(psParameter.getPrecursorIntensitySummedPerFraction(fraction), proteinMatch.getMainMatch()
+ ": " + sequenceFactory.getHeader(proteinMatch.getMainMatch()).getSimpleProteinDescription(), "" + (i + 1));
}
}
}
// molecular mass plot