I'm using the Peptides package in R to calculate the mass of peptides with the mw() method. The thing is that I want to calculate them for different pH values, and thus I wrote this little function to take the pH value into account according this image:
My code is this:
phmw = function(pept_seq , unimod_location, pH ){
monoisotopic_hydrogen_mass = 1.00794
if(pH < 7){
# mol_weight = mol_weight_of_peptide + mol_weight_of_Hydrogen
mol_weight = mw(pept_seq, monoisotopic = T) + monoisotopic_hydrogen_mass
}else if(pH > 7){
# mol_weight = mol_weight_of_peptide - mol_weight_of_Hydrogen
mol_weight = mw(pept_seq, monoisotopic = T) - monoisotopic_hydrogen_mass
}else if(pH == 7){
# mol_weight = mol_weight_of_peptide
mol_weight = mw(pept_seq, monoisotopic = T)
}
return(mol_weight)
}
Do you think that this approach is correct or not?
T
instead ofTRUE, and don’t use
return` (which is unnecessary here). Generally I suggest reading the Tidyverse style guide, even if you decide not to follow it. $\endgroup$