def getManhattanData(type, value): # We'll need to get which phenotypes are selected. significantPhenotypes = getPhenotypes.getSignigicantPhenotypes(type, value) if significantPhenotypes.any()['nom']: # Check if there are significant phenotypes phenotype = getPhenotypes.getSignigicantPhenotypes(type, value).iat[0,0] #This gets the name of the significant phenotype # phenotype = "All cause death" # First we define the query sqlQuery="select distinct a.rs_id_assoc, a.chromosome,a.pos,a.info_assoc,a.pvalue_assoc,a.allele_A,a.allele_B,a.cohort_AA,a.cohort_BB,a.beta_assoc,a.maf, a.all_OR,xp.covariates,m.gene,m.gene_before,m.gene_after from assoc a join experiment xp on a.experiment=xp.idexperiment join phenotypes p on xp.phenotype=p.idphenotypes join marqueurs m on a.rs_id_assoc=m.nom where p.nom='"+phenotype+"' and a.pvalue_assoc<=0.001" # Then we fetch the data and store it in a dataframe sorted_data = connect.fetchData(sqlQuery) UserLogs.add( 'Victor Dupuy', '255.255.255.255', 'accessed the module : Interactive Manhattan', 'MySQL Database', ['assoc', 'phenotypes', 'marqueurs'] ) sorted_data.drop_duplicates(subset='rs_id_assoc', inplace=True,keep='last') sorted_data["log10"] = -numpy.log10(sorted_data.pvalue_assoc) #ADD COLUMN LOG10 sorted_data = sorted_data.sort(['chromosome', 'pos']) sorted_data['even']=numpy.where(sorted_data['chromosome'] %2==0,sorted_data['log10'] , 'NaN') sorted_data["odd"]=numpy.where(sorted_data['chromosome'] %2!=0,sorted_data['log10'] , 'NaN') col=['rs_id_assoc', 'chromosome', 'pos', 'pvalue_assoc', 'allele_A', 'allele_B', 'covariates', 'cohort_BB', 'cohort_AA', 'beta_assoc', 'maf'] return sorted_data, phenotype else: print "There is no phenotype !" return "No Phenotype !"
def getManhattanData(type, value): # We'll need to get which phenotypes are selected. significantPhenotypes = getPhenotypes.getSignigicantPhenotypes(type, value) if significantPhenotypes.any()['nom']: # Check if there are significant phenotypes phenotype = getPhenotypes.getSignigicantPhenotypes(type, value).iat[0,0] #This gets the name of the significant phenotype # phenotype = "All cause death" # First we define the query sqlQuery="select distinct a.rs_id_assoc, a.chromosome,a.pos,a.info_assoc,a.pvalue_assoc,a.allele_A,a.allele_B,a.cohort_AA,a.cohort_BB,a.beta_assoc,a.maf, a.all_OR,xp.covariates,m.gene,m.gene_before,m.gene_after from assoc a join experiment xp on a.experiment=xp.idexperiment join phenotypes p on xp.phenotype=p.idphenotypes join marqueurs m on a.rs_id_assoc=m.nom where p.nom='"+phenotype+"' and a.pvalue_assoc<=0.001 limit 1000" # Then we fetch the data and store it in a dataframe sorted_data = connect.fetchData(sqlQuery) UserLogs.add( 'Victor Dupuy', '255.255.255.255', 'accessed the module : Interactive Manhattan', 'MySQL Database', ['assoc', 'phenotypes', 'marqueurs'] ) sorted_data.drop_duplicates(subset='rs_id_assoc', inplace=True,keep='last') sorted_data["log10"] = -numpy.log10(sorted_data.pvalue_assoc) #ADD COLUMN LOG10 sorted_data = sorted_data.sort(['chromosome', 'pos']) sorted_data['even']=numpy.where(sorted_data['chromosome'] %2==0,sorted_data['log10'] , 'NaN') sorted_data["odd"]=numpy.where(sorted_data['chromosome'] %2!=0,sorted_data['log10'] , 'NaN') col=['rs_id_assoc', 'chromosome', 'pos', 'pvalue_assoc', 'allele_A', 'allele_B', 'covariates', 'cohort_BB', 'cohort_AA', 'beta_assoc', 'maf'] return sorted_data, phenotype else: print "There is no phenotype !" return "No Phenotype !"
def table(request, type, value): print request, type, value global data UserLogs.add( 'Victor Dupuy', '255.255.255.255', 'accessed the module : Web', 'MySQL Database', ['assoc', 'phenotypes', 'marqueurs'] ) # We'll need to get which phenotypes are selected. significantPhenotypes = getPhenotypes.getSignigicantPhenotypes(type, value) if significantPhenotypes.any()['nom']: # Check if there are significant phenotypes phenotype_selected = getPhenotypes.getSignigicantPhenotypes(type, value).iat[0,0] #This gets the name of the significant phenotype print significantPhenotypes # First we define the query sqlQuery = "select distinct a.rs_id_assoc,a.chromosome,a.pos,a.pvalue_assoc,m.gene_before,m.gene,m.gene_after,a.experiment,a.info_assoc,a.allele_A,a.allele_B,a.cohort_AA,a.cohort_BB,a.beta_assoc,a.maf,a.all_OR,xp.covariates, p.nom, case when a.beta_assoc>0 and p.Risk_on_rise is true then a.allele_B when a.beta_assoc<0 and p.Risk_on_rise is true then a.allele_A when a.beta_assoc>0 and p.Risk_on_rise is false then a.allele_A when a.beta_assoc<0 and p.Risk_on_rise is false then a.allele_B end as risk_allele, case when a.beta_assoc>0 and p.Risk_on_rise is true then ( (2*a.cohort_BB) + a.cohort_AB ) / ((2*a.cohort_AA) + (2*a.cohort_AB) +(2*a.cohort_BB) ) when a.beta_assoc<0 and p.Risk_on_rise is true then ( (2*a.cohort_AA) + a.cohort_AB ) / ((2*a.cohort_AA) + (2*a.cohort_AB) +(2*a.cohort_BB) ) when a.beta_assoc>0 and p.Risk_on_rise is false then ( (2*a.cohort_AA) + a.cohort_AB ) / ((2*a.cohort_AA) + (2*a.cohort_AB) +(2*a.cohort_BB) ) when a.beta_assoc<0 and p.Risk_on_rise is false then ( (2*a.cohort_BB) + a.cohort_AB ) / ((2*a.cohort_AA) + (2*a.cohort_AB) +(2*a.cohort_BB) ) end as risk_af, case when a.beta_assoc>0 and p.Risk_on_rise is true then a.beta_assoc when a.beta_assoc<0 and p.Risk_on_rise is true then a.beta_assoc*(-1) when a.beta_assoc>0 and p.Risk_on_rise is false then a.beta_assoc*(-1) when a.beta_assoc<0 and p.Risk_on_rise is false then a.beta_assoc end as risk_allele_beta from assoc a join experiment xp on a.experiment=xp.idexperiment join phenotypes p on xp.phenotype=p.idphenotypes join marqueurs m on a.rs_id_assoc=m.nom where p.nom='"+phenotype_selected+"' and a.pvalue_assoc<0.001" # Then we fetch the data and store it in a dataframe dataframe = connect.fetchData(sqlQuery) # dataframe.rename(columns={'rs_id_assoc':'rs id assoc'}) #Self-explanatory data = dataframe dataframe.rename(columns = { 'rs_id_assoc': 'rs_ID', 'pos': 'Pos', 'chromosome': 'Chr', 'gene_before': 'GeneBefore', 'pvalue_assoc': 'P-value', 'allele_A': 'Allele A', 'allele_B': 'Allele B', 'cohort_AA' : 'cohort AA', 'cohort_BB' : 'cohort BB', 'beta_assoc' : 'Beta Assoc', 'covariates' : 'Covariates', 'risk_allele' : 'Risk Allele', 'risk_af' : 'Risk Af', 'risk_allele_beta' : 'Risk Allele Beta', 'gene': 'Gene', 'gene_after': 'GeneAfter', 'nom' : 'Phenotype' }, inplace=True) #rename column to make them look nicer jsonData = dataframe.to_json(orient='records') significantPhenotypes.rename(columns={'nom' : 'Phenotypes'}, inplace=True); # Then we pass the dataframe to the client with json format response = json.dumps({ 'noResult' : False, 'phenotypes': significantPhenotypes.to_json(orient='records'), 'data' : jsonData }, sort_keys=True, indent=4, separators=(',', ': ') ) return HttpResponse(response) else: print "There is no phenotype !" response = json.dumps({ 'noResult' : True, 'phenotypes': [], 'data' : [] }, sort_keys=True, indent=4, separators=(',', ': ') ) return HttpResponse(response)