diff --git a/rpg/RapidPeptidesGenerator.py b/rpg/RapidPeptidesGenerator.py index f7177d6105ae2217d4785a7f4e4850da1edbf92c..de832b1157278df9289b18a32488b9e6bda48420 100644 --- a/rpg/RapidPeptidesGenerator.py +++ b/rpg/RapidPeptidesGenerator.py @@ -272,9 +272,9 @@ def main(): "error(s) (--quiet enable, overwrite -v). If output " "filename already exists, output file will be " "overwritten.") - parser.add_argument("-p", "--pka", metavar="", choices=['ipc', 'stryer'], - default="ipc", help="Define pKa values. Either 'ipc' " - "or 'stryer' (default: ipc)") + parser.add_argument("-p", "--pka", metavar="", choices=['ipc2', 'stryer', 'ipc'], + default="ipc2", help="Define pKa values. Either 'ipc2' " + "'stryer' or 'ipc' (deprecated) (default: ipc2)") group_output = parser.add_mutually_exclusive_group() group_output.add_argument("-o", "--outputfile", type=str, metavar="", default="", help="Optional result file " @@ -306,9 +306,11 @@ def main(): args.miscleavage = [] # No miscleavage on concurrent, infinite time # --pka option - aa_pka = core.AA_PKA_IPC + aa_pka = core.AA_PKA_IPC_2 if args.pka == "stryer": aa_pka = core.AA_PKA_S + elif args.pka == "ipc": + aa_pka = core.AA_PKA_IPC # --list option if args.list: diff --git a/rpg/core.py b/rpg/core.py index d9f55858a17474e177aafc7e178a757c4b1208e7..76db9f3355f2df8135b805788a2e7b83d9bff689 100644 --- a/rpg/core.py +++ b/rpg/core.py @@ -86,6 +86,17 @@ AA_PKA_IPC = {"Nterm" : 9.564, "Y" : 10.071, "Cterm" : 2.383} """pKa of important amino acid to compute pI (from IPC_peptide. See http://isoelectric.org/theory.html for details).""" +# IPC_peptide2 +AA_PKA_IPC_2 = {"Nterm" : 7.947, + "C" : 9.454, + "D" : 3.969, + "E" : 4.507, + "H" : 6.439, + "K" : 8.165, + "R" : 11.493, + "Y" : 9.153, + "Cterm" : 2.977} +"""pKa of important amino acid to compute pI (from IPC_peptide2. See http://www.ipc2-isoelectric-point.org/ for details).""" def handle_errors(message="", err=1, error_type=""): """Custom handling of errors and warnings. diff --git a/rpg/sequence.py b/rpg/sequence.py index f4d2209b1294ea5bbca1b2e072e68c67dd2053e6..7dd05b1ad0e6ee0c54404d3479e3d9d8254b9dd2 100644 --- a/rpg/sequence.py +++ b/rpg/sequence.py @@ -68,9 +68,11 @@ class Peptide: # self representation for print def __repr__(self): - pka = "IPC" + pka = "IPC2" if self.aa_pka == core.AA_PKA_S: pka = "Stryer" + elif self.aa_pka == core.AA_PKA_IPC: + pka = "IPC" return "Original header: " + self.header + "\nNo. peptide: " + \ str(self.nb_peptide) + "\nEnzyme: " + self.enzyme_name + \ "\nCleav. pos: " + str(self.position) + "\nPep. size: " + \ diff --git a/tests/test_functional.py b/tests/test_functional.py index ed8296b0943ef90a006d418e14163235d59e107f..572fe52622690095053d8fcf298a3c70599ba438 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -9,6 +9,220 @@ from rpg import RapidPeptidesGenerator @pytest.fixture def truth(): + """ Solution """ + return [">A0A2C9KB11/1065-1162_0_Trypsin_2_2_289.29138_5.98\n", + "DR\n", + ">A0A2C9KB11/1065-1162_1_Trypsin_10_8_935.00128_4.29\n", + "EALDSSWK\n", + ">A0A2C9KB11/1065-1162_2_Trypsin_11_1_146.18938_8.06\n", + "K\n", + ">A0A2C9KB11/1065-1162_3_Trypsin_13_2_287.36218_9.71\n", + "LR\n", + ">A0A2C9KB11/1065-1162_4_Trypsin_19_6_503.51548_9.71\n", + "SGAGGR\n", + ">A0A2C9KB11/1065-1162_5_Trypsin_20_1_146.18938_8.06\n", + "K\n", + ">A0A2C9KB11/1065-1162_6_Trypsin_25_5_529.59668_9.71\n", + "NAGIR\n", + ">A0A2C9KB11/1065-1162_7_Trypsin_38_13_1623.99478_7.2\n", + "LVLWMLDHVPNMR\n", + ">A0A2C9KB11/1065-1162_8_Trypsin_42_4_535.60048_8.06\n", + "NQFK\n", + ">A0A2C9KB11/1065-1162_9_Trypsin_43_1_146.18938_8.06\n", + "K\n", + ">A0A2C9KB11/1065-1162_10_Trypsin_54_11_1297.43618_7.2\n", + "FAHQPDSVLQR\n", + ">A0A2C9KB11/1065-1162_11_Trypsin_64_10_1189.29028_3.89\n", + "DPEFLAQVDR\n", + ">A0A2C9KB11/1065-1162_12_Trypsin_88_24_2545.84688_3.63\n", + "ILGGVESMINNVDDPVALEAAFDR\n", + ">A0A2C9KB11/1065-1162_13_Trypsin_97_9_958.09728_5.22\n", + "LADAHLSMT\n", + ">A0A2C9KB11/1221-1332_0_Trypsin_2_2_303.31828_6.23\n", + "ER\n", + ">A0A2C9KB11/1221-1332_1_Trypsin_3_1_146.18938_8.06\n", + "K\n", + ">A0A2C9KB11/1221-1332_2_Trypsin_6_3_330.42758_8.06\n", + "ALK\n", + ">A0A2C9KB11/1221-1332_3_Trypsin_13_7_821.88518_5.87\n", + "SSWDSLK\n", + ">A0A2C9KB11/1221-1332_4_Trypsin_38_25_2643.03068_6.23\n", + "SAAGGSQEAGVNLVLWMLQNVPNMR\n", + ">A0A2C9KB11/1221-1332_5_Trypsin_40_2_289.29138_5.98\n", + "DR\n", + ">A0A2C9KB11/1221-1332_6_Trypsin_53_13_1463.56938_5.37\n", + "FTFNAHQGDDALK\n", + ">A0A2C9KB11/1221-1332_7_Trypsin_60_7_792.88708_4.29\n", + "ADAEFIK\n", + ">A0A2C9KB11/1221-1332_8_Trypsin_64_4_529.59678_9.71\n", + "QVQR\n", + ">A0A2C9KB11/1221-1332_9_Trypsin_81_17_1804.98958_3.89\n", + "ITGGLESMIDNLDNQGK\n", + ">A0A2C9KB11/1221-1332_10_Trypsin_88_7_785.89848_5.98\n", + "LQAAIDR\n", + ">A0A2C9KB11/1221-1332_11_Trypsin_110_22_2524.91728_5.5\n", + "LVDAHLHMTPSVGLEYFEPLQK\n", + ">A0A2C9KB11/1221-1332_12_Trypsin_111_1_132.11908_5.46\n", + "N\n", + ">A0A2C9KB11/1378-1486_0_Trypsin_2_2_289.29138_5.98\n", + "DR\n", + ">A0A2C9KB11/1378-1486_1_Trypsin_3_1_146.18938_8.06\n", + "K\n", + ">A0A2C9KB11/1378-1486_2_Trypsin_10_7_912.00988_6.12\n", + "YIESSWK\n", + ">A0A2C9KB11/1378-1486_3_Trypsin_11_1_146.18938_8.06\n", + "K\n", + ">A0A2C9KB11/1378-1486_4_Trypsin_21_10_947.99758_4.29\n", + "LTDAAGGSEK\n", + ">A0A2C9KB11/1378-1486_5_Trypsin_38_17_1994.29828_5.98\n", + "AGTNFVFWLLDNVPNMR\n", + ">A0A2C9KB11/1378-1486_6_Trypsin_40_2_289.29138_5.98\n", + "DR\n", + ">A0A2C9KB11/1378-1486_7_Trypsin_59_19_2255.34168_4.12\n", + "FTFNAHQSDAALQEDEEFR\n", + ">A0A2C9KB11/1378-1486_8_Trypsin_63_4_487.55648_8.06\n", + "NQVK\n", + ">A0A2C9KB11/1378-1486_9_Trypsin_108_45_4677.21938_4.05\n", + "AITGGIESFVNNVNNPAALQSSIETLVDAHLNMQPSIGLSYFGSV\n", + ">A0A2C9KB11/1535-1643_0_Trypsin_2_2_289.29138_5.98\n", + "DR\n", + ">A0A2C9KB11/1535-1643_1_Trypsin_3_1_174.20278_9.71\n", + "R\n", + ">A0A2C9KB11/1535-1643_2_Trypsin_10_7_775.90298_8.06\n", + "AVVSSWK\n", + ">A0A2C9KB11/1535-1643_3_Trypsin_11_1_146.18938_8.06\n", + "K\n", + ">A0A2C9KB11/1535-1643_4_Trypsin_17_6_603.67618_9.71\n", + "LTASGR\n", + ">A0A2C9KB11/1535-1643_5_Trypsin_36_19_2281.67528_5.98\n", + "QSFGIDLVLWMFNNVPNMR\n", + ">A0A2C9KB11/1535-1643_6_Trypsin_44_8_985.06128_4.29\n", + "EQFTFDAK\n", + ">A0A2C9KB11/1535-1643_7_Trypsin_51_7_803.82708_4.04\n", + "QSDADLR\n", + ">A0A2C9KB11/1535-1643_8_Trypsin_52_1_174.20278_9.71\n", + "R\n", + ">A0A2C9KB11/1535-1643_9_Trypsin_58_6_732.83448_5.87\n", + "DPNFLK\n", + ">A0A2C9KB11/1535-1643_10_Trypsin_79_21_2158.36788_3.75\n", + "QVNSIVNGLGDMVDSVNDPGK\n", + ">A0A2C9KB11/1535-1643_11_Trypsin_86_7_842.95038_6.23\n", + "LQANLER\n", + ">A0A2C9KB11/1535-1643_12_Trypsin_108_22_2521.94168_5.57\n", + "LSEIHLHFVPSVGPEFFVPLEK\n", + ">A0A2C9K1A5/128-239_0_Trypsin_3_3_374.43738_5.87\n", + "DIK\n", + ">A0A2C9K1A5/128-239_1_Trypsin_11_8_919.98958_5.87\n", + "ALDSSWNK\n", + ">A0A2C9K1A5/128-239_2_Trypsin_19_8_759.81728_5.98\n", + "LTAGADGR\n", + ">A0A2C9K1A5/128-239_3_Trypsin_37_18_2120.51518_9.71\n", + "TTFGNNLVLWMLNVPNMR\n", + ">A0A2C9K1A5/128-239_4_Trypsin_39_2_303.31828_6.23\n", + "ER\n", + ">A0A2C9K1A5/128-239_5_Trypsin_42_3_392.49858_8.06\n", + "FVK\n", + ">A0A2C9K1A5/128-239_6_Trypsin_53_11_1259.34088_5.53\n", + "FNAHQSDEALK\n", + ">A0A2C9K1A5/128-239_7_Trypsin_60_7_835.91208_4.29\n", + "NDAEFIK\n", + ">A0A2C9K1A5/128-239_8_Trypsin_63_3_373.45268_8.06\n", + "QVK\n", + ">A0A2C9K1A5/128-239_9_Trypsin_111_48_5318.17868_6.16\n", + "LIVGGLQTLIINLNNPGQLQASIEHLADVHLHMKPSIGLEYFKPLQEN\n", + ">A0A2C9K1A5/285-395_0_Trypsin_2_2_261.27798_5.87\n", + "DK\n", + ">A0A2C9K1A5/285-395_1_Trypsin_11_9_1034.13688_6.23\n", + "VALESSWSR\n", + ">A0A2C9K1A5/285-395_2_Trypsin_19_8_758.87288_8.06\n", + "LTAGVNGK\n", + ">A0A2C9K1A5/285-395_3_Trypsin_20_1_174.20278_9.71\n", + "R\n", + ">A0A2C9K1A5/285-395_4_Trypsin_25_5_515.56988_9.71\n", + "NAGVR\n", + ">A0A2C9K1A5/285-395_5_Trypsin_37_12_1520.87088_5.98\n", + "LVLWMFNVPDMR\n", + ">A0A2C9K1A5/285-395_6_Trypsin_39_2_303.31828_6.23\n", + "ER\n", + ">A0A2C9K1A5/285-395_7_Trypsin_42_3_422.48448_9.71\n", + "FTR\n", + ">A0A2C9K1A5/285-395_8_Trypsin_46_4_478.54858_8.06\n", + "FNAK\n", + ">A0A2C9K1A5/285-395_9_Trypsin_53_7_789.84058_4.29\n", + "QSDEALK\n", + ">A0A2C9K1A5/285-395_10_Trypsin_60_7_822.91338_4.29\n", + "TDAEFLK\n", + ">A0A2C9K1A5/285-395_11_Trypsin_85_25_2798.14518_3.68\n", + "QVDVIIGGFETLINNLNDPTLLQDR\n", + ">A0A2C9K1A5/285-395_12_Trypsin_96_11_1225.36408_4.66\n", + "LESLADAHLEK\n", + ">A0A2C9K1A5/285-395_13_Trypsin_110_14_1504.79238_8.32\n", + "KPAIGVSYFGPLQK\n", + ">A0A2C9K1A5/588-698_0_Trypsin_2_2_261.27798_5.87\n", + "DK\n", + ">A0A2C9K1A5/588-698_1_Trypsin_3_1_146.18938_8.06\n", + "K\n", + ">A0A2C9K1A5/588-698_2_Trypsin_25_22_2285.50118_8.06\n", + "ALQSSWNTLVNQAGGQQNAGIK\n", + ">A0A2C9K1A5/588-698_3_Trypsin_37_12_1519.88608_9.71\n", + "LVLWMFNVPNMR\n", + ">A0A2C9K1A5/588-698_4_Trypsin_39_2_289.29138_5.98\n", + "DR\n", + ">A0A2C9K1A5/588-698_5_Trypsin_42_3_380.44418_8.06\n", + "FSK\n", + ">A0A2C9K1A5/588-698_6_Trypsin_53_11_1204.26148_5.37\n", + "FNAHSSDDALK\n", + ">A0A2C9K1A5/588-698_7_Trypsin_60_7_792.88708_4.29\n", + "ADAEFLK\n", + ">A0A2C9K1A5/588-698_8_Trypsin_81_21_2198.41478_3.68\n", + "QVNVIVGGLESLVNNVDDADK\n", + ">A0A2C9K1A5/588-698_9_Trypsin_88_7_771.87168_6.23\n", + "LQAGVER\n", + ">A0A2C9K1A5/588-698_10_Trypsin_110_22_2438.78338_5.38\n", + "LVDAHLHMSPSVGLEYFGPLQQ\n", + ">A0A2C9K1A5/745-855_0_Trypsin_2_2_289.29138_5.98\n", + "DR\n", + ">A0A2C9K1A5/745-855_1_Trypsin_3_1_146.18938_8.06\n", + "K\n", + ">A0A2C9K1A5/745-855_2_Trypsin_7_4_515.61028_6.23\n", + "VLER\n", + ">A0A2C9K1A5/745-855_3_Trypsin_19_12_1257.41158_8.06\n", + "TWNQLISGPGGK\n", + ">A0A2C9K1A5/745-855_4_Trypsin_21_2_275.30488_6.13\n", + "EK\n", + ">A0A2C9K1A5/745-855_5_Trypsin_25_4_387.47948_8.06\n", + "AGIK\n", + ">A0A2C9K1A5/745-855_6_Trypsin_38_13_1649.00158_6.23\n", + "LVLWMFENVPNMR\n", + ">A0A2C9K1A5/745-855_7_Trypsin_43_5_623.66348_5.87\n", + "DQFSK\n", + ">A0A2C9K1A5/745-855_8_Trypsin_48_5_616.67448_7.08\n", + "FDAHK\n", + ">A0A2C9K1A5/745-855_9_Trypsin_60_12_1349.50358_4.67\n", + "SDEALSKPEFVK\n", + ">A0A2C9K1A5/745-855_10_Trypsin_96_36_3961.35988_4.38\n", + "QVNNIFGGLESILNNLNKPGQLQSALENLADDHLDR\n", + ">A0A2C9K1A5/745-855_11_Trypsin_99_3_399.49358_9.93\n", + "KPR\n", + ">A0A2C9K1A5/745-855_12_Trypsin_110_11_1248.48748_6.13\n", + "IGLEFFGPLQK\n", + ">A0A2C9K1A5/935-1004_0_Trypsin_10_10_1288.50498_7.2\n", + "QMFEHVPNMR\n", + ">A0A2C9K1A5/935-1004_1_Trypsin_15_5_651.71728_6.13\n", + "EQFTK\n", + ">A0A2C9K1A5/935-1004_2_Trypsin_26_11_1211.34268_7.08\n", + "FDAHQPNAALK\n", + ">A0A2C9K1A5/935-1004_3_Trypsin_37_11_1258.39948_6.23\n", + "QNPEFLAQVGR\n", + ">A0A2C9K1A5/935-1004_4_Trypsin_55_18_1881.15618_3.89\n", + "ILGGIESLLNNDDPVALK\n", + ">A0A2C9K1A5/935-1004_5_Trypsin_60_5_544.60838_5.98\n", + "AAIDR\n", + ">A0A2C9K1A5/935-1004_6_Trypsin_69_9_944.07038_5.22\n", + "LADAHLSMS\n"] + +@pytest.fixture +def truth_ipc(): """ Solution """ return [">A0A2C9KB11/1065-1162_0_Trypsin_2_2_289.29138_6.73\n", "DR\n", @@ -302,6 +516,40 @@ def list_enz(): @pytest.fixture def res_dig_1_42(): + """ Result for digestion with 1 and 42 and IPC2 """ + return ">Input_0_Arg-C_2_2_289.29138_5.98\n"\ + "DR\n"\ + ">Input_1_Arg-C_13_11_1332.52228_7.79\n"\ + "EALDSSWKKLR\n"\ + ">Input_2_Arg-C_19_6_503.51548_9.71\n"\ + "SGAGGR\n"\ + ">Input_3_Arg-C_25_6_657.77078_9.93\n"\ + "KNAGIR\n"\ + ">Input_4_Arg-C_44_19_2283.62998_4.3\n"\ + "LVLWMLDFDAHQPDSVLQR\n"\ + ">Input_5_Arg-C_47_3_407.46678_3.74\n"\ + "EFL\n"\ + ">Input_0_Trypsin_2_2_289.29138_5.98\n"\ + "DR\n"\ + ">Input_1_Trypsin_10_8_935.00128_4.29\n"\ + "EALDSSWK\n"\ + ">Input_2_Trypsin_11_1_146.18938_8.06\n"\ + "K\n"\ + ">Input_3_Trypsin_13_2_287.36218_9.71\n"\ + "LR\n"\ + ">Input_4_Trypsin_19_6_503.51548_9.71\n"\ + "SGAGGR\n"\ + ">Input_5_Trypsin_20_1_146.18938_8.06\n"\ + "K\n"\ + ">Input_6_Trypsin_25_5_529.59668_9.71\n"\ + "NAGIR\n"\ + ">Input_7_Trypsin_44_19_2283.62998_4.3\n"\ + "LVLWMLDFDAHQPDSVLQR\n"\ + ">Input_8_Trypsin_47_3_407.46678_3.74\n"\ + "EFL\n" + +@pytest.fixture +def res_dig_1_42_ipc(): """ Result for digestion with 1 and 42 """ return ">Input_0_Arg-C_2_2_289.29138_6.73\n"\ "DR\n"\ @@ -424,6 +672,17 @@ def test_s_option(capsys, res_dig_1_42): captured = capsys.readouterr() assert res_dig_1_42 in captured.out +def test_s_option_ipc(capsys, res_dig_1_42_ipc): + """ Test -s behavior """ + with unittest.mock.patch("sys.argv", ["func_test", + "-s", "DREALDSSWKKLRSgagGRKNAGI"\ + "RLVLWMLDFDAHQPDSVLQREFL", + "-e", "1", "42", "-p", "ipc"]): + RapidPeptidesGenerator.main() + # Output + captured = capsys.readouterr() + assert res_dig_1_42_ipc in captured.out + def test_d_option(capsys): """ Test -d behavior """ # sequential @@ -433,6 +692,40 @@ def test_d_option(capsys): RapidPeptidesGenerator.main() # Output captured = capsys.readouterr() + assert ">Input_0_Lys-C_2_2_243.30608_8.06\nPK\n"\ + ">Input_1_Lys-C_4_2_243.30608_8.06\nPK\n"\ + ">Input_2_Lys-C_6_2_243.30608_8.06\nPK\n"\ + ">Input_3_Lys-C_8_2_243.30608_8.06\nPK\n"\ + ">Input_0_Lys-N_1_1_115.13198_5.46\nP\n"\ + ">Input_1_Lys-N_3_2_243.30608_8.06\nKP\n"\ + ">Input_2_Lys-N_5_2_243.30608_8.06\nKP\n"\ + ">Input_3_Lys-N_7_2_243.30608_8.06\nKP\n"\ + ">Input_4_Lys-N_8_1_146.18938_8.06\nK\n" in captured.out + # concurrent + with unittest.mock.patch("sys.argv", ["func_test", + "-s", "PKPKPKPK", + "-e", "28", "29", "-d", "c"]): + RapidPeptidesGenerator.main() + # Output + captured = capsys.readouterr() + assert ">Input_0_Lys-C-Lys-N_1_1_115.13198_5.46\nP\n"\ + ">Input_1_Lys-C-Lys-N_2_1_146.18938_8.06\nK\n"\ + ">Input_2_Lys-C-Lys-N_3_1_115.13198_5.46\nP\n"\ + ">Input_3_Lys-C-Lys-N_4_1_146.18938_8.06\nK\n"\ + ">Input_4_Lys-C-Lys-N_5_1_115.13198_5.46\nP\n"\ + ">Input_5_Lys-C-Lys-N_6_1_146.18938_8.06\nK\n"\ + ">Input_6_Lys-C-Lys-N_7_1_115.13198_5.46\nP\n"\ + ">Input_7_Lys-C-Lys-N_8_1_146.18938_8.06\nK\n" in captured.out + +def test_d_option_ipc(capsys): + """ Test -d behavior """ + # sequential + with unittest.mock.patch("sys.argv", ["func_test", + "-s", "PKPKPKPK", "-p", "ipc", + "-e", "28", "29", "-d", "s"]): + RapidPeptidesGenerator.main() + # Output + captured = capsys.readouterr() assert "Input_0_Lys-C_2_2_243.30608_10.04\nPK\n"\ ">Input_1_Lys-C_4_2_243.30608_10.04\nPK\n"\ ">Input_2_Lys-C_6_2_243.30608_10.04\nPK\n"\ @@ -444,7 +737,7 @@ def test_d_option(capsys): ">Input_4_Lys-N_8_1_146.18938_10.04\nK\n" in captured.out # concurrent with unittest.mock.patch("sys.argv", ["func_test", - "-s", "PKPKPKPK", + "-s", "PKPKPKPK", "-p", "ipc", "-e", "28", "29", "-d", "c"]): RapidPeptidesGenerator.main() # Output @@ -463,19 +756,19 @@ def test_p_option(capsys): # default with unittest.mock.patch("sys.argv", ["func_test", "-s", "PKPKPKPK", - "-e", "28", "29", "-p", "ipc"]): + "-e", "28", "29", "-p", "ipc2"]): RapidPeptidesGenerator.main() # Output captured = capsys.readouterr() - assert "Input_0_Lys-C_2_2_243.30608_10.04\nPK\n"\ - ">Input_1_Lys-C_4_2_243.30608_10.04\nPK\n"\ - ">Input_2_Lys-C_6_2_243.30608_10.04\nPK\n"\ - ">Input_3_Lys-C_8_2_243.30608_10.04\nPK\n"\ - ">Input_0_Lys-N_1_1_115.13198_5.97\nP\n"\ - ">Input_1_Lys-N_3_2_243.30608_10.04\nKP\n"\ - ">Input_2_Lys-N_5_2_243.30608_10.04\nKP\n"\ - ">Input_3_Lys-N_7_2_243.30608_10.04\nKP\n"\ - ">Input_4_Lys-N_8_1_146.18938_10.04\nK\n" in captured.out + assert ">Input_0_Lys-C_2_2_243.30608_8.06\nPK\n"\ + ">Input_1_Lys-C_4_2_243.30608_8.06\nPK\n"\ + ">Input_2_Lys-C_6_2_243.30608_8.06\nPK\n"\ + ">Input_3_Lys-C_8_2_243.30608_8.06\nPK\n"\ + ">Input_0_Lys-N_1_1_115.13198_5.46\nP\n"\ + ">Input_1_Lys-N_3_2_243.30608_8.06\nKP\n"\ + ">Input_2_Lys-N_5_2_243.30608_8.06\nKP\n"\ + ">Input_3_Lys-N_7_2_243.30608_8.06\nKP\n"\ + ">Input_4_Lys-N_8_1_146.18938_8.06\nK\n" in captured.out # stryer with unittest.mock.patch("sys.argv", ["func_test", @@ -494,6 +787,23 @@ def test_p_option(capsys): ">Input_3_Lys-N_7_2_243.30608_9.4\nKP\n"\ ">Input_4_Lys-N_8_1_146.18938_9.4\nK\n" in captured.out + # ipc + with unittest.mock.patch("sys.argv", ["func_test", + "-s", "PKPKPKPK", + "-e", "28", "29", "-p", "ipc"]): + RapidPeptidesGenerator.main() + # Output + captured = capsys.readouterr() + assert ">Input_0_Lys-C_2_2_243.30608_10.04\nPK\n"\ + ">Input_1_Lys-C_4_2_243.30608_10.04\nPK\n"\ + ">Input_2_Lys-C_6_2_243.30608_10.04\nPK\n"\ + ">Input_3_Lys-C_8_2_243.30608_10.04\nPK\n"\ + ">Input_0_Lys-N_1_1_115.13198_5.97\nP\n"\ + ">Input_1_Lys-N_3_2_243.30608_10.04\nKP\n"\ + ">Input_2_Lys-N_5_2_243.30608_10.04\nKP\n"\ + ">Input_3_Lys-N_7_2_243.30608_10.04\nKP\n"\ + ">Input_4_Lys-N_8_1_146.18938_10.04\nK\n" in captured.out + def test_f_option(capsys): """ Test -f behavior """ # default @@ -503,6 +813,63 @@ def test_f_option(capsys): RapidPeptidesGenerator.main() # Output captured = capsys.readouterr() + assert ">Input_0_Lys-C_2_2_243.30608_8.06\nPK\n"\ + ">Input_1_Lys-C_4_2_243.30608_8.06\nPK\n"\ + ">Input_2_Lys-C_6_2_243.30608_8.06\nPK\n"\ + ">Input_3_Lys-C_8_2_243.30608_8.06\nPK\n"\ + ">Input_0_Lys-N_1_1_115.13198_5.46\nP\n"\ + ">Input_1_Lys-N_3_2_243.30608_8.06\nKP\n"\ + ">Input_2_Lys-N_5_2_243.30608_8.06\nKP\n"\ + ">Input_3_Lys-N_7_2_243.30608_8.06\nKP\n"\ + ">Input_4_Lys-N_8_1_146.18938_8.06\nK\n" in captured.out + + # csv + with unittest.mock.patch("sys.argv", ["func_test", + "-s", "PKPKPKPK", + "-e", "28", "29", "-f", "csv"]): + RapidPeptidesGenerator.main() + # Output + captured = capsys.readouterr() + assert "Original_header,No_peptide,Enzyme,Cleaving_pos,Peptide_size,"\ + "Peptide_mass,pI,Sequence\n"\ + "Input,0,Lys-C,2,2,243.30608,8.06,PK\n"\ + "Input,1,Lys-C,4,2,243.30608,8.06,PK\n"\ + "Input,2,Lys-C,6,2,243.30608,8.06,PK\n"\ + "Input,3,Lys-C,8,2,243.30608,8.06,PK\n"\ + "Input,0,Lys-N,1,1,115.13198,5.46,P\n"\ + "Input,1,Lys-N,3,2,243.30608,8.06,KP\n"\ + "Input,2,Lys-N,5,2,243.30608,8.06,KP\n"\ + "Input,3,Lys-N,7,2,243.30608,8.06,KP\n"\ + "Input,4,Lys-N,8,1,146.18938,8.06,K\n" in captured.out + + # tsv + with unittest.mock.patch("sys.argv", ["func_test", + "-s", "PKPKPKPK", + "-e", "28", "29", "-f", "tsv"]): + RapidPeptidesGenerator.main() + # Output + captured = capsys.readouterr() + assert "Original_header\tNo_peptide\tEnzyme\tCleaving_pos\tPeptide_size\t"\ + "Peptide_mass\tpI\tSequence\n"\ + "Input\t0\tLys-C\t2\t2\t243.30608\t8.06\tPK\n"\ + "Input\t1\tLys-C\t4\t2\t243.30608\t8.06\tPK\n"\ + "Input\t2\tLys-C\t6\t2\t243.30608\t8.06\tPK\n"\ + "Input\t3\tLys-C\t8\t2\t243.30608\t8.06\tPK\n"\ + "Input\t0\tLys-N\t1\t1\t115.13198\t5.46\tP\n"\ + "Input\t1\tLys-N\t3\t2\t243.30608\t8.06\tKP\n"\ + "Input\t2\tLys-N\t5\t2\t243.30608\t8.06\tKP\n"\ + "Input\t3\tLys-N\t7\t2\t243.30608\t8.06\tKP\n"\ + "Input\t4\tLys-N\t8\t1\t146.18938\t8.06\tK\n" in captured.out + +def test_f_option_ipc(capsys): + """ Test -f behavior """ + # default + with unittest.mock.patch("sys.argv", ["func_test", + "-s", "PKPKPKPK", "-p", "ipc", + "-e", "28", "29", "-f", "fasta"]): + RapidPeptidesGenerator.main() + # Output + captured = capsys.readouterr() assert "Input_0_Lys-C_2_2_243.30608_10.04\nPK\n"\ ">Input_1_Lys-C_4_2_243.30608_10.04\nPK\n"\ ">Input_2_Lys-C_6_2_243.30608_10.04\nPK\n"\ @@ -515,7 +882,7 @@ def test_f_option(capsys): # csv with unittest.mock.patch("sys.argv", ["func_test", - "-s", "PKPKPKPK", + "-s", "PKPKPKPK", "-p", "ipc", "-e", "28", "29", "-f", "csv"]): RapidPeptidesGenerator.main() # Output @@ -534,7 +901,7 @@ def test_f_option(capsys): # tsv with unittest.mock.patch("sys.argv", ["func_test", - "-s", "PKPKPKPK", + "-s", "PKPKPKPK", "-p", "ipc", "-e", "28", "29", "-f", "tsv"]): RapidPeptidesGenerator.main() # Output @@ -564,6 +931,19 @@ def test_i_option(capsys, truth, file_a): for i in truth: assert i in captured.out +def test_i_option_ipc(capsys, truth_ipc, file_a): + """ Test the functional behavior of FRAG of i option """ + # Test -i behavior with fasta file + with unittest.mock.patch("sys.argv", ["func_test", + "-i", str(file_a), + "-e", "42", "-p", "ipc"]): + RapidPeptidesGenerator.main() + # Output + captured = capsys.readouterr() + # Check result + for i in truth_ipc: + assert i in captured.out + def test_i_option_parallel(capsys, truth, file_a): """ Test the functional behavior of FRAG of i option """ # Test -i behavior with fasta file @@ -578,6 +958,20 @@ def test_i_option_parallel(capsys, truth, file_a): for i in truth: assert i in captured.out +def test_i_option_parallel_ipc(capsys, truth_ipc, file_a): + """ Test the functional behavior of FRAG of i option """ + # Test -i behavior with fasta file + with unittest.mock.patch("sys.argv", ["func_test", + "-i", str(file_a), + "-e", "42", + "-c", "8", "-p", "ipc"]): + RapidPeptidesGenerator.main() + # Output + captured = capsys.readouterr() + # Check result + for i in truth_ipc: + assert i in captured.out + def test_o_option(tmpdir, truth, file_a): """ Test the functional behavior of FRAG of o (and q) option """ # Output folder @@ -599,6 +993,27 @@ def test_o_option(tmpdir, truth, file_a): assert line in truth assert nb_line == len(truth) +def test_o_option_ipc(tmpdir, truth_ipc, file_a): + """ Test the functional behavior of FRAG of o (and q) option """ + # Output folder + output_folder = tmpdir.mkdir("res_functional_tests") + + # Test -o behavior with fasta file + with unittest.mock.patch("sys.argv", ["func_test", + "-i", str(file_a), + "-e", "42", + "-q", "-p", "ipc", + "-o", os.path.join(output_folder, + "res.fa")]): + RapidPeptidesGenerator.main() + # Check result + nb_line = 0 + with open(os.path.join(output_folder, "res.fa")) as file_res: + for line in file_res: + nb_line += 1 + assert line in truth_ipc + assert nb_line == len(truth_ipc) + def test_no_enz(capsys, monkeypatch, list_enz, res_dig_1_42): """ Test -l behavior """ responses = iter(["1 42", ""]) @@ -612,6 +1027,19 @@ def test_no_enz(capsys, monkeypatch, list_enz, res_dig_1_42): assert list_enz in captured.out assert res_dig_1_42 in captured.out +def test_no_enz_ipc(capsys, monkeypatch, list_enz, res_dig_1_42_ipc): + """ Test -l behavior """ + responses = iter(["1 42", ""]) + with unittest.mock.patch("sys.argv", ["func_test", "-p", "ipc", + "-s", "DREALDSSWKKLRSgagGRKNAGI"\ + "RLVLWMLDFDAHQPDSVLQREFL"]): + monkeypatch.setattr('builtins.input', lambda msg: next(responses)) + RapidPeptidesGenerator.main() + # Output + captured = capsys.readouterr() + assert list_enz in captured.out + assert res_dig_1_42_ipc in captured.out + def test_no_enz_quit(capsys, monkeypatch, list_enz): """ Test -l behavior """ responses = iter(["q"]) @@ -640,3 +1068,18 @@ def test_no_enz_err(capsys, monkeypatch, list_enz, res_dig_1_42): assert res_dig_1_42 in captured.out assert "Warning: 'b' should be an integer value. This values will be "\ "ignored.\n" in captured.err + +def test_no_enz_err_ipc(capsys, monkeypatch, list_enz, res_dig_1_42_ipc): + """ Test -l behavior """ + responses = iter(["1 42 b", ""]) + with unittest.mock.patch("sys.argv", ["func_test", "-p", "ipc", + "-s", "DREALDSSWKKLRSgagGRKNAGI"\ + "RLVLWMLDFDAHQPDSVLQREFL"]): + monkeypatch.setattr('builtins.input', lambda msg: next(responses)) + RapidPeptidesGenerator.main() + # Output + captured = capsys.readouterr() + assert list_enz in captured.out + assert res_dig_1_42_ipc in captured.out + assert "Warning: 'b' should be an integer value. This values will be "\ + "ignored.\n" in captured.err