Repository 'aresite2'
hg clone https://toolshed.g2.bx.psu.edu/repos/rnateam/aresite2

Changeset 0:6d3269dc319e (2017-02-02)
Next changeset 1:138ff4068d27 (2017-03-04)
Commit message:
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/aresite2 commit f437f5e8c6c856c6f0bb8d8ea6e34f5441ee088f
added:
aresite2.py
aresite2.xml
test-data/AREsite2_Rest_ATTTA_cxcl2_Homo_sapiens.bed
b
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)
b
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 @@
+<tool id="AREsite2_REST" name="Get motifs from AREsite2" version="0.1.2">
+    <description>AREsite2 REST Interface</description>
+    <requirements>
+        <requirement type="package" version="2.12.4">requests</requirement>
+        <requirement type="package" version="1.10.0">six</requirement>
+    </requirements>
+    <command>
+<![CDATA[
+python '$__tool_directory__/aresite2.py'
+-g '$gene'
+-m '$motif'
+-s '$species_selector'
+> '$AREsite2_REST_out'
+]]>
+    </command>
+
+    <inputs>
+    <param name="gene" type="text" label="Gene ID to search for" help="Try e.g. cxcl2" />
+    <param name="species_selector" type="select" label="Select species">
+        <option value="Homo_sapiens" selected="true"></option>
+        <option value="Mus_musculus"></option>
+ <option value="Danio_rerio"></option>
+ <option value="Drosophila_melanogaster"></option>
+ <option value="Caenorhabditis_elegans"></option>
+    </param>
+    <param name="motif" type="text" label="Motif to search for" help="Choose a single motif, e.g. ATTTA" />
+    </inputs>
+
+    <outputs>
+        <data name="AREsite2_REST_out" label="AREsite2_Rest_${motif}_${gene}_${species_selector}" format="bed" />
+    </outputs>
+
+    <tests>
+        <test>
+          <param name="species" value="Homo_sapiens" />
+          <param name="motif" value="ATTTA" />
+   <param name="gene" value="Cxcl2" />
+          <output name="outputFile" file="AREsite2_Rest_ATTTA_cxcl2_Homo_sapiens.bed" />
+        </test>
+    </tests>
+
+    <help>
+<![CDATA[
+**What it does**
+
+Retrieve motif information in BED format from AREsite2 using its REST API.
+
+]]>
+    </help>
+    <citations>
+      <citation type="doi">10.1093/nar/gkv1238</citation>
+    </citations>
+</tool>
b
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
b
@@ -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 <a href="http://www.genomebiology.com/content/supplementary/gb-2014-15-1-r12-s2.csv">http://www.genomebiology.com/content/supplementary/gb-2014-15-1-r12-s2.csv</a> 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