Skip to content

Instantly share code, notes, and snippets.

@walterst
Created November 20, 2013 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterst/7557053 to your computer and use it in GitHub Desktop.
Save walterst/7557053 to your computer and use it in GitHub Desktop.
Usage: python split_fasta_qual_seqs.py X Y Z A B C D where X - input fasta file Y - input qual file Z - Number of seqs to write to first file, remaining will be written to second A - first output fasta file B - second output fasta file C - first output qual file D - second output qual file One can use a: grep -c "^>" fasta_filepath to see how ma…
#!/usr/bin/env python
""" Usage:
python split_fasta_qual_seqs.py X Y Z A B C D
where
X - input fasta file
Y - input qual file
Z - Number of seqs to write to first file, remaining will be written to second
A - first output fasta file
B - second output fasta file
C - first output qual file
D - second output qual file
"""
from sys import argv
in_fasta = open(argv[1], "U")
in_qual = open(argv[2], "U")
seq_count = int(argv[3])
out_fasta1 = open(argv[4], "w")
out_fasta2 = open(argv[5], "w")
out_qual1 = open(argv[6], "w")
out_qual2 = open(argv[7], "w")
counter = 0
for line in in_fasta:
if line.startswith(">"):
counter += 1
if counter > seq_count:
out_fasta2.write(line)
else:
out_fasta1.write(line)
counter = 0
for line in in_qual:
if line.startswith(">"):
counter += 1
if counter > seq_count:
out_qual2.write(line)
else:
out_qual1.write(line)
in_fasta.close()
in_qual.close()
out_fasta1.close()
out_fasta2.close()
out_qual1.close()
out_qual2.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment