Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!

  • #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


    • #3
      Quite simple! Thanks!

      Comment


      • #4
        you're welcome

        Comment


        • #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


          • #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

            • seqadmin
              Strategies for Sequencing Challenging Samples
              by seqadmin


              Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
              03-22-2024, 06:39 AM
            • seqadmin
              Techniques and Challenges in Conservation Genomics
              by seqadmin



              The field of conservation genomics centers on applying genomics technologies in support of conservation efforts and the preservation of biodiversity. This article features interviews with two researchers who showcase their innovative work and highlight the current state and future of conservation genomics.

              Avian Conservation
              Matthew DeSaix, a recent doctoral graduate from Kristen Ruegg’s lab at The University of Colorado, shared that most of his research...
              03-08-2024, 10:41 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by seqadmin, Yesterday, 06:37 PM
            0 responses
            12 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, Yesterday, 06:07 PM
            0 responses
            10 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 03-22-2024, 10:03 AM
            0 responses
            52 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 03-21-2024, 07:32 AM
            0 responses
            68 views
            0 likes
            Last Post seqadmin  
            Working...
            X