system commands from R containing single and double quotes
0
0
Entering edit mode
3.2 years ago
joe ▴ 500

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 • 716 views
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1926 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6