This is a test version of Biostars. For the public version, visit https://www.biostars.org.
system commands from R containing single and double quotes

Hi all,

I have a system command which works fine from terminal;

samtools mpileup -r chr1:1-100 -B -Q 0 input.sort.bam | awk '{gsub("[^^]","",$5);print length($5)}' > ./output.txt

I would like to implement this from R, but can't figure out how to work around the requirement to have both single(') and double(") quotes within a string, as using an escaped quote (\') or (\") won't work as a system command;

sys.cmd <- paste0("samtools mpileup -r ",locus.of.interest," -B -Q 0 ",input.sort.bam,"|awk '",'{gsub("[^^]","",$5);print length($5)}',"'")
print(sys.cmd)
"samtools mpileup -r chr1:1-100 -B -Q 0 input.sort.bam | awk '{gsub(\"[^^]\",\"\",$5);print length($5)}'"
sys.output <- system(sys.cmd, intern=TRUE) # DOES NOT WORK BECAUE OF (\")

Any advice? Thanks!!!

r bash

Have you looked at rsamtools? I am not sure if it has the functionality you are looking for, I just now it exists, and that such solutions are likely to be less tricky than the system call that you are trying here.

Thanks! I'l try to implement the same with rsamtools/R ...but, I'm still really curious how to solve my initial problem

0 answers

No answers yet.

Log in to answer this question.