Skip to content

Commit 9e60a02

Browse files
committed
make it possible for excel2flapjack to add sboluris
1 parent a22391d commit 9e60a02

5 files changed

Lines changed: 18 additions & 45 deletions

File tree

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,11 @@
11
import pandas as pd
2-
import random
32
from flapjack import Flapjack
43

54

6-
# # this is for testing without flapjack
7-
# # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8-
# class id_thing():
9-
# def __init__(self, id_in):
10-
# self.id = [id_in]
11-
12-
13-
# class Flapjack():
14-
15-
# def create(self, *args):
16-
17-
# # UNCOMMENT ONE OF THE TWO
18-
# print(args)
19-
# # temp = args
20-
21-
# return id_thing(random.randint(1, 100))
22-
# # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
23-
24-
255
# still requires some work to ensure studies etc created too
26-
def flapjack_upload(fj_url, fj_user, fj_pass, excel_path):
6+
def flapjack_upload(fj_url, fj_user, fj_pass, excel_path, sbol_hash_map={},
7+
add_sbol_uris=False, flapjack_override=False,
8+
print_progress=False):
279
hash_map = {}
2810

2911
# UNCOMMENT BELOW TO USE FLAPJACK
@@ -32,16 +14,14 @@ def flapjack_upload(fj_url, fj_user, fj_pass, excel_path):
3214
fj.log_in(username=fj_user, password=fj_pass)
3315

3416
# read in Excel Data
35-
#xls = pd.read_excel(excel_path,sheet_name=None)
3617
xls = pd.ExcelFile(excel_path)
3718
fj_conv_sht = xls.parse('FlapjackCols', skiprows=0)
3819

3920
# order is important as Chemicals and DNA must be created before
4021
# they can be referenced
4122
types = ['Chemical', 'DNA', 'Supplement', 'Vector', 'Strain', 'Media',
4223
'Signal', 'Study', 'Assay', 'Sample', 'Measurement']
43-
#types = ['DNA', 'Supplement', 'Vector', 'Strain', 'Media',
44-
#'Signal', 'Measurement']
24+
4525
# initiate hashmap for linking to chemicals
4626
hash_map = {}
4727

@@ -68,31 +48,25 @@ def flapjack_upload(fj_url, fj_user, fj_pass, excel_path):
6848
# Create a dictionary of the data for flapjack
6949
obj_dict = obj_df.to_dict('index')
7050

71-
# REMOVE THIS LINE WHEN USING FLAPJACK
72-
#fj = Flapjack()
73-
7451
# Upload all the objects to flapjack
7552
for key in obj_dict:
53+
if print_progress:
54+
print(key)
7655
data = obj_dict[key]
7756

57+
if key in sbol_hash_map and add_sbol_uris:
58+
data['sboluri'] = sbol_hash_map[key]
59+
7860
# Change to flapjack id rather than name for chemicals and dnas
7961
lookups = {'chemical', 'dnas', 'study', 'vector', 'strain', 'media', 'assay', 'sample', 'signal'}
8062
lk_inter = lookups.intersection(set(data.keys()))
81-
print(lk_inter)
8263
for it in list(lk_inter):
8364
data[it] = hash_map[data[it]]
8465

85-
# CHANGE THIS WHEN USING FLAPJACK
86-
# add ** infront of data later when not patched!!!!!!!!
87-
print(obj)
8866
data['model'] = obj.lower()
89-
print(data)
90-
91-
flapjack_id = fj.create(**data)
92-
# flapjack_id = fj.create(data)
67+
flapjack_id = fj.create(**data, confirm=not(flapjack_override))
9368

9469
# add Chemical and DNA to hash map to allow cross referencing
95-
print(flapjack_id)
9670
hash_map[key] = flapjack_id.id[0]
9771

9872
return hash_map

excel2flapjack/excel2flapjack/temp.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33

44
#fj_url = "localhost:8000"
55
fj_url = "flapjack.rudge-lab.org:8000" #Web Instance
6-
fj_user = "saisam17"
7-
fj_pass = "Il0vem$her"
6+
fj_user = ""
7+
fj_pass = ""
88

99
direct = __file__
1010
test_file_path = os.path.join(os.path.split(os.path.split(direct)[0])[0],
1111
'tests', 'test_files')
12-
excel_path = os.path.join(test_file_path, "flapjack_excel_converter_v028.xlsx")
12+
excel_path = os.path.join(test_file_path, "flapjack_excel_converter_v030.xlsx")
1313

14-
hash_map = e2f.flapjack_upload(fj_url, fj_user, fj_pass, excel_path)
14+
shm = {'Study1': 'https://synbiohub.org/user/JVM/Flapjack/Study1/1', 'Assay1': 'https://synbiohub.org/user/JVM/Flapjack/Assay1/1', 'Assay2': 'https://synbiohub.org/user/JVM/Flapjack/Assay2/1', 'Sample1': 'https://synbiohub.org/user/JVM/Flapjack/Sample1/1', 'Sample2': 'https://synbiohub.org/user/JVM/Flapjack/Sample2/1', 'Sample3': 'https://synbiohub.org/user/JVM/Flapjack/Sample3/1', 'Sample4': 'https://synbiohub.org/user/JVM/Flapjack/Sample4/1', 'M9Glucose': 'https://synbiohub.org/user/JVM/Flapjack/M9Glucose/1', 'Signal1': 'https://synbiohub.org/user/JVM/Flapjack/Signal1/1', 'Signal9': 'https://synbiohub.org/user/JVM/Flapjack/Signal9/1', 'EcoliT7': 'https://synbiohub.org/user/JVM/Flapjack/EcoliT7/1', 'Rep_HIGH_degrate_plasmid': 'https://synbiohub.org/user/JVM/Flapjack/Rep_HIGH_degrate_plasmid/1', 'Rep_LOW_degrate_plasmid': 'https://synbiohub.org/user/JVM/Flapjack/Rep_LOW_degrate_plasmid/1', 'DNA1': 'https://synbiohub.org/user/JVM/Flapjack/DNA1/1', 'DNA2': 'https://synbiohub.org/user/JVM/Flapjack/DNA2/1', 'DNA3': 'https://synbiohub.org/user/JVM/Flapjack/DNA3/1'}
15+
16+
hash_map = e2f.flapjack_upload(fj_url, fj_user, fj_pass, excel_path, sbol_hash_map=shm,
17+
add_sbol_uris=True, flapjack_override=True, print_progress=True)
1518
print(hash_map)

excel2flapjack/excel2flapjack/temp2.py

Lines changed: 0 additions & 4 deletions
This file was deleted.
-165 Bytes
Binary file not shown.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pyflapjack==1.0.5
2-
pandas==1.4.4
2+
pandas==1.3.3
33
openpyxl==3.0.9

0 commit comments

Comments
 (0)