Skip to content

Commit

Permalink
Improve import speed
Browse files Browse the repository at this point in the history
1. Move predicted spectra importing
2. Some bugs fixed
  • Loading branch information
KaiLiCn committed Dec 2, 2022
1 parent 3f92862 commit 4880528
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 158 deletions.
14 changes: 11 additions & 3 deletions src/main/java/GUI/Export/ExportExpectedSizeDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public class ExportExpectedSizeDialog extends JDialog {
* Check peptide or not
*/
private Boolean isCheckPeptide;
private Boolean isNormPeptide;
private Boolean isCheckSpectra;
private Boolean isPredict;
/**
* Pattern removing illegal
*/
Expand All @@ -96,14 +99,17 @@ public class ExportExpectedSizeDialog extends JDialog {
* @param spectrumKey Spectrum Key
*/
public ExportExpectedSizeDialog(SpectrumMainPanel spectrumMainPanel, JLayeredPane jLayeredPane, SequenceFragmentationPanel secondarySpectrumPlotsJPanel, JPanel mirrorSequenceFragmentationPanel,
SpectrumContainer spectrumJPanel, Integer peptideSize, String spectrumKey, Boolean isCheckPeptide){
SpectrumContainer spectrumJPanel, Integer peptideSize, String spectrumKey, Boolean isNormPeptide, Boolean isCheckSpectra, Boolean isCheckPeptide, Boolean isPredict){
super(spectrumMainPanel.parentFrame, true);

this.jLayeredPane = jLayeredPane;
this.secondarySpectrumPlotsJPanel = secondarySpectrumPlotsJPanel;
this.mirrorSequenceFragmentationPanel = mirrorSequenceFragmentationPanel;
this.spectrumJPanel = spectrumJPanel;
this.isCheckPeptide = isCheckPeptide;
this.isNormPeptide = isNormPeptide;
this.isCheckSpectra = isCheckSpectra;
this.isPredict = isPredict;
this.spectrumMainPanel = spectrumMainPanel;
this.parentJFrame = spectrumMainPanel.parentFrame;
this.peptideSize = peptideSize;
Expand Down Expand Up @@ -339,12 +345,14 @@ public void windowClosing(WindowEvent evt) {
* @param evt window event
*/
private void formWindowClosing(WindowEvent evt) {
if(mirrorSequenceFragmentationPanel != null){
if(isCheckSpectra){
spectrumMainPanel.showMirrorJMenuItemActionPerformed(null);
} else if(isCheckPeptide){
spectrumMainPanel.showCheckPeptideJMenuItemActionPerformed(null);
} else {
} else if (isNormPeptide){
spectrumMainPanel.showSpectrumJMenuItemAction(null);
} else if (isPredict){
spectrumMainPanel.showPredictionJMenuItemActionPerformed(null);
}
spectrumMainPanel.setBounds(0, 0, oldWidth, oldHeight);
spectrumMainPanel.spectrumShowPanel.setBounds(0, 0, oldWidth, oldHeight);
Expand Down
60 changes: 25 additions & 35 deletions src/main/java/GUI/GUIMainClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public class GUIMainClass extends JFrame {
/**
* Results folder
*/
private File resultsFolder;
public File resultsFolder;
/**
* Threads number
*/
Expand All @@ -276,7 +276,7 @@ public class GUIMainClass extends JFrame {
/**
*
*/
private HashMap<String, Integer[]> experimentInfo = new HashMap<>();
public HashMap<String, Integer[]> experimentInfo = new HashMap<>();
/**
*
*/
Expand Down Expand Up @@ -313,6 +313,14 @@ public class GUIMainClass extends JFrame {
*
*/
public HashMap<String, PredictionEntry> predictionEntryHashMap = new HashMap<>();
/**
* Experiment information
*/
public ArrayList<String> expInformation = new ArrayList<>();
/**
*
*/
public Boolean hasPredictionSpectra = false;
/**
*
*/
Expand Down Expand Up @@ -2427,7 +2435,10 @@ private void spectrumJTableKeyReleased(KeyEvent evt) {
} else {
spectrumMatch = sqliteConnection.getSpectrumMatch(selectedPsmKey);
}
updateSpectrum(getSpectrum(selectedPsmKey), spectrumMatch);
String spectrumTitle = sqliteConnection.getSpectrumOldTitle(selectedPsmKey);
checkSpectrumFactory(spectrumTitle.split("\\.")[0]);

updateSpectrum(getSpectrum(selectedPsmKey), spectrumMatch);
} catch (SQLException | FileParsingException | MzMLUnmarshallerException | IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -3219,38 +3230,13 @@ private void checkSpectrumFactory(String spectrumFileName){

if (!finishedSpectrumFiles.contains(spectrumFileName)) {
if (readFactoryThread.isAlive()) {
readFactoryThread.interrupt();
while (readFactoryThread.isInterrupted()){
readFactoryThread.interrupt();
}

updateSpectrumFactory(true, spectrumFileName);
}
}
// ProgressDialogX progressDialog = new ProgressDialogX(this,
// Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/SeaGullMass.png")),
// Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/SeaGullMassWait.png")),
// true);
// progressDialog.setPrimaryProgressCounterIndeterminate(true);
// progressDialog.setTitle("Load new spectrum file. Please Wait...");
//
// new Thread(() -> {
// try {
// progressDialog.setVisible(true);
// } catch (IndexOutOfBoundsException ignored) {
// }
// }, "ProgressDialog").start();
// new Thread("DisplayThread") {
// @Override
// public void run() {
//
// if (!finishedSpectrumFiles.contains(spectrumFileName)) {
// if (readFactoryThread.isAlive()) {
// readFactoryThread.interrupt();
// updateSpectrumFactory(true, spectrumFileName);
// }
// }
//
// progressDialog.setRunFinished();
// }
// }.start();

}

/**
Expand Down Expand Up @@ -3440,6 +3426,8 @@ public void run() {
spectrumFileOrder = oneImport.getSpectrumFileOrder();
spectrumFileMap = oneImport.getSpectrumFileMap();
predictionEntryHashMap = oneImport.getPredictionEntryHashMap();
expInformation = oneImport.getExpInformation();
hasPredictionSpectra = oneImport.getHasPredictionSpectra();

psmScoreName = oneImport.getPSMScoreName();
proteinScoreName = oneImport.getProteinScoreName();
Expand Down Expand Up @@ -3529,14 +3517,16 @@ public void run() {
if (Files.exists(new File(spectralFilePath).toPath())) {
loadingJButton.setText(eachFileName);
// try {
// Thread.sleep(10000);
// sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
try {
readSpectrumFile(spectralFilePath);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
if (e.getClass() != InterruptedException.class){
e.printStackTrace();
}
}
} else {
JOptionPane.showMessageDialog(
Expand Down
57 changes: 50 additions & 7 deletions src/main/java/GUI/SpectrumMainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import com.compomics.util.gui.spectrum.FragmentIonTable;
import com.compomics.util.gui.spectrum.SequenceFragmentationPanel;
import com.compomics.util.gui.spectrum.SpectrumPanel;
import com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX;
import com.compomics.util.preferences.LastSelectedFolder;
import com.compomics.util.preferences.SequenceMatchingPreferences;
import com.compomics.util.preferences.UtilitiesUserPreferences;
import umich.ms.fileio.filetypes.diann.DiannSpeclibReader;
import umich.ms.fileio.filetypes.diann.PredictionEntry;

import javax.swing.*;
Expand Down Expand Up @@ -1136,7 +1138,7 @@ private void exportSpectrumAsMGF(){
*/
private void exportSpectrumAsFigure() {

ExportExpectedSizeDialog exportExpectedSizeDialog = new ExportExpectedSizeDialog(this, spectrumJLayeredPane, sequenceFragmentationPanel, null, spectrumPanel, currentPeptideSequence.length(), currentSpectrum.getSpectrumTitle(), false);
ExportExpectedSizeDialog exportExpectedSizeDialog = new ExportExpectedSizeDialog(this, spectrumJLayeredPane, sequenceFragmentationPanel, null, spectrumPanel, currentPeptideSequence.length(), currentSpectrum.getSpectrumTitle(), true, false, false, false);

spectrumSetAction.setExportDialog(exportExpectedSizeDialog);

Expand All @@ -1148,7 +1150,7 @@ private void exportSpectrumAsFigure() {
*/
private void exportMirrorSpectrumAsFigure() {

ExportExpectedSizeDialog exportExpectedSizeDialog = new ExportExpectedSizeDialog(this, mirrorJLayeredPane, sequenceFragmentationPanelMirror, mirrorFragmentPanel, mirrorSpectrumPanel, currentPeptideSequence.length(), currentSpectrum.getSpectrumTitle(), false);
ExportExpectedSizeDialog exportExpectedSizeDialog = new ExportExpectedSizeDialog(this, mirrorJLayeredPane, sequenceFragmentationPanelMirror, mirrorFragmentPanel, mirrorSpectrumPanel, currentPeptideSequence.length(), currentSpectrum.getSpectrumTitle(), false, true, false, false);

mirrorSetAction.setExportDialog(exportExpectedSizeDialog);

Expand All @@ -1160,7 +1162,7 @@ private void exportMirrorSpectrumAsFigure() {
*/
private void exportCheckSpectrumAsFigure() {

ExportExpectedSizeDialog exportExpectedSizeDialog = new ExportExpectedSizeDialog(this, checkPeptideJLayeredPane, sequenceFragmentationPanelCheck, checkFragmentPanel, checkPeptideSpectrumPanel, currentPeptideSequence.length(), currentSpectrum.getSpectrumTitle(), true);
ExportExpectedSizeDialog exportExpectedSizeDialog = new ExportExpectedSizeDialog(this, checkPeptideJLayeredPane, sequenceFragmentationPanelCheck, checkFragmentPanel, checkPeptideSpectrumPanel, currentPeptideSequence.length(), currentSpectrum.getSpectrumTitle(), false, false, true, false);

checkSetAction.setExportDialog(exportExpectedSizeDialog);

Expand All @@ -1172,7 +1174,7 @@ private void exportCheckSpectrumAsFigure() {
*/
private void exportPreSpectrumAsFigure() {

ExportExpectedSizeDialog exportExpectedSizeDialog = new ExportExpectedSizeDialog(this, predictionJLayeredPane, sequenceFragmentationPanelPredicted, predictedFragmentPanel, predictedSpectrumPanel, currentPeptideSequence.length(), currentSpectrum.getSpectrumTitle(), false);
ExportExpectedSizeDialog exportExpectedSizeDialog = new ExportExpectedSizeDialog(this, predictionJLayeredPane, sequenceFragmentationPanelPredicted, predictedFragmentPanel, predictedSpectrumPanel, currentPeptideSequence.length(), currentSpectrum.getSpectrumTitle(), false, false, false, true);

preSetAction.setExportDialog(exportExpectedSizeDialog);

Expand Down Expand Up @@ -1345,7 +1347,7 @@ public void showCheckPeptideJMenuItemActionPerformed(ActionEvent evt) {
peptideCheckMenu.setVisible(true);
}

private void showPredictionJMenuItemActionPerformed(ActionEvent evt){
public void showPredictionJMenuItemActionPerformed(ActionEvent evt){
showSpectrumSelected = false;
ionTableSelected = false;
mirrorSelected = false;
Expand All @@ -1360,6 +1362,47 @@ private void showPredictionJMenuItemActionPerformed(ActionEvent evt){

exportGraphicsMenu.setVisible(true);

if (parentFrame.predictionEntryHashMap.size() == 0){
ProgressDialogX progressDialog = new ProgressDialogX(parentFrame,
Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/SeaGullMass.png")),
Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/SeaGullMassWait.png")),
true);
progressDialog.setPrimaryProgressCounterIndeterminate(true);
progressDialog.setTitle("First time Loading predicted spectra. Please Wait...");

new Thread(() -> {
try {
progressDialog.setVisible(true);
} catch (IndexOutOfBoundsException ignored) {
}
}, "ProgressDialog").start();
new Thread("Import_Spectra") {
@Override
public void run() {
try {
if (parentFrame.expInformation.contains("inner_defined_empty_exp")) {
DiannSpeclibReader dslr = new DiannSpeclibReader(parentFrame.resultsFolder.getAbsolutePath() + "/spectraRT.predicted.bin");
parentFrame.predictionEntryHashMap = dslr.getPreds();
} else {
for (File eachFileInMax : Objects.requireNonNull(parentFrame.resultsFolder.listFiles())) {
if (parentFrame.expInformation.contains(eachFileInMax.getName())) {
DiannSpeclibReader dslr = new DiannSpeclibReader(eachFileInMax.getAbsolutePath() + "/spectraRT.predicted.bin");
parentFrame.predictionEntryHashMap.putAll(dslr.getPreds());
}
}
}
progressDialog.setRunFinished();
updateSpectrum();
} catch (Exception e){
progressDialog.setRunFinished();
JOptionPane.showMessageDialog(
parentFrame, "Failed to load predicted spectra, please check it.",
"Loading spectrum file error", JOptionPane.ERROR_MESSAGE);
}
}
}.start();
}

mainShowJPanel.removeAll();
GroupLayout mainShowJPanelLayout = new GroupLayout(mainShowJPanel);
mainShowJPanel.setLayout(mainShowJPanelLayout);
Expand Down Expand Up @@ -2162,7 +2205,7 @@ public void updateSpectrum(){
predictionJLayeredPane.add(sequenceFragmentationPanelPredicted);
zoomAction(sequenceFragmentationPanelPredicted, modSequence, false);

mirrorSetAction = new SetAction(this, predictionJLayeredPane, sequenceFragmentationPanelPredicted, predictedFragmentPanel, predictedSpectrumPanel, 0, 0, spectrumShowPanel);
preSetAction = new SetAction(this, predictionJLayeredPane, sequenceFragmentationPanelPredicted, predictedFragmentPanel, predictedSpectrumPanel, 0, 0, spectrumShowPanel);

ArrayList<ArrayList<IonMatch>> allAnnotations = new ArrayList<>();
allAnnotations.add(annotations);
Expand Down Expand Up @@ -2358,7 +2401,7 @@ public void updateSpectrum(SpectrumIdentificationAssumption spectrumIdentificati
}
}

if (parentFrame.predictionEntryHashMap.size() == 0){
if (!parentFrame.hasPredictionSpectra){
showPredictionJMenuItem.setEnabled(false);
}

Expand Down
Loading

0 comments on commit 4880528

Please sign in to comment.