PB Rename ids - mendessoares/BuddySuite GitHub Wiki
--rename_ids, -ri
Description
Replace some regex pattern in taxa IDs and node labels with some other string.
Arguments
Regular expression ( str )
If there are any special characters in the expression, ensure the string is enclosed in quotes.
Substitution ( str )
The matched regular expression will be replaced by this text. If you want to retain part of the regex match, use the '(...)' syntax, and then include escaped indices (e.g., '\1', '\2') in the substitution string (see example 2 below).
Examples
Input file: Mle_Panx.nwk
(('Mle-Panxα12':0.24785,(('Mle-Panxα7A':0.51324,('Mle-Panxα2':0.5425,('Mle-Panxα6':0.31957,('Mle-Panxα1':0.62588,'Mle-Panxα5':0.48557)0.450:0.04238)0.652:0.02277)0.938:0.06567)0.867:0.04265,('Mle-Panxα4':0.50524,'Mle-Panxα8':0.33085)0.913:0.07789)0.924:0.05363)0.910:0.0533,('Mle-Panxα9':0.00394,('Mle-Panxα10B':0.00144,'Mle-Panxα10A':0.01578)1.000:0.05152)1.000:0.30415,('Mle-Panxα11':0.27774,'Mle-Panxα3':0.39731)0.922:0.05673);
Input tree
/---------------------------------------------------------- Mle-Panxα12
|
| /-------------------------------------- Mle-Panxα7A
| /---------+
/--------+ | | /----------------------------- Mle-Panxα2
| | | \--------+
| | | | /------------------- Mle-Panxα6
| | | \---------+
| \---------+ | /--------- Mle-Panxα1
| | \---------+
| | \--------- Mle-Panxα5
| |
| | /--------- Mle-Panxα4
+ \--------------------------------------+
| \--------- Mle-Panxα8
|
| /------------------- Mle-Panxα9
|-----------------------------------------------+
| | /--------- Mle-Panxα10B
| \---------+
| \--------- Mle-Panxα10A
|
| /--------- Mle-Panxα11
\---------------------------------------------------------+
\--------- Mle-Panxα3
Usage example 1
$: pb Mle_Panx.nwk -ri 'α' 'A'
Output
(('Mle-PanxA12':0.24785,(('Mle-PanxA7A':0.51324,('Mle-PanxA2':0.5425,('Mle-PanxA6':0.31957,('Mle-PanxA1':0.62588,'Mle-PanxA5':0.48557)0.450:0.04238)0.652:0.02277)0.938:0.06567)0.867:0.04265,('Mle-PanxA4':0.50524,'Mle-PanxA8':0.33085)0.913:0.07789)0.924:0.05363)0.910:0.0533,('Mle-PanxA9':0.00394,('Mle-PanxA10B':0.00144,'Mle-PanxA10A':0.01578)1.000:0.05152)1.000:0.30415,('Mle-PanxA11':0.27774,'Mle-PanxA3':0.39731)0.922:0.05673);
Output tree
/---------------------------------------------------------- Mle-PanxA12
|
| /-------------------------------------- Mle-PanxA7A
| /---------+
/--------+ | | /----------------------------- Mle-PanxA2
| | | \--------+
| | | | /------------------- Mle-PanxA6
| | | \---------+
| \---------+ | /--------- Mle-PanxA1
| | \---------+
| | \--------- Mle-PanxA5
| |
| | /--------- Mle-PanxA4
+ \--------------------------------------+
| \--------- Mle-PanxA8
|
| /------------------- Mle-PanxA9
|-----------------------------------------------+
| | /--------- Mle-PanxA10B
| \---------+
| \--------- Mle-PanxA10A
|
| /--------- Mle-PanxA11
\---------------------------------------------------------+
\--------- Mle-PanxA3
Usage example 2 (note that part of the match is retained)
$: pb Mle_Panx.nwk -ri 'α([3-9])' 'A\1'
Output
(('Mle-Panxα12':0.24785,(('Mle-PanxA7A':0.51324,('Mle-Panxα2':0.5425,('Mle-PanxA6':0.31957,('Mle-Panxα1':0.62588,'Mle-PanxA5':0.48557)0.450:0.04238)0.652:0.02277)0.938:0.06567)0.867:0.04265,('Mle-PanxA4':0.50524,'Mle-PanxA8':0.33085)0.913:0.07789)0.924:0.05363)0.910:0.0533,('Mle-PanxA9':0.00394,('Mle-Panxα10B':0.00144,'Mle-Panxα10A':0.01578)1.000:0.05152)1.000:0.30415,('Mle-Panxα11':0.27774,'Mle-PanxA3':0.39731)0.922:0.05673);
Output tree
/---------------------------------------------------------- Mle-Panxα12
|
| /-------------------------------------- Mle-PanxA7A
| /---------+
/--------+ | | /----------------------------- Mle-Panxα2
| | | \--------+
| | | | /------------------- Mle-PanxA6
| | | \---------+
| \---------+ | /--------- Mle-Panxα1
| | \---------+
| | \--------- Mle-PanxA5
| |
| | /--------- Mle-PanxA4
+ \--------------------------------------+
| \--------- Mle-PanxA8
|
| /------------------- Mle-PanxA9
|-----------------------------------------------+
| | /--------- Mle-Panxα10B
| \---------+
| \--------- Mle-Panxα10A
|
| /--------- Mle-Panxα11
\---------------------------------------------------------+
\--------- Mle-PanxA3