def test(): from modifications import Modifications mods = Modifications() mypep2 = Peptide('LMGPTSVVMGR', modifications={9: mods.mods_TPPcode['M[147]']}) #M[147] mypep = Peptide('LMGPTSVVMGR') phospho = mods.mods_unimods[21] oxi = mods.mods_unimods[35] isoform4_1 = Peptide('MHGGTGFAGIDSSSPEVK', modifications={ 1: oxi, 5: phospho }) isoform4_2 = Peptide('MHGGTGFAGIDSSSPEVK', modifications={ 1: oxi, 12: phospho }) isoform4_3 = Peptide('MHGGTGFAGIDSSSPEVK', modifications={ 1: oxi, 13: phospho }) isoform4_4 = Peptide('MHGGTGFAGIDSSSPEVK', modifications={ 1: oxi, 14: phospho }) isof_target = isoform4_2 theOtherIsoforms = [isoform4_1, isoform4_2, isoform4_3, isoform4_4] theOtherIsoforms.remove(isof_target) for isof in theOtherIsoforms: print isof.getSequenceWithMods('unimod') annot, ion_masses = isof.all_ions(ionseries=[ 'y', ], frg_z_list=[ 1, ], fragmentlossgains=[ 0, ], mass_limits=[300, 1500], label='') print isof_target.getSequenceWithMods('unimod') annot, ion_masses = isof_target.all_ions(ionseries=[ 'y', ], frg_z_list=[ 1, ], fragmentlossgains=[ 0, ], mass_limits=[300, 1500], label='') UISmass, UISannot = isof_target.cal_UIS(theOtherIsoforms, UISorder=2, ionseries=[ 'y', ], fragmentlossgains=[ 0, ], precision=1e-5, frg_z_list=[ 1, ], mass_limits=[300, 1500]) for UIS in UISannot.itervalues(): print UIS matched, unmatched = mypep.comparePeptideFragments([ mypep2, ], ['y', 'b'], precision=1e-2) print "Matched ions : ", matched print "Unmatched ions : ", unmatched my_isoforms = mypep2.calIsoforms(mods.mods_TPPcode['M[147]'], mods) print "isoforms of %s" % mypep2.getSequenceWithMods('unimod') for iso in my_isoforms: print iso.getSequenceWithMods('unimod') for pep in [mypep, mypep2]: print pep.sequence, pep.mass, pep.modifications print pep._getComposition() print pep._getAminoacidList(True) print pep.getSequenceWithMods("ProteinPilot") print pep.getMZ(1) print '#,', ", ".join(pep.iontypes) masses = [] for v in range(1, len(pep.sequence) + 1): masses.append(str(v)) for ionserie in pep.iontypes: masses.append(str(pep.getMZfragment(ionserie, v, 1))) print ", ".join(masses) masses = [] #for property, value in vars(pep).iteritems() : # print property , " : " , value '''
class ModificationsTest(unittest.TestCase): def setUp(self): self.fixture = Modifications() def test_calculate_date_with_default_arguments_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03'), '2001-02-03') def test_calculate_date_with_days_argument_only_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', days=13), '2001-02-16') def test_calculate_date_with_days_string_argument_only_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', days='13'), '2001-02-16') def test_calculate_date_with_large_days_argument_only_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', days=100), '2001-05-14') def test_calculate_date_with_large_days_string_argument_only_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', days='100'), '2001-05-14') def test_calculate_date_with_months_argument_only_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', months=3), '2001-05-03') def test_calculate_date_with_months_string_argument_only_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', months='3'), '2001-05-03') def test_calculate_date_with_large_months_argument_only_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', months=14), '2002-04-03') def test_calculate_date_with_large_months_string_argument_only_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', months='14'), '2002-04-03') def test_calculate_date_with_years_argument_only_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', years=3), '2004-02-03') def test_calculate_date_with_years_string_argument_only_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', years='3'), '2004-02-03') def test_calculate_date_with_day_and_month_arguments_only_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', days=100, months=14), '2002-07-14') def test_calculate_date_with_day_and_year_arguments_only_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', days=100, years=3), '2004-05-14') def test_calculate_date_with_month_and_year_arguments_only_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', months=14, years=5), '2007-04-03') def test_calculate_date_with_all_given_arguments_works(self): self.assertEqual(self.fixture.calculate_date('2001-02-03', days=100, months=14, years=5), '2007-07-14') def test_calculate_date_with_invalid_date_argument_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.calculate_date('bla') self.assertEqual(context.exception.message, "Expected a date with format YYYY-MM-DD got 'bla'") def test_calculate_date_with_integer_date_argument_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.calculate_date(2001 - 02 - 03) self.assertEqual(context.exception.message, "Expected a date with format YYYY-MM-DD got '1996'") def test_calculate_date_with_invalid_days_in_date_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.calculate_date('2012-01-70') self.assertEqual(context.exception.message, "Expected a date with format YYYY-MM-DD got '2012-01-70'") def test_calculate_date_with_invalid_days_argument_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.calculate_date('2001-02-03', days='Bla') self.assertEqual(context.exception.message, "String passed in is not a number") def test_calculate_date_with_boolean_days_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.calculate_date('2001-02-03', days=True) self.assertEqual(context.exception.message, "String is None or is a Boolean") def test_calculate_date_with_invalid_months_argument_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.calculate_date('2001-02-03', months='Bla') self.assertEqual(context.exception.message, "String passed in is not a number") def test_calculate_date_with_boolean_months_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.calculate_date('2001-02-03', months=False) self.assertEqual(context.exception.message, "String is None or is a Boolean") def test_calculate_date_with_invalid_years_argument_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.calculate_date('2001-02-03', years='Bla') self.assertEqual(context.exception.message, "String passed in is not a number") def test_calculate_date_with_boolean_years_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.calculate_date('2001-02-03', years=True) self.assertEqual(context.exception.message, "String is None or is a Boolean") def test_calculate_date_with_none_as_date_argument_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.calculate_date(None) self.assertEqual(context.exception.message, "Expected a date with format YYYY-MM-DD got 'None'") def test_calculate_date_with_none_as_any_of_arguments_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.calculate_date('2001-02-03', days=None, months=None, years=None) self.assertEqual(context.exception.message, "String is None or is a Boolean") def test_timestamp_to_date_realstic_argument_works(self): self.assertEqual(self.fixture.timestamp_to_date(1350000000000), '2012-10-11') def test_timestamp_to_date_low_argument_works(self): self.assertEqual(self.fixture.timestamp_to_date(999), '1969-12-31') def test_timestamp_to_date_high_argument_works(self): self.assertEqual(self.fixture.timestamp_to_date(23500000000000), '2714-09-08') def test_timestamp_to_date_string_number_argument_works(self): self.assertEqual(self.fixture.timestamp_to_date('1350000000000'), '2012-10-11') def test_timestamp_to_date_negative_argument_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.timestamp_to_date(-12345678) self.assertEqual(context.exception.message, "Timestamp cannot be negative") def test_timestamp_to_date_empty_string_argument_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.timestamp_to_date('') self.assertEqual(context.exception.message, "String passed in is not a number") def test_timestamp_to_date_string_argument_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.timestamp_to_date('Time') self.assertEqual(context.exception.message, "String passed in is not a number") def test_timestamp_to_date_boolean_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.timestamp_to_date(True) self.assertEqual(context.exception.message, "String is None or is a Boolean") def test_timestamp_to_date_none_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.timestamp_to_date(None) self.assertEqual(context.exception.message, "String is None or is a Boolean") def test_date_to_timestamp_realistic_argument_works(self): self.assertEqual(self.fixture.date_to_timestamp('2012-10-11'), 1349928000000) def test_date_to_timestamp_low_argument_works(self): self.assertEqual(self.fixture.date_to_timestamp('1970-01-01'), 18000000) def test_date_to_timestamp_high_argument_works(self): self.assertEqual(self.fixture.date_to_timestamp('2700-01-01'), 23036590800000) def test_date_to_timestamp_invalid_year_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.date_to_timestamp('1969-12-31') self.assertEqual(context.exception.message, "Year cannot be under 1970") def test_date_to_timestamp_invalid_day_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.date_to_timestamp('2012-01-70') self.assertEqual(context.exception.message, "Expected a date with format YYYY-MM-DD got '2012-01-70'") def test_date_to_timestamp_invalid_argument_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.date_to_timestamp('bla') self.assertEqual(context.exception.message, "Expected a date with format YYYY-MM-DD got 'bla'") def test_date_to_timestamp_integer_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.date_to_timestamp(123) self.assertEqual(context.exception.message, "Date is not a string") def test_date_to_timestamp_boolean_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.date_to_timestamp(False) self.assertEqual(context.exception.message, "Date is not a string") def test_date_to_timestamp_empty_argument_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.date_to_timestamp('') self.assertEqual(context.exception.message, "Expected a date with format YYYY-MM-DD got ''") def test_date_to_timestamp_none_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.date_to_timestamp(None) self.assertEqual(context.exception.message, "Date is not a string") def test_increment_one_day_works(self): self.assertEqual(self.fixture.increment_one_day('2012-10-11'), '2012-10-12') def test_increment_one_day_at_month_end_works(self): self.assertEqual(self.fixture.increment_one_day('2012-10-31'), '2012-11-01') def test_increment_one_day_at_year_end_works(self): self.assertEqual(self.fixture.increment_one_day('2012-12-31'), '2013-01-01') def test_increment_one_day_with_invalid_days_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.increment_one_day('2012-01-70') self.assertEqual(context.exception.message, "Expected a date with format YYYY-MM-DD got '2012-01-70'") def test_increment_one_day_with_invalid_string_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.increment_one_day('bla') self.assertEqual(context.exception.message, "Expected a date with format YYYY-MM-DD got 'bla'") def test_increment_one_day_integer_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.increment_one_day(123) self.assertEqual(context.exception.message, "Date is not a string") def test_increment_one_day_boolean_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.increment_one_day(False) self.assertEqual(context.exception.message, "Date is not a string") def test_increment_one_day_empty_argument_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.increment_one_day('') self.assertEqual(context.exception.message, "Expected a date with format YYYY-MM-DD got ''") def test_increment_one_day_none_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.increment_one_day(None) self.assertEqual(context.exception.message, "Date is not a string") def test_decrement_one_day_works(self): self.assertEqual(self.fixture.decrement_one_day('2012-10-11'), '2012-10-10') def test_decrement_one_day_at_month_beginning_works(self): self.assertEqual(self.fixture.decrement_one_day('2012-03-01'), '2012-02-29') def test_decrement_one_day_at_year_end_works(self): self.assertEqual(self.fixture.decrement_one_day('2012-01-01'), '2011-12-31') def test_decrement_one_day_with_invalid_days_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.decrement_one_day('2012-01-70') self.assertEqual(context.exception.message, "Expected a date with format YYYY-MM-DD got '2012-01-70'") def test_decrement_one_day_with_invalid_string_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.decrement_one_day('bla') self.assertEqual(context.exception.message, "Expected a date with format YYYY-MM-DD got 'bla'") def test_decrement_one_day_integer_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.decrement_one_day(123) self.assertEqual(context.exception.message, "Date is not a string") def test_decrement_one_day_boolean_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.decrement_one_day(False) self.assertEqual(context.exception.message, "Date is not a string") def test_decrement_one_day_empty_argument_throws_error(self): with self.assertRaises(ValueError) as context: self.fixture.decrement_one_day('') self.assertEqual(context.exception.message, "Expected a date with format YYYY-MM-DD got ''") def test_decrement_one_day_none_argument_throws_error(self): with self.assertRaises(TypeError) as context: self.fixture.decrement_one_day(None) self.assertEqual(context.exception.message, "Date is not a string")
def setUp(self): self.fixture = Modifications()
from peptide import Peptide from modifications import Modifications from elements import Formulas mods = Modifications() phospho = mods.mods_unimods[21] oxi = mods.mods_TPPcode['M[147]']; cys = mods.mods_TPPcode['C[160]']; nTMT = mods.mods_TPPcode['n[230]']; TMT = mods.mods_TPPcode['K[357]']; massNH3 = Formulas.mass(Formulas.NH3) #massN + 3 * massH massH2O = Formulas.mass(Formulas.H2O) #(massH *2 + massO) p1 = Peptide('CKDALA',modifications={1: cys}) p2 = Peptide('CKDALA',modifications={1: cys, 0: nTMT, 2:TMT}) for pep in [ p1, p2 ]: # annot , ion_masses = pep.all_ions(ionseries = ['y','b'], # frg_z_list = [1,2], # fragmentlossgains = [0, ], # mass_limits = [100,3000], # label = '') # for a in annot: # print a print "PEPTIDE:", pep.getSequenceWithMods("TPP"), "\tpreMz:", pep.getMZ(2) #CHARGE=2 for v in range(1, len(pep.sequence)):