Skip to content

Commit

Permalink
Improve MGF title parse and error output.
Browse files Browse the repository at this point in the history
  • Loading branch information
fcyu committed Aug 21, 2017
1 parent 433b183 commit 145eb70
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/proteomics/Spectrum/PreSpectra.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer, SpectrumEntry> num_spectrum_map = new HashMap<>();
private Set<Integer> debug_scan_num_set = new HashSet<>();
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 145eb70

Please sign in to comment.