So I have this programme samtools that I want to use from cmd line, converting one file to another. It works like this:
bash-4.2$ samtools view filename.bam | awk '{OFS="\t"; print ">"$1"\n"$10}' - > filename.fasta
As I want to automate this, I would like to automate it by using an R script. I know you can use system() to run an OS command, but I cannot get it to work by trying
system(samtools view filename.bam | awk '{OFS="\t"; print ">"$1"\n"$10}' - > filename.fasta)
Is it just a matter of using regexes to get rid of spaces and stuff so the comma nd argument system(command) is readable? How do I do this?
EDIT:
system(“samtools view filename.bam | awk ‘{OFS=”\t”; print “>”$1″\n”$10}’ – > first_batch_1.fasta”)
Error: unexpected input in “system(“samtools view filename.bam | awk ‘{OFS=”\”
EDIT2:
system(“samtools view filename.bam | awk ‘{OFS=\”\t\”; print \”>\”$1\”\n\”$10}’ – > filename.fasta”)
awk: cmd. line:1: {OFS=" "; print ">"$1"
awk: cmd. line:1: ^ unterminated string
awk: cmd. line:1: {OFS=" "; print ">"$1"
awk: cmd. line:1: ^ syntax error
>
EDIT3:
And the winner is:
system("samtools view filename.bam | awk '{OFS=\"\\t\"; print \">\"$1\"\\n\"$10}' -> filename.fasta")
The way to debug this is to use
catto test whether your character string has been escaped correctly. So:xwith your stringcat(x)to inspect the resulting string.For example:
If this gives the correct string, then you should be able to use