Compare commits
60 Commits
Author | SHA1 | Date |
---|---|---|
kuoi | 3b07034cda | |
kuoi | 7d423e48de | |
kuoi | 28292a5a74 | |
kuoi | 945ba6882b | |
kuoi | bee830bd42 | |
kuoi | 094422fe97 | |
kuoi | d395c8720f | |
kuoi | 0ffc437e50 | |
kuoi | c65a61162a | |
kuoi | 0cc95f8d11 | |
kuoi | 3938a03b70 | |
kuoi | e4b2f66b55 | |
kuoi | 2ca938605e | |
kuoi | a23c2f3335 | |
kuoi | 957a4a9400 | |
kuoi | 76c422d958 | |
kuoi | b763809491 | |
kuoi | f09742a8ce | |
kuoi | 4a6c9455b0 | |
kuoi | dd2dc6c065 | |
kuoi | 94cd57c28f | |
kuoi | dafdaf90bc | |
kuoi | 8951e073c4 | |
kuoi | 5ad3988229 | |
kuoi | c4acef8a75 | |
kuoi | f7ce8a70e6 | |
kuoi | 5e284e5604 | |
kuoi | 9334b6a8ec | |
kuoi | b2282592d1 | |
kuoi | b0ea8a801e | |
kuoi | 0c0cd350e9 | |
kuoi | d56e863736 | |
kuoi | 33dd36290d | |
kuoi | 0332d175fd | |
kuoi | b2c852eabe | |
kuoi | cd60624662 | |
kuoi | 718373d809 | |
kuoi | 3a380d893e | |
kuoi | 0b81ca0d76 | |
kuoi | b850f75098 | |
kuoi | 3ddaad9393 | |
kuoi | 349d2c8eb8 | |
kuoi | b2fbe72823 | |
kuoi | 05ba3e3fc4 | |
kuoi | 12829a96af | |
kuoi | ce2cc5a662 | |
kuoi | 5a7faee66e | |
kuoi | d4c7afd20c | |
kuoi | 6382d4f8aa | |
kuoi | 8b165c649d | |
kuoi | 62937d5d65 | |
kuoi | faeaf710d0 | |
kuoi | dacaf7828b | |
kuoi | 96275b4929 | |
kuoi | 9197ac7df5 | |
kuoi | 73139aca73 | |
kuoi | 92c7918df5 | |
kuoi | 39eaf9d7a5 | |
kuoi | 9ed9f85b82 | |
kuoi | 55f0e78d36 |
|
@ -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"
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
|
project(tnt_script)
|
||||||
|
SET( CMAKE_EXPORT_COMPILE_COMMANDS ON )
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
|
||||||
|
add_subdirectory(src_tnt2winclada)
|
||||||
|
add_subdirectory(src_tnt2figtree)
|
||||||
|
|
||||||
|
install(FILES guoyi.run DESTINATION /usr/share/tnt/tnt_scripts)
|
||||||
|
install(FILES LICENSE DESTINATION /usr/share/licenses/tnt-guoyi-script)
|
||||||
|
install(FILES README.md DESTINATION /usr/share/doc/tnt-guoyi-script)
|
117
README.md
117
README.md
|
@ -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
|
## Usage
|
||||||
|
|
||||||
|
@ -12,13 +14,13 @@ The TNT script follows MIT and part of script is from setk.run belonging to Salv
|
||||||
|
|
||||||
## Functions
|
## 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 and Xmult.
|
- 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, and bootstrap.
|
- 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.
|
- Map apomorphic characters on the consensus tree.
|
||||||
|
|
||||||
|
@ -26,53 +28,80 @@ The TNT script follows MIT and part of script is from setk.run belonging to Salv
|
||||||
|
|
||||||
## Options
|
## 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: 407–437)
|
||||||
|
|
||||||
|
- 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`.
|
- Results instructions are at the end of `tnt.log`.
|
||||||
|
|
||||||
- `trees.tre`, `con.tre` are trees with taxname.
|
- `*.tre` are trees with taxname, `*_no.tre` are trees without taxname.
|
||||||
|
|
||||||
- `trees_no.tre`, `con_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.
|
- `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.
|
||||||
|
|
||||||
# TNT2WinClada
|
## Cite
|
||||||
|
|
||||||
```
|
Cite this script is mandatory, list me (Guoyi Zhang) in your Acknowledgements is recommended. This script follows MIT License.
|
||||||
~|~|\ |~|~ ~) | |o._ |~| _ _| _
|
|
||||||
| | \| | /_ \/\/ || ||_|(_|(_|(_|
|
|
||||||
|
|
||||||
MIT, Guoyi Zhang, 2023
|
# Further information
|
||||||
```
|
|
||||||
|
|
||||||
## Function
|
To make tnt exported trees can be readable by WinClada (Nixon, 2021) and FigTree, please check tnt2winclada and tnt2figtree in this repository.
|
||||||
|
|
||||||
Convert TNT output tree file without tags and taxname, e.g. `winclada.tre` produced by TNT script, to WinClada acceptable format tree.
|
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.
|
||||||
|
|
||||||
## Compile
|
|
||||||
|
|
||||||
### Linux & Unix
|
|
||||||
|
|
||||||
```
|
|
||||||
g++ tnt2winclada.cpp -o tnt2winclada
|
|
||||||
```
|
|
||||||
|
|
||||||
or
|
|
||||||
|
|
||||||
```
|
|
||||||
clang++ -o tnt2winclada tnt2winclada.cpp
|
|
||||||
```
|
|
||||||
|
|
||||||
### Windows
|
|
||||||
|
|
||||||
```
|
|
||||||
cl /EHsc tnt2winclada.cpp
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```
|
|
||||||
tnt2winclada -i ${input_file} -o ${output_file}
|
|
||||||
```
|
|
||||||
|
|
735
guoyi.run
735
guoyi.run
|
@ -1,196 +1,621 @@
|
||||||
log tnt.log;
|
|
||||||
macro=;
|
macro=;
|
||||||
taxname+1000;
|
|
||||||
taxname=;
|
|
||||||
mxram 10240;
|
|
||||||
nstates 32;
|
|
||||||
nstates NOGAPS;
|
|
||||||
|
|
||||||
/*Arguments*/
|
log %7.tnt.log;
|
||||||
if ( argnumber != 1 )
|
|
||||||
|
/*primary notification*/
|
||||||
|
if ( (argnumber == 0) || (argnumber >7) )
|
||||||
silent -console;
|
silent -console;
|
||||||
quote - /-----------------------------------------------\;
|
quote
|
||||||
quote - | GUOYI TNT SCRIPT 2022-2023 MIT |;
|
/----------------------------------------------------\
|
||||||
quote - | You need to give your filename |;
|
| GUOYI TNT SCRIPT 2022-2023 MIT |
|
||||||
quote - | tnt*> guoyi filename; |;
|
| You need to give your filename |
|
||||||
quote - \-----------------------------------------------/;
|
| 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/;
|
proc/;
|
||||||
end
|
end
|
||||||
|
|
||||||
/*Report what will be done*/
|
/*Var for handling args*/
|
||||||
quote - /-----------------------------------------------\;
|
|
||||||
quote - | Implied weighting will be estimated. |;
|
|
||||||
quote - | TBR Mult and Xmult will be performed. |;
|
|
||||||
quote - | Strict consensus will be used. |;
|
|
||||||
quote - | Relative bremer support, jackknifing and |;
|
|
||||||
quote - | bootstrap will be shown on the con.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 - \------------------------------------------------/;
|
|
||||||
|
|
||||||
|
|
||||||
/*Set K*/
|
|
||||||
procedure %1;
|
|
||||||
var:
|
var:
|
||||||
actK
|
dojak doboot dosym dobrs dorbrs rsmp dobremer
|
||||||
minK
|
dostr domjr dohlf contype
|
||||||
maxK
|
doew doiw doeiw dowt wtstring wttype
|
||||||
gVal
|
kvalue
|
||||||
a
|
search
|
||||||
b
|
isfas istnt isnex input;
|
||||||
Nval
|
|
||||||
maxIts
|
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;
|
||||||
if (ntax<0)
|
set doew 0; set doiw 0; set doeiw 0; set dowt 0; set wttype 0;
|
||||||
quote There is no data;
|
set kvalue 12;
|
||||||
proc/;
|
set search 0;
|
||||||
end
|
set isfas 0; set istnt 0; set isnex 0;
|
||||||
/** find the value of g **/
|
|
||||||
loop 0 nchar
|
goto=%0;
|
||||||
if (!isinfo[#1]) continue; end
|
|
||||||
if (!isact[#1]) continue; end
|
/*Get prefix and extension of input*/
|
||||||
set a=maxsteps[#1];
|
set input $%1;
|
||||||
set b=minsteps[#1];
|
|
||||||
if (('a'-'b')>'gVal')
|
/*confirm input format*/
|
||||||
set gVal 'a'-'b';
|
if ((eqstring [ $input>. fas ]) || (eqstring [ $input>. fasta ]))
|
||||||
end
|
set isfas 1;
|
||||||
stop
|
else
|
||||||
quote g value: 'gVal';
|
if ((eqstring [ $input>. tnt ]) || (eqstring [ $input>. ss ]))
|
||||||
set actK 10;
|
set istnt 1;
|
||||||
set minK 0;
|
else
|
||||||
set maxK 500; /** Assume 500 as the maximum possible value of K **/
|
if ((eqstring [ $input>. nex ]) || (eqstring [ $input>. nexus ]))
|
||||||
set maxIts 0;
|
set isnex 1;
|
||||||
/** find the best value of K **/
|
else
|
||||||
loop 0 1
|
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);
|
||||||
quote actual k value: 'actK';
|
end end end
|
||||||
set a 1-('actK'/('actK'+1));
|
|
||||||
quote 'a';
|
/*handle weighting type*/
|
||||||
set b ('actK'/('actK'+'gVal'-1))-('actK'/('actK'+'gVal'));
|
if (argnumber>=3)
|
||||||
quote 'b';
|
set wtstring $%3;
|
||||||
set Nval 'a'/'b';
|
if (eqstring [ $wtstring ew ])
|
||||||
quote N value: 'Nval';
|
set doew 1;
|
||||||
if (('Nval'>14.8)&&('Nval'<15.2)) endloop; end /** N is in range **/
|
set wttype 1;
|
||||||
if ('Nval'>15.2)
|
|
||||||
set minK 'actK';
|
|
||||||
else
|
else
|
||||||
set maxK 'actK';
|
if (eqstring [ $wtstring iw ])
|
||||||
end
|
set doiw 1;
|
||||||
set a ('maxK'-'minK')/2;
|
set wttype 2;
|
||||||
set actK 'minK' + 'a';
|
else
|
||||||
set maxIts ++;
|
if (eqstring [ $wtstring eiw ])
|
||||||
if ('maxIts'==100) endloop; end /** emergency exit **/
|
set doeiw 1;
|
||||||
setloop 0;
|
set wttype 3;
|
||||||
stop
|
else
|
||||||
/** If out of emergency **/
|
goto wttypeerr;
|
||||||
if ('maxIts'==100)
|
end end end
|
||||||
quote Iterations are not finished;
|
else
|
||||||
quote Best K is 'actK';
|
set doeiw 1;
|
||||||
proc /;
|
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
|
end
|
||||||
quote K value: 'actK' (N='Nval');
|
|
||||||
piwe='actK';
|
|
||||||
|
|
||||||
/*Reopen tnt*/
|
/*Reopen tnt*/
|
||||||
procedure %1;
|
if ('istnt' || 'isnex')
|
||||||
hold 5000;
|
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*/
|
||||||
|
if ('doiw')
|
||||||
|
piwe&;
|
||||||
|
else
|
||||||
|
if ('doeiw')
|
||||||
|
xpiwe(*;
|
||||||
|
log %7.eiw.log;
|
||||||
|
piwe&;
|
||||||
|
log/;
|
||||||
|
log + %7.tnt.log;
|
||||||
|
end end
|
||||||
|
|
||||||
/*Search trees*/
|
/*Search trees*/
|
||||||
xpiwe(*;
|
if ('search'==1)
|
||||||
mult=replic 1000 tbr hold 10;
|
ienum;
|
||||||
sect: slack 1000;
|
else
|
||||||
xmult=rss hit 1000 drift 10 ratchet 10 fuse 10;
|
if ('search'==2)
|
||||||
piwe&;
|
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*/
|
||||||
export= trees.tre;
|
export= %7.trees.tre;
|
||||||
taxname-;
|
taxname-;
|
||||||
export= trees_no.tre;
|
export= %7.trees_no.tre;
|
||||||
|
tsave *= %7.trees.tnt.tre;
|
||||||
taxname=;
|
taxname=;
|
||||||
|
tsave = %7.trees.ctf;
|
||||||
|
|
||||||
/*Consensus tree*/
|
/*Get npars number*/
|
||||||
bbreak=tbr;
|
var: npars;
|
||||||
nelsen *;
|
set npars ntrees;
|
||||||
|
|
||||||
/*Get Bremer/jak/boot support*/
|
/*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=;
|
||||||
sub 1; hold +1000; bbreak=fill;
|
ttags]; /*in one line*/
|
||||||
sub 2; hold +2000; bbreak=fill;
|
|
||||||
sub 3; hold +3000; bbreak=fill;
|
/* jak=1, boot=2, sym=4, */
|
||||||
sub 4; hold +4000; bbreak=fill;
|
/* jak+boot=3, */
|
||||||
sub 5; hold +5000; bbreak=fill;
|
/* jak+sym=5, boot+sym=6, */
|
||||||
sub 6; hold +6000; bbreak=fill;
|
/* jak+boot+sym=7, */
|
||||||
sub 7; hold +7000; bbreak=fill;
|
|
||||||
sub 8; hold +8000; bbreak=fill;
|
/* relative-bremer=0.1, bremer=0.2 */
|
||||||
bsupport[;
|
/* bremer+relative-bremer=0.3 */
|
||||||
resample jak replications 1000;
|
|
||||||
resample boot replications 1000;
|
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*/
|
/*Export consensus tree with supports*/
|
||||||
ttags & con.svg thickness 7 italics fontsize 15;
|
ttags & %7.resample.svg thickness 7 italics fontsize 15;
|
||||||
export < con.tre;
|
log %7.resample.log;
|
||||||
|
quote /-------------resample tags start---------------\;
|
||||||
|
ttags/;
|
||||||
|
quote \-------------resample tags stop----------------/;
|
||||||
|
log/;
|
||||||
|
log + %7.tnt.log;
|
||||||
|
export < %7.resample.tre;
|
||||||
taxname-;
|
taxname-;
|
||||||
export - con_no.tre;
|
export - %7.resample_no.tre;
|
||||||
|
ttags-;
|
||||||
|
taxname=;
|
||||||
|
|
||||||
|
/*Export consensus tree*/
|
||||||
|
tchoose /;
|
||||||
|
export - %7.original.tre;
|
||||||
|
taxname-;
|
||||||
|
export - %7.original_no.tre;
|
||||||
|
tsave = %7.original.ctf;
|
||||||
|
tsave *= %7.original.tnt.tre;
|
||||||
|
|
||||||
/*Apomorphic characters*/
|
/*Apomorphic characters*/
|
||||||
export = winclada.tre;
|
export = %7.winclada.tre;
|
||||||
taxname =;
|
taxname =;
|
||||||
ttags-;
|
|
||||||
ttags=;
|
ttags=;
|
||||||
apo >0;
|
apo >0;
|
||||||
ttags & apo.svg thickness 7 italics fontsize 15;
|
log %7.apo.log;
|
||||||
export < apo.tre;
|
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-;
|
taxname-;
|
||||||
export - apo_no.tre;
|
export - %7.apo_no.tre;
|
||||||
ttags-;
|
ttags-;
|
||||||
|
|
||||||
|
/*Character Analysis*/
|
||||||
|
log %7.homo.log;
|
||||||
|
chomo;
|
||||||
|
cscores;
|
||||||
|
log/;
|
||||||
|
log + %7.tnt.log;
|
||||||
|
|
||||||
/*Caulculate TL/CI/RI score*/
|
/*Caulculate TL/CI/RI score*/
|
||||||
length *;
|
|
||||||
report-;
|
report-;
|
||||||
var-;
|
var: themin themax CI RI TL ;
|
||||||
var =
|
|
||||||
0 themin
|
|
||||||
1 themax
|
|
||||||
+ CIs [ ( ntrees + 1 ) ]
|
|
||||||
+ RIs [ ( ntrees + 1 ) ]
|
|
||||||
+ this
|
|
||||||
;
|
|
||||||
set themin minsteps;
|
set themin minsteps;
|
||||||
set themax maxsteps;
|
set themax maxsteps;
|
||||||
loop 0 ntrees
|
set TL length[0];
|
||||||
progress #1 (ntrees+1) Calculating indices...;
|
set CI 'themin'/'TL'; /*CI=1 means no homoplasy*/
|
||||||
set this length[#1];
|
set RI ('themax'-'TL')/('themax'-'themin'); /*RI=1 character fits perfetcly*/
|
||||||
set CIs[#1] 'themin'/'this'; /*CI=1 means no homoplasy*/
|
|
||||||
set RIs[#1] ('themax'-'this')/('themax'-'themin'); /*RI=1 character fits perfetcly*/
|
/*Report CI/RI/TL */
|
||||||
stop
|
log %7.report.log;
|
||||||
progress/;
|
|
||||||
report=;
|
|
||||||
macfloat 3;
|
macfloat 3;
|
||||||
maketable CIs Consistency index;
|
quote Consistency Index (CI) is 'CI';
|
||||||
maketable RIs Retention index;
|
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*/
|
/*Report*/
|
||||||
quote - /----------------------------------------------\;
|
quote
|
||||||
quote - | The analysis has been finished. |;
|
/----------------------------------------------\
|
||||||
quote - | The file `tnt.log` contains |;
|
| The analysis has been finished. |
|
||||||
quote - | K, TL, CI and RI |;
|
| The file `tnt.log` contains |
|
||||||
quote - | The file `trees*.tre` contain |;
|
| the performing details |
|
||||||
quote - | trees found by mult and xmult |;
|
| The file `trees*.tre` contain |
|
||||||
quote - | The file `con*.tre` contain |;
|
| trees found by mult and xmult |
|
||||||
quote - | strict consensus tree |;
|
| The file `original*.tre` contain |
|
||||||
quote - | The file `apo*.tre` contain |;
|
| consensus tree without label |
|
||||||
quote - | tree with apomorphic character |;
|
| The file `resample*.tre` contain |
|
||||||
quote - | The file `*_no.tre` contain |;
|
| consensus tree with support |
|
||||||
quote - | tree with `taxaname-` |;
|
| The file `apo*.tre` contain |
|
||||||
quote - | The file `con.svg` contain |;
|
| tree with apomorphic character |
|
||||||
quote - | strict consensus tree with |;
|
| The file `*_no.tre` contain |
|
||||||
quote - | relative bremer, jak and boot |;
|
| tree with `taxname-` |
|
||||||
quote - | support on the tree |;
|
| The file `*.ctf` tree file is |
|
||||||
quote - | The file `apo.svg` contain the |;
|
| only readable for TNT |
|
||||||
quote - | tree with apomorphy mapping |;
|
| The file `*.tnt.tre` contain |
|
||||||
quote - | The file `winclada.tre` can be |;
|
| is the tre file without taxname |
|
||||||
quote - | converted by tnt2winclada |;
|
| The file `resample.svg` contain |;
|
||||||
quote - \----------------------------------------------/;
|
|
||||||
|
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*/
|
/*Quit*/
|
||||||
zzz;
|
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/;
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
macro=;
|
||||||
|
taxname+5000;
|
||||||
|
p %1;
|
||||||
|
ttags=;
|
||||||
|
apo>0;
|
||||||
|
wincladtree %1.wincladtree.svg noalign shade rotate squaresize 15 taxangle 0;
|
||||||
|
zzz;
|
|
@ -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)
|
|
@ -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>
|
||||||
|
```
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
|
@ -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)
|
|
@ -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>
|
||||||
|
```
|
|
@ -0,0 +1,237 @@
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
string inputFileName, outputFileName, tnt_format, winclada_format;
|
||||||
|
|
||||||
|
void argument(int argc, char** argv);
|
||||||
|
int read_tnt();
|
||||||
|
void showhelp(int help_num);
|
||||||
|
void parse_line();
|
||||||
|
void add_space(string winclada, char x);
|
||||||
|
bool isNum(string strnum);
|
||||||
|
void write_winclada();
|
||||||
|
void interactive_commands();
|
||||||
|
|
||||||
|
void interactive_commands()
|
||||||
|
{
|
||||||
|
string command, filename1, filename2;
|
||||||
|
cout << "~|~|\\ |~|~ ~) | |o._ |~| _ _| _ " << endl;
|
||||||
|
cout << " | | \\| | /_ \\/\\/ || ||_|(_|(_|(_|" << endl;
|
||||||
|
cout << "TNT2WinClada\nMIT, Guoyi Zhang, 2023\nplease type help "
|
||||||
|
"to see more commands"
|
||||||
|
<< endl;
|
||||||
|
while (true) {
|
||||||
|
cout << "tnt2winclada> ";
|
||||||
|
getline(cin, command);
|
||||||
|
if (command == "help") {
|
||||||
|
cout << "help\t\t\tshow interactive commands "
|
||||||
|
"help\ninput "
|
||||||
|
"<filename>\tinput a TNT output tree from the "
|
||||||
|
"specified file\noutput <filename>\toutput a "
|
||||||
|
"winclada accessible tree file\nquit\t\t\tquit "
|
||||||
|
"the program\nexit\t\t\texit the program"
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
else if (command.find("input ") == 0) {
|
||||||
|
std::stringstream ss(command.substr(6));
|
||||||
|
ss >> filename1;
|
||||||
|
if (filename1.empty()) {
|
||||||
|
cout << "tnt2winclada> please specify a "
|
||||||
|
"filename."
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ifstream infile(filename1);
|
||||||
|
if (infile.good()) {
|
||||||
|
inputFileName = filename1;
|
||||||
|
cout << "tnt2winclada> Input file set "
|
||||||
|
"to "
|
||||||
|
<< filename1 << endl;
|
||||||
|
int trelen;
|
||||||
|
trelen = read_tnt();
|
||||||
|
if (trelen == 0) {
|
||||||
|
cout << "tnt2winclada> Input "
|
||||||
|
"format occurs error"
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
parse_line();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cout << "tnt2winclada> file not found. "
|
||||||
|
"Please "
|
||||||
|
"try again."
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (command.find("output ") == 0) {
|
||||||
|
std::stringstream ss(command.substr(7));
|
||||||
|
ss >> filename2;
|
||||||
|
if (filename2.empty()) {
|
||||||
|
cout << "tnt2winclada> please specify a "
|
||||||
|
"filename."
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ofstream outfile(filename2);
|
||||||
|
outputFileName = filename2;
|
||||||
|
cout << "tnt2winclada> Output file set to "
|
||||||
|
<< filename2 << endl;
|
||||||
|
write_winclada();
|
||||||
|
cout << "tnt2winclada> Finished." << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (command == "quit" || command == "exit") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cout << "tnt2wincalda> unrecognized command. Type "
|
||||||
|
"'help' for "
|
||||||
|
"a list of commands."
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void show_help(int help_num)
|
||||||
|
{
|
||||||
|
if (help_num == 0) {
|
||||||
|
cout << "~|~|\\ |~|~ ~) | |o._ |~| _ _| _ " << endl;
|
||||||
|
cout << " | | \\| | /_ \\/\\/ || ||_|(_|(_|(_|" << endl;
|
||||||
|
cout << "TNT2WinClada\nMIT, Guoyi Zhang, 2023\nplease use -h "
|
||||||
|
"to see more options"
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cout << "~|~|\\ |~|~ ~) | |o._ |~| _ _| _ " << endl;
|
||||||
|
cout << " | | \\| | /_ \\/\\/ || ||_|(_|(_|(_|" << endl;
|
||||||
|
cout << "Usage: tnt2winclada -i ${input_file} -o "
|
||||||
|
"${output_file}\n-h help;\n-i input: -i "
|
||||||
|
"${input_file};\n-o output: -o ${output_file}"
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void argument(int argc, char** argv)
|
||||||
|
{
|
||||||
|
// -i -h -o option
|
||||||
|
for (int i = 0; i < argc; i++) {
|
||||||
|
if (argc == 2 && string(argv[1]) == "-h") {
|
||||||
|
show_help(1);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (argc != 5 || string(argv[1]) != "-i" ||
|
||||||
|
string(argv[3]) != "-o") {
|
||||||
|
cout << "input or output can't be empty." << endl;
|
||||||
|
show_help(0);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (string(argv[i]) == "-i") {
|
||||||
|
i++;
|
||||||
|
inputFileName = argv[i];
|
||||||
|
}
|
||||||
|
if (string(argv[i]) == "-o") {
|
||||||
|
i++;
|
||||||
|
outputFileName = argv[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int read_tnt()
|
||||||
|
{
|
||||||
|
int trelen = 0;
|
||||||
|
ifstream inputFile(inputFileName);
|
||||||
|
if (inputFile.is_open()) {
|
||||||
|
getline(inputFile, tnt_format);
|
||||||
|
inputFile.close();
|
||||||
|
trelen = tnt_format.length();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cout << "File can't be opened" << endl;
|
||||||
|
}
|
||||||
|
inputFile.close();
|
||||||
|
return trelen;
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_space(char x)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
string winclada;
|
||||||
|
for (i = 0; i < (int)tnt_format.length(); i++) {
|
||||||
|
if (tnt_format[i] != x) {
|
||||||
|
winclada = winclada + tnt_format[i];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
winclada = winclada + " " + tnt_format[i] + " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tnt_format = winclada;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isNum(string strnum)
|
||||||
|
{
|
||||||
|
char* p;
|
||||||
|
strtol(strnum.c_str(), &p, 10);
|
||||||
|
return *p == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_line()
|
||||||
|
{
|
||||||
|
// add space
|
||||||
|
char x1 = '(', x2 = ')', x3 = ',';
|
||||||
|
add_space(x1);
|
||||||
|
add_space(x2);
|
||||||
|
add_space(x3);
|
||||||
|
// use space as separator
|
||||||
|
istringstream istr(tnt_format);
|
||||||
|
string buffer;
|
||||||
|
int tem;
|
||||||
|
while (getline(istr, buffer, ' ')) {
|
||||||
|
istr >> buffer;
|
||||||
|
if (isNum(buffer)) {
|
||||||
|
tem = stoi(buffer) - 1;
|
||||||
|
buffer = to_string(tem);
|
||||||
|
}
|
||||||
|
winclada_format = winclada_format + buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_winclada()
|
||||||
|
{
|
||||||
|
ofstream outputFile(outputFileName);
|
||||||
|
if (outputFile.is_open()) {
|
||||||
|
outputFile << "tread" << endl;
|
||||||
|
outputFile << winclada_format << endl;
|
||||||
|
outputFile << "proc-;";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cout << "File can't be written" << endl;
|
||||||
|
}
|
||||||
|
outputFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
if (argc == 1) {
|
||||||
|
interactive_commands();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
argument(argc, argv);
|
||||||
|
int trelen;
|
||||||
|
trelen = read_tnt();
|
||||||
|
if (trelen != 0) {
|
||||||
|
parse_line();
|
||||||
|
write_winclada();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cout << "Input file format occurs error." << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
124
tnt2winclada.cpp
124
tnt2winclada.cpp
|
@ -1,124 +0,0 @@
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
string inputFileName, outputFileName, tnt_format, winclada_format;
|
|
||||||
|
|
||||||
void argument(int argc, char** argv);
|
|
||||||
int read_tnt();
|
|
||||||
void showhelp(int help_num);
|
|
||||||
void parse_line(int trelen);
|
|
||||||
void add_space (string winclada, char x);
|
|
||||||
bool isNum(string strnum);
|
|
||||||
|
|
||||||
void show_help (int help_num){
|
|
||||||
if (help_num == 0) {
|
|
||||||
cout << "~|~|\\ |~|~ ~) | |o._ |~| _ _| _ " << endl;
|
|
||||||
cout << " | | \\| | /_ \\/\\/ || ||_|(_|(_|(_|" << endl;
|
|
||||||
cout << "TNT2WinClada\nMIT, Guoyi Zhang, 2023\nplease use -h to see more options" << endl;
|
|
||||||
} else {
|
|
||||||
cout << "~|~|\\ |~|~ ~) | |o._ |~| _ _| _ " << endl;
|
|
||||||
cout << " | | \\| | /_ \\/\\/ || ||_|(_|(_|(_|" << endl;
|
|
||||||
cout << "Usage: tnt2winclada -i ${input_file} -o ${output_file}\n-h help;\n-i input: -i ${input_file};\n-o output: -o ${output_file}" << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void argument(int argc, char **argv) {
|
|
||||||
// -i -h -o option
|
|
||||||
for (int i = 0; i < argc; i++) {
|
|
||||||
if (argc == 2 && string(argv[1]) == "-h") {
|
|
||||||
show_help(1);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
if (argc != 5 || string(argv[1]) != "-i" || string(argv[3]) != "-o") {
|
|
||||||
cout << "input or output can't be empty." << endl;
|
|
||||||
show_help(0);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
if (string(argv[i]) == "-i") {
|
|
||||||
i++;
|
|
||||||
inputFileName = argv[i];
|
|
||||||
}
|
|
||||||
if (string(argv[i]) == "-o") {
|
|
||||||
i++;
|
|
||||||
outputFileName = argv[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int read_tnt() {
|
|
||||||
int trelen;
|
|
||||||
ifstream inputFile(inputFileName);
|
|
||||||
if (inputFile.is_open()) {
|
|
||||||
getline(inputFile, tnt_format);
|
|
||||||
inputFile.close();
|
|
||||||
trelen = tnt_format.length();
|
|
||||||
} else {
|
|
||||||
cout << "File can't be opened" << endl;
|
|
||||||
}
|
|
||||||
inputFile.close();
|
|
||||||
return trelen;
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_space (char x) {
|
|
||||||
int i = 0;
|
|
||||||
string winclada;
|
|
||||||
for (i=0; i<tnt_format.length(); i++) {
|
|
||||||
if (tnt_format[i] != x) {
|
|
||||||
winclada=winclada+tnt_format[i];
|
|
||||||
} else {
|
|
||||||
winclada=winclada+" "+tnt_format[i]+" ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tnt_format=winclada;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNum(string strnum) {
|
|
||||||
char* p;
|
|
||||||
strtol(strnum.c_str(), &p, 10);
|
|
||||||
return *p == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void parse_line (int trelen) {
|
|
||||||
// add space
|
|
||||||
char x1 = '(', x2 = ')', x3= ',';
|
|
||||||
add_space(x1);
|
|
||||||
add_space(x2);
|
|
||||||
add_space(x3);
|
|
||||||
// use space as separator
|
|
||||||
istringstream istr(tnt_format);
|
|
||||||
string buffer;
|
|
||||||
int tem;
|
|
||||||
while (getline(istr, buffer, ' ')) {
|
|
||||||
istr >> buffer;
|
|
||||||
if(isNum(buffer)){
|
|
||||||
tem = stoi(buffer)-1;
|
|
||||||
buffer = to_string(tem);
|
|
||||||
}
|
|
||||||
winclada_format=winclada_format+buffer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_winclada() {
|
|
||||||
ofstream outputFile(outputFileName);
|
|
||||||
if (outputFile.is_open()) {
|
|
||||||
outputFile << "tread" << endl;
|
|
||||||
outputFile << winclada_format << endl;
|
|
||||||
outputFile << "proc-;" ;
|
|
||||||
} else {
|
|
||||||
cout << "File can't be written" << endl;
|
|
||||||
}
|
|
||||||
outputFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
int main (int argc, char **argv){
|
|
||||||
argument(argc, argv);
|
|
||||||
int trelen;
|
|
||||||
trelen = read_tnt();
|
|
||||||
parse_line(trelen);
|
|
||||||
write_winclada();
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Reference in New Issue