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
            Advanced Tools Transforming the Field of Cytogenomics
            by seqadmin


            At the intersection of cytogenetics and genomics lies the exciting field of cytogenomics. It focuses on studying chromosomes at a molecular scale, involving techniques that analyze either the whole genome or particular DNA sequences to examine variations in structure and behavior at the chromosomal or subchromosomal level. By integrating cytogenetic techniques with genomic analysis, researchers can effectively investigate chromosomal abnormalities related to diseases, particularly...
            Yesterday, 06:26 AM
          • seqadmin
            How RNA-Seq is Transforming Cancer Studies
            by seqadmin



            Cancer research has been transformed through numerous molecular techniques, with RNA sequencing (RNA-seq) playing a crucial role in understanding the complexity of the disease. Maša Ivin, Ph.D., Scientific Writer at Lexogen, and Yvonne Goepel Ph.D., Product Manager at Lexogen, remarked that “The high-throughput nature of RNA-seq allows for rapid profiling and deep exploration of the transcriptome.” They emphasized its indispensable role in cancer research, aiding in biomarker...
            09-07-2023, 11:15 PM
          • seqadmin
            Methods for Investigating the Transcriptome
            by seqadmin




            Ribonucleic acid (RNA) represents a range of diverse molecules that play a crucial role in many cellular processes. From serving as a protein template to regulating genes, the complex processes involving RNA make it a focal point of study for many scientists. This article will spotlight various methods scientists have developed to investigate different RNA subtypes and the broader transcriptome.

            Whole Transcriptome RNA-seq
            Whole transcriptome sequencing...
            08-31-2023, 11:07 AM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by seqadmin, Today, 06:57 AM
          0 responses
          6 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, Yesterday, 07:53 AM
          0 responses
          8 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 09-25-2023, 07:42 AM
          0 responses
          14 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 09-22-2023, 09:05 AM
          0 responses
          44 views
          0 likes
          Last Post seqadmin  
          Working...
          X