import sys
from Bio import SeqIO
from Bio.SeqRecord import SeqRecord

if len(sys.argv) < 5: 
    print("Usage: %s <length threshold> <contigs_file> <suffix> <output>" % sys.argv[0])
    sys.exit(1) 

f_n = sys.argv[2]
suffix = sys.argv[3]
input_seq_iterator = SeqIO.parse(open(f_n, "r"), "fasta")

output_handle = open(sys.argv[4], "w")
SeqIO.write((SeqRecord(record.seq, (record.name + "_" + suffix).replace(".", "_"), "","") for record in input_seq_iterator \
                if len(record.seq) > int(sys.argv[1])), output_handle, "fasta")
output_handle.close()

import sys
from Bio import SeqIO

if len(sys.argv) < 4: 
    print("Usage: %s <length threshold> <contigs_file> <output>" % sys.argv[0])
    sys.exit(1) 

f_n = sys.argv[2]
input_seq_iterator = SeqIO.parse(open(f_n, "r"), "fasta")
filtered_iterator = (record for record in input_seq_iterator \
                      if len(record.seq) > int(sys.argv[1]))
 
output_handle = open(sys.argv[3], "w")
SeqIO.write(filtered_iterator, output_handle, "fasta")
output_handle.close()

Revert "length filter script now adds provided suffix to contig names"
Revert "length filter script now adds provided suffix to contig names"

This reverts commit 4d3985f667465eb5564de4fada8820e23607a58b.

  import sys
  from Bio import SeqIO
- from Bio.SeqRecord import SeqRecord
  
- if len(sys.argv) < 5: 
+ if len(sys.argv) < 4: 
-     print("Usage: %s <length threshold> <contigs_file> <suffix> <output>" % sys.argv[0])
+     print("Usage: %s <length threshold> <contigs_file> <output>" % sys.argv[0])
      sys.exit(1) 
  
  f_n = sys.argv[2]
- suffix = sys.argv[3]
  input_seq_iterator = SeqIO.parse(open(f_n, "r"), "fasta")
- 
+ filtered_iterator = (record for record in input_seq_iterator \
+                       if len(record.seq) > int(sys.argv[1]))
+  
- output_handle = open(sys.argv[4], "w")
+ output_handle = open(sys.argv[3], "w")
+ SeqIO.write(filtered_iterator, output_handle, "fasta")
- SeqIO.write((SeqRecord(record.seq, (record.name + "_" + suffix).replace(".", "_"), "","") for record in input_seq_iterator \
-                 if len(record.seq) > int(sys.argv[1])), output_handle, "fasta")
  output_handle.close()
  
Revert "length filter script now adds provided suffix to contig names"
## Code Before:
import sys
from Bio import SeqIO
from Bio.SeqRecord import SeqRecord

if len(sys.argv) < 5: 
    print("Usage: %s <length threshold> <contigs_file> <suffix> <output>" % sys.argv[0])
    sys.exit(1) 

f_n = sys.argv[2]
suffix = sys.argv[3]
input_seq_iterator = SeqIO.parse(open(f_n, "r"), "fasta")

output_handle = open(sys.argv[4], "w")
SeqIO.write((SeqRecord(record.seq, (record.name + "_" + suffix).replace(".", "_"), "","") for record in input_seq_iterator \
                if len(record.seq) > int(sys.argv[1])), output_handle, "fasta")
output_handle.close()

## Instruction:
Revert "length filter script now adds provided suffix to contig names"
## Code After:
import sys
from Bio import SeqIO

if len(sys.argv) < 4: 
    print("Usage: %s <length threshold> <contigs_file> <output>" % sys.argv[0])
    sys.exit(1) 

f_n = sys.argv[2]
input_seq_iterator = SeqIO.parse(open(f_n, "r"), "fasta")
filtered_iterator = (record for record in input_seq_iterator \
                      if len(record.seq) > int(sys.argv[1]))
 
output_handle = open(sys.argv[3], "w")
SeqIO.write(filtered_iterator, output_handle, "fasta")
output_handle.close()
