File: create_cluster_info.py

package info (click to toggle)
python-seqcluster 1.2.9%2Bds-3
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm
  • size: 113,624 kB
  • sloc: python: 5,308; makefile: 184; sh: 122; javascript: 55
file content (40 lines) | stat: -rw-r--r-- 1,235 bytes parent folder | download | duplicates (3)
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
38
39
40
from optparse import OptionParser

usagetxt = "usage: %prog  -r res_seqcluster -c clusters_id -o outputdir"
parser = OptionParser(usage=usagetxt, version="%prog 0.1")
parser.add_option("-c", "--clusterid", dest="clus",
                  help="", metavar="FILE")
parser.add_option("-r", "--results", dest="res",
                  help="", metavar="FILE")
parser.add_option("-o", "--output", dest="out",
                  help="", metavar="FILE")
(options, args) = parser.parse_args()

clus = {}
c = open(options.clus, 'r')
for line in c:
    line = line.strip()
    clus[line] = 0
c.close()

isin = 0
f = open(options.res, 'r')
for line in f:
    line = line.strip()
    if not "#" in line:
        if "C:" in line:
            if isin==1:
                out.close()
                outfa.close()
                isin = 0
            if line in clus:
                out = open(options.out+"/"+line, 'w')
                outfa = open(options.out+"/"+line+".fa", 'w')
                out.write(line+"\n")
                isin = 1
        else:
            if isin == 1:
                out.write(line+"\n")
            if "seq_" in line:
                cols = line.split(" ")
                outfa.write(">"+cols[0]+"\n"+cols[1]+"\n")