Browse Source

first commit

master
junikimm717 2 years ago
commit
5e3802bf85
  1. 2
      .gitattributes
  2. 3
      .gitignore
  3. BIN
      csv/1.csv
  4. BIN
      csv/2.csv
  5. 33
      data1.py
  6. 33
      data2.py
  7. 21
      enter_data.py
  8. 11
      requirements.txt
  9. BIN
      xlsx/Example1.xlsx
  10. BIN
      xlsx/Example2.xlsx

2
.gitattributes

@ -0,0 +1,2 @@
*.csv filter=lfs diff=lfs merge=lfs -text
*.xlsx filter=lfs diff=lfs merge=lfs -text

3
.gitignore

@ -0,0 +1,3 @@
__pycache__
.DS_Store
/venv

BIN
csv/1.csv (Stored with Git LFS)

size 2753

BIN
csv/2.csv (Stored with Git LFS)

size 38956

33
data1.py

@ -0,0 +1,33 @@
#!/usr/bin/env python3
from pandas import read_csv
from pprint import pprint
df = read_csv("./csv/1.csv")
pprint(list(enumerate(df.columns)))
cols = [
('chemical_db_id', 1),
('library', 2),
('name', 4),
('formula', 5),
('mass', 6),
('pubchem_cid', 7),
('pubmed_refcount', 8),
('standard_class', 9),
('inchikey', 11),
('inchikey14', 12),
('final_mz', 15),
('final_rt', 16),
('final_adduct', 17),
('adduct', 18),
('detected_adducts', 20),
('adduct_calc_mz', 21),
('msms_detected', 24),
('msms_purity', 26)
]
idxs = [x[1] for x in cols]
data = [{x[0]: row[x[1]] for x in cols} for row in df.to_dict('tight')['data']]
for x in data:
if x['msms_detected'] == 'No':
del x['msms_detected']

33
data2.py

@ -0,0 +1,33 @@
#!/usr/bin/env python3
from pandas import read_csv
from pprint import pprint
df = read_csv("./csv/2.csv")
pprint(list(enumerate(df.columns)))
cols = [
('chemical_db_id', 1),
('library', 2),
('name', 4),
('formula', 6),
('mass', 7),
('pubchem_cid', 10),
('pubmed_refcount', 8),
('standard_class', 11),
('inchikey', 13),
('inchikey14', 14),
('final_mz', 17),
('final_rt', 18),
('final_adduct', 19),
('adduct', 20),
('detected_adducts', 22),
('adduct_calc_mz', 23),
('msms_detected', 26),
('msms_purity', 28)
]
data = [{x[0]: row[x[1]] for x in cols} for row in df.to_dict('tight')['data']]
for x in data:
if x['msms_detected'] == 'No':
del x['msms_detected']

21
enter_data.py

@ -0,0 +1,21 @@
#!/usr/bin/env python3
import requests
import sys
import data2
import data1
baseurl = "http://127.0.0.1:5000"
session = requests.session()
with session.post(baseurl + "/admin/login", {'username': 'admin', 'password': 'admin'}) as req:
if req.status_code != 200:
print("Auth Failed")
sys.exit(1)
for x in data1.data + data2.data:
print(f"POSTing for {x}...")
req = session.post(baseurl + "/chemical/create", x)
if req.status_code != 200:
print(f"Request Failed for {x}")
print("Complete.")

11
requirements.txt

@ -0,0 +1,11 @@
certifi==2022.12.7
charset-normalizer==2.1.1
idna==3.4
numpy==1.24.0
pandas==1.5.2
python-dateutil==2.8.2
pytz==2022.7
requests==2.28.1
six==1.16.0
urllib3==1.26.13
xlsx2csv==0.8.0

BIN
xlsx/Example1.xlsx (Stored with Git LFS)

size 11700

BIN
xlsx/Example2.xlsx (Stored with Git LFS)

size 29000
Loading…
Cancel
Save