Compare commits

...

46 Commits
0.0.7 ... main

Author SHA1 Message Date
kuoi 3b07034cda fix: runwincladtree.svg comment issue 2024-03-19 23:45:15 +08:00
kuoi 7d423e48de add: runwincladtree.run 2024-03-19 23:33:47 +08:00
kuoi 28292a5a74 fix: sstream missing 2024-01-15 20:23:49 +08:00
kuoi 945ba6882b add: standard run script based on guoyi.run 2024-01-14 23:05:59 +08:00
kuoi bee830bd42 fix: CMakeList.txt for full project 2024-01-14 22:53:27 +08:00
kuoi 094422fe97 add: tnt2figtree 2024-01-14 22:30:04 +08:00
kuoi d395c8720f polish: new version, doi changed 2023-10-11 22:34:53 +08:00
kuoi 0ffc437e50 polish: doi display 2023-10-11 22:03:06 +08:00
kuoi c65a61162a add: doi 2023-10-11 21:59:45 +08:00
kuoi 0cc95f8d11 add: bbreak after xmult 2023-10-11 16:31:56 +08:00
kuoi 3938a03b70 fix: else logi 2023-10-10 23:02:06 +08:00
kuoi e4b2f66b55 polish: update README 2023-10-10 22:57:20 +08:00
kuoi 2ca938605e add: nex input function 2023-10-10 22:34:05 +08:00
kuoi a23c2f3335 add: fasta input func 2023-10-10 17:17:29 +08:00
kuoi 957a4a9400 polish: goto to handle error msg 2023-10-10 16:24:48 +08:00
kuoi 76c422d958 fix: wc related; polish: var string 2023-10-10 14:41:21 +08:00
kuoi b763809491 add: winclada.ss directly; fix quote 2023-10-10 13:58:32 +08:00
kuoi f09742a8ce fix: change default 2023-10-10 02:15:39 +08:00
kuoi 4a6c9455b0 fix: formatting 2023-10-10 02:02:11 +08:00
kuoi dd2dc6c065 fix: formatting 2023-10-10 02:00:53 +08:00
kuoi 94cd57c28f fix: ntax is not 0 after tnt input 2023-10-10 01:29:47 +08:00
kuoi dafdaf90bc fix: quote issue 2023-10-10 01:07:46 +08:00
kuoi 8951e073c4 fix: space 2023-10-10 00:58:29 +08:00
kuoi 5ad3988229 fix: typo quote 2023-10-10 00:54:48 +08:00
kuoi c4acef8a75 fix: typo quote 2023-10-10 00:52:59 +08:00
kuoi f7ce8a70e6 fix: typo quote 2023-10-10 00:51:04 +08:00
kuoi 5e284e5604 fix: some logic 2023-10-10 00:49:27 +08:00
kuoi 9334b6a8ec polish: tvault 2023-10-10 00:36:11 +08:00
kuoi b2282592d1 fix: equal; add: tv 2023-10-10 00:35:15 +08:00
kuoi b0ea8a801e polish: add handle arg vars 2023-10-10 00:25:05 +08:00
kuoi 0c0cd350e9 fix: logic 2023-10-09 18:46:43 +08:00
kuoi d56e863736 fix: warning non-binary, search hold 2023-10-09 17:55:52 +08:00
kuoi 33dd36290d polish: bremer from TBR instead of sub 2023-10-09 17:00:29 +08:00
kuoi 0332d175fd fix: sub should re-adj to 0 2023-10-09 01:11:27 +08:00
kuoi b2c852eabe add: relative bremer support; polish: bremer related search 2023-10-08 21:00:10 +08:00
kuoi cd60624662 fix: OR issue 2023-09-20 23:48:36 +08:00
kuoi 718373d809 fix: change relative bremer to bremer 2023-09-20 21:29:12 +08:00
kuoi 3a380d893e fix: make it workable 2023-09-18 15:17:34 +08:00
kuoi 0b81ca0d76 fix: default iew fix 2023-09-17 02:43:05 +08:00
kuoi b850f75098 fix: default now can run 2023-09-17 02:37:10 +08:00
kuoi 3ddaad9393 fix: typo and rm extra 2023-09-14 00:16:32 +08:00
kuoi 349d2c8eb8 fix: typo 2023-09-14 00:10:08 +08:00
kuoi b2fbe72823 add: prefix 2023-09-14 00:08:43 +08:00
kuoi 05ba3e3fc4 polish: fix eiw ntax<=25 related mistake 2023-09-13 21:06:47 +08:00
kuoi 12829a96af polish: update parameters 2023-09-13 21:05:52 +08:00
kuoi ce2cc5a662 polish: add more parameters 2023-09-13 20:57:13 +08:00
11 changed files with 1052 additions and 192 deletions

54
3tnt.sh Executable file
View 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"

View File

@ -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)

136
README.md
View File

@ -1,6 +1,8 @@
# TNT Script used by Guoyi
# guoyi.run
The TNT script follows MIT and part of script is from setk.run belonging to Salvador Arias (Instituto Miguel Lillo, San Miguel de Tucumán, Argentina).
[![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
@ -12,13 +14,13 @@ The TNT script follows MIT and part of script is from setk.run belonging to Salv
## Functions
- Estimate implied weighting K value.
- 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 TBR Mult (1000 times) and Xmult (use random sectorial searches, produce 1,000 hits to best length and stop, 10 cycles of drifting, ratchet and fusing).
- 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.
- Perform Strict consensus / Majority-rule consensus (without bremer support variations) / Half strict consensus (without bremer support variations).
- Calculate Relative Bremer support, jackknifing (1,000 times), and bootstrap (1,000 times).
- 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.
@ -26,74 +28,80 @@ The TNT script follows MIT and part of script is from setk.run belonging to Salv
## Options
For Windows users
```
tnt run guoyi.run filename datatype weight 0/K cons resample prefix;
```
For Linux and Mac users
```
tnt run guoyi.run filename datatype weight 0/K cons resample prefix,
```
- datatype should be `32`, `dna`, `prot`, `num` or any types tnt allowed
- 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. ew must followed 0 (the K value position for ew iw and eiw)
- K is `12` (default) following Goloboff et al. 2017 (Cladistics 34: 407437)
- it must more than 0
- cons should be `str`, `mjr`, `hlf`
- mjr=majority rule, hlf=half, str=strict (default)
- resample should be sum of what you want
- 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
- default is empty
## Results
- 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.
- `nelsen` can be replaced by `majority`.
- `*.ctf` can only be read by TNT via `shortread`.
- `xmult` and `mult` replications and hold trees number can be adjusted.
- `*.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.

699
guoyi.run
View File

@ -1,164 +1,621 @@
log tnt.log;
macro=; taxname+1000; taxname=; mxram 10240; nstates 32; nstates NOGAPS;
macro=;
/*Arguments*/
if ( argnumber != 1 )
log %7.tnt.log;
/*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; (Windows) |;
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: 407437) |
| 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
/*Report what will be done*/
quote - /-----------------------------------------------\;
quote - | Implied weighting will be estimated. |;
quote - | TBR Mult and Xmult will be performed. |;
quote - | Strict consensus will be used. |;
quote - | Jackknifing, bootstrap and relative bremer |;
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 - \------------------------------------------------/;
/*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;
/*Set K*/
piwe=12;
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=;
mxram 10240;
if(argnumber>=2)
nstates %2;
else
nstates 32;
end
nstates NOGAPS;
/*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;
/*handle search*/
if (ntax<=24) /*taxa lower than 25 (including 25)*/
if ('doeiw')
set search 2;
else
set search 1;
end
else
if (ntax<74) /*taxa lower than 75 do mult*/
set search 2;
else
set search 3;
end
end
/*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 ('dobrs')
quote
| bremer support |;
end
if ('dojak')
quote
| jackknifing |;
end
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*/
xpiwe(*;
piwe&;
if ('doiw')
piwe&;
else
if ('doeiw')
xpiwe(*;
log %7.eiw.log;
piwe&;
log/;
log + %7.tnt.log;
end end
/*Search trees*/
mult=replic 1000 tbr hold 1000;
bbreak=tbr fill;
sect: slack 1000;
xmult=hit 1000 noupdate replications 20 drift 10 ratchet 10 fuse 10 hold 1 keepall;
if ('search'==1)
ienum;
else
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;
end end end
/*Export trees*/
export= trees.tre;
export= %7.trees.tre;
taxname-;
export= trees_no.tre;
export= %7.trees_no.tre;
tsave *= %7.trees.tnt.tre;
taxname=;
tsave = trees.ctf;
tsave *= trees.tnt.tre;
tsave = %7.trees.ctf;
/*Consensus tree*/
nelsen *;
/*Get npars number*/
var: npars;
set npars ntrees;
/*Tree vault store*/
hold /+0;
tvault >/;
/*Get consensus tree*/
if ('dostr')
nelsen * 0.'npars';
else
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
/*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
/*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 /;
export - original.tre;
export - %7.original.tre;
taxname-;
export - original_no.tre;
tsave = original.ctf;
tsave *= original.tnt.tre;
export - %7.original_no.tre;
tsave = %7.original.ctf;
tsave *= %7.original.tnt.tre;
/*Apomorphic characters*/
export = %7.winclada.tre;
taxname =;
ttags=;
apo >0;
log %7.apo.log;
quote /-----------apomorphy tags start --------------\;
ttags/;
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-;
/*Character Analysis*/
log %7.homo.log;
chomo;
cscores;
log/;
log + %7.tnt.log;
/*Caulculate TL/CI/RI score*/
report-;
var-;
var =
0 themin
1 themax
2 CI
3 RI
4 TL
;
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=;
/*Apomorphic characters*/
export = winclada.tre;
taxname =;
ttags=;
apo >0;
quote - /----------------------------------------------\;
quote - apomorphy tags start ;
ttags/;
quote - apomorphy tags stop ;
quote - \----------------------------------------------/;
ttags & apo.svg thickness 7 italics fontsize 15;
export < apo.tre;
taxname-;
export - apo_no.tre;
ttags-;
/*Get jak/boot/relative-bremer support*/
tchoose/;
ttags=;
ttags]; /*in one line*/
resample jak replications 1000 from 0;
resample boot replications 1000 from 0;
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[;
/*Export consensus tree with supports*/
ttags & resample.svg thickness 7 italics fontsize 15;
quote - /----------------------------------------------\;
quote - resample tags start ;
ttags/;
quote - resample tags stop ;
quote - \----------------------------------------------/;
export < resample.tre;
taxname-;
export - resample_no.tre;
ttags-;
/*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 - | strict consensus tree with |;
quote - | relative jak, boot and bremer |;
quote - | support on the tree |;
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 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 ('dostr')
quote
| strict consensus tree with |;
else
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 ('doew')
quote
| under equal weighting |;
else
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 `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
View 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;

View 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
View 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>
```

View 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;
}

View 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)

View 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>
```