
import argparse
import sys
from Bio import SeqIO

def main(args):
    seqs = []
    for i, seq in enumerate(SeqIO.parse(sys.stdin, "fasta")):
        if len(seq) >= args.length_threshold:
            seqs.append(seq)
        if i % 1000 == 0 and len(seqs):
            SeqIO.write(seqs, sys.stdout, 'fasta')
            seqs = []
    
    if len(seqs):
        SeqIO.write(seqs, sys.stdout, 'fasta')

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("-l", "--length_threshold", type=int, help="Length trheshold to filter on.")

    args = parser.parse_args()

    main(args)


import argparse
import sys
from Bio import SeqIO

def main(args):
    seqs = []
    if args.input_fasta is not None:
        input_handle = open(args.input_fasta, 'r')
    else:
        input_handle = sys.stdin

    for i, seq in enumerate(SeqIO.parse(input_handle, "fasta")):
        if len(seq) >= args.length_threshold:
            seqs.append(seq)
        if i % 1000 == 0 and len(seqs):
            SeqIO.write(seqs, sys.stdout, 'fasta')
            seqs = []
    
    if len(seqs):
        SeqIO.write(seqs, sys.stdout, 'fasta')

    input_handle.close()

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--input_fasta", help="Input file")
    parser.add_argument("-l", "--length_threshold", type=int, help="Length threshold to filter on.")

    args = parser.parse_args()

    main(args)

Use either file input or stdin for filtering length
Use either file input or stdin for filtering length

  
  import argparse
  import sys
  from Bio import SeqIO
  
  def main(args):
      seqs = []
+     if args.input_fasta is not None:
+         input_handle = open(args.input_fasta, 'r')
+     else:
+         input_handle = sys.stdin
+ 
-     for i, seq in enumerate(SeqIO.parse(sys.stdin, "fasta")):
+     for i, seq in enumerate(SeqIO.parse(input_handle, "fasta")):
          if len(seq) >= args.length_threshold:
              seqs.append(seq)
          if i % 1000 == 0 and len(seqs):
              SeqIO.write(seqs, sys.stdout, 'fasta')
              seqs = []
      
      if len(seqs):
          SeqIO.write(seqs, sys.stdout, 'fasta')
  
+     input_handle.close()
+ 
  if __name__ == "__main__":
      parser = argparse.ArgumentParser(description=__doc__)
+     parser.add_argument("--input_fasta", help="Input file")
-     parser.add_argument("-l", "--length_threshold", type=int, help="Length trheshold to filter on.")
+     parser.add_argument("-l", "--length_threshold", type=int, help="Length threshold to filter on.")
  
      args = parser.parse_args()
  
      main(args)
  
Use either file input or stdin for filtering length
## Code Before:

import argparse
import sys
from Bio import SeqIO

def main(args):
    seqs = []
    for i, seq in enumerate(SeqIO.parse(sys.stdin, "fasta")):
        if len(seq) >= args.length_threshold:
            seqs.append(seq)
        if i % 1000 == 0 and len(seqs):
            SeqIO.write(seqs, sys.stdout, 'fasta')
            seqs = []
    
    if len(seqs):
        SeqIO.write(seqs, sys.stdout, 'fasta')

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("-l", "--length_threshold", type=int, help="Length trheshold to filter on.")

    args = parser.parse_args()

    main(args)

## Instruction:
Use either file input or stdin for filtering length
## Code After:

import argparse
import sys
from Bio import SeqIO

def main(args):
    seqs = []
    if args.input_fasta is not None:
        input_handle = open(args.input_fasta, 'r')
    else:
        input_handle = sys.stdin

    for i, seq in enumerate(SeqIO.parse(input_handle, "fasta")):
        if len(seq) >= args.length_threshold:
            seqs.append(seq)
        if i % 1000 == 0 and len(seqs):
            SeqIO.write(seqs, sys.stdout, 'fasta')
            seqs = []
    
    if len(seqs):
        SeqIO.write(seqs, sys.stdout, 'fasta')

    input_handle.close()

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--input_fasta", help="Input file")
    parser.add_argument("-l", "--length_threshold", type=int, help="Length threshold to filter on.")

    args = parser.parse_args()

    main(args)
