gravatar for joe

3 hours ago by

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!!!

link

modified 2 hours ago

written
3 hours ago
by

joe170



Source link