From 145eb70a0c491026414e9fbdc7efd857d5ac7572 Mon Sep 17 00:00:00 2001 From: Fengchao Date: Mon, 21 Aug 2017 20:06:15 +0800 Subject: [PATCH] Improve MGF title parse and error output. --- .../java/proteomics/Spectrum/PreSpectra.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/proteomics/Spectrum/PreSpectra.java b/src/main/java/proteomics/Spectrum/PreSpectra.java index 78e5839..260ffec 100644 --- a/src/main/java/proteomics/Spectrum/PreSpectra.java +++ b/src/main/java/proteomics/Spectrum/PreSpectra.java @@ -20,7 +20,9 @@ public class PreSpectra { private static final Logger logger = LoggerFactory.getLogger(PreSpectra.class); private static final Pattern pattern = Pattern.compile("^[0-9]+$"); - private static final Pattern scanNumPattern = Pattern.compile("Scan:([0-9]+) "); + private static final Pattern scanNumPattern1 = Pattern.compile("Scan:([0-9]+) ", Pattern.CASE_INSENSITIVE); + private static final Pattern scanNumPattern2 = Pattern.compile("scan=([0-9]+)", Pattern.CASE_INSENSITIVE); + private static final Pattern scanNumPattern3 = Pattern.compile("^[^.]+\\.([0-9]+)\\.[0-9]+\\.[0-9]"); private Map num_spectrum_map = new HashMap<>(); private Set debug_scan_num_set = new HashSet<>(); @@ -111,11 +113,17 @@ public void write(int b) throws IOException {} try { if (ext.toLowerCase().contentEquals("mgf")) { mgfTitle = ((Ms2Query) spectrum).getTitle(); - Matcher matcher = scanNumPattern.matcher(mgfTitle); - if (matcher.find()) { - scan_num = Integer.valueOf(matcher.group(1)); + Matcher matcher1 = scanNumPattern1.matcher(mgfTitle); + Matcher matcher2 = scanNumPattern2.matcher(mgfTitle); + Matcher matcher3 = scanNumPattern3.matcher(mgfTitle); + if (matcher1.find()) { + scan_num = Integer.valueOf(matcher1.group(1)); + } else if (matcher2.find()) { + scan_num = Integer.valueOf(matcher2.group(1)); + } else if (matcher3.find()) { + scan_num = Integer.valueOf(matcher3.group(1)); } else { - logger.error("Cannot get scan number from the MGF file. PIPI only support the MGF files converted from ReAdw4Mascot4."); + logger.error("Cannot get scan number from the MGF title {}. Please report your MGF title to the author.", mgfTitle); System.exit(1); } } else {