Skip to content

Commit

Permalink
test for significance using londFDR before sending response
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Aug 20, 2019
1 parent fa2ed8a commit c8c3c9b
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
#from old_feed.computation_request import computation_request
from interface import computational_request
# from comp_req import comp_req
from epivizFeed import LondFDR
from flask_cache import Cache
from flask_sockets import Sockets
import time
import ujson
import logging
import os
import pandas as pd
import json

app = Flask(__name__)
cache = Cache(app, config={'CACHE_TYPE': 'simple', 'CACHE_DEFAULT_TIMEOUT': 0})
Expand All @@ -20,37 +23,61 @@
@sockets.route('/getdata')
def feed(websocket):
message = ujson.loads(websocket.receive())

with open( os.getcwd() + "/epiviz.json", "r") as config_file:
measurements = ujson.loads(config_file.read())

logging.info(message)

data = message['data']
start = data['start']
end = data['end']
chromosome = data['chr']
gene_name = data['gene']
seqID = message['seq']
pval_disc = data['significant']
pval_count = data['totalTests']
logging.info ("parameters")

key = chromosome + '-' + str(start) + '-' + str(end)
cached = cache.get(key)
pValFDR = LondFDR(R = pval_disc, N = pval_count)
if cached:
significantCount = 0
for cr in cached:
if cr[u"significance"]:
significantCount += 1
websocket.send(ujson.dumps(cached))
websocket.send(ujson.dumps(seqID))
websocket.send(ujson.dumps({"seq": seqID, "significant": significantCount, "totalTests": len(cached)}))
return

results = computational_request(start, end, chromosome, gene_name, measurements=measurements)
cache_results = []
logging.info (results)

for result in results:
logging.info ("send back!")
logging.info (time.time())
logging.info ("\n")
# emit('returned_results', result)
cache_results.extend(result)
websocket.send(ujson.dumps(result))
significant_result =pd.DataFrame()

cache.set(key, cache_results)
if len(result) > 1:
logging.info("batch is > 1, FDR")
pvalues = result["pvalue"].tolist()
cor_pval = pValFDR.batchLondStar(pval = pvalues)
result["adjusted_testing_levels"] = cor_pval[1]
result["significance"] = cor_pval[2]
# significant_result = result.loc[result['significance'] == True]

websocket.send(ujson.dumps(seqID))

comp_res = result.to_json(orient='records')
parse_res = json.loads(comp_res)
cache_results.extend(parse_res)
websocket.send(ujson.dumps(parse_res))

cache.set(key, cache_results)
websocket.send(ujson.dumps({"seq": seqID, "significant": pValFDR.R, "totalTests": pValFDR.N}))

if __name__ == "__main__":
from gevent import pywsgi
Expand Down

0 comments on commit c8c3c9b

Please sign in to comment.