aboutsummaryrefslogtreecommitdiff
path: root/workflows/pangenome-generate/relabel-seqs.py
diff options
context:
space:
mode:
authorlltommy2020-04-22 18:37:35 +0200
committerlltommy2020-04-22 18:37:35 +0200
commit5582ed4f4bd6bd5b03d20a0c88dc7fa27d2d5cde (patch)
tree466dfc19d583aedb44f366ddacc6fa8e0b7a890e /workflows/pangenome-generate/relabel-seqs.py
parentb34531de1f49e4faa82a9c350f0c5d4169ccfeb4 (diff)
parentce696b41b3476891ecb05185d64c289b140a73af (diff)
downloadbh20-seq-resource-5582ed4f4bd6bd5b03d20a0c88dc7fa27d2d5cde.tar.gz
bh20-seq-resource-5582ed4f4bd6bd5b03d20a0c88dc7fa27d2d5cde.tar.lz
bh20-seq-resource-5582ed4f4bd6bd5b03d20a0c88dc7fa27d2d5cde.zip
Merge branch 'master' of https://github.com/arvados/bh20-seq-resource
Diffstat (limited to 'workflows/pangenome-generate/relabel-seqs.py')
-rw-r--r--workflows/pangenome-generate/relabel-seqs.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/workflows/pangenome-generate/relabel-seqs.py b/workflows/pangenome-generate/relabel-seqs.py
index 1188ceb..6b022a0 100644
--- a/workflows/pangenome-generate/relabel-seqs.py
+++ b/workflows/pangenome-generate/relabel-seqs.py
@@ -1,5 +1,17 @@
-reads = $(inputs.readsFA)
-subjects = $(inputs.subjects)
+import os
+import json
+
+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
+
+reads = readitems("block")
+subjects = readitems("subs")
relabeled_fasta = open("relabeledSeqs.fasta", "wt")
original_labels = open("originalLabels.ttl", "wt")
@@ -7,12 +19,12 @@ original_labels = open("originalLabels.ttl", "wt")
for i, r in enumerate(reads):
with open(r["path"], "rt") as fa:
label = fa.readline()
- original_labels.write("<%s> <http://biohackathon.org/bh20-seq-schema/original_fasta_label> \\"%s\\" .\\n" % (subjects[i], label[1:].strip().replace('"', '\\\\"')))
- relabeled_fasta.write(">"+subjects[i]+"\\n")
+ original_labels.write("<%s> <http://biohackathon.org/bh20-seq-schema/original_fasta_label> \"%s\" .\n" % (subjects[i], label[1:].strip().replace('"', '\\"')))
+ relabeled_fasta.write(">"+subjects[i]+"\n")
data = fa.read(8096)
while data:
relabeled_fasta.write(data)
- endswithnewline = data.endswith("\\n")
+ endswithnewline = data.endswith("\n")
data = fa.read(8096)
if not endswithnewline:
- relabeled_fasta.write("\\n")
+ relabeled_fasta.write("\n")