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

            • 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
            26 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...