Skip to content

Commit

Permalink
fix crash on spectrum files with names containing '_calibrated'
Browse files Browse the repository at this point in the history
  • Loading branch information
dpolasky committed Sep 25, 2024
1 parent 353d8f2 commit 772f7ee
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/edu/umich/andykong/ptmshepherd/PSMFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,24 @@ public int getColumn(String head) {
return res;
}

/**
* Uses name with file extension to support handling user-named files like "_calibrated.raw", which became
* "_calibrated_calibrated.mzML" and crashed before. Returns filename without extension after removing
* _(un)calibrated.mzML/MGF.
*/
private static String removeCalTag(String fileBaseName) {
if (fileBaseName.contains("_calibrated"))
return fileBaseName.replace("_calibrated", "");
else if (fileBaseName.contains("_uncalibrated"))
return fileBaseName.replace("_uncalibrated", "");
String nameWithExt;
if (fileBaseName.contains("_calibrated.mzML"))
nameWithExt = fileBaseName.replace("_calibrated.mzML", ".mzML");
else if (fileBaseName.contains("_uncalibrated.mzML"))
nameWithExt = fileBaseName.replace("_uncalibrated.mzML", ".mzML");
else if (fileBaseName.contains("_calibrated.MGF"))
nameWithExt = fileBaseName.replace("_calibrated.MGF", ".MGF");
else if (fileBaseName.contains("_uncalibrated.MGF"))
nameWithExt = fileBaseName.replace("_uncalibrated.MGF", ".MGF");
else
return fileBaseName;
nameWithExt = fileBaseName;
return splitName(nameWithExt)[0];
}

public static String getCRC32(File f) throws Exception {
Expand Down Expand Up @@ -420,7 +431,7 @@ public static void getMappings(File path, HashMap<String,File> mappings, HashSet
} else { // see if valid file ext
String matchedKey = getMatchingExtension(path, priorities);
if (matchedKey != null) { // end of name exists in priorities map
String rawFileName = removeCalTag(splitName(path.getName())[0]);
String rawFileName = removeCalTag(path.getName());
// If raw file not part of this analysis, continue
if (!mappings.containsKey(rawFileName))
return;
Expand Down

0 comments on commit 772f7ee

Please sign in to comment.