forked from MIRRI/mirri_utils
18-07
This commit is contained in:
@@ -5,7 +5,6 @@ from openpyxl.workbook.workbook import Workbook
|
||||
|
||||
from mirri import rgetattr
|
||||
from mirri.settings import GROWTH_MEDIA, MIRRI_FIELDS, DATA_DIR, PUBLICATION_FIELDS
|
||||
from mirri.settings_v1 import GROWTH_MEDIA, MIRRI_FIELDS, DATA_DIR, PUBLICATION_FIELDS
|
||||
from mirri.io.parsers.mirri_excel import NAGOYA_TRANSLATOR, RESTRICTION_USE_TRANSLATOR
|
||||
|
||||
INITIAL_SEXUAL_STATES = [
|
||||
@@ -51,81 +50,9 @@ 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 == "12052023":
|
||||
if version == "5.1.2":
|
||||
_write_mirri_excel_12052023(path, strains, growth_media)
|
||||
|
||||
|
||||
def _write_mirri_excel_20200601(path, strains, growth_media):
|
||||
wb = Workbook()
|
||||
|
||||
write_markers_sheet(wb)
|
||||
|
||||
ontobiotope_path = DATA_DIR / "ontobiotopes.csv"
|
||||
write_ontobiotopes(wb, ontobiotope_path)
|
||||
|
||||
write_growth_media(wb, growth_media)
|
||||
growth_media_indexes = [str(gm.acronym) for gm in growth_media]
|
||||
|
||||
locations = {}
|
||||
publications = {}
|
||||
sexual_states = set(deepcopy(INITIAL_SEXUAL_STATES))
|
||||
genomic_markers = {}
|
||||
strains_data = _deserialize_strains(strains, locations, growth_media_indexes,
|
||||
publications, sexual_states, genomic_markers)
|
||||
strains_data = list(strains_data)
|
||||
|
||||
# write strain to generate indexed data
|
||||
strain_sheet = wb.create_sheet("Strains")
|
||||
strain_sheet.append([field["label"] for field in MIRRI_FIELDS])
|
||||
for strain_row in strains_data:
|
||||
strain_sheet.append(strain_row)
|
||||
redimension_cell_width(strain_sheet)
|
||||
|
||||
# write locations
|
||||
loc_sheet = wb.create_sheet("Geographic origin")
|
||||
loc_sheet.append(["ID", "Country", "Region", "City", "Locality"])
|
||||
for index, loc_index in enumerate(locations.keys()):
|
||||
location = locations[loc_index]
|
||||
row = [index, location.country, location.state, location.municipality,
|
||||
loc_index]
|
||||
loc_sheet.append(row)
|
||||
redimension_cell_width(loc_sheet)
|
||||
|
||||
# write publications
|
||||
pub_sheet = wb.create_sheet("Literature")
|
||||
pub_sheet.append(PUB_HEADERS)
|
||||
for publication in publications.values():
|
||||
row = []
|
||||
for pub_field in PUBLICATION_FIELDS:
|
||||
# if pub_field['attribute'] == 'id':
|
||||
# value = index
|
||||
value = getattr(publication, pub_field['attribute'], None)
|
||||
row.append(value)
|
||||
pub_sheet.append(row)
|
||||
redimension_cell_width(pub_sheet)
|
||||
|
||||
# write 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)
|
||||
|
||||
# write genetic markers
|
||||
markers_sheet = wb.create_sheet("Genomic information")
|
||||
markers_sheet.append(['Strain AN', 'Marker', 'INSDC AN', 'Sequence'])
|
||||
for strain_id, markers in genomic_markers.items():
|
||||
for marker in markers:
|
||||
row = [strain_id, marker.marker_type, marker.marker_id, marker.marker_seq]
|
||||
markers_sheet.append(row)
|
||||
redimension_cell_width(markers_sheet)
|
||||
|
||||
del wb["Sheet"]
|
||||
wb.save(str(path))
|
||||
|
||||
|
||||
def _write_mirri_excel_12052023(path, strains, growth_media):
|
||||
wb = Workbook()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user