comparison export.py @ 5:7610987e0c48 draft

planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
author eric-rasche
date Wed, 01 Mar 2017 22:39:58 -0500
parents d4ae83dedb14
children f9a6e151b3b4
comparison
equal deleted inserted replaced
4:23ead6905145 5:7610987e0c48
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 import sys 2 import sys
3 import StringIO 3 try:
4 import StringIO as io
5 except ImportError:
6 import io
7
4 import json 8 import json
5 import argparse 9 import argparse
6 from Bio import SeqIO 10 from Bio import SeqIO
7 from BCBio import GFF 11 from BCBio import GFF
8 from webapollo import WAAuth, WebApolloInstance, CnOrGuess, GuessCn 12 from webapollo import WAAuth, WebApolloInstance, CnOrGuess, GuessCn
9 13
10 14
11 def export(org_cn, seqs): 15 def export(org_cn, seqs):
12 org_data = wa.organisms.findOrganismByCn(org_cn) 16 org_data = wa.organisms.findOrganismByCn(org_cn)
13 17
14 data = StringIO.StringIO() 18 data = io.StringIO()
15 19
16 kwargs = dict( 20 kwargs = dict(
17 exportType='GFF3', 21 exportType='GFF3',
18 seqType='genomic', 22 seqType='genomic',
19 exportGff3Fasta=True, 23 exportGff3Fasta=True,
38 # Seek back to start 42 # Seek back to start
39 data.seek(0) 43 data.seek(0)
40 44
41 records = list(GFF.parse(data)) 45 records = list(GFF.parse(data))
42 if len(records) == 0: 46 if len(records) == 0:
43 print "Could not find any sequences or annotations for this organism + reference sequence" 47 print("Could not find any sequences or annotations for this organism + reference sequence")
44 sys.exit(2) 48 sys.exit(2)
45 else: 49 else:
46 for record in records: 50 for record in records:
47 record.annotations = {} 51 record.annotations = {}
52 record.features = sorted(record.features, key=lambda x: x.location.start)
48 if args.gff: 53 if args.gff:
49 GFF.write([record], args.gff) 54 GFF.write([record], args.gff)
50 record.description = "" 55 record.description = ""
51 if args.fasta: 56 if args.fasta:
52 SeqIO.write([record], args.fasta, 'fasta') 57 SeqIO.write([record], args.fasta, 'fasta')
53 58
54 return org_data 59 return org_data
60
55 61
56 if __name__ == '__main__': 62 if __name__ == '__main__':
57 parser = argparse.ArgumentParser(description='Sample script to add an attribute to a feature via web services') 63 parser = argparse.ArgumentParser(description='Sample script to add an attribute to a feature via web services')
58 WAAuth(parser) 64 WAAuth(parser)
59 CnOrGuess(parser) 65 CnOrGuess(parser)