Compare commits
14 commits
Author | SHA1 | Date | |
---|---|---|---|
a5c85911d0 | |||
561f88be60 | |||
6c05ec1de7 | |||
3c9cdd67e0 | |||
ec4fe0222b | |||
2609a4fbd4 | |||
e1154cb7c5 | |||
3b07034cda | |||
7d423e48de | |||
28292a5a74 | |||
945ba6882b | |||
bee830bd42 | |||
094422fe97 | |||
d395c8720f |
11 changed files with 435 additions and 74 deletions
54
3tnt.sh
Executable file
54
3tnt.sh
Executable file
|
@ -0,0 +1,54 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Found TNT
|
||||
|
||||
if [ -z "tnt" ]; then
|
||||
echo "TNT not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Define input data
|
||||
|
||||
input_file=$1
|
||||
|
||||
if [ -z "$input_file" ]; then
|
||||
echo "Usage: $0 <input_file> <guoyi.run>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Define tnt script
|
||||
|
||||
script_file=$2
|
||||
|
||||
if [ -z "$script_file" ]; then
|
||||
echo "Usage: $0 <input_file> <guoyi.run>"
|
||||
echo "Warning: guoyi.run will be set as /usr/share/tnt/tnt_scripts/guoyi.run"
|
||||
script_file="/usr/share/tnt/tnt_scripts/guoyi.run"
|
||||
fi
|
||||
|
||||
|
||||
# Define three weighting functions
|
||||
task1() {
|
||||
echo "Equal Weighting started"
|
||||
tnt run $script_file $input_file 3 ew 0 str 5 EW,
|
||||
echo "Equal Weighting completed"
|
||||
}
|
||||
|
||||
task2() {
|
||||
echo "Implied Weighting started"
|
||||
tnt run $script_file $input_file 3 iw 12 str 5 IW,
|
||||
echo "Implied Weighting completed"
|
||||
}
|
||||
|
||||
task3() {
|
||||
echo "Extended Implied Weighting started"
|
||||
tnt run $script_file $input_file 3 eiw 12 str 5 EIW,
|
||||
echo "Extended Implied Weighting completed"
|
||||
}
|
||||
|
||||
task1
|
||||
task2
|
||||
task3
|
||||
|
||||
echo "All tasks completed"
|
||||
|
|
@ -1,15 +1,13 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
project(tnt2winclada)
|
||||
project(tnt_script)
|
||||
SET( CMAKE_EXPORT_COMPILE_COMMANDS ON )
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_executable(tnt2winclada tnt2winclada.cpp)
|
||||
add_subdirectory(src_tnt2winclada)
|
||||
add_subdirectory(src_tnt2figtree)
|
||||
|
||||
target_compile_options(tnt2winclada PRIVATE -Wall -Wextra -pedantic)
|
||||
|
||||
install(TARGETS tnt2winclada DESTINATION /usr/bin)
|
||||
install(FILES guoyi.run DESTINATION /usr/share/tnt/tnt_scripts)
|
||||
install(FILES LICENSE DESTINATION /usr/share/licenses/tnt2winclada)
|
||||
install(FILES README.md DESTINATION /usr/share/doc/tnt2winclada)
|
||||
install(FILES LICENSE DESTINATION /usr/share/licenses/tnt-guoyi-script)
|
||||
install(FILES README.md DESTINATION /usr/share/doc/tnt-guoyi-script)
|
||||
|
|
66
README.md
66
README.md
|
@ -1,7 +1,5 @@
|
|||
# guoyi.run
|
||||
|
||||
[](https://doi.org/10.5281/zenodo.8428198)
|
||||
|
||||
TNT Script for Maximum Parsimony Analysis (Phylogeny)
|
||||
|
||||
## Usage
|
||||
|
@ -58,7 +56,9 @@ tnt run guoyi.run filename datatype weight 0/K cons resample prefix,
|
|||
|
||||
- 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)
|
||||
- relative bremer support (rbrs)=0.1, bremer support (brs)=0.2, jackknifing (jak)=1, bootstrap (boot)=2, symmetric resampling (sym)=4 i.e. jak+boot+sym=7 (default)
|
||||
|
||||
- Notice: Bremer related support would change the tree topology, so it should be used with caution.
|
||||
|
||||
- prefix can be empty or a string
|
||||
|
||||
|
@ -80,9 +80,9 @@ tnt run guoyi.run filename datatype weight 0/K cons resample prefix,
|
|||
|
||||
- `apo.tre` is the apomorphic character mapping tree.
|
||||
|
||||
- `resample.tre` is the consensus tree with support.
|
||||
- `resample.tre` is the consensus tree with support, which can be read by figtree after processing by tnt2figtree.
|
||||
|
||||
- `trees*.tre` contains he MPTs.
|
||||
- `trees*.tre` contains he MPTs, which can be read by figtree after processing by tnt2figtree.
|
||||
|
||||
- `resample/apo.log` contains the tree tags.
|
||||
|
||||
|
@ -100,58 +100,8 @@ tnt run guoyi.run filename datatype weight 0/K cons resample prefix,
|
|||
|
||||
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.
|
||||
|
|
34
guoyi.run
34
guoyi.run
|
@ -111,7 +111,7 @@ end
|
|||
|
||||
/*handle resmaple type*/
|
||||
if (argnumber<6)
|
||||
set dojak 1; set doboot 1; set dosym 1; set dorbrs 1;
|
||||
set dojak 1; set doboot 1; set dosym 1; set dorbrs 0;
|
||||
else
|
||||
set rsmp %6;
|
||||
loop 1 5
|
||||
|
@ -356,7 +356,6 @@ 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=;
|
||||
|
@ -377,20 +376,21 @@ if ('dobremer')
|
|||
|
||||
/*calculate relative bremer support*/
|
||||
if ('dorbrs')
|
||||
bs ]!! 0;
|
||||
bs ]!! 0.'npars';
|
||||
end
|
||||
|
||||
/*calculate bremer support*/
|
||||
if ('dobrs')
|
||||
macfloat 1; /*set the br value float*/
|
||||
bsupport !! 0;
|
||||
bsupport !! 0.'npars';
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
/*Choose final tree*/
|
||||
tchoose 0.'npars';
|
||||
tv<;
|
||||
tchoose/;
|
||||
tchoose /;
|
||||
|
||||
/*adjust to zero following Pablo Goloboff*/
|
||||
sub 0;
|
||||
|
@ -426,6 +426,10 @@ taxname=;
|
|||
|
||||
/*Export consensus tree*/
|
||||
tchoose /;
|
||||
ttags=;
|
||||
tp/;
|
||||
ttags & %7.original.svg thickness 7 italics fontsize 15;
|
||||
ttags-;
|
||||
export - %7.original.tre;
|
||||
taxname-;
|
||||
export - %7.original_no.tre;
|
||||
|
@ -463,13 +467,21 @@ 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*/
|
||||
if ('themax' != 'themin')
|
||||
set RI ('themax'-'TL')/('themax'-'themin'); /*RI=1 character fits perfetcly*/
|
||||
else
|
||||
set RI 999;
|
||||
end
|
||||
|
||||
/*Report CI/RI/TL */
|
||||
log %7.report.log;
|
||||
macfloat 3;
|
||||
quote Consistency Index (CI) is 'CI';
|
||||
quote Retention Index (RI) is 'RI';
|
||||
if ('RI' == 999)
|
||||
quote Retention Index (RI) is NA;
|
||||
else
|
||||
quote Retention Index (RI) is 'RI';
|
||||
end
|
||||
quote Tree Length (TL) is 'TL';
|
||||
log/;
|
||||
|
||||
|
@ -537,7 +549,11 @@ if ('dohlf')
|
|||
quote
|
||||
| half strict consensus tree with |;
|
||||
end end end
|
||||
|
||||
if ('dobremer')
|
||||
quote
|
||||
| WARNING: bremer-related will |
|
||||
| WARNING: change the polytomy |;
|
||||
end
|
||||
if ('dorbrs')
|
||||
quote
|
||||
| relative bremer support |;
|
||||
|
|
7
runwincladtree.run
Normal file
7
runwincladtree.run
Normal file
|
@ -0,0 +1,7 @@
|
|||
macro=;
|
||||
taxname+5000;
|
||||
p %1;
|
||||
ttags=;
|
||||
apo>0;
|
||||
wincladtree %1.wincladtree.svg noalign shade rotate squaresize 15 taxangle 0;
|
||||
zzz;
|
14
src_tnt2figtree/CMakeLists.txt
Normal file
14
src_tnt2figtree/CMakeLists.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
project(tnt2figtree)
|
||||
SET( CMAKE_EXPORT_COMPILE_COMMANDS ON )
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_executable(tnt2figtree tnt2figtree.cpp)
|
||||
|
||||
target_compile_options(tnt2figtree PRIVATE -Wall -Wextra -pedantic)
|
||||
|
||||
install(TARGETS tnt2figtree DESTINATION /usr/bin)
|
||||
install(FILES ../LICENSE DESTINATION /usr/share/licenses/tnt2figtree)
|
||||
install(FILES README.md DESTINATION /usr/share/doc/tnt2figtree)
|
55
src_tnt2figtree/README.md
Normal file
55
src_tnt2figtree/README.md
Normal file
|
@ -0,0 +1,55 @@
|
|||
# TNT2FigTree
|
||||
|
||||
```
|
||||
~|~|\ |~|~~)|~o(~|~|~._ _ _
|
||||
| | \| | /_|~| _| | | }_}_
|
||||
|
||||
MIT, Guoyi Zhang, 2024
|
||||
```
|
||||
|
||||
## Function
|
||||
|
||||
Convert TNT output tree file with resample tags, e.g. `resample.tre` produced by TNT script `guoyi.run`, to complete nexus format tree.
|
||||
|
||||
## Compile
|
||||
|
||||
### Linux & Unix
|
||||
|
||||
```
|
||||
mkdir -p build && cd build
|
||||
cmake ..
|
||||
make && make install
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
```
|
||||
cl /EHsc tnt2figtree.cpp
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
tnt2figtree ${input_file} ${output_file}
|
||||
```
|
||||
|
||||
Interactive commands are also available.
|
||||
|
||||
```
|
||||
tnt2figtree
|
||||
|
||||
~|~|\ |~|~~)|~o(~|~|~._ _ _
|
||||
| | \| | /_|~| _| | | }_}_
|
||||
TNT2FigTree
|
||||
MIT, Guoyi Zhang, 2024
|
||||
please type help to see more commands
|
||||
|
||||
tnt2figtree> help
|
||||
help show interactive commands help
|
||||
import <filename> import a TNT output nexus format tree by TNT export command
|
||||
export <filename> export a nexus format tree file
|
||||
quit quit the program
|
||||
exit exit the program
|
||||
|
||||
tnt2figree>
|
||||
```
|
198
src_tnt2figtree/tnt2figtree.cpp
Normal file
198
src_tnt2figtree/tnt2figtree.cpp
Normal file
|
@ -0,0 +1,198 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
|
||||
std::string remove_useless(std::string input_str1)
|
||||
{
|
||||
std::string result_str1 =
|
||||
std::regex_replace(input_str1, std::regex(" /*"), " ");
|
||||
result_str1 = std::regex_replace(result_str1, std::regex("\\["), "{");
|
||||
result_str1 = std::regex_replace(result_str1, std::regex("\\]"), "}");
|
||||
return result_str1;
|
||||
}
|
||||
|
||||
std::string add_support(std::string input_str2)
|
||||
{
|
||||
std::string result_str2 = "";
|
||||
size_t i = 0;
|
||||
while (i < input_str2.length()) {
|
||||
if (input_str2[i] == ')') {
|
||||
result_str2 += input_str2[i];
|
||||
i++;
|
||||
std::string support_str = "";
|
||||
while (i < input_str2.length() &&
|
||||
std::regex_match(std::string(1, input_str2[i]),
|
||||
std::regex("[/0-9{}?]"))) {
|
||||
support_str += input_str2[i];
|
||||
i++;
|
||||
}
|
||||
result_str2 += "[&support=\"" + support_str + "\"]";
|
||||
}
|
||||
else {
|
||||
result_str2 += input_str2[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return result_str2;
|
||||
}
|
||||
|
||||
std::string add_blen(std::string input_str3)
|
||||
{
|
||||
std::string result_str3 = "";
|
||||
int i = 0;
|
||||
for (char c : input_str3) {
|
||||
if (c == '(') {
|
||||
i++;
|
||||
result_str3 += c;
|
||||
}
|
||||
else if (c == ')') {
|
||||
result_str3 += ":" + std::to_string(i) + c;
|
||||
i--;
|
||||
}
|
||||
else if (c == ',') {
|
||||
result_str3 += ":" + std::to_string(i) + c;
|
||||
}
|
||||
else {
|
||||
result_str3 += c;
|
||||
}
|
||||
}
|
||||
return result_str3;
|
||||
}
|
||||
|
||||
std::string remove_slash(std::string input_str4)
|
||||
{
|
||||
std::string result_str4 = std::regex_replace(
|
||||
input_str4, std::regex("\\[&support=\"[\\/\\s]*\"\\]"), "");
|
||||
return result_str4;
|
||||
}
|
||||
|
||||
std::vector<std::string> get_lines(std::string filename)
|
||||
{
|
||||
std::ifstream file(filename);
|
||||
if (!file.is_open()) {
|
||||
std::cout << "Failed to open the input file." << std::endl;
|
||||
}
|
||||
|
||||
std::vector<std::string> lines;
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
lines.push_back(line);
|
||||
}
|
||||
file.close();
|
||||
return lines;
|
||||
}
|
||||
|
||||
std::vector<std::string> process_line(std::vector<std::string> lines,
|
||||
size_t lineNum)
|
||||
{
|
||||
std::string line = remove_useless(lines[lineNum]);
|
||||
line = add_blen(line);
|
||||
line = add_support(line);
|
||||
|
||||
lines[lineNum] = remove_slash(line);
|
||||
return lines;
|
||||
}
|
||||
|
||||
void write_lines(const std::vector<std::string>& lines,
|
||||
const std::string& filename)
|
||||
{
|
||||
std::ofstream outfile(filename);
|
||||
|
||||
if (!outfile.is_open()) {
|
||||
std::cout << "Failed to open the output file." << std::endl;
|
||||
}
|
||||
|
||||
for (const std::string& line : lines) {
|
||||
outfile << line << std::endl;
|
||||
}
|
||||
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
void interactive_commands(std::vector<std::string> lines)
|
||||
{
|
||||
std::string command, filename1, filename2;
|
||||
std::cout
|
||||
<< "~|~|\\ |~|~~)|~o(~|~|~._ _ _\n | | \\| | /_|~| _| | | }_}_"
|
||||
<< std::endl;
|
||||
std::cout << "TNT2FigTree\nMIT, Guoyi Zhang, 2024\nplease type help "
|
||||
"to see more commands"
|
||||
<< std::endl;
|
||||
while (true) {
|
||||
std::cout << "tnt2figtree> ";
|
||||
getline(std::cin, command);
|
||||
if (command == "help") {
|
||||
std::cout << "help\t\t\tshow interactive commands "
|
||||
"help\nimport <filename>\timport a TNT "
|
||||
"output nexus format tree by TNT export "
|
||||
"command\nexport <filename>\texport a "
|
||||
"nexus format tree file\nquit\t\t\tquit "
|
||||
"the program\nexit\t\t\texit the program"
|
||||
<< std::endl;
|
||||
}
|
||||
else if (command.find("import ") == 0) {
|
||||
std::stringstream ss(command.substr(7));
|
||||
ss >> filename1;
|
||||
if (filename1.empty()) {
|
||||
std::cout << "tnt2figtree> please specify a "
|
||||
"filename."
|
||||
<< std::endl;
|
||||
}
|
||||
else {
|
||||
lines = get_lines(filename1);
|
||||
}
|
||||
}
|
||||
else if (command.find("export ") == 0) {
|
||||
std::stringstream ss(command.substr(7));
|
||||
ss >> filename2;
|
||||
if (filename2.empty()) {
|
||||
std::cout << "tnt2figtree> please specify a "
|
||||
"filename."
|
||||
<< std::endl;
|
||||
}
|
||||
else {
|
||||
for (size_t i = 0; i < lines.size(); i++) {
|
||||
if (lines[i][0] == '(') {
|
||||
lines = process_line(lines, i);
|
||||
}
|
||||
}
|
||||
write_lines(lines, filename2);
|
||||
}
|
||||
}
|
||||
else if (command == "quit" || command == "exit") {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
std::cout << "tnt2figtree> unrecognized command. Type "
|
||||
"'help' for "
|
||||
"a list of commands."
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
if (argc == 1) {
|
||||
interactive_commands(lines);
|
||||
return 0;
|
||||
}
|
||||
else if (argc == 3) {
|
||||
lines = get_lines(argv[1]);
|
||||
for (size_t i = 0; i < lines.size(); i++) {
|
||||
if (lines[i][0] == '(') {
|
||||
lines = process_line(lines, i);
|
||||
}
|
||||
}
|
||||
write_lines(lines, argv[2]);
|
||||
}
|
||||
else {
|
||||
std::cout << "Usage: " << argv[0]
|
||||
<< " <input_tnt_treefile> <output_nexus_treefile>"
|
||||
<< std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
14
src_tnt2winclada/CMakeLists.txt
Normal file
14
src_tnt2winclada/CMakeLists.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
project(tnt2winclada)
|
||||
SET( CMAKE_EXPORT_COMPILE_COMMANDS ON )
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_executable(tnt2winclada tnt2winclada.cpp)
|
||||
|
||||
target_compile_options(tnt2winclada PRIVATE -Wall -Wextra -pedantic)
|
||||
|
||||
install(TARGETS tnt2winclada DESTINATION /usr/bin)
|
||||
install(FILES ../LICENSE DESTINATION /usr/share/licenses/tnt2winclada)
|
||||
install(FILES README.md DESTINATION /usr/share/doc/tnt2winclada)
|
55
src_tnt2winclada/README.md
Normal file
55
src_tnt2winclada/README.md
Normal file
|
@ -0,0 +1,55 @@
|
|||
# TNT2WinClada
|
||||
|
||||
```
|
||||
~|~|\ |~|~ ~) | |o._ |~| _ _| _
|
||||
| | \| | /_ \/\/ || ||_|(_|(_|(_|
|
||||
|
||||
MIT, Guoyi Zhang, 2023
|
||||
```
|
||||
|
||||
## Function
|
||||
|
||||
Convert TNT output tree file without tags and taxname, e.g. `winclada.tre` produced by TNT script `guoyi.run`, to WinClada acceptable format tree.
|
||||
|
||||
## Compile
|
||||
|
||||
### Linux & Unix
|
||||
|
||||
```
|
||||
mkdir -p build && cd build
|
||||
cmake ..
|
||||
make && make install
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
```
|
||||
cl /EHsc tnt2winclada.cpp
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
tnt2winclada -i ${input_file} -o ${output_file}
|
||||
```
|
||||
|
||||
Interactive commands are also available.
|
||||
|
||||
```
|
||||
tnt2winclada
|
||||
|
||||
~|~|\ |~|~ ~) | |o._ |~| _ _| _
|
||||
| | \| | /_ \/\/ || ||_|(_|(_|(_|
|
||||
TNT2WinClada
|
||||
MIT, Guoyi Zhang, 2023
|
||||
please type help to see more commands
|
||||
|
||||
tnt2winclada> help
|
||||
help show interactive commands help
|
||||
input <filename> input a TNT output tree from the specified file
|
||||
output <filename> output a winclada accessible tree file
|
||||
quit quit the program
|
||||
exit exit the program
|
||||
|
||||
tnt2winclada>
|
||||
```
|
Loading…
Add table
Reference in a new issue