Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • running samtools in shell script

    hi
    I am trying to run this shell script
    Code:
    for a in {seq 1 22}
    samtools view -h file.bam | awk '$3=="chr$a" || /^@/' | samtools view -S - -b -o Chr$a.bam
    done
    when I do it on the command line it works like a charm, but when i try to throw it in a shell it doesn't give any output. Any ideas?

  • #2
    You should specify whether you're using bash, tcsh, or something else. I recall that for bash your syntax is wrong. Also, I imagine you should escape the $3 since that could otherwise cause some issues.

    Comment


    • #3
      I don't have any help for why your script didn't run, but I can tell you that
      samtools can do what you want by itself.

      Code:
      for a in {1..22}; do 
        samtools view -b file.bam chr$a -o Chr$a.bam
      done
      Or, better yet, pipe the result of that "samtools view file region" command to the next step of the analysis instead of creating a bunch of new bam files.

      Comment


      • #4
        HTML Code:
        You should specify whether you're using bash, tcsh, or something else. I recall that for bash your syntax is wrong. Also, I imagine you should escape the $3 since that could otherwise cause some issues.
        i am using bash. The entire command is below:
        Code:
        for a in {1..22}
        do
              samtools view -h AD3.sorted.bam | awk '$3=="chr$a" || /^@/' | samtools view -S - -b -o chr$a.bam
        done
        Last edited by zorph; 03-02-2012, 06:35 AM.

        Comment


        • #5
          For me, the awk command doesn't work even from the command line. The single quotes prevent bash from expanding "chr$a" to (e.g.) "chr1". Awk is looking for the third column to literally match "chr$a".

          I did this to get the awk command to work:

          Code:
          awk -v a=$a '$3==sprintf("chr%s",a) || /^@/ '

          Comment

          Latest Articles

          Collapse

          • seqadmin
            Understanding Genetic Influence on Infectious Disease
            by seqadmin




            During the COVID-19 pandemic, scientists observed that while some individuals experienced severe illness when infected with SARS-CoV-2, others were barely affected. These disparities left researchers and clinicians wondering what causes the wide variations in response to viral infections and what role genetics plays.

            Jean-Laurent Casanova, M.D., Ph.D., Professor at Rockefeller University, is a leading expert in this crossover between genetics and infectious...
            09-09-2024, 10:59 AM
          • seqadmin
            Addressing Off-Target Effects in CRISPR Technologies
            by seqadmin






            The first FDA-approved CRISPR-based therapy marked the transition of therapeutic gene editing from a dream to reality1. CRISPR technologies have streamlined gene editing, and CRISPR screens have become an important approach for identifying genes involved in disease processes2. This technique introduces targeted mutations across numerous genes, enabling large-scale identification of gene functions, interactions, and pathways3. Identifying the full range...
            08-27-2024, 04:44 AM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by seqadmin, 09-11-2024, 02:44 PM
          0 responses
          13 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 09-06-2024, 08:02 AM
          0 responses
          146 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 09-03-2024, 08:30 AM
          0 responses
          153 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 08-27-2024, 04:40 AM
          0 responses
          163 views
          0 likes
          Last Post seqadmin  
          Working...
          X