From ae4cb3c2cf7103bbc84f52618bb755d7ce25775b Mon Sep 17 00:00:00 2001 From: LLTommy Date: Thu, 25 Jun 2020 09:22:47 +0200 Subject: Update labels.ttl adding label for "Illumina HiSeq X"--- semantic_enrichment/labels.ttl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/semantic_enrichment/labels.ttl b/semantic_enrichment/labels.ttl index cd0464a..85c40e8 100644 --- a/semantic_enrichment/labels.ttl +++ b/semantic_enrichment/labels.ttl @@ -36,6 +36,7 @@ "Illumina" . "Ion Semiconductor Sequencing". "Dideoxy Chain Termination DNA Sequencing" . + "Illumina HiSeq X" . "Nasopharyngeal Swab Specimen" . "Oropharyngeal Swab Specimen" . "Bronchoalveolar Lavage Fluid" . @@ -44,4 +45,4 @@ "Feces" . "Serum" . "Saliva" . - "Nasal Swab" . \ No newline at end of file + "Nasal Swab" . -- cgit v1.2.3 From 841af02eaa45c1b7395d5f4e4711de3c3661c146 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 3 Jul 2020 16:36:55 -0400 Subject: Fix single arg upload Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- bh20sequploader/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bh20sequploader/main.py b/bh20sequploader/main.py index c442af0..89c30e8 100644 --- a/bh20sequploader/main.py +++ b/bh20sequploader/main.py @@ -62,7 +62,7 @@ def main(): parser = argparse.ArgumentParser(description='Upload SARS-CoV-19 sequences for analysis') parser.add_argument('metadata', type=argparse.FileType('r'), help='sequence metadata json') parser.add_argument('sequence_p1', type=argparse.FileType('rb'), help='sequence FASTA/FASTQ') - parser.add_argument('sequence_p2', type=argparse.FileType('rb'), default=None, help='sequence FASTQ pair') + parser.add_argument('sequence_p2', type=argparse.FileType('rb'), default=None, nargs='?', help='sequence FASTQ pair') parser.add_argument("--validate", action="store_true", help="Dry run, validate only") args = parser.parse_args() -- cgit v1.2.3 From 535b8017ddd27a9db683f6d29368258b5c48cf5a Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 3 Jul 2020 20:45:17 +0000 Subject: Improving genbank import workflow --- scripts/docker/Dockerfile | 2 +- .../from_genbank_to_fasta_and_yaml.py | 10 +++-- scripts/fetch_from_genbank.cwl | 49 ++++++++++++++++++++++ scripts/import.cwl | 2 +- scripts/import_from_genbank.cwl | 27 ++++++++++++ scripts/import_to_arvados.py | 2 +- scripts/split_into_arrays.cwl | 30 +++++++++++++ 7 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 scripts/fetch_from_genbank.cwl create mode 100644 scripts/import_from_genbank.cwl create mode 100644 scripts/split_into_arrays.cwl diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile index 9fb33d5..8811927 100644 --- a/scripts/docker/Dockerfile +++ b/scripts/docker/Dockerfile @@ -7,4 +7,4 @@ RUN apt-get update && \ libssl-dev libmagic-dev python3-magic && \ apt-get clean -RUN pip3 install bh20-seq-uploader +RUN pip3 install bh20-seq-uploader py-dateutil diff --git a/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py b/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py index d76f56b..4bb4964 100755 --- a/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py +++ b/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py @@ -4,6 +4,8 @@ import argparse parser = argparse.ArgumentParser() parser.add_argument('--skip-request', action='store_true', help='skip metadata and sequence request', required=False) parser.add_argument('--only-missing-id', action='store_true', help='download only missing id', required=False) +parser.add_argument('--dict-ontology', type=str, help='where is the ontology', + default='../dict_ontology_standardization/',required=False) args = parser.parse_args() from Bio import Entrez @@ -22,7 +24,7 @@ num_ids_for_request = 100 dir_metadata = 'metadata_from_nuccore' dir_fasta_and_yaml = 'fasta_and_yaml' -dir_dict_ontology_standardization = '../dict_ontology_standardization/' +dir_dict_ontology_standardization = args.dict_ontology today_date = date.today().strftime("%Y.%m.%d") path_ncbi_virus_accession = 'sequences.{}.acc'.format(today_date) @@ -126,7 +128,7 @@ for path_dict_xxx_csv in [os.path.join(dir_dict_ontology_standardization, name_x if term in term_to_uri_dict: print('Warning: in the dictionaries there are more entries for the same term ({}).'.format(term)) continue - + term_to_uri_dict[term] = uri if not os.path.exists(dir_fasta_and_yaml): @@ -274,7 +276,7 @@ for path_metadata_xxx_xml in [os.path.join(dir_metadata, name_metadata_xxx_xml) if host_sex in ['male', 'female']: info_for_yaml_dict['host']['host_sex'] = "http://purl.obolibrary.org/obo/PATO_0000384" if host_sex == 'male' else "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]] + info_for_yaml_dict['host']['host_health_status'] = term_to_uri_dict[GBQualifier_value_text_list[1]] else: missing_value_list.append('\t'.join([accession_version, 'host_sex or host_health_status', GBQualifier_value_text_list[1]])) @@ -391,5 +393,5 @@ if len(accession_with_errors_list) > 0: print('Written the accession with errors in {}'.format(path_accession_with_errors_tsv)) with open(path_accession_with_errors_tsv, 'w') as fw: fw.write('\n'.join(accession_with_errors_list)) - + print('Num. new sequences with length >= {} bp: {}'.format(min_len_to_count, num_seq_with_len_ge_X_bp)) diff --git a/scripts/fetch_from_genbank.cwl b/scripts/fetch_from_genbank.cwl new file mode 100644 index 0000000..45c8eec --- /dev/null +++ b/scripts/fetch_from_genbank.cwl @@ -0,0 +1,49 @@ +cwlVersion: v1.1 +class: CommandLineTool +inputs: + importScript: + type: File + default: + class: File + location: download_genbank_data/from_genbank_to_fasta_and_yaml.py + inputBinding: {position: 1} + dict: + type: Directory + inputBinding: + prefix: --dict-ontology + position: 2 + default: + class: Directory + location: dict_ontology_standardization + existing_metadata_from_nuccore: + type: Directory? + inputBinding: + valueFrom: "--skip-request" + position: 3 +outputs: + fasta_and_yaml: + type: Directory + outputBinding: + glob: fasta_and_yaml + metadata_from_nuccore: + type: Directory + outputBinding: + glob: metadata_from_nuccore + accessions: + type: File? + outputBinding: + glob: "*.acc" + missing_terms: + type: File + outputBinding: + glob: missing_terms.tsv +requirements: + InitialWorkDirRequirement: + listing: + - entry: $(inputs.existing_metadata_from_nuccore) + entryname: metadata_from_nuccore + DockerRequirement: + dockerPull: bh20-seq-uploader/import + NetworkAccess: + networkAccess: true +baseCommand: python3 diff --git a/scripts/import.cwl b/scripts/import.cwl index d84516b..4b4b8ca 100644 --- a/scripts/import.cwl +++ b/scripts/import.cwl @@ -12,7 +12,7 @@ inputs: type: File default: class: File - location: from_genbank_to_fasta_and_yaml.py + location: download_genbank_data/from_genbank_to_fasta_and_yaml.py inputBinding: {position: 2} dict: type: Directory diff --git a/scripts/import_from_genbank.cwl b/scripts/import_from_genbank.cwl new file mode 100644 index 0000000..dcf9acb --- /dev/null +++ b/scripts/import_from_genbank.cwl @@ -0,0 +1,27 @@ +cwlVersion: v1.1 +class: Workflow +inputs: + existing_metadata_from_nuccore: + type: Directory? +outputs: [] +requirements: + ScatterFeatureRequirement: {} +steps: + fetch_from_genbank: + in: + existing_metadata_from_nuccore: existing_metadata_from_nuccore + out: [fasta_and_yaml, metadata_from_nuccore, accessions] + run: fetch_from_genbank.cwl + split_into_arrays: + in: + dir: fetch_from_genbank/fasta_and_yaml + out: [fasta, metadata] + run: split_into_arrays.cwl + upload: + in: + fasta: split_into_arrays/fasta + metadata: split_into_arrays/metadata + out: [] + scatter: [fasta, metadata] + scatterMethod: dotproduct + run: upload.cwl diff --git a/scripts/import_to_arvados.py b/scripts/import_to_arvados.py index 78cd13d..aca72d6 100644 --- a/scripts/import_to_arvados.py +++ b/scripts/import_to_arvados.py @@ -11,4 +11,4 @@ os.chdir("fasta_and_yaml") fasta_files = glob.glob("*.fasta") for f in fasta_files: - subprocess.run(["bh20-seq-uploader", f, "%s.yaml" %f[:-6]]) + subprocess.run(["bh20-seq-uploader", "%s.yaml" %f[:-6], f]) diff --git a/scripts/split_into_arrays.cwl b/scripts/split_into_arrays.cwl new file mode 100644 index 0000000..102fe7d --- /dev/null +++ b/scripts/split_into_arrays.cwl @@ -0,0 +1,30 @@ +cwlVersion: v1.1 +class: ExpressionTool +requirements: + InlineJavascriptRequirement: {} +inputs: + dir: + type: Directory + loadListing: shallow_listing +outputs: + fasta: File[] + metadata: File[] +expression: | + ${ + var dir = inputs.dir; + var fasta = []; + var metadata = []; + dir.listing.sort(function(a, b) { return a.basename < b.basename; }); + for (var i = 0; i < dir.listing.length; i++) { + if (dir.listing[i].basename.substr(-6) == ".fasta") { + fasta.push(dir.listing[i]); + } + if (dir.listing[i].basename.substr(-5) == ".yaml") { + metadata.push(dir.listing[i]); + } + } + if (fasta.length != metadata.length) { + throw "They dont match"; + } + return {"fasta": fasta, "metadata": metadata}; + } -- cgit v1.2.3 From c50e611f7be281a3b7955254be097c01e6461c20 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 3 Jul 2020 20:55:16 +0000 Subject: Fix qc_fasta bug closing stream. --- bh20sequploader/qc_fasta.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bh20sequploader/qc_fasta.py b/bh20sequploader/qc_fasta.py index e198430..1587def 100644 --- a/bh20sequploader/qc_fasta.py +++ b/bh20sequploader/qc_fasta.py @@ -51,6 +51,8 @@ def qc_fasta(arg_sequence): if seq_type == "text/fasta": # ensure that contains only one entry submitlabel, submitseq = read_fasta(sequence) + sequence.seek(0) + sequence.detach() with tempfile.NamedTemporaryFile() as tmp1: refstring = pkg_resources.resource_string(__name__, "SARS-CoV-2-reference.fasta") @@ -92,6 +94,8 @@ def qc_fasta(arg_sequence): return ("sequence.fasta"+gz, seqlabel) elif seq_type == "text/fastq": + sequence.seek(0) + sequence.detach() return ("reads.fastq"+gz, seqlabel) else: raise ValueError("Sequence file does not look like a DNA FASTA or FASTQ") -- cgit v1.2.3 From 04df498f5cd85015afce79e1e87a3979e596dcc6 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 3 Jul 2020 17:08:25 -0400 Subject: Adding --skip-qc Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- bh20sequploader/main.py | 9 +++++---- bh20sequploader/qc_fasta.py | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bh20sequploader/main.py b/bh20sequploader/main.py index 89c30e8..dc63bfc 100644 --- a/bh20sequploader/main.py +++ b/bh20sequploader/main.py @@ -22,10 +22,10 @@ ARVADOS_API_HOST='lugli.arvadosapi.com' ARVADOS_API_TOKEN='2fbebpmbo3rw3x05ueu2i6nx70zhrsb1p22ycu3ry34m4x4462' UPLOAD_PROJECT='lugli-j7d0g-n5clictpuvwk8aa' -def qa_stuff(metadata, sequence_p1, sequence_p2): +def qc_stuff(metadata, sequence_p1, sequence_p2, do_qc=True): try: log.debug("Checking metadata") - if not qc_metadata(metadata.name): + if do_qc and not qc_metadata(metadata.name): log.warning("Failed metadata qc") exit(1) except ValueError as e: @@ -37,7 +37,7 @@ def qa_stuff(metadata, sequence_p1, sequence_p2): target = [] try: log.debug("Checking FASTA/FASTQ QC") - target.append(qc_fasta(sequence_p1)) + target.append(qc_fasta(sequence_p1, check_with_clustalw=do_qc)) if sequence_p2: target.append(qc_fasta(sequence_p2)) target[0] = ("reads_1."+target[0][0][6:], target[0][1]) @@ -64,11 +64,12 @@ def main(): parser.add_argument('sequence_p1', type=argparse.FileType('rb'), help='sequence FASTA/FASTQ') parser.add_argument('sequence_p2', type=argparse.FileType('rb'), default=None, nargs='?', help='sequence FASTQ pair') parser.add_argument("--validate", action="store_true", help="Dry run, validate only") + parser.add_argument("--skip-qc", action="store_true", help="Skip local qc check") args = parser.parse_args() api = arvados.api(host=ARVADOS_API_HOST, token=ARVADOS_API_TOKEN, insecure=True) - target = qa_stuff(args.metadata, args.sequence_p1, args.sequence_p2) + target = qc_stuff(args.metadata, args.sequence_p1, args.sequence_p2, not args.skip_qc) seqlabel = target[0][1] if args.validate: diff --git a/bh20sequploader/qc_fasta.py b/bh20sequploader/qc_fasta.py index 1587def..944b52c 100644 --- a/bh20sequploader/qc_fasta.py +++ b/bh20sequploader/qc_fasta.py @@ -25,7 +25,7 @@ def read_fasta(sequence): raise ValueError("FASTA file contains multiple entries") return label, bases -def qc_fasta(arg_sequence): +def qc_fasta(arg_sequence, check_with_clustalw=True): log.debug("Starting qc_fasta") schema_resource = pkg_resources.resource_stream(__name__, "validation/formats") with tempfile.NamedTemporaryFile() as tmp: @@ -64,6 +64,9 @@ def qc_fasta(arg_sequence): refbp = 0 similarity = 0 try: + if not check_with_clustalw: + raise Exception("skipping QC") + cmd = ["clustalw", "-infile="+tmp1.name, "-quicktree", "-iteration=none", "-type=DNA"] print("QC checking similarity to reference") @@ -81,7 +84,7 @@ def qc_fasta(arg_sequence): print(g2.group(0)) print(g3.group(0)) except Exception as e: - logging.warn("Error trying to QC against reference sequence using 'clustalw': %s", e) + logging.warn("QC against reference sequence using 'clustalw': %s", e) if refbp and (subbp/refbp) < .7: raise ValueError("QC fail: submit sequence length is shorter than 70% reference") -- cgit v1.2.3 From 38340e0cedb465cd592ac40b11c9d22c75973fed Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 3 Jul 2020 21:15:48 +0000 Subject: Add --skip-qc for faster batch import --- bh20sequploader/main.py | 4 ++-- bh20sequploader/qc_fasta.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bh20sequploader/main.py b/bh20sequploader/main.py index dc63bfc..cdc4c3f 100644 --- a/bh20sequploader/main.py +++ b/bh20sequploader/main.py @@ -24,7 +24,7 @@ UPLOAD_PROJECT='lugli-j7d0g-n5clictpuvwk8aa' def qc_stuff(metadata, sequence_p1, sequence_p2, do_qc=True): try: - log.debug("Checking metadata") + log.debug("Checking metadata" if do_qc else "Skipping metadata check") if do_qc and not qc_metadata(metadata.name): log.warning("Failed metadata qc") exit(1) @@ -36,7 +36,7 @@ def qc_stuff(metadata, sequence_p1, sequence_p2, do_qc=True): target = [] try: - log.debug("Checking FASTA/FASTQ QC") + log.debug("FASTA/FASTQ QC" if do_qc else "Limited FASTA/FASTQ QC") target.append(qc_fasta(sequence_p1, check_with_clustalw=do_qc)) if sequence_p2: target.append(qc_fasta(sequence_p2)) diff --git a/bh20sequploader/qc_fasta.py b/bh20sequploader/qc_fasta.py index 944b52c..8c6ebd3 100644 --- a/bh20sequploader/qc_fasta.py +++ b/bh20sequploader/qc_fasta.py @@ -54,6 +54,9 @@ def qc_fasta(arg_sequence, check_with_clustalw=True): sequence.seek(0) sequence.detach() + if not check_with_clustalw: + return ("sequence.fasta"+gz, seqlabel) + with tempfile.NamedTemporaryFile() as tmp1: refstring = pkg_resources.resource_string(__name__, "SARS-CoV-2-reference.fasta") tmp1.write(refstring) @@ -64,9 +67,6 @@ def qc_fasta(arg_sequence, check_with_clustalw=True): refbp = 0 similarity = 0 try: - if not check_with_clustalw: - raise Exception("skipping QC") - cmd = ["clustalw", "-infile="+tmp1.name, "-quicktree", "-iteration=none", "-type=DNA"] print("QC checking similarity to reference") -- cgit v1.2.3 From 36f5c5b58a2de662eae9f379e66a9695d300dc2e Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 3 Jul 2020 21:20:28 +0000 Subject: Add --no-start-analysis --- bh20seqanalyzer/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bh20seqanalyzer/main.py b/bh20seqanalyzer/main.py index 9a36cae..9daab5a 100644 --- a/bh20seqanalyzer/main.py +++ b/bh20seqanalyzer/main.py @@ -244,6 +244,7 @@ def main(): parser.add_argument('--latest-result-collection', type=str, default='lugli-4zz18-z513nlpqm03hpca', help='') parser.add_argument('--kickoff', action="store_true") + parser.add_argument('--no-start-analysis', action="store_true") parser.add_argument('--once', action="store_true") args = parser.parse_args() @@ -276,7 +277,7 @@ def main(): args.fastq_project, args.fastq_workflow_uuid) or at_least_one_new_valid_seq - if at_least_one_new_valid_seq: + if at_least_one_new_valid_seq and not args.no_start_analysis: start_pangenome_analysis(api, args.pangenome_analysis_project, args.pangenome_workflow_uuid, -- cgit v1.2.3 From 33ed39e9e82d4f8e4af27f2f0d0676977d367137 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 3 Jul 2020 21:24:00 +0000 Subject: Add upload.cwl --- scripts/upload.cwl | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 scripts/upload.cwl diff --git a/scripts/upload.cwl b/scripts/upload.cwl new file mode 100644 index 0000000..0fed09a --- /dev/null +++ b/scripts/upload.cwl @@ -0,0 +1,13 @@ +cwlVersion: v1.1 +class: CommandLineTool +inputs: + fasta: File + metadata: File +outputs: [] +requirements: + DockerRequirement: + dockerPull: bh20-seq-uploader/import + NetworkAccess: + networkAccess: true +baseCommand: bh20-seq-uploader +arguments: [--skip-qc, $(inputs.metadata), $(inputs.fasta)] -- cgit v1.2.3 From dd0ff95c6973953542cc3a275be2b057b30ff577 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 3 Jul 2020 21:40:17 +0000 Subject: A little more logging --- bh20seqanalyzer/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bh20seqanalyzer/main.py b/bh20seqanalyzer/main.py index 9daab5a..7839d20 100644 --- a/bh20seqanalyzer/main.py +++ b/bh20seqanalyzer/main.py @@ -23,6 +23,8 @@ def validate_upload(api, collection, validated_project, # validate the collection here. Check metadata, etc. valid = True + logging.info("Validating upload '%s' (%s)" % (collection["name"], collection["uuid"])) + if "metadata.yaml" not in col: logging.warn("Upload '%s' missing metadata.yaml", collection["name"]) valid = False @@ -75,7 +77,7 @@ def validate_upload(api, collection, validated_project, "name": "%s (%s)" % (collection["name"], time.asctime(time.gmtime()))}).execute() else: # It is invalid, delete it. - logging.warn("Suggest deleting '%s'" % collection["name"]) + logging.warn("Suggest deleting '%s' (%s)" % (collection["name"], collection["uuid"])) #api.collections().delete(uuid=collection["uuid"]).execute() return valid -- cgit v1.2.3 From 4f30e506055acb788a1ff1bbcb6359c4413a4eab Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Sun, 5 Jul 2020 21:33:26 +0000 Subject: Add bh20-seq-analyzer --print-status Get status from new property "status: validated/rejected" Also store QC fail error message. --- bh20seqanalyzer/main.py | 99 +++++++++++++++++++++++++----------------- bh20sequploader/main.py | 9 ++-- bh20sequploader/qc_metadata.py | 21 +++------ 3 files changed, 70 insertions(+), 59 deletions(-) diff --git a/bh20seqanalyzer/main.py b/bh20seqanalyzer/main.py index 7839d20..2fefa86 100644 --- a/bh20seqanalyzer/main.py +++ b/bh20seqanalyzer/main.py @@ -20,28 +20,36 @@ def validate_upload(api, collection, validated_project, fastq_project, fastq_workflow_uuid): col = arvados.collection.Collection(collection["uuid"]) - # validate the collection here. Check metadata, etc. - valid = True + if collection.get("status") in ("validated", "rejected"): + return False + # validate the collection here. Check metadata, etc. logging.info("Validating upload '%s' (%s)" % (collection["name"], collection["uuid"])) - if "metadata.yaml" not in col: - logging.warn("Upload '%s' missing metadata.yaml", collection["name"]) - valid = False - else: - try: - metadata_content = ruamel.yaml.round_trip_load(col.open("metadata.yaml")) - metadata_content["id"] = "http://arvados.org/keep:%s/metadata.yaml" % collection["portable_data_hash"] - sample_id = metadata_content["sample"]["sample_id"] - add_lc_filename(metadata_content, metadata_content["id"]) - valid = qc_metadata(metadata_content) and valid - except Exception as e: - logging.warn(e) - valid = False - if not valid: - logging.warn("Failed metadata qc") - - if valid: + errors = [] + + dup = api.collections().list(filters=[["owner_uuid", "=", validated_project], + ["portable_data_hash", "=", col.portable_data_hash()]]).execute() + if dup["items"]: + # This exact collection has been uploaded before. + errors.append("Duplicate of %s" % ([d["uuid"] for d in dup["items"]])) + + if not errors: + if "metadata.yaml" not in col: + errors.append("Missing metadata.yaml", collection["name"]) + else: + try: + metadata_content = ruamel.yaml.round_trip_load(col.open("metadata.yaml")) + metadata_content["id"] = "http://arvados.org/keep:%s/metadata.yaml" % collection["portable_data_hash"] + sample_id = metadata_content["sample"]["sample_id"] + add_lc_filename(metadata_content, metadata_content["id"]) + valid = qc_metadata(metadata_content) + if not valid: + errors.append("Failed metadata qc") + except Exception as e: + errors.append(str(e)) + + if not errors: try: tgt = None paired = {"reads_1.fastq": "reads.fastq", "reads_1.fastq.gz": "reads.fastq.gz"} @@ -51,36 +59,32 @@ def validate_upload(api, collection, validated_project, with col.open(n, 'rb') as qf: tgt = qc_fasta(qf)[0] if tgt != n and tgt != paired.get(n): - logging.info("Expected %s but magic says it should be %s", n, tgt) - valid = False + errors.append("Expected %s but magic says it should be %s", n, tgt) elif tgt in ("reads.fastq", "reads.fastq.gz", "reads_1.fastq", "reads_1.fastq.gz"): start_fastq_to_fasta(api, collection, fastq_project, fastq_workflow_uuid, n, sample_id) return False if tgt is None: - valid = False - logging.warn("Upload '%s' does not contain sequence.fasta, reads.fastq or reads_1.fastq", collection["name"]) - except ValueError as v: - valid = False + errors.append("Upload '%s' does not contain sequence.fasta, reads.fastq or reads_1.fastq", collection["name"]) + except Exception as v: + errors.append(str(v)) - dup = api.collections().list(filters=[["owner_uuid", "=", validated_project], - ["portable_data_hash", "=", col.portable_data_hash()]]).execute() - if dup["items"]: - # This exact collection has been uploaded before. - valid = False - logging.warn("Upload '%s' is duplicate" % collection["name"]) - if valid: + if not errors: logging.info("Added '%s' to validated sequences" % collection["name"]) # Move it to the "validated" project to be included in the next analysis + collection["properties"]["status"] = "validated" api.collections().update(uuid=collection["uuid"], body={ "owner_uuid": validated_project, "name": "%s (%s)" % (collection["name"], time.asctime(time.gmtime()))}).execute() + return True else: - # It is invalid, delete it. - logging.warn("Suggest deleting '%s' (%s)" % (collection["name"], collection["uuid"])) - #api.collections().delete(uuid=collection["uuid"]).execute() - - return valid + # It is invalid + logging.warn("'%s' (%s) has validation errors: %s" % ( + collection["name"], collection["uuid"], "\n".join(errors))) + collection["properties"]["status"] = "rejected" + collection["properties"]["errors"] = errors + api.collections().update(uuid=collection["uuid"], body={"properties": collection["properties"]}).execute() + return False def run_workflow(api, parent_project, workflow_uuid, name, inputobj): @@ -231,6 +235,18 @@ def upload_schema(api, workflow_def_project): return "keep:%s/schema.yml" % pdh +def print_status(api, uploader_project): + pending = arvados.util.list_all(api.collections().list, filters=[["owner_uuid", "=", uploader_project]]) + out = [] + for p in pending: + prop = p["properties"] + out.append(prop) + if "status" not in prop: + prop["status"] = "pending" + prop["created_at"] = p["created_at"] + prop["uuid"] = p["uuid"] + print(json.dumps(out, indent=2)) + def main(): parser = argparse.ArgumentParser(description='Analyze collections uploaded to a project') parser.add_argument('--uploader-project', type=str, default='lugli-j7d0g-n5clictpuvwk8aa', help='') @@ -248,6 +264,7 @@ def main(): parser.add_argument('--kickoff', action="store_true") parser.add_argument('--no-start-analysis', action="store_true") parser.add_argument('--once', action="store_true") + parser.add_argument('--print-status', action="store_true") args = parser.parse_args() api = arvados.api() @@ -266,14 +283,18 @@ def main(): args.exclude_list) return + if args.print_status: + print_status(api, args.uploader_project) + exit(0) + 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) - new_collections = api.collections().list(filters=[['owner_uuid', '=', args.uploader_project]]).execute() + new_collections = arvados.util.list_all(api.collections().list, filters=[["owner_uuid", "=", args.uploader_project]]) at_least_one_new_valid_seq = False - for c in new_collections["items"]: + for c in new_collections: at_least_one_new_valid_seq = validate_upload(api, c, args.validated_project, args.fastq_project, diff --git a/bh20sequploader/main.py b/bh20sequploader/main.py index cdc4c3f..8555e2b 100644 --- a/bh20sequploader/main.py +++ b/bh20sequploader/main.py @@ -26,11 +26,9 @@ def qc_stuff(metadata, sequence_p1, sequence_p2, do_qc=True): try: log.debug("Checking metadata" if do_qc else "Skipping metadata check") if do_qc and not qc_metadata(metadata.name): - log.warning("Failed metadata qc") - exit(1) - except ValueError as e: + raise Exception("Failed metadata qc") + except Exception as e: log.debug(e) - log.debug("Failed metadata qc") print(e) exit(1) @@ -42,9 +40,8 @@ def qc_stuff(metadata, sequence_p1, sequence_p2, do_qc=True): target.append(qc_fasta(sequence_p2)) target[0] = ("reads_1."+target[0][0][6:], target[0][1]) target[1] = ("reads_2."+target[1][0][6:], target[0][1]) - except ValueError as e: + except Exception as e: log.debug(e) - log.debug("Failed FASTA qc") print(e) exit(1) diff --git a/bh20sequploader/qc_metadata.py b/bh20sequploader/qc_metadata.py index 9122ace..2b57991 100644 --- a/bh20sequploader/qc_metadata.py +++ b/bh20sequploader/qc_metadata.py @@ -21,20 +21,13 @@ def qc_metadata(metadatafile): shex = pkg_resources.resource_stream(__name__, "bh20seq-shex.rdf").read().decode("utf-8") if not isinstance(avsc_names, schema_salad.avro.schema.Names): - print(avsc_names) - return False + raise Exception(avsc_names) - try: - doc, metadata = schema_salad.schema.load_and_validate(document_loader, avsc_names, metadatafile, True) - g = schema_salad.jsonld_context.makerdf("workflow", doc, document_loader.ctx) - rslt, reason = evaluate(g, shex, doc["id"], "https://raw.githubusercontent.com/arvados/bh20-seq-resource/master/bh20sequploader/bh20seq-shex.rdf#submissionShape") + doc, metadata = schema_salad.schema.load_and_validate(document_loader, avsc_names, metadatafile, True) + g = schema_salad.jsonld_context.makerdf("workflow", doc, document_loader.ctx) + rslt, reason = evaluate(g, shex, doc["id"], "https://raw.githubusercontent.com/arvados/bh20-seq-resource/master/bh20sequploader/bh20seq-shex.rdf#submissionShape") - if not rslt: - log.debug(reason) - print(reason) + if not rslt: + raise Exception(reason) - return rslt - except Exception as e: - traceback.print_exc() - log.warn(e) - return False + return True -- cgit v1.2.3 From 1a1ba7504eff79bac6f8d7054abd418b734ae69c Mon Sep 17 00:00:00 2001 From: Andrea Guarracino Date: Mon, 6 Jul 2020 10:19:50 +0200 Subject: new terms in the sequencing_technology dictionary --- .../ncbi_sequencing_technology.csv | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/dict_ontology_standardization/ncbi_sequencing_technology.csv b/scripts/dict_ontology_standardization/ncbi_sequencing_technology.csv index 964cbf3..79c1269 100644 --- a/scripts/dict_ontology_standardization/ncbi_sequencing_technology.csv +++ b/scripts/dict_ontology_standardization/ncbi_sequencing_technology.csv @@ -33,3 +33,24 @@ ThermoFisher S5Plus,http://purl.obolibrary.org/obo/NCIT_C125894 Sanger dideoxy sequencing,http://purl.obolibrary.org/obo/NCIT_C19641 MGISEQ 2000,http://virtual-bh/MGISEQ2000 MGISEQ2000,http://virtual-bh/MGISEQ2000 +Illumina HiSeq X,http://www.ebi.ac.uk/efo/EFO_0008567 +ONT GridION X5,http://www.ebi.ac.uk/efo/EFO_0008633 +ONT PremethION,http://www.ebi.ac.uk/efo/EFO_0008634 +PacBio RS II,http://www.ebi.ac.uk/efo/EFO_0008631 +PacBio Sequel System,http://www.ebi.ac.uk/efo/EFO_0008630 +Illumina Genome Analyzer,http://www.ebi.ac.uk/efo/EFO_0004200 +Illumina Genome Analyzer II,http://www.ebi.ac.uk/efo/EFO_0004201 +Illumina Genome Analyzer IIx,http://www.ebi.ac.uk/efo/EFO_0004202 +454 GS 20 sequencer,http://www.ebi.ac.uk/efo/EFO_0004206 +454 GS FLX Titanium sequencer,http://www.ebi.ac.uk/efo/EFO_0004433 +454 GS FLX sequencer,http://www.ebi.ac.uk/efo/EFO_0004432 +454 GS Junior sequencer,http://www.ebi.ac.uk/efo/EFO_0004434 +454 GS sequencer,http://www.ebi.ac.uk/efo/EFO_0004431 +AB SOLiD 4 System,http://www.ebi.ac.uk/efo/EFO_0004438 +AB SOLiD 4hq System,http://www.ebi.ac.uk/efo/EFO_0004441 +AB SOLiD 5500,http://www.ebi.ac.uk/efo/EFO_0004440 +AB SOLiD 5500xl,http://www.ebi.ac.uk/efo/EFO_0004436 +AB SOLiD PI System,http://www.ebi.ac.uk/efo/EFO_0004437 +AB SOLiD System,http://www.ebi.ac.uk/efo/EFO_0004435 +AB SOLiD System 2.0,http://www.ebi.ac.uk/efo/EFO_0004442 +AB SOLiD System 3.0,http://www.ebi.ac.uk/efo/EFO_0004439 -- cgit v1.2.3 From 637e38be956c2fe19a0f4adf8dde196fbe6bac66 Mon Sep 17 00:00:00 2001 From: Andrea Guarracino Date: Mon, 6 Jul 2020 10:28:55 +0200 Subject: fixed bugs in the download_sra_data --- scripts/download_sra_data/download_sra_data.py | 45 ++++++++++++++++---------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/scripts/download_sra_data/download_sra_data.py b/scripts/download_sra_data/download_sra_data.py index 9145a43..e36afb6 100644 --- a/scripts/download_sra_data/download_sra_data.py +++ b/scripts/download_sra_data/download_sra_data.py @@ -8,9 +8,11 @@ import gzip dir_yaml = 'yaml' -date = '2020.06.08' +date = '2020.07.05' -# Query on SRA: 'txid2697049[Organism]' (https://www.ncbi.nlm.nih.gov/sra/?term=txid2697049%5BOrganism%5D) -> Send to -> File -> Full XML -> Create File +# Query on SRA: 'txid2697049[Organism]' (https://www.ncbi.nlm.nih.gov/sra/?term=txid2697049%5BOrganism%5D) +# Query on SRA: 'txid2697049[Organism:noexp] NOT 0[Mbases ' (https://www.ncbi.nlm.nih.gov/sra/?term=txid2697049%5BOrganism:noexp%5D%20NOT%200[Mbases) +# -> Send to -> File -> Full XML -> Create File path_sra_metadata_xml = 'SraExperimentPackage.{}.xml.gz'.format(date) dir_dict_ontology_standardization = '../dict_ontology_standardization/' @@ -70,14 +72,14 @@ for i, EXPERIMENT_PACKAGE in enumerate(EXPERIMENT_PACKAGE_SET): accession = RUN.attrib['accession'] run_accession_set.add(accession) #print(accession) - + info_for_yaml_dict['sample']['sample_id'] = accession - SRAFiles = RUN.find('SRAFiles') - if SRAFiles is not None: - url = SRAFiles.find('SRAFile').attrib['url'] - if 'sra-download.ncbi.nlm.nih.gov' in url: - run_accession_to_downloadble_file_url_dict[accession] = url + #SRAFiles = RUN.find('SRAFiles') + #if SRAFiles is not None: + # url = SRAFiles.find('SRAFile').attrib['url'] + # if 'sra-download.ncbi.nlm.nih.gov' in url: + # run_accession_to_downloadble_file_url_dict[accession] = url SAMPLE = EXPERIMENT_PACKAGE.find('SAMPLE') @@ -100,11 +102,19 @@ for i, EXPERIMENT_PACKAGE in enumerate(EXPERIMENT_PACKAGE_SET): elif VALUE_text.strip("'") not in ['missing', 'not collected', 'not provided']: missing_value_list.append('\t'.join([accession, 'host_health_status', VALUE_text])) elif TAG_text in ['strain', 'isolate']: - if VALUE_text.lower() not in ['not applicable', 'missing', 'na', 'unknown']: - if 'virus_strain' not in info_for_yaml_dict: - info_for_yaml_dict['virus']['virus_strain'] = VALUE_text + if VALUE_text.lower() not in ['not applicable', 'missing', 'na', 'unknown', 'not provided']: + value_to_insert = VALUE_text + + if value_to_insert.lower() in ['homo sapien']: + value_to_insert = 'Homo sapiens' + + if value_to_insert in term_to_uri_dict: + value_to_insert = term_to_uri_dict[value_to_insert] + + if 'virus_strain' not in info_for_yaml_dict: + info_for_yaml_dict['virus']['virus_strain'] = value_to_insert else: - info_for_yaml_dict['virus']['virus_strain'] += '; ' + VALUE_text + info_for_yaml_dict['virus']['virus_strain'] += '; ' + value_to_insert elif TAG_text in ['isolation_source', 'isolation source host-associated']: if VALUE_text in term_to_uri_dict: info_for_yaml_dict['sample']['specimen_source'] = [term_to_uri_dict[VALUE_text]] @@ -179,17 +189,18 @@ for i, EXPERIMENT_PACKAGE in enumerate(EXPERIMENT_PACKAGE_SET): EXPERIMENT = EXPERIMENT_PACKAGE.find('EXPERIMENT') INSTRUMENT_MODEL = [x.text for x in EXPERIMENT.find('PLATFORM').iter('INSTRUMENT_MODEL')][0] + if INSTRUMENT_MODEL.lower() != 'unspecified': if INSTRUMENT_MODEL in term_to_uri_dict: info_for_yaml_dict['technology']['sample_sequencing_technology'] = [term_to_uri_dict[INSTRUMENT_MODEL]] else: missing_value_list.append('\t'.join([accession, 'sample_sequencing_technology', INSTRUMENT_MODEL])) - + #else: + # print(accession, 'Missing INSTRUMENT_MODEL', info_for_yaml_dict) LIBRARY_DESCRIPTOR = EXPERIMENT.find('DESIGN').find('LIBRARY_DESCRIPTOR') if LIBRARY_DESCRIPTOR.text not in ['OTHER']: info_for_yaml_dict['technology']['additional_technology_information'] = 'LIBRARY_STRATEGY: {};'.format(LIBRARY_DESCRIPTOR.find('LIBRARY_STRATEGY').text) - - + SUBMISSION = EXPERIMENT_PACKAGE.find('SUBMISSION') info_for_yaml_dict['submitter']['submitter_sample_id'] = SUBMISSION.attrib['accession'] @@ -197,7 +208,7 @@ for i, EXPERIMENT_PACKAGE in enumerate(EXPERIMENT_PACKAGE_SET): info_for_yaml_dict['submitter']['originating_lab'] = SUBMISSION.attrib['lab_name'] STUDY = EXPERIMENT_PACKAGE.find('STUDY') - info_for_yaml_dict['submitter']['publication'] = SUBMISSION.attrib['lab_name'] + info_for_yaml_dict['submitter']['publication'] = STUDY.attrib['alias'] Organization = EXPERIMENT_PACKAGE.find('Organization') @@ -229,4 +240,4 @@ if len(missing_value_list) > 0: path_missing_terms_tsv = 'missing_terms.tsv' print('Written missing terms in {}'.format(path_missing_terms_tsv)) with open(path_missing_terms_tsv, 'w') as fw: - fw.write('\n'.join(missing_value_list)) \ No newline at end of file + fw.write('\n'.join(missing_value_list)) -- cgit v1.2.3 From 38a5b6d21d6bf631ade1b0875ca654331d50021a Mon Sep 17 00:00:00 2001 From: Andrea Guarracino Date: Mon, 6 Jul 2020 11:19:46 +0200 Subject: two more terms in the ncbi_sequencing_technology dictionary --- scripts/dict_ontology_standardization/ncbi_sequencing_technology.csv | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/dict_ontology_standardization/ncbi_sequencing_technology.csv b/scripts/dict_ontology_standardization/ncbi_sequencing_technology.csv index 79c1269..59c4800 100644 --- a/scripts/dict_ontology_standardization/ncbi_sequencing_technology.csv +++ b/scripts/dict_ontology_standardization/ncbi_sequencing_technology.csv @@ -13,12 +13,14 @@ Illumina NextSeq 550,http://www.ebi.ac.uk/efo/EFO_0008566 NextSeq550,http://www.ebi.ac.uk/efo/EFO_0008566 NextSeq 550,http://www.ebi.ac.uk/efo/EFO_0008566 Illumina MiniSeq,http://www.ebi.ac.uk/efo/EFO_0008636 +Illumina NovaSeq,http://www.ebi.ac.uk/efo/EFO_0008637 Illumina NovaSeq 6000,http://www.ebi.ac.uk/efo/EFO_0008637 Nanopore MinION,http://www.ebi.ac.uk/efo/EFO_0008632 Oxford Nanopore MinION,http://www.ebi.ac.uk/efo/EFO_0008632 ONT (Oxford Nanopore Technologies),http://purl.obolibrary.org/obo/NCIT_C146818 Oxford Nanopore Technology,http://purl.obolibrary.org/obo/NCIT_C146818 Oxford Nanopore technologies MinION,http://www.ebi.ac.uk/efo/EFO_0008632 +Oxford Nanopore Sequencing,http://purl.obolibrary.org/obo/NCIT_C146818 MinION Oxford Nanopore,http://www.ebi.ac.uk/efo/EFO_0008632 MinION,http://www.ebi.ac.uk/efo/EFO_0008632 Nanopore,http://purl.obolibrary.org/obo/NCIT_C146818 -- cgit v1.2.3 From ff426b55cf7e5370d66461218d3bfb6232b882a2 Mon Sep 17 00:00:00 2001 From: AndreaGuarracino Date: Mon, 6 Jul 2020 11:22:12 +0200 Subject: updated SraExperimentPackage info --- .../SraExperimentPackage.2020.06.08.xml.gz | Bin 3227724 -> 0 bytes .../SraExperimentPackage.2020.07.05.xml.gz | Bin 0 -> 6502056 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 scripts/download_sra_data/SraExperimentPackage.2020.06.08.xml.gz create mode 100644 scripts/download_sra_data/SraExperimentPackage.2020.07.05.xml.gz diff --git a/scripts/download_sra_data/SraExperimentPackage.2020.06.08.xml.gz b/scripts/download_sra_data/SraExperimentPackage.2020.06.08.xml.gz deleted file mode 100644 index f9cd995..0000000 Binary files a/scripts/download_sra_data/SraExperimentPackage.2020.06.08.xml.gz and /dev/null differ diff --git a/scripts/download_sra_data/SraExperimentPackage.2020.07.05.xml.gz b/scripts/download_sra_data/SraExperimentPackage.2020.07.05.xml.gz new file mode 100644 index 0000000..88acb18 Binary files /dev/null and b/scripts/download_sra_data/SraExperimentPackage.2020.07.05.xml.gz differ -- cgit v1.2.3 From 27fd3fd297edbed5e5d29669eb0ad127aec162e8 Mon Sep 17 00:00:00 2001 From: AndreaGuarracino Date: Mon, 6 Jul 2020 11:26:44 +0200 Subject: added seq technology in its additional information field if the term is missing in the dicts --- scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py b/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py index 4bb4964..7edb1dc 100755 --- a/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py +++ b/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py @@ -218,6 +218,7 @@ for path_metadata_xxx_xml in [os.path.join(dir_metadata, name_metadata_xxx_xml) if seq_tec in term_to_uri_dict: seq_tec = term_to_uri_dict[seq_tec] else: + info_for_yaml_dict['technology']['additional_technology_information'] = seq_tec missing_value_list.append('\t'.join([accession_version, 'sample_sequencing_technology', seq_tec])) new_seq_tec_list.append(seq_tec) -- cgit v1.2.3 From 92639cf2616e02a798521e61598393d6d1aad5e3 Mon Sep 17 00:00:00 2001 From: Andrea Guarracino Date: Mon, 6 Jul 2020 11:03:31 +0200 Subject: new terms in the ncbi_countries dictionary --- .../ncbi_countries.csv | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/scripts/dict_ontology_standardization/ncbi_countries.csv b/scripts/dict_ontology_standardization/ncbi_countries.csv index 204f7f2..ef8cbaa 100644 --- a/scripts/dict_ontology_standardization/ncbi_countries.csv +++ b/scripts/dict_ontology_standardization/ncbi_countries.csv @@ -284,6 +284,7 @@ USA:CA,http://www.wikidata.org/entity/Q99 USA: California,http://www.wikidata.org/entity/Q99 USA:California,http://www.wikidata.org/entity/Q99 "USA: CA, San Diego County",http://www.wikidata.org/entity/Q108143 +"USA: California, Monterey County",http://www.wikidata.org/entity/Q108072 USA: CO,http://www.wikidata.org/entity/Q1261 USA: CT,http://www.wikidata.org/entity/Q779 USA: Connecticut,http://www.wikidata.org/entity/Q779 @@ -301,8 +302,14 @@ 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 +<<<<<<< HEAD USA:Los Angeles,http://www.wikidata.org/entity/Q65 "USA: New Orleans, LA",http://www.wikidata.org/entity/Q34404 +======= +"USA: SLIDELL, LA, LA",https://www.wikidata.org/wiki/Q988156 +"USA: Slidell, LA, LA",https://www.wikidata.org/wiki/Q988156 +"USA: New Orleans, LA",https://www.wikidata.org/wiki/Q34404 +>>>>>>> 67e5976... new terms in the ncbi_countries dictionary USA: MA,http://www.wikidata.org/entity/Q771 USA: Massachusetts,http://www.wikidata.org/entity/Q771 USA: MD,http://www.wikidata.org/entity/Q1391 @@ -336,6 +343,33 @@ USA: SC,http://www.wikidata.org/entity/Q1456 USA: South Carolina,http://www.wikidata.org/entity/Q1456 USA: SD,http://www.wikidata.org/entity/Q1211 "USA: Snohomish County, WA",http://www.wikidata.org/entity/Q110403 +"USA: Washington,Snohomish County",http://www.wikidata.org/entity/Q110403 +"USA: Washington, Snohomish County",http://www.wikidata.org/entity/Q110403 +"USA: Washington,Skagit County",http://www.wikidata.org/entity/Q113892 +"USA: Washington, Skagit County",http://www.wikidata.org/entity/Q113892 +"USA: Washington,Pierce County",http://www.wikidata.org/entity/Q156459 +"USA: Washington, Pierce County",http://www.wikidata.org/entity/Q156459 +"USA: Washington,Mason County",http://www.wikidata.org/entity/Q111904 +"USA: Washington, Mason County",http://www.wikidata.org/entity/Q111904 +"USA: Washington,Kittitas County",http://www.wikidata.org/entity/Q111540 +"USA: Washington,King County",http://www.wikidata.org/entity/Q108861 +"USA: Washington, King County",http://www.wikidata.org/entity/Q108861 +"USA: King County,WA",http://www.wikidata.org/entity/Q108861 +"USA: Washington,Jefferson County",http://www.wikidata.org/entity/Q384737 +"USA: Washington,Grant County",http://www.wikidata.org/entity/Q281681 +"USA: Washington, Grant County",http://www.wikidata.org/entity/Q281681 +"USA: Washington,Franklin County",http://www.wikidata.org/entity/Q118716 +"USA: Washington, Franklin County",http://www.wikidata.org/entity/Q118716 +"USA: Washington,Clark County",http://www.wikidata.org/entity/Q156287 +"USA: Washington,Benton County",http://www.wikidata.org/entity/Q156216 +"USA: Washington, Benton County",http://www.wikidata.org/entity/Q156216 +"USA: Washington,Asotin County",http://www.wikidata.org/entity/Q156295 +"USA: Washington, Asotin County",http://www.wikidata.org/entity/Q156295 +"USA: Washington,Adams County",http://www.wikidata.org/entity/Q156273 +"USA: Washington, Adams County",http://www.wikidata.org/entity/Q156273 +"USA: Washington, Spokane County",http://www.wikidata.org/entity/Q485276 +"USA: Washington, Douglas County",http://www.wikidata.org/entity/Q156220 +"USA: Washington, Cowlitz County",http://www.wikidata.org/entity/Q156276 USA: TN,http://www.wikidata.org/entity/Q1509 USA: TX,http://www.wikidata.org/entity/Q1439 USA: UT,http://www.wikidata.org/entity/Q829 @@ -344,9 +378,17 @@ USA: Virginia,http://www.wikidata.org/entity/Q1370 USA:Virginia,http://www.wikidata.org/entity/Q1370 USA: VT,http://www.wikidata.org/entity/Q16551 USA: WA,http://www.wikidata.org/entity/Q1223 +<<<<<<< HEAD USA: Washington,http://www.wikidata.org/entity/Q1223 USA: WI,http://www.wikidata.org/entity/Q1537 USA: Wisconsin,http://www.wikidata.org/entity/Q1537 +======= +"USA: Washington,Yakima County",http://www.wikidata.org/entity/Q156629 +"USA: Washington, Yakima County",http://www.wikidata.org/entity/Q156629 +"USA: Washington,Whatcom County",http://www.wikidata.org/entity/Q156623 +USA: WI,http://www.wikidata.org/entity/Q1537 +"USA: Dane County, Wisconsin",http://www.wikidata.org/entity/Q502200 +>>>>>>> 67e5976... new terms in the ncbi_countries dictionary USA: WV,http://www.wikidata.org/entity/Q1371 USA: WY,http://www.wikidata.org/entity/Q1214 Uzbekistan,http://www.wikidata.org/entity/Q265 -- cgit v1.2.3 From c8b12b4e2b7e2e51315fe738f8bb4e37cb78ae55 Mon Sep 17 00:00:00 2001 From: AndreaGuarracino Date: Mon, 6 Jul 2020 15:22:45 +0200 Subject: fix ncbi_countries dictionary --- scripts/dict_ontology_standardization/ncbi_countries.csv | 9 --------- 1 file changed, 9 deletions(-) diff --git a/scripts/dict_ontology_standardization/ncbi_countries.csv b/scripts/dict_ontology_standardization/ncbi_countries.csv index ef8cbaa..4bea3ec 100644 --- a/scripts/dict_ontology_standardization/ncbi_countries.csv +++ b/scripts/dict_ontology_standardization/ncbi_countries.csv @@ -302,14 +302,9 @@ 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 -<<<<<<< HEAD -USA:Los Angeles,http://www.wikidata.org/entity/Q65 -"USA: New Orleans, LA",http://www.wikidata.org/entity/Q34404 -======= "USA: SLIDELL, LA, LA",https://www.wikidata.org/wiki/Q988156 "USA: Slidell, LA, LA",https://www.wikidata.org/wiki/Q988156 "USA: New Orleans, LA",https://www.wikidata.org/wiki/Q34404 ->>>>>>> 67e5976... new terms in the ncbi_countries dictionary USA: MA,http://www.wikidata.org/entity/Q771 USA: Massachusetts,http://www.wikidata.org/entity/Q771 USA: MD,http://www.wikidata.org/entity/Q1391 @@ -378,17 +373,13 @@ USA: Virginia,http://www.wikidata.org/entity/Q1370 USA:Virginia,http://www.wikidata.org/entity/Q1370 USA: VT,http://www.wikidata.org/entity/Q16551 USA: WA,http://www.wikidata.org/entity/Q1223 -<<<<<<< HEAD USA: Washington,http://www.wikidata.org/entity/Q1223 USA: WI,http://www.wikidata.org/entity/Q1537 USA: Wisconsin,http://www.wikidata.org/entity/Q1537 -======= "USA: Washington,Yakima County",http://www.wikidata.org/entity/Q156629 "USA: Washington, Yakima County",http://www.wikidata.org/entity/Q156629 "USA: Washington,Whatcom County",http://www.wikidata.org/entity/Q156623 -USA: WI,http://www.wikidata.org/entity/Q1537 "USA: Dane County, Wisconsin",http://www.wikidata.org/entity/Q502200 ->>>>>>> 67e5976... new terms in the ncbi_countries dictionary USA: WV,http://www.wikidata.org/entity/Q1371 USA: WY,http://www.wikidata.org/entity/Q1214 Uzbekistan,http://www.wikidata.org/entity/Q265 -- cgit v1.2.3 From 4e2ac9bdef97175f5d762c6e7f065a83512a3c40 Mon Sep 17 00:00:00 2001 From: AndreaGuarracino Date: Mon, 6 Jul 2020 15:24:06 +0200 Subject: renamed sra script; added seq technology in its additional information field if the term … --- .../SraExperimentPackage.2020.07.05.xml.gz | Bin 0 -> 6502056 bytes scripts/create_sra_metadata/create_sra_metadata.py | 247 +++++++++++++++++++++ .../SraExperimentPackage.2020.07.05.xml.gz | Bin 6502056 -> 0 bytes scripts/download_sra_data/download_sra_data.py | 243 -------------------- 4 files changed, 247 insertions(+), 243 deletions(-) create mode 100644 scripts/create_sra_metadata/SraExperimentPackage.2020.07.05.xml.gz create mode 100644 scripts/create_sra_metadata/create_sra_metadata.py delete mode 100644 scripts/download_sra_data/SraExperimentPackage.2020.07.05.xml.gz delete mode 100644 scripts/download_sra_data/download_sra_data.py diff --git a/scripts/create_sra_metadata/SraExperimentPackage.2020.07.05.xml.gz b/scripts/create_sra_metadata/SraExperimentPackage.2020.07.05.xml.gz new file mode 100644 index 0000000..88acb18 Binary files /dev/null and b/scripts/create_sra_metadata/SraExperimentPackage.2020.07.05.xml.gz differ diff --git a/scripts/create_sra_metadata/create_sra_metadata.py b/scripts/create_sra_metadata/create_sra_metadata.py new file mode 100644 index 0000000..470980e --- /dev/null +++ b/scripts/create_sra_metadata/create_sra_metadata.py @@ -0,0 +1,247 @@ +#!/usr/bin/env python3 + +import os +from dateutil.parser import parse +import xml.etree.ElementTree as ET +import json +import gzip + +dir_yaml = 'yaml' + +date = '2020.07.05' + +# Query on SRA: 'txid2697049[Organism]' (https://www.ncbi.nlm.nih.gov/sra/?term=txid2697049%5BOrganism%5D) +# Query on SRA: 'txid2697049[Organism:noexp] NOT 0[Mbases ' (https://www.ncbi.nlm.nih.gov/sra/?term=txid2697049%5BOrganism:noexp%5D%20NOT%200[Mbases) +# -> Send to -> File -> Full XML -> Create File +path_sra_metadata_xml = 'SraExperimentPackage.{}.xml.gz'.format(date) + +dir_dict_ontology_standardization = '../dict_ontology_standardization/' +path_sra_study_accessions_txt = 'SRAStudyAccessions.{}.txt'.format(date) + +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')]: + print('Read {}'.format(path_dict_xxx_csv)) + + with open(path_dict_xxx_csv, 'r') as f: + for line in f: + if len(line.split(',')) > 2: + term, uri = line.strip('\n').split('",') + term = term.strip('"') + else: + term, uri = line.strip('\n').split(',') + + term_to_uri_dict[term] = uri + +def is_integer(string_to_check): + try: + int(string_to_check) + return True + except ValueError: + return False + +if not os.path.exists(dir_yaml): + os.makedirs(dir_yaml) + +sra_metadata_xml_file = gzip.open(path_sra_metadata_xml, 'r') +tree = ET.parse(sra_metadata_xml_file) +sra_metadata_xml_file.close() + +EXPERIMENT_PACKAGE_SET = tree.getroot() + +missing_value_list = [] + +run_accession_set = set() +run_accession_to_downloadble_file_url_dict = {} + +for i, EXPERIMENT_PACKAGE in enumerate(EXPERIMENT_PACKAGE_SET): + #print(i, EXPERIMENT_PACKAGE) + + # A general default-empty yaml could be read from the definitive one + info_for_yaml_dict = { + 'id': 'placeholder', + 'host': {}, + 'sample': {}, + 'virus': {}, + 'technology': {}, + 'submitter': {} + } + + RUN_SET = EXPERIMENT_PACKAGE.find('RUN_SET') + RUN = RUN_SET.find('RUN') + accession = RUN.attrib['accession'] + run_accession_set.add(accession) + #print(accession) + + info_for_yaml_dict['sample']['sample_id'] = accession + + #SRAFiles = RUN.find('SRAFiles') + #if SRAFiles is not None: + # url = SRAFiles.find('SRAFile').attrib['url'] + # if 'sra-download.ncbi.nlm.nih.gov' in url: + # run_accession_to_downloadble_file_url_dict[accession] = url + + + SAMPLE = EXPERIMENT_PACKAGE.find('SAMPLE') + SAMPLE_ATTRIBUTE_list = SAMPLE.iter('SAMPLE_ATTRIBUTE') + + for SAMPLE_ATTRIBUTE in SAMPLE_ATTRIBUTE_list: + VALUE = SAMPLE_ATTRIBUTE.find('VALUE') + if VALUE is not None: + TAG_text = SAMPLE_ATTRIBUTE.find('TAG').text + VALUE_text = VALUE.text + + if TAG_text in ['host', 'host scientific name']: + if VALUE_text.lower() in ['homo sapien', 'homosapiens']: + VALUE_text = 'Homo sapiens' + + if VALUE_text in term_to_uri_dict: + info_for_yaml_dict['host']['host_species'] = term_to_uri_dict[VALUE_text] + else: + missing_value_list.append('\t'.join([accession, 'host_species', VALUE_text])) + elif TAG_text in ['host_health_status', 'host health state']: + if VALUE_text in term_to_uri_dict: + info_for_yaml_dict['host']['host_health_status'] = term_to_uri_dict[VALUE_text] + elif VALUE_text.strip("'") not in ['missing', 'not collected', 'not provided']: + missing_value_list.append('\t'.join([accession, 'host_health_status', VALUE_text])) + elif TAG_text in ['strain', 'isolate']: + if VALUE_text.lower() not in ['not applicable', 'missing', 'na', 'unknown', 'not provided']: + value_to_insert = VALUE_text + + if value_to_insert.lower() in ['homo sapien', 'homosapiens']: + value_to_insert = 'Homo sapiens' + + if value_to_insert in term_to_uri_dict: + value_to_insert = term_to_uri_dict[value_to_insert] + + if 'virus_strain' not in info_for_yaml_dict: + info_for_yaml_dict['virus']['virus_strain'] = value_to_insert + else: + info_for_yaml_dict['virus']['virus_strain'] += '; ' + value_to_insert + elif TAG_text in ['isolation_source', 'isolation source host-associated']: + if VALUE_text in term_to_uri_dict: + info_for_yaml_dict['sample']['specimen_source'] = [term_to_uri_dict[VALUE_text]] + else: + if VALUE_text.lower() in ['np/op', 'np/op swab', 'np/np swab', 'nasopharyngeal and oropharyngeal swab', 'nasopharyngeal/oropharyngeal swab', 'combined nasopharyngeal and oropharyngeal swab']: + info_for_yaml_dict['sample']['specimen_source'] = [term_to_uri_dict['nasopharyngeal swab'], term_to_uri_dict['oropharyngeal swab']] + elif VALUE_text.lower() in ['nasopharyngeal swab/throat swab', 'nasopharyngeal/throat swab', 'nasopharyngeal swab and throat swab', 'nasal swab and throat swab', 'nasopharyngeal aspirate/throat swab']: + info_for_yaml_dict['sample']['specimen_source'] = [term_to_uri_dict['nasopharyngeal swab'], term_to_uri_dict['throat swab']] + elif VALUE_text.lower() in ['nasal swab and throat swab']: + info_for_yaml_dict['sample']['specimen_source'] = [term_to_uri_dict['nasal swab'], term_to_uri_dict['throat swab']] + elif VALUE_text.lower() in ['nasal-swab and oro-pharyngeal swab']: + info_for_yaml_dict['sample']['specimen_source'] = [term_to_uri_dict['nasal swab'], term_to_uri_dict['oropharyngeal swab']] + elif VALUE_text.strip("'") not in ['missing', 'not collected', 'unknown', 'not provided', 'not applicable', 'N/A']: + missing_value_list.append('\t'.join([accession, 'specimen_source', VALUE_text])) + elif TAG_text in ['host_sex', 'host sex']: + if VALUE_text.lower() not in ['missing', 'not provided']: + if VALUE_text in ['male', 'female']: + info_for_yaml_dict['host']['host_sex'] = "http://purl.obolibrary.org/obo/PATO_0000384" if VALUE_text == 'male' else "http://purl.obolibrary.org/obo/PATO_0000383" + else: + missing_value_list.append('\t'.join([accession, 'host_sex', VALUE_text])) + elif TAG_text in ['host_age', 'host age']: + if is_integer(VALUE_text): + info_for_yaml_dict['host']['host_age'] = VALUE_text + info_for_yaml_dict['host']['host_age_unit'] = 'http://purl.obolibrary.org/obo/UO_0000036' + elif TAG_text == 'collected_by': + if VALUE_text.lower() not in ['not available', 'missing']: + name = VALUE_text in ['Dr. Susie Bartlett', 'Ahmed Babiker', 'Aisi Fu', 'Brandi Williamson', 'George Taiaroa', 'Natacha Ogando', 'Tim Dalebout', 'ykut Ozdarendeli'] + + info_for_yaml_dict['sample']['collector_name' if name else 'collecting_institution'] = VALUE_text + elif TAG_text == 'collecting institution': + if VALUE_text.lower() not in ['not provided', 'na']: + info_for_yaml_dict['sample']['collecting_institution'] = VALUE_text + elif TAG_text in ['collection_date', 'collection date']: + if VALUE_text.lower() not in ['not applicable', 'missing', 'na']: + date_to_write = VALUE_text + date_is_estimated = True + + VALUE_text_list = VALUE_text.split('-') + if len(VALUE_text_list) == 3: + date_is_estimated = False + + if VALUE_text_list[1].isalpha(): + date_to_write = parse(VALUE_text).strftime('%Y-%m-%d') + elif len(VALUE_text_list) == 2: + date_to_write = VALUE_text + '-15' + else: + if int(VALUE_text) < 2020: + date_to_write = "{}-12-15".format(VALUE_text) + else: + date_to_write = "{}-01-15".format(VALUE_text) + + info_for_yaml_dict['sample']['collection_date'] = date_to_write + + if date_is_estimated: + if 'additional_collection_information' in info_for_yaml_dict['sample']: + info_for_yaml_dict['sample']['additional_collection_information'] += "; The 'collection_date' is estimated (the original date was: {})".format(VALUE_text) + else: + info_for_yaml_dict['sample']['additional_collection_information'] = "The 'collection_date' is estimated (the original date was: {})".format(VALUE_text) + elif TAG_text == 'geo_loc_name': + if VALUE_text in term_to_uri_dict: + info_for_yaml_dict['sample']['collection_location'] = term_to_uri_dict[VALUE_text] + elif VALUE_text.lower() not in ['na', 'not applicable']: + missing_value_list.append('\t'.join([accession, 'geo_loc_name', VALUE_text])) + #else: + # if TAG_text not in ['lat_lon', 'host_disease', 'BioSampleModel', 'passage_history']: + # print(accession, TAG_text, VALUE_text) + + + taxon_id = SAMPLE.find('SAMPLE_NAME').find('TAXON_ID').text + info_for_yaml_dict['virus']['virus_species'] = "http://purl.obolibrary.org/obo/NCBITaxon_"+taxon_id + + + EXPERIMENT = EXPERIMENT_PACKAGE.find('EXPERIMENT') + INSTRUMENT_MODEL = [x.text for x in EXPERIMENT.find('PLATFORM').iter('INSTRUMENT_MODEL')][0] + + if INSTRUMENT_MODEL.lower() != 'unspecified': + if INSTRUMENT_MODEL in term_to_uri_dict: + info_for_yaml_dict['technology']['sample_sequencing_technology'] = [term_to_uri_dict[INSTRUMENT_MODEL]] + else: + info_for_yaml_dict['technology']['additional_technology_information'] = INSTRUMENT_MODEL + missing_value_list.append('\t'.join([accession, 'sample_sequencing_technology', INSTRUMENT_MODEL])) + #else: + # print(accession, 'Missing INSTRUMENT_MODEL', info_for_yaml_dict) + LIBRARY_DESCRIPTOR = EXPERIMENT.find('DESIGN').find('LIBRARY_DESCRIPTOR') + if LIBRARY_DESCRIPTOR.text not in ['OTHER']: + info_for_yaml_dict['technology']['additional_technology_information'] = 'LIBRARY_STRATEGY: {};'.format(LIBRARY_DESCRIPTOR.find('LIBRARY_STRATEGY').text) + + SUBMISSION = EXPERIMENT_PACKAGE.find('SUBMISSION') + info_for_yaml_dict['submitter']['submitter_sample_id'] = SUBMISSION.attrib['accession'] + + if SUBMISSION.attrib['lab_name'].lower() not in ['na']: + info_for_yaml_dict['submitter']['originating_lab'] = SUBMISSION.attrib['lab_name'] + + STUDY = EXPERIMENT_PACKAGE.find('STUDY') + info_for_yaml_dict['submitter']['publication'] = STUDY.attrib['alias'] + + + Organization = EXPERIMENT_PACKAGE.find('Organization') + Organization_Name = Organization.find('Name') + info_for_yaml_dict['submitter']['authors'] = [Organization_Name.text] + + Organization_Contact = Organization.find('Contact') + if Organization_Contact is not None: + Organization_Contact_Name = Organization_Contact.find('Name') + info_for_yaml_dict['submitter']['submitter_name'] = [Organization_Contact_Name.find('First').text + ' ' + Organization_Contact_Name.find('Last').text] + info_for_yaml_dict['submitter']['additional_submitter_information'] = Organization_Contact.attrib['email'] + + Organization_Concact_Address = Organization_Contact.find('Address') + if Organization_Concact_Address is not None: + info_for_yaml_dict['submitter']['submitter_address'] = '; '.join([x.text for x in Organization_Concact_Address] + ['Postal code ' + Organization_Concact_Address.attrib['postal_code']]) + + Organization_Address = Organization.find('Address') + if Organization_Address is not None: + info_for_yaml_dict['submitter']['lab_address'] = '; '.join([x.text for x in Organization_Address] + ['Postal code ' + Organization_Address.attrib['postal_code']]) + + if 'collection_date' not in info_for_yaml_dict['sample']: + info_for_yaml_dict['sample']['collection_date'] = '1970-01-01' + info_for_yaml_dict['sample']['additional_collection_information'] = "The real 'collection_date' is missing" + + with open(os.path.join(dir_yaml, '{}.yaml'.format(accession)), 'w') as fw: + json.dump(info_for_yaml_dict, fw, indent=2) + +if len(missing_value_list) > 0: + path_missing_terms_tsv = 'missing_terms.tsv' + print('Written missing terms in {}'.format(path_missing_terms_tsv)) + with open(path_missing_terms_tsv, 'w') as fw: + fw.write('\n'.join(missing_value_list)) diff --git a/scripts/download_sra_data/SraExperimentPackage.2020.07.05.xml.gz b/scripts/download_sra_data/SraExperimentPackage.2020.07.05.xml.gz deleted file mode 100644 index 88acb18..0000000 Binary files a/scripts/download_sra_data/SraExperimentPackage.2020.07.05.xml.gz and /dev/null differ diff --git a/scripts/download_sra_data/download_sra_data.py b/scripts/download_sra_data/download_sra_data.py deleted file mode 100644 index e36afb6..0000000 --- a/scripts/download_sra_data/download_sra_data.py +++ /dev/null @@ -1,243 +0,0 @@ -#!/usr/bin/env python3 - -import os -from dateutil.parser import parse -import xml.etree.ElementTree as ET -import json -import gzip - -dir_yaml = 'yaml' - -date = '2020.07.05' - -# Query on SRA: 'txid2697049[Organism]' (https://www.ncbi.nlm.nih.gov/sra/?term=txid2697049%5BOrganism%5D) -# Query on SRA: 'txid2697049[Organism:noexp] NOT 0[Mbases ' (https://www.ncbi.nlm.nih.gov/sra/?term=txid2697049%5BOrganism:noexp%5D%20NOT%200[Mbases) -# -> Send to -> File -> Full XML -> Create File -path_sra_metadata_xml = 'SraExperimentPackage.{}.xml.gz'.format(date) - -dir_dict_ontology_standardization = '../dict_ontology_standardization/' -path_sra_study_accessions_txt = 'SRAStudyAccessions.{}.txt'.format(date) - -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')]: - print('Read {}'.format(path_dict_xxx_csv)) - - with open(path_dict_xxx_csv, 'r') as f: - for line in f: - if len(line.split(',')) > 2: - term, uri = line.strip('\n').split('",') - term = term.strip('"') - else: - term, uri = line.strip('\n').split(',') - - term_to_uri_dict[term] = uri - -def is_integer(string_to_check): - try: - int(string_to_check) - return True - except ValueError: - return False - -if not os.path.exists(dir_yaml): - os.makedirs(dir_yaml) - -sra_metadata_xml_file = gzip.open(path_sra_metadata_xml, 'r') -tree = ET.parse(sra_metadata_xml_file) -sra_metadata_xml_file.close() - -EXPERIMENT_PACKAGE_SET = tree.getroot() - -missing_value_list = [] - -run_accession_set = set() -run_accession_to_downloadble_file_url_dict = {} - -for i, EXPERIMENT_PACKAGE in enumerate(EXPERIMENT_PACKAGE_SET): - #print(i, EXPERIMENT_PACKAGE) - - # A general default-empty yaml could be read from the definitive one - info_for_yaml_dict = { - 'id': 'placeholder', - 'host': {}, - 'sample': {}, - 'virus': {}, - 'technology': {}, - 'submitter': {} - } - - RUN_SET = EXPERIMENT_PACKAGE.find('RUN_SET') - RUN = RUN_SET.find('RUN') - accession = RUN.attrib['accession'] - run_accession_set.add(accession) - #print(accession) - - info_for_yaml_dict['sample']['sample_id'] = accession - - #SRAFiles = RUN.find('SRAFiles') - #if SRAFiles is not None: - # url = SRAFiles.find('SRAFile').attrib['url'] - # if 'sra-download.ncbi.nlm.nih.gov' in url: - # run_accession_to_downloadble_file_url_dict[accession] = url - - - SAMPLE = EXPERIMENT_PACKAGE.find('SAMPLE') - SAMPLE_ATTRIBUTE_list = SAMPLE.iter('SAMPLE_ATTRIBUTE') - - for SAMPLE_ATTRIBUTE in SAMPLE_ATTRIBUTE_list: - VALUE = SAMPLE_ATTRIBUTE.find('VALUE') - if VALUE is not None: - TAG_text = SAMPLE_ATTRIBUTE.find('TAG').text - VALUE_text = VALUE.text - - if TAG_text in ['host', 'host scientific name']: - if VALUE_text in term_to_uri_dict: - info_for_yaml_dict['host']['host_species'] = term_to_uri_dict[VALUE_text] - else: - missing_value_list.append('\t'.join([accession, 'host_species', VALUE_text])) - elif TAG_text in ['host_health_status', 'host health state']: - if VALUE_text in term_to_uri_dict: - info_for_yaml_dict['host']['host_health_status'] = term_to_uri_dict[VALUE_text] - elif VALUE_text.strip("'") not in ['missing', 'not collected', 'not provided']: - missing_value_list.append('\t'.join([accession, 'host_health_status', VALUE_text])) - elif TAG_text in ['strain', 'isolate']: - if VALUE_text.lower() not in ['not applicable', 'missing', 'na', 'unknown', 'not provided']: - value_to_insert = VALUE_text - - if value_to_insert.lower() in ['homo sapien']: - value_to_insert = 'Homo sapiens' - - if value_to_insert in term_to_uri_dict: - value_to_insert = term_to_uri_dict[value_to_insert] - - if 'virus_strain' not in info_for_yaml_dict: - info_for_yaml_dict['virus']['virus_strain'] = value_to_insert - else: - info_for_yaml_dict['virus']['virus_strain'] += '; ' + value_to_insert - elif TAG_text in ['isolation_source', 'isolation source host-associated']: - if VALUE_text in term_to_uri_dict: - info_for_yaml_dict['sample']['specimen_source'] = [term_to_uri_dict[VALUE_text]] - else: - if VALUE_text.lower() in ['np/op', 'np/op swab', 'np/np swab', 'nasopharyngeal and oropharyngeal swab', 'nasopharyngeal/oropharyngeal swab', 'combined nasopharyngeal and oropharyngeal swab']: - info_for_yaml_dict['sample']['specimen_source'] = [term_to_uri_dict['nasopharyngeal swab'], term_to_uri_dict['oropharyngeal swab']] - elif VALUE_text.lower() in ['nasopharyngeal swab/throat swab', 'nasopharyngeal/throat swab', 'nasopharyngeal swab and throat swab', 'nasal swab and throat swab', 'nasopharyngeal aspirate/throat swab']: - info_for_yaml_dict['sample']['specimen_source'] = [term_to_uri_dict['nasopharyngeal swab'], term_to_uri_dict['throat swab']] - elif VALUE_text.lower() in ['nasal swab and throat swab']: - info_for_yaml_dict['sample']['specimen_source'] = [term_to_uri_dict['nasal swab'], term_to_uri_dict['throat swab']] - elif VALUE_text.lower() in ['nasal-swab and oro-pharyngeal swab']: - info_for_yaml_dict['sample']['specimen_source'] = [term_to_uri_dict['nasal swab'], term_to_uri_dict['oropharyngeal swab']] - elif VALUE_text.strip("'") not in ['missing', 'not collected', 'unknown', 'not provided', 'not applicable', 'N/A']: - missing_value_list.append('\t'.join([accession, 'specimen_source', VALUE_text])) - elif TAG_text in ['host_sex', 'host sex']: - if VALUE_text.lower() not in ['missing', 'not provided']: - if VALUE_text in ['male', 'female']: - info_for_yaml_dict['host']['host_sex'] = "http://purl.obolibrary.org/obo/PATO_0000384" if VALUE_text == 'male' else "http://purl.obolibrary.org/obo/PATO_0000383" - else: - missing_value_list.append('\t'.join([accession, 'host_sex', VALUE_text])) - elif TAG_text in ['host_age', 'host age']: - if is_integer(VALUE_text): - info_for_yaml_dict['host']['host_age'] = VALUE_text - info_for_yaml_dict['host']['host_age_unit'] = 'http://purl.obolibrary.org/obo/UO_0000036' - elif TAG_text == 'collected_by': - if VALUE_text.lower() not in ['not available', 'missing']: - name = VALUE_text in ['Dr. Susie Bartlett', 'Ahmed Babiker', 'Aisi Fu', 'Brandi Williamson', 'George Taiaroa', 'Natacha Ogando', 'Tim Dalebout', 'ykut Ozdarendeli'] - - info_for_yaml_dict['sample']['collector_name' if name else 'collecting_institution'] = VALUE_text - elif TAG_text == 'collecting institution': - if VALUE_text.lower() not in ['not provided', 'na']: - info_for_yaml_dict['sample']['collecting_institution'] = VALUE_text - elif TAG_text in ['collection_date', 'collection date']: - if VALUE_text.lower() not in ['not applicable', 'missing', 'na']: - date_to_write = VALUE_text - date_is_estimated = True - - VALUE_text_list = VALUE_text.split('-') - if len(VALUE_text_list) == 3: - date_is_estimated = False - - if VALUE_text_list[1].isalpha(): - date_to_write = parse(VALUE_text).strftime('%Y-%m-%d') - elif len(VALUE_text_list) == 2: - date_to_write = VALUE_text + '-15' - else: - if int(VALUE_text) < 2020: - date_to_write = "{}-12-15".format(VALUE_text) - else: - date_to_write = "{}-01-15".format(VALUE_text) - - info_for_yaml_dict['sample']['collection_date'] = date_to_write - - if date_is_estimated: - if 'additional_collection_information' in info_for_yaml_dict['sample']: - info_for_yaml_dict['sample']['additional_collection_information'] += "; The 'collection_date' is estimated (the original date was: {})".format(VALUE_text) - else: - info_for_yaml_dict['sample']['additional_collection_information'] = "The 'collection_date' is estimated (the original date was: {})".format(VALUE_text) - elif TAG_text == 'geo_loc_name': - if VALUE_text in term_to_uri_dict: - info_for_yaml_dict['sample']['collection_location'] = term_to_uri_dict[VALUE_text] - elif VALUE_text.lower() not in ['na', 'not applicable']: - missing_value_list.append('\t'.join([accession, 'geo_loc_name', VALUE_text])) - #else: - # if TAG_text not in ['lat_lon', 'host_disease', 'BioSampleModel', 'passage_history']: - # print(accession, TAG_text, VALUE_text) - - - taxon_id = SAMPLE.find('SAMPLE_NAME').find('TAXON_ID').text - info_for_yaml_dict['virus']['virus_species'] = "http://purl.obolibrary.org/obo/NCBITaxon_"+taxon_id - - - EXPERIMENT = EXPERIMENT_PACKAGE.find('EXPERIMENT') - INSTRUMENT_MODEL = [x.text for x in EXPERIMENT.find('PLATFORM').iter('INSTRUMENT_MODEL')][0] - - if INSTRUMENT_MODEL.lower() != 'unspecified': - if INSTRUMENT_MODEL in term_to_uri_dict: - info_for_yaml_dict['technology']['sample_sequencing_technology'] = [term_to_uri_dict[INSTRUMENT_MODEL]] - else: - missing_value_list.append('\t'.join([accession, 'sample_sequencing_technology', INSTRUMENT_MODEL])) - #else: - # print(accession, 'Missing INSTRUMENT_MODEL', info_for_yaml_dict) - LIBRARY_DESCRIPTOR = EXPERIMENT.find('DESIGN').find('LIBRARY_DESCRIPTOR') - if LIBRARY_DESCRIPTOR.text not in ['OTHER']: - info_for_yaml_dict['technology']['additional_technology_information'] = 'LIBRARY_STRATEGY: {};'.format(LIBRARY_DESCRIPTOR.find('LIBRARY_STRATEGY').text) - - SUBMISSION = EXPERIMENT_PACKAGE.find('SUBMISSION') - info_for_yaml_dict['submitter']['submitter_sample_id'] = SUBMISSION.attrib['accession'] - - if SUBMISSION.attrib['lab_name'].lower() not in ['na']: - info_for_yaml_dict['submitter']['originating_lab'] = SUBMISSION.attrib['lab_name'] - - STUDY = EXPERIMENT_PACKAGE.find('STUDY') - info_for_yaml_dict['submitter']['publication'] = STUDY.attrib['alias'] - - - Organization = EXPERIMENT_PACKAGE.find('Organization') - Organization_Name = Organization.find('Name') - info_for_yaml_dict['submitter']['authors'] = [Organization_Name.text] - - Organization_Contact = Organization.find('Contact') - if Organization_Contact is not None: - Organization_Contact_Name = Organization_Contact.find('Name') - info_for_yaml_dict['submitter']['submitter_name'] = [Organization_Contact_Name.find('First').text + ' ' + Organization_Contact_Name.find('Last').text] - info_for_yaml_dict['submitter']['additional_submitter_information'] = Organization_Contact.attrib['email'] - - Organization_Concact_Address = Organization_Contact.find('Address') - if Organization_Concact_Address is not None: - info_for_yaml_dict['submitter']['submitter_address'] = '; '.join([x.text for x in Organization_Concact_Address] + ['Postal code ' + Organization_Concact_Address.attrib['postal_code']]) - - Organization_Address = Organization.find('Address') - if Organization_Address is not None: - info_for_yaml_dict['submitter']['lab_address'] = '; '.join([x.text for x in Organization_Address] + ['Postal code ' + Organization_Address.attrib['postal_code']]) - - if 'collection_date' not in info_for_yaml_dict['sample']: - info_for_yaml_dict['sample']['collection_date'] = '1970-01-01' - info_for_yaml_dict['sample']['additional_collection_information'] = "The real 'collection_date' is missing" - - with open(os.path.join(dir_yaml, '{}.yaml'.format(accession)), 'w') as fw: - json.dump(info_for_yaml_dict, fw, indent=2) - -if len(missing_value_list) > 0: - path_missing_terms_tsv = 'missing_terms.tsv' - print('Written missing terms in {}'.format(path_missing_terms_tsv)) - with open(path_missing_terms_tsv, 'w') as fw: - fw.write('\n'.join(missing_value_list)) -- cgit v1.2.3 From 7cf561c1b92a44d488d36dd3d883750b261c6550 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 7 Jul 2020 15:52:46 -0400 Subject: Use minimap2 instead of clustalw for fasta QC Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- bh20sequploader/main.py | 9 +++++-- bh20sequploader/qc_fasta.py | 61 +++++++++++++++++++-------------------------- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/bh20sequploader/main.py b/bh20sequploader/main.py index 8555e2b..fd0278d 100644 --- a/bh20sequploader/main.py +++ b/bh20sequploader/main.py @@ -23,14 +23,16 @@ ARVADOS_API_TOKEN='2fbebpmbo3rw3x05ueu2i6nx70zhrsb1p22ycu3ry34m4x4462' UPLOAD_PROJECT='lugli-j7d0g-n5clictpuvwk8aa' def qc_stuff(metadata, sequence_p1, sequence_p2, do_qc=True): + failed = False try: log.debug("Checking metadata" if do_qc else "Skipping metadata check") if do_qc and not qc_metadata(metadata.name): - raise Exception("Failed metadata qc") + log.warning("Failed metadata qc") + failed = True except Exception as e: log.debug(e) print(e) - exit(1) + failed = True target = [] try: @@ -43,6 +45,9 @@ def qc_stuff(metadata, sequence_p1, sequence_p2, do_qc=True): except Exception as e: log.debug(e) print(e) + failed = True + + if failed: exit(1) return target diff --git a/bh20sequploader/qc_fasta.py b/bh20sequploader/qc_fasta.py index 8c6ebd3..b08333e 100644 --- a/bh20sequploader/qc_fasta.py +++ b/bh20sequploader/qc_fasta.py @@ -58,42 +58,33 @@ def qc_fasta(arg_sequence, check_with_clustalw=True): return ("sequence.fasta"+gz, seqlabel) with tempfile.NamedTemporaryFile() as tmp1: - refstring = pkg_resources.resource_string(__name__, "SARS-CoV-2-reference.fasta") - tmp1.write(refstring) - tmp1.write(submitlabel.encode("utf8")) - tmp1.write(("".join(submitseq)).encode("utf8")) - tmp1.flush() - subbp = 0 - refbp = 0 - similarity = 0 - try: - cmd = ["clustalw", "-infile="+tmp1.name, - "-quicktree", "-iteration=none", "-type=DNA"] - print("QC checking similarity to reference") - print(" ".join(cmd)) - result = subprocess.run(cmd, stdout=subprocess.PIPE) - res = result.stdout.decode("utf-8") - g1 = re.search(r"^Sequence 1: [^ ]+ +(\d+) bp$", res, flags=re.MULTILINE) - refbp = float(g1.group(1)) - g2 = re.search(r"^Sequence 2: [^ ]+ +(\d+) bp$", res, flags=re.MULTILINE) - subbp = float(g2.group(1)) - g3 = re.search(r"^Sequences \(1:2\) Aligned\. Score: (\d+(\.\d+)?)$", res, flags=re.MULTILINE) - similarity = float(g3.group(1)) + with tempfile.NamedTemporaryFile() as tmp2: + refstring = pkg_resources.resource_string(__name__, "SARS-CoV-2-reference.fasta") + tmp1.write(refstring) + tmp1.flush() + tmp2.write(submitlabel.encode("utf8")) + tmp2.write(("".join(submitseq)).encode("utf8")) + tmp2.flush() + subbp = 0 + refbp = 0 + similarity = 0 + try: + cmd = ["minimap2", "-c", tmp1.name, tmp2.name] + print("QC checking similarity to reference") + print(" ".join(cmd)) + result = subprocess.run(cmd, stdout=subprocess.PIPE) + res = result.stdout.decode("utf-8") + mm = res.split("\t") + print(mm) + # divide Number of matching bases in the mapping / Target sequence length + similarity = (float(mm[9]) / float(mm[6])) * 100.0 + except Exception as e: + logging.warn("QC against reference sequence using 'minimap2': %s", e) - print(g1.group(0)) - print(g2.group(0)) - print(g3.group(0)) - except Exception as e: - logging.warn("QC against reference sequence using 'clustalw': %s", e) - - if refbp and (subbp/refbp) < .7: - raise ValueError("QC fail: submit sequence length is shorter than 70% reference") - if refbp and (subbp/refbp) > 1.3: - raise ValueError("QC fail: submit sequence length is greater than 130% reference") - if similarity and similarity < 70.0: - raise ValueError("QC fail: submit similarity is less than 70%") - if refbp == 0 or similarity == 0: - raise ValueError("QC fail") + if similarity and similarity < 70.0: + raise ValueError("QC fail: alignment to reference was less than 70%% (was %2.2f%%)" % (similarity)) + if similarity == 0: + raise ValueError("QC fail") return ("sequence.fasta"+gz, seqlabel) elif seq_type == "text/fastq": -- cgit v1.2.3 From 9b1457763c08028179b0987d385d1fe879062b64 Mon Sep 17 00:00:00 2001 From: AndreaGuarracino Date: Tue, 7 Jul 2020 22:07:35 +0200 Subject: if the technology is not found, the YAML file is not created; managed longer species strings --- scripts/create_sra_metadata/create_sra_metadata.py | 5 +- .../ncbi_host_species.csv | 1 + .../from_genbank_to_fasta_and_yaml.py | 114 +++++++++++---------- 3 files changed, 64 insertions(+), 56 deletions(-) diff --git a/scripts/create_sra_metadata/create_sra_metadata.py b/scripts/create_sra_metadata/create_sra_metadata.py index 470980e..ef0d119 100644 --- a/scripts/create_sra_metadata/create_sra_metadata.py +++ b/scripts/create_sra_metadata/create_sra_metadata.py @@ -197,7 +197,6 @@ for i, EXPERIMENT_PACKAGE in enumerate(EXPERIMENT_PACKAGE_SET): if INSTRUMENT_MODEL in term_to_uri_dict: info_for_yaml_dict['technology']['sample_sequencing_technology'] = [term_to_uri_dict[INSTRUMENT_MODEL]] else: - info_for_yaml_dict['technology']['additional_technology_information'] = INSTRUMENT_MODEL missing_value_list.append('\t'.join([accession, 'sample_sequencing_technology', INSTRUMENT_MODEL])) #else: # print(accession, 'Missing INSTRUMENT_MODEL', info_for_yaml_dict) @@ -237,6 +236,10 @@ for i, EXPERIMENT_PACKAGE in enumerate(EXPERIMENT_PACKAGE_SET): info_for_yaml_dict['sample']['collection_date'] = '1970-01-01' info_for_yaml_dict['sample']['additional_collection_information'] = "The real 'collection_date' is missing" + if 'sample_sequencing_technology' not in info_for_yaml_dict['technology']: + print(accession, ' - technology not found') + continue + with open(os.path.join(dir_yaml, '{}.yaml'.format(accession)), 'w') as fw: json.dump(info_for_yaml_dict, fw, indent=2) diff --git a/scripts/dict_ontology_standardization/ncbi_host_species.csv b/scripts/dict_ontology_standardization/ncbi_host_species.csv index bc6ac04..40572a3 100644 --- a/scripts/dict_ontology_standardization/ncbi_host_species.csv +++ b/scripts/dict_ontology_standardization/ncbi_host_species.csv @@ -5,5 +5,6 @@ sapiens,http://purl.obolibrary.org/obo/NCBITaxon_9606 Mustela lutreola,http://purl.obolibrary.org/obo/NCBITaxon_9666 Manis javanica,http://purl.obolibrary.org/obo/NCBITaxon_9974 Felis catus,http://purl.obolibrary.org/obo/NCBITaxon_9685 +Felis catus; Domestic Shorthair,http://purl.obolibrary.org/obo/NCBITaxon_9685 Panthera tigris jacksoni,http://purl.obolibrary.org/obo/NCBITaxon_419130 Canis lupus familiaris,http://purl.obolibrary.org/obo/NCBITaxon_9615 diff --git a/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py b/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py index 7edb1dc..44308ed 100755 --- a/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py +++ b/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py @@ -218,12 +218,12 @@ for path_metadata_xxx_xml in [os.path.join(dir_metadata, name_metadata_xxx_xml) if seq_tec in term_to_uri_dict: seq_tec = term_to_uri_dict[seq_tec] else: - info_for_yaml_dict['technology']['additional_technology_information'] = seq_tec missing_value_list.append('\t'.join([accession_version, 'sample_sequencing_technology', seq_tec])) new_seq_tec_list.append(seq_tec) - info_for_yaml_dict['technology']['sample_sequencing_technology'] = [x for x in new_seq_tec_list] + if len(new_seq_tec_list) > 0: + info_for_yaml_dict['technology']['sample_sequencing_technology'] = [x for x in new_seq_tec_list] else: info_for_yaml_dict['technology'][field_in_yaml] = tech_info_to_parse @@ -241,58 +241,62 @@ for path_metadata_xxx_xml in [os.path.join(dir_metadata, name_metadata_xxx_xml) GBQualifier_name_text = GBQualifier.find('GBQualifier_name').text if GBQualifier_name_text == 'host': - GBQualifier_value_text_list = GBQualifier_value_text.split('; ') - - if GBQualifier_value_text_list[0] in term_to_uri_dict: - info_for_yaml_dict['host']['host_species'] = term_to_uri_dict[GBQualifier_value_text_list[0]] - elif GBQualifier_value_text_list[0] and ('MT215193' in accession_version or 'MT270814' in accession_version): - # Information checked manually from NCBI Virus - info_for_yaml_dict['host']['host_species'] = term_to_uri_dict['Canis lupus familiaris'] + if GBQualifier_value_text in term_to_uri_dict: + # Cases like 'Felis catus; Domestic Shorthair' + info_for_yaml_dict['host']['host_species'] = term_to_uri_dict[GBQualifier_value_text] else: - missing_value_list.append('\t'.join([accession_version, 'host_species', GBQualifier_value_text_list[0]])) - - # Possible cases: - # - Homo sapiens --> ['Homo sapiens'] - # - Homo sapiens; female --> ['Homo sapiens', 'female'] - # - Homo sapiens; female 63 --> ['Homo sapiens', 'female 63'] - # - Homo sapiens; female; age 40 --> ['Homo sapiens', 'female', 'age 40'] - # - Homo sapiens; gender: F; age: 61 --> ['Homo sapiens', 'gender: F', 'age: 61'] - # - Homo sapiens; gender: M; age: 68 --> ['Homo sapiens', 'gender: M', 'age: 68'] - # - Homo sapiens; hospitalized patient --> ['Homo sapiens', 'hospitalized patient'] - # - Homo sapiens; male --> ['Homo sapiens', 'male'] - # - Homo sapiens; male; 63 --> ['Homo sapiens', 'male', '63'] - # - Homo sapiens; male; age 29 --> ['Homo sapiens', 'male', 'age 29'] - # - Homo sapiens; symptomatic --> ['Homo sapiens', 'symptomatic'] - if len(GBQualifier_value_text_list) > 1: - host_sex = '' - if 'female' in GBQualifier_value_text_list[1]: - host_sex = 'female' - elif 'male' in GBQualifier_value_text_list[1]: - host_sex = 'male' - elif 'gender' in GBQualifier_value_text_list[1]: - host_sex_one_lecter = GBQualifier_value_text_list[1].split(':')[-1].strip() - if host_sex_one_lecter in ['F', 'M']: - host_sex = 'female' if host_sex_one_lecter == 'F' else 'male' - - if host_sex in ['male', 'female']: - info_for_yaml_dict['host']['host_sex'] = "http://purl.obolibrary.org/obo/PATO_0000384" if host_sex == 'male' else "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]] + GBQualifier_value_text_list = GBQualifier_value_text.split('; ') + + if GBQualifier_value_text_list[0] in term_to_uri_dict: + info_for_yaml_dict['host']['host_species'] = term_to_uri_dict[GBQualifier_value_text_list[0]] + elif GBQualifier_value_text_list[0] and ('MT215193' in accession_version or 'MT270814' in accession_version): + # Information checked manually from NCBI Virus + info_for_yaml_dict['host']['host_species'] = term_to_uri_dict['Canis lupus familiaris'] else: - missing_value_list.append('\t'.join([accession_version, 'host_sex or host_health_status', GBQualifier_value_text_list[1]])) - - # Host age - host_age = -1 - if len(GBQualifier_value_text_list[1].split(' ')) > 1 and is_integer(GBQualifier_value_text_list[1].split(' ')[-1]): - host_age = int(GBQualifier_value_text_list[1].split(' ')[-1]) - elif len(GBQualifier_value_text_list) > 2 and is_integer(GBQualifier_value_text_list[2].split(' ')[-1]): - host_age = int(GBQualifier_value_text_list[2].split(' ')[-1]) - - if host_age > -1: - info_for_yaml_dict['host']['host_age'] = host_age - info_for_yaml_dict['host']['host_age_unit'] = 'http://purl.obolibrary.org/obo/UO_0000036' - elif len(GBQualifier_value_text_list) > 2: - missing_value_list.append('\t'.join([accession_version, 'host_age', GBQualifier_value_text_list[2]])) + missing_value_list.append('\t'.join([accession_version, 'host_species', GBQualifier_value_text_list[0]])) + + # Possible cases: + # - Homo sapiens --> ['Homo sapiens'] + # - Homo sapiens; female --> ['Homo sapiens', 'female'] + # - Homo sapiens; female 63 --> ['Homo sapiens', 'female 63'] + # - Homo sapiens; female; age 40 --> ['Homo sapiens', 'female', 'age 40'] + # - Homo sapiens; gender: F; age: 61 --> ['Homo sapiens', 'gender: F', 'age: 61'] + # - Homo sapiens; gender: M; age: 68 --> ['Homo sapiens', 'gender: M', 'age: 68'] + # - Homo sapiens; hospitalized patient --> ['Homo sapiens', 'hospitalized patient'] + # - Homo sapiens; male --> ['Homo sapiens', 'male'] + # - Homo sapiens; male; 63 --> ['Homo sapiens', 'male', '63'] + # - Homo sapiens; male; age 29 --> ['Homo sapiens', 'male', 'age 29'] + # - Homo sapiens; symptomatic --> ['Homo sapiens', 'symptomatic'] + if len(GBQualifier_value_text_list) > 1: + host_sex = '' + if 'female' in GBQualifier_value_text_list[1]: + host_sex = 'female' + elif 'male' in GBQualifier_value_text_list[1]: + host_sex = 'male' + elif 'gender' in GBQualifier_value_text_list[1]: + host_sex_one_lecter = GBQualifier_value_text_list[1].split(':')[-1].strip() + if host_sex_one_lecter in ['F', 'M']: + host_sex = 'female' if host_sex_one_lecter == 'F' else 'male' + + if host_sex in ['male', 'female']: + info_for_yaml_dict['host']['host_sex'] = "http://purl.obolibrary.org/obo/PATO_0000384" if host_sex == 'male' else "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: + missing_value_list.append('\t'.join([accession_version, 'host_sex or host_health_status', GBQualifier_value_text_list[1]])) + + # Host age + host_age = -1 + if len(GBQualifier_value_text_list[1].split(' ')) > 1 and is_integer(GBQualifier_value_text_list[1].split(' ')[-1]): + host_age = int(GBQualifier_value_text_list[1].split(' ')[-1]) + elif len(GBQualifier_value_text_list) > 2 and is_integer(GBQualifier_value_text_list[2].split(' ')[-1]): + host_age = int(GBQualifier_value_text_list[2].split(' ')[-1]) + + if host_age > -1: + info_for_yaml_dict['host']['host_age'] = host_age + info_for_yaml_dict['host']['host_age_unit'] = 'http://purl.obolibrary.org/obo/UO_0000036' + elif len(GBQualifier_value_text_list) > 2: + missing_value_list.append('\t'.join([accession_version, 'host_age', GBQualifier_value_text_list[2]])) 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 @@ -365,9 +369,9 @@ for path_metadata_xxx_xml in [os.path.join(dir_metadata, name_metadata_xxx_xml) 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'] + if 'sample_sequencing_technology' not in info_for_yaml_dict['technology']: + print(accession_version, ' - technology not found') + continue 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())) -- cgit v1.2.3 From 54e0ce85ef3abafb8870ef5a9244a03f16b5e3f5 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 7 Jul 2020 20:41:11 +0000 Subject: minimap2 returns nothing when there is no alignment. --- bh20sequploader/qc_fasta.py | 15 +++++++++------ scripts/docker/Dockerfile | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bh20sequploader/qc_fasta.py b/bh20sequploader/qc_fasta.py index b08333e..37eb4e8 100644 --- a/bh20sequploader/qc_fasta.py +++ b/bh20sequploader/qc_fasta.py @@ -70,16 +70,19 @@ def qc_fasta(arg_sequence, check_with_clustalw=True): similarity = 0 try: cmd = ["minimap2", "-c", tmp1.name, tmp2.name] - print("QC checking similarity to reference") - print(" ".join(cmd)) + logging.info("QC checking similarity to reference") + logging.info(" ".join(cmd)) result = subprocess.run(cmd, stdout=subprocess.PIPE) + result.check_returncode() res = result.stdout.decode("utf-8") mm = res.split("\t") - print(mm) - # divide Number of matching bases in the mapping / Target sequence length - similarity = (float(mm[9]) / float(mm[6])) * 100.0 + if len(mm) >= 10: + # divide Number of matching bases in the mapping / Target sequence length + similarity = (float(mm[9]) / float(mm[6])) * 100.0 + else: + similarity = 0 except Exception as e: - logging.warn("QC against reference sequence using 'minimap2': %s", e) + logging.warn("QC against reference sequence using 'minimap2': %s", e, exc_info=e) if similarity and similarity < 70.0: raise ValueError("QC fail: alignment to reference was less than 70%% (was %2.2f%%)" % (similarity)) diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile index 8811927..02829d4 100644 --- a/scripts/docker/Dockerfile +++ b/scripts/docker/Dockerfile @@ -3,7 +3,7 @@ FROM debian:10 RUN apt-get update && \ apt-get -yq --no-install-recommends -o Acquire::Retries=6 install \ python3 python3-pip python3-setuptools python3-dev python-pycurl \ - clustalw python3-biopython libcurl4-openssl-dev build-essential \ + minimap2 python3-biopython libcurl4-openssl-dev build-essential \ libssl-dev libmagic-dev python3-magic && \ apt-get clean -- cgit v1.2.3 From f77e86dbb84baf8add3d7a71f8f06fb44a99507b Mon Sep 17 00:00:00 2001 From: AndreaGuarracino Date: Tue, 7 Jul 2020 23:01:48 +0200 Subject: fix missing authors #91 --- scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py b/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py index 44308ed..cb94787 100755 --- a/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py +++ b/scripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py @@ -173,7 +173,9 @@ for path_metadata_xxx_xml in [os.path.join(dir_metadata, name_metadata_xxx_xml) # submitter info GBSeq_references = GBSeq.find('GBSeq_references') if GBSeq_references is not None: - info_for_yaml_dict['submitter']['authors'] = ["{}".format(x.text) for x in GBSeq_references.iter('GBAuthor')] + author_list = ["{}".format(x.text) for x in GBSeq_references.iter('GBAuthor')] + if len(author_list) > 0: + info_for_yaml_dict['submitter']['authors'] = author_list GBReference = GBSeq_references.find('GBReference') if GBReference is not None: -- cgit v1.2.3 From ba38aaf6920b246f6644cfb49730a5e2ee5f9db0 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 7 Jul 2020 17:17:31 -0400 Subject: --print-status=html creates html report --- bh20seqanalyzer/main.py | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/bh20seqanalyzer/main.py b/bh20seqanalyzer/main.py index 2fefa86..1746587 100644 --- a/bh20seqanalyzer/main.py +++ b/bh20seqanalyzer/main.py @@ -235,9 +235,10 @@ def upload_schema(api, workflow_def_project): return "keep:%s/schema.yml" % pdh -def print_status(api, uploader_project): +def print_status(api, uploader_project, fmt): pending = arvados.util.list_all(api.collections().list, filters=[["owner_uuid", "=", uploader_project]]) out = [] + status = {} for p in pending: prop = p["properties"] out.append(prop) @@ -245,7 +246,38 @@ def print_status(api, uploader_project): prop["status"] = "pending" prop["created_at"] = p["created_at"] prop["uuid"] = p["uuid"] - print(json.dumps(out, indent=2)) + status[prop["status"]] = status.get(prop["status"], 0) + 1 + if fmt == "html": + print( +""" + + +""") + print("

Total collections in upload project %s

" % len(out)) + print("

Status %s

" % status) + print( +""" + + + + + +""") + for r in out: + print("") + print("" % (r["uuid"], r["uuid"])) + print("" % r["sequence_label"]) + print("" % r["status"]) + print("" % "\n".join(r.get("errors", []))) + print("") + print( +""" +
CollectionSequence labelStatusErrors
%s%s%s
%s
+ + +""") + else: + print(json.dumps(out, indent=2)) def main(): parser = argparse.ArgumentParser(description='Analyze collections uploaded to a project') @@ -264,7 +296,7 @@ def main(): parser.add_argument('--kickoff', action="store_true") parser.add_argument('--no-start-analysis', action="store_true") parser.add_argument('--once', action="store_true") - parser.add_argument('--print-status', action="store_true") + parser.add_argument('--print-status', type=str, default=None) args = parser.parse_args() api = arvados.api() @@ -284,7 +316,7 @@ def main(): return if args.print_status: - print_status(api, args.uploader_project) + print_status(api, args.uploader_project, args.print_status) exit(0) logging.info("Starting up, monitoring %s for uploads" % (args.uploader_project)) -- cgit v1.2.3