{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Given a cyclic peptide Peptide and a spectrum Spectrum, we define Score(Peptide, Spectrum) as the number of masses shared between Cyclospectrum(Peptide) and Spectrum." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "aminoacidMass = {'G':57, 'A':71, 'S':87, 'P':97, 'V':99, 'T':101, 'C':103, 'I':113, 'L':113, 'N':114, 'D':115, 'K':128, 'Q':128, 'E':129, 'M':131, 'H':137, 'F':147, 'R':156, 'Y':163, 'W':186}\n", "def cyclicSpectrum(peptide):\n", " \"\"\"Input: An amino acid string Peptide.\n", " Output: The cyclic spectrum of Peptide.\"\"\"\n", " prefixMass = [0]*((len(peptide)+1))\n", " for i in range(len(peptide)):\n", " prefixMass[i+1] = prefixMass[i] + aminoacidMass[peptide[i]]\n", " peptideMass = prefixMass[len(peptide)]\n", " cyclic_spectrum = [0]\n", " for i in range(len(prefixMass)-1):\n", " for j in range(i+1, len(prefixMass)):\n", " cyclic_spectrum.append(prefixMass[j] - prefixMass[i])\n", " if i > 0 and j < (len(prefixMass)-1):\n", " cyclic_spectrum.append(peptideMass - (prefixMass[j] - prefixMass[i]))\n", " return sorted(cyclic_spectrum) " ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0, 57, 71, 71, 97, 97, 97, 99, 99, 101, 101, 101, 101, 103, 113, 113, 113, 113, 113, 115, 115, 115, 115, 128, 128, 128, 129, 129, 131, 131, 137, 156, 156, 156, 163, 163, 163, 172, 184, 186, 186, 188, 199, 204, 210, 210, 212, 212, 212, 213, 214, 214, 214, 214, 226, 227, 228, 228, 230, 231, 232, 241, 244, 257, 259, 260, 262, 281, 284, 285, 287, 289, 292, 292, 293, 293, 301, 301, 302, 311, 312, 314, 325, 325, 326, 327, 327, 327, 327, 328, 332, 341, 341, 343, 344, 356, 358, 360, 364, 373, 389, 391, 393, 394, 397, 398, 398, 400, 402, 403, 407, 409, 415, 418, 424, 425, 426, 428, 429, 440, 440, 441, 444, 445, 445, 449, 453, 454, 455, 456, 465, 472, 475, 488, 497, 499, 501, 502, 504, 504, 506, 511, 512, 512, 516, 520, 521, 526, 529, 533, 537, 539, 541, 544, 550, 554, 554, 554, 556, 559, 560, 568, 569, 569, 572, 573, 573, 578, 585, 590, 601, 609, 612, 612, 613, 617, 619, 621, 621, 625, 630, 631, 632, 638, 639, 652, 653, 653, 655, 657, 659, 666, 669, 672, 675, 684, 685, 686, 688, 689, 691, 692, 696, 697, 700, 701, 707, 709, 714, 716, 722, 724, 724, 725, 732, 734, 740, 746, 753, 756, 759, 761, 768, 768, 769, 770, 776, 781, 781, 784, 785, 792, 793, 797, 801, 804, 809, 813, 816, 818, 822, 824, 825, 829, 829, 835, 838, 845, 847, 852, 852, 853, 853, 855, 860, 865, 869, 870, 871, 872, 874, 898, 899, 900, 905, 905, 906, 910, 912, 912, 913, 919, 919, 923, 924, 932, 938, 939, 942, 948, 948, 953, 954, 956, 957, 965, 966, 970, 973, 974, 980, 981, 984, 985, 987, 987, 999, 1002, 1010, 1013, 1013, 1016, 1016, 1020, 1024, 1027, 1028, 1032, 1036, 1041, 1049, 1051, 1055, 1061, 1061, 1062, 1066, 1067, 1069, 1070, 1073, 1082, 1083, 1084, 1085, 1086, 1087, 1097, 1098, 1102, 1102, 1113, 1114, 1117, 1117, 1131, 1133, 1133, 1137, 1137, 1137, 1138, 1141, 1141, 1142, 1144, 1152, 1158, 1162, 1166, 1170, 1176, 1179, 1186, 1186, 1195, 1196, 1198, 1198, 1199, 1199, 1201, 1204, 1211, 1213, 1213, 1213, 1215, 1225, 1226, 1232, 1234, 1243, 1244, 1246, 1250, 1250, 1259, 1265, 1265, 1269, 1269, 1273, 1273, 1280, 1283, 1294, 1296, 1296, 1297, 1297, 1298, 1300, 1301, 1303, 1305, 1310, 1313, 1314, 1314, 1317, 1324, 1328, 1328, 1330, 1345, 1347, 1351, 1354, 1354, 1359, 1362, 1363, 1368, 1372, 1374, 1374, 1378, 1388, 1393, 1397, 1399, 1399, 1402, 1409, 1410, 1413, 1414, 1423, 1425, 1425, 1425, 1425, 1425, 1427, 1428, 1431, 1443, 1445, 1459, 1460, 1460, 1464, 1464, 1469, 1473, 1477, 1482, 1485, 1490, 1491, 1493, 1500, 1501, 1502, 1510, 1514, 1515, 1522, 1524, 1524, 1525, 1526, 1527, 1528, 1530, 1531, 1538, 1538, 1540, 1541, 1542, 1542, 1560, 1561, 1561, 1562, 1566, 1577, 1585, 1586, 1587, 1588, 1590, 1605, 1606, 1611, 1613, 1615, 1623, 1623, 1629, 1629, 1631, 1637, 1637, 1638, 1639, 1639, 1640, 1641, 1651, 1656, 1658, 1658, 1661, 1663, 1671, 1674, 1674, 1676, 1681, 1686, 1687, 1688, 1688, 1694, 1701, 1703, 1705, 1705, 1712, 1714, 1716, 1718, 1724, 1724, 1738, 1746, 1750, 1752, 1752, 1752, 1752, 1753, 1754, 1755, 1766, 1771, 1771, 1772, 1785, 1786, 1789, 1791, 1791, 1794, 1802, 1803, 1816, 1817, 1817, 1817, 1819, 1823, 1824, 1825, 1825, 1834, 1834, 1837, 1842, 1843, 1844, 1850, 1851, 1851, 1852, 1853, 1853, 1862, 1865, 1865, 1867, 1868, 1886, 1886, 1887, 1899, 1900, 1900, 1915, 1918, 1918, 1919, 1922, 1922, 1922, 1922, 1926, 1931, 1934, 1938, 1956, 1959, 1964, 1966, 1966, 1966, 1966, 1967, 1968, 1972, 1973, 1975, 1979, 1979, 1980, 1983, 1986, 1987, 1990, 1993, 1997, 1997, 2003, 2013, 2014, 2015, 2021, 2037, 2039, 2044, 2049, 2050, 2051, 2056, 2057, 2063, 2065, 2072, 2074, 2078, 2078, 2079, 2079, 2081, 2081, 2085, 2087, 2094, 2094, 2096, 2098, 2103, 2104, 2110, 2111, 2114, 2114, 2115, 2116, 2118, 2121, 2135, 2143, 2149, 2149, 2152, 2152, 2160, 2169, 2170, 2178, 2178, 2178, 2180, 2184, 2184, 2192, 2193, 2200, 2200, 2200, 2206, 2207, 2207, 2211, 2215, 2217, 2219, 2220, 2223, 2226, 2227, 2227, 2234, 2235, 2243, 2244, 2250, 2253, 2257, 2259, 2260, 2266, 2270, 2272, 2275, 2278, 2283, 2293, 2293, 2293, 2297, 2297, 2297, 2307, 2312, 2315, 2318, 2320, 2324, 2330, 2331, 2333, 2337, 2340, 2346, 2347, 2355, 2356, 2363, 2363, 2364, 2367, 2370, 2371, 2373, 2375, 2379, 2383, 2383, 2384, 2390, 2390, 2390, 2397, 2398, 2406, 2406, 2410, 2412, 2412, 2412, 2420, 2421, 2430, 2438, 2438, 2441, 2441, 2447, 2455, 2469, 2472, 2474, 2475, 2476, 2476, 2479, 2480, 2486, 2487, 2492, 2494, 2496, 2496, 2503, 2505, 2509, 2509, 2511, 2511, 2512, 2512, 2516, 2518, 2525, 2527, 2533, 2534, 2539, 2540, 2541, 2546, 2551, 2553, 2569, 2575, 2576, 2577, 2587, 2593, 2593, 2597, 2600, 2603, 2604, 2607, 2610, 2611, 2611, 2615, 2617, 2618, 2622, 2623, 2624, 2624, 2624, 2624, 2626, 2631, 2634, 2652, 2656, 2659, 2664, 2668, 2668, 2668, 2668, 2671, 2672, 2672, 2675, 2690, 2690, 2691, 2703, 2704, 2704, 2722, 2723, 2725, 2725, 2728, 2737, 2737, 2738, 2739, 2739, 2740, 2746, 2747, 2748, 2753, 2756, 2756, 2765, 2765, 2766, 2767, 2771, 2773, 2773, 2773, 2774, 2787, 2788, 2796, 2799, 2799, 2801, 2804, 2805, 2818, 2819, 2819, 2824, 2835, 2836, 2837, 2838, 2838, 2838, 2838, 2840, 2844, 2852, 2866, 2866, 2872, 2874, 2876, 2878, 2885, 2885, 2887, 2889, 2896, 2902, 2902, 2903, 2904, 2909, 2914, 2916, 2916, 2919, 2927, 2929, 2932, 2932, 2934, 2939, 2949, 2950, 2951, 2951, 2952, 2953, 2953, 2959, 2961, 2961, 2967, 2967, 2975, 2977, 2979, 2984, 2985, 3000, 3002, 3003, 3004, 3005, 3013, 3024, 3028, 3029, 3029, 3030, 3048, 3048, 3049, 3050, 3052, 3052, 3059, 3060, 3062, 3063, 3064, 3065, 3066, 3066, 3068, 3075, 3076, 3080, 3088, 3089, 3090, 3097, 3099, 3100, 3105, 3108, 3113, 3117, 3121, 3126, 3126, 3130, 3130, 3131, 3145, 3147, 3159, 3162, 3163, 3165, 3165, 3165, 3165, 3165, 3167, 3176, 3177, 3180, 3181, 3188, 3191, 3191, 3193, 3197, 3202, 3212, 3216, 3216, 3218, 3222, 3227, 3228, 3231, 3236, 3236, 3239, 3243, 3245, 3260, 3262, 3262, 3266, 3273, 3276, 3276, 3277, 3280, 3285, 3287, 3289, 3290, 3292, 3293, 3293, 3294, 3294, 3296, 3307, 3310, 3317, 3317, 3321, 3321, 3325, 3325, 3331, 3340, 3340, 3344, 3346, 3347, 3356, 3358, 3364, 3365, 3375, 3377, 3377, 3377, 3379, 3386, 3389, 3391, 3391, 3392, 3392, 3394, 3395, 3404, 3404, 3411, 3414, 3420, 3424, 3428, 3432, 3438, 3446, 3448, 3449, 3449, 3452, 3453, 3453, 3453, 3457, 3457, 3459, 3473, 3473, 3476, 3477, 3488, 3488, 3492, 3493, 3503, 3504, 3505, 3506, 3507, 3508, 3517, 3520, 3521, 3523, 3524, 3528, 3529, 3529, 3535, 3539, 3541, 3549, 3554, 3558, 3562, 3563, 3566, 3570, 3574, 3574, 3577, 3577, 3580, 3588, 3591, 3603, 3603, 3605, 3606, 3609, 3610, 3616, 3617, 3620, 3624, 3625, 3633, 3634, 3636, 3637, 3642, 3642, 3648, 3651, 3652, 3658, 3666, 3667, 3671, 3671, 3677, 3678, 3678, 3680, 3684, 3685, 3685, 3690, 3691, 3692, 3716, 3718, 3719, 3720, 3721, 3725, 3730, 3735, 3737, 3737, 3738, 3738, 3743, 3745, 3752, 3755, 3761, 3761, 3765, 3766, 3768, 3772, 3774, 3777, 3781, 3786, 3789, 3793, 3797, 3798, 3805, 3806, 3809, 3809, 3814, 3820, 3821, 3822, 3822, 3829, 3831, 3834, 3837, 3844, 3850, 3856, 3858, 3865, 3866, 3866, 3868, 3874, 3876, 3881, 3883, 3889, 3890, 3893, 3894, 3898, 3899, 3901, 3902, 3904, 3905, 3906, 3915, 3918, 3921, 3924, 3931, 3933, 3935, 3937, 3937, 3938, 3951, 3952, 3958, 3959, 3960, 3965, 3969, 3969, 3971, 3973, 3977, 3978, 3978, 3981, 3989, 4000, 4005, 4012, 4017, 4017, 4018, 4021, 4021, 4022, 4030, 4031, 4034, 4036, 4036, 4036, 4040, 4046, 4049, 4051, 4053, 4057, 4061, 4064, 4069, 4070, 4074, 4078, 4078, 4079, 4084, 4086, 4086, 4088, 4089, 4091, 4093, 4102, 4115, 4118, 4125, 4134, 4135, 4136, 4137, 4141, 4145, 4145, 4146, 4149, 4150, 4150, 4161, 4162, 4164, 4165, 4166, 4172, 4175, 4181, 4183, 4187, 4188, 4190, 4192, 4192, 4193, 4196, 4197, 4199, 4201, 4217, 4226, 4230, 4232, 4234, 4246, 4247, 4249, 4249, 4258, 4262, 4263, 4263, 4263, 4263, 4264, 4265, 4265, 4276, 4278, 4279, 4288, 4289, 4289, 4297, 4297, 4298, 4298, 4301, 4303, 4305, 4306, 4309, 4328, 4330, 4331, 4333, 4346, 4349, 4358, 4359, 4360, 4362, 4362, 4363, 4364, 4376, 4376, 4376, 4376, 4377, 4378, 4378, 4378, 4380, 4380, 4386, 4391, 4402, 4404, 4404, 4406, 4418, 4427, 4427, 4427, 4434, 4434, 4434, 4453, 4459, 4459, 4461, 4461, 4462, 4462, 4462, 4475, 4475, 4475, 4475, 4477, 4477, 4477, 4477, 4477, 4487, 4489, 4489, 4489, 4489, 4491, 4491, 4493, 4493, 4493, 4519, 4519, 4533, 4590]\n" ] } ], "source": [ "print cyclicSpectrum('VYYEVDWTMGRQIDPDEYPIAQCTRHRATILTLPDWQM')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "aminoacidMass = {'G':57, 'A':71, 'S':87, 'P':97, 'V':99, 'T':101, 'C':103, 'I':113, 'L':113, 'N':114, 'D':115, 'K':128, 'Q':128, 'E':129, 'M':131, 'H':137, 'F':147, 'R':156, 'Y':163, 'W':186}\n", "from collections import Counter\n", "def score_peptide(peptide, spectrum):\n", " \"\"\"Cyclopeptide Scoring Problem: Compute the score of a cyclic peptide against a spectrum.\n", " Input: An amino acid string Peptide and a collection of integers Spectrum. \n", " Output: The score of Peptide against Spectrum, Score(Peptide, Spectrum).\"\"\"\n", " spectrum_peptide = cyclicSpectrum(peptide)\n", " c1, c2 = Counter(spectrum_peptide), Counter(spectrum)\n", " return sum([min(n, c2[k]) for k,n in c1.items()])" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "score_peptide('MAMA', [0, 71, 178, 202, 202, 202, 333, 333, 333, 404, 507, 507])" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "11" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "peptide = 'NKEL'\n", "spectrum = [0, 99, 113, 114, 128, 227, 257, 299, 355, 356, 370, 371, 484]\n", "score_peptide(peptide, spectrum)" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "peptide VYYEVDWTMGRQIDPDEYPIAQCTRHRATILTLPDWQM\n", "spectrum [0, 71, 71, 87, 87, 97, 97, 99, 101, 101, 101, 101, 103, 113, 113, 113, 113, 113, 115, 115, 115, 115, 128, 128, 129, 129, 131, 131, 137, 147, 156, 156, 156, 163, 163, 163, 163, 172, 184, 186, 186, 199, 204, 210, 212, 212, 214, 214, 214, 216, 218, 226, 227, 228, 230, 231, 232, 243, 244, 244, 257, 259, 260, 260, 262, 273, 276, 278, 278, 281, 285, 287, 292, 293, 293, 301, 302, 303, 312, 314, 319, 325, 326, 327, 327, 327, 327, 328, 331, 332, 341, 358, 360, 364, 373, 374, 374, 375, 377, 389, 390, 391, 393, 394, 398, 402, 403, 407, 407, 409, 415, 416, 418, 425, 428, 429, 440, 440, 441, 441, 444, 445, 449, 456, 464, 465, 472, 475, 488, 490, 492, 494, 497, 499, 502, 503, 503, 504, 504, 505, 505, 512, 516, 517, 520, 521, 521, 531, 540, 541, 544, 550, 554, 556, 559, 560, 569, 570, 572, 573, 577, 578, 587, 592, 592, 601, 603, 605, 612, 613, 617, 618, 618, 619, 621, 621, 622, 625, 628, 634, 634, 653, 655, 657, 659, 661, 669, 671, 672, 675, 678, 680, 684, 688, 691, 696, 701, 704, 705, 707, 714, 715, 716, 716, 718, 721, 722, 723, 724, 732, 734, 735, 743, 748, 749, 749, 756, 768, 769, 775, 776, 781, 781, 785, 791, 792, 799, 800, 804, 806, 808, 809, 816, 819, 822, 822, 825, 829, 829, 830, 835, 836, 836, 843, 846, 847, 850, 852, 852, 870, 872, 877, 879, 887, 890, 895, 900, 904, 905, 905, 906, 912, 913, 919, 919, 921, 923, 928, 931, 932, 935, 937, 938, 942, 942, 944, 947, 948, 948, 953, 959, 961, 965, 976, 985, 985, 985, 992, 999, 1005, 1008, 1013, 1015, 1016, 1020, 1024, 1024, 1028, 1032, 1035, 1036, 1036, 1036, 1043, 1046, 1049, 1050, 1051, 1061, 1061, 1062, 1062, 1066, 1068, 1069, 1073, 1075, 1076, 1089, 1090, 1098, 1100, 1114, 1117, 1122, 1123, 1131, 1132, 1133, 1133, 1133, 1137, 1137, 1137, 1139, 1141, 1148, 1149, 1152, 1155, 1160, 1162, 1162, 1163, 1174, 1174, 1176, 1179, 1183, 1191, 1198, 1199, 1201, 1201, 1204, 1219, 1220, 1224, 1225, 1229, 1232, 1232, 1234, 1244, 1245, 1248, 1250, 1250, 1252, 1252, 1253, 1261, 1261, 1262, 1263, 1264, 1265, 1273, 1280, 1288, 1296, 1302, 1302, 1305, 1312, 1313, 1316, 1316, 1318, 1325, 1332, 1335, 1335, 1339, 1345, 1347, 1349, 1350, 1351, 1354, 1354, 1360, 1362, 1363, 1363, 1367, 1369, 1376, 1377, 1387, 1388, 1391, 1392, 1392, 1393, 1397, 1403, 1410, 1415, 1417, 1425, 1425, 1428, 1433, 1434, 1440, 1444, 1451, 1460, 1463, 1464, 1464, 1464, 1464, 1464, 1465, 1469, 1475, 1477, 1479, 1488, 1491, 1492, 1497, 1501, 1502, 1505, 1510, 1520, 1525, 1525, 1526, 1526, 1530, 1531, 1534, 1540, 1540, 1543, 1547, 1548, 1556, 1561, 1564, 1564, 1566, 1577, 1578, 1579, 1588, 1590, 1590, 1592, 1593, 1597, 1603, 1606, 1619, 1623, 1626, 1627, 1627, 1627, 1628, 1634, 1635, 1637, 1637, 1638, 1639, 1641, 1648, 1648, 1653, 1662, 1665, 1671, 1674, 1676, 1677, 1681, 1689, 1693, 1693, 1695, 1703, 1706, 1708, 1719, 1724, 1724, 1727, 1729, 1734, 1735, 1738, 1740, 1742, 1742, 1750, 1752, 1752, 1753, 1754, 1754, 1756, 1760, 1763, 1765, 1766, 1778, 1784, 1785, 1790, 1792, 1794, 1804, 1804, 1806, 1808, 1821, 1821, 1823, 1832, 1837, 1837, 1837, 1851, 1853, 1853, 1853, 1855, 1857, 1857, 1862, 1865, 1866, 1866, 1867, 1871, 1871, 1875, 1879, 1879, 1883, 1885, 1889, 1890, 1891, 1897, 1905, 1908, 1916, 1919, 1923, 1928, 1933, 1936, 1941, 1941, 1949, 1952, 1964, 1966, 1966, 1966, 1966, 1967, 1968, 1968, 1977, 1980, 1984, 1984, 1985, 1988, 1992, 2000, 2004, 2004, 2009, 2010, 2012, 2020, 2020, 2022, 2028, 2031, 2034, 2034, 2036, 2037, 2041, 2046, 2051, 2052, 2053, 2056, 2065, 2079, 2079, 2081, 2081, 2087, 2091, 2093, 2097, 2097, 2105, 2111, 2113, 2115, 2116, 2122, 2123, 2124, 2129, 2131, 2133, 2135, 2138, 2139, 2140, 2147, 2148, 2152, 2153, 2159, 2160, 2165, 2168, 2168, 2169, 2178, 2180, 2184, 2187, 2192, 2197, 2198, 2206, 2206, 2209, 2215, 2224, 2226, 2237, 2237, 2240, 2244, 2244, 2244, 2247, 2250, 2253, 2255, 2260, 2263, 2264, 2266, 2268, 2269, 2277, 2280, 2286, 2287, 2293, 2293, 2294, 2296, 2297, 2300, 2301, 2307, 2309, 2310, 2311, 2315, 2315, 2324, 2334, 2337, 2339, 2341, 2352, 2354, 2356, 2359, 2369, 2378, 2378, 2382, 2383, 2384, 2386, 2392, 2393, 2396, 2397, 2399, 2400, 2400, 2406, 2407, 2413, 2416, 2424, 2425, 2427, 2429, 2430, 2433, 2438, 2440, 2443, 2446, 2449, 2449, 2449, 2453, 2456, 2456, 2467, 2469, 2478, 2484, 2487, 2487, 2495, 2496, 2501, 2506, 2509, 2513, 2515, 2524, 2525, 2525, 2528, 2533, 2534, 2540, 2541, 2545, 2546, 2553, 2554, 2555, 2558, 2560, 2562, 2564, 2569, 2570, 2571, 2577, 2578, 2580, 2582, 2588, 2596, 2596, 2600, 2602, 2606, 2612, 2612, 2614, 2614, 2628, 2637, 2640, 2641, 2642, 2647, 2652, 2656, 2657, 2659, 2659, 2662, 2665, 2671, 2673, 2673, 2681, 2683, 2684, 2689, 2689, 2693, 2701, 2705, 2708, 2709, 2709, 2713, 2716, 2725, 2725, 2726, 2727, 2727, 2727, 2727, 2729, 2741, 2744, 2752, 2752, 2757, 2760, 2765, 2770, 2774, 2777, 2785, 2788, 2796, 2802, 2803, 2804, 2808, 2810, 2814, 2814, 2818, 2822, 2822, 2826, 2827, 2827, 2828, 2831, 2836, 2836, 2838, 2840, 2840, 2840, 2842, 2856, 2856, 2856, 2861, 2870, 2872, 2872, 2885, 2887, 2889, 2889, 2899, 2901, 2903, 2908, 2909, 2915, 2927, 2928, 2930, 2933, 2937, 2939, 2939, 2940, 2941, 2941, 2943, 2951, 2951, 2953, 2955, 2958, 2959, 2964, 2966, 2969, 2969, 2974, 2985, 2987, 2990, 2998, 3000, 3000, 3004, 3012, 3016, 3017, 3019, 3022, 3028, 3031, 3040, 3045, 3045, 3052, 3054, 3055, 3056, 3056, 3058, 3059, 3065, 3066, 3066, 3066, 3067, 3070, 3074, 3087, 3090, 3096, 3100, 3101, 3103, 3103, 3105, 3114, 3115, 3116, 3127, 3129, 3129, 3132, 3137, 3145, 3146, 3150, 3153, 3153, 3159, 3162, 3163, 3167, 3167, 3168, 3168, 3173, 3183, 3188, 3191, 3192, 3196, 3201, 3202, 3205, 3214, 3216, 3218, 3224, 3228, 3229, 3229, 3229, 3229, 3229, 3230, 3233, 3242, 3249, 3253, 3259, 3260, 3265, 3268, 3268, 3276, 3278, 3283, 3290, 3296, 3300, 3301, 3301, 3302, 3305, 3306, 3316, 3317, 3324, 3326, 3330, 3330, 3331, 3333, 3339, 3339, 3342, 3343, 3344, 3346, 3348, 3354, 3358, 3358, 3361, 3368, 3375, 3377, 3377, 3380, 3381, 3388, 3391, 3391, 3397, 3405, 3413, 3420, 3428, 3429, 3430, 3431, 3432, 3432, 3440, 3441, 3441, 3443, 3443, 3445, 3448, 3449, 3459, 3461, 3461, 3464, 3468, 3469, 3473, 3474, 3489, 3492, 3492, 3494, 3495, 3502, 3510, 3514, 3517, 3519, 3519, 3530, 3531, 3531, 3533, 3538, 3541, 3544, 3545, 3552, 3554, 3556, 3556, 3556, 3560, 3560, 3560, 3561, 3562, 3570, 3571, 3576, 3579, 3593, 3595, 3603, 3604, 3617, 3618, 3620, 3624, 3625, 3627, 3631, 3631, 3632, 3632, 3642, 3643, 3644, 3647, 3650, 3657, 3657, 3657, 3658, 3661, 3665, 3669, 3669, 3673, 3677, 3678, 3680, 3685, 3688, 3694, 3701, 3708, 3708, 3708, 3717, 3728, 3732, 3734, 3740, 3745, 3745, 3746, 3749, 3751, 3751, 3755, 3756, 3758, 3761, 3762, 3765, 3770, 3772, 3774, 3774, 3780, 3781, 3787, 3788, 3788, 3789, 3793, 3798, 3803, 3806, 3814, 3816, 3821, 3823, 3841, 3841, 3843, 3846, 3847, 3850, 3857, 3857, 3858, 3863, 3864, 3864, 3868, 3871, 3871, 3874, 3877, 3884, 3885, 3887, 3889, 3893, 3894, 3901, 3902, 3908, 3912, 3912, 3917, 3918, 3924, 3925, 3937, 3944, 3944, 3945, 3950, 3958, 3959, 3961, 3969, 3970, 3971, 3972, 3975, 3977, 3977, 3978, 3979, 3986, 3988, 3989, 3992, 3997, 4002, 4005, 4009, 4013, 4015, 4018, 4021, 4022, 4024, 4032, 4034, 4036, 4038, 4040, 4059, 4059, 4065, 4068, 4071, 4072, 4072, 4074, 4075, 4075, 4076, 4080, 4081, 4088, 4090, 4092, 4101, 4101, 4106, 4115, 4116, 4120, 4121, 4123, 4124, 4133, 4134, 4137, 4139, 4143, 4149, 4152, 4153, 4162, 4172, 4172, 4173, 4176, 4177, 4181, 4188, 4188, 4189, 4189, 4190, 4190, 4191, 4194, 4196, 4199, 4201, 4203, 4205, 4218, 4221, 4228, 4229, 4237, 4244, 4248, 4249, 4252, 4252, 4253, 4253, 4264, 4265, 4268, 4275, 4277, 4278, 4284, 4286, 4286, 4290, 4291, 4295, 4299, 4300, 4302, 4303, 4304, 4316, 4318, 4319, 4319, 4320, 4329, 4333, 4335, 4352, 4361, 4362, 4365, 4366, 4366, 4366, 4366, 4367, 4368, 4374, 4379, 4381, 4390, 4391, 4392, 4400, 4400, 4401, 4406, 4408, 4412, 4415, 4415, 4417, 4420, 4431, 4433, 4433, 4434, 4436, 4449, 4449, 4450, 4461, 4462, 4463, 4465, 4466, 4467, 4475, 4477, 4479, 4479, 4479, 4481, 4481, 4483, 4489, 4494, 4507, 4507, 4509, 4521, 4530, 4530, 4530, 4530, 4537, 4537, 4537, 4546, 4556, 4562, 4562, 4564, 4564, 4565, 4565, 4578, 4578, 4578, 4578, 4580, 4580, 4580, 4580, 4580, 4590, 4592, 4592, 4592, 4592, 4594, 4596, 4596, 4606, 4606, 4622, 4622, 4693]\n" ] } ], "source": [ "#Reading the data\n", "with open('input/CyclicScoring.txt') as f:\n", " peptide, spectrum = [line.strip() if i==0 else map(int,line.strip().split()) for i, line in enumerate(f.readlines())]\n", "print 'peptide', peptide\n", "print 'spectrum', spectrum" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Final code for Cyclopeptide Scoring Problem" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "759" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aminoacidMass = {'G':57, 'A':71, 'S':87, 'P':97, 'V':99, 'T':101, 'C':103, 'I':113, 'L':113, 'N':114, 'D':115, 'K':128, 'Q':128, 'E':129, 'M':131, 'H':137, 'F':147, 'R':156, 'Y':163, 'W':186}\n", "def cyclicSpectrum(peptide):\n", " \"\"\"Input: An amino acid string Peptide.\n", " Output: The cyclic spectrum of Peptide.\"\"\"\n", " prefixMass = [0]*((len(peptide)+1))\n", " for i in range(len(peptide)):\n", " prefixMass[i+1] = prefixMass[i] + aminoacidMass[peptide[i]]\n", " peptideMass = prefixMass[len(peptide)]\n", " cyclic_spectrum = [0]\n", " for i in range(len(prefixMass)-1):\n", " for j in range(i+1, len(prefixMass)):\n", " cyclic_spectrum.append(prefixMass[j] - prefixMass[i])\n", " if i > 0 and j < (len(prefixMass)-1):\n", " cyclic_spectrum.append(peptideMass - (prefixMass[j] - prefixMass[i]))\n", " return sorted(cyclic_spectrum) \n", "\n", "from collections import Counter\n", "def score_peptide(peptide, spectrum):\n", " \"\"\"Cyclopeptide Scoring Problem: Compute the score of a cyclic peptide against a spectrum.\n", " Input: An amino acid string Peptide and a collection of integers Spectrum. \n", " Output: The score of Peptide against Spectrum, Score(Peptide, Spectrum).\"\"\"\n", " spectrum_peptide = cyclicSpectrum(peptide)\n", " c1, c2 = Counter(spectrum_peptide), Counter(spectrum)\n", " return sum([min(n, c2[k]) for k,n in c1.items()])\n", "\n", "#Reading the data\n", "with open('input/rosalind_ba4f.txt') as f:\n", " peptide, spectrum = [line.strip() if i==0 else map(int,line.strip().split()) for i, line in enumerate(f.readlines())]\n", " \n", "#Calling the function to compute score\n", "score_peptide(peptide, spectrum)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.5" } }, "nbformat": 4, "nbformat_minor": 0 }