Skip to content

Commit 2a09902

Browse files
committed
Add the reader.close() missed by e960094.
Other minor refactors and improvements.
1 parent c73f098 commit 2a09902

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

MSFragger-GUI/src/com/dmtavt/fragpipe/tools/skyline/Skyline.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class Skyline {
6464

6565
// convert our names to Skyline names
6666
// names from Skyline cmd documentation (version 24.0-daily, 7/19/2024)
67-
private final static HashMap<String, String> enzymesMap = new HashMap<>();
67+
private final static Map<String, String> enzymesMap = new HashMap<>();
6868
static {
6969
enzymesMap.put("trypsin", "Trypsin");
7070
enzymesMap.put("stricttrypsin", "Trypsin/P");
@@ -103,8 +103,8 @@ private static void runSkyline(String skylinePath, Path wd, String skylineVersio
103103
PropsFile pf = new PropsFile(workflowPath, "for Skyline");
104104
pf.load();
105105

106-
TreeSet<String> lcmsFiles = new TreeSet<>();
107-
TreeSet<String> ddaAndDIAfiles = new TreeSet<>();
106+
Set<String> lcmsFiles = new TreeSet<>();
107+
Set<String> ddaAndDIAfiles = new TreeSet<>();
108108

109109
String dataType = "DDA";
110110
String line;
@@ -141,7 +141,7 @@ private static void runSkyline(String skylinePath, Path wd, String skylineVersio
141141
reader.close();
142142

143143
List<Path> speclibFiles = Files.walk(wd).filter(p -> p.getFileName().toString().endsWith(".speclib")).collect(Collectors.toList());
144-
TreeSet<Path> psmTsvFiles = Files.walk(wd).filter(p -> p.getFileName().toString().startsWith("psm.tsv") && p.getFileName().toString().endsWith("psm.tsv")).collect(Collectors.toCollection(TreeSet::new));
144+
Set<Path> psmTsvFiles = Files.walk(wd).filter(p -> p.getFileName().toString().startsWith("psm.tsv") && p.getFileName().toString().endsWith("psm.tsv")).collect(Collectors.toCollection(TreeSet::new));
145145

146146
if (useSpeclib && speclibFiles.isEmpty()) {
147147
System.out.println("No DIA-NN .speclib files found in " + wd + " but Skyline was set to use the spectral library as input and DIA-NN was enabled. Did the DIA-NN run fail? No Skyline document will be generated.");
@@ -156,7 +156,7 @@ private static void runSkyline(String skylinePath, Path wd, String skylineVersio
156156

157157
Path peptideListPath = skylineOutputDir.resolve("peptide_list.txt").toAbsolutePath();
158158
WritePeptideList pepWriter = new WritePeptideList();
159-
HashMap<String, HashSet<String>> addedMods = pepWriter.writePeptideList(psmTsvFiles, peptideListPath);
159+
Map<String, Set<String>> addedMods = pepWriter.writePeptideList(psmTsvFiles, peptideListPath);
160160

161161
Path modXmlPath = wd.resolve("mod.xml");
162162
WriteSkyMods writeSkyMods = new WriteSkyMods(modXmlPath, pf, modsMode, matchUnimod, !useSpeclib, addedMods);

MSFragger-GUI/src/com/dmtavt/fragpipe/tools/skyline/WritePeptideList.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.regex.Pattern;
88

99
public class WritePeptideList {
10-
private static HashMap<String, Integer> columns;
10+
private static Map<String, Integer> columns;
1111
private static final Pattern sitePattern = Pattern.compile("(\\d+)\\w\\(");
1212
private static final Pattern massPattern = Pattern.compile("(\\([\\d.]+\\))");
1313
private static final Pattern AApattern = Pattern.compile("\\d?([\\w-]+)\\(");
@@ -18,9 +18,9 @@ public class WritePeptideList {
1818
public static final String COL_PROTEIN = "Protein";
1919

2020

21-
public HashMap<String, HashSet<String>> writePeptideList(TreeSet<Path> psmtsvFiles, Path outputPath) throws IOException {
22-
HashMap<String, Set<String>> proteinMap = new HashMap<>();
23-
HashMap<String, HashSet<String>> additiveMods = new HashMap<>();
21+
public Map<String, Set<String>> writePeptideList(Set<Path> psmtsvFiles, Path outputPath) throws IOException {
22+
Map<String, Set<String>> proteinMap = new HashMap<>();
23+
Map<String, Set<String>> additiveMods = new HashMap<>();
2424

2525
for (Path psmtsv: psmtsvFiles) {
2626
BufferedReader reader = new BufferedReader(new FileReader(psmtsv.toFile()));
@@ -35,11 +35,13 @@ public HashMap<String, HashSet<String>> writePeptideList(TreeSet<Path> psmtsvFil
3535
proteinMap.get(protein).add(modpep);
3636
} else {
3737
// initialize new protein and peptide
38-
HashSet<String> peptides = new HashSet<>();
38+
Set<String> peptides = new HashSet<>();
3939
peptides.add(modpep);
4040
proteinMap.put(protein, peptides);
4141
}
4242
}
43+
44+
reader.close();
4345
}
4446

4547
// write output
@@ -60,11 +62,11 @@ public HashMap<String, HashSet<String>> writePeptideList(TreeSet<Path> psmtsvFil
6062
* of "+" characters.
6163
* @return
6264
*/
63-
public static String generateModifiedPeptide(String[] psmSplits, HashMap<String, Integer> columns, boolean addCharge, HashMap<String, HashSet<String>> additiveMods) {
65+
public static String generateModifiedPeptide(String[] psmSplits, Map<String, Integer> columns, boolean addCharge, Map<String, Set<String>> additiveMods) {
6466
String peptide = psmSplits[columns.get(COL_PEPTIDE)];
6567

6668
String[] mods = psmSplits[columns.get(COL_ASSIGNED_MODS)].split(",");
67-
HashMap<Integer, String> modMap = new HashMap<>();
69+
Map<Integer, String> modMap = new TreeMap<>();
6870
for (String mod : mods) {
6971
Matcher siteMatch = sitePattern.matcher(mod);
7072
int site;
@@ -94,15 +96,14 @@ public static String generateModifiedPeptide(String[] psmSplits, HashMap<String,
9496
/**
9597
* Generate a modified peptide String with all Assigned modifications placed within it
9698
*/
97-
private static String insertMods(String peptide, HashMap<Integer, String> modMap) {
98-
TreeMap<Integer, String> sortedMods = new TreeMap<>(modMap);
99+
private static String insertMods(String peptide, Map<Integer, String> modMap) {
99100
StringBuilder modifiedPeptide = new StringBuilder(peptide);
100101

101102
// Offset to account for insertions
102103
int offset = 0;
103104

104105
// Iterate through the sorted entries and insert the mods
105-
for (Map.Entry<Integer, String> entry : sortedMods.entrySet()) {
106+
for (Map.Entry<Integer, String> entry : modMap.entrySet()) {
106107
int position = entry.getKey() + offset;
107108
String mod = entry.getValue();
108109

MSFragger-GUI/src/com/dmtavt/fragpipe/tools/skyline/WriteSSL.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public class WriteSSL {
1010

11-
private static HashMap<String, Integer> columns;
11+
private static Map<String, Integer> columns;
1212
public static final String COL_SCANID = "Spectrum";
1313
public static final String COL_CHARGE = "Charge";
1414
public static final String COL_SCORE = "Probability";
@@ -23,13 +23,13 @@ public class WriteSSL {
2323
* file scan charge sequence score-type score RT IM
2424
* Sequence includes all mods. IM is optional. Score-type can be PERCOLATOR QVALUE or PEPTIDE PROPHET SOMETHING
2525
*/
26-
public void writeSSL(TreeSet<Path> psmtsvFiles, Path outputPath, boolean isPercolator, TreeSet<String> lcmsFiles, boolean useIonQuantPeaks) throws IOException {
26+
public void writeSSL(Set<Path> psmtsvFiles, Path outputPath, boolean isPercolator, Set<String> lcmsFiles, boolean useIonQuantPeaks) throws IOException {
2727
ArrayList<String> output = new ArrayList<>();
2828
boolean isIM = false;
2929
boolean checkIM = true;
3030

3131
// map file paths to the file names that will be in the psm.tsv
32-
HashMap<String, String> lcmsFileNames = new HashMap<>();
32+
Map<String, String> lcmsFileNames = new HashMap<>();
3333
for (String lcmsFile : lcmsFiles) {
3434
Path path = Paths.get(lcmsFile);
3535
String fileName = path.getFileName().toString();
@@ -86,6 +86,8 @@ public void writeSSL(TreeSet<Path> psmtsvFiles, Path outputPath, boolean isPerco
8686
}
8787
output.add(sslLine.toString());
8888
}
89+
90+
reader.close();
8991
}
9092

9193
// write output

MSFragger-GUI/src/com/dmtavt/fragpipe/tools/skyline/WriteSkyMods.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class WriteSkyMods {
7272
}
7373
}
7474

75-
public WriteSkyMods(Path path, PropsFile pf, int modsMode, boolean matchUnimod, boolean isSSL, HashMap<String, HashSet<String>> addedMods) throws Exception {
75+
public WriteSkyMods(Path path, PropsFile pf, int modsMode, boolean matchUnimod, boolean isSSL, Map<String, Set<String>> addedMods) throws Exception {
7676
List<Mod> mods = new ArrayList<>(4);
7777

7878
String fixModStr = pf.getProperty("msfragger.table.fix-mods");
@@ -113,7 +113,7 @@ public WriteSkyMods(Path path, PropsFile pf, int modsMode, boolean matchUnimod,
113113
}
114114

115115
// add any combined mods (multiple at one site) found during peptide list generation
116-
for (Map.Entry<String, HashSet<String>> entry : addedMods.entrySet()) {
116+
for (Map.Entry<String, Set<String>> entry : addedMods.entrySet()) {
117117
mass = Float.parseFloat(entry.getKey());
118118
mods.addAll(convertMods(String.join("", entry.getValue()), true, mass, mass, new ArrayList<>(), new ArrayList<>(), false));
119119
}

0 commit comments

Comments
 (0)