This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how to incorporate R script in perl program and then run it from perl

I wanna know how to run fully functional R scripts in from perl command line interpreter using the output of perl. All I have is a perl scripts which perform certain calculations and gives output in specific length of nucleotide sequence, I have to use those nucleotide sequence file as an input in R script and run in perl and get an output in a graphical format. I request if anybody can post a working example or guide me on the same seeing which it i can implement it in my program. this is the example which i followed whole running R from perl command line

use Statistics::R ;

my $R = Statistics::R->new() ;

$R->startR ;

$R->send(q`postscript("file.ps" , horizontal=FALSE , width=500 , height=500 , pointsize=1)`) ;
$R->send(q`plot(c(1, 5, 10), type = "l")`) ;

$R->send(qq`x = 123 \n print(x)`) ;
my $ret = $R->read ;

$R->stopR() ;

please help me out with this. Thanks in advance

r programming perl both r and perl intergrated

Hi , I think your question is about informatics and not bio-informatics. If i understand well your question the think your are looking for is how after generation of output file from perl you can use it on R. You can run a R script from perl using `` with your file generating as an argument .

Best

If you truly need to run R within Perl, you may want to look up the system function in Perl. You could write your R script to do all the calculations it needs, and call it from your Perl script with system('Script.R'). However, a more "correct" and adaptable way would probably be to write two independent scripts and use the output file from your Perl script as input for your R script.

Hello kriti.awasthi23!

We believe that this post does not fit the main topic of this site.

As Titus says, this is not strictly bioinformatics.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

Hello Ram, I simply don't understand on what parameters you people decide whether it is a bioinformatics question or not? Bio+ informatics makes it whole of a bioinformatics any question relevant to it is a bioinformatics question. I was struck in a real problem which could have had working suggestions. My question would be a question to many because its quite obvious if you are designing perl and R scripts which i hope is a "Bioinformatics" part. Thanks to those who replied and helped me solve my problem.

In my opinion, perl + R makes it computer science - there is not even the volume of biological data that gives questions of this kind a bioinformatics flavor. You're looking at a string length calculator whose output needs to be used in an R script.

I am open to reversing my decision, of course. Please convince me, and I'll gladly reopen the question. ICYMI, I have also provided some input in the answer below.

1 answer

what I would do is to call your R script from perl with the different arguments:

my $var1 = "file1.fa";
my $var2 = "file2.fa";

my $command = "Rscript nucleotide.R --file1 $var1 --file2 $var2";
system($command);

I modified your post to add code formatting (using the 101010 button), making things far easier to read. Please take this into account next time.

sir, thankyou so much for making me understand, but you are taking 2 fasta files whereas my query is suppose there is a length of motif file say 6 length motif file eg "AAAAAA AAATGC AATCGT" is saved in an array @array now I request you to read this file in R and run it. This my problem basic text and .csv files I am able to upload what is not clear to me how to make perl variables read in R?

Pass it in as a quoted string?

It should not be difficult reshaping the script above. Start with the R command, backtrack to the Rscript, then convert that to a perl line.

Running an R script via Rscript and system() is the way to go. If you ever use other scripting languages (Python, etc.) then you can reuse the R-based pipeline without rewriting the entire procedure.

Log in to answer this question.