Compare commits
40 commits
Author | SHA1 | Date | |
---|---|---|---|
3b07034cda | |||
7d423e48de | |||
28292a5a74 | |||
945ba6882b | |||
bee830bd42 | |||
094422fe97 | |||
d395c8720f | |||
0ffc437e50 | |||
c65a61162a | |||
0cc95f8d11 | |||
3938a03b70 | |||
e4b2f66b55 | |||
2ca938605e | |||
a23c2f3335 | |||
957a4a9400 | |||
76c422d958 | |||
b763809491 | |||
f09742a8ce | |||
4a6c9455b0 | |||
dd2dc6c065 | |||
94cd57c28f | |||
dafdaf90bc | |||
8951e073c4 | |||
5ad3988229 | |||
c4acef8a75 | |||
f7ce8a70e6 | |||
5e284e5604 | |||
9334b6a8ec | |||
b2282592d1 | |||
b0ea8a801e | |||
0c0cd350e9 | |||
d56e863736 | |||
33dd36290d | |||
0332d175fd | |||
b2c852eabe | |||
cd60624662 | |||
718373d809 | |||
3a380d893e | |||
0b81ca0d76 | |||
b850f75098 |
11 changed files with 970 additions and 366 deletions
54
3tnt.sh
Executable file
54
3tnt.sh
Executable file
|
@ -0,0 +1,54 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Found TNT
|
||||
|
||||
if [ -z "tnt" ]; then
|
||||
echo "TNT not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Define input data
|
||||
|
||||
input_file=$1
|
||||
|
||||
if [ -z "$input_file" ]; then
|
||||
echo "Usage: $0 <input_file> <guoyi.run>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Define tnt script
|
||||
|
||||
script_file=$2
|
||||
|
||||
if [ -z "$script_file" ]; then
|
||||
echo "Usage: $0 <input_file> <guoyi.run>"
|
||||
echo "Warning: guoyi.run will be set as /usr/share/tnt/tnt_scripts/guoyi.run"
|
||||
script_file="/usr/share/tnt/tnt_scripts/guoyi.run"
|
||||
fi
|
||||
|
||||
|
||||
# Define three weighting functions
|
||||
task1() {
|
||||
echo "Equal Weighting started"
|
||||
tnt run $script_file $input_file 3 ew 0 str 5 EW,
|
||||
echo "Equal Weighting completed"
|
||||
}
|
||||
|
||||
task2() {
|
||||
echo "Implied Weighting started"
|
||||
tnt run $script_file $input_file 3 iw 12 str 5 IW,
|
||||
echo "Implied Weighting completed"
|
||||
}
|
||||
|
||||
task3() {
|
||||
echo "Extended Implied Weighting started"
|
||||
tnt run $script_file $input_file 3 eiw 12 str 5 EIW,
|
||||
echo "Extended Implied Weighting completed"
|
||||
}
|
||||
|
||||
task1
|
||||
task2
|
||||
task3
|
||||
|
||||
echo "All tasks completed"
|
||||
|
|
@ -1,15 +1,13 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
project(tnt2winclada)
|
||||
project(tnt_script)
|
||||
SET( CMAKE_EXPORT_COMPILE_COMMANDS ON )
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_executable(tnt2winclada tnt2winclada.cpp)
|
||||
add_subdirectory(src_tnt2winclada)
|
||||
add_subdirectory(src_tnt2figtree)
|
||||
|
||||
target_compile_options(tnt2winclada PRIVATE -Wall -Wextra -pedantic)
|
||||
|
||||
install(TARGETS tnt2winclada DESTINATION /usr/bin)
|
||||
install(FILES guoyi.run DESTINATION /usr/share/tnt/tnt_scripts)
|
||||
install(FILES LICENSE DESTINATION /usr/share/licenses/tnt2winclada)
|
||||
install(FILES README.md DESTINATION /usr/share/doc/tnt2winclada)
|
||||
install(FILES LICENSE DESTINATION /usr/share/licenses/tnt-guoyi-script)
|
||||
install(FILES README.md DESTINATION /usr/share/doc/tnt-guoyi-script)
|
||||
|
|
102
README.md
102
README.md
|
@ -1,6 +1,8 @@
|
|||
# TNT Script used by Guoyi
|
||||
# guoyi.run
|
||||
|
||||
The TNT script follows MIT license.
|
||||
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8431529.svg)](https://doi.org/10.5281/zenodo.8431529)
|
||||
|
||||
TNT Script for Maximum Parsimony Analysis (Phylogeny)
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -14,11 +16,11 @@ The TNT script follows MIT license.
|
|||
|
||||
- Extended implied weighting with K value setting (default, default K=12) or implied weighting with K value setting (default K=12) or equal weighting.
|
||||
|
||||
- Search trees via implicit enumeration (ntax<=25, but not for eiw) or TBR Mult (1000 times) with branch swapping (25<ntax<75, also for ntax<=25 with eiw) or Mult with branch swapping and Xmult (use random sectorial searches, produce 1,000 hits to best length and stop, 10 cycles of drifting, ratchet and fusing) (ntax>=75).
|
||||
- Search trees via implicit enumeration (ntax<=25, but not for eiw) or TBR Mult (1000 times) with branch swapping (25<ntax<75, also for ntax<=25 with eiw) or Mult with branch swapping and Xmult (use random sectorial searches, produce 50 hits to best length and stop, 10 cycles of drifting, ratchet and fusing) (ntax>=75).
|
||||
|
||||
- Perform Strict consensus / Majority-rule consensus / Half strict consensus.
|
||||
- Perform Strict consensus / Majority-rule consensus (without bremer support variations) / Half strict consensus (without bremer support variations).
|
||||
|
||||
- Calculate jackknifing (1,000 times), bootstrap (1,000 times) and Relative Bremer support.
|
||||
- Calculate relative Bremer support, jackknifing (1,000 times), bootstrap (1,000 times) and symmetric resampling (1,000 times).
|
||||
|
||||
- Map apomorphic characters on the consensus tree.
|
||||
|
||||
|
@ -35,10 +37,10 @@ tnt run guoyi.run filename datatype weight 0/K cons resample prefix;
|
|||
For Linux and Mac users
|
||||
|
||||
```
|
||||
tnt run guoyi.run filename datatype weight K cons resample prefix,
|
||||
tnt run guoyi.run filename datatype weight 0/K cons resample prefix,
|
||||
```
|
||||
|
||||
- datatpye should be `32`, `dna`, `prot`, `num`
|
||||
- datatype should be `32`, `dna`, `prot`, `num` or any types tnt allowed
|
||||
|
||||
- num=number, dna=DNA, prot=protein, 32=max number allowed (default)
|
||||
|
||||
|
@ -56,7 +58,7 @@ tnt run guoyi.run filename datatype weight K cons resample prefix,
|
|||
|
||||
- resample should be sum of what you want
|
||||
|
||||
- jak=1, boot=2, relative bremer=4 i.e. jak+boot+bremer=7 (default)
|
||||
- relative bremer support (rbrs)=0.1, bremer support (brs)=0.2, jackknifing (jak)=1, bootstrap (boot)=2, symmetric resampling (sym)=4 i.e. rbrs+jak+boot+sym=7.1 (default)
|
||||
|
||||
- prefix can be empty or a string
|
||||
|
||||
|
@ -66,68 +68,40 @@ tnt run guoyi.run filename datatype weight K cons resample prefix,
|
|||
|
||||
- Results instructions are at the end of `tnt.log`.
|
||||
|
||||
- `trees.tre`, `resample.tre` are trees with taxname.
|
||||
- `*.tre` are trees with taxname, `*_no.tre` are trees without taxname.
|
||||
|
||||
- `trees_no.tre`, `resample_no.tre` are trees without taxname.
|
||||
- `*.tnt.tre` can be read by TNT/WinClada directly.
|
||||
|
||||
- `*.ctf` can only be read by TNT via `shortread`.
|
||||
|
||||
- `*.svg` is the tree file, which can be edited by [inkscape](https://inkscape.org)
|
||||
|
||||
- `original*` is the consensus tree.
|
||||
|
||||
- `apo.tre` is the apomorphic character mapping tree.
|
||||
|
||||
- `resample.tre` is the consensus tree with support, which can be read by figtree after processing by tnt2figtree.
|
||||
|
||||
- `trees*.tre` contains he MPTs, which can be read by figtree after processing by tnt2figtree.
|
||||
|
||||
- `resample/apo.log` contains the tree tags.
|
||||
|
||||
- `eiw.log` contains character concavities.
|
||||
|
||||
- `homo.log` contains homoplasy report of all characters.
|
||||
|
||||
- `report.log` contains CI RI TL.
|
||||
|
||||
- `winclada.ss` includes data matrix and consensus tree and it can be read by winclada directly.
|
||||
|
||||
- `winclada.tre` can be transferred to the acceptable format for WinClada by tnt2winclada and the output file can be put into Winclada with your tnt matrix file `filename` for mapping apomorphic characters and homoplasy.
|
||||
|
||||
## Cite
|
||||
|
||||
Cite this script is mandatory, list me (Guoyi Zhang) in your Acknowledgements is recommended.
|
||||
Cite this script is mandatory, list me (Guoyi Zhang) in your Acknowledgements is recommended. This script follows MIT License.
|
||||
|
||||
# TNT2WinClada
|
||||
# Further information
|
||||
|
||||
```
|
||||
~|~|\ |~|~ ~) | |o._ |~| _ _| _
|
||||
| | \| | /_ \/\/ || ||_|(_|(_|(_|
|
||||
To make tnt exported trees can be readable by WinClada (Nixon, 2021) and FigTree, please check tnt2winclada and tnt2figtree in this repository.
|
||||
|
||||
MIT, Guoyi Zhang, 2023
|
||||
```
|
||||
|
||||
## Function
|
||||
|
||||
Convert TNT output tree file without tags and taxname, e.g. `winclada.tre` produced by TNT script, to WinClada acceptable format tree.
|
||||
|
||||
## Compile
|
||||
|
||||
### Linux & Unix
|
||||
|
||||
```
|
||||
mkdir -p build && cd build
|
||||
cmake ..
|
||||
make && make install
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
```
|
||||
cl /EHsc tnt2winclada.cpp
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
tnt2winclada -i ${input_file} -o ${output_file}
|
||||
```
|
||||
|
||||
Interactive commands are also available.
|
||||
|
||||
```
|
||||
tnt2winclada
|
||||
|
||||
~|~|\ |~|~ ~) | |o._ |~| _ _| _
|
||||
| | \| | /_ \/\/ || ||_|(_|(_|(_|
|
||||
TNT2WinClada
|
||||
MIT, Guoyi Zhang, 2023
|
||||
please type help to see more commands
|
||||
|
||||
tnt2winclada> help
|
||||
help show interactive commands help
|
||||
input <filename> input a TNT output tree from the specified file
|
||||
output <filename> output a winclada accessible tree file
|
||||
quit quit the program
|
||||
exit exit the program
|
||||
|
||||
tnt2winclada>
|
||||
```
|
||||
runwincladtree.run can handle [wincladtree script](https://www.lillo.org.ar/phylogeny/tnt/scripts/wincladtree.run) with input file which must be $(PREFIX).winclada.ss or winclada.tree.
|
||||
|
|
825
guoyi.run
825
guoyi.run
|
@ -2,40 +2,193 @@ macro=;
|
|||
|
||||
log %7.tnt.log;
|
||||
|
||||
/*Arguments*/
|
||||
if ( (argnumber == 0) | (argnumber >7) )
|
||||
/*primary notification*/
|
||||
if ( (argnumber == 0) || (argnumber >7) )
|
||||
silent -console;
|
||||
quote - /----------------------------------------------------\;
|
||||
quote - | GUOYI TNT SCRIPT 2022-2023 MIT |;
|
||||
quote - | You need to give your filename |;
|
||||
quote - | shell> tnt run guoyi.tnt filename, (Linux & Mac) |;
|
||||
quote - | shell> tnt run guoyi.run filename(semicolon) (Win) |;
|
||||
quote - | ============================== |;
|
||||
quote - | === Parameters Details === |;
|
||||
quote - | ============================== |;
|
||||
quote - | filename type weight K cons resamp prefix |;
|
||||
quote - | - type should be 32, dna, prot, num |;
|
||||
quote - | num=number, dna=DNA, prot=protein |;
|
||||
quote - | 32=max number allowed (default) |;
|
||||
quote - | - weight should be iw, ew, eiw |;
|
||||
quote - | iw=implied weight, ew=equal weight |;
|
||||
quote - | eiw=extended implied weight (default) |;
|
||||
quote - | N.B. K of ew must followed 0 (=NA) |;
|
||||
quote - | - K is 12 (default) following Goloboff |;
|
||||
quote - | et al. 2017 (Cladistics 34: 407–437) |;
|
||||
quote - | it must more than 0 |;
|
||||
quote - | - cons should be str, mjr, hlf |;
|
||||
quote - | mjr=majority rule, hlf=half |;
|
||||
quote - | str=strict (default) |;
|
||||
quote - | - resamp should be sum of what you want |;
|
||||
quote - | jak=1, boot=2, relative bremer=4 |;
|
||||
quote - | i.e. jak+boot+bremer=7 (default) |;
|
||||
quote - | - prefix can be empty, or a string |;
|
||||
quote - | default is empty |;
|
||||
quote - \----------------------------------------------------/;
|
||||
quote
|
||||
/----------------------------------------------------\
|
||||
| GUOYI TNT SCRIPT 2022-2023 MIT |
|
||||
| You need to give your filename |
|
||||
| shell> tnt run guoyi.tnt filename, (Linux & Mac) |
|
||||
| shell> tnt run guoyi.run filename(semicolon) (Win) |
|
||||
| ============================== |
|
||||
| === Parameters Details === |
|
||||
| ============================== |
|
||||
| filename type weight K cons resamp prefix |
|
||||
| - filename extension must be lower case |
|
||||
| fasta (fas/fasta), tnt (tnt/ss), nexus |
|
||||
| (nex/nexus) format are allowed |
|
||||
| - type should be 32, dna, prot, num |
|
||||
| num=number, dna=DNA, prot=protein |
|
||||
| 32=max number allowed (default) |
|
||||
| - weight should be iw, ew, eiw |
|
||||
| iw=implied weight, ew=equal weight |
|
||||
| eiw=extended implied weight (default) |
|
||||
| N.B. K of ew must followed 0 (=NA) |
|
||||
| - K is 12 (default) following Goloboff |
|
||||
| et al. 2017 (Cladistics 34: 407–437) |
|
||||
| it must more than 0 |
|
||||
| - cons should be str, mjr, hlf |
|
||||
| mjr=majority rule, hlf=half |
|
||||
| str=strict (default) |
|
||||
| - resamp should be sum of what you want |
|
||||
| jak=1, boot=2, sym=4 relative-bremer |
|
||||
| (rbr)=0.1, bremer(br)=0.2 |
|
||||
| i.e rbr+jak+boot+sym=7.1 (default) |
|
||||
| - prefix can be empty, or a string |
|
||||
| default is empty |
|
||||
\----------------------------------------------------/;
|
||||
proc/;
|
||||
end
|
||||
|
||||
/*Var for handling args*/
|
||||
var:
|
||||
dojak doboot dosym dobrs dorbrs rsmp dobremer
|
||||
dostr domjr dohlf contype
|
||||
doew doiw doeiw dowt wtstring wttype
|
||||
kvalue
|
||||
search
|
||||
isfas istnt isnex input;
|
||||
|
||||
set dojak 0; set doboot 0; set dosym 0; set dobrs 0; set dorbrs 0; set rsmp 0; set dobremer 0;
|
||||
set dostr 0; set domjr 0; set dohlf 0;
|
||||
set doew 0; set doiw 0; set doeiw 0; set dowt 0; set wttype 0;
|
||||
set kvalue 12;
|
||||
set search 0;
|
||||
set isfas 0; set istnt 0; set isnex 0;
|
||||
|
||||
goto=%0;
|
||||
|
||||
/*Get prefix and extension of input*/
|
||||
set input $%1;
|
||||
|
||||
/*confirm input format*/
|
||||
if ((eqstring [ $input>. fas ]) || (eqstring [ $input>. fasta ]))
|
||||
set isfas 1;
|
||||
else
|
||||
if ((eqstring [ $input>. tnt ]) || (eqstring [ $input>. ss ]))
|
||||
set istnt 1;
|
||||
else
|
||||
if ((eqstring [ $input>. nex ]) || (eqstring [ $input>. nexus ]))
|
||||
set isnex 1;
|
||||
else
|
||||
errmsg extension name of input file must be fas/fasta (for fas format), tnt/ss (for Hennig86/NONA/TNT format), nex/nexus (for nex format);
|
||||
end end end
|
||||
|
||||
/*handle weighting type*/
|
||||
if (argnumber>=3)
|
||||
set wtstring $%3;
|
||||
if (eqstring [ $wtstring ew ])
|
||||
set doew 1;
|
||||
set wttype 1;
|
||||
else
|
||||
if (eqstring [ $wtstring iw ])
|
||||
set doiw 1;
|
||||
set wttype 2;
|
||||
else
|
||||
if (eqstring [ $wtstring eiw ])
|
||||
set doeiw 1;
|
||||
set wttype 3;
|
||||
else
|
||||
goto wttypeerr;
|
||||
end end end
|
||||
else
|
||||
set doeiw 1;
|
||||
set wttype 3;
|
||||
end
|
||||
|
||||
if ('doiw' || 'doeiw')
|
||||
set dowt 1;
|
||||
end
|
||||
|
||||
/*handle k value*/
|
||||
if (argnumber>=4)
|
||||
set kvalue %4;
|
||||
if ( 'doew' && ('kvalue' != 0))
|
||||
goto kvalueerr;
|
||||
end
|
||||
end
|
||||
|
||||
/*handle resmaple type*/
|
||||
if (argnumber<6)
|
||||
set dojak 1; set doboot 1; set dosym 1; set dorbrs 1;
|
||||
else
|
||||
set rsmp %6;
|
||||
loop 1 5
|
||||
if ('rsmp' >= 4)
|
||||
set dosym 1;
|
||||
set rsmp 'rsmp'-4;
|
||||
else
|
||||
if ('rsmp' >= 2)
|
||||
set doboot 1;
|
||||
set rsmp 'rsmp'-2;
|
||||
else
|
||||
if ('rsmp' >= 1)
|
||||
set dojak 1;
|
||||
set rsmp 'rsmp'-1;
|
||||
else
|
||||
if ('rsmp' >= 0.2)
|
||||
set dobrs 1;
|
||||
set rsmp 'rsmp'-0.2;
|
||||
else
|
||||
if ('rsmp' >= 0.1)
|
||||
set dorbrs 1;
|
||||
set rsmp 'rsmp'-0.1;
|
||||
end end end end end
|
||||
stop
|
||||
end
|
||||
|
||||
if ('rsmp' != 0)
|
||||
errmsg Input 'rsmp' is illegal;
|
||||
end
|
||||
|
||||
if ('dobrs' || 'dorbrs')
|
||||
set dobremer 1;
|
||||
end
|
||||
|
||||
/*handle consensus type*/
|
||||
if (argnumber>=6)
|
||||
set contype $%5;
|
||||
if ('dobremer')
|
||||
set dostr 1;
|
||||
if (eqstring [ $contype str ])
|
||||
else
|
||||
if (eqstring [ $contype mjr ])
|
||||
goto bremererr;
|
||||
else
|
||||
if (eqstring [ $contype hlf ])
|
||||
goto bremererr;
|
||||
else
|
||||
goto contypeerr;
|
||||
end end end
|
||||
else
|
||||
if (eqstring [ $contype str ])
|
||||
set dostr 1;
|
||||
else
|
||||
if (eqstring [ $contype mjr ])
|
||||
set domjr 1;
|
||||
else
|
||||
if (eqstring [ $contype hlf ])
|
||||
set dohlf 1;
|
||||
else
|
||||
goto contypeerr;
|
||||
end end end
|
||||
end
|
||||
else
|
||||
if (argnumber==5)
|
||||
set contype $%5;
|
||||
if ((eqstring [ $contype mjr ]) || (eqstring [ $contype hlf ]))
|
||||
goto bremererr;
|
||||
else
|
||||
if (eqstring [ $contype str ])
|
||||
set dostr 1;
|
||||
else
|
||||
goto contypeerr;
|
||||
end end
|
||||
else
|
||||
set dostr 1;
|
||||
end end
|
||||
|
||||
/*Basic settings*/
|
||||
taxname+1000;
|
||||
taxname=;
|
||||
|
@ -47,170 +200,229 @@ else
|
|||
end
|
||||
nstates NOGAPS;
|
||||
|
||||
/*Set K*/
|
||||
if(argnumber>2 )
|
||||
if (eqstring [ %3 ew ])
|
||||
quote Equal weighting is used;
|
||||
if (argnumber>=4)
|
||||
if (%4!=0)
|
||||
quote Warning: equal weighting %4 should be fullfilled with 0;
|
||||
end
|
||||
end
|
||||
end
|
||||
if ((eqstring [ %3 iw ]) | (eqstring [ %3 eiw ]))
|
||||
if (argnumber>=4)
|
||||
piwe=%4;
|
||||
else
|
||||
piwe=12;
|
||||
end
|
||||
end
|
||||
else
|
||||
piwe=12;
|
||||
/*Set K*/
|
||||
if ('dowt')
|
||||
piwe='kvalue';
|
||||
end
|
||||
|
||||
/*Reopen tnt*/
|
||||
procedure %1;
|
||||
if ('istnt' || 'isnex')
|
||||
procedure $input;
|
||||
else
|
||||
if ('isfas')
|
||||
procedure & $input;
|
||||
end end
|
||||
hold 10000;
|
||||
|
||||
/*Report what will be done*/
|
||||
quote - /-----------------------------------------------\;
|
||||
if(argnumber>2)
|
||||
if (eqstring [ %3 iw ])
|
||||
if (argnumber>3)
|
||||
quote - | Implied weighting will be used, K is %4. |;
|
||||
else
|
||||
quote - | Implied weighting will be used, K is 12. |;
|
||||
end
|
||||
end
|
||||
if (eqstring [ %3 eiw ])
|
||||
if (argnumber>3)
|
||||
quote - | Ex-implied weighting will be used, K is %4. |;
|
||||
else
|
||||
quote - | Ex-implied weighting will be used, K is 12. |;
|
||||
end
|
||||
end
|
||||
if (eqstring [ %3 ew ])
|
||||
quote - | Equal weighting will be used. |;
|
||||
/*handle search*/
|
||||
if (ntax<=24) /*taxa lower than 25 (including 25)*/
|
||||
if ('doeiw')
|
||||
set search 2;
|
||||
else
|
||||
set search 1;
|
||||
end
|
||||
else
|
||||
quote - | Ex-implied weighting will be used, K is 12. |;
|
||||
end
|
||||
if (ntax<=25)
|
||||
quote - | Implicit enumeration will be performed. |;
|
||||
end
|
||||
if ((ntax>25) && (ntax < 75))
|
||||
quote - | TBR Mult will be performed. |;
|
||||
end
|
||||
if (ntax>=75)
|
||||
quote - | TBR Mult and Xmult will be performed. |;
|
||||
end
|
||||
if (argnumber>=5)
|
||||
if (eqstring [ %5 mjr ])
|
||||
quote - | Majority-rule consensus will be used. |;
|
||||
end
|
||||
if (eqstring [ %5 hlf ])
|
||||
quote - | Half strict consensus will be used. |;
|
||||
end
|
||||
if(eqstring [ %5 str ])
|
||||
quote - | Strict consensus will be used. |;
|
||||
if (ntax<74) /*taxa lower than 75 do mult*/
|
||||
set search 2;
|
||||
else
|
||||
set search 3;
|
||||
end
|
||||
end
|
||||
if (argnumber<5)
|
||||
quote - | Strict consensus will be used. |;
|
||||
|
||||
/*Report what will be done*/
|
||||
quote
|
||||
/-----------------------------------------------\;
|
||||
if ('wttype'==1)
|
||||
quote
|
||||
| Equal weighting will be used. |;
|
||||
else
|
||||
if ('wttype'==2)
|
||||
quote
|
||||
| Implied weighting will be used, K is 'kvalue'. |;
|
||||
else
|
||||
if ('wttype'==3)
|
||||
quote
|
||||
| Ex-implied weighting will be used, K is 'kvalue'. |;
|
||||
end end end
|
||||
|
||||
if ('search'==1)
|
||||
quote
|
||||
| Implicit enumeration will be performed. |;
|
||||
else
|
||||
if ('search'==2)
|
||||
quote
|
||||
| TBR Mult will be performed. |;
|
||||
else
|
||||
if ('search'==3)
|
||||
quote
|
||||
| Xmult will be performed. |;
|
||||
end end end
|
||||
|
||||
if ('dostr')
|
||||
quote
|
||||
| Strict consensus will be used. |;
|
||||
else
|
||||
if ('domjr')
|
||||
quote
|
||||
| Majority-rule consensus will be used. |;
|
||||
else
|
||||
if ('dohlf')
|
||||
quote
|
||||
| Half strict consensus will be used. |;
|
||||
end end end
|
||||
|
||||
quote
|
||||
| resample.svg will contain a tree with |;
|
||||
if ('dorbrs')
|
||||
quote
|
||||
| relative bremer support |;
|
||||
end
|
||||
if (argnumber>=6)
|
||||
if (%6==1)
|
||||
quote - | Jackknifing |;
|
||||
end
|
||||
if (%6==2)
|
||||
quote - | Bootstrap |;
|
||||
end
|
||||
if (%6==3)
|
||||
quote - | Jackknifing and bootstrap |;
|
||||
end
|
||||
if (%6==4)
|
||||
quote - | Relative bremer support |;
|
||||
end
|
||||
if (%6==5)
|
||||
quote - | Jackknifing and relative bremer support |;
|
||||
end
|
||||
if (%6==6)
|
||||
quote - | Bootstrap and relative bremer support |;
|
||||
end
|
||||
if (%6==7)
|
||||
quote - | Jackknifing, bootstrap and relative bremer |;
|
||||
end
|
||||
if ('dobrs')
|
||||
quote
|
||||
| bremer support |;
|
||||
end
|
||||
if (argnumber<6)
|
||||
quote - | Jackknifing, bootstrap and relative bremer |;
|
||||
if ('dojak')
|
||||
quote
|
||||
| jackknifing |;
|
||||
end
|
||||
quote - | will be shown on the resample.svg. |;
|
||||
quote - | Apomorphic characters mapping will be shown |;
|
||||
quote - | on the apo.svg and saved to apo*.tre. |;
|
||||
quote - | TL, CI and RI will be calculated finally. |;
|
||||
quote - \------------------------------------------------/;
|
||||
if ('doboot')
|
||||
quote
|
||||
| bootstrap |;
|
||||
end
|
||||
if ('dosym')
|
||||
quote
|
||||
| symmetric resampling |;
|
||||
end
|
||||
|
||||
quote
|
||||
| Apomorphic characters mapping will be shown |
|
||||
| on the apo.svg and saved to apo*.tre. |
|
||||
| TL, CI and RI will be calculated finally. |
|
||||
\------------------------------------------------/;
|
||||
|
||||
/*Implied weighting settings*/
|
||||
if(argnumber>2)
|
||||
if (eqstring [ %3 iw ])
|
||||
piwe&;
|
||||
end
|
||||
if (eqstring [ %3 eiw ])
|
||||
xpiwe(*;
|
||||
piwe&;
|
||||
end
|
||||
else
|
||||
xpiwe(*;
|
||||
if ('doiw')
|
||||
piwe&;
|
||||
end
|
||||
else
|
||||
if ('doeiw')
|
||||
xpiwe(*;
|
||||
log %7.eiw.log;
|
||||
piwe&;
|
||||
log/;
|
||||
log + %7.tnt.log;
|
||||
end end
|
||||
|
||||
/*Search trees*/
|
||||
if(eqstring [ %3 ew ] | eqstring [ %3 iw ] )
|
||||
if (ntax<=25)
|
||||
ienum;
|
||||
else
|
||||
mult=replic 1000 tbr hold 1000;
|
||||
bbreak=tbr fill;
|
||||
if (ntax>74)
|
||||
sect: slack 1000;
|
||||
xmult=hit 1000 noupdate replications 20 drift 10 ratchet 10 fuse 10 hold 1 keepall;
|
||||
end
|
||||
end
|
||||
if ('search'==1)
|
||||
ienum;
|
||||
else
|
||||
mult=replic 1000 tbr hold 1000;
|
||||
if ('search'==2)
|
||||
mult=replic 1000 tbr hold 10;
|
||||
bbreak=tbr fill;
|
||||
else
|
||||
if ('search'==3)
|
||||
sect: slack 40;
|
||||
xmult=hit 50 replications 20 drift 10 ratchet 10 fuse 10 hold 1 keepall;
|
||||
bbreak=tbr fill;
|
||||
if (ntax>74)
|
||||
sect: slack 1000;
|
||||
xmult=hit 1000 noupdate replications 20 drift 10 ratchet 10 fuse 10 hold 1 keepall;
|
||||
end
|
||||
end
|
||||
end end end
|
||||
|
||||
/*Export trees*/
|
||||
export= %7.trees.tre;
|
||||
taxname-;
|
||||
export= %7.trees_no.tre;
|
||||
tsave *= %7.trees.tnt.tre;
|
||||
taxname=;
|
||||
tsave = %7.trees.ctf;
|
||||
tsave *= %7.trees.tnt.tre;
|
||||
|
||||
/*Consensus tree*/
|
||||
if (argnumber<=4)
|
||||
nelsen *;
|
||||
/*Get npars number*/
|
||||
var: npars;
|
||||
set npars ntrees;
|
||||
|
||||
/*Get consensus tree*/
|
||||
if ('dostr')
|
||||
nelsen * 0.'npars';
|
||||
else
|
||||
if (eqstring [ %5 str ])
|
||||
nelsen *;
|
||||
if ('domjr')
|
||||
majority * 0.'npars';
|
||||
else
|
||||
if ('dohlf')
|
||||
comcomp * 0.'npars';
|
||||
end end end
|
||||
|
||||
/*Get the consensus tree number*/
|
||||
var: contree;
|
||||
set contree ntrees;
|
||||
|
||||
/*Store consensus tree to tree vault*/
|
||||
hold /+0;
|
||||
tv>/;
|
||||
tchoose 0.'npars';
|
||||
|
||||
/*Get rbr/br/jak/boot/sym support and get consensus tree*/
|
||||
ttags=;
|
||||
ttags]; /*in one line*/
|
||||
|
||||
/* jak=1, boot=2, sym=4, */
|
||||
/* jak+boot=3, */
|
||||
/* jak+sym=5, boot+sym=6, */
|
||||
/* jak+boot+sym=7, */
|
||||
|
||||
/* relative-bremer=0.1, bremer=0.2 */
|
||||
/* bremer+relative-bremer=0.3 */
|
||||
|
||||
if ('dobremer')
|
||||
|
||||
/*set value of suboptimal from most parsimony tree */
|
||||
sub: 0;
|
||||
|
||||
/*calculate relative bremer support*/
|
||||
if ('dorbrs')
|
||||
bs ]!! 0;
|
||||
end
|
||||
if (eqstring [ %5 mjr ])
|
||||
majority *;
|
||||
end
|
||||
if (eqstring [ %5 hlf ])
|
||||
comcomp *;
|
||||
|
||||
/*calculate bremer support*/
|
||||
if ('dobrs')
|
||||
macfloat 1; /*set the br value float*/
|
||||
bsupport !! 0;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
/*Choose final tree*/
|
||||
tv<;
|
||||
tchoose/;
|
||||
|
||||
/*adjust to zero following Pablo Goloboff*/
|
||||
sub 0;
|
||||
|
||||
/*jakknifing*/
|
||||
if ('dojak')
|
||||
resample jak replications 1000 from 0; /*from 0 will orphan other trees*/
|
||||
end
|
||||
|
||||
/*Tree vault store*/
|
||||
hold /+0;
|
||||
tvault >/;
|
||||
/*bootstrap*/
|
||||
if ('doboot')
|
||||
resample boot replications 1000 from 0;
|
||||
end
|
||||
|
||||
/*symmetric resampling*/
|
||||
if ('dosym')
|
||||
resample sym replications 1000 from 0;
|
||||
end
|
||||
|
||||
/*Export consensus tree with supports*/
|
||||
ttags & %7.resample.svg thickness 7 italics fontsize 15;
|
||||
log %7.resample.log;
|
||||
quote /-------------resample tags start---------------\;
|
||||
ttags/;
|
||||
quote \-------------resample tags stop----------------/;
|
||||
log/;
|
||||
log + %7.tnt.log;
|
||||
export < %7.resample.tre;
|
||||
taxname-;
|
||||
export - %7.resample_no.tre;
|
||||
ttags-;
|
||||
taxname=;
|
||||
|
||||
/*Export consensus tree*/
|
||||
tchoose /;
|
||||
|
@ -220,167 +432,190 @@ export - %7.original_no.tre;
|
|||
tsave = %7.original.ctf;
|
||||
tsave *= %7.original.tnt.tre;
|
||||
|
||||
/*Caulculate TL/CI/RI score*/
|
||||
report-;
|
||||
var-;
|
||||
var =
|
||||
0 themin
|
||||
1 themax
|
||||
2 CI
|
||||
3 RI
|
||||
4 TL
|
||||
;
|
||||
set themin minsteps;
|
||||
set themax maxsteps;
|
||||
set TL length[0];
|
||||
set CI 'themin'/'TL'; /*CI=1 means no homoplasy*/
|
||||
set RI ('themax'-'TL')/('themax'-'themin'); /*RI=1 character fits perfetcly*/
|
||||
report=;
|
||||
|
||||
/*Apomorphic characters*/
|
||||
export = %7.winclada.tre;
|
||||
taxname =;
|
||||
ttags=;
|
||||
apo >0;
|
||||
quote - /----------------------------------------------\;
|
||||
quote - apomorphy tags start ;
|
||||
log %7.apo.log;
|
||||
quote /-----------apomorphy tags start --------------\;
|
||||
ttags/;
|
||||
quote - apomorphy tags stop ;
|
||||
quote - \----------------------------------------------/;
|
||||
quote \-----------apomorphy tags stop ---------------/;
|
||||
log/;
|
||||
log + %7.tnt.log;
|
||||
ttags & %7.apo.svg thickness 7 italics fontsize 15;
|
||||
export < %7.apo.tre;
|
||||
taxname-;
|
||||
export - %7.apo_no.tre;
|
||||
ttags-;
|
||||
|
||||
/*Get jak/boot/relative-bremer support*/
|
||||
tchoose/;
|
||||
ttags=;
|
||||
ttags]; /*in one line*/
|
||||
/*Character Analysis*/
|
||||
log %7.homo.log;
|
||||
chomo;
|
||||
cscores;
|
||||
log/;
|
||||
log + %7.tnt.log;
|
||||
|
||||
/* jak=1, boot=2, bremer=4, */
|
||||
/* jak+boot=3, */
|
||||
/* jak+brember=5, boot+bremer=6, */
|
||||
/* jak+boot+bremer=7, */
|
||||
|
||||
if (argnumber<=5)
|
||||
/*jakknifing*/
|
||||
resample jak replications 1000 from 0;
|
||||
/*bootstrap*/
|
||||
resample boot replications 1000 from 0;
|
||||
/*relative bremer*/
|
||||
sub 1; hold +1000; bbreak=fill;
|
||||
sub 3; hold +3000; bbreak=fill;
|
||||
sub 5; hold +5000; bbreak=fill;
|
||||
sub 7; hold +7000; bbreak=fill;
|
||||
bsupport[;
|
||||
else
|
||||
if((%6==1) | (%6==3) | (%6==5) | (%6==7))
|
||||
resample jak replications 1000 from 0;
|
||||
end
|
||||
|
||||
if((%6==2) | (%6==3) | (%6==6) | (%6==7))
|
||||
resample boot replications 1000 from 0;
|
||||
end
|
||||
|
||||
if((%6==4) | (%6==5) | (%6==6) | (%6==7))
|
||||
sub 1; hold +1000; bbreak=fill;
|
||||
sub 3; hold +3000; bbreak=fill;
|
||||
sub 5; hold +5000; bbreak=fill;
|
||||
sub 7; hold +7000; bbreak=fill;
|
||||
bsupport[;
|
||||
end
|
||||
end
|
||||
|
||||
/*Export consensus tree with supports*/
|
||||
ttags & %7.resample.svg thickness 7 italics fontsize 15;
|
||||
quote - /----------------------------------------------\;
|
||||
quote - resample tags start ;
|
||||
ttags/;
|
||||
quote - resample tags stop ;
|
||||
quote - \----------------------------------------------/;
|
||||
export < %7.resample.tre;
|
||||
taxname-;
|
||||
export - %7.resample_no.tre;
|
||||
ttags-;
|
||||
/*Caulculate TL/CI/RI score*/
|
||||
report-;
|
||||
var: themin themax CI RI TL ;
|
||||
set themin minsteps;
|
||||
set themax maxsteps;
|
||||
set TL length[0];
|
||||
set CI 'themin'/'TL'; /*CI=1 means no homoplasy*/
|
||||
set RI ('themax'-'TL')/('themax'-'themin'); /*RI=1 character fits perfetcly*/
|
||||
|
||||
/*Report CI/RI/TL */
|
||||
log %7.report.log;
|
||||
macfloat 3;
|
||||
quote Consistency Index (CI) is 'CI';
|
||||
quote Retention Index (RI) is 'RI';
|
||||
quote Tree Length (TL) is 'TL';
|
||||
log/;
|
||||
|
||||
watch-;
|
||||
/*Generate ss file for winclada*/
|
||||
log %7.winclada.ss;
|
||||
/*get basic info*/
|
||||
var: taxnum chanum;
|
||||
set taxnum ntax+1;
|
||||
set chanum nchar+1;
|
||||
/*output head*/
|
||||
quote
|
||||
xread
|
||||
'
|
||||
Data saved from TNT
|
||||
'
|
||||
'chanum' 'taxnum';
|
||||
/*outhead body*/
|
||||
xread!;
|
||||
/*output split symnol*/
|
||||
runc!
|
||||
tntprintf(";\n\n");
|
||||
!
|
||||
/*output the tread*/
|
||||
taxname-;
|
||||
tp*;
|
||||
/*output the end*/
|
||||
runc!
|
||||
tntprintf("proc/;\n");
|
||||
!
|
||||
log/;
|
||||
log + %7.tnt.log;
|
||||
|
||||
/*Report*/
|
||||
quote - /----------------------------------------------\;
|
||||
quote - | The analysis has been finished. |;
|
||||
quote - | The file `tnt.log` contains |;
|
||||
quote - | K, TL, CI and RI |;
|
||||
quote - | The file `trees*.tre` contain |;
|
||||
quote - | trees found by mult and xmult |;
|
||||
quote - | The file `original*.tre` contain |;
|
||||
quote - | strict consensus tree without label |;
|
||||
quote - | The file `resample*.tre` contain |;
|
||||
quote - | consensus tree with support |;
|
||||
quote - | The file `apo*.tre` contain |;
|
||||
quote - | tree with apomorphic character |;
|
||||
quote - | The file `*_no.tre` contain |;
|
||||
quote - | tree with `taxname-` |;
|
||||
quote - | The file `*.ctf` tree file is |;
|
||||
quote - | only readable for TNT |;
|
||||
quote - | The file `*.tnt.tre` contain |;
|
||||
quote - | is the ctf file with taxname |;
|
||||
quote - | The file `resample.svg` contain |;
|
||||
quote
|
||||
/----------------------------------------------\
|
||||
| The analysis has been finished. |
|
||||
| The file `tnt.log` contains |
|
||||
| the performing details |
|
||||
| The file `trees*.tre` contain |
|
||||
| trees found by mult and xmult |
|
||||
| The file `original*.tre` contain |
|
||||
| consensus tree without label |
|
||||
| The file `resample*.tre` contain |
|
||||
| consensus tree with support |
|
||||
| The file `apo*.tre` contain |
|
||||
| tree with apomorphic character |
|
||||
| The file `*_no.tre` contain |
|
||||
| tree with `taxname-` |
|
||||
| The file `*.ctf` tree file is |
|
||||
| only readable for TNT |
|
||||
| The file `*.tnt.tre` contain |
|
||||
| is the tre file without taxname |
|
||||
| The file `resample.svg` contain |;
|
||||
|
||||
|
||||
if (argnumber>=5)
|
||||
if(eqstring [ %5 mjr ])
|
||||
quote - | majority rule consensus tree with |;
|
||||
end
|
||||
if(eqstring [ %5 hlf ])
|
||||
quote - | half strict consensus tree with |;
|
||||
end
|
||||
if(eqstring [ %5 str ])
|
||||
quote - | strict consensus tree with |;
|
||||
end
|
||||
if ('dostr')
|
||||
quote
|
||||
| strict consensus tree with |;
|
||||
else
|
||||
quote - | strict consensus tree with |;
|
||||
if ('domjr')
|
||||
quote
|
||||
| majority-rule consensus tree with |;
|
||||
else
|
||||
if ('dohlf')
|
||||
quote
|
||||
| half strict consensus tree with |;
|
||||
end end end
|
||||
|
||||
if ('dorbrs')
|
||||
quote
|
||||
| relative bremer support |;
|
||||
end
|
||||
if ('dobrs')
|
||||
quote
|
||||
| bremer support |;
|
||||
end
|
||||
if ('dojak')
|
||||
quote
|
||||
| jackknifing |;
|
||||
end
|
||||
if ('doboot')
|
||||
quote
|
||||
| bootstrap |;
|
||||
end
|
||||
if ('dosym')
|
||||
quote
|
||||
| symmetric resampling |;
|
||||
end
|
||||
|
||||
if (argnumber>=6)
|
||||
if (%6==1)
|
||||
quote - | jackknifing |;
|
||||
end
|
||||
if (%6==2)
|
||||
quote - | bootstrap |;
|
||||
end
|
||||
if (%6==3)
|
||||
quote - | jackknifing and bootstrap |;
|
||||
end
|
||||
if (%6==4)
|
||||
quote - | relative bremer support |;
|
||||
end
|
||||
if (%6==5)
|
||||
quote - | jackknifing and relative bremer |;
|
||||
quote - | support |;
|
||||
end
|
||||
if (%6==6)
|
||||
quote - | bootstrap and relative bremer |;
|
||||
quote - | support |;
|
||||
end
|
||||
if (%6==7)
|
||||
quote - | jackknifing, bootstrap and |;
|
||||
quote - | relative bremer support |;
|
||||
end
|
||||
if ('doew')
|
||||
quote
|
||||
| under equal weighting |;
|
||||
else
|
||||
quote - | jackknifing, bootstrap and |;
|
||||
quote - | relative bremer support |;
|
||||
if ('doiw')
|
||||
quote
|
||||
| under implied weighting, |
|
||||
| K value is 'kvalue' |;
|
||||
else
|
||||
if ('doeiw')
|
||||
quote
|
||||
| under extended implied weighting, |
|
||||
| K value is 'kvalue' |;
|
||||
end end end
|
||||
|
||||
quote
|
||||
| The file `apo.svg` contains the |
|
||||
| tree with apomorphy mapping |
|
||||
| The file `report.log` contains the |
|
||||
| CI RI TL publish-needed info |
|
||||
| The file `resample/apo.log` contains |
|
||||
| the tree tags text |
|
||||
| The file `homo.log` contains the report |
|
||||
| of character homoplasy |;
|
||||
|
||||
if ('doeiw')
|
||||
quote
|
||||
| The file `eiw.log` contains the report |
|
||||
| of character concavities |;
|
||||
end
|
||||
|
||||
quote - | The file `apo.svg` contain the |;
|
||||
quote - | tree with apomorphy mapping |;
|
||||
quote - | The file `winclada.tre` can be |;
|
||||
quote - | converted by tnt2winclada |;
|
||||
quote - \----------------------------------------------/;
|
||||
quote
|
||||
| The file `winclada.tre` can be |
|
||||
| converted by tnt2winclada |
|
||||
| The file `winclada.ss` can be read by |
|
||||
| winclada directly |
|
||||
\----------------------------------------------/;
|
||||
|
||||
/*Quit*/
|
||||
zzz;
|
||||
|
||||
/*consensus type error*/
|
||||
label contypeerr
|
||||
errmsg Consensus type must be str mjr or hlf;
|
||||
proc/;
|
||||
|
||||
/*weighting type error*/
|
||||
label wttypeerr
|
||||
errmsg Weighting type must be ew, iw or eiw;
|
||||
proc/;
|
||||
|
||||
/*equal weighting k value error*/
|
||||
label kvalueerr
|
||||
errmsg Equal weighting (ew) must be followed with 0 instead of 'kvalue';
|
||||
proc/;
|
||||
|
||||
/*bremer support not strict consensus error*/
|
||||
label bremererr
|
||||
errmsg Bremer support or any bremer support variations must use strict consensus;
|
||||
proc/;
|
||||
|
|
7
runwincladtree.run
Normal file
7
runwincladtree.run
Normal file
|
@ -0,0 +1,7 @@
|
|||
macro=;
|
||||
taxname+5000;
|
||||
p %1;
|
||||
ttags=;
|
||||
apo>0;
|
||||
wincladtree %1.wincladtree.svg noalign shade rotate squaresize 15 taxangle 0;
|
||||
zzz;
|
14
src_tnt2figtree/CMakeLists.txt
Normal file
14
src_tnt2figtree/CMakeLists.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
project(tnt2figtree)
|
||||
SET( CMAKE_EXPORT_COMPILE_COMMANDS ON )
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_executable(tnt2figtree tnt2figtree.cpp)
|
||||
|
||||
target_compile_options(tnt2figtree PRIVATE -Wall -Wextra -pedantic)
|
||||
|
||||
install(TARGETS tnt2figtree DESTINATION /usr/bin)
|
||||
install(FILES ../LICENSE DESTINATION /usr/share/licenses/tnt2figtree)
|
||||
install(FILES README.md DESTINATION /usr/share/doc/tnt2figtree)
|
55
src_tnt2figtree/README.md
Normal file
55
src_tnt2figtree/README.md
Normal file
|
@ -0,0 +1,55 @@
|
|||
# TNT2FigTree
|
||||
|
||||
```
|
||||
~|~|\ |~|~~)|~o(~|~|~._ _ _
|
||||
| | \| | /_|~| _| | | }_}_
|
||||
|
||||
MIT, Guoyi Zhang, 2024
|
||||
```
|
||||
|
||||
## Function
|
||||
|
||||
Convert TNT output tree file with resample tags, e.g. `resample.tre` produced by TNT script `guoyi.run`, to complete nexus format tree.
|
||||
|
||||
## Compile
|
||||
|
||||
### Linux & Unix
|
||||
|
||||
```
|
||||
mkdir -p build && cd build
|
||||
cmake ..
|
||||
make && make install
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
```
|
||||
cl /EHsc tnt2figtree.cpp
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
tnt2figtree ${input_file} ${output_file}
|
||||
```
|
||||
|
||||
Interactive commands are also available.
|
||||
|
||||
```
|
||||
tnt2figtree
|
||||
|
||||
~|~|\ |~|~~)|~o(~|~|~._ _ _
|
||||
| | \| | /_|~| _| | | }_}_
|
||||
TNT2FigTree
|
||||
MIT, Guoyi Zhang, 2024
|
||||
please type help to see more commands
|
||||
|
||||
tnt2figtree> help
|
||||
help show interactive commands help
|
||||
import <filename> import a TNT output nexus format tree by TNT export command
|
||||
export <filename> export a nexus format tree file
|
||||
quit quit the program
|
||||
exit exit the program
|
||||
|
||||
tnt2figree>
|
||||
```
|
198
src_tnt2figtree/tnt2figtree.cpp
Normal file
198
src_tnt2figtree/tnt2figtree.cpp
Normal file
|
@ -0,0 +1,198 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
|
||||
std::string remove_useless(std::string input_str1)
|
||||
{
|
||||
std::string result_str1 =
|
||||
std::regex_replace(input_str1, std::regex(" /*"), " ");
|
||||
result_str1 = std::regex_replace(result_str1, std::regex("\\["), "{");
|
||||
result_str1 = std::regex_replace(result_str1, std::regex("\\]"), "}");
|
||||
return result_str1;
|
||||
}
|
||||
|
||||
std::string add_support(std::string input_str2)
|
||||
{
|
||||
std::string result_str2 = "";
|
||||
size_t i = 0;
|
||||
while (i < input_str2.length()) {
|
||||
if (input_str2[i] == ')') {
|
||||
result_str2 += input_str2[i];
|
||||
i++;
|
||||
std::string support_str = "";
|
||||
while (i < input_str2.length() &&
|
||||
std::regex_match(std::string(1, input_str2[i]),
|
||||
std::regex("[/0-9{}?]"))) {
|
||||
support_str += input_str2[i];
|
||||
i++;
|
||||
}
|
||||
result_str2 += "[&support=\"" + support_str + "\"]";
|
||||
}
|
||||
else {
|
||||
result_str2 += input_str2[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return result_str2;
|
||||
}
|
||||
|
||||
std::string add_blen(std::string input_str3)
|
||||
{
|
||||
std::string result_str3 = "";
|
||||
int i = 0;
|
||||
for (char c : input_str3) {
|
||||
if (c == '(') {
|
||||
i++;
|
||||
result_str3 += c;
|
||||
}
|
||||
else if (c == ')') {
|
||||
result_str3 += ":" + std::to_string(i) + c;
|
||||
i--;
|
||||
}
|
||||
else if (c == ',') {
|
||||
result_str3 += ":" + std::to_string(i) + c;
|
||||
}
|
||||
else {
|
||||
result_str3 += c;
|
||||
}
|
||||
}
|
||||
return result_str3;
|
||||
}
|
||||
|
||||
std::string remove_slash(std::string input_str4)
|
||||
{
|
||||
std::string result_str4 = std::regex_replace(
|
||||
input_str4, std::regex("\\[&support=\"[\\/\\s]*\"\\]"), "");
|
||||
return result_str4;
|
||||
}
|
||||
|
||||
std::vector<std::string> get_lines(std::string filename)
|
||||
{
|
||||
std::ifstream file(filename);
|
||||
if (!file.is_open()) {
|
||||
std::cout << "Failed to open the input file." << std::endl;
|
||||
}
|
||||
|
||||
std::vector<std::string> lines;
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
lines.push_back(line);
|
||||
}
|
||||
file.close();
|
||||
return lines;
|
||||
}
|
||||
|
||||
std::vector<std::string> process_line(std::vector<std::string> lines,
|
||||
size_t lineNum)
|
||||
{
|
||||
std::string line = remove_useless(lines[lineNum]);
|
||||
line = add_blen(line);
|
||||
line = add_support(line);
|
||||
|
||||
lines[lineNum] = remove_slash(line);
|
||||
return lines;
|
||||
}
|
||||
|
||||
void write_lines(const std::vector<std::string>& lines,
|
||||
const std::string& filename)
|
||||
{
|
||||
std::ofstream outfile(filename);
|
||||
|
||||
if (!outfile.is_open()) {
|
||||
std::cout << "Failed to open the output file." << std::endl;
|
||||
}
|
||||
|
||||
for (const std::string& line : lines) {
|
||||
outfile << line << std::endl;
|
||||
}
|
||||
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
void interactive_commands(std::vector<std::string> lines)
|
||||
{
|
||||
std::string command, filename1, filename2;
|
||||
std::cout
|
||||
<< "~|~|\\ |~|~~)|~o(~|~|~._ _ _\n | | \\| | /_|~| _| | | }_}_"
|
||||
<< std::endl;
|
||||
std::cout << "TNT2FigTree\nMIT, Guoyi Zhang, 2024\nplease type help "
|
||||
"to see more commands"
|
||||
<< std::endl;
|
||||
while (true) {
|
||||
std::cout << "tnt2figtree> ";
|
||||
getline(std::cin, command);
|
||||
if (command == "help") {
|
||||
std::cout << "help\t\t\tshow interactive commands "
|
||||
"help\nimport <filename>\timport a TNT "
|
||||
"output nexus format tree by TNT export "
|
||||
"command\nexport <filename>\texport a "
|
||||
"nexus format tree file\nquit\t\t\tquit "
|
||||
"the program\nexit\t\t\texit the program"
|
||||
<< std::endl;
|
||||
}
|
||||
else if (command.find("import ") == 0) {
|
||||
std::stringstream ss(command.substr(7));
|
||||
ss >> filename1;
|
||||
if (filename1.empty()) {
|
||||
std::cout << "tnt2figtree> please specify a "
|
||||
"filename."
|
||||
<< std::endl;
|
||||
}
|
||||
else {
|
||||
lines = get_lines(filename1);
|
||||
}
|
||||
}
|
||||
else if (command.find("export ") == 0) {
|
||||
std::stringstream ss(command.substr(7));
|
||||
ss >> filename2;
|
||||
if (filename2.empty()) {
|
||||
std::cout << "tnt2figtree> please specify a "
|
||||
"filename."
|
||||
<< std::endl;
|
||||
}
|
||||
else {
|
||||
for (size_t i = 0; i < lines.size(); i++) {
|
||||
if (lines[i][0] == '(') {
|
||||
lines = process_line(lines, i);
|
||||
}
|
||||
}
|
||||
write_lines(lines, filename2);
|
||||
}
|
||||
}
|
||||
else if (command == "quit" || command == "exit") {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
std::cout << "tnt2figtree> unrecognized command. Type "
|
||||
"'help' for "
|
||||
"a list of commands."
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
if (argc == 1) {
|
||||
interactive_commands(lines);
|
||||
return 0;
|
||||
}
|
||||
else if (argc == 3) {
|
||||
lines = get_lines(argv[1]);
|
||||
for (size_t i = 0; i < lines.size(); i++) {
|
||||
if (lines[i][0] == '(') {
|
||||
lines = process_line(lines, i);
|
||||
}
|
||||
}
|
||||
write_lines(lines, argv[2]);
|
||||
}
|
||||
else {
|
||||
std::cout << "Usage: " << argv[0]
|
||||
<< " <input_tnt_treefile> <output_nexus_treefile>"
|
||||
<< std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
14
src_tnt2winclada/CMakeLists.txt
Normal file
14
src_tnt2winclada/CMakeLists.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
project(tnt2winclada)
|
||||
SET( CMAKE_EXPORT_COMPILE_COMMANDS ON )
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_executable(tnt2winclada tnt2winclada.cpp)
|
||||
|
||||
target_compile_options(tnt2winclada PRIVATE -Wall -Wextra -pedantic)
|
||||
|
||||
install(TARGETS tnt2winclada DESTINATION /usr/bin)
|
||||
install(FILES ../LICENSE DESTINATION /usr/share/licenses/tnt2winclada)
|
||||
install(FILES README.md DESTINATION /usr/share/doc/tnt2winclada)
|
55
src_tnt2winclada/README.md
Normal file
55
src_tnt2winclada/README.md
Normal file
|
@ -0,0 +1,55 @@
|
|||
# TNT2WinClada
|
||||
|
||||
```
|
||||
~|~|\ |~|~ ~) | |o._ |~| _ _| _
|
||||
| | \| | /_ \/\/ || ||_|(_|(_|(_|
|
||||
|
||||
MIT, Guoyi Zhang, 2023
|
||||
```
|
||||
|
||||
## Function
|
||||
|
||||
Convert TNT output tree file without tags and taxname, e.g. `winclada.tre` produced by TNT script `guoyi.run`, to WinClada acceptable format tree.
|
||||
|
||||
## Compile
|
||||
|
||||
### Linux & Unix
|
||||
|
||||
```
|
||||
mkdir -p build && cd build
|
||||
cmake ..
|
||||
make && make install
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
```
|
||||
cl /EHsc tnt2winclada.cpp
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
tnt2winclada -i ${input_file} -o ${output_file}
|
||||
```
|
||||
|
||||
Interactive commands are also available.
|
||||
|
||||
```
|
||||
tnt2winclada
|
||||
|
||||
~|~|\ |~|~ ~) | |o._ |~| _ _| _
|
||||
| | \| | /_ \/\/ || ||_|(_|(_|(_|
|
||||
TNT2WinClada
|
||||
MIT, Guoyi Zhang, 2023
|
||||
please type help to see more commands
|
||||
|
||||
tnt2winclada> help
|
||||
help show interactive commands help
|
||||
input <filename> input a TNT output tree from the specified file
|
||||
output <filename> output a winclada accessible tree file
|
||||
quit quit the program
|
||||
exit exit the program
|
||||
|
||||
tnt2winclada>
|
||||
```
|