Skip to content

Commit

Permalink
Added single random mutated residue to decoy generation options in Pe…
Browse files Browse the repository at this point in the history
…ptide class
  • Loading branch information
danielgeiszler committed Mar 26, 2024
1 parent a5226f0 commit e19eaa9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
58 changes: 42 additions & 16 deletions src/edu/umich/andykong/ptmshepherd/utils/Peptide.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@
public class Peptide { //TODO theoretical peptide fragments, should this not start at 0? Skip b1/y1/a1?
public String pepSeq;
public float[] mods;
public int mutatedResidue; // for mono-mutated decoys, 0 indexed

public Peptide(String pepSeq, float[] mods) {
this.pepSeq = pepSeq;
this.mods = mods;
}

private Peptide(String pepSeq, float[] mods, int mutatedResidue) {
this(pepSeq, mods);
this.mutatedResidue = mutatedResidue;
}

public static ArrayList<Float> calculatePeptideFragments(String seq, float[] mods, String ionTypes, int maxCharge) {
ArrayList<Float> knownFrags = new ArrayList<>(seq.length() * ionTypes.length());

ArrayList<Character> nIonTypes = new ArrayList<>();
ArrayList<Character> cIonTypes = new ArrayList<>();
// Todo this should start at b2
for (int i = 0; i < ionTypes.length(); i++) {
char curIonType = ionTypes.charAt(i);
if (curIonType == 'a' || curIonType == 'b' || curIonType == 'c')
Expand Down Expand Up @@ -64,25 +70,13 @@ public static Peptide generateDecoy(String pep, float[] mods, Random rng, String
if (method.equals("shuffled"))
return generateShuffledDecoy(pep, mods, rng);
else if (method.equals("mutated"))
return generateMutatedDecoy(pep, mods, rng);
return generateMutatedDecoy(pep, mods);
else if (method.equals("mono-mutated"))
return generateMonoMutatedDecoy(pep, mods, rng);
else
return null; //TODO
}

public static Peptide generateMutatedDecoy(String pep, float[] mods, Random rng) {
ArrayList<Site> sites = new ArrayList<>(pep.length());
for (int i = 0; i < pep.length(); i++)
sites.add(new Site(pep.charAt(i), mods[i]));
sites.get(1).aa = AAMutationRules.mutateFrom.get(sites.get(1).aa);
sites.get(pep.length()-2).aa = AAMutationRules.mutateFrom.get(sites.get(pep.length()-2).aa);

StringBuilder newPep = new StringBuilder();

for (int i = 0; i < sites.size(); i++)
newPep.append(sites.get(i).aa);

return new Peptide(newPep.toString(), mods);
}

public static Peptide generateShuffledDecoy(String pep, float[] mods, Random rng) {
ArrayList<Site> sites = new ArrayList<>(pep.length());
Expand All @@ -108,6 +102,38 @@ public static Peptide generateShuffledDecoy(String pep, float[] mods, Random rng
return new Peptide(newPep.toString(), newMods);
}

public static Peptide generateMutatedDecoy(String pep, float[] mods) {
ArrayList<Site> sites = new ArrayList<>(pep.length());
for (int i = 0; i < pep.length(); i++)
sites.add(new Site(pep.charAt(i), mods[i]));
sites.get(1).aa = AAMutationRules.mutateFrom.get(sites.get(1).aa);
sites.get(pep.length()-2).aa = AAMutationRules.mutateFrom.get(sites.get(pep.length()-2).aa);

StringBuilder newPep = new StringBuilder();

for (int i = 0; i < sites.size(); i++)
newPep.append(sites.get(i).aa);

return new Peptide(newPep.toString(), mods);
}

public static Peptide generateMonoMutatedDecoy(String pep, float[] mods, Random rng) {
int randomSite = rng.nextInt(pep.length());
return generateMonoMutatedDecoy(pep, mods, randomSite);
}

public static Peptide generateMonoMutatedDecoy(String pep, float[] mods, int mutSite) {
StringBuilder newPep = new StringBuilder();
for (int i = 0; i < pep.length(); i++) {
if (i != mutSite)
newPep.append(pep.charAt(i));
else
newPep.append(AAMutationRules.mutateFrom.get(pep.charAt(i)));
}
return new Peptide(newPep.toString(), mods, mutSite);
}


static class Site {
char aa;
float mod;
Expand Down
7 changes: 6 additions & 1 deletion test/utils/PeptideTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ void generateDecoy() {
assertEquals(expectedSeq, decoy.pepSeq);
assertArrayEquals(expectedMods, decoy.mods);

decoy = Peptide.generateDecoy(seq, mods, rng, "mutated");
decoy = Peptide.generateDecoy(seq, mods, rng, "mutated");
expectedSeq = "PDPTIEE";
assertEquals(expectedSeq, decoy.pepSeq);

decoy = Peptide.generateDecoy(seq, mods, rng, "mono-mutated");
expectedSeq = "PEPTIDD";
assertEquals(expectedSeq, decoy.pepSeq);
assertEquals(6, decoy.mutatedResidue);
}
}

0 comments on commit e19eaa9

Please sign in to comment.