0

Im a beginer in R

I don't know how to import my shell variable into R.

read -p " enter the Read :" r1

tabix -h -R Reference/Covered_region.bed output/"$r1"/"$r1".vcf.gz > output/"$r1"/Covered_"$r1".vcf

perl convert2annovar.pl -format vcf4 output/"$r1"/Covered_"$r1".vcf -outfile output/"$r1"/Covered_"$r1".avinput -includeinfo -withzyg

perl table_annovar.pl output/"$r1"/Covered_"$r1".avinput humandb/ -buildver hg38 -out output/"$r1"/"$r1"_GATK.hg38_multianno.csv -csvout

now i want to import the last out out put of my perl script output/"$r1"/"$r1"_GATK.hg38_multianno.csv into R

my R script looks like

library(readr)

test <- read_csv("/output/"$r1"/"$r1"_GATK.hg38_multianno.csv")
data= test[!duplicated(as.list(test))]
filtering= data[data$`1000g2015aug_all` <=0.01,]
write.csv(data,"output/"$r1"/"$r1".csv",row.names = F)
  • 1
    I'm confused, are you using `perl` or `R`? Because your R code also doesn't look very much like R. R doesn't use `$` for variables. How are you calling the R script exactly? Are you using `Rscript` with parameters? Or how does that interact with perl? – MrFlick May 18 '21 at 05:06
  • I'm using Perl inside my shell scripts. the user has to enter the file name. which I use as the input for the program. The shell script contains a lot of other programmings, I want use the output of the Perl which will be in the CSV file into R and it wants to do filter and remove duplicates. from the CSV file. – Manojkumar K May 18 '21 at 06:02
  • So, if I understand correctly, you want to provide arguments from bash into R? If so, is the answer in the following links: [1](https://stackoverflow.com/questions/4547789/command-line-arguments-in-bash-to-rscript), [2](https://stackoverflow.com/questions/2151212/how-can-i-read-command-line-parameters-from-an-r-script) – slamballais May 18 '21 at 06:05
  • I have added few more lines of my programming above. currently, for using the output name in getting the variable from the name as the input. I don't want to change the file name. finally, I'm ending with a CSV file. which will the input for my R. Currently I'm importing the file manually is there any way to import my file in a pipeline. for example, I have store the above R script. and sun as `R test.r filename' – Manojkumar K May 18 '21 at 06:45

1 Answers1

0

library(readr)

#importing data

args <- commandArgs(TRUE)

filename <-args[1]

filename1 <-args[2]

testdata <- read_csv(filename)

data= testdata[!duplicated(as.list(testdata))]

filtering= data[data$`1000g2015aug_all` <=0.01,]

write.csv(data,paste0(filename1,".csv"),row.names = F)

Use Rscript Filtering_variants.r test1.csv out 2>out_error.txt