Skip to content

Commit

Permalink
Update spectra files import logic
Browse files Browse the repository at this point in the history
Support to read mzML files directly without raw files.
  • Loading branch information
KaiLiCn committed Feb 9, 2024
1 parent b2c1d72 commit 537260e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 81 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<packaging>jar</packaging>
<groupId>org.example</groupId>
<artifactId>FP-PDV</artifactId>
<version>1.1.7</version>
<version>1.1.8</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
97 changes: 19 additions & 78 deletions src/main/java/GUI/GUIMainClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -3680,7 +3680,7 @@ public void run() {
loadingJButton.setText(eachFileName);

try {
readSpectrumFile(spectralFilePath);
readSpectrumFile(spectralFilePath, eachFileName);
if (addNewFile && Objects.equals(newSpectrumFile, eachFileName)){
updateSpectrum(getSpectrum(selectedPsmKey), spectrumMatch);
importNewFileDialog.setRunFinished();
Expand Down Expand Up @@ -3709,69 +3709,12 @@ public void run() {
readFactoryThread.start();
}

// private void updateSpectrumFactory(Boolean addNew, String addOneFile, ProgressDialogX progressDialog){
// if (addNew){
// String spectralFilePath = spectrumFileMap.get(addOneFile);
//
// if (Files.exists(new File(spectralFilePath).toPath())) {
// try {
// readSpectrumFile(spectralFilePath);
// progressDialog.setRunFinished();
// } catch (IOException | ClassNotFoundException e) {
// e.printStackTrace();
// }
// } else {
// JOptionPane.showMessageDialog(
// null, "Invalid spectrum file path, please check it.",
// "Loading spectrum file error", JOptionPane.ERROR_MESSAGE);
// progressDialog.setRunFinished();
// }
// finishedSpectrumFiles.add(addOneFile);
// }
//
// readFactoryThread = new Thread("ImportSpectrum") {
// @Override
// public void run() {
// for (String eachFileName : spectrumFileOrder){
// if (!finishedSpectrumFiles.contains(eachFileName)){
// String spectralFilePath = spectrumFileMap.get(eachFileName);
// if (Files.exists(new File(spectralFilePath).toPath())) {
// loadingJButton.setText(eachFileName);
//// try {
//// sleep(1000);
//// } catch (InterruptedException e) {
//// e.printStackTrace();
//// }
// try {
// readSpectrumFile(spectralFilePath);
// } catch (Exception e) {
// if (e.getClass() != InterruptedException.class){
// e.printStackTrace();
// }
// }
// } else {
// JOptionPane.showMessageDialog(
// null, "Invalid spectrum file path, please check it.",
// "Loading spectrum file error", JOptionPane.ERROR_MESSAGE);
// }
// finishedSpectrumFiles.add(eachFileName);
// }
// }
// loadingJButton.setIcon(new ImageIcon(getClass().getResource("/icons/done.png")));
// loadingJButton.setText("Import done");
//
// }
// };
// readFactoryThread.start();
// }

private void updateSpectrumFactoryFirst(ProgressDialogX progressDialog, String firstTitle) {
String spectrumFileName = firstTitle.split("\\.")[0];
String spectralFilePath = spectrumFileMap.get(spectrumFileName);
System.out.println(spectrumFileMap);
try {
if (Files.exists(new File(spectralFilePath).toPath())) {
readSpectrumFile(spectralFilePath);
readSpectrumFile(spectralFilePath, spectrumFileName);
} else {
JOptionPane.showMessageDialog(
null, "Invalid spectrum file path, please check it.",
Expand All @@ -3790,29 +3733,29 @@ private void updateSpectrumFactoryFirst(ProgressDialogX progressDialog, String f
progressDialog.setRunFinished();
}

private void readSpectrumFile(String spectralFilePath) throws IOException, ClassNotFoundException {
String spectrumName = new File(spectralFilePath).getName().split("\\.")[0];
private void readSpectrumFile(String spectralFilePath, String spectrumName) throws IOException, ClassNotFoundException {
// String spectrumName = new File(spectralFilePath).getName().split("\\.")[0];
if (!spectrumFileTypes.containsKey(spectrumName)){

if (spectralFilePath.endsWith("mgf")){
spectrumFactory.addSpectra(new File(spectralFilePath));
mgfFiles.add(spectralFilePath);
spectrumFileTypes.put(spectrumName, "mgf");
} else if (spectralFilePath.endsWith("raw")){
if (new File(spectralFilePath.replace(".raw", "_uncalibrated.mzml")).exists()){
addOneMzML(spectrumName, spectralFilePath.replace(".raw", "_uncalibrated.mzml"));
} else {
addOneMzML(spectrumName, spectralFilePath.replace(".raw", "_calibrated.mzml"));
}

} else if (spectralFilePath.endsWith(".d")){
if (new File(spectralFilePath.replace(".d", "_uncalibrated.mzml")).exists()){
addOneMzML(spectrumName, spectralFilePath.replace(".d", "_uncalibrated.mzml"));
} else if (new File(spectralFilePath.replace(".d", "_calibrated.mzml")).exists()){
addOneMzML(spectrumName, spectralFilePath.replace(".d", "_calibrated.mzml"));
} else {
addOneMzML(spectrumName + "_centric", spectralFilePath.replace(".d", "_centric.mzML"));
}
// } else if (spectralFilePath.endsWith("raw")){
// if (new File(spectralFilePath.replace(".raw", "_uncalibrated.mzml")).exists()){
// addOneMzML(spectrumName, spectralFilePath.replace(".raw", "_uncalibrated.mzml"));
// } else {
// addOneMzML(spectrumName, spectralFilePath.replace(".raw", "_calibrated.mzml"));
// }
//
// } else if (spectralFilePath.endsWith(".d")){
// if (new File(spectralFilePath.replace(".d", "_uncalibrated.mzml")).exists()){
// addOneMzML(spectrumName, spectralFilePath.replace(".d", "_uncalibrated.mzml"));
// } else if (new File(spectralFilePath.replace(".d", "_calibrated.mzml")).exists()){
// addOneMzML(spectrumName, spectralFilePath.replace(".d", "_calibrated.mzml"));
// } else {
// addOneMzML(spectrumName + "_centric", spectralFilePath.replace(".d", "_centric.mzML"));
// }

} else if (spectralFilePath.toLowerCase().endsWith("mzml")){
addOneMzML(spectrumName, spectralFilePath);
Expand All @@ -3824,8 +3767,6 @@ private void readSpectrumFile(String spectralFilePath) throws IOException, Class
}

private void addOneMzML(String spectrumName, String spectralFilePath){
System.out.println(spectrumName);
System.out.println("Reading " + spectralFilePath);
MZMLFile mzmlFile = new MZMLFile(spectralFilePath);
mzmlFile.setNumThreadsForParsing(threadsNumber);
ScanCollectionDefault scans = new ScanCollectionDefault();
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/GUI/utils/ImportData.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,19 @@ private void processManifestFile(File mainFestFile) throws IOException {
spectrumFileMap.put(fileArr[fileArr.length-1].split("\\.mzml")[0], lineSplit[0]);
} else if (lineSplit[0].endsWith(".raw")){
String[] fileArr = lineSplit[0].split(pattern);
spectrumFileMap.put(fileArr[fileArr.length-1].split("\\.raw")[0], lineSplit[0]);
if (new File(lineSplit[0].replace(".raw", "_uncalibrated.mzml")).exists()){
spectrumFileMap.put(fileArr[fileArr.length-1].split("\\.raw")[0], lineSplit[0].replace(".raw", "_uncalibrated.mzml"));
} else {
spectrumFileMap.put(fileArr[fileArr.length-1].split("\\.raw")[0], lineSplit[0].replace(".raw", "_calibrated.mzml"));
}

} else if (lineSplit[0].endsWith(".d")){
String[] fileArr = lineSplit[0].split(pattern);
spectrumFileMap.put(fileArr[fileArr.length-1].split("\\.d")[0], lineSplit[0]);
if (new File(lineSplit[0].replace(".d", "_uncalibrated.mzml")).exists()){
spectrumFileMap.put(fileArr[fileArr.length-1].split("\\.d")[0], lineSplit[0].replace(".d", "_uncalibrated.mzml"));
} else {
spectrumFileMap.put(fileArr[fileArr.length-1].split("\\.d")[0], lineSplit[0].replace(".d", "_calibrated.mzml"));
}
}

if (Objects.equals(lineSplit[1], "") || Objects.equals(lineSplit[3], "DIA")){
Expand Down

0 comments on commit 537260e

Please sign in to comment.