Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HSV-1
    Member
    • Jul 2012
    • 38

    #1

    How to Pick certain reads out of RNA-seq data to a fasta file?

    Hello, every one.
    I tried searching the solution to my question. But I couldn't . So put a new thread here. What I want to do is to pick out all the reads by Illumina Hiseq that contain the sequence "CACAGCTTCTAGTGCTATTCTGCGCCGGTATCC" and collect these reads into a fasta file or any other formats.

    I have read through the manual of bowtie and BWA, I didn't find this usage.

    Anyone could help me out?

    Thanks!
  • dpryan
    Devon Ryan
    • Jul 2011
    • 3478

    #2
    Do you have the original fastq files or do you have the aligned SAM/BAM files? It sounds like you'll be best served by just using grep:

    grep -B 1 -A 2 CACAGCTTCTAGTGCTATTCTGCGCCGGTATCC reads.fastq > matches.fastq

    or

    samtools view aligned.bam | grep CACAGCTTCTAGTGCTATTCTGCGCCGGTATCC > matches.sam

    You could trivially pipe the second one through awk/perl/whatever to get output in fastq or fasta, if you prefer.

    Comment

    • JamieHeather
      @jamimmunology
      • Nov 2012
      • 96

      #3
      Like dpryan said, you could get fasta output like this:

      Code:
      grep --no-group-separator -B 1 CACAGCTTCTAGTGCTATTCTGCGCCGGTATCC FILE.fq | sed 's/@/>/' > NEW_FILE.fa
      Last edited by JamieHeather; 09-11-2013, 03:28 AM. Reason: Taking too long to reply

      Comment

      • dpryan
        Devon Ryan
        • Jul 2011
        • 3478

        #4
        Originally posted by JamieHeather View Post
        You could do this in bash like this:

        Code:
        grep --no-group-separator -B 1 CACAGCTTCTAGTGCTATTCTGCGCCGGTATCC FILE.fq | sed 's/\@/\>/' > NEW_FILE.fa
        I always forget about the --no-group-separator flag!

        It should be noted that this flag isn't always available, in which case grep -v can be used to remove the separator (this issue has come up a couple times on this forum).

        Comment

        • JamieHeather
          @jamimmunology
          • Nov 2012
          • 96

          #5
          Ooh I didn't realise the --no-group-separator isn't always present, good to know.

          I thought the -v flag gave all non-matches? At least it seems to in my version.

          Comment

          • HSV-1
            Member
            • Jul 2012
            • 38

            #6
            Originally posted by dpryan View Post
            Do you have the original fastq files or do you have the aligned SAM/BAM files? It sounds like you'll be best served by just using grep:

            grep -B 1 -A 2 CACAGCTTCTAGTGCTATTCTGCGCCGGTATCC reads.fastq > matches.fastq

            or

            samtools view aligned.bam | grep CACAGCTTCTAGTGCTATTCTGCGCCGGTATCC > matches.sam

            You could trivially pipe the second one through awk/perl/whatever to get output in fastq or fasta, if you prefer.

            Thanks for your reply. I have the original rna-seq data in *.fastq format.
            is grep the linux function? what are -B and -A 2 for?

            Thank you guys!

            Comment

            • JamieHeather
              @jamimmunology
              • Nov 2012
              • 96

              #7
              You're welcome!

              Grep is indeed a unix function, you can just enter it straight into the command line.

              Grep finds and returns the line(s) that contain the expression or string you supplied (in this case your sequence), then the A and B flags tell grep to also output lines above and below the matching line.

              So -B 1 -A 2 would give you the line above the sequence line and the two lines beneath, thus outputting the entire fastq record.

              The code I gave you output just the one above, as fasta doesn't use lines 3 and 4, and then just used sed to change the '@' character to a '>' in the ID line.

              Grep and sed are very useful for hands on playing with your data like this, they're both worth getting to grips with.
              Last edited by JamieHeather; 09-11-2013, 03:39 AM.

              Comment

              • HSV-1
                Member
                • Jul 2012
                • 38

                #8
                Originally posted by JamieHeather View Post
                You're welcome!

                Grep is indeed a unix function, you can just enter it straight into the command line.

                Grep finds and returns the line that contains the expression or string you supplied (in this case your sequence), then the A and B flags tell grep to also output lines above and below the matching line.

                It's a very powerful tool, worth getting to grips with.
                Thanks. thank you very much.

                Comment

                • dpryan
                  Devon Ryan
                  • Jul 2011
                  • 3478

                  #9
                  Originally posted by JamieHeather View Post
                  Ooh I didn't realise the --no-group-separator isn't always present, good to know.

                  I thought the -v flag gave all non-matches? At least it seems to in my version.
                  It does, you just have to pipe the first grep into a grep -v and then the output of that into awk/sed/whatever. I don't recall which platform was missing the --no-group-separator option, I'd have to search back through the forums.

                  Comment

                  • JamieHeather
                    @jamimmunology
                    • Nov 2012
                    • 96

                    #10
                    Originally posted by dpryan View Post
                    It does, you just have to pipe the first grep into a grep -v and then the output of that into awk/sed/whatever. I don't recall which platform was missing the --no-group-separator option, I'd have to search back through the forums.
                    Ahh I see, that makes sense!

                    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, Yesterday, 11:13 AM
                    0 responses
                    21 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, Yesterday, 10:48 AM
                    0 responses
                    18 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 10-15-2026, 10:52 AM
                    0 responses
                    36 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 10-14-2026, 05:39 AM
                    0 responses
                    42 views
                    0 reactions
                    Last Post SEQadmin2  
                    Working...