Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: How to embed a tool in my script

by angel_perl (Initiate)
on Feb 12, 2012 at 13:43 UTC ( #953311=note: print w/ replies, xml ) Need Help??


in reply to Re: How to embed a tool in my script
in thread How to embed a tool in my script

Thanks @Darren, will the code look like this? and also i want the output to be printed for respective files as different files in different directory

my $dir = '/path/to/dir'; # read only pd files: opendir DIR, $dir or die "read dir $dir - $!"; my @pdb_files = grep /\.pdb/, readdir DIR; closedir DIR; foreach my $file (@pdb_files) { open( FH,"$dir\\$file") while(<FH>) { $output_from_my_precompiled_tool = `/path/to/my/tool $file`; } close(FH); }


Comment on Re^2: How to embed a tool in my script
Download Code
Re^3: How to embed a tool in my script
by McDarren (Abbot) on Feb 12, 2012 at 16:48 UTC
    Well, no. Probably not.

    I'm not exactly clear whether you want to pass each entire file to your external tool, or whether you want to open each file and then pass it line by line. I guess probably the former. If that's the case, then perhaps this example will help.

    $ echo 'some text' > 1.pdb $ echo 'some more text' > 2.pdb
    Lets say for example your external tool is /bin/cat, and you want to cat each file and capture the output.
    $ cat foo.pl #!/usr/bin/perl use strict; use warnings; my $dir = '.'; my $cat = '/bin/cat'; opendir DIR, $dir or die "Cannot open directory $dir:$!\n"; my @pdb_files = grep { -f $_ && $_ =~ /\.pdb$/ } readdir DIR; closedir DIR; for my $file (@pdb_files) { my $content = `$cat "$dir/$file"`; chomp $content; print "Content of $file is $content\n"; }
    $ perl foo.pl Content of 1.pdb is some text Content of 2.pdb is some more text
    That should be enough to get you going?

      Sorry @Darren the program doesn't seems to work because its asking for two input files first input file is the exterior script(written already)and the second input is the PDB files. So,i think incorporating a function which calls the script file first followed by the PDB files will help. So, could you please tell me how to do this?

        I'm sorry, but I'm a bit lost.

        I understand that English might not be your first language, but you're not doing a very good job of explaining what you need (no offense intended).

        This is what I understand from your posts so far:

        • You have a number of files with a .pdb extension
        • You have a tool that processes these files in some way
        • You want to use perl to feed these files to this tool
        Now, assuming that the above is correct - I have a couple of questions for you.
        Firstly, how do these files need to be passed to your external tool? Do you need to a) just pass the name and location of the file, or b) open the file within perl and then pass it line by line?

        And secondly, does this external tool produce any output? And if it does, what should be done with that output?

        Perhaps if you can describe as best you can the steps you would take if you were going to process one of these files manually (from start to finish), then that might help me to understand a bit better what it is you need.

      will the code look like this? after embedding the external script ?

      #!/usr/bin/perl use strict; use warnings; my $dir = '.'; #for embeding the mcsearch percompile version my $mcsearch = '/bin/mcsearch'; #to read the PDB files from the directory opendir DIR, $dir or die "Cannot open directory $dir:$!\n"; my @pdb_files = grep { -f $_ && $_ =~ /\.pdb$/ } readdir DIR; closedir DIR; print "Enter the script file"; $a=<>; open(IN,$a) or die; #giving each file as a input to mcsearch for my $file (@pdb_files) { while(<>) { my $content = `$mcsearch "$dir/$file"`; chomp $content; print "Content of $file is $content\n"; } }

      http://www.major.iric.ca/MajorLabEn/MC-Tools_files/MC-Annotate.zip here is the tool, i want to embed this tool and give the inputs to the tool, the web version of this tool looks like http://www.major.iric.ca/MC-Search/

      So looking at the web version i was trying to provide two inputs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://953311]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-07-11 06:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (220 votes), past polls