7
7
import java .util .regex .Pattern ;
8
8
9
9
public class WritePeptideList {
10
- private static HashMap <String , Integer > columns ;
10
+ private static Map <String , Integer > columns ;
11
11
private static final Pattern sitePattern = Pattern .compile ("(\\ d+)\\ w\\ (" );
12
12
private static final Pattern massPattern = Pattern .compile ("(\\ ([\\ d.]+\\ ))" );
13
13
private static final Pattern AApattern = Pattern .compile ("\\ d?([\\ w-]+)\\ (" );
@@ -18,9 +18,9 @@ public class WritePeptideList {
18
18
public static final String COL_PROTEIN = "Protein" ;
19
19
20
20
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 <>();
24
24
25
25
for (Path psmtsv : psmtsvFiles ) {
26
26
BufferedReader reader = new BufferedReader (new FileReader (psmtsv .toFile ()));
@@ -35,11 +35,13 @@ public HashMap<String, HashSet<String>> writePeptideList(TreeSet<Path> psmtsvFil
35
35
proteinMap .get (protein ).add (modpep );
36
36
} else {
37
37
// initialize new protein and peptide
38
- HashSet <String > peptides = new HashSet <>();
38
+ Set <String > peptides = new HashSet <>();
39
39
peptides .add (modpep );
40
40
proteinMap .put (protein , peptides );
41
41
}
42
42
}
43
+
44
+ reader .close ();
43
45
}
44
46
45
47
// write output
@@ -60,11 +62,11 @@ public HashMap<String, HashSet<String>> writePeptideList(TreeSet<Path> psmtsvFil
60
62
* of "+" characters.
61
63
* @return
62
64
*/
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 ) {
64
66
String peptide = psmSplits [columns .get (COL_PEPTIDE )];
65
67
66
68
String [] mods = psmSplits [columns .get (COL_ASSIGNED_MODS )].split ("," );
67
- HashMap <Integer , String > modMap = new HashMap <>();
69
+ Map <Integer , String > modMap = new TreeMap <>();
68
70
for (String mod : mods ) {
69
71
Matcher siteMatch = sitePattern .matcher (mod );
70
72
int site ;
@@ -94,15 +96,14 @@ public static String generateModifiedPeptide(String[] psmSplits, HashMap<String,
94
96
/**
95
97
* Generate a modified peptide String with all Assigned modifications placed within it
96
98
*/
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 ) {
99
100
StringBuilder modifiedPeptide = new StringBuilder (peptide );
100
101
101
102
// Offset to account for insertions
102
103
int offset = 0 ;
103
104
104
105
// 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 ()) {
106
107
int position = entry .getKey () + offset ;
107
108
String mod = entry .getValue ();
108
109
0 commit comments