# HG changeset patch
# User rnateam
# Date 1486082007 18000
# Node ID 6d3269dc319e541f33c97d830f8271b53584f1dc
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/aresite2 commit f437f5e8c6c856c6f0bb8d8ea6e34f5441ee088f
diff -r 000000000000 -r 6d3269dc319e aresite2.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aresite2.py Thu Feb 02 19:33:27 2017 -0500
@@ -0,0 +1,113 @@
+# A simple tool to connect to the AREsite server and retrieve feature
+# information using the AREsite REST Interface.
+# Parts of this code are from https://toolshed.g2.bx.psu.edu/repos/earlhaminst/ensembl_get_feature_info
+import json
+import optparse
+import sys
+import urllib.request, urllib.parse, urllib.error
+import urllib.request, urllib.error, urllib.parse
+import time
+import requests
+from six.moves.urllib.parse import urljoin
+
+usage = "usage: %prog [options] arg1 arg2"
+parser = optparse.OptionParser(usage=usage)
+parser.add_option('-g', '--gene', help='Gene ID to search for')
+parser.add_option('-m', '--motif', help='Motif to look for', default='ATTTA', type=str)
+parser.add_option('-s', '--species', type='choice',
+ choices=['Homo_sapiens', 'Mus_musculus', 'Danio_rerio', 'Drosophila_melanogaster', 'Caenorhabditis_elegans'], default='Homo_sapiens',
+ help='Specify the species to investigate')
+options, args = parser.parse_args()
+
+if options.gene is None:
+ raise Exception('- Specify the gene you want to look for!')
+
+if "," in options.motif :
+ raise Exception('- Please only search for single motifs at once')
+
+class AREsiteRestClient(object):
+ def __init__(self, server='http://rna.tbi.univie.ac.at/AREsite2/api/', reqs_per_sec=1):
+ self.server = server
+ self.reqs_per_sec = reqs_per_sec
+ self.req_count = 0
+ self.last_req = 0
+
+ def perform_rest_action(self, endpoint, hdrs=None, params=None):
+ if hdrs is None:
+ hdrs = {}
+
+ if 'Content-Type' not in hdrs:
+ hdrs['Content-Type'] = 'application/json'
+
+ if params:
+ endpoint += '?' + urllib.parse.urlencode(params)
+
+ data = None
+
+ # check if we need to rate limit ourselves
+ if self.req_count >= self.reqs_per_sec:
+ delta = time.time() - self.last_req
+ if delta < 1:
+ time.sleep(1 - delta)
+ self.last_req = time.time()
+ self.req_count = 0
+
+ try:
+ request = urllib.request.Request(self.server + endpoint, headers=hdrs)
+ response = urllib.request.urlopen(request)
+ content = response.read().decode('utf-8')
+ if content:
+ data = json.loads(content)
+ self.req_count += 1
+
+ except urllib2.HTTPError as e:
+ # check if we are being rate limited by the server
+ if e.code == 429:
+ if 'Retry-After' in e.headers:
+ retry = e.headers['Retry-After']
+ time.sleep(float(retry))
+ self.perform_rest_action(endpoint, hdrs, params)
+ else:
+ sys.stderr.write('Request failed for {0}: Status code: {1.code} Reason: {1.reason}\n'.format(endpoint, e))
+
+ return data
+
+ def get_motifs(self, species, gene, motifs):
+ query = str('?query={0}&species={1}&list={2}'.format(gene, species, motifs))
+ if query:
+ aresite = self.perform_rest_action(
+ query
+ )
+ return aresite
+ return None
+
+def run(species, gene, motifs):
+ client = AREsiteRestClient()
+ aresite = client.get_motifs(species, gene, motifs)
+ if aresite:
+
+ mots = aresite["exact_motifs"]
+ starts = aresite["motif_starts"]
+ ends = aresite["motif_ends"]
+ chrs = aresite["chromosomes"]
+ strands = aresite["strands"]
+ transcripts = aresite["transcripts"]
+ genes = aresite["genes"]
+ evh = aresite["hur_evidence"]
+ evt = aresite["ttp_evidence"]
+ eva = aresite["auf_evidence"]
+ anno = aresite["annotation"]
+
+ aresite = zip(chrs,starts,ends,mots,anno,strands,genes,transcripts,evh,evt,eva)
+
+ def getKey(item):
+ return item[1]
+
+ aresite = sorted(aresite, key=getKey)
+
+ for site in aresite:
+ print("\t".join(site))
+
+
+if __name__ == '__main__':
+ run(options.species, options.gene, options.motif)
diff -r 000000000000 -r 6d3269dc319e aresite2.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/aresite2.xml Thu Feb 02 19:33:27 2017 -0500
@@ -0,0 +1,53 @@
+
+ AREsite2 REST Interface
+
+ requests
+ six
+
+
+ '$AREsite2_REST_out'
+]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 10.1093/nar/gkv1238
+
+
diff -r 000000000000 -r 6d3269dc319e test-data/AREsite2_Rest_ATTTA_cxcl2_Homo_sapiens.bed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/AREsite2_Rest_ATTTA_cxcl2_Homo_sapiens.bed Thu Feb 02 19:33:27 2017 -0500
@@ -0,0 +1,11 @@
+chr4 74097045 74097050 ATTTA Exon^3UTR - ENSG00000081041 ENST00000508487 NA NA NA
+chr4 74097083 74097088 ATTTA Exon^3UTR - ENSG00000081041 ENST00000508487 NA NA NA
+chr4 74097257 74097262 ATTTA Exon^3UTR - ENSG00000081041 ENST00000508487 NA NA NA
+chr4 74097449 74097454 ATTTA Exon^3UTR - ENSG00000081041 ENST00000508487 NA NA NA
+chr4 74097499 74097504 ATTTA Exon^3UTR - ENSG00000081041 ENST00000508487 NA http://www.genomebiology.com/content/supplementary/gb-2014-15-1-r12-s2.csv NA
+chr4 74097589 74097594 ATTTA Exon^3UTR - ENSG00000081041 ENST00000508487 NA NA NA
+chr4 74097593 74097598 ATTTA Exon^3UTR - ENSG00000081041 ENST00000508487 NA NA NA
+chr4 74097597 74097602 ATTTA Exon^3UTR - ENSG00000081041 ENST00000508487 NA NA NA
+chr4 74097601 74097606 ATTTA Exon^3UTR - ENSG00000081041 ENST00000508487 NA NA NA
+chr4 74097605 74097610 ATTTA Exon^3UTR - ENSG00000081041 ENST00000508487 NA NA NA
+chr4 74098127 74098132 ATTTA Intron^CDS - ENSG00000081041 ENST00000508487 NA NA NA