From d29dfd593233541b85c1cefb239650279d57d59f Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Mon, 20 Apr 2020 13:41:56 -0400 Subject: Relabel sequences to match metadata subjects. Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- workflows/pangenome-generate/pangenome-generate.cwl | 12 +++++++++++- workflows/pangenome-generate/relabel-seqs.cwl | 19 +++++++++++++++++++ workflows/pangenome-generate/relabel-seqs.py | 13 +++++++++++++ workflows/pangenome-generate/seqkit-rmdup.cwl | 5 +++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 workflows/pangenome-generate/relabel-seqs.cwl create mode 100644 workflows/pangenome-generate/relabel-seqs.py diff --git a/workflows/pangenome-generate/pangenome-generate.cwl b/workflows/pangenome-generate/pangenome-generate.cwl index 2710743..896f936 100644 --- a/workflows/pangenome-generate/pangenome-generate.cwl +++ b/workflows/pangenome-generate/pangenome-generate.cwl @@ -22,8 +22,18 @@ outputs: type: File outputSource: mergeMetadata/merged steps: + relabel: + in: + readsFA: inputReads + subjects: subjects + out: [relabeledSeqs] + run: relabel-seqs.cwl + common: + in: {readsFA: relabel/relabeledSeqs} + out: [duplicatedReads] + run: seqkit-common.cwl dedup: - in: {readsFA: inputReads} + in: {readsFA: relabel/relabeledSeqs} out: [readsMergeDedup] run: seqkit-rmdup.cwl overlapReads: diff --git a/workflows/pangenome-generate/relabel-seqs.cwl b/workflows/pangenome-generate/relabel-seqs.cwl new file mode 100644 index 0000000..b5b7231 --- /dev/null +++ b/workflows/pangenome-generate/relabel-seqs.cwl @@ -0,0 +1,19 @@ +cwlVersion: v1.1 +class: CommandLineTool +inputs: + readsFA: File[] + subjects: string[] +outputs: + relabeledSeqs: + type: stdout +requirements: + InlineJavascriptRequirement: {} + InitialWorkDirRequirement: + listing: + - entry: {$include: relabel-seqs.py} + entryname: relabel-seqs.py +hints: + DockerRequirement: + dockerPull: commonworkflowlanguage/cwltool_module +stdout: relabeledSeqs.fasta +baseCommand: [python, relabel-seqs.py] diff --git a/workflows/pangenome-generate/relabel-seqs.py b/workflows/pangenome-generate/relabel-seqs.py new file mode 100644 index 0000000..32f2386 --- /dev/null +++ b/workflows/pangenome-generate/relabel-seqs.py @@ -0,0 +1,13 @@ +import sys + +reads = $(inputs.readsFA) +subjects = $(inputs.subjects) + +for i, r in enumerate(reads): + with open(r["path"], "rt") as fa: + fa.readline() + print(">"+subjects[i]) + data = fa.read(8096) + while data: + sys.stdout.write(data) + data = fa.read(8096) diff --git a/workflows/pangenome-generate/seqkit-rmdup.cwl b/workflows/pangenome-generate/seqkit-rmdup.cwl index d3626f5..07184c3 100644 --- a/workflows/pangenome-generate/seqkit-rmdup.cwl +++ b/workflows/pangenome-generate/seqkit-rmdup.cwl @@ -7,6 +7,10 @@ outputs: type: File outputBinding: glob: readsMergeDedup.fasta + dups: + type: File + outputBinding: + glob: dups.txt requirements: InlineJavascriptRequirement: {} hints: @@ -28,5 +32,6 @@ baseCommand: seqkit arguments: [rmdup, --by-seq, --ignore-case, + --dup-num-file, dups.txt, -o, readsMergeDedup.fasta, $(inputs.readsFA)] -- cgit v1.2.3 From 9ddcfeacb3191638f42b08af999889d867f0f81c Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Mon, 20 Apr 2020 14:57:25 -0400 Subject: Better handling of duplicate sequences Also save original fasta label in metadata --- bh20sequploader/bh20seq-schema.yml | 11 ++++++++++- workflows/pangenome-generate/merge-metadata.cwl | 2 ++ workflows/pangenome-generate/merge-metadata.py | 21 ++++++++++++++++++++- workflows/pangenome-generate/pangenome-generate.cwl | 10 ++++------ workflows/pangenome-generate/relabel-seqs.cwl | 10 ++++++++-- workflows/pangenome-generate/relabel-seqs.py | 12 +++++++----- workflows/pangenome-generate/seqkit-rmdup.cwl | 4 ++-- workflows/pangenome-generate/testjob.yml | 16 ++++++++++++++++ 8 files changed, 69 insertions(+), 17 deletions(-) create mode 100644 workflows/pangenome-generate/testjob.yml diff --git a/bh20sequploader/bh20seq-schema.yml b/bh20sequploader/bh20seq-schema.yml index 64008f2..982447c 100644 --- a/bh20sequploader/bh20seq-schema.yml +++ b/bh20sequploader/bh20seq-schema.yml @@ -18,6 +18,7 @@ $graph: jsonldPredicate: _id: http://www.ebi.ac.uk/efo/EFO_0000532 _type: "@id" + identity: true host_id: doc: Identifer for the host. If you submit multiple samples from the same host, use the same host_id for those samples type: string @@ -29,6 +30,7 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/PATO_0000047 _type: "@id" + identity: true host_age: doc: Age of the host as number (e.g. 50) type: int? @@ -40,6 +42,7 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/NCIT_C42574 _type: "@id" + identity: true host_health_status: doc: A condition or state at a particular time type: string? @@ -79,12 +82,14 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/OBI_0001479 _type: "@id" + identity: true specimen_source2: doc: Method how the specimen was derived as NCIT IRI, e.g. http://purl.obolibrary.org/obo/NCIT_C155835 (=throat swabb) type: string? jsonldPredicate: _id: http://purl.obolibrary.org/obo/OBI_0001479 _type: "@id" + identity: true collection_date: doc: Date when the sample was taken type: string @@ -96,6 +101,7 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/GAZ_00000448 _type: "@id" + identity: true sample_storage_conditions: doc: Information about storage of a specified type, e.g. frozen specimen, paraffin, fresh .... type: string? @@ -126,6 +132,7 @@ $graph: jsonldPredicate: _id: http://edamontology.org/data_1875 _type: "@id" + identity: true virus_strain: doc: Name of the virus strain type: string? @@ -141,12 +148,14 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/OBI_0600047 _type: "@id" + identity: true sample_sequencing_technology2: doc: Technology that was used to sequence this sample (e.g Sanger, Nanopor MiniION) type: string? jsonldPredicate: _id: http://purl.obolibrary.org/obo/OBI_0600047 _type: "@id" + identity: true sequence_assembly_method: doc: Protocol which provides instructions on the alignment of sequencing reads to reference genome type: string? @@ -215,7 +224,7 @@ $graph: jsonldPredicate: _id: http://semanticscience.org/resource/SIO_000115 _type: "@id" - noLinkCheck: true + identity: true - name: MainSchema type: record diff --git a/workflows/pangenome-generate/merge-metadata.cwl b/workflows/pangenome-generate/merge-metadata.cwl index 9164c09..fcefe32 100644 --- a/workflows/pangenome-generate/merge-metadata.cwl +++ b/workflows/pangenome-generate/merge-metadata.cwl @@ -7,6 +7,8 @@ inputs: metadata: File[] metadataSchema: File subjects: string[] + dups: File? + originalLabels: File outputs: merged: stdout stdout: mergedmetadata.ttl diff --git a/workflows/pangenome-generate/merge-metadata.py b/workflows/pangenome-generate/merge-metadata.py index 64275b1..bfec781 100644 --- a/workflows/pangenome-generate/merge-metadata.py +++ b/workflows/pangenome-generate/merge-metadata.py @@ -1,9 +1,13 @@ +import re import schema_salad.schema import schema_salad.jsonld_context +import json metadataSchema = '$(inputs.metadataSchema.path)' metadata = $(inputs.metadata) subjects = $(inputs.subjects) +dups = json.loads('''$(inputs.dups)''') +originalLabels = $(inputs.originalLabels) (document_loader, avsc_names, @@ -11,7 +15,22 @@ 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")) + +import logging + +if dups: + sameseqs = open(dups["path"], "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> <%s> ." % (n.strip(), sp[0].strip())) + +orig = open(originalLabels["path"], "rt") +print(orig.read()) diff --git a/workflows/pangenome-generate/pangenome-generate.cwl b/workflows/pangenome-generate/pangenome-generate.cwl index 896f936..0cb1368 100644 --- a/workflows/pangenome-generate/pangenome-generate.cwl +++ b/workflows/pangenome-generate/pangenome-generate.cwl @@ -26,15 +26,11 @@ steps: in: readsFA: inputReads subjects: subjects - out: [relabeledSeqs] + out: [relabeledSeqs, originalLabels] run: relabel-seqs.cwl - common: - in: {readsFA: relabel/relabeledSeqs} - out: [duplicatedReads] - run: seqkit-common.cwl dedup: in: {readsFA: relabel/relabeledSeqs} - out: [readsMergeDedup] + out: [readsMergeDedup, dups] run: seqkit-rmdup.cwl overlapReads: in: {readsFA: dedup/readsMergeDedup} @@ -63,5 +59,7 @@ steps: metadata: metadata metadataSchema: metadataSchema subjects: subjects + dups: dedup/dups + originalLabels: relabel/originalLabels out: [merged] run: merge-metadata.cwl diff --git a/workflows/pangenome-generate/relabel-seqs.cwl b/workflows/pangenome-generate/relabel-seqs.cwl index b5b7231..2b780d4 100644 --- a/workflows/pangenome-generate/relabel-seqs.cwl +++ b/workflows/pangenome-generate/relabel-seqs.cwl @@ -5,7 +5,13 @@ inputs: subjects: string[] outputs: relabeledSeqs: - type: stdout + type: File + outputBinding: + glob: relabeledSeqs.fasta + originalLabels: + type: File + outputBinding: + glob: originalLabels.ttl requirements: InlineJavascriptRequirement: {} InitialWorkDirRequirement: @@ -15,5 +21,5 @@ requirements: hints: DockerRequirement: dockerPull: commonworkflowlanguage/cwltool_module -stdout: relabeledSeqs.fasta +stdout: baseCommand: [python, relabel-seqs.py] diff --git a/workflows/pangenome-generate/relabel-seqs.py b/workflows/pangenome-generate/relabel-seqs.py index 32f2386..b558fe2 100644 --- a/workflows/pangenome-generate/relabel-seqs.py +++ b/workflows/pangenome-generate/relabel-seqs.py @@ -1,13 +1,15 @@ -import sys - reads = $(inputs.readsFA) subjects = $(inputs.subjects) +relabeled_fasta = open("relabeledSeqs.fasta", "wt") +original_labels = open("originalLabels.ttl", "wt") + for i, r in enumerate(reads): with open(r["path"], "rt") as fa: - fa.readline() - print(">"+subjects[i]) + label = fa.readline() + original_labels.write("<%s> \\"%s\\" .\\n" % (subjects[i], label[1:].strip().replace('"', '\\\\"'))) + relabeled_fasta.write(">"+subjects[i]+"\\n") data = fa.read(8096) while data: - sys.stdout.write(data) + relabeled_fasta.write(data) data = fa.read(8096) diff --git a/workflows/pangenome-generate/seqkit-rmdup.cwl b/workflows/pangenome-generate/seqkit-rmdup.cwl index 07184c3..071fa66 100644 --- a/workflows/pangenome-generate/seqkit-rmdup.cwl +++ b/workflows/pangenome-generate/seqkit-rmdup.cwl @@ -1,14 +1,14 @@ cwlVersion: v1.1 class: CommandLineTool inputs: - readsFA: File[] + readsFA: File outputs: readsMergeDedup: type: File outputBinding: glob: readsMergeDedup.fasta dups: - type: File + type: File? outputBinding: glob: dups.txt requirements: diff --git a/workflows/pangenome-generate/testjob.yml b/workflows/pangenome-generate/testjob.yml new file mode 100644 index 0000000..a48aff8 --- /dev/null +++ b/workflows/pangenome-generate/testjob.yml @@ -0,0 +1,16 @@ +inputReads: + - class: File + location: ../../example/sequence.fasta + - class: File + location: ../../example/sequence.fasta +metadata: + - class: File + location: ../../example/metadata.yaml + - class: File + location: ../../example/metadata.yaml +metadataSchema: + class: File + location: ../../bh20sequploader/bh20seq-schema.yml +subjects: + - http://arvados.org/keep/seq1 + - http://arvados.org/keep/seq2 -- cgit v1.2.3 From a2a4b1a16cef38bb4ec9d222430fd396c70ba225 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Mon, 20 Apr 2020 16:46:28 -0400 Subject: Schema changes from @LLTommy --- bh20sequploader/bh20seq-schema.yml | 52 ++++++++++++++++++-------------------- bh20sequploader/bh20seq-shex.rdf | 25 +++++++++--------- 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/bh20sequploader/bh20seq-schema.yml b/bh20sequploader/bh20seq-schema.yml index 982447c..3d8604a 100644 --- a/bh20sequploader/bh20seq-schema.yml +++ b/bh20sequploader/bh20seq-schema.yml @@ -21,7 +21,7 @@ $graph: identity: true host_id: doc: Identifer for the host. If you submit multiple samples from the same host, use the same host_id for those samples - type: string + type: string? jsonldPredicate: _id: http://semanticscience.org/resource/SIO_000115 host_sex: @@ -66,16 +66,27 @@ $graph: - name: sampleSchema type: record fields: + collection_date: + doc: Date when the sample was taken + type: string + jsonldPredicate: + _id: http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C25164 + collection_location: + doc: Geographical location where the sample was collected as wikidata reference, e.g. http://www.wikidata.org/entity/Q148 (China) + type: string + jsonldPredicate: + _id: http://purl.obolibrary.org/obo/GAZ_00000448 + _type: "@id" collector_name: doc: Name of the person that took the sample - type: string + type: string? jsonldPredicate: _id: http://purl.obolibrary.org/obo/OBI_0001895 collecting_institution: doc: Institute that was responsible of sampeling - type: string + type: string? jsonldPredicate: - _id: http://semanticscience.org/resource/SIO_001167 + _id: http://purl.obolibrary.org/obo/NCIT_C41206 specimen_source: doc: Method how the specimen was derived as NCIT IRI, e.g. http://purl.obolibrary.org/obo/NCIT_C155831 (=nasopharyngeal swab) type: string? @@ -89,19 +100,6 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/OBI_0001479 _type: "@id" - identity: true - collection_date: - doc: Date when the sample was taken - type: string - jsonldPredicate: - _id: http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C25164 - collection_location: - doc: Geographical location where the sample was collected as wikidata reference, e.g. http://www.wikidata.org/entity/Q148 (China) - type: string - jsonldPredicate: - _id: http://purl.obolibrary.org/obo/GAZ_00000448 - _type: "@id" - identity: true sample_storage_conditions: doc: Information about storage of a specified type, e.g. frozen specimen, paraffin, fresh .... type: string? @@ -114,7 +112,7 @@ $graph: _id: http://semanticscience.org/resource/SIO_001167 sample_id: doc: Id of the sample as defined by the submitter - type: string + type: string? jsonldPredicate: _id: http://semanticscience.org/resource/SIO_000115 source_database_accession: @@ -167,7 +165,7 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/FLU_0000848 sequencing_coverage2: - doc: If a second sequence technology was use you can submit its coverage here + doc: If a second sequence technology was used you can submit its coverage here type: float? jsonldPredicate: _id: http://purl.obolibrary.org/obo/FLU_0000848 @@ -180,9 +178,14 @@ $graph: - name: submitterSchema type: record fields: + authors: + doc: Name of the author(s) + type: string + jsonldPredicate: + _id: http://purl.obolibrary.org/obo/NCIT_C42781 submitter_name: doc: Name of the submitter - type: string + type: string? jsonldPredicate: _id: http://semanticscience.org/resource/SIO_000116 submitter_address: @@ -192,7 +195,7 @@ $graph: _id: http://semanticscience.org/resource/SIO_000172 originating_lab: doc: Name of the laboratory that took the sample - type: string + type: string? jsonldPredicate: _id: http://purl.obolibrary.org/obo/NCIT_C37984 lab_address: @@ -208,11 +211,6 @@ $graph: type: string? jsonldPredicate: _id: http://www.ebi.ac.uk/efo/EFO_0001741 - authors: - doc: Name of the author(s) - type: string? - jsonldPredicate: - _id: http://purl.obolibrary.org/obo/NCIT_C42781 publication: doc: Reference to publication of this sample (e.g. DOI, pubmed ID, ...) type: string? @@ -232,7 +230,7 @@ $graph: fields: host: hostSchema sample: sampleSchema - virus: virusSchema? + virus: virusSchema technology: technologySchema submitter: submitterSchema id: diff --git a/bh20sequploader/bh20seq-shex.rdf b/bh20sequploader/bh20seq-shex.rdf index 8d3f5fc..6e646c7 100644 --- a/bh20sequploader/bh20seq-shex.rdf +++ b/bh20sequploader/bh20seq-shex.rdf @@ -7,6 +7,7 @@ PREFIX sio: PREFIX efo: PREFIX evs: PREFIX edam: +PREFIX wikidata: :submissionShape { MainSchema:host @:hostShape ; @@ -18,8 +19,8 @@ PREFIX edam: :hostShape { efo:EFO_0000532 [ obo:NCBITaxon_~ ] ; - obo:PATO_0000047 [ obo:NCIT_C20197 obo:NCIT_C27993 obo:NCIT_C17998 ] ; - sio:SIO_000115 xsd:string ; + sio:SIO_000115 xsd:string ?; + obo:PATO_0000047 [ obo:PATO_0000384 obo:PATO_0000383 ] ?; obo:PATO_0000011 xsd:integer ?; obo:NCIT_C42574 [ obo:UO_~ ] ?; sio:SIO_001167 xsd:string ?; @@ -27,20 +28,20 @@ PREFIX edam: } :sampleShape { - obo:OBI_0001895 xsd:string ; - sio:SIO_000115 xsd:string ; - sio:SIO_001167 xsd:string ; - evs:C25164 xsd:string ?; - obo:GAZ_00000448 [obo:GAZ_~] ?; + evs:C25164 xsd:string?; + obo:GAZ_00000448 [wikidata:~] ; + obo:OBI_0001895 xsd:string ?; + sio:SIO_001167 xsd:string ?; + sio:SIO_000115 xsd:string ?; obo:OBI_0001472 xsd:string ?; - obo:OBI_0001479 xsd:string ?; + obo:OBI_0001479 IRI {0,2}; } :submitterShape { - sio:SIO_000116 xsd:string ; - obo:NCIT_C37984 xsd:string ; + obo:NCIT_C42781 xsd:string ; + obo:NCIT_C37984 xsd:string ?; obo:NCIT_C37900 xsd:string ?; - obo:NCIT_C42781 xsd:string ?; + sio:SIO_000116 xsd:string ?; obo:OBI_0600047 xsd:string ?; sio:SIO_000115 /https:\u002F\u002Forcid.org\u002F.{4}-.{4}-.{4}-.{4}/?; sio:SIO_000172 xsd:string ?; @@ -48,7 +49,7 @@ PREFIX edam: } :technologyShape { - obo:OBI_0600047 xsd:string ; + obo:OBI_0600047 IRI {0,2} ; obo:FLU_0000848 xsd:integer ?; efo:EFO_0002699 xsd:string ?; } -- cgit v1.2.3 From 5b4bad5571d76957ddb7f9121f1f5a694efaa856 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Mon, 20 Apr 2020 17:00:21 -0400 Subject: Add identity:true to collection_location Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- bh20sequploader/bh20seq-schema.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/bh20sequploader/bh20seq-schema.yml b/bh20sequploader/bh20seq-schema.yml index 3d8604a..efc60a3 100644 --- a/bh20sequploader/bh20seq-schema.yml +++ b/bh20sequploader/bh20seq-schema.yml @@ -77,6 +77,7 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/GAZ_00000448 _type: "@id" + identity: true collector_name: doc: Name of the person that took the sample type: string? -- cgit v1.2.3 From 5f44da5804547088d0f39d0687d81598598eebe5 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Mon, 20 Apr 2020 17:01:30 -0400 Subject: Reconsidered these should be noLinkCheck --- bh20sequploader/bh20seq-schema.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bh20sequploader/bh20seq-schema.yml b/bh20sequploader/bh20seq-schema.yml index efc60a3..57f3b3d 100644 --- a/bh20sequploader/bh20seq-schema.yml +++ b/bh20sequploader/bh20seq-schema.yml @@ -18,7 +18,7 @@ $graph: jsonldPredicate: _id: http://www.ebi.ac.uk/efo/EFO_0000532 _type: "@id" - identity: true + noLinkCheck: true host_id: doc: Identifer for the host. If you submit multiple samples from the same host, use the same host_id for those samples type: string? @@ -30,7 +30,7 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/PATO_0000047 _type: "@id" - identity: true + noLinkCheck: true host_age: doc: Age of the host as number (e.g. 50) type: int? @@ -42,7 +42,7 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/NCIT_C42574 _type: "@id" - identity: true + noLinkCheck: true host_health_status: doc: A condition or state at a particular time type: string? @@ -77,7 +77,7 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/GAZ_00000448 _type: "@id" - identity: true + noLinkCheck: true collector_name: doc: Name of the person that took the sample type: string? @@ -94,7 +94,7 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/OBI_0001479 _type: "@id" - identity: true + noLinkCheck: true specimen_source2: doc: Method how the specimen was derived as NCIT IRI, e.g. http://purl.obolibrary.org/obo/NCIT_C155835 (=throat swabb) type: string? @@ -131,7 +131,7 @@ $graph: jsonldPredicate: _id: http://edamontology.org/data_1875 _type: "@id" - identity: true + noLinkCheck: true virus_strain: doc: Name of the virus strain type: string? @@ -147,14 +147,14 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/OBI_0600047 _type: "@id" - identity: true + noLinkCheck: true sample_sequencing_technology2: doc: Technology that was used to sequence this sample (e.g Sanger, Nanopor MiniION) type: string? jsonldPredicate: _id: http://purl.obolibrary.org/obo/OBI_0600047 _type: "@id" - identity: true + noLinkCheck: true sequence_assembly_method: doc: Protocol which provides instructions on the alignment of sequencing reads to reference genome type: string? @@ -223,7 +223,7 @@ $graph: jsonldPredicate: _id: http://semanticscience.org/resource/SIO_000115 _type: "@id" - identity: true + noLinkCheck: true - name: MainSchema type: record -- cgit v1.2.3 From cc557a64bb489bb39c3abf932a6cdfb87ad4a383 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Mon, 20 Apr 2020 17:25:37 -0400 Subject: Make sure there is a newline in relabeled fasta (but no blank lines) --- workflows/pangenome-generate/relabel-seqs.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/workflows/pangenome-generate/relabel-seqs.py b/workflows/pangenome-generate/relabel-seqs.py index b558fe2..1188ceb 100644 --- a/workflows/pangenome-generate/relabel-seqs.py +++ b/workflows/pangenome-generate/relabel-seqs.py @@ -12,4 +12,7 @@ for i, r in enumerate(reads): data = fa.read(8096) while data: relabeled_fasta.write(data) + endswithnewline = data.endswith("\\n") data = fa.read(8096) + if not endswithnewline: + relabeled_fasta.write("\\n") -- cgit v1.2.3 From ecae9863069585d88fc88b7f2a7434479f7425c1 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Mon, 20 Apr 2020 17:45:17 -0400 Subject: Add readsMergeDedup.fasta to output Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- workflows/pangenome-generate/pangenome-generate.cwl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/workflows/pangenome-generate/pangenome-generate.cwl b/workflows/pangenome-generate/pangenome-generate.cwl index 0cb1368..6794e2d 100644 --- a/workflows/pangenome-generate/pangenome-generate.cwl +++ b/workflows/pangenome-generate/pangenome-generate.cwl @@ -18,6 +18,9 @@ outputs: odgiRDF: type: File outputSource: odgi2rdf/rdf + readsMergeDedup: + type: File + outputSource: dedup/readsMergeDedup mergedMetadata: type: File outputSource: mergeMetadata/merged -- cgit v1.2.3 From 85b85b676d7ecc218d9f84357b2e7ea0133eed94 Mon Sep 17 00:00:00 2001 From: lltommy Date: Tue, 21 Apr 2020 16:49:47 +0200 Subject: Updated shex and manditory fields and stuff --- bh20sequploader/bh20seq-schema.yml | 10 +++++----- bh20sequploader/bh20seq-shex.rdf | 4 ++-- example/minimal_example.yaml | 6 +----- scripts/from_genbank_to_fasta_and_yaml.py | 19 +++++++++++++------ 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/bh20sequploader/bh20seq-schema.yml b/bh20sequploader/bh20seq-schema.yml index 57f3b3d..75308ab 100644 --- a/bh20sequploader/bh20seq-schema.yml +++ b/bh20sequploader/bh20seq-schema.yml @@ -66,6 +66,11 @@ $graph: - name: sampleSchema type: record fields: + sample_id: + doc: Id of the sample as defined by the submitter + type: string + jsonldPredicate: + _id: http://semanticscience.org/resource/SIO_000115 collection_date: doc: Date when the sample was taken type: string @@ -111,11 +116,6 @@ $graph: type: string? jsonldPredicate: _id: http://semanticscience.org/resource/SIO_001167 - sample_id: - doc: Id of the sample as defined by the submitter - type: string? - jsonldPredicate: - _id: http://semanticscience.org/resource/SIO_000115 source_database_accession: doc: If data is deposit at a public resource (e.g. Genbank, ENA) enter the Accession Id here type: string? diff --git a/bh20sequploader/bh20seq-shex.rdf b/bh20sequploader/bh20seq-shex.rdf index 6e646c7..59ee71b 100644 --- a/bh20sequploader/bh20seq-shex.rdf +++ b/bh20sequploader/bh20seq-shex.rdf @@ -28,11 +28,11 @@ PREFIX wikidata: } :sampleShape { - evs:C25164 xsd:string?; + sio:SIO_000115 xsd:string; obo:GAZ_00000448 [wikidata:~] ; + evs:C25164 xsd:string; obo:OBI_0001895 xsd:string ?; sio:SIO_001167 xsd:string ?; - sio:SIO_000115 xsd:string ?; obo:OBI_0001472 xsd:string ?; obo:OBI_0001479 IRI {0,2}; } diff --git a/example/minimal_example.yaml b/example/minimal_example.yaml index ed578e2..0e36a25 100644 --- a/example/minimal_example.yaml +++ b/example/minimal_example.yaml @@ -1,13 +1,10 @@ id: placeholder host: - host_id: XX1 host_species: http://purl.obolibrary.org/obo/NCBITaxon_9606 sample: sample_id: XX - collector_name: John Doe - collecting_institution: Doe university collection_date: 2020-01 collection_location: http://www.wikidata.org/entity/Q148 @@ -18,5 +15,4 @@ technology: sample_sequencing_technology: http://www.ebi.ac.uk/efo/EFO_0008632 submitter: - submitter_name: John Doe - originating_lab: John Doe's kitchen \ No newline at end of file + authors: John Doe \ No newline at end of file diff --git a/scripts/from_genbank_to_fasta_and_yaml.py b/scripts/from_genbank_to_fasta_and_yaml.py index 0c410d7..7e7c089 100644 --- a/scripts/from_genbank_to_fasta_and_yaml.py +++ b/scripts/from_genbank_to_fasta_and_yaml.py @@ -1,5 +1,5 @@ from Bio import Entrez -Entrez.email = 'insert_your_email@gmail.com' +Entrez.email = 'another_email@gmail.com' import xml.etree.ElementTree as ET import yaml @@ -31,6 +31,8 @@ for term in term_list: tmp_list = [x.split('.')[0] for x in tmp_list] print(term, len(tmp_list)) + tmp_list=tmp_list +# tmp_list = tmp_list[0:2] # restricting to small run id_set.update([x.split('.')[0] for x in tmp_list]) @@ -78,7 +80,7 @@ for path_dict_xxx_csv in [os.path.join(dir_dict_ontology_standardization, name_x term_to_uri_dict[term] = uri species_to_taxid_dict = { - 'Homo sapiens': 9606 + 'Homo sapiens': 'http://purl.obolibrary.org/obo/NCBITaxon_9606' } @@ -108,8 +110,8 @@ if not os.path.exists(dir_fasta_and_yaml_today): 'submitter': {} } - info_for_yaml_dict['sample']['sample_id'] = accession_version + info_for_yaml_dict['sample']['source_database_accession'] = accession_version info_for_yaml_dict['submitter']['authors'] = ';'.join([x.text for x in GBSeq.iter('GBAuthor')]) @@ -163,7 +165,7 @@ if not os.path.exists(dir_fasta_and_yaml_today): if GBQualifier_name_text == 'host': GBQualifier_value_text_list = GBQualifier_value_text.split('; ') - info_for_yaml_dict['host']['host_common_name'] = GBQualifier_value_text_list[0] + #info_for_yaml_dict['host']['host_common_name'] = GBQualifier_value_text_list[0] # Removed if GBQualifier_value_text_list[0] in species_to_taxid_dict: info_for_yaml_dict['host']['host_species'] = species_to_taxid_dict[GBQualifier_value_text_list[0]] @@ -206,8 +208,13 @@ if not os.path.exists(dir_fasta_and_yaml_today): elif GBQualifier_name_text == 'isolate': info_for_yaml_dict['virus']['virus_strain'] = GBQualifier_value_text elif GBQualifier_name_text == 'db_xref': - info_for_yaml_dict['virus']['virus_species'] = int(GBQualifier_value_text.split('taxon:')[1]) - + info_for_yaml_dict['virus']['virus_species'] = "http://purl.obolibrary.org/obo/NCBITaxon_"+GBQualifier_value_text.split('taxon:')[1] + + + #Remove technology key if empty! + if (info_for_yaml_dict['technology']=={}): + del info_for_yaml_dict['key'] + with open(os.path.join(dir_fasta_and_yaml_today, '{}.fasta'.format(accession_version)), 'w') as fw: fw.write('>{}\n{}'.format(accession_version, GBSeq_sequence.text.upper())) -- cgit v1.2.3 From b34531de1f49e4faa82a9c350f0c5d4169ccfeb4 Mon Sep 17 00:00:00 2001 From: lltommy Date: Tue, 21 Apr 2020 16:59:51 +0200 Subject: fixing silly mistake --- scripts/from_genbank_to_fasta_and_yaml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/from_genbank_to_fasta_and_yaml.py b/scripts/from_genbank_to_fasta_and_yaml.py index 7e7c089..91562d0 100644 --- a/scripts/from_genbank_to_fasta_and_yaml.py +++ b/scripts/from_genbank_to_fasta_and_yaml.py @@ -213,7 +213,7 @@ if not os.path.exists(dir_fasta_and_yaml_today): #Remove technology key if empty! if (info_for_yaml_dict['technology']=={}): - del info_for_yaml_dict['key'] + del info_for_yaml_dict['technology'] with open(os.path.join(dir_fasta_and_yaml_today, '{}.fasta'.format(accession_version)), 'w') as fw: fw.write('>{}\n{}'.format(accession_version, GBSeq_sequence.text.upper())) -- cgit v1.2.3 From 88d81f853cf04b7f28681dd9cdee775b0422f252 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 21 Apr 2020 12:53:19 -0400 Subject: Working on NCBI import Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- bh20sequploader/bh20seq-schema.yml | 4 ++-- bh20sequploader/main.py | 7 ++++--- scripts/foreach.sh | 18 ++++++++++++++++++ scripts/from_genbank_to_fasta_and_yaml.py | 26 ++++++++++++++------------ 4 files changed, 38 insertions(+), 17 deletions(-) create mode 100755 scripts/foreach.sh mode change 100644 => 100755 scripts/from_genbank_to_fasta_and_yaml.py diff --git a/bh20sequploader/bh20seq-schema.yml b/bh20sequploader/bh20seq-schema.yml index 75308ab..ebca35b 100644 --- a/bh20sequploader/bh20seq-schema.yml +++ b/bh20sequploader/bh20seq-schema.yml @@ -162,12 +162,12 @@ $graph: _id: http://www.ebi.ac.uk/efo/EFO_0002699 sequencing_coverage: doc: Sequence coverage defined as the average number of reads representing a given nucleotide (e.g. 100x) - type: float? + type: ["null", float, int] jsonldPredicate: _id: http://purl.obolibrary.org/obo/FLU_0000848 sequencing_coverage2: doc: If a second sequence technology was used you can submit its coverage here - type: float? + type: ["null", float, int] jsonldPredicate: _id: http://purl.obolibrary.org/obo/FLU_0000848 additional_technology_information: diff --git a/bh20sequploader/main.py b/bh20sequploader/main.py index 49d012d..2fda347 100644 --- a/bh20sequploader/main.py +++ b/bh20sequploader/main.py @@ -44,7 +44,8 @@ def main(): with col.open(target, "w") as f: r = args.sequence.read(65536) - print(r[0:20]) + seqlabel = r[1:r.index("\n")] + print(seqlabel) while r: f.write(r) r = args.sequence.read(65536) @@ -67,8 +68,8 @@ def main(): "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']), + col.save_new(owner_uuid=UPLOAD_PROJECT, name="%s uploaded by %s from %s" % + (seqlabel, properties['upload_user'], properties['upload_ip']), properties=properties, ensure_unique_name=True) print("Done") diff --git a/scripts/foreach.sh b/scripts/foreach.sh new file mode 100755 index 0000000..35b07b8 --- /dev/null +++ b/scripts/foreach.sh @@ -0,0 +1,18 @@ +#!/bin/sh +rm -rf validated fasta_and_yaml_* +mkdir -p validated +./from_genbank_to_fasta_and_yaml.py +fasta_files=$(find fasta_and_yaml_20200421/ -name "*.fasta") +for f in $fasta_files ; do + yaml=$(echo $f | rev | cut -c7- | rev).yaml + echo $f + echo $yaml + if bh20-seq-uploader --validate $f $yaml ; then + sz=$(stat --format=%s $f) + if test $sz -gt 20000 ; then + mv $f $yaml validated + else + echo "Fasta file too small" + fi + fi +done diff --git a/scripts/from_genbank_to_fasta_and_yaml.py b/scripts/from_genbank_to_fasta_and_yaml.py old mode 100644 new mode 100755 index 7e7c089..1a12513 --- a/scripts/from_genbank_to_fasta_and_yaml.py +++ b/scripts/from_genbank_to_fasta_and_yaml.py @@ -1,8 +1,10 @@ +#!/usr/bin/env python3 + from Bio import Entrez Entrez.email = 'another_email@gmail.com' import xml.etree.ElementTree as ET -import yaml +import json import os from datetime import date @@ -29,7 +31,7 @@ for term in term_list: # Remove the version in the id tmp_list = [x.split('.')[0] for x in tmp_list] - + print(term, len(tmp_list)) tmp_list=tmp_list # tmp_list = tmp_list[0:2] # restricting to small run @@ -49,11 +51,11 @@ print(term_list + ['NCBI Virus'], len(id_set)) def chunks(lst, n): for i in range(0, len(lst), n): yield lst[i:i + n] - + num_ids_for_request = 100 if not os.path.exists(dir_metadata_today): os.makedirs(dir_metadata_today) - + for i, id_x_list in enumerate(chunks(list(id_set), num_ids_for_request)): path_metadata_xxx_xml = os.path.join(dir_metadata_today, 'metadata_{}.xml'.format(i)) print('Requesting {} ids --> {}'.format(len(id_x_list), path_metadata_xxx_xml)) @@ -63,7 +65,7 @@ if not os.path.exists(dir_metadata_today): Entrez.efetch(db='nuccore', id=id_x_list, retmode='xml').read() ) - + term_to_uri_dict = {} for path_dict_xxx_csv in [os.path.join(dir_dict_ontology_standardization, name_xxx_csv) for name_xxx_csv in os.listdir(dir_dict_ontology_standardization) if name_xxx_csv.endswith('.csv')]: @@ -74,7 +76,7 @@ for path_dict_xxx_csv in [os.path.join(dir_dict_ontology_standardization, name_x if len(line.split(',')) > 2: term, uri = line.strip('\n').split('",') term = term.strip('"') - else: + else: term, uri = line.strip('\n').split(',') term_to_uri_dict[term] = uri @@ -125,7 +127,7 @@ if not os.path.exists(dir_fasta_and_yaml_today): ): if info_to_check in GBSeq_comment_text: tech_info_to_parse = GBSeq_comment_text.split('{} :: '.format(info_to_check))[1].split(' ;')[0] - + if field_in_yaml == 'sequencing_coverage': # A regular expression would be better! info_for_yaml_dict['technology'][field_in_yaml] = ';'.join( @@ -139,7 +141,7 @@ if not os.path.exists(dir_fasta_and_yaml_today): seq_tec = term_to_uri_dict[seq_tec] else: print(accession_version, 'missing technologies:', seq_tec) - + new_seq_tec_list.append(seq_tec) for n, seq_tec in enumerate(new_seq_tec_list): @@ -147,7 +149,7 @@ if not os.path.exists(dir_fasta_and_yaml_today): else: info_for_yaml_dict['technology'][field_in_yaml] = tech_info_to_parse - + #term_to_uri_dict for GBFeature in GBSeq.iter('GBFeature'): @@ -211,12 +213,12 @@ if not os.path.exists(dir_fasta_and_yaml_today): info_for_yaml_dict['virus']['virus_species'] = "http://purl.obolibrary.org/obo/NCBITaxon_"+GBQualifier_value_text.split('taxon:')[1] - #Remove technology key if empty! + # Remove technology key if empty! if (info_for_yaml_dict['technology']=={}): - del info_for_yaml_dict['key'] + del info_for_yaml_dict['technology'] with open(os.path.join(dir_fasta_and_yaml_today, '{}.fasta'.format(accession_version)), 'w') as fw: fw.write('>{}\n{}'.format(accession_version, GBSeq_sequence.text.upper())) with open(os.path.join(dir_fasta_and_yaml_today, '{}.yaml'.format(accession_version)), 'w') as fw: - yaml.dump(info_for_yaml_dict, fw, default_flow_style=False) + json.dump(info_for_yaml_dict, fw, indent=2) -- cgit v1.2.3 From 7e085b2958d9bd4f0a2b1912cf259a05b56366bc Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 21 Apr 2020 13:22:53 -0400 Subject: Tweak handling of "coverage" also fix typo Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- bh20sequploader/bh20seq-schema.yml | 4 ++-- bh20sequploader/bh20seq-shex.rdf | 2 +- scripts/dict_ontology_standardization/ncbi_speciesman_source.csv | 2 +- scripts/from_genbank_to_fasta_and_yaml.py | 9 ++++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bh20sequploader/bh20seq-schema.yml b/bh20sequploader/bh20seq-schema.yml index ebca35b..75308ab 100644 --- a/bh20sequploader/bh20seq-schema.yml +++ b/bh20sequploader/bh20seq-schema.yml @@ -162,12 +162,12 @@ $graph: _id: http://www.ebi.ac.uk/efo/EFO_0002699 sequencing_coverage: doc: Sequence coverage defined as the average number of reads representing a given nucleotide (e.g. 100x) - type: ["null", float, int] + type: float? jsonldPredicate: _id: http://purl.obolibrary.org/obo/FLU_0000848 sequencing_coverage2: doc: If a second sequence technology was used you can submit its coverage here - type: ["null", float, int] + type: float? jsonldPredicate: _id: http://purl.obolibrary.org/obo/FLU_0000848 additional_technology_information: diff --git a/bh20sequploader/bh20seq-shex.rdf b/bh20sequploader/bh20seq-shex.rdf index 59ee71b..31e714f 100644 --- a/bh20sequploader/bh20seq-shex.rdf +++ b/bh20sequploader/bh20seq-shex.rdf @@ -50,7 +50,7 @@ PREFIX wikidata: :technologyShape { obo:OBI_0600047 IRI {0,2} ; - obo:FLU_0000848 xsd:integer ?; + obo:FLU_0000848 xsd:double ?; efo:EFO_0002699 xsd:string ?; } diff --git a/scripts/dict_ontology_standardization/ncbi_speciesman_source.csv b/scripts/dict_ontology_standardization/ncbi_speciesman_source.csv index 2905588..909cf37 100644 --- a/scripts/dict_ontology_standardization/ncbi_speciesman_source.csv +++ b/scripts/dict_ontology_standardization/ncbi_speciesman_source.csv @@ -1,4 +1,4 @@ -nasopharyngeal swab, http://purl.obolibrary.org/obo/NCIT_C155831 +nasopharyngeal swab,http://purl.obolibrary.org/obo/NCIT_C155831 nasopharyngeal exudate,http://purl.obolibrary.org/obo/NCIT_C155831 respiratory swab,http://purl.obolibrary.org/obo/NCIT_C155831 naso-pharyngeal exudate,http://purl.obolibrary.org/obo/NCIT_C155831 diff --git a/scripts/from_genbank_to_fasta_and_yaml.py b/scripts/from_genbank_to_fasta_and_yaml.py index 1a12513..00c0012 100755 --- a/scripts/from_genbank_to_fasta_and_yaml.py +++ b/scripts/from_genbank_to_fasta_and_yaml.py @@ -130,9 +130,12 @@ if not os.path.exists(dir_fasta_and_yaml_today): if field_in_yaml == 'sequencing_coverage': # A regular expression would be better! - info_for_yaml_dict['technology'][field_in_yaml] = ';'.join( - [x.strip('(average)').strip("reads/nt").replace(',', '.').strip(' xX>') for x in tech_info_to_parse.split(';')] - ) + try: + info_for_yaml_dict['technology'][field_in_yaml] = float( + tech_info_to_parse.strip('(average)').strip("reads/nt").replace(',', '.').strip(' xX>')) + except ValueError: + print(accession_version, "Couldn't make sense of Coverage '%s'" % tech_info_to_parse) + pass elif field_in_yaml == 'sample_sequencing_technology': new_seq_tec_list = [] for seq_tec in tech_info_to_parse.split(';'): -- cgit v1.2.3 From cad23032ecf6ef325aab2978d5df36609ad50088 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 21 Apr 2020 18:16:47 +0000 Subject: add noLinkCheck to specimen_source2 --- bh20sequploader/bh20seq-schema.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/bh20sequploader/bh20seq-schema.yml b/bh20sequploader/bh20seq-schema.yml index 75308ab..1ceebe2 100644 --- a/bh20sequploader/bh20seq-schema.yml +++ b/bh20sequploader/bh20seq-schema.yml @@ -106,6 +106,7 @@ $graph: jsonldPredicate: _id: http://purl.obolibrary.org/obo/OBI_0001479 _type: "@id" + noLinkCheck: true sample_storage_conditions: doc: Information about storage of a specified type, e.g. frozen specimen, paraffin, fresh .... type: string? -- cgit v1.2.3 From f4c3da88c1233802fea46cc972a81dc3b5b51185 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 21 Apr 2020 15:37:58 -0400 Subject: Work around CWL content size limit by chunking Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- bh20sequploader/main.py | 1 + workflows/pangenome-generate/relabel-seqs.cwl | 31 +++++++++++++++++++++++---- workflows/pangenome-generate/relabel-seqs.py | 22 +++++++++++++------ 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/bh20sequploader/main.py b/bh20sequploader/main.py index 2fda347..4c4711d 100644 --- a/bh20sequploader/main.py +++ b/bh20sequploader/main.py @@ -63,6 +63,7 @@ def main(): external_ip = urllib.request.urlopen('https://ident.me').read().decode('utf8') properties = { + "sequence_label": seqlabel, "upload_app": "bh20-seq-uploader", "upload_ip": external_ip, "upload_user": "%s@%s" % (getpass.getuser(), socket.gethostname()) diff --git a/workflows/pangenome-generate/relabel-seqs.cwl b/workflows/pangenome-generate/relabel-seqs.cwl index 2b780d4..01196f6 100644 --- a/workflows/pangenome-generate/relabel-seqs.cwl +++ b/workflows/pangenome-generate/relabel-seqs.cwl @@ -3,6 +3,10 @@ class: CommandLineTool inputs: readsFA: File[] subjects: string[] + script: + type: File + default: {class: File, location: relabel-seqs.py} + inputBinding: {} outputs: relabeledSeqs: type: File @@ -15,11 +19,30 @@ outputs: requirements: InlineJavascriptRequirement: {} InitialWorkDirRequirement: - listing: - - entry: {$include: relabel-seqs.py} - entryname: relabel-seqs.py + listing: | + ${ + var i = 0; + var b = 1; + var out = []; + for (; i < inputs.readsFA.length; i++) { + var block = []; + for (; i < (b*100) && i < inputs.readsFA.length; i++) { + block.push(inputs.readsFA[i]); + } + out.push({ + entryname: "block"+b, + entry: JSON.stringify(block) + }); + b++; + } + out.push({ + entry: JSON.stringify(inputs.subjects), + entryname: "subjects" + }); + return out; + } hints: DockerRequirement: dockerPull: commonworkflowlanguage/cwltool_module stdout: -baseCommand: [python, relabel-seqs.py] +baseCommand: [python] diff --git a/workflows/pangenome-generate/relabel-seqs.py b/workflows/pangenome-generate/relabel-seqs.py index 1188ceb..970540f 100644 --- a/workflows/pangenome-generate/relabel-seqs.py +++ b/workflows/pangenome-generate/relabel-seqs.py @@ -1,5 +1,15 @@ -reads = $(inputs.readsFA) -subjects = $(inputs.subjects) +import os +import json + +reads = [] +b = 1 +while os.path.exists("block%i" % b): + with open("block%i" % b) as f: + reads.extend(json.load(f)) + b += 1 + +with open("subjects") as f: + subjects = json.load(f) relabeled_fasta = open("relabeledSeqs.fasta", "wt") original_labels = open("originalLabels.ttl", "wt") @@ -7,12 +17,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> \\"%s\\" .\\n" % (subjects[i], label[1:].strip().replace('"', '\\\\"'))) - relabeled_fasta.write(">"+subjects[i]+"\\n") + original_labels.write("<%s> \"%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") -- cgit v1.2.3 From 61726edb9293fe529e6efbe5bb6f1cc953bb3c4e Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 21 Apr 2020 16:20:10 -0400 Subject: Workaround CWL limit by chunking file list Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- workflows/pangenome-generate/merge-metadata.cwl | 46 +++++++++++++++++++++---- workflows/pangenome-generate/merge-metadata.py | 33 ++++++++++++------ workflows/pangenome-generate/relabel-seqs.cwl | 12 ++++--- workflows/pangenome-generate/relabel-seqs.py | 18 +++++----- 4 files changed, 79 insertions(+), 30 deletions(-) diff --git a/workflows/pangenome-generate/merge-metadata.cwl b/workflows/pangenome-generate/merge-metadata.cwl index fcefe32..4d9c808 100644 --- a/workflows/pangenome-generate/merge-metadata.cwl +++ b/workflows/pangenome-generate/merge-metadata.cwl @@ -5,16 +5,48 @@ hints: dockerPull: commonworkflowlanguage/cwltool_module inputs: metadata: File[] - metadataSchema: File subjects: string[] - dups: File? - originalLabels: File + metadataSchema: + type: File + inputBinding: {position: 2} + originalLabels: + type: File + inputBinding: {position: 3} + dups: + type: File? + inputBinding: {position: 4} + script: + type: File + inputBinding: {position: 1} + default: {class: File, location: merge-metadata.py} outputs: merged: stdout stdout: mergedmetadata.ttl requirements: + InlineJavascriptRequirement: {} InitialWorkDirRequirement: - listing: - - entry: {$include: merge-metadata.py} - entryname: merge-metadata.py -baseCommand: [python3, merge-metadata.py] + listing: | + ${ + var i = 0; + var b = 1; + var out = []; + for (; i < inputs.metadata.length; i++) { + var block = []; + var sub = []; + for (; i < (b*150) && i < inputs.metadata.length; i++) { + block.push(inputs.metadata[i]); + sub.push(inputs.subjects[i]); + } + out.push({ + entryname: "block"+b, + entry: JSON.stringify(block) + }); + out.push({ + entryname: "subs"+b, + entry: JSON.stringify(sub) + }); + b++; + } + return out; + } +baseCommand: python diff --git a/workflows/pangenome-generate/merge-metadata.py b/workflows/pangenome-generate/merge-metadata.py index bfec781..65d08a6 100644 --- a/workflows/pangenome-generate/merge-metadata.py +++ b/workflows/pangenome-generate/merge-metadata.py @@ -2,12 +2,27 @@ import re import schema_salad.schema import schema_salad.jsonld_context import json +import sys +import os +import logging + +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 -metadataSchema = '$(inputs.metadataSchema.path)' -metadata = $(inputs.metadata) -subjects = $(inputs.subjects) -dups = json.loads('''$(inputs.dups)''') -originalLabels = $(inputs.originalLabels) +metadata = readitems("block") +subjects = readitems("subs") (document_loader, avsc_names, @@ -20,17 +35,15 @@ for i, m in enumerate(metadata): g = schema_salad.jsonld_context.makerdf(subjects[i], doc, document_loader.ctx) print(g.serialize(format="ntriples").decode("utf-8")) -import logging - if dups: - sameseqs = open(dups["path"], "rt") + sameseqs = open(dups, "rt") for d in sameseqs: logging.warn(d) - g = re.match(r"\\d+\\t(.*)", 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> <%s> ." % (n.strip(), sp[0].strip())) -orig = open(originalLabels["path"], "rt") +orig = open(originalLabels, "rt") print(orig.read()) diff --git a/workflows/pangenome-generate/relabel-seqs.cwl b/workflows/pangenome-generate/relabel-seqs.cwl index 01196f6..c1f17a4 100644 --- a/workflows/pangenome-generate/relabel-seqs.cwl +++ b/workflows/pangenome-generate/relabel-seqs.cwl @@ -26,19 +26,21 @@ requirements: var out = []; for (; i < inputs.readsFA.length; i++) { var block = []; - for (; i < (b*100) && i < inputs.readsFA.length; i++) { + var sub = []; + for (; i < (b*150) && i < inputs.readsFA.length; i++) { block.push(inputs.readsFA[i]); + sub.push(inputs.subjects[i]); } out.push({ entryname: "block"+b, entry: JSON.stringify(block) }); + out.push({ + entryname: "subs"+b, + entry: JSON.stringify(sub) + }); b++; } - out.push({ - entry: JSON.stringify(inputs.subjects), - entryname: "subjects" - }); return out; } hints: diff --git a/workflows/pangenome-generate/relabel-seqs.py b/workflows/pangenome-generate/relabel-seqs.py index 970540f..6b022a0 100644 --- a/workflows/pangenome-generate/relabel-seqs.py +++ b/workflows/pangenome-generate/relabel-seqs.py @@ -1,15 +1,17 @@ import os import json -reads = [] -b = 1 -while os.path.exists("block%i" % b): - with open("block%i" % b) as f: - reads.extend(json.load(f)) - b += 1 +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 -with open("subjects") as f: - subjects = json.load(f) +reads = readitems("block") +subjects = readitems("subs") relabeled_fasta = open("relabeledSeqs.fasta", "wt") original_labels = open("originalLabels.ttl", "wt") -- cgit v1.2.3 From ce696b41b3476891ecb05185d64c289b140a73af Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 21 Apr 2020 17:09:16 -0400 Subject: Increase ram requirement for minimap2 Add --kickoff to immediately start an analysis workflow. Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- bh20seqanalyzer/main.py | 14 +++++++++++++- workflows/pangenome-generate/minimap2.cwl | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bh20seqanalyzer/main.py b/bh20seqanalyzer/main.py index 193a268..8d0f562 100644 --- a/bh20seqanalyzer/main.py +++ b/bh20seqanalyzer/main.py @@ -214,14 +214,26 @@ def main(): parser.add_argument('--fastq-workflow-uuid', type=str, default='lugli-7fd4e-2zp9q4jo5xpif9y', help='') parser.add_argument('--latest-result-collection', type=str, default='lugli-4zz18-z513nlpqm03hpca', help='') + parser.add_argument('--kickoff', action="store_true") args = parser.parse_args() api = arvados.api() - logging.info("Starting up, monitoring %s for uploads" % (args.uploader_project)) + schema_ref = upload_schema(api, args.workflow_def_project) + if args.kickoff: + logging.info("Starting a single analysis run") + start_pangenome_analysis(api, + args.pangenome_analysis_project, + args.pangenome_workflow_uuid, + args.validated_project, + schema_ref) + return + + logging.info("Starting up, monitoring %s for uploads" % (args.uploader_project)) + while True: move_fastq_to_fasta_results(api, args.fastq_project, args.uploader_project) diff --git a/workflows/pangenome-generate/minimap2.cwl b/workflows/pangenome-generate/minimap2.cwl index bf19ef7..42d1dce 100644 --- a/workflows/pangenome-generate/minimap2.cwl +++ b/workflows/pangenome-generate/minimap2.cwl @@ -12,7 +12,7 @@ hints: ResourceRequirement: coresMin: 8 coresMax: 32 - ramMin: $(7 * 1024) + ramMin: $(9 * 1024) outdirMin: $(Math.ceil(inputs.readsFA.size/(1024*1024*1024) + 20)) stdout: $(inputs.readsFA.nameroot).paf baseCommand: minimap2 -- cgit v1.2.3 From 53ec1c771fea5066abc83acb54859bfa3048a606 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Tue, 21 Apr 2020 18:20:58 -0400 Subject: Update metadata.yaml --- example/metadata.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/example/metadata.yaml b/example/metadata.yaml index 1e83400..57d90b5 100644 --- a/example/metadata.yaml +++ b/example/metadata.yaml @@ -6,15 +6,15 @@ host: host_sex: http://purl.obolibrary.org/obo/NCIT_C27993 host_age: 20 host_age_unit: http://purl.obolibrary.org/obo/UO_0000036 - host_health_status: A condition or state at a particular time - host_treatment: Process in which the act is intended to modify or alter host status - host_vaccination: List of vaccines given to the host + host_health_status: A condition or state at a particular time (Disease ontology) + host_treatment: Process in which the act is intended to modify or alter host status (Compounds) + host_vaccination: List of vaccines given to the host (RRIDs?) additional_host_information: Field for additional host information sample: - sample_id: Id of the sample as defined by the submitter + sample_id: Id of the sample as defined by the submitter collector_name: Name of the person that took the sample - collecting_institution: Institute that was responsible of sampeling + collecting_institution: Institute that was responsible of sampling specimen_source: http://purl.obolibrary.org/obo/NCIT_C155831 specimen_source2: http://purl.obolibrary.org/obo/NCIT_C155835 collection_date: "2020-01-01" @@ -29,15 +29,15 @@ virus: technology: sample_sequencing_technology: http://www.ebi.ac.uk/efo/EFO_0009173 sample_sequencing_technology2: http://www.ebi.ac.uk/efo/EFO_0009173 - sequence_assembly_method: Protocol used for assembly + sequence_assembly_method: Protocol used for assembly (CWL, WDL, NF, BCO?) sequencing_coverage: 70 submitter: - submitter_name: John Doe + submitter_name: John Doe (ORCID?) submitter_address: John Doe's adress originating_lab: John Doe kitchen - lab_address: John Doe's adress + lab_address: John Doe's address provider_sample_id: HmX submitter_sample_id: xXx authors: John Doe et all - submitter_orcid: https://orcid.org/0000-0000-0000-0000 + submitter_orcid: https://orcid.org/0000-0000-0000-0000 (if this is here, others can be optional?) -- cgit v1.2.3 From a12fe94f174da766be612fbb2712b4db2ba98296 Mon Sep 17 00:00:00 2001 From: lltommy Date: Wed, 22 Apr 2020 19:41:27 +0200 Subject: Small changes all around, trying to make the importer/metadata better --- bh20sequploader/bh20seq-schema.yml | 4 ++-- bh20sequploader/bh20seq-shex.rdf | 25 +++++++++++++++---------- example/metadata.yaml | 8 ++++---- scripts/foreach.sh | 2 +- scripts/from_genbank_to_fasta_and_yaml.py | 12 ++++++++---- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/bh20sequploader/bh20seq-schema.yml b/bh20sequploader/bh20seq-schema.yml index 1ceebe2..80013c3 100644 --- a/bh20sequploader/bh20seq-schema.yml +++ b/bh20sequploader/bh20seq-schema.yml @@ -25,7 +25,7 @@ $graph: jsonldPredicate: _id: http://semanticscience.org/resource/SIO_000115 host_sex: - doc: Sex of the host as defined in NCIT, IRI expected (http://purl.obolibrary.org/obo/NCIT_C20197 (Male), http://purl.obolibrary.org/obo/NCIT_C27993 (Female), http://purl.obolibrary.org/obo/NCIT_C45908 (Intersex), or http://purl.obolibrary.org/obo/NCIT_C17998 (Unknown)) + doc: Sex of the host as defined in PATO, expect male () or female () type: string? jsonldPredicate: _id: http://purl.obolibrary.org/obo/PATO_0000047 @@ -144,7 +144,7 @@ $graph: fields: sample_sequencing_technology: doc: Technology that was used to sequence this sample (e.g Sanger, Nanopor MiniION) - type: string + type: string? jsonldPredicate: _id: http://purl.obolibrary.org/obo/OBI_0600047 _type: "@id" diff --git a/bh20sequploader/bh20seq-shex.rdf b/bh20sequploader/bh20seq-shex.rdf index 31e714f..8d0055e 100644 --- a/bh20sequploader/bh20seq-shex.rdf +++ b/bh20sequploader/bh20seq-shex.rdf @@ -23,35 +23,40 @@ PREFIX wikidata: obo:PATO_0000047 [ obo:PATO_0000384 obo:PATO_0000383 ] ?; obo:PATO_0000011 xsd:integer ?; obo:NCIT_C42574 [ obo:UO_~ ] ?; - sio:SIO_001167 xsd:string ?; + obo:NCIT_C25688 xsd:string ? ; efo:EFO_0000727 xsd:string ?; + obo:VO_0000002 xsd:string ?; + sio:SIO_001167 xsd:string ?; } :sampleShape { sio:SIO_000115 xsd:string; - obo:GAZ_00000448 [wikidata:~] ; evs:C25164 xsd:string; + obo:GAZ_00000448 [wikidata:~] ; obo:OBI_0001895 xsd:string ?; - sio:SIO_001167 xsd:string ?; - obo:OBI_0001472 xsd:string ?; + obo:NCIT_C41206 xsd:string ?; obo:OBI_0001479 IRI {0,2}; + obo:OBI_0001472 xsd:string ?; + sio:SIO_001167 xsd:string ?; } :submitterShape { obo:NCIT_C42781 xsd:string ; - obo:NCIT_C37984 xsd:string ?; - obo:NCIT_C37900 xsd:string ?; sio:SIO_000116 xsd:string ?; - obo:OBI_0600047 xsd:string ?; - sio:SIO_000115 /https:\u002F\u002Forcid.org\u002F.{4}-.{4}-.{4}-.{4}/?; sio:SIO_000172 xsd:string ?; + obo:NCIT_C37984 xsd:string ?; + obo:OBI_0600047 xsd:string ?; + obo:NCIT_C37900 xsd:string ?; efo:EFO_0001741 xsd:string ?; + obo:NCIT_C19026 xsd:string ?; + sio:SIO_000115 /https:\u002F\u002Forcid.org\u002F.{4}-.{4}-.{4}-.{4}/?; } :technologyShape { - obo:OBI_0600047 IRI {0,2} ; - obo:FLU_0000848 xsd:double ?; + obo:OBI_0600047 IRI {0,2} ?; efo:EFO_0002699 xsd:string ?; + obo:FLU_0000848 xsd:double {0,2}; + sio:SIO_001167 xsd:string ?; } :virusShape{ diff --git a/example/metadata.yaml b/example/metadata.yaml index 57d90b5..d1b10c1 100644 --- a/example/metadata.yaml +++ b/example/metadata.yaml @@ -6,7 +6,7 @@ host: host_sex: http://purl.obolibrary.org/obo/NCIT_C27993 host_age: 20 host_age_unit: http://purl.obolibrary.org/obo/UO_0000036 - host_health_status: A condition or state at a particular time (Disease ontology) + host_health_status: A condition or state at a particular time host_treatment: Process in which the act is intended to modify or alter host status (Compounds) host_vaccination: List of vaccines given to the host (RRIDs?) additional_host_information: Field for additional host information @@ -29,15 +29,15 @@ virus: technology: sample_sequencing_technology: http://www.ebi.ac.uk/efo/EFO_0009173 sample_sequencing_technology2: http://www.ebi.ac.uk/efo/EFO_0009173 - sequence_assembly_method: Protocol used for assembly (CWL, WDL, NF, BCO?) + sequence_assembly_method: Protocol used for assembly sequencing_coverage: 70 submitter: - submitter_name: John Doe (ORCID?) + submitter_name: John Doe submitter_address: John Doe's adress originating_lab: John Doe kitchen lab_address: John Doe's address provider_sample_id: HmX submitter_sample_id: xXx authors: John Doe et all - submitter_orcid: https://orcid.org/0000-0000-0000-0000 (if this is here, others can be optional?) + submitter_orcid: https://orcid.org/0000-0000-0000-0000 \ No newline at end of file diff --git a/scripts/foreach.sh b/scripts/foreach.sh index 35b07b8..ddc9387 100755 --- a/scripts/foreach.sh +++ b/scripts/foreach.sh @@ -2,7 +2,7 @@ rm -rf validated fasta_and_yaml_* mkdir -p validated ./from_genbank_to_fasta_and_yaml.py -fasta_files=$(find fasta_and_yaml_20200421/ -name "*.fasta") +fasta_files=$(find fasta_and_yaml/ -name "*.fasta") for f in $fasta_files ; do yaml=$(echo $f | rev | cut -c7- | rev).yaml echo $f diff --git a/scripts/from_genbank_to_fasta_and_yaml.py b/scripts/from_genbank_to_fasta_and_yaml.py index 00c0012..096a6af 100755 --- a/scripts/from_genbank_to_fasta_and_yaml.py +++ b/scripts/from_genbank_to_fasta_and_yaml.py @@ -8,10 +8,11 @@ import json import os from datetime import date -today = date.today().strftime("%Y%m%d") +#today = date.today().strftime("%Y%m%d") -dir_metadata_today = 'metadata_from_nuccore_{}'.format(today) -dir_fasta_and_yaml_today = 'fasta_and_yaml_{}'.format(today) + +dir_metadata_today = 'metadata_from_nuccore' #_{}'.format(today) +dir_fasta_and_yaml_today = 'fasta_and_yaml' #'.format(today) dir_dict_ontology_standardization = 'dict_ontology_standardization/' @@ -177,7 +178,10 @@ if not os.path.exists(dir_fasta_and_yaml_today): if len(GBQualifier_value_text_list) > 1: if GBQualifier_value_text_list[1] in ['male', 'female']: - info_for_yaml_dict['host']['host_sex'] = GBQualifier_value_text_list[1] + if GBQualifier_value_text_list[1]=='male': + info_for_yaml_dict['host']['host_sex'] = "http://purl.obolibrary.org/obo/PATO_0000384" + elif GBQualifier_value_text_list[1]=='female': + info_for_yaml_dict['host']['host_sex'] = "http://purl.obolibrary.org/obo/PATO_0000383" else: info_for_yaml_dict['host']['host_health_status'] = GBQualifier_value_text_list[1] -- cgit v1.2.3 From 2d3f8b9707bd13433ca82449ad82dbc406a28f95 Mon Sep 17 00:00:00 2001 From: lltommy Date: Wed, 22 Apr 2020 20:43:09 +0200 Subject: Including restrictions to the host status --- bh20sequploader/bh20seq-options.yml | 9 +++++++++ bh20sequploader/bh20seq-schema.yml | 2 +- bh20sequploader/bh20seq-shex.rdf | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bh20sequploader/bh20seq-options.yml b/bh20sequploader/bh20seq-options.yml index da47e1a..68f6e79 100644 --- a/bh20sequploader/bh20seq-options.yml +++ b/bh20sequploader/bh20seq-options.yml @@ -14,6 +14,15 @@ host_sex: Male: http://purl.obolibrary.org/obo/PATO_0000384 Female: http://purl.obolibrary.org/obo/PATO_0000383 +host_health_status: + healthy: http://purl.obolibrary.org/obo/NCIT_C115935 + asymptomatic: http://purl.obolibrary.org/obo/NCIT_C3833 + sympotmatic: http://purl.obolibrary.org/obo/NCIT_C25269 + admitted to hospital: http://purl.obolibrary.org/obo/GENEPIO_0002020 + discharged from hospital: http://purl.obolibrary.org/obo/GENEPIO_0001849 + dead: http://purl.obolibrary.org/obo/NCIT_C28554 + alive: http://purl.obolibrary.org/obo/NCIT_C37987 + sample_sequencing_technology: Illumina NextSeq 500: http://www.ebi.ac.uk/efo/EFO_0009173 Illumina NextSeq 550: http://www.ebi.ac.uk/efo/EFO_0008566 diff --git a/bh20sequploader/bh20seq-schema.yml b/bh20sequploader/bh20seq-schema.yml index 80013c3..232ccc6 100644 --- a/bh20sequploader/bh20seq-schema.yml +++ b/bh20sequploader/bh20seq-schema.yml @@ -44,7 +44,7 @@ $graph: _type: "@id" noLinkCheck: true host_health_status: - doc: A condition or state at a particular time + doc: A condition or state at a particular time, must be one of the following (obo:NCIT_C115935 obo:NCIT_C3833 obo:NCIT_C25269 obo:GENEPIO_0002020 obo:GENEPIO_0001849 obo:NCIT_C28554 obo:NCIT_C37987) type: string? jsonldPredicate: http://purl.obolibrary.org/obo/NCIT_C25688 host_treatment: diff --git a/bh20sequploader/bh20seq-shex.rdf b/bh20sequploader/bh20seq-shex.rdf index 8d0055e..bb15f91 100644 --- a/bh20sequploader/bh20seq-shex.rdf +++ b/bh20sequploader/bh20seq-shex.rdf @@ -23,7 +23,7 @@ PREFIX wikidata: obo:PATO_0000047 [ obo:PATO_0000384 obo:PATO_0000383 ] ?; obo:PATO_0000011 xsd:integer ?; obo:NCIT_C42574 [ obo:UO_~ ] ?; - obo:NCIT_C25688 xsd:string ? ; + obo:NCIT_C25688 [obo:NCIT_C115935 obo:NCIT_C3833 obo:NCIT_C25269 obo:GENEPIO_0002020 obo:GENEPIO_0001849 obo:NCIT_C28554 obo:NCIT_C37987 ] ? ; efo:EFO_0000727 xsd:string ?; obo:VO_0000002 xsd:string ?; sio:SIO_001167 xsd:string ?; -- cgit v1.2.3 From 9ae32dda5908d666dd6cf574769984c882cc40e6 Mon Sep 17 00:00:00 2001 From: lltommy Date: Wed, 22 Apr 2020 20:48:00 +0200 Subject: updating example with ontology term for host_health_status --- example/metadata.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/metadata.yaml b/example/metadata.yaml index d1b10c1..a76616c 100644 --- a/example/metadata.yaml +++ b/example/metadata.yaml @@ -6,7 +6,7 @@ host: host_sex: http://purl.obolibrary.org/obo/NCIT_C27993 host_age: 20 host_age_unit: http://purl.obolibrary.org/obo/UO_0000036 - host_health_status: A condition or state at a particular time + host_health_status: http://purl.obolibrary.org/obo/NCIT_C25269 host_treatment: Process in which the act is intended to modify or alter host status (Compounds) host_vaccination: List of vaccines given to the host (RRIDs?) additional_host_information: Field for additional host information -- cgit v1.2.3 From a448aba5afb633dec197c93ed5fcc6fa61c7c491 Mon Sep 17 00:00:00 2001 From: lltommy Date: Wed, 22 Apr 2020 21:06:47 +0200 Subject: Forgot to add _id --- bh20sequploader/bh20seq-schema.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bh20sequploader/bh20seq-schema.yml b/bh20sequploader/bh20seq-schema.yml index 232ccc6..9a89979 100644 --- a/bh20sequploader/bh20seq-schema.yml +++ b/bh20sequploader/bh20seq-schema.yml @@ -46,7 +46,8 @@ $graph: host_health_status: doc: A condition or state at a particular time, must be one of the following (obo:NCIT_C115935 obo:NCIT_C3833 obo:NCIT_C25269 obo:GENEPIO_0002020 obo:GENEPIO_0001849 obo:NCIT_C28554 obo:NCIT_C37987) type: string? - jsonldPredicate: http://purl.obolibrary.org/obo/NCIT_C25688 + jsonldPredicate: + _id: http://purl.obolibrary.org/obo/NCIT_C25688 host_treatment: doc: Process in which the act is intended to modify or alter host status type: string? -- cgit v1.2.3 From 7ef2c5c45d3d1b6e71a08fd0bdf19c42ef9e1014 Mon Sep 17 00:00:00 2001 From: lltommy Date: Wed, 22 Apr 2020 21:23:32 +0200 Subject: Fixing ShEx expression, one ? too much --- bh20sequploader/bh20seq-shex.rdf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bh20sequploader/bh20seq-shex.rdf b/bh20sequploader/bh20seq-shex.rdf index bb15f91..246fd57 100644 --- a/bh20sequploader/bh20seq-shex.rdf +++ b/bh20sequploader/bh20seq-shex.rdf @@ -53,7 +53,7 @@ PREFIX wikidata: } :technologyShape { - obo:OBI_0600047 IRI {0,2} ?; + obo:OBI_0600047 IRI {0,2} ; efo:EFO_0002699 xsd:string ?; obo:FLU_0000848 xsd:double {0,2}; sio:SIO_001167 xsd:string ?; -- cgit v1.2.3 From 9790a832e7e18775f5f06bd490aed1f756a96c46 Mon Sep 17 00:00:00 2001 From: Andrea Guarracino Date: Wed, 22 Apr 2020 23:50:34 +0200 Subject: updated IDs list - 2020/04/22 --- scripts/sequences.acc | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/scripts/sequences.acc b/scripts/sequences.acc index d000a76..0ad0878 100644 --- a/scripts/sequences.acc +++ b/scripts/sequences.acc @@ -1,4 +1,125 @@ NC_045512 +LC542809 +MT114412 +MT114413 +MT114414 +MT114415 +MT114416 +MT114417 +MT114418 +MT114419 +MT230904 +MT358401 +MT358402 +MT358637 +MT358644 +MT358645 +MT358646 +MT358647 +MT358648 +MT358649 +MT358650 +MT358651 +MT358652 +MT358653 +MT358654 +MT358655 +MT358656 +MT358657 +MT358658 +MT358659 +MT358660 +MT358661 +MT358662 +MT358663 +MT358664 +MT358665 +MT358666 +MT358667 +MT358668 +MT358669 +MT358670 +MT358671 +MT358672 +MT358673 +MT358674 +MT358675 +MT358676 +MT358677 +MT358678 +MT358679 +MT358680 +MT358681 +MT358682 +MT358683 +MT358684 +MT358685 +MT358686 +MT358687 +MT358688 +MT358689 +MT358690 +MT358691 +MT358692 +MT358693 +MT358694 +MT358695 +MT358696 +MT358697 +MT358698 +MT358699 +MT358700 +MT358701 +MT358702 +MT358703 +MT358704 +MT358705 +MT358706 +MT358707 +MT358708 +MT358709 +MT358710 +MT358711 +MT358712 +MT358713 +MT358714 +MT358715 +MT358716 +MT358717 +MT358718 +MT358719 +MT358720 +MT358721 +MT358722 +MT358723 +MT358724 +MT358725 +MT358726 +MT358727 +MT358728 +MT358729 +MT358730 +MT358731 +MT358732 +MT358733 +MT358734 +MT358735 +MT358736 +MT358737 +MT358738 +MT358739 +MT358740 +MT358741 +MT358742 +MT358743 +MT358744 +MT358745 +MT358746 +MT358747 +MT358748 +MT359231 +MT359865 +MT359866 MT350234 MT350236 MT350237 -- cgit v1.2.3 From 9e1d449ddbc9705a9685535f9ede716f6adad2a8 Mon Sep 17 00:00:00 2001 From: Andrea Guarracino Date: Wed, 22 Apr 2020 23:51:28 +0200 Subject: added some rows in the ncbi_countries dict --- scripts/dict_ontology_standardization/ncbi_countries.csv | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/dict_ontology_standardization/ncbi_countries.csv b/scripts/dict_ontology_standardization/ncbi_countries.csv index d5e2235..20e8a9b 100644 --- a/scripts/dict_ontology_standardization/ncbi_countries.csv +++ b/scripts/dict_ontology_standardization/ncbi_countries.csv @@ -63,6 +63,7 @@ China: Jiangxi,http://www.wikidata.org/entity/Q57052 China: Jilin,http://www.wikidata.org/entity/Q45208 China: Liaoning,http://www.wikidata.org/entity/Q43934 China: Macau,http://www.wikidata.org/entity/Q14773 +China: Nanchang,https://www.wikidata.org/wiki/Q171943 China: Ningxia Hui Autonomous Region,http://www.wikidata.org/entity/Q57448 China: Qinghai,http://www.wikidata.org/entity/Q45833 China: Shaanxi,http://www.wikidata.org/entity/Q47974 @@ -274,6 +275,7 @@ USA: IN,http://www.wikidata.org/entity/Q1415 USA: KS,http://www.wikidata.org/entity/Q1558 USA: KY,http://www.wikidata.org/entity/Q1603 USA: LA,http://www.wikidata.org/entity/Q1588 +"USA: New Orleans, LA",https://www.wikidata.org/wiki/Q34404 USA: MA,http://www.wikidata.org/entity/Q771 USA: MD,http://www.wikidata.org/entity/Q1391 USA: ME,http://www.wikidata.org/entity/Q724 -- cgit v1.2.3 From 6b470bd78ccfc7e1088e7d31641911280bd78369 Mon Sep 17 00:00:00 2001 From: Andrea Guarracino Date: Wed, 22 Apr 2020 23:53:14 +0200 Subject: added some rows in the speciesman dict --- scripts/dict_ontology_standardization/ncbi_speciesman_source.csv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/dict_ontology_standardization/ncbi_speciesman_source.csv b/scripts/dict_ontology_standardization/ncbi_speciesman_source.csv index 909cf37..8278c90 100644 --- a/scripts/dict_ontology_standardization/ncbi_speciesman_source.csv +++ b/scripts/dict_ontology_standardization/ncbi_speciesman_source.csv @@ -22,4 +22,5 @@ bronchoalveolar lavage,http://purl.obolibrary.org/obo/NCIT_C13195 sputum,http://purl.obolibrary.org/obo/NCIT_C13278 aspirate,http://purl.obolibrary.org/obo/NCIT_C13347 stool,http://purl.obolibrary.org/obo/NCIT_C13234 -serum,http://purl.obolibrary.org/obo/NCIT_C13325 \ No newline at end of file +serum,http://purl.obolibrary.org/obo/NCIT_C13325 +saliva,http://purl.obolibrary.org/obo/NCIT_C13275 -- cgit v1.2.3 From 25dbffe47849fdbc517ad19b7836c75da31ea873 Mon Sep 17 00:00:00 2001 From: Andrea Guarracino Date: Wed, 22 Apr 2020 23:53:41 +0200 Subject: created dict for host health status --- scripts/dict_ontology_standardization/ncbi_host_health_status.csv | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 scripts/dict_ontology_standardization/ncbi_host_health_status.csv diff --git a/scripts/dict_ontology_standardization/ncbi_host_health_status.csv b/scripts/dict_ontology_standardization/ncbi_host_health_status.csv new file mode 100644 index 0000000..bbb9347 --- /dev/null +++ b/scripts/dict_ontology_standardization/ncbi_host_health_status.csv @@ -0,0 +1,8 @@ +healthy,http://purl.obolibrary.org/obo/NCIT_C115935 +asymptomatic,http://purl.obolibrary.org/obo/NCIT_C3833 +sympotmatic,http://purl.obolibrary.org/obo/NCIT_C25269 +admitted to hospital,http://purl.obolibrary.org/obo/GENEPIO_0002020 +hospitalized patient,http://purl.obolibrary.org/obo/GENEPIO_0002020 +discharged from hospital,http://purl.obolibrary.org/obo/GENEPIO_0001849 +dead,http://purl.obolibrary.org/obo/NCIT_C28554 +alive,http://purl.obolibrary.org/obo/NCIT_C37987 -- cgit v1.2.3 From b6ca75a8bfc452b54f7b90465eba0d3ed21e5985 Mon Sep 17 00:00:00 2001 From: Andrea Guarracino Date: Wed, 22 Apr 2020 23:56:26 +0200 Subject: code cleaning, checking and writing missing term on file - the script checks for country and specimen_source - now the missing terms are written on a tsv file--- scripts/from_genbank_to_fasta_and_yaml.py | 347 ++++++++++++++++-------------- 1 file changed, 184 insertions(+), 163 deletions(-) diff --git a/scripts/from_genbank_to_fasta_and_yaml.py b/scripts/from_genbank_to_fasta_and_yaml.py index 096a6af..f76cb29 100755 --- a/scripts/from_genbank_to_fasta_and_yaml.py +++ b/scripts/from_genbank_to_fasta_and_yaml.py @@ -7,58 +7,53 @@ import xml.etree.ElementTree as ET import json import os -from datetime import date -#today = date.today().strftime("%Y%m%d") - - -dir_metadata_today = 'metadata_from_nuccore' #_{}'.format(today) -dir_fasta_and_yaml_today = 'fasta_and_yaml' #'.format(today) +num_ids_for_request = 100 +dir_metadata = 'metadata_from_nuccore' +dir_fasta_and_yaml = 'fasta_and_yaml' dir_dict_ontology_standardization = 'dict_ontology_standardization/' - path_ncbi_virus_accession = 'sequences.acc' -# Take all the ids -id_set = set() +def chunks(lst, n): + for i in range(0, len(lst), n): + yield lst[i:i + n] -term_list = ['SARS-CoV-2', 'SARS-CoV2', 'SARS CoV2', 'SARSCoV2', 'txid2697049[Organism]'] -for term in term_list: - tmp_list = Entrez.read( - Entrez.esearch(db='nuccore', term=term, idtype='acc', retmax='10000') - )['IdList'] +if not os.path.exists(dir_metadata): + os.makedirs(dir_metadata) - # Remove mRNAs, ncRNAs, Proteins, and predicted models (more information here: https://en.wikipedia.org/wiki/RefSeq) - tmp_list = [x for x in tmp_list if x[:2] not in ['NM', 'NR', 'NP', 'XM', 'XR', 'XP', 'WP']] + # Take all the ids + id_set = set() - # Remove the version in the id - tmp_list = [x.split('.')[0] for x in tmp_list] + term_list = ['SARS-CoV-2', 'SARS-CoV2', 'SARS CoV2', 'SARSCoV2', 'txid2697049[Organism]'] + for term in term_list: + tmp_list = Entrez.read( + Entrez.esearch(db='nuccore', term=term, idtype='acc', retmax='10000') + )['IdList'] - print(term, len(tmp_list)) - tmp_list=tmp_list -# tmp_list = tmp_list[0:2] # restricting to small run + # Remove mRNAs, ncRNAs, Proteins, and predicted models (more information here: https://en.wikipedia.org/wiki/RefSeq) + tmp_list = [x for x in tmp_list if x[:2] not in ['NM', 'NR', 'NP', 'XM', 'XR', 'XP', 'WP']] - id_set.update([x.split('.')[0] for x in tmp_list]) + # Remove the version in the id + tmp_list = [x.split('.')[0] for x in tmp_list] -print(term_list, len(id_set)) + print(term, len(tmp_list)) + tmp_list=tmp_list + # tmp_list = tmp_list[0:2] # restricting to small run -with open(path_ncbi_virus_accession) as f: - tmp_list = [line.strip('\n') for line in f] + id_set.update([x.split('.')[0] for x in tmp_list]) -print('NCBI Virus', len(tmp_list)) -id_set.update(tmp_list) + print(term_list, len(id_set)) -print(term_list + ['NCBI Virus'], len(id_set)) + with open(path_ncbi_virus_accession) as f: + tmp_list = [line.strip('\n') for line in f] -def chunks(lst, n): - for i in range(0, len(lst), n): - yield lst[i:i + n] + print('NCBI Virus', len(tmp_list)) + id_set.update(tmp_list) -num_ids_for_request = 100 -if not os.path.exists(dir_metadata_today): - os.makedirs(dir_metadata_today) + print(term_list + ['NCBI Virus'], len(id_set)) for i, id_x_list in enumerate(chunks(list(id_set), num_ids_for_request)): - path_metadata_xxx_xml = os.path.join(dir_metadata_today, 'metadata_{}.xml'.format(i)) + path_metadata_xxx_xml = os.path.join(dir_metadata, 'metadata_{}.xml'.format(i)) print('Requesting {} ids --> {}'.format(len(id_x_list), path_metadata_xxx_xml)) with open(path_metadata_xxx_xml, 'w') as fw: @@ -87,145 +82,171 @@ species_to_taxid_dict = { } -if not os.path.exists(dir_fasta_and_yaml_today): - os.makedirs(dir_fasta_and_yaml_today) - - for path_metadata_xxx_xml in [os.path.join(dir_metadata_today, name_metadata_xxx_xml) for name_metadata_xxx_xml in os.listdir(dir_metadata_today) if name_metadata_xxx_xml.endswith('.xml')]: - tree = ET.parse(path_metadata_xxx_xml) - GBSet = tree.getroot() - - for GBSeq in GBSet: - accession_version = GBSeq.find('GBSeq_accession-version').text +if not os.path.exists(dir_fasta_and_yaml): + os.makedirs(dir_fasta_and_yaml) + +missing_value_list = [] + +for path_metadata_xxx_xml in [os.path.join(dir_metadata, name_metadata_xxx_xml) for name_metadata_xxx_xml in os.listdir(dir_metadata) if name_metadata_xxx_xml.endswith('.xml')]: + tree = ET.parse(path_metadata_xxx_xml) + GBSet = tree.getroot() + + for GBSeq in GBSet: + accession_version = GBSeq.find('GBSeq_accession-version').text + + GBSeq_sequence = GBSeq.find('GBSeq_sequence') + if GBSeq_sequence is None: + print(accession_version, ' - sequence not found') + continue + + + # A general default-empty yaml could be read from the definitive one + info_for_yaml_dict = { + 'id': 'placeholder', + 'host': {}, + 'sample': {}, + 'virus': {}, + 'technology': {}, + 'submitter': {} + } + + info_for_yaml_dict['sample']['sample_id'] = accession_version + info_for_yaml_dict['sample']['source_database_accession'] = accession_version + info_for_yaml_dict['submitter']['authors'] = ';'.join([x.text for x in GBSeq.iter('GBAuthor')]) + + + GBSeq_comment = GBSeq.find('GBSeq_comment') + if GBSeq_comment is not None and 'Assembly-Data' in GBSeq_comment.text: + GBSeq_comment_text = GBSeq_comment.text.split('##Assembly-Data-START## ; ')[1].split(' ; ##Assembly-Data-END##')[0] + + for info_to_check, field_in_yaml in zip( + ['Assembly Method', 'Coverage', 'Sequencing Technology'], + ['sequence_assembly_method', 'sequencing_coverage', 'sample_sequencing_technology'] + ): + if info_to_check in GBSeq_comment_text: + tech_info_to_parse = GBSeq_comment_text.split('{} :: '.format(info_to_check))[1].split(' ;')[0] + + if field_in_yaml == 'sequencing_coverage': + # A regular expression would be better! + try: + info_for_yaml_dict['technology'][field_in_yaml] = float( + tech_info_to_parse.strip('(average)').strip("reads/nt").replace(',', '.').strip(' xX>')) + except ValueError: + print(accession_version, "Couldn't make sense of Coverage '%s'" % tech_info_to_parse) + pass + elif field_in_yaml == 'sample_sequencing_technology': + new_seq_tec_list = [] + for seq_tec in tech_info_to_parse.split(';'): + seq_tec = seq_tec.strip() + if seq_tec in term_to_uri_dict: + seq_tec = term_to_uri_dict[seq_tec] + else: + #print(accession_version, 'missing sample_sequencing_technology:', seq_tec) + missing_value_list.append('\t'.join([accession_version, 'sample_sequencing_technology', seq_tec])) - GBSeq_sequence = GBSeq.find('GBSeq_sequence') - if GBSeq_sequence is None: - print(accession_version, ' - sequence not found') - continue + new_seq_tec_list.append(seq_tec) + for n, seq_tec in enumerate(new_seq_tec_list): + info_for_yaml_dict['technology'][field_in_yaml + ('' if n == 0 else str(n + 1))] = seq_tec + else: + info_for_yaml_dict['technology'][field_in_yaml] = tech_info_to_parse - # A general default-empty yaml could be read from the definitive one - info_for_yaml_dict = { - 'id': 'placeholder', - 'host': {}, - 'sample': {}, - 'virus': {}, - 'technology': {}, - 'submitter': {} - } - - info_for_yaml_dict['sample']['sample_id'] = accession_version - info_for_yaml_dict['sample']['source_database_accession'] = accession_version - info_for_yaml_dict['submitter']['authors'] = ';'.join([x.text for x in GBSeq.iter('GBAuthor')]) - - - GBSeq_comment = GBSeq.find('GBSeq_comment') - if GBSeq_comment is not None and 'Assembly-Data' in GBSeq_comment.text: - GBSeq_comment_text = GBSeq_comment.text.split('##Assembly-Data-START## ; ')[1].split(' ; ##Assembly-Data-END##')[0] - - for info_to_check, field_in_yaml in zip( - ['Assembly Method', 'Coverage', 'Sequencing Technology'], - ['sequence_assembly_method', 'sequencing_coverage', 'sample_sequencing_technology'] - ): - if info_to_check in GBSeq_comment_text: - tech_info_to_parse = GBSeq_comment_text.split('{} :: '.format(info_to_check))[1].split(' ;')[0] - - if field_in_yaml == 'sequencing_coverage': - # A regular expression would be better! - try: - info_for_yaml_dict['technology'][field_in_yaml] = float( - tech_info_to_parse.strip('(average)').strip("reads/nt").replace(',', '.').strip(' xX>')) - except ValueError: - print(accession_version, "Couldn't make sense of Coverage '%s'" % tech_info_to_parse) - pass - elif field_in_yaml == 'sample_sequencing_technology': - new_seq_tec_list = [] - for seq_tec in tech_info_to_parse.split(';'): - seq_tec = seq_tec.strip() - if seq_tec in term_to_uri_dict: - seq_tec = term_to_uri_dict[seq_tec] - else: - print(accession_version, 'missing technologies:', seq_tec) - - new_seq_tec_list.append(seq_tec) - - for n, seq_tec in enumerate(new_seq_tec_list): - info_for_yaml_dict['technology'][field_in_yaml + ('' if n == 0 else str(n + 1))] = seq_tec - else: - info_for_yaml_dict['technology'][field_in_yaml] = tech_info_to_parse + #term_to_uri_dict - #term_to_uri_dict + for GBFeature in GBSeq.iter('GBFeature'): + if GBFeature.find('GBFeature_key').text != 'source': + continue - for GBFeature in GBSeq.iter('GBFeature'): - if GBFeature.find('GBFeature_key').text != 'source': + for GBQualifier in GBFeature.iter('GBQualifier'): + GBQualifier_value = GBQualifier.find('GBQualifier_value') + if GBQualifier_value is None: continue + GBQualifier_value_text = GBQualifier_value.text - for GBQualifier in GBFeature.iter('GBQualifier'): - GBQualifier_value = GBQualifier.find('GBQualifier_value') - if GBQualifier_value is None: - continue - GBQualifier_value_text = GBQualifier_value.text + GBQualifier_name_text = GBQualifier.find('GBQualifier_name').text - GBQualifier_name_text = GBQualifier.find('GBQualifier_name').text + if GBQualifier_name_text == 'host': + GBQualifier_value_text_list = GBQualifier_value_text.split('; ') - if GBQualifier_name_text == 'host': - GBQualifier_value_text_list = GBQualifier_value_text.split('; ') + #info_for_yaml_dict['host']['host_common_name'] = GBQualifier_value_text_list[0] # Removed - #info_for_yaml_dict['host']['host_common_name'] = GBQualifier_value_text_list[0] # Removed + if GBQualifier_value_text_list[0] in species_to_taxid_dict: + info_for_yaml_dict['host']['host_species'] = species_to_taxid_dict[GBQualifier_value_text_list[0]] - if GBQualifier_value_text_list[0] in species_to_taxid_dict: - info_for_yaml_dict['host']['host_species'] = species_to_taxid_dict[GBQualifier_value_text_list[0]] - - if len(GBQualifier_value_text_list) > 1: - if GBQualifier_value_text_list[1] in ['male', 'female']: - if GBQualifier_value_text_list[1]=='male': - info_for_yaml_dict['host']['host_sex'] = "http://purl.obolibrary.org/obo/PATO_0000384" - elif GBQualifier_value_text_list[1]=='female': - info_for_yaml_dict['host']['host_sex'] = "http://purl.obolibrary.org/obo/PATO_0000383" - else: - info_for_yaml_dict['host']['host_health_status'] = GBQualifier_value_text_list[1] - - if 'age' in GBQualifier_value_text: - info_for_yaml_dict['host']['host_age'] = int(GBQualifier_value_text_list[2].split('age ')[1]) - info_for_yaml_dict['host']['host_age_unit'] = 'year' - elif GBQualifier_name_text == 'collected_by': - if any([x in GBQualifier_value_text.lower() for x in ['institute', 'hospital', 'city', 'center']]): - info_for_yaml_dict['sample']['collecting_institution'] = GBQualifier_value_text + if len(GBQualifier_value_text_list) > 1: + if GBQualifier_value_text_list[1] in ['male', 'female']: + if GBQualifier_value_text_list[1]=='male': + info_for_yaml_dict['host']['host_sex'] = "http://purl.obolibrary.org/obo/PATO_0000384" + elif GBQualifier_value_text_list[1]=='female': + info_for_yaml_dict['host']['host_sex'] = "http://purl.obolibrary.org/obo/PATO_0000383" + elif GBQualifier_value_text_list[1] in term_to_uri_dict: + info_for_yaml_dict['host']['host_health_status'] = term_to_uri_dict[GBQualifier_value_text_list[1]] else: - info_for_yaml_dict['sample']['collector_name'] = GBQualifier_value_text - elif GBQualifier_name_text == 'isolation_source': - if GBQualifier_value_text in term_to_uri_dict: - info_for_yaml_dict['sample']['specimen_source'] = term_to_uri_dict[GBQualifier_value_text] + #print(accession_version, 'missing {}:'.format(GBQualifier_name_text), GBQualifier_value_text_list[1]) + missing_value_list.append('\t'.join([accession_version, GBQualifier_name_text, GBQualifier_value_text_list[1]])) + + if 'age' in GBQualifier_value_text: + info_for_yaml_dict['host']['host_age'] = int(GBQualifier_value_text_list[2].split('age ')[1]) + info_for_yaml_dict['host']['host_age_unit'] = 'year' + elif GBQualifier_name_text == 'collected_by': + if any([x in GBQualifier_value_text.lower() for x in ['institute', 'hospital', 'city', 'center']]): + info_for_yaml_dict['sample']['collecting_institution'] = GBQualifier_value_text + else: + info_for_yaml_dict['sample']['collector_name'] = GBQualifier_value_text + elif GBQualifier_name_text == 'isolation_source': + if GBQualifier_value_text.upper() in term_to_uri_dict: + GBQualifier_value_text = GBQualifier_value_text.upper() # For example, in case of 'usa: wa' + + if GBQualifier_value_text in term_to_uri_dict: + info_for_yaml_dict['sample']['specimen_source'] = term_to_uri_dict[GBQualifier_value_text] + else: + if GBQualifier_value_text in ['NP/OP swab', 'nasopharyngeal and oropharyngeal swab', 'nasopharyngeal/oropharyngeal swab', 'np/np swab', 'np/op']: + info_for_yaml_dict['sample']['specimen_source'] = term_to_uri_dict['nasopharyngeal swab'] + info_for_yaml_dict['sample']['specimen_source2'] = term_to_uri_dict['oropharyngeal swab'] + elif GBQualifier_value_text in ['nasopharyngeal swab/throat swab']: + info_for_yaml_dict['sample']['specimen_source'] = term_to_uri_dict['nasopharyngeal swab'] + info_for_yaml_dict['sample']['specimen_source2'] = term_to_uri_dict['throat swab'] + elif GBQualifier_value_text in ['nasopharyngeal aspirate/throat swab']: + info_for_yaml_dict['sample']['specimen_source'] = term_to_uri_dict['nasopharyngeal aspirate'] + info_for_yaml_dict['sample']['specimen_source2'] = term_to_uri_dict['throat swab'] else: - if GBQualifier_value_text in ['NP/OP swab', 'nasopharyngeal and oropharyngeal swab', 'nasopharyngeal/oropharyngeal swab', 'np/np swab', 'np/op']: - info_for_yaml_dict['sample']['specimen_source'] = term_to_uri_dict['nasopharyngeal swab'] - info_for_yaml_dict['sample']['specimen_source2'] = term_to_uri_dict['oropharyngeal swab'] - else: - print(accession_version, 'missing specimen_source:', GBQualifier_value_text) - elif GBQualifier_name_text == 'collection_date': - # TO_DO: which format we will use? - info_for_yaml_dict['sample']['collection_date'] = GBQualifier_value_text - elif GBQualifier_name_text in ['lat_lon', 'country']: - if GBQualifier_value_text in term_to_uri_dict: - GBQualifier_value_text = term_to_uri_dict[GBQualifier_value_text] - else: - print(accession_version, 'missing {}:'.format(GBQualifier_name_text), GBQualifier_value_text) - - info_for_yaml_dict['sample']['collection_location'] = GBQualifier_value_text - elif GBQualifier_name_text == 'note': - info_for_yaml_dict['sample']['additional_collection_information'] = GBQualifier_value_text - elif GBQualifier_name_text == 'isolate': - info_for_yaml_dict['virus']['virus_strain'] = GBQualifier_value_text - elif GBQualifier_name_text == 'db_xref': - info_for_yaml_dict['virus']['virus_species'] = "http://purl.obolibrary.org/obo/NCBITaxon_"+GBQualifier_value_text.split('taxon:')[1] - - - # Remove technology key if empty! - if (info_for_yaml_dict['technology']=={}): - del info_for_yaml_dict['technology'] - - with open(os.path.join(dir_fasta_and_yaml_today, '{}.fasta'.format(accession_version)), 'w') as fw: - fw.write('>{}\n{}'.format(accession_version, GBSeq_sequence.text.upper())) - - with open(os.path.join(dir_fasta_and_yaml_today, '{}.yaml'.format(accession_version)), 'w') as fw: - json.dump(info_for_yaml_dict, fw, indent=2) + #print(accession_version, 'missing specimen_source:', GBQualifier_value_text) + missing_value_list.append('\t'.join([accession_version, 'specimen_source', GBQualifier_value_text])) + elif GBQualifier_name_text == 'collection_date': + # TO_DO: which format we will use? + info_for_yaml_dict['sample']['collection_date'] = GBQualifier_value_text + elif GBQualifier_name_text in ['lat_lon', 'country']: + if GBQualifier_value_text == 'Hong Kong': + GBQualifier_value_text = 'China: Hong Kong' + + + if GBQualifier_value_text in term_to_uri_dict: + GBQualifier_value_text = term_to_uri_dict[GBQualifier_value_text] + else: + #print(accession_version, 'missing {}:'.format(GBQualifier_name_text), GBQualifier_value_text) + missing_value_list.append('\t'.join([accession_version, GBQualifier_name_text, GBQualifier_value_text])) + + info_for_yaml_dict['sample']['collection_location'] = GBQualifier_value_text + elif GBQualifier_name_text == 'note': + info_for_yaml_dict['sample']['additional_collection_information'] = GBQualifier_value_text + elif GBQualifier_name_text == 'isolate': + info_for_yaml_dict['virus']['virus_strain'] = GBQualifier_value_text + elif GBQualifier_name_text == 'db_xref': + info_for_yaml_dict['virus']['virus_species'] = "http://purl.obolibrary.org/obo/NCBITaxon_"+GBQualifier_value_text.split('taxon:')[1] + + + # Remove technology key if empty! + if (info_for_yaml_dict['technology']=={}): + del info_for_yaml_dict['technology'] + + with open(os.path.join(dir_fasta_and_yaml, '{}.fasta'.format(accession_version)), 'w') as fw: + fw.write('>{}\n{}'.format(accession_version, GBSeq_sequence.text.upper())) + + with open(os.path.join(dir_fasta_and_yaml, '{}.yaml'.format(accession_version)), 'w') as fw: + json.dump(info_for_yaml_dict, fw, indent=2) + + +if len(missing_value_list) > 0: + with open('missing_terms.tsv', 'w') as fw: + fw.write('\n'.join(missing_value_list)) -- cgit v1.2.3