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

            • kinpict.com
              Reply to 16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
              by kinpict.com
              The part about this topic feels surprisingly grounded, and the details on the page is the bit that made me slow down. I’d keep <a href="https://kinpict.com/">ai family photo generator</a> bookmarked for later.
              Today, 06:37 PM
            • SEQadmin2
              16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
              by SEQadmin2





              NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification,...
              10-30-2026, 06:46 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by SEQadmin2, 11-12-2026, 07:59 AM
            0 responses
            27 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 11-05-2026, 09:25 AM
            0 responses
            35 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 11-03-2026, 11:54 AM
            2 responses
            56 views
            0 reactions
            Last Post kinpict.com  
            Started by SEQadmin2, 10-28-2026, 09:57 AM
            0 responses
            175 views
            0 reactions
            Last Post SEQadmin2  
            Working...