Skip to content

Commit e7b32b8

Browse files
Merge pull request #164 from SynBioDex/test-branch
Fixed pytests
2 parents f54eecc + 0f27742 commit e7b32b8

36 files changed

+1308
-720
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ jobs:
4141
run: |
4242
python -m pip install -e .
4343
python -m pytest -vv -s
44-
# python -m unittest discover -s tests
44+
python -m unittest discover -s tests

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Excel-to-SBOL
22

3-
**Excel-to-SBOL** is an open source python library that converts [Excel Templates](https://github.com/SynBioDex/Excel-to-SBOL/tree/master/excel2sbol/resources/templates) to [SBOL](https://sbolstandard.org/) documents.
3+
**Excel-to-SBOL** is an open source python library that converts [Excel Templates](https://github.com/SynBioDex/Excel-to-SBOL/tree/master/resources/templates) to [SBOL](https://sbolstandard.org/) documents.
44

55
A similar utility developed for SBOL3 support (developed by Jake Beal) is in [SBOL-utilities](https://github.com/SynBioDex/SBOL-utilities).
66

@@ -31,7 +31,7 @@ To get the latest version you can use `git clone https://github.com/SynBioDex/Ex
3131
## How to use
3232

3333
**1) Choose an Excel Template**
34-
Choose an excel template from the [templates folder](https://github.com/SynBioDex/Excel-to-SBOL/tree/master/excel2sbol/resources/templates).
34+
Choose an excel template from the [templates folder](https://github.com/SynBioDex/Excel-to-SBOL/tree/master/resources/templates).
3535
We suggest choosing the latest version. Fill out the template as the instructions indicate.
3636

3737
**2) Install the Converter**
@@ -43,7 +43,7 @@ The following script asks the user for the name of the input file, version of SB
4343

4444
If you want to use the tool in offline mode for a custom SynBioHub instance, leave the "Domain" field empty on the spreadsheet "Welcome page".
4545

46-
[Converter File](https://github.com/SynBioDex/Excel-to-SBOL/blob/master/excel2sbol/tests/test_files/Excel2SBOLConverter.py)
46+
[Converter File](https://github.com/SynBioDex/Excel-to-SBOL/blob/master/resources/Excel2SBOLConverter.py)
4747

4848
Tip: the use of `os.getcwd()` and `os.path.join` is recommended for the creation of the file paths. This is safer from a cybersecurity stand point and provide better operating system interoperability.
4949

@@ -52,7 +52,7 @@ The SBOL file that is output can then be used by further [SBOL tools](https://sb
5252

5353
# Example Conversion
5454

55-
A data-filled [spreadsheet](https://github.com/SynBioDex/Excel-to-SBOL/blob/master/excel2sbol/resources/templates/Sample_template_Excel2SBOL.xlsm) was converted to an [SBOL file](https://github.com/SynBioDex/Excel-to-SBOL/blob/master/excel2sbol/resources/templates/Sample_template_Excel2SBOL.xml).
55+
A data-filled [spreadsheet](https://github.com/SynBioDex/Excel-to-SBOL/blob/master/resources/templates/Sample_template_Excel2SBOL.xlsm) was converted to an [SBOL file](https://github.com/SynBioDex/Excel-to-SBOL/blob/master/resources/templates/Sample_template_Excel2SBOL.xml).
5656

5757
**Example Spreadsheet**
5858
![Example Spreadsheet](https://github.com/SynBioDex/Excel-to-SBOL/blob/master/images/sample_template.png)
@@ -74,6 +74,10 @@ Alternatively you can also make changes to the package and then use it locally:
7474
1. Clone the directory: `git clone https://github.com/SynBioDex/Excel-to-SBOL`
7575
2. Change to the excel2sbol folder:
7676

77-
cd ./Excel_to_SBOL/excel2sbol
77+
cd ./Excel_to_SBOL/src/excel2sbol
7878

7979
3. Install an editable version of the package: `python -m pip install -e .` (will overwrite the directory in site-packages with a symbolic link to the locations repository). If a virtual environment is being used the python -m can be left off.
80+
81+
# Excel2SBOL Paper
82+
83+
An updated version of the Excel template referenced in the paper [Excel–SBOL Converter: Creating SBOL from Excel Templates and Vice Versa](https://pubs.acs.org/doi/full/10.1021/acssynbio.2c00521) can be found [here](https://github.com/SynBioDex/Excel-to-SBOL/blob/master/tests/test_files/sb2c00521_si_001.xlsx).

src/excel2sbol/compiler.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def initialise(file_path_in):
130130
lib_df = pd.read_excel(file_path_in, sheet_name=sheet_name,
131131
header=0, skiprows=skipval,
132132
engine='openpyxl').fillna("")
133+
133134
sheet_dict['library'] = lib_df.applymap(lambda x: x.strip() if isinstance(x, str) else x).to_dict('list')
134135

135136
# need dicitonary with as keys every column name and as values a list of values (note ordered list and need place holder empty values)
@@ -182,7 +183,10 @@ def parse_objects(col_read_df, to_convert, compiled_sheets,
182183

183184
sbol2.Config.setOption(sbol2.ConfigOptions.SBOL_COMPLIANT_URIS, True)
184185
sbol2.Config.setOption(sbol2.ConfigOptions.SBOL_TYPED_URIS, False)
185-
186+
# print("[DEBUG]")
187+
# print(compiled_sheets)
188+
189+
186190
for sht in to_convert:
187191
sht_df = col_read_df.loc[col_read_df['Sheet Name'] == sht]
188192

@@ -197,6 +201,7 @@ def parse_objects(col_read_df, to_convert, compiled_sheets,
197201
raise KeyError(f'The sheet "{sht}" has no column with sbol_objectType as type. Thus the following error was raised: {e}')
198202

199203
sht_convert_dict[sht] = dis_name_col
204+
200205
ids = compiled_sheets[sht]['library'][dis_name_col]
201206
types = compiled_sheets[sht]['library'][obj_type_col]
202207

@@ -272,7 +277,10 @@ def parse_objects3(col_read_df, to_convert, compiled_sheets,
272277
mol_types = None
273278

274279
sht_convert_dict[sht] = dis_name_col
280+
275281
ids = compiled_sheets[sht]['library'][dis_name_col]
282+
283+
276284
obj_types = compiled_sheets[sht]['library'][obj_type_col]
277285

278286
for ind, id in enumerate(ids):
@@ -400,7 +408,9 @@ def column_parse(to_convert, compiled_sheets, sht_convert_dict, dict_of_objs,
400408
# the sbol_term of the column
401409
# This creates an object with the converted cell values
402410
# hierarchy: sbol term, multicolumn, column name, cell val
411+
403412
mcol = col_convert_df['Multicolumn'].values[0]
413+
404414
sbol_term = col_convert_df['SBOL Term'].values[0]
405415

406416
if hasattr(term_dict, sbol_term):

src/excel2sbol/converter.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ def converter(file_path_in, file_path_out, sbol_version=3, homespace="http://exa
2020

2121
col_read_df, to_convert, compiled_sheets, version_info, homespace2 = e2s.initialise(file_path_in)
2222
dict = e2s.initialise_welcome(file_path_in)
23-
for key, value in dict.items():
24-
if isinstance(value, datetime):
25-
dict[key] = value.isoformat()
23+
# for key, value in dict.items():
24+
# if isinstance(value, datetime):
25+
# dict[key] = value.isoformat()
2626
if dict is not None:
27+
for key, value in dict.items():
28+
if isinstance(value, datetime):
29+
dict[key] = value.isoformat()
2730
os.environ["SBOL_DICTIONARY"] = json.dumps(dict)
2831
# print(dict)
2932

src/excel2sbol/library2.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ def displayId(rowobj):
216216
password = os.getenv("SBOL_PASSWORD")
217217

218218
dict = os.getenv("SBOL_DICTIONARY")
219+
if dict is None:
220+
# print("No welcome page provided. Returning")
221+
return
219222
data = json.loads(dict)
220223
url = data["Domain"].strip()
221224
if url.endswith('/'):
@@ -496,8 +499,8 @@ def encodesFor(rowobj):
496499
password = os.getenv("SBOL_PASSWORD")
497500
url = os.getenv("SBOL_URL")
498501
# print(rowobj.col_cell_dict)
499-
dict = os.getenv("SBOL_DICTIONARY")
500-
data = json.loads(dict)
502+
# dict = os.getenv("SBOL_DICTIONARY")
503+
# data = json.loads(dict)
501504

502505

503506
for col in rowobj.col_cell_dict.keys():
@@ -928,8 +931,11 @@ def sequence(rowobj):
928931
username = os.getenv("SBOL_USERNAME")
929932
password = os.getenv("SBOL_PASSWORD")
930933
url = os.getenv("SBOL_URL")
931-
dict = os.getenv("SBOL_DICTIONARY")
932-
data = json.loads(dict)
934+
dict_env = os.getenv("SBOL_DICTIONARY")
935+
data = None
936+
if dict_env is not None:
937+
data = json.loads(dict_env)
938+
933939

934940
if isinstance(val, str):
935941
# might need to be careful if the object type is sequence!
@@ -957,7 +963,7 @@ def sequence(rowobj):
957963
# if data["Domain"].strip() == "":
958964
# # print("Domain not provided. Proceding without checking the domain for duplicate sequences.")
959965
# return
960-
if data["Domain"].strip() != "":
966+
if data and data["Domain"].strip() != "":
961967
# print("Domain provided. Proceeding with checking the domain for duplicate sequences.")
962968
valid_uri = sequence_authentication(username, password, url,uri)
963969
if not valid_uri:
@@ -994,8 +1000,12 @@ def proteinSequence(rowobj):
9941000
username = os.getenv("SBOL_USERNAME")
9951001
password = os.getenv("SBOL_PASSWORD")
9961002
url = os.getenv("SBOL_URL")
997-
dict = os.getenv("SBOL_DICTIONARY")
998-
data = json.loads(dict)
1003+
dict_env = os.getenv("SBOL_DICTIONARY")
1004+
1005+
data = None
1006+
if dict_env is not None:
1007+
data = json.loads(dict_env)
1008+
9991009
if isinstance(val, str):
10001010
# might need to be careful if the object type is sequence!
10011011
# THIS MIGHT HAVE BUGS IF MULTIPLE SEQUENCES ARE PROVIDED FOR
@@ -1023,7 +1033,7 @@ def proteinSequence(rowobj):
10231033
# if data["Domain"].strip() == "":
10241034
# # print("Domain not provided. Proceding without checking the domain for duplicate sequences.")
10251035
# return
1026-
if data["Domain"].strip() != "":
1036+
if data and data["Domain"].strip() != "":
10271037
# print("Domain provided. Proceeding with checking the domain for duplicate sequences.")
10281038
valid_uri = sequence_authentication(username, password, url,uri)
10291039
if not valid_uri:

tests/Test_converter_function_README.md

Lines changed: 0 additions & 36 deletions
This file was deleted.
166 KB
Binary file not shown.
File renamed without changes.

tests/test_files/SBOL2_simple_parts_template.xlsx renamed to tests/non-working spreadsheets/SBOL2_simple_parts_template.xlsx

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)