forked from MIRRI/mirri_utils
update mirri folder
This commit is contained in:
@@ -37,14 +37,14 @@ TRUEFALSE_TRANSLATOR = {
|
||||
}
|
||||
|
||||
|
||||
def parse_mirri_excel(fhand, version="20200601"):
|
||||
if version == "20200601":
|
||||
return _parse_mirri_v20200601(fhand)
|
||||
def parse_mirri_excel(fhand, version=""):
|
||||
if version == "5.1.2":
|
||||
return _parse_mirri_v12052023(fhand)
|
||||
else:
|
||||
raise NotImplementedError("Only version 20200601 is implemented")
|
||||
raise NotImplementedError("Only version is 5.1.2 implemented")
|
||||
|
||||
|
||||
def _parse_mirri_v20200601(fhand):
|
||||
def _parse_mirri_v12052023(fhand):
|
||||
fhand.seek(0)
|
||||
file_content = BytesIO(fhand.read())
|
||||
wb = load_workbook(filename=file_content, read_only=True, data_only=True)
|
||||
@@ -64,7 +64,6 @@ def _parse_mirri_v20200601(fhand):
|
||||
|
||||
return {"strains": strains, "growth_media": growth_media}
|
||||
|
||||
|
||||
def index_list_by(list_, id_):
|
||||
return {str(item[id_]): item for item in list_}
|
||||
|
||||
@@ -125,7 +124,7 @@ def parse_strains(wb, locations, growth_media, markers, publications,
|
||||
publications = index_list_by_attr(publications, 'id')
|
||||
markers = index_markers(markers)
|
||||
|
||||
for strain_row in workbook_sheet_reader(wb, STRAINS, "Accession number"):
|
||||
for strain_row in workbook_sheet_reader(wb, STRAINS, "accessionNumber"):
|
||||
strain = StrainMirri()
|
||||
strain_id = None
|
||||
label = None
|
||||
@@ -140,7 +139,7 @@ def parse_strains(wb, locations, growth_media, markers, publications,
|
||||
collection, number = value.split(" ", 1)
|
||||
value = StrainId(collection=collection, number=number)
|
||||
rsetattr(strain, attribute, value)
|
||||
|
||||
|
||||
elif attribute == "restriction_on_use":
|
||||
rsetattr(strain, attribute, RESTRICTION_USE_TRANSLATOR[value])
|
||||
elif attribute == "nagoya_protocol":
|
||||
@@ -202,9 +201,19 @@ def parse_strains(wb, locations, growth_media, markers, publications,
|
||||
items = value.split(";")
|
||||
strain.collect.location.latitude = float(items[0])
|
||||
strain.collect.location.longitude = float(items[1])
|
||||
strain.collect.location.precision = float(items[2])
|
||||
strain.collect.location.altitude = float(items[3])
|
||||
if len(items) > 4:
|
||||
strain.collect.location.coord_uncertainty = items[4]
|
||||
|
||||
elif attribute == "collect.site.links":
|
||||
items = value.split(";")
|
||||
strain.collect.site.links.nameSite = str(items[0])
|
||||
strain.collect.site.links.urlSite = str(items[1])
|
||||
rsetattr(strain, attribute, value.split(";")) #ver o separador
|
||||
if len(items) > 2:
|
||||
strain.collect.location.coord_uncertainty = items[2]
|
||||
|
||||
strain.collect.site.links.site_uncertainty = items[2]
|
||||
|
||||
elif attribute == "collect.location":
|
||||
location = locations[value]
|
||||
if 'Country' in location and location['Country']:
|
||||
|
||||
@@ -50,11 +50,10 @@ PUB_HEADERS = [pb["label"] for pb in PUBLICATION_FIELDS]
|
||||
|
||||
|
||||
def write_mirri_excel(path, strains, growth_media, version):
|
||||
if version == "20200601":
|
||||
_write_mirri_excel_20200601(path, strains, growth_media)
|
||||
if version == "5.1.2":
|
||||
_write_mirri_excel_12052023(path, strains, growth_media)
|
||||
|
||||
|
||||
def _write_mirri_excel_20200601(path, strains, growth_media):
|
||||
def _write_mirri_excel_12052023(path, strains, growth_media):
|
||||
wb = Workbook()
|
||||
|
||||
write_markers_sheet(wb)
|
||||
@@ -104,7 +103,7 @@ def _write_mirri_excel_20200601(path, strains, growth_media):
|
||||
redimension_cell_width(pub_sheet)
|
||||
|
||||
# write sexual states
|
||||
sex_sheet = wb.create_sheet("Sexual states")
|
||||
sex_sheet = wb.create_sheet("Sexual state")
|
||||
for sex_state in sorted(list(sexual_states)):
|
||||
sex_sheet.append([sex_state])
|
||||
redimension_cell_width(sex_sheet)
|
||||
@@ -121,7 +120,6 @@ def _write_mirri_excel_20200601(path, strains, growth_media):
|
||||
del wb["Sheet"]
|
||||
wb.save(str(path))
|
||||
|
||||
|
||||
def _deserialize_strains(strains, locations, growth_media_indexes,
|
||||
publications, sexual_states, genomic_markers):
|
||||
for strain in strains:
|
||||
@@ -189,10 +187,21 @@ def _deserialize_strains(strains, locations, growth_media_indexes,
|
||||
elif attribute == "collect.location.coords":
|
||||
lat = strain.collect.location.latitude
|
||||
long = strain.collect.location.longitude
|
||||
if lat is not None and long is not None:
|
||||
value = f"{lat};{long}"
|
||||
alt = strain.collect.location.altitude
|
||||
prec = strain.collect.location.precision
|
||||
if lat is not None and long is not None and prec is not None and alt is not None:
|
||||
value = f"{lat};{long};{prec};{alt}"
|
||||
else:
|
||||
value = None
|
||||
value = None
|
||||
elif attribute == "collect.site.links":
|
||||
name = strain.collect.site.links.nameSite
|
||||
url = strain.collect.site.links.urlSite
|
||||
value = rgetattr(strain, attribute)
|
||||
value = ";".join(value)
|
||||
if name is not None and url is not None:
|
||||
value = f"{name};{url}"
|
||||
else:
|
||||
value = None
|
||||
|
||||
elif attribute == "collect.location":
|
||||
location = strain.collect.location
|
||||
|
||||
Reference in New Issue
Block a user