Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marcela
    Junior Member
    • Feb 2011
    • 7

    #1

    Removing reads with "N" > 4

    Hi!

    I was wondering if there is a tool to remove reads that have a specific number of "N's". Fastx has the fastx_trimmer, but it takes positions to trim, without looking at the nucleotide content. Any suggestions?

    Thanks!
  • NicoBxl
    not just another member
    • Aug 2010
    • 264

    #2
    in R it's easy
    Code:
    countN <- function(a){
      return(sum(strsplit(a,"")[[1]]=="N")==4)
    }
    
    a <- "ATGCNNNN"
    b <- "ATGCNN"
    x <- c(a,b)
    sapply(x,countN)
    
    ATGCNN   ATGN 
         TRUE      FALSE

    Comment

    • marcela
      Junior Member
      • Feb 2011
      • 7

      #3
      Quite simple! Thanks!

      Comment

      • NicoBxl
        not just another member
        • Aug 2010
        • 264

        #4
        you're welcome

        Comment

        • schmima
          Member
          • Apr 2010
          • 56

          #5
          hm - don't know of any - but is relatively easy task - heres a quick and dirty script (assumes that your infile has no header) - most probably not too fast due to simultanous reading and writing. But it should work (did not test - was originally something else):

          [EDIT - THE TABS ARE NOT CORRECTLY PRINTED HERE... DONT KNOW IF THEY WILL APPEAR IF YOU COPY IT]

          ############

          import sys

          if len(sys.argv) < 5:
          print 'usage:\n\tpython %s infile outfile char maxnum' % (str(sys.argv[0]))
          sys.exit(0)

          in_file = sys.argv[1]
          out_file = sys.argv[2]
          char = sys.argv[3]
          maxnum = int(sys.argv[4])

          infile = open(in_file, 'r')
          outfile = open(out_file, 'w')

          prevLines = []
          for line in infile:
          prevLines.append(str(line[:-1]))
          if len(prevLines) == 4:
          nucID = prevLines[0]
          nucSeq = prevLines[1]
          qualID = prevLines[2]
          qualSeq = prevLines[3]
          if nucSeq.count(char) <= maxnum:
          outstring = '\n'.join([nucID,nucSeq,qualID,qualSeq])+'\n'
          outfile.write(outstring)
          prevLines = []

          if len(prevLines) == 4:
          charcounter = 0
          nucID = prevLines[0]
          nucSeq = prevLines[1]
          qualID = prevLines[2]
          qualSeq = prevLines[3]
          if nucSeq.count(char) <= maxnum:
          outstring = '\n'.join([nucID,nucSeq,qualID,qualSeq])+'\n'
          outfile.write(outstring)


          outfile.close()
          infile.close()


          ##############

          copy the part between the ###### into an empty textfile, save as XY.py and run:
          python XY.py pathtoinfile pathtooutfile characteryouwanttoremove threshold

          eg
          python XY.py /home/me/myreads.fastq /home/me/myreads_filtered.fastq N 4

          (removes all reads with more than 4 Ns - ie writes the others to outfile)

          Comment

          • schmima
            Member
            • Apr 2010
            • 56

            #6
            ad tabs: if necessary use this code here and replace every * with one tab. ** are double tabs and so on:

            import sys

            if len(sys.argv) < 5:
            *print 'usage:\n\tpython %s infile outfile char maxnum' % (str(sys.argv[0]))
            *sys.exit(0)

            in_file = sys.argv[1]
            out_file = sys.argv[2]
            char = sys.argv[3]
            maxnum = int(sys.argv[4])

            infile = open(in_file, 'r')
            outfile = open(out_file, 'w')

            prevLines = []
            for line in infile:
            *prevLines.append(str(line[:-1]))
            *if len(prevLines) == 4:
            **nucID = prevLines[0]
            **nucSeq = prevLines[1]
            **qualID = prevLines[2]
            **qualSeq = prevLines[3]
            **if nucSeq.count(char) <= maxnum:
            ***outstring = '\n'.join([nucID,nucSeq,qualID,qualSeq])+'\n'
            ***outfile.write(outstring)
            **prevLines = []

            if len(prevLines) == 4:
            *charcounter = 0
            *nucID = prevLines[0]
            *nucSeq = prevLines[1]
            *qualID = prevLines[2]
            *qualSeq = prevLines[3]
            *if nucSeq.count(char) <= maxnum:
            **outstring = '\n'.join([nucID,nucSeq,qualID,qualSeq])+'\n'
            **outfile.write(outstring)


            outfile.close()
            infile.close()

            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
            19 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...