Mercurial > repos > bgruening > rrna
annotate rna_hmm3.py @ 0:1a12c379df0c draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
author | bgruening |
---|---|
date | Thu, 17 Sep 2015 16:50:41 -0400 |
parents | |
children |
rev | line source |
---|---|
0
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
1 #! /usr/bin/env python |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
2 import os |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
3 import re |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
4 import sys |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
5 import string |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
6 import optparse |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
7 import fasta |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
8 import math |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
9 import tempfile |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
10 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
11 def format(seq, N=60): |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
12 nseg = int(math.ceil(len(seq)/(N+0.0))) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
13 return '\n'.join([seq[i*N:(i+1)*N] for i in range(nseg)]) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
14 # write into fasta format file |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
15 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
16 parser = optparse.OptionParser(version="%prog ") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
17 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
18 parser.add_option("-i", "--input", dest="input_fasta",action="store", |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
19 help="name of input file in fasta format") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
20 parser.add_option("-L", "--LibHmm", dest="hmm_path",action="store", |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
21 default="HMM3",help="path of hmm database") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
22 parser.add_option("--gff", dest="out_gff",action="store", |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
23 help="name of output gff file") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
24 parser.add_option("--seq", dest="out_seq",action="store", |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
25 help="name of output sequence file") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
26 parser.add_option("--mask", dest="out_mask",action="store", |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
27 help="name of output mask file") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
28 parser.add_option("-k", "--kingdoms", dest="kingdoms",action="store", |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
29 default="arc,bac,euk",help="kingdom used") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
30 parser.add_option("-m", "--moltypes", dest="moltypes",action="store", |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
31 default="lsu,ssu,tsu",help="molecule type detected") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
32 parser.add_option("-e","--Evalue", dest="evalue",action="store",type="float", |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
33 default=0.01,help="evalue cut-off for hmmsearch") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
34 parser.add_option("--cpu", dest="cpu",action="store",type="int", |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
35 default=4,help="number of cpus hmmsearch should use") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
36 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
37 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
38 try: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
39 (options, args) = parser.parse_args() |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
40 except: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
41 parser.print_help() |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
42 sys.exit(1) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
43 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
44 if options.input_fasta is None or options.hmm_path is None: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
45 parser.print_help() |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
46 sys.exit(1) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
47 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
48 #print "%s"% os.path.abspath(options.hmm_path) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
49 #os.environ["HMMERDB"] += ":"+os.path.abspath(options.hmm_path) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
50 #print os.environ["HMMERDB"] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
51 fname = os.path.abspath(options.input_fasta) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
52 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
53 tr = string.maketrans("gatcryswkmbdhvnGATCRYSWKMBDHVN","ctagyrswmkvhdbnCTAGYRSWMKVHDBN") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
54 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
55 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
56 def rev_record(record): |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
57 return ">"+record.header+"|rev\n"+format(record.sequence[::-1].translate(tr)) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
58 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
59 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
60 records = [rec for rec in fasta.fasta_itr(fname)] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
61 headers = [[rec.header,len(rec.sequence)] for rec in records] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
62 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
63 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
64 temp_fasta = tempfile.NamedTemporaryFile(delete=False) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
65 ff = open(temp_fasta.name,'w') |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
66 for (i, rec) in enumerate(records): |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
67 ff.write('>s'+str(i)+'\n'+format(rec.sequence)+'\n') |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
68 ff.write('>s'+str(i)+'|rev\n'+format(rec.sequence[::-1].translate(tr))+'\n') |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
69 ff.close() |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
70 #sys.exit(1) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
71 # a temporary fasta file, use s(int) to easy the parsing |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
72 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
73 def parse_hmmsearch(kingdom, moltype, src): |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
74 # function to parse hmmsearch output |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
75 resu = [] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
76 data = open(src).readlines() |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
77 inds = [-1]+[i for (i,x) in enumerate(data[2]) if x==" "] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
78 inds = [(inds[j]+1,inds[j+1]) for j in range(len(inds)-1)] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
79 data = [line for line in data if line[0] != "#"] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
80 for line in data: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
81 if not len(line.strip()): |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
82 continue |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
83 [read, acc, tlen, qname, qaccr, qlen, seq_evalue, seq_score, seq_bias, \ |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
84 seq_num, seq_of, dom_cEvalue, dom_iEvalue, dom_score, dom_bias, \ |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
85 hmm_start, hmm_end, dom_start, dom_end, env_start, env_end] = \ |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
86 line.split()[:21] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
87 # [line[x[0]:x[1]].strip() for x in inds[:21]] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
88 if string.atof(dom_iEvalue) < options.evalue: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
89 # resu.append("\t".join([read, acc, tlen, qname, qaccr, \ |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
90 # qlen, seq_evalue, seq_score, seq_bias, seq_num, seq_of, \ |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
91 # dom_cEvalue, dom_iEvalue, dom_score, dom_bias, hmm_start, \ |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
92 # hmm_end, dom_start, dom_end, env_start, env_end])) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
93 resu.append("\t".join([qname, dom_start, dom_end, read, dom_iEvalue])) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
94 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
95 # print resu[0] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
96 # print resu[-1] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
97 return resu |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
98 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
99 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
100 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
101 hmm_resu = [] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
102 for kingdom in options.kingdoms.split(','): |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
103 for moltype in options.moltypes.split(','): |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
104 #print kingdom, moltype |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
105 #hmm_out_fname = "%s.%s_%s.out" % (out_fname, kingdom, moltype) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
106 temp_hmm_out = tempfile.NamedTemporaryFile(delete=False) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
107 #dom_out_fname = "%s.%s_%s.dom" % (out_fname, kingdom, moltype) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
108 temp_dom_out = tempfile.NamedTemporaryFile(delete=False) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
109 #cmd = '/home/thumper6/camera-annotation/sitao/hmmer3.0/hmmer-3.0-linux-intel-x86_64/binaries/hmmsearch --cpu 1 -o %s --domtblout %s -E %g %s/%s_%s.hmm %s' % \ |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
110 cmd = 'hmmsearch --cpu %s -o %s --domtblout %s -E %g %s/%s_%s.hmm %s' % \ |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
111 (options.cpu, temp_hmm_out.name, temp_dom_out.name, \ |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
112 options.evalue,os.path.abspath(options.hmm_path),kingdom,moltype,temp_fasta.name) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
113 # hmm_resu += parse_hmmsearch(os.popen(cmd)) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
114 os.system(cmd) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
115 hmm_resu += parse_hmmsearch(kingdom, moltype, temp_dom_out.name) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
116 os.remove(temp_hmm_out.name) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
117 os.remove(temp_dom_out.name) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
118 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
119 dict_read2kingdom = {} |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
120 for line in hmm_resu: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
121 [feature_type, r_start, r_end, read, evalue] = line.strip().split('\t') |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
122 read = read.split('|')[0] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
123 evalue = string.atof(evalue) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
124 kingdom = feature_type.split('_')[0] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
125 if read in dict_read2kingdom: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
126 if evalue < dict_read2kingdom[read][1]: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
127 dict_read2kingdom[read] = [kingdom, evalue] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
128 else: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
129 dict_read2kingdom[read] = [kingdom, evalue] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
130 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
131 header = ['##seq_name','method','feature','start','end','evalue','strand','gene'] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
132 ff = open(options.out_gff,"w") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
133 dict_rRNA = {'arc_lsu':'Archaeal:23S_rRNA','arc_ssu':'Archaeal:16S_rRNA','arc_tsu':'Archaeal:5S_rRNA', |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
134 'bac_lsu':'Bacterial:23S_rRNA','bac_ssu':'Bacterial:16S_rRNA','bac_tsu':'Bacterial:5S_rRNA', |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
135 'euk_lsu':'Eukaryotic:28S_rRNA','euk_ssu':'Eukaryotic18S_rRNA','euk_tsu':'Eukaryotic:8S_rRNA'} |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
136 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
137 ff.write('\t'.join(header)+'\n') |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
138 for line in hmm_resu: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
139 # [kingdom, moltype, read, acc, tlen, qname, qaccr, \ |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
140 # qlen, seq_evalue, seq_score, seq_bias, seq_num, seq_of, \ |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
141 # dom_cEvalue, dom_iEvalue, dom_score, dom_bias, hmm_start, \ |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
142 # hmm_end, dom_start, dom_end, env_start, env_end] = line.strip().split('\t') |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
143 [feature_type, r_start, r_end, read, evalue] = line.strip().split('\t') |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
144 if dict_read2kingdom[read.split('|')[0]][0] != feature_type.split('_')[0]: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
145 continue |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
146 feature_type = dict_rRNA[feature_type] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
147 if read.endswith('|rev'): |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
148 strand = '-' |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
149 tmp = map(string.atoi,[r_start,r_end]) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
150 pos = string.atoi(read[1:-4]) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
151 header = headers[pos][0] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
152 L = headers[pos][1] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
153 [r_end,r_start] = [str(L+1-x) for x in tmp] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
154 else: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
155 strand = '+' |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
156 pos = string.atoi(read[1:]) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
157 header = headers[pos][0] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
158 ff.write('\t'.join([header.split()[0], 'rna_hmm3','rRNA',r_start,r_end,evalue,strand,feature_type])+'\n') |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
159 ff.close() |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
160 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
161 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
162 os.remove(temp_fasta.name) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
163 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
164 #postprocessing |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
165 rRNA_dict={} |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
166 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
167 if options.out_gff: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
168 for line in open(options.out_gff).readlines()[1:]: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
169 line=line.strip().split() |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
170 #print '%s %s'% (line[0],line[1]) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
171 if rRNA_dict.get(line[0],None) is None: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
172 rRNA_dict[line[0]] = [] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
173 #else: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
174 rRNA_dict[line[0]].append( (string.atoi(line[3]),string.atoi(line[4]),line[6],line[7])) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
175 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
176 if options.out_mask: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
177 f_mask = open(options.out_mask,"w") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
178 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
179 if options.out_seq: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
180 f_seq = open(options.out_seq,"w") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
181 for rec in fasta.fasta_itr( options.input_fasta ): |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
182 header = rec.header.split()[0] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
183 seq = rec.sequence[:] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
184 tno = 1 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
185 for (start,end,strand,rRNA_type) in rRNA_dict.get(header,[]): |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
186 seq = seq[:(start-1)]+'N'*(end-start+1)+seq[end:] |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
187 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
188 #print "%s %d"% (header,tno) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
189 if options.out_seq: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
190 f_seq.write(">%s.%d /start=%d /end=%d /strand=%s %s\n" % (header,tno,start,end,strand,rRNA_type)) |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
191 if strand=="+": # forward strand |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
192 f_seq.write(format(rec.sequence[(start-1):end])+"\n") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
193 else: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
194 f_seq.write(format(rec.sequence[(start-1):end][::-1].translate(tr))+"\n") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
195 tno = tno+1 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
196 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
197 #f_mask.write(">"+header+"\n") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
198 #next line by liwz |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
199 if options.out_mask: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
200 f_mask.write(">"+rec.header+"\n") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
201 f_mask.write(format(seq)+"\n") |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
202 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
203 if options.out_mask: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
204 f_mask.close() |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
205 if options.out_seq: |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
206 f_seq.close() |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
207 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
208 |
1a12c379df0c
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rRNA commit 1973f3035c10db80883d80847ea254289f5cce2a-dirty
bgruening
parents:
diff
changeset
|
209 |