From: Rami Rauch Date: Fri, 7 Nov 2008 00:44:40 +0000 (+0000) Subject: Progress Reports Generator X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=348910598256a535290a99e1a8fb97d92b7138a5 Progress Reports Generator --- diff --git a/htswfrontend/htswfrontend/htsw_reports/reports.py b/htswfrontend/htswfrontend/htsw_reports/reports.py new file mode 100755 index 0000000..b6496f0 --- /dev/null +++ b/htswfrontend/htswfrontend/htsw_reports/reports.py @@ -0,0 +1,293 @@ +from htswfrontend.exp_track.models import * +from django.http import HttpResponse +from django.core.exceptions import ObjectDoesNotExist +from django.shortcuts import render_to_response, get_object_or_404 + +def getBgColor(reads_cnt,exp_type): + # Color Scheme: green is more than 12M, blue is more than 5M, orange is more than 3M and red is less. For RNAseq, all those thresholds are ~ double + bgcolor = '#ff3300' # Red is the color for minimum read counts + rc_thr = [12000000,5000000,3000000] # Default for ChIP-Seq and Methyl-Seq + if exp_type == 'RNA-seq': + rc_thr = [20000000,10000000,6000000] + + if reads_cnt > rc_thr[0]: + bgcolor = '#66ff66' # Green + else: + if reads_cnt > rc_thr[1]: + bgcolor ='#00ccff' # Blue + else: + if reads_cnt > rc_thr[2]: + bgcolor ='#ffcc33' # Orange + #tstr = '
' + #tstr += res[0].__str__()+' Lanes, '+rc+' M Reads' + #tstr += '
' + + return bgcolor + +def report1(request): + EXP = 'ChIP-seq' + + if request.has_key('aflid'): + AFL_Id = request['aflid'] + try: + AFL = Affiliation.objects.get(id=AFL_Id).name + AFL_CNT = Affiliation.objects.get(id=AFL_Id).contact + except ObjectDoesNotExist: + return HttpResponse("ERROR: Affiliation Record Not Found for: '"+AFL_ID+"'") + else: + AFL = 'ENCODE_Tier1' + AFL_CNT = '' + try: + AFL_Id = Affiliation.objects.get(name=AFL,contact=AFL_CNT).id.__str__() + except ObjectDoesNotExist: + return HttpResponse("ERROR: Affiliation Record Not Found for: '"+AFL+"'") + + TFall = Library.objects.values('antibody').order_by('antibody').distinct() + CLLall = Library.objects.values('cell_line').order_by('cell_line').distinct() + + TFs = TFall.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT) + CLLs = CLLall.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT) + + # Check Replicate numbers + Reps = 1 + RepRecs = Library.objects.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT).order_by('-replicate') + if len(RepRecs) > 0: Reps = RepRecs[0].replicate + + ######## + str = '' + str += 'Main Page' + ##str += 'Max Replicates: '+MaxRep.replicate.__str__()+'' + str += 'Select another '+EXP+' Report: ' + + str += 'color scheme: > 12 M > 5 M > 3 M < 3 M' + + str += '' + str += 'Switch to: '+AFL+' '+AFL_CNT+' RNA-Seq Report' + str += ' | ' + str += 'Methyl-Seq Report' + + bgc = '#ffffff' + pbgc = '#f7f7f7' + str += '

' + str += '' + str += '' + for H in CLLs: + str += '' + tbgc = bgc + bgc = pbgc + pbgc = tbgc + str += '' + bgc = '#ffffff' + pbgc = '#f7f7f7' + for H in CLLs: + for r in range(1,Reps+1): + str += '' + tbgc = bgc + bgc = pbgc + pbgc = tbgc + str += '' + str += '' + bgc = '#ffffff' + pbgc = '#f7f7f7' + for H in CLLs: + for r in range(1,Reps+1): + repReads = Library.objects.filter(experiment_type='INPUT_RXLCh',affiliations__name=AFL,affiliations__contact=AFL_CNT,cell_line=H['cell_line'].__str__(),replicate=r) + str += "' + tbgc = bgc + bgc = pbgc + pbgc = tbgc + str += '' + + for T in TFs: + str += '' + try: + if T['antibody']: + str += '' + except Antibody.DoesNotExist: + str += '' + + bgc = '#ffffff' + pbgc = '#f7f7f7' + for H in CLLs: + for r in range(1,Reps+1): + repReads = Library.objects.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT,cell_line=H['cell_line'].__str__(),antibody=T['antibody'].__str__(),replicate=r) + str += "' + tbgc = bgc + bgc = pbgc + pbgc = tbgc + str += '' + str += '
PROJECT'+AFL+' '+AFL_CNT+' '+EXP+'
CELL LINE'+Cellline.objects.get(id=H['cell_line']).cellline_name+'
TFRep. '+r.__str__()+'
Total Chromatin" + if len(repReads) == 0: + str += 'No Libraries' + else: + cnt = 0 + for R1 in repReads: + cnt = R1.aligned_m_reads()[1] + if cnt > 0: + str += "
" + str += "%1.2f" % (cnt/1000000.0)+" M" + else: str += "
0 Reads" + str += "
"+R1.library_id+", "+R1.condition.nickname+"
" + str += "
" + str += '
'+Antibody.objects.get(id=T['antibody']).nickname+'n/a" + if len(repReads) == 0: + str += 'No Libraries' + else: + cnt = 0 + for R1 in repReads: + cnt = R1.aligned_m_reads()[1] + if cnt > 0: + str += "
" + str += "%1.2f" % (cnt/1000000.0)+" M" + else: str += "
0 Reads" + str += "
"+R1.library_id+", "+R1.condition.nickname+"
" + str += "
" + str += '
' + + return render_to_response('htsw_reports/report.html',{'main': str}) + + +def report_RM(request): #for RNA-Seq and Methyl-Seq + EXP = 'RNA-seq' + + if request.has_key('exp'): + EXP = request['exp'] # Methyl-seq + + if request.has_key('aflid'): + AFL_Id = request['aflid'] + try: + AFL = Affiliation.objects.get(id=AFL_Id).name + AFL_CNT = Affiliation.objects.get(id=AFL_Id).contact + except ObjectDoesNotExist: + return HttpResponse("ERROR: Affiliation Record Not Found for: '"+AFL_ID+"'") + else: + AFL = 'ENCODE_Tier1' + AFL_CNT = '' + try: + AFL_Id = Affiliation.objects.get(name=AFL,contact=AFL_CNT).id.__str__() + except ObjectDoesNotExist: + return HttpResponse("ERROR: Affiliation Record Not Found for: '"+AFL+"'") + + CLLall = Library.objects.values('cell_line').order_by('cell_line').distinct() + CLLs = CLLall.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT) + + ######## + # Check Replicate numbers + Reps = 1 + RepRecs = Library.objects.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT).order_by('-replicate') + if len(RepRecs) > 0: Reps = RepRecs[0].replicate + + str = '' + str += 'Main Page' + str += 'Select another '+EXP+' Report: ' + + if EXP == 'RNA-seq': + str += 'color scheme: > 20 M > 10 M > 6 M < 6 M' + str += '' + str += 'Switch to: '+AFL+' '+AFL_CNT+' ChIP-Seq Report' + str += ' | ' + str += 'Methyl-Seq Report' + else: + str += 'color scheme: > 12 M > 5 M > 3 M < 3 M' + str += '' + str += 'Switch to: '+AFL+' '+AFL_CNT+' ChIP-Seq Report' + str += ' | ' + str += 'RNA-Seq Report' + + str += '

' + str += '' + str += '' + bgc = '#ffffff' + pbgc = '#f7f7f7' + for H in CLLs: + str += '' + tbgc = bgc + bgc = pbgc + pbgc = tbgc + str += '' + bgc = '#ffffff' + pbgc = '#f7f7f7' + for H in CLLs: + for r in range(1,Reps+1): + str += '' + tbgc = bgc + bgc = pbgc + pbgc = tbgc + str += '' + + str += '' + bgc = '#ffffff' + pbgc = '#f7f7f7' + for H in CLLs: + for r in range(1,Reps+1): + repReads = Library.objects.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT,cell_line=H['cell_line'],replicate=r) + str += "' + str += "
'+AFL+' '+AFL_CNT+' '+EXP+'
'+Cellline.objects.get(id=H['cell_line']).cellline_name+'
Rep. '+r.__str__()+'
" + if len(repReads) == 0: + str += 'No Libraries' + else: + cnt = 0 + for R1 in repReads: + cnt = R1.aligned_m_reads()[1] + if cnt > 0: + str += "
" + str += "%1.2f" % (cnt/1000000.0)+" M" + else: str += "
0 Reads" + str += "
"+R1.library_id+", "+R1.condition.nickname+", "+R1.library_species.common_name+"
" + str += "
\""+R1.library_name+"\"
'+f.Lanes()+''+f.run_date.__str__()+'
" + return render_to_response('htsw_reports/report.html',{'main':str}) + +def test_Libs(request): + str = '' + str += '' + allLibs = Library.objects.all() + #allLibs = Library.objects.filter(antibody__isnull=False) + for L in allLibs: + str += '' + str += '' + str += '' + + str += '
Lib IDCurrent Libaray Name (Free Text)Auto-composed Libaray Name (antibody + celline + libid + species + [replicate])
'+L.library_id+''+L.library_name+'' + str += L.experiment_type+'_' + if L.cell_line.cellline_name != 'Unknown': + str += L.cell_line.cellline_name+'_' + + try: + if L.antibody is not None: + str += L.antibody.nickname + '_' + except Antibody.DoesNotExist: + pass + + str += 'Rep'+L.replicate.__str__() + str += '
' + return HttpResponse(str)