Skip to content

Commit

Permalink
add remainder fragment intensities and counts to diagnostic extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
dpolasky committed Jun 12, 2024
1 parent 1771d0d commit 86bc546
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 21 deletions.
23 changes: 23 additions & 0 deletions src/edu/umich/andykong/ptmshepherd/PTMShepherd.java
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,29 @@ public static String concatIonTypes() {
sb.append("z");
return sb.toString();
}

public static ArrayList<Character> getNionTypes() {
ArrayList<Character> nIonTypes = new ArrayList<>();
if (PTMShepherd.getParam("iontype_a").trim().equals("1"))
nIonTypes.add('a');
if (PTMShepherd.getParam("iontype_b").trim().equals("1"))
nIonTypes.add('b');
if (PTMShepherd.getParam("iontype_c").trim().equals("1"))
nIonTypes.add('c');
return nIonTypes;
}

public static ArrayList<Character> getCionTypes() {
ArrayList<Character> cIonTypes = new ArrayList<>();
if (PTMShepherd.getParam("iontype_x").trim().equals("1"))
cIonTypes.add('x');
if (PTMShepherd.getParam("iontype_y").trim().equals("1"))
cIonTypes.add('y');
if (PTMShepherd.getParam("iontype_z").trim().equals("1"))
cIonTypes.add('z');
return cIonTypes;
}

private static GlycoParams parseGlycoParams() {
String glycanResidueDB = getParam("glyco_residue_list");
String glycanModDB = getParam("glyco_mod_list");
Expand Down
89 changes: 74 additions & 15 deletions src/edu/umich/andykong/ptmshepherd/core/Spectrum.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,78 @@ public float getHyper(String seq, float [] mods, double ppmTol) {

return score;
}

public void getRemainderFrags(String seq, float [] mods, double ppmTol, TreeMap<Character, Float> ionIntensities, TreeMap<Character, Integer> ionCounts, int modPos) {
int maxCharge = (charge==2)?1:2;

float [] aaMasses = AAMasses.monoisotopic_masses;
float [] fragTypeShifts = AAMasses.ionTypeShifts;

float cM = 0;
double tol;
int fP = 0;
int cLen = seq.length();

float nTermMass;
for (Character iType : ionIntensities.keySet()) {
if (iType < 'd') {
nTermMass = fragTypeShifts[iType - 'a'];
for (int ccharge = 1; ccharge <= maxCharge; ccharge++) {
double cmass = AAMasses.monoisotopic_nterm_mass + nTermMass;
float iB = 0.0f;
int nB = 0;
fP = 0;
for (int i = 0; i < cLen - 1; i++) {
cmass += (aaMasses[seq.charAt(i) - 'A'] + mods[i]) / ccharge;
if (i >= modPos) { // only record fragment remainder intensity including the provided mod site
tol = cmass * (ppmTol / 1000000.0);
while (fP < peakMZ.length && peakMZ[fP] < (cmass - tol))
fP++;
if (fP < peakMZ.length && Math.abs(peakMZ[fP] - cmass) < tol) {
cM = peakInt[fP];
} else
cM = 0;
if (cM > 0) {
nB++;
iB += cM;
}
}
}
ionIntensities.put(iType, ionIntensities.get(iType) + iB);
ionCounts.put(iType, ionCounts.get(iType) + nB);
}
} else {
float cTermMass;
cTermMass = fragTypeShifts[iType - 'x' + 3];
for (int ccharge = 1; ccharge <= maxCharge; ccharge++) {
float iY = 0.0f;
int nY = 0;
//double cmass = (AAMasses.monoisotopic_cterm_mass + (ccharge + 1) * AAMasses.monoisotopic_nterm_mass) / ccharge;
double cmass = (cTermMass + ccharge * AAMasses.monoisotopic_nterm_mass) / ccharge;
fP = 0;
for (int i = 0; i < cLen - 1; i++) {
cmass += (aaMasses[seq.charAt(cLen - 1 - i) - 'A'] + mods[cLen - 1 - i]) / ccharge;
if (cLen - 1 - i <= modPos) {
tol = cmass * (ppmTol / 1000000.0);
while (fP < peakMZ.length && peakMZ[fP] < (cmass - tol))
fP++;
if (fP < peakMZ.length && Math.abs(peakMZ[fP] - cmass) < tol) {
cM = peakInt[fP];
} else
cM = 0;
if (cM > 0) {
nY++;
iY += cM;
}
}
}
ionIntensities.put(iType, ionIntensities.get(iType) + iY);
ionCounts.put(iType, ionCounts.get(iType) + nY);
}
}
}
}


public int getFrags(String seq, float [] mods, double ppmTol) {
float iB = 0.0f, iY = 0.0f;
Expand All @@ -316,21 +388,8 @@ public int getFrags(String seq, float [] mods, double ppmTol) {
int fP = 0;
int cLen = seq.length();

ArrayList<Character> nIonTypes = new ArrayList<>();
ArrayList<Character> cIonTypes = new ArrayList<>();

if (PTMShepherd.getParam("iontype_a").trim().equals("1"))
nIonTypes.add('a');
if (PTMShepherd.getParam("iontype_b").trim().equals("1"))
nIonTypes.add('b');
if (PTMShepherd.getParam("iontype_c").trim().equals("1"))
nIonTypes.add('c');
if (PTMShepherd.getParam("iontype_x").trim().equals("1"))
cIonTypes.add('x');
if (PTMShepherd.getParam("iontype_y").trim().equals("1"))
cIonTypes.add('y');
if (PTMShepherd.getParam("iontype_z").trim().equals("1"))
cIonTypes.add('z');
ArrayList<Character> nIonTypes = PTMShepherd.getNionTypes();
ArrayList<Character> cIonTypes = PTMShepherd.getCionTypes();

float nTermMass;
for (Character iType : nIonTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

Expand Down Expand Up @@ -93,10 +94,17 @@ public void extractDiagPSMs(PSMFile pf, HashMap<String, File> mzMappings, Execut

//write header
StringBuilder diagnosticHeader = new StringBuilder(String.format("%s\t%s\t%s\t%s\t%s", "Spectrum", "Peptide", "Mods", "Pep Mass", "Mass Shift"));
String ionTypes = PTMShepherd.concatIonTypes();

for (double capYShift : capYShifts) diagnosticHeader.append(String.format("\tY_%.4f_intensity", capYShift));
for (double oxoniumIon : oxoniumIons) diagnosticHeader.append(String.format("\tox_%.4f_intensity", oxoniumIon));
for (double remainderMass : remainderMasses) diagnosticHeader.append(String.format("\tdeltascore_%.4f\tlocalization_%.4f", remainderMass, remainderMass));
for (double remainderMass : remainderMasses) {
diagnosticHeader.append(String.format("\tdeltascore_%.4f\tlocalization_%.4f", remainderMass, remainderMass));
for (int k=0; k < ionTypes.length(); k++) {
diagnosticHeader.append(String.format("\tCount_%s_%.4f", ionTypes.charAt(k), remainderMass));
diagnosticHeader.append(String.format("\tInt_%s_%.4f", ionTypes.charAt(k), remainderMass));
}
}
diagnosticOut.println(diagnosticHeader);
//get necessary col indices
specCol = pf.getColumn("Spectrum");
Expand Down Expand Up @@ -201,7 +209,10 @@ public String processLine(String line) {
for (double oxoniumIonIntensity : oxoniumIonIntensities)
diagnosticResultString.append(String.format("\t%.2f", oxoniumIonIntensity));
float[] deltaScores = new float[remainderMasses.length];
boolean[][] isMaxScores = localizeRemainderFragments(spec, sp[pepCol], smods, deltaScores);
String ionTypes = PTMShepherd.concatIonTypes();
float[][] remainderIntensities = new float[remainderMasses.length][ionTypes.length()];
int[][] remainderCounts = new int[remainderMasses.length][ionTypes.length()];
boolean[][] isMaxScores = localizeRemainderFragments(spec, sp[pepCol], smods, deltaScores, remainderIntensities, remainderCounts);

for (int i = 0; i < remainderMasses.length; i++) {
diagnosticResultString.append(String.format("\t%.1f", deltaScores[i]));
Expand All @@ -211,6 +222,11 @@ public String processLine(String line) {
locSb.append(String.format("%d%c", j + 1, seq.charAt(j))); //position (1 indexed), character
}
}
// add remainder intensities
for (int k=0; k < ionTypes.length(); k++) {
locSb.append(String.format("\t%d", remainderCounts[i][k]));
locSb.append(String.format("\t%.1f", remainderIntensities[i][k]));
}
diagnosticResultString.append(locSb);
}
return diagnosticResultString.toString();
Expand Down Expand Up @@ -271,7 +287,7 @@ public double[] findOxoniumIonMasses(Spectrum spec, double pepMass) {
return oxoniumIonIntensities;
}

public boolean[][] localizeRemainderFragments(Spectrum spec, String seq, String[] smods, float[] deltaScores) {
public boolean[][] localizeRemainderFragments(Spectrum spec, String seq, String[] smods, float[] deltaScores, float[][] remainderInts, int[][] remainderCounts) {
//initialize allowed positions
boolean [] allowedPoses = SiteLocalization.parseAllowedPositions(seq, PTMShepherd.getParam("localization_allowed_res"));
//initialize remainder delta scores
Expand Down Expand Up @@ -305,6 +321,7 @@ else if(spos.equals("c")) {
boolean [][] isMaxScores = new boolean[remainderMasses.length][seq.length()]; //1 if localized AND = max score
//these 3 variables store values that are constant for the PSM

String ionTypes = PTMShepherd.concatIonTypes();
float baseScore = spec.getHyper(seq, mods, ppmTol);
int baseFrags = spec.getFrags(seq, mods, ppmTol);
//these 3 variables need to be reinitialized every remainder mass
Expand All @@ -319,27 +336,41 @@ else if(spos.equals("c")) {
frags = new int[seq.length()];
maxScores[i] = baseScore;
maxFrags[i] = baseFrags;

//localize at each position
for(int j = 0; j < seq.length(); j++) {
if (allowedPoses[j])
mods[j] += dmass;
scores[j] = spec.getHyper(seq, mods, ppmTol);
//System.out.println(scores[j] + "score");
frags[j] = spec.getFrags(seq, mods, ppmTol);
if(frags[j] > maxFrags[i])
if(frags[j] > maxFrags[i]) {
maxFrags[i] = frags[j];
if(scores[j] > maxScores[i])
}
if(scores[j] > maxScores[i]) {
maxScores[i] = scores[j];
}
if (allowedPoses[j])
mods[j] -= dmass;
}

//System.out.println(maxScores[i]+"maxscore");
//determine if localized and record max positions
if (maxScores[i] > baseScore) {
deltaScores[i] = maxScores[i] - baseScore;
for (int j = 0; j < seq.length(); j++) {
if (scores[j] == maxScores[i]) {
isMaxScores[i][j] = true;
// save remainder fragment intensities for best position only
TreeMap<Character, Float> ionIntensities = initIonIntensities();
TreeMap<Character, Integer> ionCounts = initIonCounts();
mods[j] += (float) dmass;
spec.getRemainderFrags(seq, mods, ppmTol, ionIntensities, ionCounts, j);
mods[j] -= (float) dmass;
for (int k=0; k < ionIntensities.size(); k++) {
remainderInts[i][k] = ionIntensities.get(ionTypes.charAt(k));
remainderCounts[i][k] = ionCounts.get(ionTypes.charAt(k));
}
} else {
isMaxScores[i][j] = false;
}
Expand Down Expand Up @@ -369,6 +400,25 @@ public boolean isDiagnosticComplete() throws Exception {
}
return false;
}

private TreeMap<Character, Float> initIonIntensities() {
TreeMap<Character, Float> ionIntensities = new TreeMap<>();
String ionTypes = PTMShepherd.concatIonTypes();
for (int i=0; i < ionTypes.length(); i++) {
ionIntensities.put(ionTypes.charAt(i), 0.0F);
}
return ionIntensities;
}

private TreeMap<Character, Integer> initIonCounts() {
TreeMap<Character, Integer> ionCounts = new TreeMap<>();
String ionTypes = PTMShepherd.concatIonTypes();
for (int i=0; i < ionTypes.length(); i++) {
ionCounts.put(ionTypes.charAt(i), 0);
}
return ionCounts;
}

public void completeDiagnostic() throws Exception {
PrintWriter out = new PrintWriter(new FileWriter(rawDiagnosticFile,true));
out.println("COMPLETE");
Expand Down
2 changes: 1 addition & 1 deletion src/edu/umich/andykong/ptmshepherd/glyco/GlycoRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void updateWithLine(String [] sp) {
}
//get instances of remainder frag identified
startCol = endCol;
endCol = sp.length;
endCol = startCol + remFragCounts.length;
for(int i = startCol; i < endCol; i++){
cInt = Double.parseDouble(sp[i]); //is actually delta score, not intensity
if (cInt > 0.0) {
Expand Down

0 comments on commit 86bc546

Please sign in to comment.