annotate annotateviz.py @ 6:9a09f7072ed5 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 92d0101d8677f60a314611d325ca51a809a545d7-dirty
author eduardo
date Tue, 27 Jun 2017 08:12:24 -0400
parents 92921dfea0b5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
1 import sys
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
2 import os
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
3 import gffutils
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
4 import argparse
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
5 import json
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
6
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
7 def add_matches(matches,array):
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
8 for m in matches:
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
9 trans = {}
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
10 trans['mRNA'] = '.'.join(m.id.split('.',2)[:2]) #hack to recover mRNA from PFAM gff which doesn't include a query field
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
11 trans['Contig'] = m.seqid
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
12 trans['Source'] = m.source
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
13 trans['Score'] = m.score
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
14 trans['Prediction']=m["Name"]
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
15 array.append(trans)
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
16 def main(argv, wayout):
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
17 if not len(argv):
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
18 argv.append("-h")
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
19 parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description=__doc__)
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
20 parser.add_argument('-d','--database', help="gffutils sqlite database")
4
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
21 parser.add_argument('-j','--json', help="annotations in json format")
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
22 parser.add_argument('-p','--pred', help="predictions in json")
3
3302f18f9e16 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents: 0
diff changeset
23 args = parser.parse_args(argv)
0
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
24 gffutils.constants.always_return_list = False
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
25 db = gffutils.interface.FeatureDB(args.database)
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
26 prediction_list = []
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
27 add_matches(db.features_of_type("protein_match"), prediction_list)
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
28 add_matches(db.features_of_type("signalpep"), prediction_list)
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
29 add_matches(db.features_of_type("trans_helix"), prediction_list)
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
30 add_matches(db.features_of_type("PFAM"), prediction_list)
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
31 fout=open(args.json, 'w')
7537482eed36 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents:
diff changeset
32 json.dump(prediction_list,fout)
4
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
33 # create json for protein predictions
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
34 array=[]
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
35 for f in db.features_of_type("gene"):
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
36 dict = {}
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
37 dict['seqid'] = f.seqid
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
38 dict['source'] = f.source
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
39 dict['featuretype'] = f.featuretype
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
40 dict['start'] = f.start
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
41 dict['end'] = f.end
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
42 dict['score'] = f.score
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
43 dict['strand'] = f.strand
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
44 dict['frame'] = f.frame
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
45 dict['attributes']=f.attributes.__dict__["_d"]
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
46 array.append(dict)
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
47 for c in db.children(f):
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
48 dict = {}
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
49 dict['seqid'] = c.seqid
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
50 dict['source'] = c.source
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
51 dict['featuretype'] = c.featuretype
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
52 dict['start'] = c.start
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
53 dict['end'] = c.end
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
54 dict['score'] = c.score
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
55 dict['strand'] = c.strand
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
56 dict['frame'] = c.frame
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
57 dict['attributes'] = c.attributes.__dict__["_d"]
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
58 array.append(dict)
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
59 fout2=open(args.pred,'w')
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
60 json.dump(array,fout2)
92921dfea0b5 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 230f5fe14cc469e56626201a5c377686976d81fc
eduardo
parents: 3
diff changeset
61
3
3302f18f9e16 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents: 0
diff changeset
62 if __name__ == "__main__":
3302f18f9e16 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/annotateviz commit 9bbaa3eacc76ff3bf2b6da313cc0d85705f15dd1-dirty
eduardo
parents: 0
diff changeset
63 main(sys.argv[1:],sys.stdout)