Accessing filenames inside a script

75 views
Skip to first unread message

Evgeny Shcherbakov

unread,
Aug 2, 2015, 8:29:10 PM8/2/15
to TNT-Tree Analysis using New Technology
Hello!

Could someone kindly help me with a very frustrating problem?
I want to analyze many different datasets under several parameters and write the results under the corresponding filename, but with different extensions.
I have files with names like dataset.tnt, each with a matrix and weights.
I want to save after each analysis trees, metafiles, logs, nexus files under the names dataset.tre, dataset.emf etc.

The problem is, I can't find a way to access the filename as a string inside my script. I pass it to the script as

run script.run dataset.tnt

and inside the script the file itself could be passed to the commands as %1. But I want to set the string variables, each with the filename of dataset + different extensions, something like this:

set matrix_file name of the dataset file (dataset.tnt)
set log_file (matrix_file + $.out)

I tried $%1, wrapping the whole script in forfiles command and using $curfile inside, nothing works. Either TNT tries to read it as a variable, or (in case of using $curfile) give matrix_file value "0.00000", not the filename of dataset.
If I don't find a solution, I will need to input all the filenames manually, which ruins the benefit of the scripting...

Martín Ramírez

unread,
Aug 3, 2015, 11:36:21 AM8/3/15
to TNT-Tree Analysis using New Technology
Hello Evgeny, 

I usually make a configuration file with the hard variables. For example, there is a file config.txt containing stuff like: 

set SettingMinMax $Min; /* this can be Min Max Avg */
set MatrixNameBase $MyMatrixBase;
proc/;

Then the main script will have something like:

var: 
SettingMinMax[32]
var: rootpath[32]
MatrixNameBase[32]
;

proc config.txt; /* this loads the hard variables */

proc $(MatrixNameBase).tnt; /* this loads the dataset */
proc trees\$(MatrixNameBase).tre; /* this loads the trees, from a folder trees\ */

/* this is en example of processing text arguments from the config.txt file */
if ( isinstring [ $(SettingMinMax) Min ] == 3 )  
... here do something for the setting Min ...


I hope it helps!

Cheers, 

Martín

Evgeny Shcherbakov

unread,
Aug 9, 2015, 7:46:49 PM8/9/15
to TNT-Tree Analysis using New Technology
Dear Martin,

many thanks for the reply!
I tried your method, but it doesn't work for me.
I made a config file matrixconf.tnt with

set matrixnamebase $basematrix ;
proc / ;

then pass its name from inside the main script to the script which actually does the analyses:

var: matrixconfigname[32] ;
set matrixconfigname $matrixconf.tnt ;
run work_script.run $(matrixconfigname) ;

(it is redundant here, but I have many files, so I need to test a principle, as there will be a different config file for each matrix)

Then, in work_script.run:

var: matrixnamebase[32] logfname[32] ...etc. ;

proc %1 ;

proc $(matrixnamebase).tnt ;

work_script.run apparently reads the config file correctly but fails to assign the value to matrixnamebase set in the config file. So at line "proc $(matrixnamebase).tnt ;" TNT displays an error "Can't open file .tnt", because variable matrixnamebase remains undefined.
work_script also correctly reads the matrix itself at line "proc %1" if it is passed to it instead of the config file, but, again, I can't get the filename out of %1 (even though it is technically a string) to create different strings for other files... The transfer of setting the hard variables to the matrix file has similarly no effect.
I guess I'll have to use extremely standardized filenames inside a loop, but that's a pity.

Martín Ramírez

unread,
Aug 10, 2015, 8:25:49 AM8/10/15
to tnt-tree-analysis-u...@googlegroups.com
Hi Evgeny, 

well, it look scomplicated! It is better to test with tiny scripts first, just to get it to work. It also helps adding some report lines (quote) to see what's going on: 

quote string in matrixnamebase: $(matrixnamebase);
proc $(matrixnamebase).tnt ;

quote it works up to here; 

good luck!

Martín

--
Has recibido este mensaje porque estás suscrito al grupo "TNT-Tree Analysis using New Technology" de Grupos de Google.
Para anular la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a tnt-tree-analysis-using-n...@googlegroups.com.
Para publicar en este grupo, envía un correo electrónico a tnt-tree-analysis-u...@googlegroups.com.
Visita este grupo en http://groups.google.com/group/tnt-tree-analysis-using-new-technology.
Para acceder a más opciones, visita https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages