Mercurial > repos > bgruening > glimmer_extract
annotate glimmer2seq.py @ 2:3186204e3146 draft default tip
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 274d1f6804bfd0362fdcd2383bfdb32ca8fd634e"
author | iuc |
---|---|
date | Sun, 20 Mar 2022 10:08:06 +0000 |
parents | 5631611d5bb8 |
children |
rev | line source |
---|---|
0
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
1 #!/usr/bin/env python |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
2 """ |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
3 Input: DNA FASTA file + Glimmer ORF file |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
4 Output: ORF sequences as FASTA file |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
5 Author: Bjoern Gruening |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
6 """ |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
7 import sys |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
8 |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
9 from Bio import SeqIO |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
10 from Bio.SeqRecord import SeqRecord |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
11 |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
12 |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
13 def glimmer2seq(glimmer_prediction=sys.argv[1], genome_sequence=sys.argv[2], outfile=sys.argv[3]): |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
14 if len(sys.argv) >= 4: |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
15 glimmerfile = open(glimmer_prediction, "r") |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
16 sequence = open(genome_sequence) |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
17 else: |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
18 print("Missing input values.") |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
19 sys.exit() |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
20 |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
21 fastafile = SeqIO.parse(sequence, "fasta") |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
22 |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
23 sequences = dict() |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
24 seq_records = list() |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
25 for entry in fastafile: |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
26 sequences[entry.description] = entry |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
27 |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
28 for line in glimmerfile: |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
29 if line.startswith('>'): |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
30 entry = sequences[line[1:].strip()] |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
31 else: |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
32 orf_start = int(line[8:17]) |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
33 orf_end = int(line[18:26]) |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
34 |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
35 orf_name = line[0:8] |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
36 if orf_start <= orf_end: |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
37 seq_records.append(SeqRecord(entry.seq[orf_start - 1:orf_end], id=orf_name, description=entry.description)) |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
38 else: |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
39 seq_records.append(SeqRecord(entry.seq[orf_end - 1:orf_start].reverse_complement(), id=orf_name, description=entry.description)) |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
40 |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
41 SeqIO.write(seq_records, outfile, "fasta") |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
42 glimmerfile.close() |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
43 sequence.close() |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
44 |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
45 |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
46 if __name__ == "__main__": |
5631611d5bb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/glimmer commit 37388949e348d221170659bbee547bf4ac67ef1a
bgruening
parents:
diff
changeset
|
47 glimmer2seq() |