Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated the converter.py #144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added .github/.DS_Store
Binary file not shown.
Binary file added excel2sbol/.DS_Store
Binary file not shown.
Binary file added excel2sbol/excel2sbol/.DS_Store
Binary file not shown.
53 changes: 52 additions & 1 deletion excel2sbol/excel2sbol/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,53 @@

# the homespace only works if the change is made to pysbol2 shown in https://github.com/SynBioDex/pySBOL2/pull/411/files

def initialise_welcome(file_path_in):
init_info = pd.read_excel(file_path_in, sheet_name="Init",
skiprows=9, index_col=0,
engine='openpyxl')
init_info = init_info.applymap(lambda x: x.strip() if isinstance(x, str) else x).to_dict('index')

version_info = pd.read_excel(file_path_in, sheet_name="Init",
nrows=4, index_col=0, header=None,
engine='openpyxl')
version_info = version_info.applymap(lambda x: x.strip() if isinstance(x, str) else x).to_dict('index')
if 'Homespace' in version_info:
homespace = version_info['Homespace'][1]
else:
homespace = ""
version_info = version_info['SBOL Version'][1]

# For key in dict read in sheet,
# if sheet convert = true, add to convert list
compiled_sheets = {}
to_convert = []
for sheet_name, val in init_info.items():
# print(f"reading in {sheet_name}...")
# MY CODE
if sheet_name.lower() == "welcome":
print("Processing the welcome page...")
try:
welcome_metadata = pd.read_excel(file_path_in, sheet_name=sheet_name,
index_col=0, engine='openpyxl').fillna("")
print("Welcome Page Metadata:")

dict = {}
for _, row in welcome_metadata.iterrows():
if len(row) >= 2:
key, value = row[0], row[1]
if isinstance(key, str) and key.strip():
dict[key.strip()] = value.strip() if isinstance(value, str) else value
for key, value in dict.items():
print(f"{key}: {value}")
return dict

except Exception as e:
print(f"Error reading the welcome page: {e}")
return None

else:
return

def initialise(file_path_in):
init_info = pd.read_excel(file_path_in, sheet_name="Init",
skiprows=9, index_col=0,
Expand All @@ -33,6 +79,11 @@ def initialise(file_path_in):
to_convert = []
for sheet_name, val in init_info.items():
# print(f"reading in {sheet_name}...")
# MY CODE
if sheet_name.lower() == "welcome":
continue
# MY CODE

convert = val['Convert']

if convert:
Expand Down Expand Up @@ -390,4 +441,4 @@ def column_parse(to_convert, compiled_sheets, sht_convert_dict, dict_of_objs,
else:
doc.write(file_path_out, file_format = file_format)

return
return
21 changes: 19 additions & 2 deletions excel2sbol/excel2sbol/converter.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
# from ensurepip import version
import excel2sbol.compiler as e2s
import os
import json
from datetime import datetime


def converter(file_path_in, file_path_out, sbol_version=3, homespace="http://examples.org/", file_format=None):
def converter(file_path_in, file_path_out, sbol_version=3, homespace="http://examples.org/", file_format=None, username=None, password=None, url = None):
"""Convert a given excel file to SBOL

Args:
file_path_in (string): path to excel file
file_path_out (string): desired path to sbol file
sbol_version (int): sbol version number, defaults to 3
"""
if username is not None and password is not None and url is not None:
# print(username, password, url)
os.environ["SBOL_USERNAME"] = username
os.environ["SBOL_PASSWORD"] = password
os.environ["SBOL_URL"] = url

col_read_df, to_convert, compiled_sheets, version_info, homespace2 = e2s.initialise(file_path_in)
dict = e2s.initialise_welcome(file_path_in)
for key, value in dict.items():
if isinstance(value, datetime):
dict[key] = value.isoformat()
if dict is not None:
os.environ["SBOL_DICTIONARY"] = json.dumps(dict)
# print(dict)

if len(homespace2) > 0:
homespace = homespace2
Expand All @@ -33,3 +48,5 @@ def converter(file_path_in, file_path_out, sbol_version=3, homespace="http://exa
e2s.column_parse(to_convert, compiled_sheets, sht_convert_dict,
dict_of_objs, col_read_df, doc, file_path_out,
sbol_version=sbol_version, file_format=file_format)


Binary file added excel2sbol/resources/.DS_Store
Binary file not shown.
Binary file added excel2sbol/tests/.DS_Store
Binary file not shown.
Loading