Skip to content

Instantly share code, notes, and snippets.

@moselhy
Created June 21, 2018 09:56
Show Gist options
  • Save moselhy/ca69052e074f39e0fe61440bea1bec35 to your computer and use it in GitHub Desktop.
Save moselhy/ca69052e074f39e0fe61440bea1bec35 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import os
if len(sys.argv) != 4:
print("Usage: {} (string)filename.fastq (string)readID (int)numreads".format(sys.argv[0]))
sys.exit(1)
filepath = sys.argv[1]
readID = sys.argv[2]
numreads = int(sys.argv[3])
filename = os.path.splitext(filepath)[0]
newfilepath = "{}_new.fastq".format(filename)
with open(filepath, 'r') as fpread, open(newfilepath, 'w') as fpwrite:
for line in fpread:
if line.startswith(readID):
numreads-=1
if numreads >= 0:
fpwrite.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment