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
              Essential Discoveries and Tools in Epitranscriptomics
              by seqadmin




              The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
              04-22-2024, 07:01 AM
            • seqadmin
              Current Approaches to Protein Sequencing
              by seqadmin


              Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
              04-04-2024, 04:25 PM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by seqadmin, Yesterday, 08:47 AM
            0 responses
            12 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-11-2024, 12:08 PM
            0 responses
            60 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-10-2024, 10:19 PM
            0 responses
            59 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-10-2024, 09:21 AM
            0 responses
            54 views
            0 likes
            Last Post seqadmin  
            Working...
            X