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
                      Beyond CRISPR/Cas9: Understand, Choose, and Use the Right Genome Editing Tool
                      by SEQadmin2



                      CRISPR/Cas9 sparked the gene editing revolution for both research and therapeutics.1 But this system still showed severe issues that limited its applications. The most prominent were the heavy reliance on PAM sequences, delivery limitations, double-stranded breaks that prompt unintended edits and cell death, and editing inefficiency (both in targeting and in knock-in reliability).

                      Despite this, “CRISPR helped turn genome editing from a specialized technique into
                      ...
                      07-31-2026, 11:01 AM
                    • SEQadmin2
                      Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
                      by SEQadmin2


                      Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

                      The systematic characterization of the human proteome has
                      ...
                      07-20-2026, 11:48 AM
                    • SEQadmin2
                      Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                      by SEQadmin2



                      Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                      ...
                      07-09-2026, 11:10 AM

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by SEQadmin2, Today, 07:41 AM
                    0 responses
                    9 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 08-03-2026, 10:13 AM
                    0 responses
                    25 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-31-2026, 02:55 AM
                    0 responses
                    38 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-24-2026, 12:17 PM
                    0 responses
                    25 views
                    0 reactions
                    Last Post SEQadmin2  
                    Working...