aboutsummaryrefslogtreecommitdiff
path: root/bh20sequploader/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'bh20sequploader/main.py')
-rw-r--r--bh20sequploader/main.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/bh20sequploader/main.py b/bh20sequploader/main.py
new file mode 100644
index 0000000..8b8fefe
--- /dev/null
+++ b/bh20sequploader/main.py
@@ -0,0 +1,56 @@
+import argparse
+import time
+import arvados
+import arvados.collection
+import json
+import urllib.request
+import socket
+import getpass
+from .qc_metadata import qc_metadata
+
+ARVADOS_API_HOST='lugli.arvadosapi.com'
+ARVADOS_API_TOKEN='2fbebpmbo3rw3x05ueu2i6nx70zhrsb1p22ycu3ry34m4x4462'
+UPLOAD_PROJECT='lugli-j7d0g-n5clictpuvwk8aa'
+
+def main():
+ 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, insecure=True)
+
+ qc_metadata(args.metadata.name)
+
+ col = arvados.collection.Collection(api_client=api)
+
+ print("Reading FASTA")
+ with col.open("sequence.fasta", "w") as f:
+ r = args.sequence.read(65536)
+ print(r[0:20])
+ while r:
+ f.write(r)
+ r = args.sequence.read(65536)
+
+ print("Reading metadata")
+ with col.open("metadata.yaml", "w") as f:
+ r = args.metadata.read(65536)
+ print(r[0:20])
+ 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)
+
+if __name__ == "__main__":
+ main()