TNT_Script/guoyi.run

622 lines
13 KiB
Plaintext
Raw Permalink Normal View History

2023-09-13 20:57:13 +08:00
macro=;
2023-02-26 03:32:18 +08:00
2023-09-14 00:08:43 +08:00
log %7.tnt.log;
2023-10-10 00:25:05 +08:00
/*primary notification*/
2023-09-20 23:48:36 +08:00
if ( (argnumber == 0) || (argnumber >7) )
2023-02-27 01:24:22 +08:00
silent -console;
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 |
2023-10-10 17:17:29 +08:00
| - filename extension must be lower case |
2023-10-10 22:34:05 +08:00
| 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 |
2023-10-10 02:15:39 +08:00
| i.e rbr+jak+boot+sym=7.1 (default) |
| - prefix can be empty, or a string |
| default is empty |
\----------------------------------------------------/;
2023-02-27 01:24:22 +08:00
proc/;
end
2023-10-10 00:25:05 +08:00
/*Var for handling args*/
2023-10-10 16:24:48 +08:00
var:
dojak doboot dosym dobrs dorbrs rsmp dobremer
2023-10-10 14:41:21 +08:00
dostr domjr dohlf contype
doew doiw doeiw dowt wtstring wttype
2023-10-10 00:25:05 +08:00
kvalue
2023-10-10 17:17:29 +08:00
search
2023-10-10 22:34:05 +08:00
isfas istnt isnex input;
2023-10-10 00:25:05 +08:00
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;
2023-10-10 22:34:05 +08:00
set isfas 0; set istnt 0; set isnex 0;
2023-10-10 00:25:05 +08:00
2023-10-10 16:24:48 +08:00
goto=%0;
2023-10-10 17:17:29 +08:00
/*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;
2023-10-10 23:02:06 +08:00
else
2023-10-10 22:34:05 +08:00
if ((eqstring [ $input>. nex ]) || (eqstring [ $input>. nexus ]))
set isnex 1;
2023-10-10 17:17:29 +08:00
else
2023-10-10 22:34:05 +08:00
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
2023-10-10 17:17:29 +08:00
2023-10-10 00:25:05 +08:00
/*handle weighting type*/
if (argnumber>=3)
2023-10-10 14:41:21 +08:00
set wtstring $%3;
if (eqstring [ $wtstring ew ])
2023-10-10 00:25:05 +08:00
set doew 1;
set wttype 1;
else
2023-10-10 14:41:21 +08:00
if (eqstring [ $wtstring iw ])
2023-10-10 00:25:05 +08:00
set doiw 1;
set wttype 2;
else
2023-10-10 14:41:21 +08:00
if (eqstring [ $wtstring eiw ])
2023-10-10 00:25:05 +08:00
set doeiw 1;
set wttype 3;
else
2023-10-10 16:24:48 +08:00
goto wttypeerr;
2023-10-10 00:25:05 +08:00
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))
2023-10-10 16:24:48 +08:00
goto kvalueerr;
2023-10-10 00:25:05 +08:00
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
2023-10-10 00:35:15 +08:00
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
2023-10-10 00:25:05 +08:00
stop
end
if ('rsmp' != 0)
2023-10-10 16:24:48 +08:00
errmsg Input 'rsmp' is illegal;
2023-10-10 00:25:05 +08:00
end
if ('dobrs' || 'dorbrs')
set dobremer 1;
end
/*handle consensus type*/
if (argnumber>=6)
2023-10-10 14:41:21 +08:00
set contype $%5;
2023-10-10 00:25:05 +08:00
if ('dobremer')
set dostr 1;
2023-10-10 14:41:21 +08:00
if (eqstring [ $contype str ])
2023-10-10 00:25:05 +08:00
else
2023-10-10 14:41:21 +08:00
if (eqstring [ $contype mjr ])
2023-10-10 16:24:48 +08:00
goto bremererr;
2023-10-10 00:25:05 +08:00
else
2023-10-10 14:41:21 +08:00
if (eqstring [ $contype hlf ])
2023-10-10 16:24:48 +08:00
goto bremererr;
2023-10-10 00:25:05 +08:00
else
2023-10-10 16:24:48 +08:00
goto contypeerr;
2023-10-10 00:25:05 +08:00
end end end
else
2023-10-10 14:41:21 +08:00
if (eqstring [ $contype str ])
2023-10-10 00:25:05 +08:00
set dostr 1;
else
2023-10-10 14:41:21 +08:00
if (eqstring [ $contype mjr ])
2023-10-10 00:25:05 +08:00
set domjr 1;
else
2023-10-10 14:41:21 +08:00
if (eqstring [ $contype hlf ])
2023-10-10 00:25:05 +08:00
set dohlf 1;
else
2023-10-10 16:24:48 +08:00
goto contypeerr;
2023-10-10 00:25:05 +08:00
end end end
end
else
if (argnumber==5)
2023-10-10 14:41:21 +08:00
set contype $%5;
if ((eqstring [ $contype mjr ]) || (eqstring [ $contype hlf ]))
2023-10-10 16:24:48 +08:00
goto bremererr;
2023-10-10 00:25:05 +08:00
else
2023-10-10 14:41:21 +08:00
if (eqstring [ $contype str ])
2023-10-10 00:25:05 +08:00
set dostr 1;
else
2023-10-10 16:24:48 +08:00
goto contypeerr;
2023-10-10 00:25:05 +08:00
end end
else
set dostr 1;
end end
2023-09-13 20:57:13 +08:00
/*Basic settings*/
2023-09-20 21:29:12 +08:00
taxname+1000;
2023-09-13 20:57:13 +08:00
taxname=;
mxram 10240;
2023-09-13 20:57:13 +08:00
if(argnumber>=2)
nstates %2;
else
nstates 32;
end
nstates NOGAPS;
2023-10-10 00:25:05 +08:00
/*Set K*/
if ('dowt')
piwe='kvalue';
2023-09-13 20:57:13 +08:00
end
/*Reopen tnt*/
2023-10-10 22:34:05 +08:00
if ('istnt' || 'isnex')
2023-10-10 17:17:29 +08:00
procedure $input;
else
if ('isfas')
procedure & $input;
end end
2023-09-13 20:57:13 +08:00
hold 10000;
2023-10-10 01:29:47 +08:00
/*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
2023-02-27 01:24:22 +08:00
/*Report what will be done*/
quote
/-----------------------------------------------\;
2023-10-10 00:25:05 +08:00
if ('wttype'==1)
quote
| Equal weighting will be used. |;
2023-09-13 20:57:13 +08:00
else
2023-10-10 00:25:05 +08:00
if ('wttype'==2)
quote
2023-10-10 00:25:05 +08:00
| 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
2023-10-10 00:25:05 +08:00
if ('search'==2)
quote
| TBR Mult will be performed. |;
else
2023-10-10 00:25:05 +08:00
if ('search'==3)
quote
| Xmult will be performed. |;
end end end
2023-10-10 00:25:05 +08:00
if ('dostr')
quote
| Strict consensus will be used. |;
else
2023-10-10 00:25:05 +08:00
if ('domjr')
quote
| Majority-rule consensus will be used. |;
2023-10-10 00:25:05 +08:00
else
if ('dohlf')
quote
| Half strict consensus will be used. |;
2023-10-10 00:25:05 +08:00
end end end
2023-10-10 02:00:53 +08:00
quote
| resample.svg will contain a tree with |;
2023-10-10 00:25:05 +08:00
if ('dorbrs')
quote
2023-10-10 02:00:53 +08:00
| relative bremer support |;
2023-10-10 00:49:27 +08:00
end
2023-10-10 00:25:05 +08:00
if ('dobrs')
quote
2023-10-10 02:00:53 +08:00
| bremer support |;
2023-10-10 00:49:27 +08:00
end
2023-10-10 00:25:05 +08:00
if ('dojak')
quote
2023-10-10 02:00:53 +08:00
| jackknifing |;
2023-10-10 00:49:27 +08:00
end
2023-10-10 00:25:05 +08:00
if ('doboot')
quote
2023-10-10 02:00:53 +08:00
| bootstrap |;
2023-10-10 00:49:27 +08:00
end
2023-10-10 00:25:05 +08:00
if ('dosym')
2023-10-10 00:51:04 +08:00
quote
2023-10-10 02:00:53 +08:00
| symmetric resampling |;
2023-10-10 00:49:27 +08:00
end
2023-10-10 00:25:05 +08:00
quote
| Apomorphic characters mapping will be shown |
| on the apo.svg and saved to apo*.tre. |
| TL, CI and RI will be calculated finally. |
\------------------------------------------------/;
2023-02-27 01:24:22 +08:00
/*Implied weighting settings*/
2023-10-10 00:25:05 +08:00
if ('doiw')
piwe&;
2023-09-13 20:57:13 +08:00
else
2023-10-10 00:25:05 +08:00
if ('doeiw')
2023-09-13 20:57:13 +08:00
xpiwe(*;
log %7.eiw.log;
2023-09-13 20:57:13 +08:00
piwe&;
log/;
2023-10-10 00:25:05 +08:00
log + %7.tnt.log;
end end
/*Search trees*/
2023-10-10 00:25:05 +08:00
if ('search'==1)
ienum;
2023-09-13 20:57:13 +08:00
else
2023-10-10 00:25:05 +08:00
if ('search'==2)
2023-10-09 17:55:52 +08:00
mult=replic 1000 tbr hold 10;
2023-10-10 00:25:05 +08:00
bbreak=tbr fill;
else
if ('search'==3)
sect: slack 40;
xmult=hit 50 replications 20 drift 10 ratchet 10 fuse 10 hold 1 keepall;
2023-10-11 16:31:56 +08:00
bbreak=tbr fill;
2023-10-10 00:25:05 +08:00
end end end
2023-02-27 01:24:22 +08:00
/*Export trees*/
2023-09-14 00:08:43 +08:00
export= %7.trees.tre;
2023-02-26 03:32:18 +08:00
taxname-;
2023-09-14 00:08:43 +08:00
export= %7.trees_no.tre;
2023-10-09 17:00:29 +08:00
tsave *= %7.trees.tnt.tre;
2023-02-26 03:32:18 +08:00
taxname=;
2023-09-14 00:08:43 +08:00
tsave = %7.trees.ctf;
2023-02-26 03:32:18 +08:00
/*Get npars number*/
var: npars;
set npars ntrees;
2023-07-20 20:53:29 +08:00
2023-10-10 00:25:05 +08:00
/*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;
2023-10-10 00:35:15 +08:00
/*Store consensus tree to tree vault*/
2023-10-10 00:36:11 +08:00
hold /+0;
2023-10-10 00:35:15 +08:00
tv>/;
tchoose 0.'npars';
/*Get rbr/br/jak/boot/sym support and get consensus tree*/
2023-02-26 03:32:18 +08:00
ttags=;
ttags]; /*in one line*/
/* jak=1, boot=2, sym=4, */
2023-09-13 20:57:13 +08:00
/* jak+boot=3, */
/* jak+sym=5, boot+sym=6, */
/* jak+boot+sym=7, */
2023-10-10 00:25:05 +08:00
/* relative-bremer=0.1, bremer=0.2 */
/* bremer+relative-bremer=0.3 */
2023-10-10 00:25:05 +08:00
if ('dobremer')
2023-10-09 17:00:29 +08:00
/*set value of suboptimal from most parsimony tree */
sub: 0;
/*calculate relative bremer support*/
2023-10-10 00:25:05 +08:00
if ('dorbrs')
2023-10-09 17:55:52 +08:00
bs ]!! 0;
2023-10-10 00:25:05 +08:00
end
/*calculate bremer support*/
2023-10-10 00:25:05 +08:00
if ('dobrs')
macfloat 1; /*set the br value float*/
2023-10-09 17:55:52 +08:00
bsupport !! 0;
2023-10-10 00:25:05 +08:00
end
2023-10-10 00:25:05 +08:00
end
2023-10-10 00:35:15 +08:00
/*Choose final tree*/
tv<;
2023-10-10 00:25:05 +08:00
tchoose/;
2023-10-10 00:25:05 +08:00
/*adjust to zero following Pablo Goloboff*/
sub 0;
2023-10-09 17:00:29 +08:00
2023-10-10 00:25:05 +08:00
/*jakknifing*/
if ('dojak')
resample jak replications 1000 from 0; /*from 0 will orphan other trees*/
2023-10-10 00:25:05 +08:00
end
2023-10-10 00:25:05 +08:00
/*bootstrap*/
if ('doboot')
resample boot replications 1000 from 0;
end
2023-10-10 00:25:05 +08:00
/*symmetric resampling*/
if ('dosym')
resample sym replications 1000 from 0;
2023-09-13 20:57:13 +08:00
end
2023-02-27 01:24:22 +08:00
/*Export consensus tree with supports*/
2023-09-14 00:08:43 +08:00
ttags & %7.resample.svg thickness 7 italics fontsize 15;
log %7.resample.log;
quote /-------------resample tags start---------------\;
2023-07-19 19:47:57 +08:00
ttags/;
quote \-------------resample tags stop----------------/;
log/;
log + %7.tnt.log;
2023-09-14 00:08:43 +08:00
export < %7.resample.tre;
2023-02-26 03:32:18 +08:00
taxname-;
2023-09-14 00:08:43 +08:00
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*/
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: 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*/
2023-10-10 14:41:21 +08:00
/*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-;
2023-10-10 13:58:32 +08:00
/*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;
2023-02-27 01:24:22 +08:00
/*Report*/
quote
/----------------------------------------------\
| The analysis has been finished. |
| The file `tnt.log` contains |
2023-10-10 22:57:20 +08:00
| the performing details |
| The file `trees*.tre` contain |
| trees found by mult and xmult |
| The file `original*.tre` contain |
2023-10-10 00:49:27 +08:00
| 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 |
2023-10-10 22:57:20 +08:00
| is the tre file without taxname |
| The file `resample.svg` contain |;
2023-10-10 00:25:05 +08:00
if ('dostr')
quote
| strict consensus tree with |;
2023-09-13 20:57:13 +08:00
else
2023-10-10 00:25:05 +08:00
if ('domjr')
quote
| majority-rule consensus tree with |;
2023-10-10 00:25:05 +08:00
else
if ('dohlf')
quote
| half strict consensus tree with |;
2023-10-10 00:25:05 +08:00
end end end
2023-09-13 20:57:13 +08:00
2023-10-10 00:25:05 +08:00
if ('dorbrs')
quote
| relative bremer support |;
2023-10-10 00:49:27 +08:00
end
2023-10-10 00:25:05 +08:00
if ('dobrs')
quote
| bremer support |;
2023-10-10 00:49:27 +08:00
end
2023-10-10 00:25:05 +08:00
if ('dojak')
quote
| jackknifing |;
2023-10-10 00:49:27 +08:00
end
2023-10-10 00:25:05 +08:00
if ('doboot')
quote
| bootstrap |;
2023-10-10 00:49:27 +08:00
end
2023-10-10 00:25:05 +08:00
if ('dosym')
quote
| symmetric resampling |;
2023-10-10 00:49:27 +08:00
end
if ('doew')
quote
| under equal weighting |;
else
if ('doiw')
quote
2023-10-10 01:07:46 +08:00
| under implied weighting, |
2023-10-10 13:58:32 +08:00
| K value is 'kvalue' |;
2023-10-10 00:49:27 +08:00
else
if ('doeiw')
quote
| under extended implied weighting, |
2023-10-10 00:58:29 +08:00
| K value is 'kvalue' |;
2023-10-10 00:49:27 +08:00
end end end
2023-09-13 20:57:13 +08:00
quote
| The file `apo.svg` contains the |
| tree with apomorphy mapping |
| The file `report.log` contains the |
| CI RI TL publish-needed info |
2023-10-10 22:57:20 +08:00
| The file `resample/apo.log` contains |
| the tree tags text |
| The file `homo.log` contains the report |
2023-10-10 00:52:59 +08:00
| of character homoplasy |;
2023-10-10 00:49:27 +08:00
if ('doeiw')
2023-10-10 00:54:48 +08:00
quote
2023-10-10 22:57:20 +08:00
| The file `eiw.log` contains the report |
2023-10-10 13:58:32 +08:00
| of character concavities |;
2023-10-10 00:49:27 +08:00
end
2023-10-10 00:52:59 +08:00
quote
| The file `winclada.tre` can be |
| converted by tnt2winclada |
2023-10-10 13:58:32 +08:00
| The file `winclada.ss` can be read by |
| winclada directly |
\----------------------------------------------/;
2023-02-27 01:24:22 +08:00
/*Quit*/
zzz;
2023-10-10 16:24:48 +08:00
/*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/;