diff options
author | LLTommy | 2020-04-23 20:18:36 +0200 |
---|---|---|
committer | GitHub | 2020-04-23 20:18:36 +0200 |
commit | 7049cd5d29acd601ccbbc9d04f001b84a51e9bd5 (patch) | |
tree | 34a1254d81c2e526427fedb1deaa9f8441e8b260 /scripts | |
parent | f38b9c6f22b82327df9648938a5a4bcf863d8c41 (diff) | |
parent | c7612e7eda5cd38bfbb2d293bebf732893a41b6c (diff) | |
download | bh20-seq-resource-7049cd5d29acd601ccbbc9d04f001b84a51e9bd5.tar.gz bh20-seq-resource-7049cd5d29acd601ccbbc9d04f001b84a51e9bd5.tar.lz bh20-seq-resource-7049cd5d29acd601ccbbc9d04f001b84a51e9bd5.zip |
Merge branch 'master' into patch-3
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/dict_ontology_standardization/ncbi_countries.csv | 2 | ||||
-rw-r--r-- | scripts/dict_ontology_standardization/ncbi_host_health_status.csv | 8 | ||||
-rw-r--r-- | scripts/dict_ontology_standardization/ncbi_speciesman_source.csv | 5 | ||||
-rwxr-xr-x | scripts/foreach.sh | 18 | ||||
-rwxr-xr-x[-rw-r--r--] | scripts/from_genbank_to_fasta_and_yaml.py | 349 | ||||
-rw-r--r-- | scripts/sequences.acc | 121 |
6 files changed, 345 insertions, 158 deletions
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 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 diff --git a/scripts/dict_ontology_standardization/ncbi_speciesman_source.csv b/scripts/dict_ontology_standardization/ncbi_speciesman_source.csv index 2905588..8278c90 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 @@ -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 diff --git a/scripts/foreach.sh b/scripts/foreach.sh new file mode 100755 index 0000000..ddc9387 --- /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/ -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 index 0c410d7..f76cb29 100644..100755 --- a/scripts/from_genbank_to_fasta_and_yaml.py +++ b/scripts/from_genbank_to_fasta_and_yaml.py @@ -1,59 +1,59 @@ +#!/usr/bin/env python3 + 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 +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] - - print(term, len(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'] - id_set.update([x.split('.')[0] for x in tmp_list]) + # 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']] -print(term_list, len(id_set)) + # Remove the version in the id + tmp_list = [x.split('.')[0] for x in tmp_list] -with open(path_ncbi_virus_accession) as f: - tmp_list = [line.strip('\n') for line in f] + print(term, len(tmp_list)) + tmp_list=tmp_list + # tmp_list = tmp_list[0:2] # restricting to small run -print('NCBI Virus', len(tmp_list)) -id_set.update(tmp_list) + id_set.update([x.split('.')[0] for x in tmp_list]) -print(term_list + ['NCBI Virus'], len(id_set)) + print(term_list, len(id_set)) + + with open(path_ncbi_virus_accession) as f: + tmp_list = [line.strip('\n') for line in f] + + print('NCBI Virus', len(tmp_list)) + id_set.update(tmp_list) + + 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)) + 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: @@ -61,7 +61,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')]: @@ -72,144 +72,181 @@ 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 species_to_taxid_dict = { - 'Homo sapiens': 9606 + 'Homo sapiens': 'http://purl.obolibrary.org/obo/NCBITaxon_9606' } -if not os.path.exists(dir_fasta_and_yaml_today): - os.makedirs(dir_fasta_and_yaml_today) +if not os.path.exists(dir_fasta_and_yaml): + os.makedirs(dir_fasta_and_yaml) - 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() +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])) - for GBSeq in GBSet: - accession_version = GBSeq.find('GBSeq_accession-version').text + new_seq_tec_list.append(seq_tec) - GBSeq_sequence = GBSeq.find('GBSeq_sequence') - if GBSeq_sequence is None: - print(accession_version, ' - sequence not found') - continue + 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['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! - 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(';')] - ) - 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] + #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']: - info_for_yaml_dict['host']['host_sex'] = GBQualifier_value_text_list[1] - 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'] = int(GBQualifier_value_text.split('taxon:')[1]) - - 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) + #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)) 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 |