aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Amstutz2020-04-06 12:46:38 -0400
committerPeter Amstutz2020-04-06 12:46:38 -0400
commitfd137721188b0044b9259b3a9aed14c155477888 (patch)
treee1faa26b9fcaa188f02d1409517ecc0f15a0086a
parentbd8608e32072b6898342b32e3f146483b25a27d6 (diff)
downloadbh20-seq-resource-fd137721188b0044b9259b3a9aed14c155477888.tar.gz
bh20-seq-resource-fd137721188b0044b9259b3a9aed14c155477888.tar.lz
bh20-seq-resource-fd137721188b0044b9259b3a9aed14c155477888.zip
Now uploads data
-rw-r--r--bh20sequploader/main.py47
-rw-r--r--setup.py4
2 files changed, 48 insertions, 3 deletions
diff --git a/bh20sequploader/main.py b/bh20sequploader/main.py
index e3095b2..049a21c 100644
--- a/bh20sequploader/main.py
+++ b/bh20sequploader/main.py
@@ -1,2 +1,47 @@
+import argparse
+import time
+import arvados
+import arvados.collection
+import json
+import urllib.request
+import socket
+import getpass
+
+ARVADOS_API_HOST='lugli.arvadosapi.com'
+ARVADOS_API_TOKEN='2fbebpmbo3rw3x05ueu2i6nx70zhrsb1p22ycu3ry34m4x4462'
+UPLOAD_PROJECT='lugli-j7d0g-n5clictpuvwk8aa'
+WORKFLOW=''
+
def main():
- print("hello world")
+ parser = argparse.ArgumentParser(description='Upload SARS-CoV-19 sequences for analysis')
+ parser.add_argument('sequence', type=argparse.FileType('r'), help='sequence FASTA')
+ parser.add_argument('metadata', type=argparse.FileType('r'), help='sequence metadata json')
+ args = parser.parse_args()
+
+ api = arvados.api(host=ARVADOS_API_HOST, token=ARVADOS_API_TOKEN)
+
+ col = arvados.collection.Collection(api_client=api)
+
+ with col.open("sequence.fasta", "w") as f:
+ r = args.sequence.read(65536)
+ while r:
+ f.write(r)
+ r = args.sequence.read(65536)
+
+ with col.open("metadata.jsonld", "w") as f:
+ r = args.metadata.read(65536)
+ while r:
+ f.write(r)
+ r = args.metadata.read(65536)
+
+ external_ip = urllib.request.urlopen('https://ident.me').read().decode('utf8')
+
+ properties = {
+ "upload_app": "bh20-seq-uploader",
+ "upload_ip": external_ip,
+ "upload_user": "%s@%s" % (getpass.getuser(), socket.gethostname())
+ }
+
+ col.save_new(owner_uuid=UPLOAD_PROJECT, name="Uploaded by %s from %s" %
+ (properties['upload_user'], properties['upload_ip']),
+ properties=properties, ensure_unique_name=True)
diff --git a/setup.py b/setup.py
index acff69b..d5c71b2 100644
--- a/setup.py
+++ b/setup.py
@@ -15,7 +15,7 @@ try:
except ImportError:
tagger = egg_info_cmd.egg_info
-install_requires = []
+install_requires = ["arvados-python-client"]
needs_pytest = {"pytest", "test", "ptr"}.intersection(sys.argv)
pytest_runner = ["pytest < 6", "pytest-runner < 5"] if needs_pytest else []
@@ -35,7 +35,7 @@ setup(
tests_require=["pytest<5"],
entry_points={
"console_scripts": [
- "bh20sequploader=bh20sequploader.main:main"
+ "bh20-seq-uploader=bh20sequploader.main:main"
]
},
zip_safe=True,