Mercurial > repos > artbio > mircounts
annotate mature_mir_gff_translation.py @ 5:9ea96a02c416 draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
author | artbio |
---|---|
date | Tue, 05 Sep 2017 06:33:16 -0400 |
parents | 6b8adacd4750 |
children | 3f62272192f9 |
rev | line source |
---|---|
5
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
1 import argparse |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
2 |
5
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
3 from datetime import datetime |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
4 |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
5 |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
6 def Parser(): |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
7 the_parser = argparse.ArgumentParser() |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
8 the_parser.add_argument( |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
9 '--input', action="store", type=str, help="input miRBase GFF3 file") |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
10 the_parser.add_argument( |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
11 '--output', action="store", type=str, |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
12 help="output GFF3 file with converted mature mir coordinates") |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
13 args = the_parser.parse_args() |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
14 return args |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
15 |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
16 |
5
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
17 def get_gff_header(gff_input_file): |
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
18 string_list = [] |
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
19 for line in open(gff_input_file, "r"): |
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
20 if line[0] == '#': |
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
21 string_list.append(line) |
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
22 string_list.append('# generated by mature_mir_gff_translation.py %s\n#\n' % |
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
23 str(datetime.now())) |
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
24 return ''.join(string_list) |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
25 |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
26 |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
27 def load_gff_in_dict(gff_input_file): |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
28 ''' |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
29 Reads the gff3 file and return a dictionary of dictionaries |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
30 with keys equal to standard gff3 fields (9) |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
31 Note that the key of the primary dictionary is the ID |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
32 ''' |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
33 gff_dict = {} |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
34 for line in open(gff_input_file, "r"): |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
35 if line[0] == "#": |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
36 continue |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
37 gff_fields = line[:-1].split("\t") |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
38 ID = gff_fields[8].split("ID=")[1].split(";")[0] |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
39 gff_dict[ID] = {} |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
40 gff_dict[ID]["seqid"] = gff_fields[0] |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
41 gff_dict[ID]["source"] = gff_fields[1] |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
42 gff_dict[ID]["type"] = gff_fields[2] |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
43 gff_dict[ID]["start"] = gff_fields[3] |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
44 gff_dict[ID]["end"] = gff_fields[4] |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
45 gff_dict[ID]["score"] = gff_fields[5] |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
46 gff_dict[ID]["strand"] = gff_fields[6] |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
47 gff_dict[ID]["phase"] = gff_fields[7] |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
48 gff_dict[ID]["attributes"] = gff_fields[8] |
5
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
49 if "erives_from" in gff_dict[ID]["attributes"]: |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
50 parent_primary_transcript = gff_dict[ID]["attributes"].split( |
5
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
51 "erives_from=")[1] |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
52 parent_primary_transcript = gff_dict[parent_primary_transcript][ |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
53 "attributes"].split("Name=")[1] |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
54 gff_dict[ID]["attributes"] = "%s;Parent_mir_Name=%s" % ( |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
55 gff_dict[ID]["attributes"], parent_primary_transcript) |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
56 return gff_dict |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
57 |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
58 |
5
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
59 def genome_to_mir_gff(gff_dict, output, header): |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
60 ''' |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
61 Converts seqid field from chromosome to item Name |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
62 Then converts coordinates relative to "miRNA_primary_transcript" |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
63 Note that GFF files are 1-based coordinates |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
64 ''' |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
65 for key in gff_dict: |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
66 name = gff_dict[key]["attributes"].split("Name=")[1].split(";")[0] |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
67 gff_dict[key]["seqid"] = name |
5
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
68 if "erives_from=" in gff_dict[key]["attributes"]: |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
69 parent_ID = gff_dict[key]["attributes"].split( |
5
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
70 "erives_from=")[1].split(";")[0] |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
71 gff_dict[key]["start"] = str(int(gff_dict[key]["start"])-int( |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
72 gff_dict[parent_ID]["start"])+1) |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
73 gff_dict[key]["end"] = str(int(gff_dict[key]["end"])-int( |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
74 gff_dict[parent_ID]["start"])+1) |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
75 hairpins = {} |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
76 matures = {} |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
77 # treats miRNA_primary_transcript coordinates |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
78 # in a second loop to avoid errors in conversion |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
79 for key in gff_dict: |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
80 if gff_dict[key]["type"] == "miRNA_primary_transcript": |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
81 gff_dict[key]["end"] = str(int(gff_dict[key]["end"])-int( |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
82 gff_dict[key]["start"]) + 1) |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
83 gff_dict[key]["start"] = '1' |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
84 # now, do a dict[ID]=Name but only for miRNA_primary_transcript |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
85 hairpins[key] = gff_dict[key]["attributes"].split( |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
86 "Name=")[1].split( |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
87 ";")[0] |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
88 else: |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
89 matures[key] = gff_dict[key]["attributes"].split( |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
90 "Name=")[1].split( |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
91 ";")[0] |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
92 with open(output, "w") as output: |
5
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
93 output.write(header) |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
94 for ID in sorted(hairpins, key=hairpins.get): |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
95 output.write("\t".join([gff_dict[ID]["seqid"], |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
96 gff_dict[ID]["source"], gff_dict[ID]["type"], |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
97 gff_dict[ID]["start"], gff_dict[ID]["end"], |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
98 gff_dict[ID]["score"], gff_dict[ID]["strand"], |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
99 gff_dict[ID]["phase"], gff_dict[ID]["attributes"]])) |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
100 output.write("\n") |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
101 for id in sorted(matures, key=matures.get, reverse=True): |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
102 if ID in gff_dict[id]["attributes"]: |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
103 output.write("\t".join([gff_dict[id]["seqid"], |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
104 gff_dict[id]["source"], gff_dict[id]["type"], |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
105 gff_dict[id]["start"], gff_dict[id]["end"], |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
106 gff_dict[id]["score"], |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
107 gff_dict[id]["strand"], |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
108 gff_dict[id]["phase"], |
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
109 gff_dict[id]["attributes"]])) |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
110 output.write("\n") |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
111 |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
112 |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
113 def main(infile, outfile): |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
114 gff_dict = load_gff_in_dict(infile) |
5
9ea96a02c416
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit 04980585c257ab5f8eb5d10de007316c47c5d1ce
artbio
parents:
3
diff
changeset
|
115 genome_to_mir_gff(gff_dict, outfile, get_gff_header(infile)) |
0
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
116 |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
117 |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
118 if __name__ == "__main__": |
da29af78a960
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff
changeset
|
119 args = Parser() |
3
6b8adacd4750
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/mircounts commit fa65a844f9041a83767f5305ab360abfdf68f59f
artbio
parents:
0
diff
changeset
|
120 main(args.input, args.output) |