Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fhb
    Member
    • Aug 2010
    • 10

    #1

    help to create fastq file with non-aligned reads

    Hi everyone,
    So far I have been reading posts only, and it has been really helpful.

    I am using TopHat to align Illumina sequences (SE 100bases) from a polyA+mRNA library. I would like to have a fastq file with the reads that were not aligned. TopHat does not have an option to output that (to my knowledge).

    Can anyone, please, indicate a way of creating that file? May be pointing directions or sharing a code.

    Thanks in advance.
  • simonandrews
    Simon Andrews
    • May 2009
    • 870

    #2
    We do this routinely, but not from SAM files so our code isn't directly applicable. Basically all we do is read through the aligned file recording all of the sequence IDs we see. Then we go back through the original fastq file printing out any entries for which we didn't see the ID in the aligned file.

    Comment

    • KevinLam
      Senior Member
      • Nov 2009
      • 204

      #3
      Check out http://code.google.com/p/hydra-sv/wiki/TypicalWorkflow
      I believe you can use unmapped as a flag (i think it's 4) filter
      and pipe it thru bamtofastq
      for what you need.
      http://kevin-gattaca.blogspot.com/

      Comment

      • fhb
        Member
        • Aug 2010
        • 10

        #4
        Originally posted by simonandrews View Post
        We do this routinely, but not from SAM files so our code isn't directly applicable. Basically all we do is read through the aligned file recording all of the sequence IDs we see. Then we go back through the original fastq file printing out any entries for which we didn't see the ID in the aligned file.
        Hi Simon,
        Thanks very much. I was able to isolate all the sequence IDs, but when it came to matching the IDs between the file from the alignment output and the fastq, I could not do it. As a beginner in the bioinformatics field, I have tried to do it using simple bash commands. ie: grep, cut, etc. Could you please share the part of your code that does the matching and prints what is not matched?

        I do appreciate your first reply .
        Thanks in advance.
        Fernando

        Comment

        • fhb
          Member
          • Aug 2010
          • 10

          #5
          Hi Kevin,
          as I mentioned before, TopHat does not print non aligned reads.
          Thanks for the link.
          Fernando

          Comment

          • simonandrews
            Simon Andrews
            • May 2009
            • 870

            #6
            Originally posted by fhb View Post
            Hi Simon,
            Thanks very much. I was able to isolate all the sequence IDs, but when it came to matching the IDs between the file from the alignment output and the fastq, I could not do it. As a beginner in the bioinformatics field, I have tried to do it using simple bash commands. ie: grep, cut, etc. Could you please share the part of your code that does the matching and prints what is not matched?

            I do appreciate your first reply .
            Thanks in advance.
            Fernando
            Fernando,

            I've just tried this code on a tophat file I had lying around and it seemed to filter out the unmapped reads OK. It takes the name of a SAM and fastq file on the command line and returns the unmapped reads on stdout.

            eg

            script.pl accepted_hits.sam s_1_sequence.txt > unmapped.txt

            Code:
            #!perl
            use warnings;
            use strict;
            
            my ($sam_file,$fastq_file) = @ARGV;
            
            my $ids = read_sam($sam_file);
            
            filter_fastq($ids,$fastq_file);
            
            sub filter_fastq {
            
                warn "Filtering FastQ file\n";
            
                my ($ids,$fastq) = @_;
            
                open (IN,$fastq) or die $!;
            
                while (1) {
            	my $id1 = <IN>;
            	my $seq = <IN>;
            	my $id2 = <IN>;
            	my $qual = <IN>;
            
            	last unless ($qual);
            
            	my $match_id = substr($id1,1);
            	chomp $match_id;
            	$match_id =~ s/\/\d$//;
            
            	print $id1,$seq,$id2,$qual unless (exists $ids->{$match_id});
                }
            }
            
            
            sub read_sam {
            
                warn "Reading found ids\n";
                my ($sam) = @_;
            
                my %ids;
            
                open (IN,$sam) or die $!;
                while (<IN>) {
            	next if (/^\@/);
            	my $id = (split/\t/)[0];
            	$ids{$id} = 1;
                }
            
                close IN;
                return \%ids;
            }

            Comment

            • fhb
              Member
              • Aug 2010
              • 10

              #7
              Simon,
              thanks very much for one more time sharing one of your helpful scripts. I appreciate it.
              Best,
              Fernando

              Comment

              • M&M
                Member
                • May 2011
                • 10

                #8
                Thanks Simon! I found this script handy as well.

                Comment

                • swbarnes2
                  Senior Member
                  • May 2008
                  • 910

                  #9
                  Picard is another program that will take a .bam and make a fastq from it.

                  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
                    ...
                    10-14-2026, 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, 11:13 AM
                  0 responses
                  12 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, Today, 10:48 AM
                  0 responses
                  11 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 10-15-2026, 10:52 AM
                  0 responses
                  32 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 10-14-2026, 05:39 AM
                  0 responses
                  40 views
                  0 reactions
                  Last Post SEQadmin2  
                  Working...