1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454
|
Author: Andreas Tille <tille@debian.org>
Last-Update: Mon, 29 Oct 2018 14:47:53 +0100
Description: Run 2to3 on examples
Forwarded: Jaime Huerta-Cepas <huerta@embl.de>
--- a/examples/clustering/bubbles_validation.py
+++ b/examples/clustering/bubbles_validation.py
@@ -13,7 +13,7 @@ array = t.arraytable
# Calculates some stats on the matrix. Needed to establish the color
# gradients.
-matrix_dist = [i for r in xrange(len(array.matrix))\
+matrix_dist = [i for r in range(len(array.matrix))\
for i in array.matrix[r] if numpy.isfinite(i)]
matrix_max = numpy.max(matrix_dist)
matrix_min = numpy.min(matrix_dist)
--- a/examples/clustering/cluster_visualization.py
+++ b/examples/clustering/cluster_visualization.py
@@ -13,8 +13,8 @@ F\t-1.04\t-1.11\t0.87\t-0.14\t-0.80\t1.7
G\t-1.57\t-1.17\t1.29\t0.23\t-0.20\t1.17\t0.26
H\t-1.53\t-1.25\t0.59\t-0.30\t0.32\t1.41\t0.77
"""
-print "Example numerical matrix"
-print matrix
+print("Example numerical matrix")
+print(matrix)
# #Names col1 col2 col3 col4 col5 col6 col7
# A -1.23 -0.81 1.79 0.78 -0.42 -0.69 0.58
# B -1.76 -0.94 1.16 0.36 0.41 -0.35 1.12
--- a/examples/clustering/clustering_tree.py
+++ b/examples/clustering/clustering_tree.py
@@ -13,8 +13,8 @@ F\t-1.04\t-1.11\t0.87\t-0.14\t-0.80\t1.7
G\t-1.57\t-1.17\t1.29\t0.23\t-0.20\t1.17\t0.26
H\t-1.53\t-1.25\t0.59\t-0.30\t0.32\t1.41\t0.77
"""
-print "Example numerical matrix"
-print matrix
+print("Example numerical matrix")
+print(matrix)
# #Names col1 col2 col3 col4 col5 col6 col7
# A -1.23 -0.81 1.79 0.78 -0.42 -0.69 0.58
# B -1.76 -0.94 1.16 0.36 0.41 -0.35 1.12
@@ -30,7 +30,7 @@ print matrix
# numerical matrix. We use the text_array argument to link the tree
# with numerical matrix.
t = ClusterTree("(((A,B),(C,(D,E))),(F,(G,H)));", text_array=matrix)
-print "Example tree", t
+print("Example tree", t)
# /-A
# /--------|
# | \-B
@@ -49,18 +49,18 @@ print "Example tree", t
# Now we can ask the numerical profile associated to each node
A = t.search_nodes(name='A')[0]
-print "A associated profile:\n", A.profile
+print("A associated profile:\n", A.profile)
# [-1.23 -0.81 1.79 0.78 -0.42 -0.69 0.58]
#
# Or we can ask for the mean numerical profile of an internal
# partition, which is computed as the average of all vectors under the
# the given node.
cluster = t.get_common_ancestor("E", "A")
-print "Internal cluster mean profile:\n", cluster.profile
+print("Internal cluster mean profile:\n", cluster.profile)
#[-1.574 -0.686 1.048 -0.012 -0.118 0.614 0.728]
#
# We can also obtain the std. deviation vector of the mean profile
-print "Internal cluster std deviation profile:\n", cluster.deviation
+print("Internal cluster std deviation profile:\n", cluster.deviation)
#[ 0.36565558 0.41301816 0.40676283 0.56211743 0.50704635 0.94949671
# 0.26753691]
# If would need to re-link the tree to a different matrix or use
@@ -96,7 +96,7 @@ H\t0\t0\t0\t0\t0\t0\t0
# obviated from association.
t.children[0].link_to_arraytable(matrix_ones)
t.children[1].link_to_arraytable(matrix_zeros)
-print "A profile (using matrix with 1s", (t&"A").profile
-print "H profile (using matrix with 0s)", (t&"H").profile
+print("A profile (using matrix with 1s", (t&"A").profile)
+print("H profile (using matrix with 0s)", (t&"H").profile)
#A profile (using matrix with 1s [ 1. 1. 1. 1. 1. 1. 1.]
#H profile (using matrix with 0s) [ 0. 0. 0. 0. 0. 0. 0.]
--- a/examples/evol/1_freeratio.py
+++ b/examples/evol/1_freeratio.py
@@ -23,13 +23,13 @@ tree = EvolTree ("data/S_example/measuri
print (tree)
-input ('\n tree loaded, hit some key.\n')
+eval(input ('\n tree loaded, hit some key.\n'))
print ('Now, it is necessary to link this tree to an alignment:')
tree.link_to_alignment ('data/S_example/alignment_S_measuring_evol.fasta')
-input ('\n alignment loaded, hit some key to see.\n')
+eval(input ('\n alignment loaded, hit some key to see.\n'))
tree.show()
@@ -38,28 +38,28 @@ we will run free-ratio model that is one
function run_model:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
''')
-print (tree.run_model.__doc__ +'\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
+print(tree.run_model.__doc__ +'\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
tree.run_model ('fb.example')
-input ('free-ratio model runned, all results are store in a Model object.')
+eval(input ('free-ratio model runned, all results are store in a Model object.'))
fb = tree.get_evol_model('fb.example')
print ('Have a look to the parameters used to run this model on codeml: ')
-print (fb.get_ctrl_string())
-input ('hit some key...')
+print(fb.get_ctrl_string())
+eval(input ('hit some key...'))
print ('Have a look to run message of codeml: ')
-print (fb.run)
-input ('hit some key...')
+print(fb.run)
+eval(input ('hit some key...'))
print ('Have a look to log likelihood value of this model, and number of parameters:')
-print ('lnL: %s and np: %s' % (fb.lnL, fb.np))
-input ('hit some key...')
+print('lnL: %s and np: %s' % (fb.lnL, fb.np))
+eval(input ('hit some key...'))
-input ('finally have a look to two layouts available to display free-ratio:')
+eval(input ('finally have a look to two layouts available to display free-ratio:'))
tree.show()
# have to import layou
--- a/examples/evol/2_sites_model.py
+++ b/examples/evol/2_sites_model.py
@@ -24,14 +24,14 @@ try:
except NameError:
pass
-input ('\n tree and alignment loaded\n Hit some key, to start computation of site models M1 and M2.\n')
+eval(input ('\n tree and alignment loaded\n Hit some key, to start computation of site models M1 and M2.\n'))
print ('running model M1')
tree.run_model ('M1')
print ('running model M2')
tree.run_model ('M2')
-print ('\n\n comparison of models M1 and M2, p-value: ' + str(tree.get_most_likely ('M2','M1')))
+print('\n\n comparison of models M1 and M2, p-value: ' + str(tree.get_most_likely ('M2','M1')))
#tree.show()
@@ -73,8 +73,8 @@ tree.run_model ('M8a')
print ('running model M3')
tree.run_model ('M3')
-print ('\n\n comparison of models M7 and M8, p-value: ' + str(tree.get_most_likely ('M8','M7')))
-print ('\n\n comparison of models M8a and M8, p-value: ' + str(tree.get_most_likely ('M8','M8a')))
+print('\n\n comparison of models M7 and M8, p-value: ' + str(tree.get_most_likely ('M8','M7')))
+print('\n\n comparison of models M8a and M8, p-value: ' + str(tree.get_most_likely ('M8','M8a')))
print ('The End.')
--- a/examples/evol/3_branchsite_test.py
+++ b/examples/evol/3_branchsite_test.py
@@ -34,9 +34,9 @@ tree.run_model('M0')
for leaf in tree:
leaf.node_id
- print ('\n---------\nNow working with leaf ' + leaf.name)
+ print('\n---------\nNow working with leaf ' + leaf.name)
tree.mark_tree([leaf.node_id], marks=['#1'])
- print (tree.write())
+ print(tree.write())
# to organize a bit, we name model with the name of the marked node
# any character after the dot, in model name, is not taken into account
# for computation. (have a look in /tmp/ete3.../bsA.. directory)
@@ -46,9 +46,9 @@ for leaf in tree:
print ('p-value of positive selection for sites on this branch is: ')
ps = tree.get_most_likely('bsA.' + leaf.name, 'bsA1.'+ leaf.name)
rx = tree.get_most_likely('bsA1.'+ leaf.name, 'M0')
- print (str(ps))
+ print(str(ps))
print ('p-value of relaxation for sites on this branch is: ')
- print (str(rx))
+ print(str(rx))
model = tree.get_evol_model("bsA." + leaf.name)
if ps < 0.05 and float(model.classes['foreground w'][2]) > 1:
print ('we have positive selection on sites on this branch')
@@ -58,7 +58,7 @@ for leaf in tree:
else:
print ('no signal detected on this branch, best fit for M0')
print ('\nclean tree, remove marks')
- tree.mark_tree(map(lambda x: x.node_id, tree.get_descendants()),
+ tree.mark_tree([x.node_id for x in tree.get_descendants()],
marks=[''] * len(tree.get_descendants()), verbose=True)
# nothing working yet to get which sites are under positive selection/relaxation,
--- a/examples/evol/4_branch_models.py
+++ b/examples/evol/4_branch_models.py
@@ -28,12 +28,12 @@ tree.link_to_alignment ('data/S_example/
print (tree)
print ('Tree and alignment loaded.')
-input ('Tree will be mark in order to contrast Gorilla and Chimpanzee as foreground \nspecies.')
+eval(input ('Tree will be mark in order to contrast Gorilla and Chimpanzee as foreground \nspecies.'))
marks = ['1', '3', '7']
tree.mark_tree (marks, ['#1'] * 3)
-print (tree.write ())
+print(tree.write ())
print ('we can easily colorize marked branches')
# display marked branches in orange
@@ -57,13 +57,13 @@ tree.run_model ('b_neut.137')
print ('running M0 (all branches have the save value of omega)...')
tree.run_model ('M0')
-input ('''Now we can do comparisons...
+eval(input ('''Now we can do comparisons...
Compare first if we have one or 2 rates of evolution among phylogeny.
LRT between b_free and M0 (that is one or two rates of omega value)
-p-value ofthis comparison is:''')
-print (tree.get_most_likely ('b_free.137', 'M0'))
+p-value ofthis comparison is:'''))
+print(tree.get_most_likely ('b_free.137', 'M0'))
-input ('''
+eval(input ('''
Now test if foreground rate is significantly different of 1.
(b_free with significantly better likelihood than b_neut)
if significantly different, and higher than one, we will be under
@@ -71,17 +71,17 @@ positive selection, if different and low
negative selection. And finally if models are not significantly different
we should accept null hypothesis that omega value on marked branches is
equal to 1, what would be a signal of relaxation.
-p-value for difference in rates between marked branches and the rest:''')
-print (tree.get_most_likely ('b_free.137', 'M0'))
+p-value for difference in rates between marked branches and the rest:'''))
+print(tree.get_most_likely ('b_free.137', 'M0'))
print ('p-value representing significance that omega is different of 1:')
-print (tree.get_most_likely ('b_free.137', 'b_neut.137'))
+print(tree.get_most_likely ('b_free.137', 'b_neut.137'))
print ('value of omega in marked branch (frg branch):')
b_free = tree.get_evol_model ('b_free.137')
-print (b_free.branches[1]['w'])
+print(b_free.branches[1]['w'])
print ('and value of omega for background: ')
-print (b_free.branches[2]['w'])
+print(b_free.branches[2]['w'])
print ('we will now run 2 branch models over this tree, one letting the omega \nvalue of foreground species to be free, and the other fixing it at one.\n')
--- a/examples/evol/5_branchsite_cladetest.py
+++ b/examples/evol/5_branchsite_cladetest.py
@@ -26,12 +26,12 @@ tree.link_to_alignment ('data/S_example/
print (tree)
print ('Tree and alignment loaded.')
-input ('Tree will be mark in order to contrast Gorilla and Chimpanzee as foreground \nspecies.')
+eval(input ('Tree will be mark in order to contrast Gorilla and Chimpanzee as foreground \nspecies.'))
marks = ['1', 3, '7']
tree.mark_tree (marks, ['#1'] * 3)
-print (tree.write ())
+print(tree.write ())
# display marked branches in orange
for node in tree.traverse ():
@@ -65,7 +65,7 @@ tree.run_model ('M1')
print ('''p-value that, in marked clade, we have one class of site
specifically evolving at a different rate:''')
-print (tree.get_most_likely ('bsC.137', 'M1'))
+print(tree.get_most_likely ('bsC.137', 'M1'))
#print ('p-value representing significance that omega is different of 1:')
#print (tree.get_most_likely ('bsD.137', 'M3'))
--- a/examples/evol/measuring_evolution_trees.py
+++ b/examples/evol/measuring_evolution_trees.py
@@ -7,7 +7,7 @@ import sys, re
typ = None
while typ != 'L' and typ != 'S':
- typ = raw_input(\
+ typ = input(\
"choose kind of example [L]ong or [S]hort, hit [L] or [S]:\n").upper()
TREE_PATH = "data/%s_example/measuring_%s_tree.nw" % (typ, typ)
@@ -24,8 +24,8 @@ ALG_PATH = MY_PATH + re.sub('\./', '',
# load tree
-print '\n ----> we create a EvolTree object, and give to him a topology, from',
-print TREE_PATH
+print('\n ----> we create a EvolTree object, and give to him a topology, from\n')
+print(TREE_PATH)
out = True
while out == True:
try:
@@ -33,7 +33,7 @@ while out == True:
out = False
except:
sys.stderr.write('Bad path for working directory. Enter new path or quit("Q"):\n')
- PATH = raw_input('')
+ PATH = input('')
if PATH.startswith('q') or PATH.startswith('Q'):
sys.exit()
TREE_PATH = "./measuring_%s_tree.nw" % (typ)
@@ -42,62 +42,62 @@ while out == True:
ALG_PATH = PATH + re.sub('\./', '', ALG_PATH )
-print T
-print '\n ----> and an alignment from: \n'+ALG_PATH+'\n\n'
+print(T)
+print('\n ----> and an alignment from: \n'+ALG_PATH+'\n\n')
T.link_to_alignment(ALG_PATH)
-raw_input(" ====> hit some key to see the Tree with alignment")
+input(" ====> hit some key to see the Tree with alignment")
T.show()
###
# run free-branch model, and display result
-print '\n\n\n ----> We define now our working directory, that will be created:', \
- WORKING_PATH
+print('\n\n\n ----> We define now our working directory, that will be created:', \
+ WORKING_PATH)
T.workdir = (WORKING_PATH)
-print '\n ----> and run the free-branch model with run_model function:\n\n%s\n%s\n%s\n'\
- % ('*'*10 + ' doc ' + '*'*10, T.run_model.func_doc, '*'*30)
+print('\n ----> and run the free-branch model with run_model function:\n\n%s\n%s\n%s\n'\
+ % ('*'*10 + ' doc ' + '*'*10, T.run_model.__doc__, '*'*30))
-raw_input(" ====> Hit some key to start free-branch computation with codeml...\n")
+input(" ====> Hit some key to start free-branch computation with codeml...\n")
T.run_model('fb')
T.show()
###
# run site model, and display result
-print '\n\n\n ----> We are now goingn to run sites model M1 and M2 with run_model function:\n'
-raw_input(" ====> hit some key to start")
+print('\n\n\n ----> We are now goingn to run sites model M1 and M2 with run_model function:\n')
+input(" ====> hit some key to start")
for model in ['M1', 'M2']:
- print 'running model ' + model
+ print('running model ' + model)
T.run_model(model)
-print '\n\n\n ----> and use the get_most_likely function to compute the LRT between those models:\n'
-print 'get_most_likely function: \n\n'+ '*'*10 + ' doc ' + '*'*10
-print '\n' + T.get_most_likely.func_doc
-print '*'*30
+print('\n\n\n ----> and use the get_most_likely function to compute the LRT between those models:\n')
+print('get_most_likely function: \n\n'+ '*'*10 + ' doc ' + '*'*10)
+print('\n' + T.get_most_likely.__doc__)
+print('*'*30)
-raw_input("\n ====> Hit some key to launch LRT")
+input("\n ====> Hit some key to launch LRT")
pv = T.get_most_likely('M2', 'M1')
if pv <= 0.05:
- print ' ----> -> most likely model is model M2, there is positive selection, pval: ',pv
+ print(' ----> -> most likely model is model M2, there is positive selection, pval: ',pv)
else:
- print ' ----> -> most likely model is model M1, pval: ',pv
+ print(' ----> -> most likely model is model M1, pval: ',pv)
-raw_input(" ====> Hit some key...")
+input(" ====> Hit some key...")
###
# tengo que encontrar un ejemplo mas bonito pero bueno.... :P
-print '\n\n\n ----> We now add histograms to our tree to repesent site models with add_histface function: \n\n%s\n%s\n%s\n'\
- % ('*'*10 + ' doc ' + '*'*10, T.get_evol_model('M2').set_histface.func_doc,'*'*30)
-print 'Upper face is an histogram representing values of omega for each column in the alignment,'
-print '\
+print('\n\n\n ----> We now add histograms to our tree to repesent site models with add_histface function: \n\n%s\n%s\n%s\n'\
+ % ('*'*10 + ' doc ' + '*'*10, T.get_evol_model('M2').set_histface.__doc__,'*'*30))
+print('Upper face is an histogram representing values of omega for each column in the alignment,')
+print('\
Colors represent significantly conserved sites(cyan to blue), neutral sites(greens), or under \n\
positive selection(orange to red). \n\
Lower face also represents values of omega(red line) and bars represent the error of the estimation.\n\
Also significance of belonging to one class of site can be painted in background(here lightgrey for\n\
evrething significant)\n\
Both representation are done according to BEB estimation of M2, M1 or M7 estimation can also be \n\
-drawn but should not be used.\n'
-raw_input(" ====> Hit some key to display, histograms of omegas BEB from M2 model...")
+drawn but should not be used.\n')
+input(" ====> Hit some key to display, histograms of omegas BEB from M2 model...")
col = {'NS' : 'grey',
'RX' : 'grey',
@@ -118,12 +118,12 @@ T.show(histfaces = ['M1', 'M2'])
###
# re-run without reeeeeeeeee-run
-print '\n\n\n ----> Now we have runned once those 3 models, we can load again our tree from'
-print ' ----> our tree file and alignment file, and this time load directly oufiles from previous'
-print ' with the function link_to_evol_model \n\n%s\n%s\n%s\n' % ('*'*10 + ' doc ' + '*'*10, \
- T.link_to_evol_model.func_doc, \
- '*'*30)
-raw_input('runs\n ====> hit some key to see...')
+print('\n\n\n ----> Now we have runned once those 3 models, we can load again our tree from')
+print(' ----> our tree file and alignment file, and this time load directly oufiles from previous')
+print(' with the function link_to_evol_model \n\n%s\n%s\n%s\n' % ('*'*10 + ' doc ' + '*'*10, \
+ T.link_to_evol_model.__doc__, \
+ '*'*30))
+input('runs\n ====> hit some key to see...')
T = EvolTree(TREE_PATH)
T.link_to_alignment(ALG_PATH)
T.workdir = (WORKING_PATH)
@@ -141,41 +141,41 @@ T.show(histfaces = ['M1', 'M2'])
###
# mark tree functionality
-print T.write(format=10)
+print(T.write(format=10))
name = None
while name not in T.get_leaf_names():
- name = raw_input(' ====> As you need to mark some branches to run branch\n\
+ name = input(' ====> As you need to mark some branches to run branch\n\
models, type the name of one leaf: ')
idname = T.get_leaves_by_name(name)[0].node_id
-print ' ----> you want to mark:',name,'that has this idname: ', idname
+print(' ----> you want to mark:',name,'that has this idname: ', idname)
T.mark_tree([idname]) # by default will mark with '#1'
-print 'have a look to the mark: '
-print re.sub('#','|',re.sub('[0-9a-zA-Z_(),;]',' ',T.write(format=10)))
-print re.sub('#','v',re.sub('[0-9a-zA-Z_(),;]',' ',T.write(format=10)))
-print T.write(format=10)
-print '\n You have marked the tree with a command like: T.mark_tree([%d])\n' % (idname)
-print '\n%s\n%s\n%s\n' % ('*'*10 + ' doc ' + '*'*10, T.mark_tree.func_doc, \
- '*'*30)
+print('have a look to the mark: ')
+print(re.sub('#','|',re.sub('[0-9a-zA-Z_(),;]',' ',T.write(format=10))))
+print(re.sub('#','v',re.sub('[0-9a-zA-Z_(),;]',' ',T.write(format=10))))
+print(T.write(format=10))
+print('\n You have marked the tree with a command like: T.mark_tree([%d])\n' % (idname))
+print('\n%s\n%s\n%s\n' % ('*'*10 + ' doc ' + '*'*10, T.mark_tree.__doc__, \
+ '*'*30))
-print '\n\n\n ----> We are now going to run branch-site models bsA and bsA1:\n\n'
-raw_input(" ====> hit some key to start computation with our marked tree")
+print('\n\n\n ----> We are now going to run branch-site models bsA and bsA1:\n\n')
+input(" ====> hit some key to start computation with our marked tree")
for model in ['bsA','bsA1']:
- print 'running model ' + model
+ print('running model ' + model)
T.run_model(model)
-print '\n\n\n ----> again we use the get_most_likely function to compute the LRT between those models:\n'
-raw_input(" ====> Hit some key to launch LRT")
+print('\n\n\n ----> again we use the get_most_likely function to compute the LRT between those models:\n')
+input(" ====> Hit some key to launch LRT")
pv = T.get_most_likely('bsA', 'bsA1')
if pv <= 0.05:
- print ' ----> -> most likely model is model bsA, there is positive selection, pval: ',pv
- print ' ' + name + ' is under positive selection.'
+ print(' ----> -> most likely model is model bsA, there is positive selection, pval: ',pv)
+ print(' ' + name + ' is under positive selection.')
else:
- print ' ----> -> most likely model is model bsA1, pval of LRT: ',pv
- print ' ' + name + ' is not under positive selection.'
+ print(' ----> -> most likely model is model bsA1, pval of LRT: ',pv)
+ print(' ' + name + ' is not under positive selection.')
sys.stderr.write('\n\nThe End.\n\n')
--- a/examples/evol/test_protamine.py
+++ b/examples/evol/test_protamine.py
@@ -30,15 +30,15 @@ def main():
tree.link_to_evol_model (WRKDIR + 'paml/M7/M7.out', 'M7')
tree.link_to_evol_model (WRKDIR + 'paml/M8/M8.out', 'M8')
tree.link_to_alignment (WRKDIR + 'alignments.fasta_ali')
- print 'pv of LRT M2 vs M1: ',
- print tree.get_most_likely ('M2','M1')
- print 'pv of LRT M8 vs M7: ',
- print tree.get_most_likely ('M8','M7')
+ print('pv of LRT M2 vs M1: \n')
+ print(tree.get_most_likely ('M2','M1'))
+ print('pv of LRT M8 vs M7: \n')
+ print(tree.get_most_likely ('M8','M7'))
tree.show (histfaces=['M2'])
- print 'The End.'
+ print('The End.')
def random_swap(tree):
@@ -49,9 +49,9 @@ def random_swap(tree):
def check_annotation (tree):
for node in tree.iter_descendants():
if not hasattr (node, 'paml_id'):
- print 'Error, unable to label with paml ids'
+ print('Error, unable to label with paml ids')
break
- print 'Labelling ok!'
+ print('Labelling ok!')
if __name__ == "__main__":
--- a/examples/general/add_features.py
+++ b/examples/general/add_features.py
@@ -2,7 +2,7 @@ import random
from ete3 import Tree
# Creates a normal tree
t = Tree( '((H:0.3,I:0.1):0.5, A:1, (B:0.4,(C:0.5,(J:1.3, (F:1.2, D:0.1):0.5):0.5):0.5):0.5);' )
-print t
+print(t)
# Let's locate some nodes using the get common ancestor method
ancestor=t.get_common_ancestor("J", "F", "C")
# the search_nodes method (I take only the first match )
@@ -26,8 +26,8 @@ for leaf in t.traverse():
else:
leaf.add_features(vowel=False, confidence=random.random())
# Now we use these information to analyze the tree.
-print "This tree has", len(t.search_nodes(vowel=True)), "vowel nodes"
-print "Which are", [leaf.name for leaf in t.iter_leaves() if leaf.vowel==True]
+print("This tree has", len(t.search_nodes(vowel=True)), "vowel nodes")
+print("Which are", [leaf.name for leaf in t.iter_leaves() if leaf.vowel==True])
# But features may refer to any kind of data, not only simple
# values. For example, we can calculate some values and store them
# within nodes.
@@ -38,10 +38,10 @@ matches = [leaf for leaf in ancestor.tra
# And save this pre-computed information into the ancestor node
ancestor.add_feature("long_branch_nodes", matches)
# Prints the precomputed nodes
-print "These are nodes under ancestor with long branches", \
- [n.name for n in ancestor.long_branch_nodes]
+print("These are nodes under ancestor with long branches", \
+ [n.name for n in ancestor.long_branch_nodes])
# We can also use the add_feature() method to dynamically add new features.
-label = raw_input("custom label:")
-value = raw_input("custom label value:")
+label = input("custom label:")
+value = input("custom label value:")
ancestor.add_feature(label, value)
-print "Ancestor has now the [", label, "] attribute with value [", value, "]"
+print("Ancestor has now the [", label, "] attribute with value [", value, "]")
--- a/examples/general/byoperand_search.py
+++ b/examples/general/byoperand_search.py
@@ -8,14 +8,14 @@ path = []
while node.up:
path.append(node)
node = node.up
-print t
+print(t)
# I substract D node from the total number of visited nodes
-print "There are", len(path)-1, "nodes between D and the root"
+print("There are", len(path)-1, "nodes between D and the root")
# Using parentheses you can use by-operand search syntax as a node
# instance itself
Dsparent= (t&"C").up
Bsparent= (t&"B").up
Jsparent= (t&"J").up
# I check if nodes belong to certain partitions
-print "It is", Dsparent in Bsparent, "that C's parent is under B's ancestor"
-print "It is", Dsparent in Jsparent, "that C's parent is under J's ancestor"
+print("It is", Dsparent in Bsparent, "that C's parent is under B's ancestor")
+print("It is", Dsparent in Jsparent, "that C's parent is under J's ancestor")
--- a/examples/general/copy_and_paste_trees.py
+++ b/examples/general/copy_and_paste_trees.py
@@ -3,13 +3,13 @@ from ete3 import Tree
t1 = Tree('(A,(B,C));')
t2 = Tree('((D,E), (F,G));')
t3 = Tree('(H, ((I,J), (K,L)));')
-print "Tree1:", t1
+print("Tree1:", t1)
# /-A
# ---------|
# | /-B
# \--------|
# \-C
-print "Tree2:", t2
+print("Tree2:", t2)
# /-D
# /--------|
# | \-E
@@ -17,7 +17,7 @@ print "Tree2:", t2
# | /-F
# \--------|
# \-G
-print "Tree3:", t3
+print("Tree3:", t3)
# /-H
# |
# ---------| /-I
@@ -32,7 +32,7 @@ A = t1.search_nodes(name='A')[0]
# and adds the two other trees as children.
A.add_child(t2)
A.add_child(t3)
-print "Resulting concatenated tree:", t1
+print("Resulting concatenated tree:", t1)
# /-D
# /--------|
# | \-E
--- a/examples/general/create_trees_from_scratch.py
+++ b/examples/general/create_trees_from_scratch.py
@@ -15,7 +15,7 @@ R = A.add_child(name="R") # Adds a third
# randomly.
R.populate(6, names_library=["r1","r2","r3","r4","r5","r6"])
# Prints the tree topology
-print t
+print(t)
# /-C
# |
# |--D
--- a/examples/general/custom_search.py
+++ b/examples/general/custom_search.py
@@ -10,9 +10,9 @@ def conditional_function(node):
# method in the filter function. This will iterate over all nodes to
# assess if they meet our custom conditions and will return a list of
# matches.
-matches = filter(conditional_function, t.traverse())
-print len(matches), "nodes have distance >0.3"
+matches = list(filter(conditional_function, t.traverse()))
+print(len(matches), "nodes have distance >0.3")
# depending on the complexity of your conditions you can do the same
# in just one line with the help of lambda functions:
-matches = filter(lambda n: n.dist>0.3 and n.is_leaf(), t.traverse() )
-print len(matches), "nodes have distance >0.3 and are leaves"
+matches = [n for n in t.traverse() if n.dist>0.3 and n.is_leaf()]
+print(len(matches), "nodes have distance >0.3 and are leaves")
--- a/examples/general/custom_tree_traversing.py
+++ b/examples/general/custom_tree_traversing.py
@@ -3,7 +3,7 @@ t = Tree( '(A:1,(B:1,(C:1,D:1):0.5):0.5)
# Browse the tree from a specific leaf to the root
node = t.search_nodes(name="C")[0]
while node:
- print node
+ print(node)
node = node.up
# --C
# /-C
--- a/examples/general/get_common_ancestor.py
+++ b/examples/general/get_common_ancestor.py
@@ -1,8 +1,8 @@
from ete3 import Tree
#Loads a tree
tree = Tree( '((H:1,I:1):0.5, A:1, (B:1,(C:1,D:1):0.5):0.5);' )
-print "this is the original tree:"
-print tree
+print("this is the original tree:")
+print(tree)
# /-H
# /--------|
# | \-I
@@ -16,15 +16,15 @@ print tree
# \-D
# Finds the first common ancestor between B and C.
ancestor = tree.get_common_ancestor("D", "C")
-print "The ancestor of C and D is:"
-print ancestor
+print("The ancestor of C and D is:")
+print(ancestor)
# /-C
#---------|
# \-D
# You can use more than two nodes in the search
ancestor = tree.get_common_ancestor("B", "C", "D")
-print "The ancestor of B, C and D is:"
-print ancestor
+print("The ancestor of B, C and D is:")
+print(ancestor)
# /-B
#---------|
# | /-C
@@ -33,9 +33,9 @@ print ancestor
# Finds the first sister branch of the ancestor node. Because
# multifurcations are allowed, many sister branches are possible.
sisters = ancestor.get_sisters()
-print "which has has", len(sisters), "sister nodes"
-print "and the first of such sister nodes like this:"
-print sisters[0]
+print("which has has", len(sisters), "sister nodes")
+print("and the first of such sister nodes like this:")
+print(sisters[0])
#
# /-H
#---------|
--- a/examples/general/get_distances_between_nodes.py
+++ b/examples/general/get_distances_between_nodes.py
@@ -7,7 +7,7 @@ nw = """(((A:0.1, B:0.01):0.001, C:0.000
(((((D:0.00001,I:0):0,F:0):0,G:0):0,H:0):0,
E:0.000001):0.0000001):2.0;"""
t = Tree(nw)
-print t
+print(t)
# /-A
# /--------|
# /--------| \-B
@@ -30,24 +30,24 @@ print t
A = t&"A"
C = t&"C"
# Calculate distance from current node
-print "The distance between A and C is", A.get_distance("C")
+print("The distance between A and C is", A.get_distance("C"))
# Calculate distance between two descendants of current node
-print "The distance between A and C is", t.get_distance("A","C")
+print("The distance between A and C is", t.get_distance("A","C"))
# Calculate the toplogical distance (number of nodes in between)
-print "The number of nodes between A and D is ", \
- t.get_distance("A","D", topology_only=True)
+print("The number of nodes between A and D is ", \
+ t.get_distance("A","D", topology_only=True))
# Calculate the farthest node from E within the whole structure
farthest, dist = (t&"E").get_farthest_node()
-print "The farthest node from E is", farthest.name, "with dist=", dist
+print("The farthest node from E is", farthest.name, "with dist=", dist)
# Calculate the farthest node from E within the whole structure,
# regarding the number of nodes in between as distance value
# Note that the result is differnt.
farthest, dist = (t&"E").get_farthest_node(topology_only=True)
-print "The farthest (topologically) node from E is", \
- farthest.name, "with", dist, "nodes in between"
+print("The farthest (topologically) node from E is", \
+ farthest.name, "with", dist, "nodes in between")
# Calculate farthest node from an internal node
farthest, dist = t.get_farthest_node()
-print "The farthest node from root is", farthest.name, "with dist=", dist
+print("The farthest node from root is", farthest.name, "with dist=", dist)
#
# The program results in the following information:
#
--- a/examples/general/get_midpoint_outgroup.py
+++ b/examples/general/get_midpoint_outgroup.py
@@ -2,7 +2,7 @@ from ete3 import Tree
# generates a random tree
t = Tree();
t.populate(15);
-print t
+print(t)
#
#
# /-qogjl
@@ -38,7 +38,7 @@ print t
R = t.get_midpoint_outgroup()
# and set it as tree outgroup
t.set_outgroup(R)
-print t
+print(t)
# /-opben
# |
# /--------| /-xoryn
--- a/examples/general/getting_leaves.py
+++ b/examples/general/getting_leaves.py
@@ -1,7 +1,7 @@
from ete3 import Tree
# Loads a basic tree
t = Tree( '(A:0.2,(B:0.4,(C:1.1,D:0.45):0.5):0.1);' )
-print t
+print(t)
# /-A
#---------|
# | /-B
@@ -13,16 +13,16 @@ print t
nleaves = 0
for leaf in t.get_leaves():
nleaves += 1
-print "This tree has", nleaves, "terminal nodes"
+print("This tree has", nleaves, "terminal nodes")
# But, like this is much simpler :)
nleaves = len(t)
-print "This tree has", nleaves, "terminal nodes [proper way: len(tree) ]"
+print("This tree has", nleaves, "terminal nodes [proper way: len(tree) ]")
# Counts leaves within the tree
ninternal = 0
for node in t.get_descendants():
if not node.is_leaf():
ninternal +=1
-print "This tree has", ninternal, "internal nodes"
+print("This tree has", ninternal, "internal nodes")
# Counts nodes with whose distance is higher than 0.3
nnodes = 0
for node in t.get_descendants():
@@ -30,4 +30,4 @@ for node in t.get_descendants():
nnodes +=1
# or, translated into a better pythonic
nnodes = len([n for n in t.get_descendants() if n.dist>0.3])
-print "This tree has", nnodes, "nodes with a branch length > 0.3"
+print("This tree has", nnodes, "nodes with a branch length > 0.3")
--- a/examples/general/iterators.py
+++ b/examples/general/iterators.py
@@ -7,16 +7,16 @@ tree.populate(10000)
t1 = time.time()
for leaf in tree.iter_leaves():
if "aw" in leaf.name:
- print "found a match:", leaf.name,
+ print("found a match:", leaf.name, '\n')
break
-print "Iterating: ellapsed time:", time.time()-t1
+print("Iterating: ellapsed time:", time.time()-t1)
# This slower
t1 = time.time()
for leaf in tree.get_leaves():
if "aw" in leaf.name:
- print "found a match:", leaf.name,
+ print("found a match:", leaf.name, '\n')
break
-print "Getting: ellapsed time:", time.time()-t1
+print("Getting: ellapsed time:", time.time()-t1)
# Results in something like:
# found a match: guoaw Iterating: ellapsed time: 0.00436091423035 secs
# found a match: guoaw Getting: ellapsed time: 0.124316930771 secs
--- a/examples/general/label_nodes.py
+++ b/examples/general/label_nodes.py
@@ -1,16 +1,16 @@
from ete3 import Tree
tree = Tree( '(A:1,(B:1,(C:1,D:1):0.5):0.5);' )
# Prints the name of every leaf under the tree root
-print "Leaf names:"
+print("Leaf names:")
for leaf in tree.get_leaves():
- print leaf.name
+ print(leaf.name)
# Label nodes as terminal or internal. If internal, saves also the
# number of leaves that it contains.
-print "Labeled tree:"
+print("Labeled tree:")
for node in tree.get_descendants():
if node.is_leaf():
node.add_features(ntype="terminal")
else:
node.add_features(ntype="internal", size=len(node))
# Gets the extended newick of the tree including new node features
-print tree.write(features=[])
+print(tree.write(features=[]))
--- a/examples/general/nhx_format.py
+++ b/examples/general/nhx_format.py
@@ -2,7 +2,7 @@ import random
from ete3 import Tree
# Creates a normal tree
t = Tree('((H:0.3,I:0.1):0.5, A:1,(B:0.4,(C:0.5,(J:1.3,(F:1.2, D:0.1):0.5):0.5):0.5):0.5);')
-print t
+print(t)
# Let's locate some nodes using the get common ancestor method
ancestor=t.get_common_ancestor("J", "F", "C")
# Let's label leaf nodes
@@ -16,21 +16,21 @@ for leaf in t.traverse():
matches = [leaf for leaf in ancestor.traverse() if leaf.dist>1.0]
# And save this pre-computed information into the ancestor node
ancestor.add_feature("long_branch_nodes", matches)
-print
-print "NHX notation including vowel and confidence attributes"
-print
-print t.write(features=["vowel", "confidence"])
-print
-print "NHX notation including all node's data"
-print
+print()
+print("NHX notation including vowel and confidence attributes")
+print()
+print(t.write(features=["vowel", "confidence"]))
+print()
+print("NHX notation including all node's data")
+print()
# Note that when all features are requested, only those with values
# equal to text-strings or numbers are considered. "long_branch_nodes"
# is not included into the newick string.
-print t.write(features=[])
-print
-print "basic newick formats are still available"
-print
-print t.write(format=9, features=["vowel"])
+print(t.write(features=[]))
+print()
+print("basic newick formats are still available")
+print()
+print(t.write(format=9, features=["vowel"]))
# You don't need to do anything speciall to read NHX notation. Just
# specify the newick format and the NHX tags will be automatically
# detected.
@@ -46,4 +46,4 @@ t = Tree(nw)
# And access node's attributes.
for n in t.traverse():
if hasattr(n,"S"):
- print n.name, n.S
+ print(n.name, n.S)
--- a/examples/general/prune_tree.py
+++ b/examples/general/prune_tree.py
@@ -1,8 +1,8 @@
from ete3 import Tree
# Let's create simple tree
t = Tree('((((H,K),(F,I)G),E),((L,(N,Q)O),(P,S)));', format=1)
-print "Original tree looks like this:"
-print t
+print("Original tree looks like this:")
+print(t)
#
# /-H
# /--------|
@@ -25,8 +25,8 @@ print t
# \-S
# Prune the tree in order to keep only some leaf nodes.
t.prune(["H","F","E","Q", "P"])
-print "Pruned tree"
-print t
+print("Pruned tree")
+print(t)
#
# /-F
# /--------|
--- a/examples/general/remove_and_delete_nodes.py
+++ b/examples/general/remove_and_delete_nodes.py
@@ -1,11 +1,11 @@
from ete3 import Tree
# Loads a tree. Note that we use format 1 to read internal node names
t = Tree('((((H,K)D,(F,I)G)B,E)A,((L,(N,Q)O)J,(P,S)M)C);', format=1)
-print "original tree looks like this:"
+print("original tree looks like this:")
# This is an alternative way of using "print t". Thus we have a bit
# more of control on how tree is printed. Here i print the tree
# showing internal node names
-print t.get_ascii(show_internal=True)
+print(t.get_ascii(show_internal=True))
#
# /-H
# /D-------|
@@ -37,8 +37,8 @@ C = t.search_nodes(name="C")[0]
removed_node = J.detach() # = C.remove_child(J)
# if we know print the original tree, we will see how J partition is
# no longer there.
-print "Tree after REMOVING the node J"
-print t.get_ascii(show_internal=True)
+print("Tree after REMOVING the node J")
+print(t.get_ascii(show_internal=True))
# /-H
# /D-------|
# | \-K
@@ -56,8 +56,8 @@ print t.get_ascii(show_internal=True)
# tree, and all its descendants will then hang from the next upper
# node.
G.delete()
-print "Tree after DELETING the node G"
-print t.get_ascii(show_internal=True)
+print("Tree after DELETING the node G")
+print(t.get_ascii(show_internal=True))
# /-H
# /D-------|
# | \-K
--- a/examples/general/rooting_subtrees.py
+++ b/examples/general/rooting_subtrees.py
@@ -1,7 +1,7 @@
from ete3 import Tree
t = Tree('(((A,C),((H,F),(L,M))),((B,(J,K)),(E,D)));')
-print "Original tree:"
-print t
+print("Original tree:")
+print(t)
# /-A
# /--------|
# | \-C
@@ -29,8 +29,8 @@ node1 = t.get_common_ancestor("A","H")
node2 = t.get_common_ancestor("B","D")
node1.set_outgroup("H")
node2.set_outgroup("E")
-print "Tree after rooting each node independently:"
-print t
+print("Tree after rooting each node independently:")
+print(t)
#
# /-F
# |
--- a/examples/general/rooting_trees.py
+++ b/examples/general/rooting_trees.py
@@ -3,8 +3,8 @@ from ete3 import Tree
# node. This usually means that no information is available about
# which of nodes is more basal.
t = Tree('(A,(H,F),(B,(E,D)));')
-print "Unrooted tree"
-print t
+print("Unrooted tree")
+print(t)
# /-A
# |
# | /-H
@@ -21,8 +21,8 @@ print t
# course, the definition of an outgroup will depend on user criteria.
ancestor = t.get_common_ancestor("E","D")
t.set_outgroup(ancestor)
-print "Tree rooted at E and D's ancestor is more basal that the others."
-print t
+print("Tree rooted at E and D's ancestor is more basal that the others.")
+print(t)
#
# /-B
# /--------|
@@ -39,8 +39,8 @@ print t
# Note that setting a different outgroup, a different interpretation
# of the tree is possible
t.set_outgroup( t&"A" )
-print "Tree rooted at a terminal node"
-print t
+print("Tree rooted at a terminal node")
+print(t)
# /-H
# /--------|
# | \-F
--- a/examples/general/search_nodes.py
+++ b/examples/general/search_nodes.py
@@ -1,7 +1,7 @@
from ete3 import Tree
#Loads a tree
t = Tree( '((H:1,I:1):0.5, A:1, (B:1,(C:1,D:1):0.5):0.5);' )
-print t
+print(t)
# /-H
# /--------|
# | \-I
@@ -17,4 +17,4 @@ print t
D = t.search_nodes(name="D")
# I get all nodes with distance=0.5
nodes = t.search_nodes(dist=0.5)
-print len(nodes), "nodes have distance=0.5"
+print(len(nodes), "nodes have distance=0.5")
--- a/examples/general/tree_basis.py
+++ b/examples/general/tree_basis.py
@@ -6,16 +6,16 @@ A = t.add_child(name="A")
B = t.add_child(name="B")
C = A.add_child(name="C")
D = A.add_child(name="D")
-print t
+print(t)
# /-C
# /--------|
#---------| \-D
# |
# \-B
-print 'is "t" the root?', t.is_root() # True
-print 'is "A" a terminal node?', A.is_leaf() # False
-print 'is "B" a terminal node?', B.is_leaf() # True
-print 'B.get_tree_root() is "t"?', B.get_tree_root() is t # True
-print 'Number of leaves in tree:', len(t) # returns number of leaves under node (3)
-print 'is C in tree?', C in t # Returns true
-print "All leaf names in tree:", [node.name for node in t]
+print('is "t" the root?', t.is_root()) # True
+print('is "A" a terminal node?', A.is_leaf()) # False
+print('is "B" a terminal node?', B.is_leaf()) # True
+print('B.get_tree_root() is "t"?', B.get_tree_root() is t) # True
+print('Number of leaves in tree:', len(t)) # returns number of leaves under node (3)
+print('is C in tree?', C in t) # Returns true
+print("All leaf names in tree:", [node.name for node in t])
--- a/examples/general/tree_traverse.py
+++ b/examples/general/tree_traverse.py
@@ -2,7 +2,7 @@ from ete3 import Tree
t = Tree( '(A:1,(B:1,(C:1,D:1):0.5):0.5);' )
# Visit nodes in preorder (this is the default strategy)
for n in t.traverse():
- print n
+ print(n)
# It Will visit the nodes in the following order:
# /-A
# ---------|
@@ -25,7 +25,7 @@ for n in t.traverse():
# --D
# Visit nodes in postorder
for n in t.traverse("postorder"):
- print n
+ print(n)
# It Will visit the nodes in the following order:
# --A
# --B
--- a/examples/general/write_newick.py
+++ b/examples/general/write_newick.py
@@ -3,6 +3,6 @@ from ete3 import Tree
t = Tree('(A:1,(B:1,(E:1,D:1)Internal_1:0.5)Internal_2:0.5)Root;', format=1)
# And prints its newick representation omiting all the information but
# the tree topology
-print t.write(format=100) # (,(,(,)));
+print(t.write(format=100)) # (,(,(,)));
# We can also write into a file
t.write(format=100, outfile="/tmp/tree.new")
--- a/examples/nexml/nexml_annotated_trees.py
+++ b/examples/nexml/nexml_annotated_trees.py
@@ -13,12 +13,12 @@ trees = tree_collection.tree
# For each loaded tree, prints its structure and some of its
# meta-properties
for t in trees:
- print t
- print
- print "Leaf node meta information:\n"
- print
+ print(t)
+ print()
+ print("Leaf node meta information:\n")
+ print()
for meta in t.children[0].nexml_node.meta:
- print meta.property, ":", (meta.content)
+ print(meta.property, ":", (meta.content))
# Output
--- a/examples/nexml/nexml_parser.py
+++ b/examples/nexml/nexml_parser.py
@@ -7,10 +7,10 @@ nexml_project.build_from_file("trees.xml
# All XML elements are within the project instance.
# exist in each element to access their attributes.
-print "Loaded Taxa:"
+print("Loaded Taxa:")
for taxa in nexml_project.get_otus():
for otu in taxa.get_otu():
- print "OTU:", otu.id
+ print("OTU:", otu.id)
# Extracts all the collection of trees in the project
tree_collections = nexml_project.get_trees()
@@ -21,10 +21,10 @@ collection_1 = tree_collections[0]
for tree in collection_1.get_tree():
# trees contain all the nexml information in their "nexml_node",
# "nexml_tree", and "nexml_edge" attributes.
- print "Tree id", tree.nexml_tree.id
- print tree
+ print("Tree id", tree.nexml_tree.id)
+ print(tree)
for node in tree.traverse():
- print "node", node.nexml_node.id, "is associated with", node.nexml_node.otu, "OTU"
+ print("node", node.nexml_node.id, "is associated with", node.nexml_node.otu, "OTU")
# Output:
--- a/examples/phylogenies/dating_evolutionary_events.py
+++ b/examples/phylogenies/dating_evolutionary_events.py
@@ -8,8 +8,8 @@ nw = """
,Mmu_001),((Hsa_004,Ptr_004),Mmu_004))),(Ptr_002,(Hsa_002,Mmu_002))));
"""
t = PhyloTree(nw)
-print "Original tree:",
-print t
+print("Original tree:\n")
+print(t)
#
# /-Dme_001
# /--------|
@@ -59,11 +59,11 @@ age2name = {
}
event1= t.get_common_ancestor("Hsa_001", "Hsa_004")
event2=t.get_common_ancestor("Hsa_001", "Hsa_002")
-print
-print "The duplication event leading to the human sequences Hsa_001 and "+\
- "Hsa_004 is dated at: ", age2name[event1.get_age(species2age)]
-print "The duplication event leading to the human sequences Hsa_001 and "+\
- "Hsa_002 is dated at: ", age2name[event2.get_age(species2age)]
+print()
+print("The duplication event leading to the human sequences Hsa_001 and "+\
+ "Hsa_004 is dated at: ", age2name[event1.get_age(species2age)])
+print("The duplication event leading to the human sequences Hsa_001 and "+\
+ "Hsa_002 is dated at: ", age2name[event2.get_age(species2age)])
# The duplication event leading to the human sequences Hsa_001 and Hsa_004
# is dated at: primates
#
--- a/examples/phylogenies/link_sequences_to_phylogenies.py
+++ b/examples/phylogenies/link_sequences_to_phylogenies.py
@@ -25,9 +25,9 @@ iphylip_txt = """
t = PhyloTree("(((seqA,seqB),seqC),seqD);", alignment=fasta_txt, alg_format="fasta")
#We can now access the sequence of every leaf node
-print "These are the nodes and its sequences:"
+print("These are the nodes and its sequences:")
for leaf in t.iter_leaves():
- print leaf.name, leaf.sequence
+ print(leaf.name, leaf.sequence)
#seqD MAEAPDETIQQFMALTNVSHNIAVQYLSEFGDLNEAL--------------REEAH
#seqC MAEIPDATIQ---ALTNVSHNIAVQYLSEFGDLNEALNSYYASQTDDQPDRREEAH
#seqA MAEIPDETIQQFMALT---HNIAVQYLSEFGDLNEALNSYYASQTDDIKDRREEAH
@@ -36,9 +36,9 @@ for leaf in t.iter_leaves():
# The associated alignment can be changed at any time
t.link_to_alignment(alignment=iphylip_txt, alg_format="iphylip")
# Let's check that sequences have changed
-print "These are the nodes and its re-linked sequences:"
+print("These are the nodes and its re-linked sequences:")
for leaf in t.iter_leaves():
- print leaf.name, leaf.sequence
+ print(leaf.name, leaf.sequence)
#seqD MAEAPDETIQQFMALTNVSHNIAVQYLSEFGDLNEAL--------------REEAHQ----------FMALTNVSH
#seqC MAEIPDATIQ---ALTNVSHNIAVQYLSEFGDLNEALNSYYASQTDDQPDRREEAHQFMALTNVSH----------
#seqA MAEIPDETIQQFMALT---HNIAVQYLSEFGDLNEALNSYYASQTDDIKDRREEAHQFMALTNVSHQFMALTNVSH
@@ -46,7 +46,7 @@ for leaf in t.iter_leaves():
#
# The sequence attribute is considered as node feature, so you can
# even include sequences in your extended newick format!
-print t.write(features=["sequence"], format=9)
+print(t.write(features=["sequence"], format=9))
#
#
# (((seqA[&&NHX:sequence=MAEIPDETIQQFMALT---HNIAVQYLSEFGDLNEALNSYYASQTDDIKDRREEAHQF
@@ -57,8 +57,8 @@ print t.write(features=["sequence"], for
#
# And yes, you can save this newick text and reload it into a PhyloTree instance.
sametree = PhyloTree(t.write(features=["sequence"]))
-print "Recovered tree with sequence features:"
-print sametree
+print("Recovered tree with sequence features:")
+print(sametree)
#
# /-seqA
# /--------|
@@ -68,5 +68,5 @@ print sametree
# |
# \-seqD
#
-print "seqA sequence:", (t&"seqA").sequence
+print("seqA sequence:", (t&"seqA").sequence)
# MAEIPDETIQQFMALT---HNIAVQYLSEFGDLNEALNSYYASQTDDIKDRREEAHQFMALTNVSHQFMALTNVSH
--- a/examples/phylogenies/orthology_and_paralogy_prediction.py
+++ b/examples/phylogenies/orthology_and_paralogy_prediction.py
@@ -5,7 +5,7 @@ nw = """
(Ptr_002,(Hsa_002,Mmu_002))));
"""
t = PhyloTree(nw)
-print t
+print(t)
# /-Dme_001
# /--------|
# | \-Dme_002
@@ -33,22 +33,22 @@ human_seq = matches[0]
# Obtains its evolutionary events
events = human_seq.get_my_evol_events()
# Print its orthology and paralogy relationships
-print "Events detected that involve Hsa_001:"
+print("Events detected that involve Hsa_001:")
for ev in events:
if ev.etype == "S":
- print ' ORTHOLOGY RELATIONSHIP:', ','.join(ev.in_seqs), "<====>", ','.join(ev.out_seqs)
+ print(' ORTHOLOGY RELATIONSHIP:', ','.join(ev.in_seqs), "<====>", ','.join(ev.out_seqs))
elif ev.etype == "D":
- print ' PARALOGY RELATIONSHIP:', ','.join(ev.in_seqs), "<====>", ','.join(ev.out_seqs)
+ print(' PARALOGY RELATIONSHIP:', ','.join(ev.in_seqs), "<====>", ','.join(ev.out_seqs))
# Alternatively, you can scan the whole tree topology
events = t.get_descendant_evol_events()
# Print its orthology and paralogy relationships
-print "Events detected from the root of the tree"
+print("Events detected from the root of the tree")
for ev in events:
if ev.etype == "S":
- print ' ORTHOLOGY RELATIONSHIP:', ','.join(ev.in_seqs), "<====>", ','.join(ev.out_seqs)
+ print(' ORTHOLOGY RELATIONSHIP:', ','.join(ev.in_seqs), "<====>", ','.join(ev.out_seqs))
elif ev.etype == "D":
- print ' PARALOGY RELATIONSHIP:', ','.join(ev.in_seqs), "<====>", ','.join(ev.out_seqs)
+ print(' PARALOGY RELATIONSHIP:', ','.join(ev.in_seqs), "<====>", ','.join(ev.out_seqs))
# If we are only interested in the orthology and paralogy relationship
# among a given set of species, we can filter the list of sequences
@@ -56,16 +56,16 @@ for ev in events:
# fseqs is a function that, given a list of sequences, returns only
# those from human and mouse
fseqs = lambda slist: [s for s in slist if s.startswith("Hsa") or s.startswith("Mms")]
-print "Paralogy relationships among human and mouse"
+print("Paralogy relationships among human and mouse")
for ev in events:
if ev.etype == "D":
# Prints paralogy relationships considering only human and
# mouse. Some duplication event may not involve such species,
# so they will be empty
- print ' PARALOGY RELATIONSHIP:', \
+ print(' PARALOGY RELATIONSHIP:', \
','.join(fseqs(ev.in_seqs)), \
"<====>",\
- ','.join(fseqs(ev.out_seqs))
+ ','.join(fseqs(ev.out_seqs)))
# Note that besides the list of events returned, the detection
# algorithm has labeled the tree nodes according with the
--- a/examples/phylogenies/species_aware_phylogenies.py
+++ b/examples/phylogenies/species_aware_phylogenies.py
@@ -14,9 +14,9 @@ t = PhyloTree("(((Hsa_001,Ptr_001),(Cfa_
# \-Dme_002
#
# Prints current leaf names and species codes
-print "Deafult mode:"
+print("Deafult mode:")
for n in t.get_leaves():
- print "node:", n.name, "Species name:", n.species
+ print("node:", n.name, "Species name:", n.species)
# node: Dme_001 Species name: Dme
# node: Dme_002 Species name: Dme
# node: Hsa_001 Species name: Hsa
@@ -42,9 +42,9 @@ def get_species_name(node_name_string):
return code2name[spcode]
# Now, let's ask the tree to use our custom species naming function
t.set_species_naming_function(get_species_name)
-print "Custom mode:"
+print("Custom mode:")
for n in t.get_leaves():
- print "node:", n.name, "Species name:", n.species
+ print("node:", n.name, "Species name:", n.species)
# node: Dme_001 Species name: Drosophila melanogaster
# node: Dme_002 Species name: Drosophila melanogaster
# node: Hsa_001 Species name: Homo sapiens
@@ -63,9 +63,9 @@ mynewick = """
(Dme_001[&&NHX:species=Fly],Dme_002[&&NHX:species=Fly]));
"""
t = PhyloTree(mynewick, sp_naming_function=None)
-print "Disabled mode (manual set):"
+print("Disabled mode (manual set):")
for n in t.get_leaves():
- print "node:", n.name, "Species name:", n.species
+ print("node:", n.name, "Species name:", n.species)
# node: Dme_001 Species name: Fly
# node: Dme_002 Species name: Fly
# node: Hsa_001 Species name: Human
@@ -76,8 +76,8 @@ for n in t.get_leaves():
# Of course, once this info is available you can query any internal
# node for species covered.
human_mouse_ancestor = t.get_common_ancestor("Hsa_001", "Mms_001")
-print "These are the species under the common ancestor of Human & Mouse"
-print '\n'.join( human_mouse_ancestor.get_species() )
+print("These are the species under the common ancestor of Human & Mouse")
+print('\n'.join( human_mouse_ancestor.get_species() ))
# Mouse
# Chimp
# Dog
--- a/examples/phylogenies/tree_reconciliation.py
+++ b/examples/phylogenies/tree_reconciliation.py
@@ -7,7 +7,7 @@ gene_tree_nw = '((Dme_001,Dme_002),(((Cf
species_tree_nw = "((((Hsa, Ptr), Mmu), (Mms, Cfa)), Dme);"
genetree = PhyloTree(gene_tree_nw)
sptree = PhyloTree(species_tree_nw)
-print genetree
+print(genetree)
# /-Dme_001
# /--------|
# | \-Dme_002
@@ -32,14 +32,14 @@ print genetree
recon_tree, events = genetree.reconcile(sptree)
# a new "reconcilied tree" is returned. As well as the list of
# inferred events.
-print "Orthology and Paralogy relationships:"
+print("Orthology and Paralogy relationships:")
for ev in events:
if ev.etype == "S":
- print 'ORTHOLOGY RELATIONSHIP:', ','.join(ev.inparalogs), "<====>", ','.join(ev.orthologs)
+ print('ORTHOLOGY RELATIONSHIP:', ','.join(ev.inparalogs), "<====>", ','.join(ev.orthologs))
elif ev.etype == "D":
- print 'PARALOGY RELATIONSHIP:', ','.join(ev.inparalogs), "<====>", ','.join(ev.outparalogs)
+ print('PARALOGY RELATIONSHIP:', ','.join(ev.inparalogs), "<====>", ','.join(ev.outparalogs))
# And we can explore the resulting reconciled tree
-print recon_tree
+print(recon_tree)
# You will notice how the reconcilied tree is the same as the gene
# tree with some added branches. They are inferred gene losses.
#
--- a/examples/phyloxml/phyloxml_from_scratch.py
+++ b/examples/phyloxml/phyloxml_from_scratch.py
@@ -9,7 +9,7 @@ phylo.phyloxml_phylogeny.set_name("test_
# Add the tree to the phyloxml project
project.add_phylogeny(phylo)
-print project.get_phylogeny()[0]
+print(project.get_phylogeny()[0])
# /-iajom
# /---|
--- a/examples/phyloxml/phyloxml_parser.py
+++ b/examples/phyloxml/phyloxml_parser.py
@@ -4,13 +4,13 @@ project.build_from_file("apaf.xml")
# Each tree contains the same methods as a PhyloTree object
for tree in project.get_phylogeny():
- print tree
+ print(tree)
# you can even use rendering options
tree.show()
# PhyloXML features are stored in the phyloxml_clade attribute
for node in tree:
- print "Node name:", node.name
+ print("Node name:", node.name)
for seq in node.phyloxml_clade.get_sequence():
for domain in seq.domain_architecture.get_domain():
domain_data = [domain.valueOf_, domain.get_from(), domain.get_to()]
- print " Domain:", '\t'.join(map(str, domain_data))
+ print(" Domain:", '\t'.join(map(str, domain_data)))
--- a/examples/treeview/barchart_and_piechart_faces.py
+++ b/examples/treeview/barchart_and_piechart_faces.py
@@ -2,7 +2,7 @@ import sys
import random
from ete3 import Tree, faces, TreeStyle, COLOR_SCHEMES
-schema_names = COLOR_SCHEMES.keys()
+schema_names = list(COLOR_SCHEMES.keys())
def layout(node):
if node.is_leaf():
--- a/examples/treeview/floating_piecharts.py
+++ b/examples/treeview/floating_piecharts.py
@@ -2,7 +2,7 @@ import sys
import random
from ete3 import Tree, faces, TreeStyle, COLOR_SCHEMES
-schema_names = COLOR_SCHEMES.keys()
+schema_names = list(COLOR_SCHEMES.keys())
def layout(node):
if not node.is_leaf():
--- a/examples/treeview/item_faces.py
+++ b/examples/treeview/item_faces.py
@@ -48,8 +48,7 @@ def random_color(h=None):
return _hls2hex(h, l, s)
def _hls2hex(h, l, s):
- return '#%02x%02x%02x' %tuple(map(lambda x: int(x*255),
- colorsys.hls_to_rgb(h, l, s)))
+ return '#%02x%02x%02x' %tuple([int(x*255) for x in colorsys.hls_to_rgb(h, l, s)])
def ugly_name_face(node, *args, **kargs):
""" This is my item generator. It must receive a node object, and
--- a/examples/treeview/new_seq_face.py
+++ b/examples/treeview/new_seq_face.py
@@ -297,9 +297,9 @@ if __name__ == "__main__":
# Show very large algs
tree = PhyloTree('(Orangutan,Human,Chimp);')
- tree.link_to_alignment(">Human\n" + ''.join([_aabgcolors.keys()[int(random() * len (_aabgcolors))] for _ in xrange (5000)]) + \
- "\n>Chimp\n" + ''.join([_aabgcolors.keys()[int(random() * len (_aabgcolors))] for _ in xrange (5000)]) + \
- "\n>Orangutan\n" + ''.join([_aabgcolors.keys()[int(random() * len (_aabgcolors))] for _ in xrange (5000)]))
+ tree.link_to_alignment(">Human\n" + ''.join([list(_aabgcolors.keys())[int(random() * len (_aabgcolors))] for _ in range (5000)]) + \
+ "\n>Chimp\n" + ''.join([list(_aabgcolors.keys())[int(random() * len (_aabgcolors))] for _ in range (5000)]) + \
+ "\n>Orangutan\n" + ''.join([list(_aabgcolors.keys())[int(random() * len (_aabgcolors))] for _ in range (5000)]))
tree.dist = 0
ts = TreeStyle()
ts.title.add_face(TextFace("better not set interactivity if alg is very large", fsize=15), column=0)
--- a/examples/treeview/random_draw.py
+++ b/examples/treeview/random_draw.py
@@ -28,7 +28,7 @@ def leaf_name(node):
def aligned_faces(node):
if node.is_leaf():
- for i in xrange(3):
+ for i in range(3):
F = faces.TextFace("ABCDEFGHIJK"[0:random.randint(1,11)])
F.border.width = 1
F.border.line_style = 1
|