Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8196143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:23:02+00:00 2026-06-07T05:23:02+00:00

So I have this programme samtools that I want to use from cmd line,

  • 0

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")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:23:04+00:00Added an answer on June 7, 2026 at 5:23 am

    The way to debug this is to use cat to test whether your character string has been escaped correctly. So:

    1. Create an object x with your string
    2. Carefully escape all the special characters, in this case quotes and backslashes
    3. Use cat(x) to inspect the resulting string.

    For example:

    x <- 'samtools view filename.bam | awk \'{OFS="\\t"; print ">"$1"\\n"$10}\' - > filename.fasta'
    
    cat(x)
    samtools view filename.bam | awk '{OFS="\t"; print ">"$1"\n"$10}' - > filename.fasta
    

    If this gives the correct string, then you should be able to use

    system(x)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this line samtools view -h file | awk '$3==chr$a || /^@/' |
I have an access macro, that I want to run automatically from a batch
Scala programmer should have known that this sort of writing : class Person{ var
I have this program that should execute a piece of code base on the
I have this program that I am working on for class, I think the
I have this simple program that computes salaries for four different worker types. It's
I have application use SDF file and I use System.Data.SqlServerCe, Version 3.5.0.0 I make
I have this code from the PIL-handbook but I get an error message. from
I want to write a programme (in python) on Linux (Ubuntu Linux 9.10) that
Here is my programme, which have a two threads, one is listening user input,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.