Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rakesh12
    Junior Member
    • Mar 2012
    • 6

    #1

    Un-align reads in BWA

    Hi All,
    I have RNA-seq data from human tissue samples. I want to align to RefSeq and then to UCSC and then to human genome in sequential order using BWA. But how can I store unalign sequences? For examples, unalign sequences from RefSeq reference alignment (which will be input sequences for UCSC)?
    Thank you so much for your help,
    Rakesh
  • maubp
    Peter (Biopython etc)
    • Jul 2009
    • 1544

    #2
    Normally unaligned reads are stored in FASTQ, although you can also store unaligned reads in SAM/BAM which is supported by some alignment tools (including BWA).

    See also my blog post which might be of interest:
    I think it is time to retire the FASTQ file format in favour of storing unaligned reads in SAM/BAM format . I will try to explain, as thi...


    Are you asking in general how to go from aligned reads in SAM/BAM to unaligned reads?

    Comment

    • rakesh12
      Junior Member
      • Mar 2012
      • 6

      #3
      Hi Peter,

      Thanks for your detailed response and very interesting blog.

      Specifically, I want to align my RNA-seq data (in fastq format) using BWA with RefSeq reference database and at same time I want to store un-align reads (in fastq or SAM format) in separate file. As BWA does not have any option to store un-align reads. Can you please guide me?

      Thanks again for your kind help,

      Rakesh

      Comment

      • chadn737
        Senior Member
        • Jan 2009
        • 392

        #4
        This is a perl script that will take your bam file and your original fastq file and generate an fastq file containing only your unaligned reads.

        One caveat, you can't have any unaligned reads in your bam file.

        I should also note that I did not write this script. If I remember correctly it was written by Simon Anders, the author of DESeq, DEXseq, and other useful things. I think he posted it on here sometime ago, but I have no idea which thread anymore.


        Code:
        #!/usr/bin/perl
        use warnings;
        use strict;
        
        my ($fastq,$sam,$outfile) = @ARGV;
        
        unless ($outfile) {
          die "Usage is filter_unmapped_reads.pl [FastQ file] [SAM File] [File for unmapped reads]\n";
        }
        
        if (-e $outfile) {
          die "Won't overwrite an existing file, delete it first!";
        }
        
        open (FASTQ,$fastq) or die "Can't open fastq file: $!";
        open (SAM,$sam) or die "Can't open SAM file: $!";
        open (OUT,'>',$outfile) or die "Can't write to $outfile: $!";
        
        my $ids = read_ids();
        
        filter_fastq($ids);
        
        close OUT or die "Can't write to $outfile: $!";
        
        
        sub filter_fastq {
        
          warn "Filtering FastQ file\n";
        
          my ($ids) = @_;
        
          while (<FASTQ>) {
        
            if (/^@(\S+)/) {
              my $id = $1;
        
              # Remove the end designator from paired end reads
              $id =~ s/\/\d+$//;
        
              my $seq = <FASTQ>;
              my $id2 = <FASTQ>;
              my $qual = <FASTQ>;
        
        
              unless (exists $ids->{$id}) {
        	print OUT $_,$seq,$id2,$qual;
              }
            }
            else {
              warn "Line '$_' should have been an id line, but wasn't\n";
            }
        
          }
        
        }
        
        
        sub read_ids {
        
          warn "Collecting mapped ids\n";
        
          my $ids;
        
          while (<SAM>) {
        
            next if (/^@/);
            my ($id) = split(/\t/);
            $ids->{$id} = 1;
          }
        
          return $ids;
        }
        To use:

        Code:
        $ perl unaligned_reads.pl <in.fastq> <in.bam> <out.fastq>

        Comment

        • chadn737
          Senior Member
          • Jan 2009
          • 392

          #5
          Ah, here is the thread where Simon originally posted it:

          Discussion of next-gen sequencing related bioinformatics: resources, algorithms, open source efforts, etc

          Comment

          • rakesh12
            Junior Member
            • Mar 2012
            • 6

            #6
            Hi Chadn,

            Thank you so much for your detailed response.

            Best wishes,

            Rakesh

            Comment

            Latest Articles

            Collapse

            • SEQadmin2
              Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
              by SEQadmin2



              Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

              Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
              ...
              Yesterday, 09:55 AM
            • SEQadmin2
              New Genomics Technologies Take Aim at Long-Standing Limits
              by SEQadmin2


              Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

              We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
              ...
              09-28-2026, 10:25 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by SEQadmin2, Today, 10:52 AM
            0 responses
            8 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, Yesterday, 05:39 AM
            0 responses
            17 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 10-13-2026, 09:56 AM
            0 responses
            15 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 10-09-2026, 11:14 AM
            0 responses
            27 views
            0 reactions
            Last Post SEQadmin2  
            Working...