aboutsummaryrefslogtreecommitdiff
path: root/workflows/pangenome-generate/merge-metadata.py
diff options
context:
space:
mode:
authorLLTommy2020-04-23 20:18:36 +0200
committerGitHub2020-04-23 20:18:36 +0200
commit7049cd5d29acd601ccbbc9d04f001b84a51e9bd5 (patch)
tree34a1254d81c2e526427fedb1deaa9f8441e8b260 /workflows/pangenome-generate/merge-metadata.py
parentf38b9c6f22b82327df9648938a5a4bcf863d8c41 (diff)
parentc7612e7eda5cd38bfbb2d293bebf732893a41b6c (diff)
downloadbh20-seq-resource-7049cd5d29acd601ccbbc9d04f001b84a51e9bd5.tar.gz
bh20-seq-resource-7049cd5d29acd601ccbbc9d04f001b84a51e9bd5.tar.lz
bh20-seq-resource-7049cd5d29acd601ccbbc9d04f001b84a51e9bd5.zip
Merge branch 'master' into patch-3
Diffstat (limited to 'workflows/pangenome-generate/merge-metadata.py')
-rw-r--r--workflows/pangenome-generate/merge-metadata.py40
1 files changed, 36 insertions, 4 deletions
diff --git a/workflows/pangenome-generate/merge-metadata.py b/workflows/pangenome-generate/merge-metadata.py
index 64275b1..65d08a6 100644
--- a/workflows/pangenome-generate/merge-metadata.py
+++ b/workflows/pangenome-generate/merge-metadata.py
@@ -1,9 +1,28 @@
+import re
import schema_salad.schema
import schema_salad.jsonld_context
+import json
+import sys
+import os
+import logging
-metadataSchema = '$(inputs.metadataSchema.path)'
-metadata = $(inputs.metadata)
-subjects = $(inputs.subjects)
+metadataSchema = sys.argv[1]
+originalLabels = sys.argv[2]
+dups = None
+if len(sys.argv) == 4:
+ dups = sys.argv[3]
+
+def readitems(stem):
+ items = []
+ b = 1
+ while os.path.exists("%s%i" % (stem, b)):
+ with open("%s%i" % (stem, b)) as f:
+ items.extend(json.load(f))
+ b += 1
+ return items
+
+metadata = readitems("block")
+subjects = readitems("subs")
(document_loader,
avsc_names,
@@ -11,7 +30,20 @@ subjects = $(inputs.subjects)
metaschema_loader) = schema_salad.schema.load_schema(metadataSchema)
for i, m in enumerate(metadata):
- doc, metadata = schema_salad.schema.load_and_validate(document_loader, avsc_names, m["path"], True)
+ doc, metadata = schema_salad.schema.load_and_validate(document_loader, avsc_names, m["path"], False, False)
doc["id"] = subjects[i]
g = schema_salad.jsonld_context.makerdf(subjects[i], doc, document_loader.ctx)
print(g.serialize(format="ntriples").decode("utf-8"))
+
+if dups:
+ sameseqs = open(dups, "rt")
+ for d in sameseqs:
+ logging.warn(d)
+ g = re.match(r"\d+\t(.*)", d)
+ logging.warn("%s", g.group(1))
+ sp = g.group(1).split(",")
+ for n in sp[1:]:
+ print("<%s> <http://biohackathon.org/bh20-seq-schema/has_duplicate_sequence> <%s> ." % (n.strip(), sp[0].strip()))
+
+orig = open(originalLabels, "rt")
+print(orig.read())