def get_general_info(): return jsonify({ 'all datasets': dt.list_datasets(), 'id types': dt.list_idtypes(), 'id manager': dt.get_idmanager(), 'mapping manager': dt.get_mappingmanager() })
def update_weights(values): partial_header = ["CCI_SCORE"] split_values = values.split('+') for i in range(0, len(partial_header)): weights_CCI[partial_header[i]] = int(split_values[i]) return jsonify({'weights': weights_CCI})
def display_descriptions(term): concept1 = mongo.db.s20160901 output1 = [] for q1 in concept1.find({'sctName': {"$regex": term, "$options": "i"}}): output1.append(q1) return jsonify(output1)
def get_pat_info(PAT_ID, dataset): return jsonify({ 'Demo': get_info([int(PAT_ID)], dataset_hash['Demo'][dataset]), 'Orders': get_info([int(PAT_ID)], dataset_hash['Orders'][dataset]), 'PRO': get_info([int(PAT_ID)], dataset_hash['PRO'][dataset]) })
def display_icd10codes(name): concept = mongo.db.s20160901 output = [] for q in concept.find({'mapTarget': name}): output.append(q) return jsonify(output)
def display_concepts(name): concept = mongo.db.s20160901 output = [] for q in concept.find({'referencedComponentId': name}): output.append(q) return jsonify(output)
def display_initial(): concept = mongo.db.s20160901 output = [] for q in concept.find({}).limit(300): output.append(q) return jsonify(output)
def get_result(task_id): """ returns the result of a task with blocking :param task_id: :return: """ from phovea_processing_queue.task_definition import get_result res = get_result(task_id) return jsonify(res.get())
def update_weights(values): partial_header = [ "PAT_BIRTHDATE", "PAT_GENDER", "PAT_ETHNICITY", "PAT_RACE", "PAT_MARITAL_STAT", "BMI", "HEIGHT_CM", "WEIGHT_KG", "TOBACCO_USER", "ALCOHOL_USER", "ILLICIT_DRUG_USER" ] split_values = values.split('+') for i in range(0, len(partial_header)): weights_Demo[partial_header[i]] = int(split_values[i]) return jsonify({'weights': weights_Demo})
def get_generated_username(): # use additional random integer to increase possible combinations # import random # new_username = f"{pydng.generate_name()}_{random.randint(1, 10)}" new_username = pydng.generate_name( ) # 108 adjectives * 237 lastnames = 25.596 combinations if (username_exists(new_username)): _log.info(F"Generated user {new_username} already exists. Retrying...") return get_generated_username() return jsonify(new_username)
def get_similar_rows(PAT_ID, number, dataset): Demo_score = handle_Demo.get_similarity_score( int(PAT_ID), dataset_hash['Demo'][dataset]) CCI_score = handle_CCI.get_similarity_score(int(PAT_ID), dataset_hash['CCI'][dataset]) Pro_score = handle_pro.get_similarity_score(int(PAT_ID), dataset_hash['PRO'][dataset]) id_scores = [] pat_ids = set(list(Demo_score.keys()) + (list(CCI_score.keys()))) for id in pat_ids: temp = 0 if id in Demo_score: temp += Demo_score[id] if id in CCI_score: temp += CCI_score[id] if id in Pro_score: temp += Pro_score[id] id_scores.append([id, temp]) id_scores.sort(key=lambda r: r[1], reverse=True) ids = [d[0] for d in id_scores[:number]] scores = [d[1] for d in id_scores[:number]] all_scores = [d[1] for d in id_scores] pat_demo_info = get_info([int(PAT_ID)], dataset_hash['Demo'][dataset]) demo_info = get_info(ids, dataset_hash['Demo'][dataset]) pat_pro_info = get_info([int(PAT_ID)], dataset_hash['PRO'][dataset]) pro_info = get_info(ids, dataset_hash['PRO'][dataset]) pat_orders_info = get_info([int(PAT_ID)], dataset_hash['Orders'][dataset]) orders_info = get_info(ids, dataset_hash['Orders'][dataset]) #difference = handle_Demo.get_difference(int(PAT_ID), ids) # maybe in the client?! return jsonify({ 'PAT_ID': PAT_ID, 'ids': ids, 'all_scores': all_scores, 'similarity_scores': scores, 'pat_Demo': pat_demo_info, 'pat_PRO': pat_pro_info, 'pat_Orders': pat_orders_info, 'similar_Demo': demo_info, 'similar_PRO': pro_info, 'similar_Orders': orders_info #'difference': difference #'all_pro_rows': sum(pro_rows, get_all_info_for_pat('PRO', int(PAT_ID))) })
def get_latest_info(): data = dt.get('Demo').aslist() pat_ids = set([int(d['PAT_ID']) for d in data]) pats = [] pat_weights = [] for id in pat_ids: temp_pat = [] for row in data: if row['PAT_ID'] == id: temp_pat.append(row) temp_pat.sort(key=lambda x: to_date_time(x['ADM_DATE']), reverse=True) pats.append(temp_pat[0]) pat_weights.append( [t['WEIGHT_KG'] for t in temp_pat if t['WEIGHT_KG']]) return jsonify({'rows': pats, 'WEIGHT_KG': pat_weights})
def get_info_by_functions(id): my_data = dt.get(id) #range = rng.RangeElem(2, 5, 1) return jsonify({ 'id': id, 'my_data': my_data, 'rows': my_data.rows(), 'data': my_data.asjson(), 'rowids': my_data.rowids(), 'aslist': my_data.aslist(), 'aspandas': my_data.aspandas(), 'columns': my_data.columns, 'CSVEntry.to_description': my_data.to_description(), 'CSVEntry.idtypes': my_data.idtypes() #, #'asList( range(2,5,1) )': my_data.aslist(range), #'rows( range(2,5,1) )': my_data.rows(range), #'aspandas( range(2,5,1) )': my_data.aspandas(range) })
def get_stat(dataset): my_data = dt.get(dataset_hash['Demo'][dataset]) data = my_data.aslist() length = 0 gender = [0, 0] bmi = [0, 0, 0, 0, 0, 0, 0] age = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] today = pd.datetime.today() for row in data: length += 1 if row['PAT_GENDER'] == 'F': gender[0] += 1 elif row['PAT_GENDER'] == 'M': gender[1] += 1 if not row['BMI']: bmi[0] += 1 elif row['BMI'] <= 18: bmi[1] += 1 elif row['BMI'] > 30: bmi[6] += 1 else: bmi[int(math.ceil((row['BMI'] - 15) / 3))] += 1 pat_age = int( (today - to_date_time(row['PAT_BIRTHDATE'])).days / 365.25) if pat_age <= 10: age[0] += 1 elif pat_age > 100: age[10] += 1 else: age[int(math.floor((pat_age - 1) / 10))] += 1 return jsonify({ 'length': length, 'GENDER': gender, 'BMI': bmi, 'AGE': age })
def get_order_type(dataset, ordertype): filtered_orders = handle_Orders.get_order_type( dataset_hash['Orders'][dataset], ordertype) return jsonify({'filtered_Orders': filtered_orders})
def get_filtered_orders_by_month(dataset, order): filtered_orders = handle_Orders.get_filteres_orders( dataset_hash['Orders'][dataset], order) return jsonify({'filtered_Orders': filtered_orders})
def get_latest_info(dataset_id): if dataset_id == 'Demo': return handle_Demo.get_latest_info() return jsonify({'message': 'error'})
def get_weights(): return jsonify({'weights': weights_Demo})
def _func(): return jsonify({'message': 'Get method'})
def get_weights(): return jsonify({'weights': weights_CCI})
def _test(): return jsonify({'message': simplePythonFile.simple_python_method()})
def get_col_titles(id): my_data = dt.get(id) return jsonify({'cols': my_data.columns})
def get_col_by_name(id, col_name): my_data = dt.get(id) cols = my_data.aspandas() return jsonify({'cols': cols[col_name]})
def get_all_rows(dataset_id): my_data = dt.get(dataset_id) rows = my_data.aslist() return jsonify({dataset_id: rows[:50]})
def hist(): # hist?cohortId=2&type=dataCat&attribute=race # hist?cohortId=2&type=dataNum&attribute=age # hist?cohortId=2&type=geneScoreCat&attribute=aa_mutated&table=mutation&ensg=ENSG00000141510 # hist?cohortId=2&type=geneScoreNum&attribute=relativecopynumber&table=copynumber&ensg=ENSG00000141510 # hist?cohortId=3&type=depletionScore&attribute=rsa&table=depletionscore&ensg=ENSG00000141510&depletionscreen=Drive # hist?cohortId=2&type=panelAnnotation&panel=TCGA normals error_msg = """Paramerter missing or wrong! For the {route} query the following parameter is needed: - cohortId: id of the cohort parent cohort - type: dataCat | dataNum | geneScoreCat | geneScoreNum | depletionScore | panelAnnotation Depending on the 'type' different additional parameters have to exist --> Type: dataCat | dataNum - attribute: the entity attribute --> Type: geneScoreCat | geneScoreNum - table: the score table, which contains the attribute - attribute: the score attribute - ensg: name of the gene --> Type: depletionScore - table: the score table, which contains the attribute - attribute: the score attribute - ensg: name of the gene - depletionscreen: name of the screen --> Type: panelAnnotation - panel: name of the panel""".format(route='hist') try: query = QueryElements() type = request.values.get('type') # get type of hist if type is None: raise RuntimeError(error_msg) hist = jsonify([]) cohort = query.get_cohort_from_db(request.values, error_msg) # get cohort database = cohort.entity_database num_bins = 10 if type == 'dataCat': # - cohortId: id of the cohort # - attribute: the entity attribute sql_text = query.get_hist_cat_sql(request.values, cohort, error_msg) hist = query.execute_sql_query( sql_text, database, config.supp_statement_timeout) # execute sql statement elif type == 'dataNum': # - cohortId: id of the cohort # - attribute: the entity attribute sql_text = query.get_hist_num_sql(request.values, cohort, num_bins, error_msg) hist_dict = query.execute_sql_query_as_dict( sql_text, database, config.supp_statement_timeout) # execute sql statement hist = query.format_num_hist(hist_dict, num_bins) elif type == 'geneScoreCat': # - cohortId: id of the cohort # - table: the score table, which contains the attribute # - attribute: the score attribute # - ensg: name of the gene sql_text = query.get_hist_gene_cat_sql(request.values, cohort, error_msg) hist = query.execute_sql_query( sql_text, database, config.supp_statement_timeout) # execute sql statement elif type == 'geneScoreNum': # - cohortId: id of the cohort # - table: the score table, which contains the attribute # - attribute: the score attribute # - ensg: name of the gene sql_text = query.get_hist_gene_num_sql(request.values, cohort, num_bins, error_msg) hist_dict = query.execute_sql_query_as_dict( sql_text, database, config.supp_statement_timeout) # execute sql statement hist = query.format_num_hist(hist_dict, num_bins) elif type == 'depletionScore': # - cohortId: id of the cohort # - table: the score table, which contains the attribute # - attribute: the score attribute # - ensg: name of the gene # - depletionscreen: name of the screen sql_text = query.get_hist_depletion_sql(request.values, cohort, num_bins, error_msg) hist_dict = query.execute_sql_query_as_dict( sql_text, database, config.supp_statement_timeout) # execute sql statement hist = query.format_num_hist(hist_dict, num_bins) elif type == 'panelAnnotation': # - cohortId: id of the cohort # - panel: name of the panel sql_text = query.get_hist_panel_sql(request.values, cohort, error_msg) hist = query.execute_sql_query( sql_text, database, config.supp_statement_timeout) # execute sql statement return hist except RuntimeError as error: abort(400, error)
def _hello(): return jsonify({'message': 'Hello World'})
def get_weights(dataset_id): if dataset_id == 'Demo': return handle_Demo.get_weights() if dataset_id == 'CCI': return handle_CCI.get_weights() return jsonify({'message': 'error'})
def get_group(dataset, group): if '/' + dataset + '/' + group not in h5: abort(404) g = h5.get_node('/' + dataset + '/' + group) return jsonify(g)
def update_weights(dataset_id, values): if dataset_id == 'Demo': return handle_Demo.update_weights(values) if dataset_id == 'CCI': return handle_CCI.update_weights(values) return jsonify({'message': 'error'})
def get_row_by_index(id, index): my_data = dt.get(id) rows = my_data.aslist() return jsonify({'row': rows[int(index)]})
def get_data(id): return jsonify({'data': dt.get(id)})