aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAndreaGuarracino2020-07-07 22:07:35 +0200
committerAndreaGuarracino2020-07-07 22:07:35 +0200
commit9b1457763c08028179b0987d385d1fe879062b64 (patch)
tree081fb21af3deb27160e23f35a1b3cb968f36b87f /scripts
parent4e2ac9bdef97175f5d762c6e7f065a83512a3c40 (diff)
downloadbh20-seq-resource-9b1457763c08028179b0987d385d1fe879062b64.tar.gz
bh20-seq-resource-9b1457763c08028179b0987d385d1fe879062b64.tar.lz
bh20-seq-resource-9b1457763c08028179b0987d385d1fe879062b64.zip
if the technology is not found, the YAML file is not created; managed longer species strings
Diffstat (limited to 'scripts')
-rw-r--r--scripts/create_sra_metadata/create_sra_metadata.py5
-rw-r--r--scripts/dict_ontology_standardization/ncbi_host_species.csv1
-rwxr-xr-xscripts/download_genbank_data/from_genbank_to_fasta_and_yaml.py114
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()))