Browse Source

small schema changes

master
Juni Kim 2 years ago
parent
commit
5e8e011c42
  1. 6
      app.py
  2. 2
      templates/batchadd.html
  3. 2
      templates/create_chemical.html
  4. 5
      validate.py

6
app.py

@ -72,6 +72,8 @@ def object_as_dict(obj):
class Chemical(db.Model): class Chemical(db.Model):
query: db.Query query: db.Query
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
standard_grp = db.Column(db.String, nullable=False)
uploaded_by = db.Column(db.String, nullable=False)
# all fields after here are included in the database # all fields after here are included in the database
chemical_db_id = db.Column(db.String) chemical_db_id = db.Column(db.String)
library = db.Column(db.String) library = db.Column(db.String)
@ -89,7 +91,7 @@ class Chemical(db.Model):
final_mz = db.Column(db.Float, nullable=False) final_mz = db.Column(db.Float, nullable=False)
final_rt = db.Column(db.Float, nullable=False) final_rt = db.Column(db.Float, nullable=False)
final_adduct = db.Column(db.String)
final_adduct = db.Column(db.String, nullable=False)
adduct = db.Column(db.String) adduct = db.Column(db.String)
detected_adducts = db.Column(db.String) detected_adducts = db.Column(db.String)
adduct_calc_mz = db.Column(db.String) adduct_calc_mz = db.Column(db.String)
@ -298,7 +300,7 @@ def batch_add_request():
def cleanup(): return os.remove(filename) def cleanup(): return os.remove(filename)
# read it as a csv # read it as a csv
with open(filename, "r") as csvfile: with open(filename, "r") as csvfile:
reader = csv.DictReader(csvfile)
reader = csv.DictReader(csvfile, delimiter="\t")
results, error = validate.validate_insertion_csv_fields(reader) results, error = validate.validate_insertion_csv_fields(reader)
if error: if error:
cleanup() cleanup()

2
templates/batchadd.html

@ -5,7 +5,7 @@
<a href="https://git.junickim.me/junikimm717/walker-database/raw/master/validate.py"> Source Code with required type definitions </a> <a href="https://git.junickim.me/junikimm717/walker-database/raw/master/validate.py"> Source Code with required type definitions </a>
<form method="post" enctype="multipart/form-data"> <form method="post" enctype="multipart/form-data">
<label for="csv">CSV: </label>
<label for="csv"> Input file (tab delimited text file) </label>
<input type="file" name="csv"> <input type="file" name="csv">
<input type="submit" value="Submit"> <input type="submit" value="Submit">
</form> </form>

2
templates/create_chemical.html

@ -2,7 +2,7 @@
{% block content %} {% block content %}
{% if id %} {% if id %}
<h2>Editing Chemical {{id}}</h2>
<h2>Editing Chemical {{id}} (* = required)</h2>
{% endif %} {% endif %}
{% if invalid %} {% if invalid %}
<p style="color: red;">Invalid Form!</p> <p style="color: red;">Invalid Form!</p>

5
validate.py

@ -1,5 +1,4 @@
import csv import csv
from datetime import date
""" """
Required fields when inserting into the database. Required fields when inserting into the database.
@ -14,6 +13,9 @@ _required_fields = [
("final_mz", "float"), ("final_mz", "float"),
("final_rt", "float"), ("final_rt", "float"),
("final_adduct", "str"),
("standard_grp", "str"),
("uploaded_by", "str"),
] ]
@ -31,7 +33,6 @@ _optional_fields = [
("inchikey", "str"), ("inchikey", "str"),
("inchikey14", "str"), ("inchikey14", "str"),
("final_adduct", "str"),
("adduct", "str"), ("adduct", "str"),
("detected_adducts", "str"), ("detected_adducts", "str"),
("adduct_calc_mz", "str"), ("adduct_calc_mz", "str"),

Loading…
Cancel
Save