changeset 0:bbf3b6e6a026 tip

planemo upload commit b'4aa8338dc8bcd7f6c0fb675044ea9d0c045ee7f3\n'
author jpayne
date Tue, 05 Dec 2017 11:42:47 -0500
parents
children
files bio2srr.py bio2srr.xml test-data/test.txt
diffstat 3 files changed, 99 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bio2srr.py	Tue Dec 05 11:42:47 2017 -0500
@@ -0,0 +1,58 @@
+#! /usr/bin/env python3
+
+"Grab SRR numbers from BioProjects via the EMBL-ENA REST API's."
+
+import requests
+import sys
+
+sra_exp_query = "http://www.ebi.ac.uk/ebisearch/ws/rest/sra-experiment?query={bioproject}"
+
+sample = """{
+    "hitCount": 2,
+    "entries": [
+        {
+            "id": "SRX377510",
+            "source": "sra-experiment"
+        },
+        {
+            "id": "SRX583279",
+            "source": "sra-experiment"
+        }
+    ],
+    "facets": []
+}"""
+
+sra_run_query = "http://www.ebi.ac.uk/ebisearch/ws/rest/sra-run?query={experiment}"
+
+sample = """{
+    "hitCount": 1,
+    "entries": [
+        {
+            "id": "SRR1029665",
+            "source": "sra-run"
+        }
+    ],
+    "facets": []
+}"""
+
+if __name__ == "__main__":
+	try:
+		bioproject = sys.argv[1]
+		b_result = requests.get(sra_exp_query.format(bioproject=bioproject), headers=dict(Accept="application/json"))
+		b_result.raise_for_status()
+		if b_result.json()['entries']:
+			for experiment in [d['id'] for d in b_result.json()['entries']]:
+				r_result = requests.get(sra_run_query.format(experiment=experiment), headers=dict(Accept="application/json"))
+				r_result.raise_for_status()
+				for run in [d['id'] for d in r_result.json()['entries']]:
+					print(run)
+		else:
+			print(f"No results found for '{bioproject}'.", file=sys.stderr)
+			quit(1)
+	except IndexError:
+		raise ValueError("Please provide an NCBI BioProject, NCBI BioSample, EMBL Project, or EMBL Study accession.")
+	except KeyError as e:
+		raise ValueError() from e
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bio2srr.xml	Tue Dec 05 11:42:47 2017 -0500
@@ -0,0 +1,26 @@
+<tool id="bio2srr" name="Bioproject to SRR" version="0.1.0">
+	<description>Retrieve SRR accessions from BioProject or BioSample.</description>
+    <requirements>
+    	<requirement type="package" version="2.18.4">requests</requirement>
+    </requirements>
+    <command detect_errors="exit_code"><![CDATA[
+        $__tool_directory__/bio2srr.py "$input1" > "$output"
+    ]]></command>
+    <inputs>
+        <param type="text" name="input1" label="BioProject or BioSample" />
+    </inputs>
+    <outputs>
+    	<data format="txt" name="output" />
+    </outputs>
+    <tests>
+    	<test>
+    		<param name="input1" value="NOTHING" />
+    		<output name="output" file="test.txt" />
+    	</test>
+    </tests>
+    <help><![CDATA[
+        Retrieve SRR accessions by BioSample or BioProject.
+    ]]></help>
+    <citations>
+    </citations>
+</tool>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/test.txt	Tue Dec 05 11:42:47 2017 -0500
@@ -0,0 +1,15 @@
+ERR2130609
+ERR2130611
+ERR2130613
+ERR2130497
+ERR2130499
+ERR2130502
+ERR2130503
+ERR2130506
+ERR2130508
+ERR2130510
+ERR2130512
+ERR2130517
+ERR2130520
+ERR2130521
+ERR2130523
\ No newline at end of file