7
7
import java .util .regex .Pattern ;
8
8
9
9
public class WritePeptideList {
10
+
10
11
private static Map <String , Integer > columns ;
11
- private static final Pattern sitePattern = Pattern .compile ("(\\ d +)\\ w \\ ( " );
12
- private static final Pattern massPattern = Pattern .compile ("( \\ ([\\ d.]+ \\ ) )" );
13
- private static final Pattern AApattern = Pattern .compile ("\\ d?( [\\ w -]+)\\ ( " );
12
+ private static final Pattern varModPattern = Pattern .compile ("([0-9]+)([A-Z]) \\ (([ \\ d.-] +)\\ ) " );
13
+ private static final Pattern nTermModPattern = Pattern .compile ("N-term \\ (( [\\ d.-]+) \\ )" );
14
+ private static final Pattern cTermModPattern = Pattern .compile ("C-term \\ (( [\\ d. -]+)\\ ) " );
14
15
15
16
public static final String COL_ASSIGNED_MODS = "Assigned Modifications" ;
16
17
public static final String COL_PEPTIDE = "Peptide" ;
17
18
public static final String COL_CHARGE = "Charge" ;
18
19
public static final String COL_PROTEIN = "Protein" ;
19
20
20
21
21
- public Map <String , Set <String >> writePeptideList (Set <Path > psmtsvFiles , Path outputPath ) throws IOException {
22
+ public Map <Float , Set <String >> writePeptideList (Set <Path > psmtsvFiles , Path outputPath ) throws IOException {
22
23
Map <String , Set <String >> proteinMap = new HashMap <>();
23
- Map <String , Set <String >> additiveMods = new HashMap <>();
24
+ Map <Float , Set <String >> additiveMods = new HashMap <>();
24
25
25
26
for (Path psmtsv : psmtsvFiles ) {
26
27
BufferedReader reader = new BufferedReader (new FileReader (psmtsv .toFile ()));
@@ -62,31 +63,48 @@ public Map<String, Set<String>> writePeptideList(Set<Path> psmtsvFiles, Path out
62
63
* of "+" characters.
63
64
* @return
64
65
*/
65
- public static String generateModifiedPeptide (String [] psmSplits , Map <String , Integer > columns , boolean addCharge , Map <String , Set <String >> additiveMods ) {
66
+ public static String generateModifiedPeptide (String [] psmSplits , Map <String , Integer > columns , boolean addCharge , Map <Float , Set <String >> additiveMods ) {
66
67
String peptide = psmSplits [columns .get (COL_PEPTIDE )];
68
+ String mods = psmSplits [columns .get (COL_ASSIGNED_MODS )].trim ();
69
+ Map <Integer , Float > modMap = new HashMap <>();
70
+
71
+ Matcher m = nTermModPattern .matcher (mods );
72
+ while (m .find ()) {
73
+ Float f = modMap .get (1 );
74
+ if (f != null ) {
75
+ f += Float .parseFloat (m .group (1 ));
76
+ modMap .put (1 , f );
77
+ additiveMods .computeIfAbsent (f , k -> new HashSet <>()).add ("n^" );
78
+ } else {
79
+ modMap .put (1 , Float .parseFloat (m .group (1 )));
80
+ }
81
+ }
67
82
68
- String [] mods = psmSplits [columns .get (COL_ASSIGNED_MODS )].split ("," );
69
- Map <Integer , String > modMap = new TreeMap <>();
70
- for (String mod : mods ) {
71
- Matcher siteMatch = sitePattern .matcher (mod );
72
- int site ;
73
- if (siteMatch .find ()) {
74
- site = Integer .parseInt (siteMatch .group (1 ));
75
- Matcher massMatch = massPattern .matcher (mod );
76
- if (massMatch .find ()) {
77
- if (modMap .containsKey (site )) {
78
- // handle multiple mods (e.g., 5C(57.0215),5C(100.00)) by adding masses together into a single mod
79
- double mass = Double .parseDouble (massMatch .group (1 ).replace ("(" , "" ).replace (")" , "" ));
80
- mass += Double .parseDouble (modMap .get (site ).replace ("[" , "" ).replace ("]" , "" ));
81
- modMap .put (site , String .format ("[%.5f]" , mass ));
82
- // add mod to list for appending to mod.xml
83
- additiveMods .computeIfAbsent (String .format ("%.4f" , mass ), k -> new HashSet <>()).add (getSite (mod ));
84
- } else {
85
- modMap .put (site , massMatch .group (1 ).replace ("(" , "[" ).replace (")" , "]" ));
86
- }
87
- }
83
+ m = cTermModPattern .matcher (mods );
84
+ while (m .find ()) {
85
+ Float f = modMap .get (peptide .length ());
86
+ if (f != null ) {
87
+ f += Float .parseFloat (m .group (1 ));
88
+ modMap .put (peptide .length (), f );
89
+ additiveMods .computeIfAbsent (f , k -> new HashSet <>()).add ("c^" );
90
+ } else {
91
+ modMap .put (peptide .length (), Float .parseFloat (m .group (1 )));
92
+ }
93
+ }
94
+
95
+ m = varModPattern .matcher (mods );
96
+ while (m .find ()) {
97
+ int site = Integer .parseInt (m .group (1 ));
98
+ Float f = modMap .get (site );
99
+ if (f != null ) {
100
+ f += Float .parseFloat (m .group (3 ));
101
+ modMap .put (site , f );
102
+ additiveMods .computeIfAbsent (f , k -> new HashSet <>()).add (m .group (2 ));
103
+ } else {
104
+ modMap .put (site , Float .parseFloat (m .group (3 )));
88
105
}
89
106
}
107
+
90
108
String modPep = insertMods (peptide , modMap );
91
109
int charge = Integer .parseInt (psmSplits [columns .get (COL_CHARGE )]);
92
110
String chargeStr = addCharge ? "+" .repeat (charge ) : "" ;
@@ -96,34 +114,21 @@ public static String generateModifiedPeptide(String[] psmSplits, Map<String, Int
96
114
/**
97
115
* Generate a modified peptide String with all Assigned modifications placed within it
98
116
*/
99
- private static String insertMods (String peptide , Map <Integer , String > modMap ) {
100
- StringBuilder modifiedPeptide = new StringBuilder (peptide );
101
-
102
- // Offset to account for insertions
103
- int offset = 0 ;
104
-
105
- // Iterate through the sorted entries and insert the mods
106
- for (Map .Entry <Integer , String > entry : modMap .entrySet ()) {
107
- int position = entry .getKey () + offset ;
108
- String mod = entry .getValue ();
109
-
110
- if (position >= 0 && position <= modifiedPeptide .length ()) {
111
- modifiedPeptide .insert (position , mod );
112
- offset += mod .length ();
117
+ private static String insertMods (String peptide , Map <Integer , Float > modMap ) {
118
+ StringBuilder modifiedPeptide = new StringBuilder (peptide .length ());
119
+ char [] aas = peptide .toCharArray ();
120
+ for (int i = 0 ; i < aas .length ; ++i ) {
121
+ Float f = modMap .get (i + 1 );
122
+ if (f != null ) {
123
+ // With more decimal digits, there will be mismatches between the floating point values from FragPipe and Skyline.
124
+ modifiedPeptide .append (String .format ("%c[%.1f]" , aas [i ], f ));
125
+ } else {
126
+ modifiedPeptide .append (aas [i ]);
113
127
}
114
128
}
115
129
return modifiedPeptide .toString ();
116
130
}
117
131
118
- // Return the AA (or terminus) of a given Assigned Mod
119
- private static String getSite (String mod ) {
120
- Matcher m = AApattern .matcher (mod );
121
- if (m .find ()) {
122
- return m .group (1 );
123
- }
124
- return "" ;
125
- }
126
-
127
132
private String initHeader (String header ) {
128
133
columns = new HashMap <>();
129
134
String [] splits = header .split ("\t " );
0 commit comments