[Bio] / FigKernelScripts / svr_reroot_tree.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/svr_reroot_tree.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (view) (download) (as text)

1 : overbeek 1.1 use strict;
2 :     use Data::Dumper;
3 :     use Carp;
4 :     use gjonewicklib;
5 :    
6 :     #
7 :     # This is a SAS Component
8 :     #
9 :    
10 :     =head1 svr_reroot_tree
11 :    
12 :     Reroot a tree at a different node or a point on an internal arc.
13 :    
14 :     =head2 Introduction
15 :    
16 :     Examples:
17 :    
18 :     svr_reroot_tree -m < tree.nwk > rerooted.tree.wk [to midpoint of tree (an approximation of that)]
19 :     svr_reroot_tree 'Deh.eth.19,Sph.the.DS,Deh.sp.CBD' < tree.nwk > rerooted.tree.nwk [at a node in an unrooted tree]
20 :     svr_reroot_tree 'Deh.eth.19,Deh.sp.CBD' < tree.nwk > rerooted.tree.nwk [at an internal node in a rooted tree]
21 :     svr_reroot_tree 'Deh.eth.19' < tree.nwk > rerooted.tree.nwk [at a tip]
22 :     svr_reroot_tree -t 'Deh.eth.19' < tree.nwk > rerooted.tree.nwk [at a node next to a tip]
23 :    
24 :     To reroot to a point on an arc between two nodes, use
25 :    
26 :     svr_reroot_tree -f 0.5 NODE1 NODE2 < tree.nwk > rerooted.tree.nwk [NODE1 and NODE2 can be 1, 2,or 3 ids]
27 :     e.g.,
28 :     svr_reroot_tree -f 0.5 Deh.eth.19 'Deh.eth.19,Deh.sp.CBD' < tree.nwk > rerooted.tree.nwk [NODE1 and NODE2 can be 1, 2,or 3 ids]
29 :     or svr_reroot_tree -d 1.5 Deh.eth.19 'Deh.eth.19,Deh.sp.CBD' < tree.nwk > rerooted.tree.nwk [NODE1 and NODE2 can be 1, 2,or 3 ids]
30 :    
31 :    
32 :     =head2 Command-Line Arguments
33 :    
34 :     The program is invoked using
35 :    
36 : overbeek 1.3 svr_reroot_tree [-m] [-t] [-f Fraction] [-d Distance] Node(s)
37 : overbeek 1.1
38 :     The operation may require one or two nodes to be specified; these
39 :     immediately follow the optional arguments. A node is specified
40 :     as a string containing 1 to 3 IDs comma-separated.
41 :    
42 :     =over 4
43 :    
44 :     =item -m
45 :    
46 :     Root at the midpoint of the tree (an approximation)
47 :    
48 :     =item -t
49 :    
50 :     Root at the parent node of the specified tip (i.e., there should be a single node given,
51 :     and it should be a single tip ID).
52 :    
53 :     =item -f=Fraction
54 :    
55 :     Specifies the fraction along the path from NODE1 to NODE2 that you wish to place the root at
56 :    
57 :     =item -d=Distance
58 :    
59 :     Specifies the distance along the path from NODE1 to NODE2 that you wish to place the root at
60 :    
61 :     =back
62 :    
63 :     =head2 Output
64 :    
65 :     A rerooted tree in newick format.
66 :    
67 :     =cut
68 :    
69 :     use Getopt::Long;
70 :     my $midpoint = 0;
71 :     my $root_at_parent = 0;
72 : overbeek 1.2 my $fraction;
73 :     my $distance;
74 : overbeek 1.1 my $usage = "svr_corresponding_genes [-m] [-t] [-f Fraction] [-d Distance] Node(s) < tree > rerooted\n";
75 :    
76 :     my $rc = GetOptions( "m" => \$midpoint,
77 :     "a" => \$root_at_parent,
78 :     "f=f" => \$fraction,
79 :     "d=f" => \$distance
80 :     );
81 :    
82 :     $rc or print STDERR $usage and exit;
83 :    
84 :     if (($fraction || $distance) && (@ARGV != 2))
85 :     {
86 :     print STDERR "You need to specify two nodes when rerooting to a point on a path\n";
87 :     print STDERR $usage;
88 :     exit;
89 :     }
90 :    
91 : overbeek 1.2 if ((! defined($fraction)) && (! defined($distance)) && (@ARGV == 2))
92 : overbeek 1.1 {
93 :     print STDERR "You need to specify fraction or distance when rerooting to a point on a path\n";
94 :     print STDERR $usage;
95 :     exit;
96 :     }
97 :    
98 :     if ($root_at_parent && (@ARGV != 1))
99 :     {
100 :     print STDERR "You need to specify a single tip node when rerooting to the parent of a tip\n";
101 :     print STDERR $usage;
102 :     exit;
103 :     }
104 :    
105 :     if ($midpoint && (@ARGV != 0))
106 :     {
107 :     print STDERR "You have extra arguments (rerooting to the midpoint of a tree requires no nodes\n";
108 :     print STDERR $usage;
109 :     exit;
110 :     }
111 :    
112 :     if ((@ARGV == 0) && (! $midpoint))
113 :     {
114 :     print STDERR "You are missing arguments (node(s) are required if not rerooting to a midpoint)\n";
115 :     print STDERR $usage;
116 :     exit;
117 :     }
118 :    
119 :     my @args = map { [split(/,/,$_)] } @ARGV;
120 :    
121 :     my $tree = &gjonewicklib::read_newick_tree( );
122 :    
123 :     my $rerooted = &gjonewicklib::reroot_tree($tree, { midpoint => $midpoint,
124 :     adjacent_to_tip => $root_at_parent,
125 :     fraction => $fraction,
126 :     distance => $distance,
127 :     nodes => \@args
128 :     });
129 :    
130 :     &gjonewicklib::writeNewickTree( $rerooted );

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3