0

I have an R script I am trying to run through in a bash script but im not sure how to make the two compatible my R script(seq_trimming.R):

#!/usr/bin/Rscript

input <- file('stdin','r')
row <- readLines(input, n=1)
while (length(row)>0) {


#loading reads
#path needs to go to .ab1 
seq.filepath = row 
seq.abif = read.abif(seq.filepath)
seq.sanger = sangerseq(seq.abif)

#trimming low quality bases
#you can control the severity of the trim by usuing (seq.abif, 0.01) the     higher the number the less amount of bases are trimmed
trims = trim.mott(seq.abif, 0.001)
trims
}

while my bash script is

ls *.ab1 | while read line
do
cd ../../sanger_analysis | Rscript seq_trimming.R $line >../../sanger_analysis/trim_$line
done

my goal is to be able to take a group of ab1 files in a folder and put them through this script and get the trimmed sequences out

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
  • Is the problem that your R script doesn't get your $line variable, i.e. the command line argument? – xxfelixxx May 30 '18 at 07:33
  • do `args <- commandArgs()`, then `$line` would be `args[1]` inside your R script. – xxfelixxx May 30 '18 at 07:36
  • https://stackoverflow.com/questions/2151212/how-can-i-read-command-line-parameters-from-an-r-script – xxfelixxx May 30 '18 at 07:36
  • `stdin` in this case is the output of `cd`, which is nothing. You shouldn't need `cd` at all since this is working on all of the files in the current directory. – heathobrien May 30 '18 at 09:02

0 Answers0