forked from jgurtowski/ectools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uniqreads.py
42 lines (27 loc) · 1003 Bytes
/
uniqreads.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
###
#Takes a bunch of seq files and outputs
#only unique reads based on their names
# (only up to first space in their names)
#everything becomes fasta format
###
import sys
from itertools import starmap, chain
from functools import partial
from seqio import iteratorFromExtension, fastaRecordToString
from nucio import fileIterator, openerFromExtension
if not len(sys.argv) > 1:
sys.exit("uniqreads.py in.{fa,fq} [in2.{fa.fq} ...]\n")
files = sys.argv[1:]
(openers,nfiles) = zip(*map(partial(openerFromExtension, default=open), files))
its = map(iteratorFromExtension, nfiles)
fileits = starmap(fileIterator, zip(files, its, openers))
namehash = {}
for record in chain.from_iterable(fileits):
cleanname = record.name.split()[0]
if not namehash.get(cleanname, False):
namehash[cleanname] = True
nr = record._replace(name=cleanname)
print fastaRecordToString(nr)
else:
sys.stderr.write("Duplicate : %s \n" % cleanname)