mirror of
http://43.156.76.180:8026/YuuMJ/EukPhylo.git
synced 2025-12-27 07:50:25 +08:00
fix copying files twice
This commit is contained in:
parent
2a55025595
commit
577e95d5e9
@ -43,7 +43,7 @@ figtree_format = '''begin figtree;
|
|||||||
set nodeLabels.colorAttribute="User selection";
|
set nodeLabels.colorAttribute="User selection";
|
||||||
set nodeLabels.displayAttribute="Node ages";
|
set nodeLabels.displayAttribute="Node ages";
|
||||||
set nodeLabels.fontName="sansserif";
|
set nodeLabels.fontName="sansserif";
|
||||||
set nodeLabels.fontSize=8;
|
set nodeLabels.fontSize=16;
|
||||||
set nodeLabels.fontStyle=0;
|
set nodeLabels.fontStyle=0;
|
||||||
set nodeLabels.isShown=false;
|
set nodeLabels.isShown=false;
|
||||||
set nodeLabels.significantDigits=4;
|
set nodeLabels.significantDigits=4;
|
||||||
@ -83,7 +83,7 @@ figtree_format = '''begin figtree;
|
|||||||
set tipLabels.colorAttribute="User selection";
|
set tipLabels.colorAttribute="User selection";
|
||||||
set tipLabels.displayAttribute="Names";
|
set tipLabels.displayAttribute="Names";
|
||||||
set tipLabels.fontName="sansserif";
|
set tipLabels.fontName="sansserif";
|
||||||
set tipLabels.fontSize=12;
|
set tipLabels.fontSize=16;
|
||||||
set tipLabels.fontStyle=0;
|
set tipLabels.fontStyle=0;
|
||||||
set tipLabels.isShown=true;
|
set tipLabels.isShown=true;
|
||||||
set tipLabels.significantDigits=4;
|
set tipLabels.significantDigits=4;
|
||||||
@ -213,23 +213,7 @@ def write_nexus(newick, leaf_colors, params):
|
|||||||
write_lines(o, newick, taxa_and_colors, tree_font_size)
|
write_lines(o, newick, taxa_and_colors, tree_font_size)
|
||||||
|
|
||||||
|
|
||||||
def tree_formatting_wrapper(file):
|
|
||||||
try:
|
|
||||||
newick = get_newick(file)
|
|
||||||
tree = ete3.Tree(newick)
|
|
||||||
|
|
||||||
majs = list(dict.fromkeys([leaf.name[:2] for leaf in tree]))
|
|
||||||
#Only try to reroot trees with more than 2 major clades. This was added to fix the ETE3 "Cannot set myself as outgroup" error
|
|
||||||
|
|
||||||
if len(majs) > 2:
|
|
||||||
tree = reroot(tree)
|
|
||||||
tree.ladderize(direction = 1)
|
|
||||||
tree.write(outfile = 'ColoredTrees/' + file.split('/')[-1].split('.tree')[0] + '_Colored.tree')
|
|
||||||
except Exception as e:
|
|
||||||
print(f" {file.split('/')[-1]} has {e} error ")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def color(file, args):
|
def color(file, args):
|
||||||
|
|
||||||
if args.keyfile != None:
|
if args.keyfile != None:
|
||||||
@ -242,11 +226,19 @@ def color(file, args):
|
|||||||
else:
|
else:
|
||||||
print('\nERROR: your input keyfile could not be found\n')
|
print('\nERROR: your input keyfile could not be found\n')
|
||||||
else:
|
else:
|
||||||
colors = { 'Ba' : '[&!color=#000000]', 'Za' : '[&!color=#808080]', 'Sr' : '[&!color=#B4A26D]', 'Op' : '[&!color=#1260CC]', 'Pl' : '[&!color=#026736]', 'Ex' : '[&!color=#E63B60]', 'EE' : '[&!color=#C76A6A]', 'Am' : '[&!color=#29C5F6]', 'EE_cr' : '[&!color=#08B461]', 'EE_ha' : '[&!color=#03EA74]', 'Sr_ci' : '[&!color=#A97533]', 'Sr_ap' : '[&!color=#D4BA99]', 'Sr_rh' : '[&!color=#8A3324]', 'Sr_st' : '[&!color=#E97451]', 'Sr_di' : '[&!color=#492815]' }
|
colors = { 'Ba' : '[&!color=#000000]', 'Za' : '[&!color=#808080]', 'Sr' : '[&!color=#B4A26D]', 'Op' : '[&!color=#c07ba0]', 'Pl' : '[&!color=#026736]', 'Ex' : '[&!color=#E63B60]', 'EE' : '[&!color=#0343FC]', 'Am' : '[&!color=#29C5F6]', 'EE_cr' : '[&!color=#08B461]', 'EE_ha' : '[&!color=#03EA74]', 'Sr_ci' : '[&!color=#A97533]', 'Sr_ap' : '[&!color=#D4BA99]', 'Sr_rh' : '[&!color=#8A3324]', 'Sr_st' : '[&!color=#E97451]', 'Sr_di' : '[&!color=#492815]' }
|
||||||
|
#tree_formatting_wrapper
|
||||||
|
try:
|
||||||
|
newick = get_newick(file)
|
||||||
|
tree = ete3.Tree(newick)
|
||||||
|
|
||||||
newick = get_newick(file)
|
majs = list(dict.fromkeys([leaf.name[:2] for leaf in tree]))
|
||||||
|
#Only try to reroot trees with more than 2 major clades. This was added to fix the ETE3 "Cannot set myself as outgroup" error
|
||||||
tree = ete3.Tree(newick)
|
if len(majs) > 2:
|
||||||
|
tree = reroot(tree)
|
||||||
|
tree.ladderize(direction = 1)
|
||||||
|
except Exception as e:
|
||||||
|
print(f" {file.split('/')[-1]} has {e} error ")
|
||||||
|
|
||||||
leaf_colors = []
|
leaf_colors = []
|
||||||
for leaf in tree:
|
for leaf in tree:
|
||||||
@ -263,7 +255,7 @@ def color(file, args):
|
|||||||
else:
|
else:
|
||||||
leaf_colors.append(leaf.name)
|
leaf_colors.append(leaf.name)
|
||||||
|
|
||||||
with open('ColoredTrees/' + file.split('/')[-1].split('.tree')[0] + '.tree', 'w') as o:
|
with open('ColoredTrees/' + file.split('/')[-1].split('.tree')[0] + '_Colored.tree', 'w') as o:
|
||||||
write_lines(o, newick, leaf_colors, str(12))#change tree font size here (right now it is 12)
|
write_lines(o, newick, leaf_colors, str(12))#change tree font size here (right now it is 12)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -275,23 +267,5 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
for tree in os.listdir(args.input):
|
for tree in os.listdir(args.input):
|
||||||
if tree.split('.')[-1] in ('tree', 'tre', 'treefile', 'nex'):
|
if tree.split('.')[-1] in ('tree', 'tre', 'treefile', 'nex'):
|
||||||
tree_formatting_wrapper(args.input + '/' + tree)
|
color(args.input + '/' + tree, args)
|
||||||
|
|
||||||
for tree in os.listdir('ColoredTrees'):
|
|
||||||
if tree.split('.')[-1] in ('tree', 'tre', 'treefile', 'nex'):
|
|
||||||
color('ColoredTrees/' + tree, args)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user