Skip to content

Instantly share code, notes, and snippets.

@dinovski
Last active February 4, 2023 16:59
Show Gist options
  • Save dinovski/559d89d9e8f0e0d51461f50d02241255 to your computer and use it in GitHub Desktop.
Save dinovski/559d89d9e8f0e0d51461f50d02241255 to your computer and use it in GitHub Desktop.
convert sanger output to fastq
#! /usr/bin/env python
import os
import sys
try:
SEQ_DIR = sys.argv[1]
except:
sys.stderr.write("Usage: python sanger2fastq.py <directory with.seq files>\n")
sys.exit(1)
seq_files = os.listdir(SEQ_DIR)
#list comprehension (instead of for loop to modify items in list)
seq_files = [fname for fname in seq_files if ".seq" in fname]
fastq = open('mmp9_round2.fq', 'w')
for sf in seq_files:
fname = os.path.join(SEQ_DIR, sf)
f = open(fname, "r")
read = ""
lines = f.readlines()
for l in lines:
read = read + l.strip()
f.close()
read = read.replace(" ","")
read_id = sf.strip(".seq")
id = "@" + read_id
read = read
read_id = "+" + read_id
qual = "D"*len(read)
fastq.write(id + '\n')
fastq.write(read + '\n')
fastq.write(read_id + '\n')
fastq.write(qual + '\n')
fastq.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment