Skip to content

Commit

Permalink
Merge pull request #26 from SynBioDex/3-Package-the-functions-into-a-…
Browse files Browse the repository at this point in the history
…Library

initial setup to support issue #15
  • Loading branch information
tramyn authored Oct 10, 2020
2 parents 325f10a + d46e156 commit f4faa70
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 16 deletions.
2 changes: 1 addition & 1 deletion excel2sbol/converter/part_library_converter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class PartLibraryConverter(object):

DARPA_TEMPLATE = ''
def __init__(self):
pass
5 changes: 5 additions & 0 deletions excel2sbol/converter/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

class Template(object):

def __init__(self):
pass
7 changes: 7 additions & 0 deletions excel2sbol/converter/template_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class TemplateFactory(object):

def __init__(self):
pass

def create_darpa_template(self):
pass
63 changes: 63 additions & 0 deletions excel2sbol/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,67 @@
import argparse
import excel2sbol.utils.converter_utils as converter_utils
import pandas as pd

def convert_part_library(template_file: str, input_excel: str):
# Read in template and filled spreadsheet for the Parts library
start_row = 13
nrows = 8
description_row = 9
filled_library, filled_library_metadata, filled_description = converter_utils.read_library(input_excel,
start_row=start_row, nrows=nrows,
description_row=description_row)
blank_library, blank_library_metadata, blank_description = converter_utils.read_library(template_file,
start_row=start_row, nrows=nrows,
description_row=description_row)

ontology = pd.read_excel(input_excel, header=None, sheet_name="Ontology Terms", skiprows=3, index_col=0)
ontology = ontology.to_dict("dict")[1]

converter_utils.quality_check(filled_library,
blank_library,
filled_library_metadata,
blank_library_metadata,
filled_description,
blank_description, nrows, description_row)

# Create SBOL document
doc = converter_utils.write_sbol(filled_library, filled_library_metadata, filled_description, ontology)
return doc

def convert_composition_reading(template_file: str, input_excel: str):
# Load Data
startrow_composition = 9
sheet_name = "Composite Parts"
nrows = 8
use_cols = [0, 1]
# read in whole composite sheet below metadata
table = pd.read_excel(input_excel, sheet_name=sheet_name,
header=None, skiprows=startrow_composition)

# Load Metadata
filled_composition_metadata = pd.read_excel(input_excel, sheet_name=sheet_name,
header=None, nrows=nrows, usecols=use_cols)
blank_composition_metadata = pd.read_excel(template_file, sheet_name=sheet_name,
header=None, nrows=nrows, usecols=use_cols)

# Compare the metadata to the template
converter_utils.quality_check_metadata(filled_composition_metadata, blank_composition_metadata)

# Load Libraries required for Parts
libraries = converter_utils.load_libraries(table)

# Loop over all rows and find those where each block begins
compositions, list_of_rows = converter_utils.get_data(table)

# Extract parts from table
compositions, all_parts = converter_utils.get_parts(list_of_rows, table, compositions)

# Check if Collection names are alphanumeric and separated by underscore
compositions = converter_utils.check_name(compositions)

# Create sbol
doc = converter_utils.write_sbol_comp(libraries, compositions, all_parts)
return doc

def main():
parser = argparse.ArgumentParser(description='Creates libraries of basic parts by converting a spreadsheet to SBOL.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#Set up
import os
import pandas as pd
from excel2sbol.functions import quality_check_metadata, load_libraries, get_data
from excel2sbol.functions import get_parts, check_name, write_sbol_comp, fix_msec_sbol
from excel2sbol.utils.converter_utils import quality_check_metadata, load_libraries, get_data
from excel2sbol.utils.converter_utils import get_parts, check_name, write_sbol_comp, fix_msec_sbol

cwd = os.path.dirname(os.path.abspath("__file__")) #get current working directory
path_filled = os.path.join(cwd, "templates", "darpa_template.xlsx")
Expand Down
6 changes: 3 additions & 3 deletions Excel.py → excel2sbol/resources/Excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#Setup
import pandas as pd
import os
from excel2sbol.functions import read_library, quality_check, write_sbol
from excel2sbol.utils.converter_utils import read_library, quality_check, write_sbol


cwd = os.path.dirname(os.path.abspath("__file__")) #get current working directory
path_blank = os.path.join(cwd, "templates/darpa_template_blank.xlsx")
# path_filled = os.path.join("C:\\Users\\JVM\\Downloads\\build-request-template_BsPpVn.xlsx")
# file_path_out = "C:\\Users\\JVM\\Downloads\\converted.xml"
path_filled = None #os.path.join("C:\\Users\\JVM\\Downloads\\build-request-template_BsPpVn.xlsx")
file_path_out = None #"C:\\Users\\JVM\\Downloads\\converted.xml"

#Read in template and filled spreadsheet for the Parts library
start_row = 13
Expand Down
File renamed without changes.
Binary file added excel2sbol/tests/data/darpa_template_blank.xlsx
Binary file not shown.
29 changes: 26 additions & 3 deletions excel2sbol/tests/test_golden_files.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
import excel2sbol.main as tool
import os
import unittest

class GoldenFileTest(unittest.TestCase):

def setup(self):
@classmethod
def setUpClass(cls):
pass

def setUp(self):
curr_path = os.path.dirname(os.path.realpath(__file__))
self.data_dir = os.path.join(curr_path, 'data')

def tearDown(self):
pass

def test_library_file(self):
pass
@classmethod
def tearDownClass(cls):
pass

def test_convert_part_library(self):
file = 'darpa_template.xlsx'
input_file_path = os.path.join(self.data_dir, file)
template_file = os.path.join(self.data_dir, 'darpa_template_blank.xlsx')
output_doc = tool.convert_part_library(template_file=template_file, input_excel=input_file_path)
self.assertTrue(output_doc)

dna_parts = output_doc.componentDefinitions
self.assertEqual(5, len(dna_parts))

def test_convert_composition_reading(self):
file = 'darpa_template.xlsx'
input_file_path = os.path.join(self.data_dir, file)
template_file = os.path.join(self.data_dir, 'darpa_template_blank.xlsx')
output_doc = tool.convert_composition_reading(template_file=template_file, input_excel=input_file_path)
self.assertTrue(output_doc)
14 changes: 7 additions & 7 deletions excel2sbol/utils/converter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,19 +432,19 @@ def read_library(path, start_row, nrows, description_row, use_cols = [0, 1],
start_row = 13, nrows = 8, description_row = 9)
"""
basic_DNA_parts = pd.read_excel (path, sheet_name = sheet_name,
header= 0, skiprows = start_row)
basic_DNA_parts = pd.read_excel(path, sheet_name=sheet_name,
header=0, skiprows=start_row)

metadata = pd.read_excel (path, sheet_name = sheet_name,
header= None, nrows = nrows, usecols = use_cols)
metadata = pd.read_excel (path, sheet_name=sheet_name,
header=None, nrows=nrows, usecols=use_cols)

description = pd.read_excel (path, sheet_name = sheet_name, skiprows = description_row,
nrows = 1, usecols = description_col)
description = pd.read_excel (path, sheet_name=sheet_name, skiprows=description_row,
nrows=1, usecols=description_col)

return (basic_DNA_parts, metadata, description)

def quality_check(filled_library, blank_library, filled_metadata, blank_metadata, filled_description,
blank_description, nrows, description_row, description_col=[0], use_cols = [0,1]):
blank_description, nrows, description_row, description_col=[0], use_cols=[0,1]):
"""
the function compares the edited excel spreadsheet with the template
Expand Down
Empty file.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sbol2==1.0b8
pandas==1.0.1
numpy==1.18.1
xlrd >= 1.0.0

0 comments on commit f4faa70

Please sign in to comment.