Skip to content

Commit

Permalink
Merge pull request #317 from ncats/protein_disulf_hotfix
Browse files Browse the repository at this point in the history
Protein disulf hotfix
  • Loading branch information
blueSwordfish authored Feb 1, 2024
2 parents 4fc5769 + 36b57fa commit 6c4a1e0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,31 @@ public void proteinMolFormulaTest() {
"Formula must be the same when protein sequence includes lowercase codes");
}

@Test
public void proteinMolFormulaDisulfidesTest() {
ProteinSubstance proteinSubstance = new ProteinSubstance();
Protein protein = new Protein();
Subunit subunit1= new Subunit();
protein.subunits = new ArrayList<>();
protein.subunits.add(subunit1);
subunit1.sequence =
"CMMC";

DisulfideLink disulfideLink = new DisulfideLink();
List<Site> sitesDisulfide = new ArrayList<>();
sitesDisulfide.add(new Site(1, 1));
sitesDisulfide.add(new Site(1, 4));
disulfideLink.setSites(sitesDisulfide);
protein.setDisulfideLinks(Collections.singletonList(disulfideLink));
proteinSubstance.setProtein(protein);

Set<String> unknownResidues = new HashSet<>();

MolecularWeightAndFormulaContribution contribution=ProteinUtils.generateProteinWeightAndFormula(substanceRepository,
proteinSubstance, unknownResidues);
assertEquals("C16H28N4O5S4", contribution.getFormula());
}

@Test
public void aparaginePeptideMolFormulaTest() {
ProteinSubstance proteinSubstance = new ProteinSubstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ public static MolecularWeightAndFormulaContribution generateProteinWeightAndForm
log.trace(String.format("basic MW: %.2f; basic formula: %s; disulfideContribution: %.2f",
total, makeFormulaFromMap(formulaCounts), disulfideContribution));
total -= disulfideContribution;
int numberOfHydrogensToRemove = getNumberOfHydrogensToRemoveForDisulfides(ps.protein);
log.trace("numberOfHydrogensToRemove: {}", numberOfHydrogensToRemove);
Map<String, SingleThreadCounter> formulaMapWithContrib[] =new Map[1];
formulaMapWithContrib[0]=formulaCounts;
if (ps.hasModifications() && ps.modifications.structuralModifications.size() > 0) {
Expand Down Expand Up @@ -413,6 +415,10 @@ else if (contribution.getMw() > 0 || (contribution.getMwHigh() > 0 && contributi
log.debug("no mods to consider");
}

if( formulaMapWithContrib[0].containsKey("H")) {
log.trace("going to remove {} H atoms for disulfide bonds", numberOfHydrogensToRemove);
formulaMapWithContrib[0].get("H").decrement(numberOfHydrogensToRemove);
}
log.trace(String.format("final total: %.2f; highTotal: %.2f; lowTotal: %.2f; highLimitTotal: %.2f; lowLimitTotal: %.2f", total,
highTotal, lowTotal, highLimitTotal, lowLimitTotal));
result = new MolecularWeightAndFormulaContribution(total, ps.substanceClass.toString(), formulaMapWithContrib[0]);
Expand Down Expand Up @@ -738,6 +744,12 @@ public static double getDisulfideContribution(Protein protein) {
: 0.0d;
}

public static int getNumberOfHydrogensToRemoveForDisulfides(Protein protein) {
return (protein != null && protein.getDisulfideLinks() != null)
? 2 * protein.getDisulfideLinks().size()
: 0;
}

public static Map<String,SingleThreadCounter> subtractFormulas(Map<String,SingleThreadCounter> minuend, Map<String,SingleThreadCounter> subtrahend){
Map<String,SingleThreadCounter> difference = new HashMap<>();
minuend.keySet().forEach(s->{
Expand Down

0 comments on commit 6c4a1e0

Please sign in to comment.