Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7c4c50c
Latest version copied to anamailyan fork
anamailyan Mar 17, 2019
bbc1397
Change db user
anamailyan Mar 17, 2019
c39a5d8
More details to project
anamailyan Mar 17, 2019
fe154ec
Adding fields from HPFS data and some ifs to test nulls
anamailyan Mar 18, 2019
1cd9037
Merging with upstream
anamailyan Mar 19, 2019
9a528bb
Adding schema changes
anamailyan Mar 19, 2019
e232d1f
Reverting to clean version without ifs
anamailyan Mar 19, 2019
b63f67d
Typo fix
anamailyan Mar 19, 2019
d7dc041
open and close db connection/cursor
anamailyan Mar 20, 2019
9341bd2
Adding HPFS fields to schema
anamailyan Mar 21, 2019
1cc4318
Typo fix
anamailyan Mar 21, 2019
00de047
Adding couple missing fields to Metadata
anamailyan Mar 21, 2019
72fc054
making sure schema changes are reflected in all files
anamailyan Mar 22, 2019
e13865e
Adding Version to schema for future use
anamailyan Mar 22, 2019
9c96af7
Reducing number of queries
anamailyan Mar 23, 2019
734422d
Adding command to set environment var for password
anamailyan Mar 23, 2019
2e4ecc5
Removing some test ifs and test cases
anamailyan Mar 25, 2019
3d604c0
adding placeholders for init and exit for future use
anamailyan Mar 25, 2019
b49cfea
Using pooling, c extension, cursor dictionary, and pulling version
anamailyan Mar 27, 2019
b7ba27d
moving connection out of fetch results
anamailyan Mar 27, 2019
ead4a8b
experimenting with connection pools
anamailyan Mar 27, 2019
4147de1
testing saving projects info
anamailyan Mar 28, 2019
cd9a8bc
working fast with projects saved
anamailyan Mar 28, 2019
bfe86e2
get pool and release pool added
anamailyan Mar 29, 2019
1a43677
fixing version on front page
anamailyan Mar 29, 2019
672689e
fixing version text in db
anamailyan Mar 29, 2019
b006e65
fixing typo
anamailyan Mar 29, 2019
d19b20b
file returns file_id as id, not name
anamailyan Mar 30, 2019
202b64c
combine 2 loops
anamailyan Mar 30, 2019
eb0672a
making metadata weight lbs and totMETs1 float
anamailyan Mar 31, 2019
e52ec5b
Moving query strings to separate file
anamailyan Apr 2, 2019
7c9f446
Comments added
anamailyan Apr 2, 2019
39bad35
Adding metadata_participant to FileCase, portal ui needs it
anamailyan Apr 3, 2019
9f737c7
Fixing primary site issue
anamailyan Apr 3, 2019
9805477
primary site fix again
anamailyan Apr 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ then run
1. ``CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';``
2. ``GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;``
3. ``flush privileges;``

More information https://dev.mysql.com/doc/refman/5.5/en/adding-users.html
4. Set environment variable BIOM_MASS that holds user's password
``export BIOM_MASS="password"``

load_local_database.py script needs mysql.connect module.

Expand Down
316 changes: 279 additions & 37 deletions database.py

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions dbqueries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# This file holds all queries run in database.py



all_counts_query='''select count(id) as total from project
union all select count(id) as total from participant
union all select count(id) as total from sample
union all select count(distinct data_format) as total from file_sample
union all select count(id) as total from file_sample where type="rawFiles"
union all select count(id) as total from file_sample where type="processedFiles"'''
projects_query="select id from project"
version_query="select * from version order by updated desc limit 1"
files_query="select id from file_sample"
cases_query="select id from participant"
files_size_query="select sum(file_size) as sum_size from file_sample"
files_total_query="select count(id) as total from file_sample"
cases_total_query="select count(distinct id) as total from participant"

def project_query(p_id):
return "select * from project where id =" + str(p_id)

def project_counts_query(p_id):
query="select count(id) as total from file_sample where project='"+p_id+"'"
query=query+" union all "
query=query+"select count(distinct participant) as total from file_sample where project='"+p_id+"'"
query=query+" union all "
query=query+"select sum(file_size) as total from file_sample where project='"+p_id+"'"
return query

def data_cat_query(table, p_id):
return "select distinct data_category from file_sample where "+ table+"='" + str(p_id)+"'"

def data_cat_counts_query(table,p_id,data_cat):
query="select count(id) as total from file_sample where data_category='"+data_cat+"' and "+table+"='"+str(p_id)+"'"
query=query+" union all "
query=query+"select count(distinct participant) as total from file_sample where data_category='"+data_cat+"' and "+table+"='"+str(p_id)+"'"
return query

def exp_str_query(table,p_id):
return "select distinct experimental_strategy from file_sample where "+ table+"='" + str(p_id) +"'"

def exp_str_counts_query(table,p_id,exp_str):
query="select count(id) as total from file_sample where experimental_strategy='"+exp_str+"' and "+table+"='"+str(p_id)+"'"
query=query+" union all "
query=query+ "select count(distinct participant) as total from file_sample where experimental_strategy='"+exp_str+"' and "+table+"='"+str(p_id)+"'"
return query

def file_query(f_id):
query='''select file_sample.*,
project.id as p_id, project.project_id as proj_id,project.primary_site,
participant.id as part_id, participant.age_2012, participant.totMETs1, participant.weight_lbs
from file_sample,project,participant where file_sample.id='''+str(f_id)
query=query+''' and file_sample.project=project.project_id and
file_sample.participant=participant.entity_participant_id'''
return query

def case_query(p_id):
return '''select participant.entity_participant_id, file_sample.id, file_sample.experimental_strategy,
file_sample.data_category, file_sample.platform, file_sample.access,file_sample.data_format
from participant, file_sample
where participant.id='''+str(p_id)+" and file_sample.participant=participant.entity_participant_id"

def case_counts_query(p_id):
query="select count(id) as total from participant where entity_participant_id="+str(p_id)
query=query+" union all "
query=query+ "select count(id) as total from file_sample where participant="+str(p_id)
query=query+" union all "
query=query+"select sum(file_size) as total from file_sample where participant="+str(p_id)
return query

def case_project_query(p_id):
query="select distinct file_sample.project, project.id as p_id, project.primary_site "
query=query+"from file_sample, project where file_sample.participant='"
query=query+str(p_id)+"' and project.project_id=file_sample.project limit 1"
return query


def metadata_part_query(p_id):
return "select * from participant where entity_participant_id="+str(p_id)

def metadata_sample_query(p_id):
return "select * from sample where participant="+str(p_id)

4 changes: 2 additions & 2 deletions load_local_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def parse_arguments(args):
required=False)
parser.add_argument(
"--key-file",
default="biom-mass-fdcadb440fdf.json",
default="/home/hutlab_public/compute_engine_service_account_key/biom-mass-8dc9ab934396.json",
help="google project service account private key file path\n]",
required=False)
parser.add_argument(
Expand Down Expand Up @@ -256,7 +256,7 @@ def main():
new_version = str(0.1)

now = datetime.datetime.now()
release_date ="Date Release "+new_version+" "+ now.strftime("%b %d, %Y")
release_date ="Data Release "+new_version+" - "+ now.strftime("%b %d, %Y")
commit ="commit_"+now.strftime("%m%d%Y")
query_insert_version ='''INSERT INTO `version` (
commit,
Expand Down
2 changes: 1 addition & 1 deletion query_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def parse_arguments(args):
required=False)
parser.add_argument(
"--key-file",
default="biom-mass-fdcadb440fdf.json",
default="/home/hutlab_public/compute_engine_service_account_key/biom-mass-8dc9ab934396.json",
help="google project service account private key file path\n]",
required=False)
parser.add_argument(
Expand Down
44 changes: 44 additions & 0 deletions schema.graphql
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,59 @@ type Case implements Node {
primary_site: String
submitter_id: String
demographic: Demographic
metadata_participant: MetadataParticipant
metadata_sample: [MetadataSample]
project: Project
summary: Summary
annotations: CaseAnnotations
files: CaseFiles
}

type MetadataParticipant {
id: Int
participant: Int
age_2012: Int
totMETs1: Float
weight_lbs: Float
}

type MetadataSample
id: Int
project: String
sample: String
participant: Int
DaysSince1Jan12: Int
drAlcohol: Float
drB12: Float
drCalories: Float
drCarbs: Float
drCholine: Float
drFat: Float
drFiber: Float
drFolate: Float
drIron: Float
drProtein: Float
participant: Int
q2Alcohol: String
q2B12: String
q2Calories: String
q2Carbs: String
q2Choline: String
q2Fat: String
q2Fiber: String
q2Folate: String
q2Iron: String
q2Protein: String
Time: String
week: Int

type CaseAggregations {
demographic__ethnicity: Aggregations
demographic__gender: Aggregations
demographic__race: Aggregations
metadata_participant__age_2012: Aggregations
metadata_participant__totMETs1: Aggregations
metadata_participant__weight_lbs: Aggregations
primary_site: Aggregations
project__project_id: Aggregations
project__program__name: Aggregations
Expand Down Expand Up @@ -180,6 +223,7 @@ type FileCase implements Node {
case_id: String
project: Project
demographic: Demographic
metadata_participant: MetadataParticipant
primary_site: String
}

Expand Down
48 changes: 46 additions & 2 deletions schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,51 @@ class Demographic(graphene.ObjectType):
gender = graphene.String()
race = graphene.String()

class MetadataParticipant(graphene.ObjectType):
id = graphene.Int()
participant = graphene.Int()
age_2012 = graphene.Int()
totMETs1 = graphene.Float()
weight_lbs = graphene.Float()

class MetadataSample(graphene.ObjectType):
id = graphene.Int()
project = graphene.String()
sample = graphene.String()
participant = graphene.Int()
DaysSince1Jan12 = graphene.Int()
drAlcohol = graphene.Float()
drB12 = graphene.Float()
drCalories = graphene.Float()
drCarbs = graphene.Float()
drCholine = graphene.Float()
drFat = graphene.Float()
drFiber = graphene.Float()
drFolate = graphene.Float()
drIron = graphene.Float()
drProtein = graphene.Float()
participant = graphene.Int()
q2Alcohol = graphene.String()
q2B12 = graphene.String()
q2Calories = graphene.String()
q2Carbs = graphene.String()
q2Choline = graphene.String()
q2Fat = graphene.String()
q2Fiber = graphene.String()
q2Folate = graphene.String()
q2Iron = graphene.String()
q2Protein = graphene.String()
Time = graphene.String()
week = graphene.Int()

class FileCase(graphene.ObjectType):
class Meta:
interfaces = (graphene.relay.Node,)

case_id = graphene.String()
project = graphene.Field(Project)
demographic = graphene.Field(Demographic)
metadata_participant = graphene.Field(MetadataParticipant)
primary_site = graphene.String()

class FileCaseConnection(graphene.relay.Connection):
Expand Down Expand Up @@ -137,7 +175,7 @@ class Meta:
type = graphene.String()

def resolve_file_id(self, info):
return self.name
return self.file_id

def resolve_type(self, info):
return self.data_format
Expand All @@ -160,6 +198,7 @@ class Meta:
total = graphene.Int()

def resolve_total(self, info):
# return data.get_files_total()
return len(self.edges)

class Bucket(graphene.ObjectType):
Expand Down Expand Up @@ -214,6 +253,9 @@ class CaseAggregations(graphene.ObjectType):
demographic__ethnicity = graphene.Field(Aggregations)
demographic__gender = graphene.Field(Aggregations)
demographic__race = graphene.Field(Aggregations)
metadata_participant__age_2012 = graphene.Field(Aggregations)
metadata_participant__totMETs1 = graphene.Field(Aggregations)
metadata_participant__weight_lbs = graphene.Field(Aggregations)
primary_site = graphene.Field(Aggregations)
project__project_id = graphene.Field(Aggregations)
project__program__name = graphene.Field(Aggregations)
Expand Down Expand Up @@ -280,8 +322,9 @@ class Meta:
case_id = graphene.String()
primary_site = graphene.String()
submitter_id = graphene.String()

demographic = graphene.Field(Demographic)
metadata_participant = graphene.Field(MetadataParticipant)
metadata_sample = graphene.List(MetadataSample)
project = graphene.Field(Project)
summary = graphene.Field(Summary)
annotations = graphene.Field(CaseAnnotations)
Expand All @@ -298,6 +341,7 @@ class Meta:
total = graphene.Int()

def resolve_total(self, info):
#return data.get_cases_total()
return len(self.edges)

class RepositoryCases(graphene.ObjectType):
Expand Down
11 changes: 7 additions & 4 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import os

import flask
import flask_cors
import flask_graphql
import graphene

import schema
import const
#import const
from database import data

NAME = "firecloud_graphql"
HOST = "0.0.0.0"
Expand All @@ -41,7 +43,8 @@ def process_query(request, schema):
def main():
# create the graphql flask app
app = flask.Flask(NAME)

# allow initial OPTIONS requests
flask_cors.CORS(app)
# add the root graphql queries
@app.route('/graphql', methods=["POST"])
def get_root_schema():
Expand All @@ -55,8 +58,8 @@ def get_schema(name):
# add static endpoint for version/status
@app.route('/status', methods=["GET"])
def get_version():
return flask.jsonify(const.VERSION)

return flask.jsonify(data.get_current_version())
# app.debug = True
# add end point for graphql gui
app.add_url_rule('/test', view_func=flask_graphql.GraphQLView.as_view(
'test', schema=graphene.Schema(query=schema.Query, auto_camelcase=False), graphiql=True))
Expand Down