示例#1
0
		$(this).one('mouseout', function(){
			$(document).one('click', function() { $(tmp).prev().fadeOut(); });
		});

	})
})

</script>

</head>
<body>
<div class="row-fluid">
<div class="span12" style="margin-left:10px; margin-top:10px;">
<form method='get' class="form-inline">
<select name='dbN' style="width:120px; height:23px; font-size:9pt">
''' % (geneN, mycgi.db2dsetN(dbN))

mycgi.dbOptions(dbN)

print '''
</select>
<input type='text' name='geneN' value='%s' style="width:130px; height:15px; font-size:9pt">
<input type='submit' class="btn btn-small" value='Submit'>
</form>

''' % (geneN)

main(dbN, geneN)

print('''
<br><h5>Legends</h5>
示例#2
0
def main(dbN, geneN):

    (con, cursor) = mycgi.connectDB(db=dbN)

    # prep RNA-Seq data availability table
    cursor.execute(
        'create temporary table t_avail_RNASeq as select distinct samp_id from rpkm_gene_expr'
    )

    # prep exonSkip info
    cursor.execute(
        'select delExons,frame,loc1,loc2, count(*) cnt from splice_skip where gene_sym = "%s" and nPos>=5 group by delExons order by count(*) desc'
        % geneN)
    results = cursor.fetchall()

    conditionL_exonSkip = []

    for (delExons, frame, loc1, loc2, cnt) in results:

        if ':Y' in frame:
            frame_code = 'in'
        elif ':N' in frame:
            frame_code = 'off'
        else:
            frame_code = 'utr'

        conditionL_exonSkip.append( [
         ('nReads', 'splice_skip', 'loc1="%s" and loc2="%s" and nPos>=5' % (loc1,loc2), '%3d', '%s<br><sup>(n=%s, %s)</sup>' % (delExons.split(',')[0], cnt,frame_code),), \
			#			('avg(nReads)', 'splice_normal', 'loc1="%s" or loc2="%s"' % (loc1,loc2), '%d') ])

         ('sum(nReads)', 'splice_normal', 'loc1="%s"' % (loc1,), '%d') ])

    # prep mutation info


#		where gene_symL like "%s%s%s" and ch_type != "synonymous_variant" and ch_type != "nc_transcript_variant,synonymous_variant" and ch_type != "intron_variant,synonymous_variant" \
    if dbN == 'CancerSCAN':
        cursor.execute('create temporary table t_mut as \
			select concat(substring(chrom,4,4),":",cast(chrSta as char),ref,">",alt) as ch_pos, ch_dna,ch_aa,ch_type,cosmic from mutation_cs \
			where find_in_set("%s",gene_sym) > 0 and ch_type != "synonymous_variant" and ch_type != "nc_transcript_variant,synonymous_variant" and ch_type != "intron_variant,synonymous_variant" \
			and ch_type != "nc_transcript_variant" and ch_type != "intron_variant,nc_transcript_variant" and ch_type != "intron_variant" and ch_type != "Substitution - coding silent"\
			and nReads_alt<>2 order by ch_type desc' % (geneN))
    else:
        cursor.execute('create temporary table t_mut as \
			select concat(substring(chrom,4,4),":",cast(chrSta as char),ref,">",alt) as ch_pos, ch_dna,ch_aa,ch_type,cosmic from mutation_rxsq \
			where find_in_set("%s",gene_symL) > 0 and ch_type != "synonymous_variant" and ch_type != "nc_transcript_variant,synonymous_variant" and ch_type != "intron_variant,synonymous_variant" \
			and ch_type != "nc_transcript_variant" and ch_type != "intron_variant,nc_transcript_variant" and ch_type != "intron_variant" and ch_type != "Substitution - coding silent"\
			and nReads_alt<>2 order by ch_type desc' % (geneN))

    cursor.execute(
        'select *,count(*) cnt from t_mut group by ch_pos order by count(*) desc, cosmic desc'
    )
    results = cursor.fetchall()

    conditionL_mutation = []

    for (ch_pos, ch_dna, ch_aa, ch_type, cosmic, cnt) in results:

        ch_aa = ch_aa.replace(',', '<br>')

        if (dbN == 'CancerSCAN' and 'cosmic' in cosmic) or (dbN != 'CancerSCAN'
                                                            and cosmic):
            cosmic_fmt = '<font color="red">%s</font><br><sup>(n=%d, %s)</sup>'

        else:
            cosmic_fmt = '%s<br><sup>(n=%d, %s)</sup>'

        if ch_aa:
            cnd = ch_aa
        elif ch_dna:
            cnd = ch_dna
        else:
            cnd = ch_pos

        if dbN == 'CancerSCAN':
            conditionL_mutation.append([
             ('nReads_alt', 'mutation_cs', 'nReads_alt<>2 and concat(substring(chrom,4,4),":",cast(chrSta as char),ref,">",alt)="%s"' % ch_pos, '%d', cosmic_fmt % (cnd, cnt, mutation_map(ch_type, dbN))), \
             ('nReads_ref', 'mutation_cs', 'nReads_alt<>2 and concat(substring(chrom,4,4),":",cast(chrSta as char),ref,">",alt)="%s"' % ch_pos, '%d') ])
        else:
            conditionL_mutation.append( [
             ('nReads_alt,r_nReads_alt', 'mutation_rxsq', 'nReads_alt<>2 and concat(substring(chrom,4,4),":",cast(chrSta as char),ref,">",alt)="%s"' % ch_pos, '%d', cosmic_fmt % (cnd, cnt, mutation_map(ch_type, dbN))), \
             ('nReads_ref,r_nReads_ref', 'mutation_rxsq', 'nReads_alt<>2 and concat(substring(chrom,4,4),":",cast(chrSta as char),ref,">",alt)="%s"' % ch_pos, '%d') ])

    # prep fusion table
    cursor.execute('create temporary table t_fusion as \
		select samp_id,locate(":Y",frame)>1 frame,count(nPos) nEvents \
		from splice_fusion where nPos>=2 and (find_in_set("%s",gene_sym1) or find_in_set("%s",gene_sym2)) group by samp_id, locate(":Y",frame)>1'
                   % (geneN, geneN))

    # prep eiJunc info
    cursor.execute(
        'select loc,juncAlias, count(*) cnt from splice_eiJunc where gene_sym="%s" and nReads>=10 group by loc'
        % geneN)
    results = cursor.fetchall()

    conditionL_eiJunc = []

    for (loc, juncAlias, cnt) in results:
        conditionL_eiJunc.append([
            ('nReads', 'splice_eiJunc', 'loc="%s" and nReads>=10' % loc, '%3d',
             '%s<br><sup>(n=%s)</sup>' % (juncAlias, cnt)),
            ('sum(nReads)', 'splice_normal', 'loc1="%s"' % (loc, ), '%d')
        ])

    # outlier
    outlier_sId = []

    if dbN in ['ircr1', 'tcga1', 'ccle1']:
        cursor.execute(
            'select samp_id, expr_MAD from array_gene_expr_MAD mad, gene_expr_stat stat where mad.gene_sym = stat.gene_sym and (mad.expr_MAD >= stat.q75 + 3*(stat.q75 - stat.q25) or mad.expr_MAD <= stat.q25 - 3*(stat.q75 - stat.q25)) and mad.gene_sym = "%s"'
            % geneN)
        results3 = cursor.fetchall()

        for i in range(len(results3)):
            outlier_sId.append(results3[i][0])

    ## corrected CN value available?
    cncorr_sId = []
    if dbN in ['ircr1']:
        cursor.execute(
            'select distinct samp_id from xsq_purity where tumor_frac != "ND"')
        resultsCorr = cursor.fetchall()
        for i in range(len(resultsCorr)):
            cncorr_sId.append(resultsCorr[i][0])
    normal_sId = []
    if dbN in ['ircr1']:
        cursor.execute('select distinct samp_id from xsq_purity')
        tttt = cursor.fetchall()
        for i in range(len(tttt)):
            normal_sId.append(tttt[i][0])

    conditionL = conditionL_preH[
        dbN] + conditionL_mutation + conditionL_fusion + conditionL_exonSkip + conditionL_eiJunc

    print '<p><h4>%s status of %s panel <small><a href="http://www.genecards.org/cgi-bin/carddisp.pl?gene=%s">[GeneCard]</a> <a href="http://www.ncbi.nlm.nih.gov/pubmed/?term=%s">[PubMed]</a></small></h4></p>' % (
        geneN, mycgi.db2dsetN(dbN), geneN, geneN)

    # census
    cursor.execute(
        'select tumor_soma, tumor_germ, syndrome, mut_type from common.census where gene_sym="%s"'
        % geneN)
    census = cursor.fetchall()

    print('\n<font size=2> <table border="1" cellpadding="0" cellspacing="0">')
    print(
        '<tr>\n<td rowspan=2>Census</td>\n<td>tumor_soma</td>\n<td>tumor_germ</td>\n<td>syndrome</td>\n<td>mut_type</td>\n</tr>\n'
    )

    if len(census) != 0:
        print(
            '<tr>\n<td>%s</td>\n<td>%s</td>\n<td>%s</td>\n<td>%s</td>\n</tr>\n'
            % (census[0][0], census[0][1], census[0][2], census[0][3]))
    else:
        print('<tr>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n')

    # drugbank
    cursor.execute('select drug from common.drugbank where gene_sym="%s"' %
                   geneN)
    drug = [x for (x, ) in cursor.fetchall()]

    print('\n<font size=2> <table border="1" cellpadding="0" cellspacing="0">')
    print('<br><tr>\n<td>Drug</td>\n')
    print('<td>%s</td>\n</tr>\n' % ('</br>\n'.join(drug)))

    # pathway
    cursor.execute(
        'select biocarta_id, biocarta_desc from common.biocarta where gene_sym="%s"'
        % geneN)
    biocarta = cursor.fetchall()

    cursor.execute(
        'select kegg_id, kegg_desc from common.kegg where gene_sym="%s"' %
        geneN)
    kegg = cursor.fetchall()

    cursor.execute('select go_id, go_desc from common.go where gene_sym="%s"' %
                   geneN)
    go = cursor.fetchall()

    print('\n<font size=2> <table border="1" cellpadding="0" cellspacing="0">')
    print('<br><tr>\n<td>Biocarta</td>\n<td>KEGG</td>\n<td>GO</td>\n</tr>\n')
    print('<tr><td><div style="width:100%; height:50px; overflow:auto">')
    for (id, desc) in biocarta:
        print(
            '<a href="http://cgap.nci.nih.gov/Pathways/BioCarta/%s">%s</br>' %
            (id, desc))
    print('</td>\n<td><div style="width:100%; height:50px; overflow:auto">')
    for (id, desc) in kegg:
        print(
            '<a href="http://www.genome.jp/dbget-bin/www_bget?pathway+%s">%s</br>'
            % (id, desc))
    print('</td>\n<td><div style="width:100%; height:50px; overflow:auto">')
    for (id, desc) in go:
        print(
            '<a href="http://amigo.geneontology.org/cgi-bin/amigo/term_details?term=GO:%s">%s</br>'
            % (id, desc))
    print('</div></td>\n</tr>\n')

    if dbN == 'CancerSCAN':
        cursor.execute(
            '''CREATE TEMPORARY TABLE t_id AS SELECT DISTINCT samp_id FROM mutation_cs UNION SELECT DISTINCT samp_id FROM cs_cn'''
        )
    elif dbN == 'tcga1':
        cursor.execute('create temporary table t_id as \
		select distinct samp_id from array_gene_expr union select distinct samp_id from array_cn union select distinct samp_id from splice_normal union select distinct samp_id from mutation_rxsq union select distinct samp_id from rpkm_gene_expr'
                       )
    else:
        cursor.execute('create temporary table t_id as \
		select distinct samp_id from array_gene_expr union select distinct samp_id from array_cn union select distinct samp_id from splice_normal union select distinct samp_id from mutation_rxsq union select distinct samp_id from rpkm_gene_expr union select distinct samp_id from xsq_cn'
                       )

    cursor.execute('alter table t_id add index (samp_id)')

    cursor.execute(
        'create temporary table t_expr as select * from array_gene_expr where gene_sym="%s"'
        % geneN)
    #cursor.execute('create temporary table t_cn as select * from xsq_cn where gene_sym="%s"' % geneN)

    cursor.execute('alter table t_expr add index (samp_id,gene_sym)')
    #cursor.execute('alter table t_cn add index (samp_id,gene_sym)')

    cursor.execute(
        'select samp_id from t_id left join t_expr using (samp_id) order by z_score desc'
    )
    #cursor.execute('select samp_id from t_id left join t_cn using (samp_id) order by value_log2 desc')

    results = cursor.fetchall()

    numTotSamp = len(results)

    print('\n<font size=3> <table border="1" cellpadding="0" cellspacing="0">')

    # header: row1
    print '<br><tr>\n<td rowspan=2><div class="verticaltext" align="middle">samples<br><sup>n=%s</sup></div></td>' % numTotSamp,

    for i in range(len(conditionL)):

        row = conditionL[i]

        if type(row) == list:
            row = row[0]

        if i < len(conditionL_preH[dbN]):
            if ('tag' in row[1]) or ('t_avail' in row[1]) or (
                    'subtype' in row[1]) or ('purity' in row[1]):
                cursor.execute('select count(*) from %s where %s' %
                               (row[1], row[2]))
            elif ('loh' in row[1]):
                cursor.execute(
                    'select count(distinct samp_id) from xsq_purity'
                )  # of samples for which purity pipeline was applied = # of samples with matched blood exome
            else:
                cursor.execute(
                    'select count(*) from %s where %s and gene_sym ="%s"' %
                    (row[1], row[2], geneN))

            count = cursor.fetchone()
            if 'MAD' in row[4]:
                print(
                    '<td rowspan=2 align="middle"><div class="verticaltext">%s, n=%s)</sup></div></td>'
                    % (row[-1], count[0]))
            else:
                print(
                    '<td rowspan=2 align="middle"><div class="verticaltext">%s<br><sup>(n=%s)</sup></div></td>'
                    % (row[-1], count[0]))
        else:
            if i == len(conditionL_preH[dbN]) and len(conditionL_mutation) > 0:
                print('<td align="middle" colspan=%s>mutation (mt/wt)</td>' %
                      len(conditionL_mutation))
            elif i == len(conditionL_preH[dbN]) + len(conditionL_mutation):
                print(
                    '<td align="middle" colspan=%s><a href="ircr_samp.py?dbN=%s&dType=Fusion">fusion</a></td>'
                    % (len(conditionL_fusion), dbN))
            elif i == len(
                    conditionL_preH[dbN]) + len(conditionL_mutation) + len(
                        conditionL_fusion) and len(conditionL_exonSkip) > 0:
                print(
                    '<td align="middle" colspan=%s><a href="ircr_samp.py?dbN=%s&dType=ExonSkipping">exonSkip</a> (mt/wt)</td>'
                    % (len(conditionL_exonSkip), dbN))
            elif i == len(conditionL_preH[dbN]) + len(
                    conditionL_mutation) + len(conditionL_fusion) + len(
                        conditionL_exonSkip) and len(conditionL_eiJunc) > 0:
                print(
                    '<td align="middle" colspan=%s><a href="ircr_samp.py?dbN=%s&dType=3pDeletion">3p deletion</a> (mt/wt)</td>'
                    % (len(conditionL_eiJunc), dbN))

    print('\n</tr>\n')

    # header: row2
    print '<tr>\n',

    for i in range(len(conditionL)):

        row = conditionL[i]

        if type(row) == list:
            row = row[0]

        if i < len(conditionL_preH[dbN]):
            pass
        else:
            print(
                '<td height="100"><div class="verticaltext" align="middle">%s</div></td>'
                % row[-1])

    print('\n</tr>\n')

    for (sId, ) in results:

        print '<tr>',
        #		print '<td nowrap><a href="ircr_samp.py?dbN=%s&sId=%s">%s</td>' % (dbN,sId,sId),
        new_id = mycgi.get_new_id(sId)
        print '<td nowrap><a href="ircr_samp.py?dbN=%s&sId=%s">%s</td>' % (
            dbN, new_id, new_id),

        d_flag = None
        r_flag = None

        for row in conditionL:

            outlier = None

            if type(row) == list:
                row_wt = row[1]
                row = row[0]
            else:
                row_wt = None

            (col, tbl, cnd, fmt) = row[:4]

            cursor.execute('show columns from %s like "gene_sym"' % tbl)

            if cursor.fetchone():
                cnd += ' and gene_sym="%s"' % geneN

            if tbl == 'mutation_rxsq':
                cursor.execute(
                    'select distinct %s from %s where samp_id="%s" and (%s)' %
                    (col, tbl, sId, cnd))
            else:
                cursor.execute(
                    'select %s from %s where samp_id="%s" and (%s)' %
                    (col, tbl, sId, cnd))

            results2 = cursor.fetchall()

            if len(results2) > 1:
                print sId
                raise Exception

            if type(row) == tuple and row[-1] == 'RSq':

                if len(results2) > 0:
                    r_flag = True
                else:
                    r_flag = False

            if type(row) == tuple and row[-1] == 'XSq':

                if len(results2) > 0:
                    d_flag = True
                else:
                    d_flag = False

            if sId not in normal_sId:  # flag for matched normal
                p_flag = False
            else:
                p_flag = True

            if type(row) == tuple and row[-1] == 'expr<br><sup>(MAD':

                if sId in outlier_sId:
                    outlier = True
                else:
                    outlier = False

            if len(results2) == 1:  # and results2[0][0] not in (0,'0'):

                value = ('%s' % fmt) % results2[0][0]

                if len(results2[0]) >= 2:
                    n_value = ('%s' % fmt) % results2[0][1]
                else:
                    n_value = 0

                if row_wt:

                    (col, tbl, cnd, fmt) = row_wt[:4]

                    if tbl == 'mutation_rxsq':
                        cursor.execute(
                            'select distinct %s from %s where samp_id="%s" and %s'
                            % (col, tbl, sId, cnd))
                    else:
                        cursor.execute(
                            'select %s from %s where samp_id="%s" and %s' %
                            (col, tbl, sId, cnd))

                    results_wt = cursor.fetchone()

                    n_count_wt = 0

                    if results_wt[0]:
                        count_wt = ('%s' % fmt) % results_wt[0]
                    else:
                        count_wt = 0

                    if len(results_wt) >= 2:
                        count_wt = ('%s' % fmt) % results_wt[0]
                        n_count_wt = ('%s' % fmt) % results_wt[1]

                    if row[1] == 'mutation_rxsq':

                        #						if int(n_value)!=0 and int(n_count_wt)!=0 and int(value)!=0 and int(count_wt)!=0:
                        if int(n_value) != 0 and int(value) != 0:
                            if int(value) > (int(value) + int(count_wt)
                                             ) * cutoff and int(n_value) > (
                                                 int(n_value) +
                                                 int(n_count_wt)) * cutoff:
                                print '<td><font color=red><b>%s</b></font><sub>/%s</sub>,<font color=468847><b>%s</b><sub>/%s</sub></font></td>' % (
                                    value, count_wt, n_value, n_count_wt),
                            elif int(n_value) > (int(n_value) +
                                                 int(n_count_wt)) * cutoff:
                                print '<td>%s<sub>/%s</sub>,<font color=468847><b>%s</b><sub>/%s</sub></font></td>' % (
                                    value, count_wt, n_value, n_count_wt),
                            elif int(value) > (int(value) +
                                               int(count_wt)) * cutoff:
                                print '<td><font color=red><b>%s</b></font><sub>/%s</sub>,<font color=468847>%s<sub>/%s</sub></font></td>' % (
                                    value, count_wt, n_value, n_count_wt),
                            else:
                                print '<td>%s<sub>/%s</sub>,<font color=468847>%s<sub>/%s</sub></font></td>' % (
                                    value, count_wt, n_value, n_count_wt),

                        elif int(value) == 0 and int(
                                count_wt) == 0:  ## no exome
                            if int(n_value) > (int(n_value) +
                                               int(n_count_wt)) * cutoff:
                                print '<td><font color=468847><b>%s</b><sub>/%s</sub></font></td>' % (
                                    n_value, n_count_wt),
                            else:
                                print '<td><font color=468847>%s<sub>/%s</sub></font></td>' % (
                                    n_value, n_count_wt),
                        elif int(n_value) == 0 and int(
                                n_count_wt) == 0:  ## no normal
                            if int(value) > (int(value) +
                                             int(count_wt)) * cutoff:
                                print '<td><font color=red><b>%s</b></font><sub>/%s</sub></td>' % (
                                    value, count_wt),
                            else:
                                print '<td>%s<sub>/%s</sub></td>' % (value,
                                                                     count_wt),

                    else:
                        if int(value) > (int(value) + int(count_wt)) * cutoff:
                            tmp = row[4].split('<br>')[0].split('/')
                            if len(tmp) > 1 and tmp[0] == tmp[1]:
                                print '<td>%s<sub>/%s</sub></td>' % (value,
                                                                     count_wt),
                            else:
                                print '<td><font color=red><b>%s</b></font><sub>/%s</sub></td>' % (
                                    value, count_wt),
                        else:
                            print '<td>%s<sub>/%s</sub></td>' % (value,
                                                                 count_wt),

                else:
                    if row[1] == 't_fusion':
                        html_content = ""
                        if row[4] == 'in':
                            print '<a name="%s"></a>' % sId
                            html_content = mycgi.compose_fusion_table(
                                cursor, dbN, geneN, sId, "in")
                            print '''
									<td><div class="tooltip_content">%s</div><div class="tooltip_link"><a href="#current">%s</a></div></td>
									''' % (html_content, value)
                        else:
                            html_content = mycgi.compose_fusion_table(
                                cursor, dbN, geneN, sId, "off")
                            print '''
									<td><div class="tooltip_content">%s</div><div class="tooltip_link"><a href="#current">%s</a></div></td>
									''' % (html_content, value)
                    elif outlier:
                        print '<td><font color=red><b>%s</b></font></td>' % value

                    elif tbl == 'array_cn' or tbl == 'cs_cn':  ##aCGH
                        (cl, bL) = cn_format(value)
                        print '<td><font color=%s>%s%s%s</font></td>' % (
                            cl, bL[0], value, bL[1])
                    elif tbl == 'xsq_cn':
                        (cl1, bL1) = cn_format(value)

                        if sId in cncorr_sId:
                            cursor.execute(
                                'select %s from xsq_cn_corr where samp_id="%s" and (%s)'
                                % (col, sId, cnd))
                            val_corr = ('%s' % fmt) % cursor.fetchone()[0]
                            (cl2, bL2) = cn_format(val_corr)
                            print '<td><font color=%s>%s%s%s</font>,<font color=%s>%s%s%s</font></td>' % (
                                cl1, bL1[0], value, bL1[1], cl2, bL2[0],
                                val_corr, bL2[1])
                        else:
                            print '<td><font color=%s>%s%s%s</font></td>' % (
                                cl1, bL1[0], value, bL1[1])
                    else:
                        print '<td>%s</td>' % value

            else:
                #grey out
                if (r_flag == False
                        and row[1] in ('splice_skip', 't_fusion',
                                       'splice_eiJunc', 'rpkm_gene_expr')
                    ) or (r_flag == False and d_flag == False
                          and row[1] in ('mutation_rxsq')) or (
                              (d_flag == False or p_flag == False)
                              and row[1] in ('xsq_loh')):
                    print '<td bgcolor=silver></td>'
                else:
                    print '<td></td>'

        print '</tr>'

    print('\n</table> </font>\n')
    return
示例#3
0
	display: none;
	padding: 5px 10px;
	border: #CACACA 1px solid;
	position: fixed;
	z-index: 9999;
	color: #0C0C0C;
	margin: 0 0 0 10px;
	-webkit-border-radius: 8px;
	-moz-border-radius: 8px;
	border-radius: 8px;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'''

if mode =='samp':
	print '<title>%s (%s)</title>' % (new_id,mycgi.db2dsetN(dbN)) # new ID
else:
	print '<title>%s (%s)</title>' % (dType,mycgi.db2dsetN(dbN))

print '''
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.js"></script>
<script type="text/javascript" src="/js/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript">
function filter(dType,geneInfoDB){
	$("#"+dType+" tbody tr:has(.not_"+geneInfoDB+")").hide()   
	$("#"+dType+" tbody tr:has(."+geneInfoDB+")").show()
}

$(document).ready(function() {

	function showTooltip(ele) {
示例#4
0
def main():

	## sample information

	if mode=='samp':

		print '<p><h4><a name="top"></a>%s <small> (%s)</small></h4></p> <p><ul>' % (new_id,mycgi.db2dsetN(dbN)) # new ID

		cursor.execute('select tag from sample_tag where samp_id="%s"' % (old_id)) # old ID
		tags = [x[0] for x in cursor.fetchall()]

		cursor.execute('select 1 from splice_normal where samp_id="%s" limit 1' % (old_id)) # old ID
		avail_RSq = cursor.fetchone()

		# panel_S
		print '<li>Panel: %s' % ', '.join(map(lambda x: x[6:], filter(lambda x: x.startswith('panel_'), tags)))

		# tum,inv
		tL = filter(lambda x: x.startswith('tum_') or x.startswith('inv_'), tags)
		tL.sort(lambda x,y: cmp(y,x))
		print '<li>Phenotype: %s' % ', '.join(tL)

		# data availability
		tL = filter(lambda x: x.startswith('XSeq_'), tags)
		if avail_RSq:
			tL.append('RNA-Seq') 
		print '<li>Available: %s' % ', '.join(tL)
			
		# matched
		text = ','.join(map(lambda x: x[5:], filter(lambda x: x.startswith('pair_'), tags)))
		print '<li>Matched: %s' % linkSamp(text).replace(',',', ')

		# normal
		print '<li>Normal: %s' % ', '.join(map(lambda x: x[7:], filter(lambda x: x.startswith('normal_'), tags)))

		if dbN == 'ircr1':
			cursor.execute('select tumor_frac from xsq_purity where samp_id="%s"' % (old_id)) # old ID
			tfrac = cursor.fetchone()
			print '<li>Tumor fraction (estimated from WXS): %s%%' % tfrac
		
		print '</ul>'

		tags = []
		for spec in specL:
			(dt,colL,tblN,cond,ordr) = spec
			tags.append(' <a href="#%s">%s</a> ' % (dt, dt))
		print '|'.join(tags)

		print '</p>'


	#census gene
	cursor.execute("select distinct gene_sym from common.census")
	census_gene = [x for (x,) in cursor.fetchall()]

	# drugbank
	cursor.execute("select distinct gene_sym from common.drugbank")
	drug_gene = [x for (x,) in cursor.fetchall()]

	# genes targeted by in-house HTS screening
	cursor.execute("select distinct gene_sym from common.scrn_drug")
	scrn_gene = [x for (x,) in cursor.fetchall()]

	# RTK
	rtk_gene= ['AATK','AATYK','AATYK2','AATYK3','ACH','ALK','anaplastic lymphoma kinase','ARK','ATP:protein-tyrosine O-phosphotransferase [ambiguous]','AXL','Bek','Bfgfr','BRT','Bsk','C-FMS','CAK','CCK4','CD115','CD135','CDw135','Cek1','Cek10','Cek11','Cek2','Cek3','Cek5','Cek6','Cek7','CFD1','CKIT','CSF1R','DAlk','DDR1','DDR2','Dek','DKFZp434C1418','Drosophila Eph kinase','DRT','DTK','Ebk','ECK','EDDR1','Eek','EGFR','Ehk2','Ehk3','Elk','EPH','EPHA1','EPHA2','EPHA6','EPHA7','EPHA8','EPHB1','EPHB2','EPHB3','EPHB4','EphB5','ephrin-B3 receptor tyrosine kinase','EPHT','EPHT2','EPHT3','EPHX','ERBB','ERBB1','ERBB2','ERBB3','ERBB4','ERK','Eyk','FGFR1','FGFR2','FGFR3','FGFR4','FLG','FLK1','FLK2','FLT1','FLT2','FLT3','FLT4','FMS','Fv2','HBGFR','HEK11','HEK2','HEK3','HEK5','HEK6','HEP','HER2','HER3','HER4','HGFR','HSCR1','HTK','IGF1R','INSR','INSRR','insulin receptor protein-tyrosine kinase','IR','IRR','JTK12','JTK13','JTK14','JWS','K-SAM','KDR','KGFR','KIA0641','KIAA1079','KIAA1459','Kil','Kin15','Kin16','KIT','KLG','LTK','MCF3','Mdk1','Mdk2','Mdk5','MEhk1','MEN2A/B','Mep','MER','MERTK','MET','Mlk1','Mlk2','Mrk','MST1R','MTC1','MUSK','Myk1','N-SAM','NEP','NET','Neu','neurite outgrowth regulating kinase','NGL','NOK','nork','novel oncogene with kinase-domain','Nsk2','NTRK1','NTRK2','NTRK3','NTRK4','NTRKR1','NTRKR2','NTRKR3','Nuk','NYK','PCL','PDGFR','PDGFRA','PDGFRB','PHB6','protein-tyrosine kinase [ambiguous]','protein tyrosine kinase [ambiguous]','PTK','PTK3','PTK7','receptor protein tyrosine kinase','RET','RON','ROR1','ROR2','ROS1','RSE','RTK','RYK','SEA','Sek2','Sek3','Sek4','Sfr','SKY','STK','STK1','TEK','TIE','TIE1','TIE2','TIF','TKT','TRK','TRKA','TRKB','TRKC','TRKE','TYK1','TYRO10','Tyro11','TYRO3','Tyro5','Tyro6','TYRO7','UFO','VEGFR1','VEGFR2','VEGFR3','Vik','YK1','Yrk']

	# CancerScan
	cs_gene = ['ABL1','AKT1','AKT2','AKT3','ALK','APC','ARID1A','ARID1B','ARID2','ATM','ATRX','AURKA','AURKB','BCL2','BRAF','BRCA1','BRCA2','CDH1','CDK4','CDK6','CDKN2A','CSF1R','CTNNB1','DDR2','EGFR','EPHB4','ERBB2','ERBB3','ERBB4','EWSR1','EZH2','FBXW7','FGFR1','FGFR2','FGFR3','FLT3','GNA11','GNAQ','GNAS','HNF1A','HRAS','IDH1','IDH2','IGF1R','ITK','JAK1','JAK2','JAK3','KDR','KIT','KRAS','MDM2','MET','MLH1','MPL','MTOR','NF1','NOTCH1','NPM1','NRAS','NTRK1','PDGFRA','PDGFRB','PIK3CA','PIK3R1','PTCH1','PTCH2','PTEN','PTPN11','RB1','RET','ROS1','SMAD4','SMARCB1','SMO','SRC','STK11','SYK','TMPRSS2','TOP1','TP53','VHL']
	
	## variant information

	if mode=='type':
		tableL = [specL[dTypeH[dType][0]]]
	else:
		tableL = specL

	print '<font size=2>'

	for spec in tableL:

		(dt,colL,tblN,cond,ordr) = spec

		if mode=='type':
			colL = ["samp_id"] + colL

		if dbN not in ['tcga1','ircr1','ccle1'] and tblN in ['t_outlier','t_expr']:
			continue
		elif dbN not in ['tcga1','ircr1','ccle1','CancerSCAN'] and tblN in ['xsq_cn']:
			continue
		elif dbN not in ['CancerSCAN'] and tblN in ['t_mut_cs','cs_cn']:
			continue

		if mode=='samp':
			cursor.execute("select %s from %s where (samp_id = '%s' or samp_id='%s') and %s order by %s" % (','.join(colL), tblN, old_id, new_id, cond, ordr)) # old ID
		else:
			cursor.execute("select %s from %s where %s order by %s" % (','.join(colL), tblN, dTypeH[dt][1], ordr))

		data = cursor.fetchall()

		print '<a name="%s"></a>' % (dt)
		
		# theader
		if mode=='samp':
			if dt in ['Fusion','ExonSkipping','3pDeletion']:
				print '<br><h5><a href="ircr_samp.py?dbN=%s&dType=%s">%s</a> (%s, %s, %s):' % (dbN,dt,dt,len(data),('All' if cond=='True' else cond),ordr)
			else:
				print '<br><h5>%s (%s, %s, %s):' % (dt,len(data),('All' if cond=='True' else cond),ordr)
		else:
			print '<h5><p id="%s_"><b>%s</b> (%s, %s, %s):</p>' % (dt,dt,len(data),dTypeH[dt][1],ordr)
		if dt in ['Mutation','Mutation_CS']:
			flt_germ=''' | <a href="#current" onclick='filter("%s","somatic")'>Filter</a>''' % dt
		else:
			flt_germ=''

		print '''
			<small>
			<a name="%s"></a><a href="#top">Page Top</a> |
			<a href="#current" onclick="$('#%s tbody tr').show()">All</a> | <a href="#current" onclick='filter("%s","census")'>Census</a> | <a href="#current" onclick='filter("%s","rtk")'>RTK</a> | <a href="#current" onclick='filter("%s","drugbank")'>Drugbank</a> | <a href="#current" onclick="$('#%s tbody tr').hide()">None</a> | <a href="#current" onclick='filter("%s","scrn")'>Screening</a> | <a href="#current" onclick='filter("%s","regulatory")'>Regulatory</a> | <a href="#current" onclick='filter("%s","cancerscan")'>CancerScan</a>%s</small></h5>''' % tuple([dt,]*9+[flt_germ])

		if dt == 'xCN':
			cursor.execute("select samp_id from sample_tag where samp_id = '%s' and tag like 'XSeq_%%'" % old_id) # old ID
			results = cursor.fetchall()
			if len(results) > 0:
				fL = glob('/EQL1/NSL/WXS/results/CNA/%s*_SS.*traj.png' % old_id) + glob('/EQL1/NSL/WXS/results/CNA/%s*_TS.*traj.png' % old_id) # old ID
				if len(fL) > 0:
					print '<div><img src="http://119.5.134.58/WXS_CNA/%s" title="%s"></img><p><font color="red">%s</font></p></div>' % (fL[0].split('/')[-1], mycgi.ID_WARN, mycgi.ID_WARN)

				fL = glob('/EQL3/pipeline/CNA_corr/*%s*/%s*.png' % (old_id,old_id)) # old ID
				if len(fL) > 0:
					print '<p>Corrected with the estimated tumor purity</p>'
					print '<div><img src="http://119.5.134.58/pipeline3/CNA_corr/%s" title="%s"></img><p><font color="red">%s</font></p></div>' % ('/'.join(fL[0].split('/')[-2:]), mycgi.ID_WARN, mycgi.ID_WARN)

				if len(glob('/EQL1/NSL/WXS/results/CNA/%s*2pl.png' % old_id)) > 0: # old ID
					basename = glob('/EQL1/NSL/WXS/results/CNA/%s*2pl.png' % old_id)[0].split('/')[-1] # old ID
					print '<a href="http://119.5.134.58/WXS_CNA/%s" target="_blank">Comparison with array CGH</a><p><font color="red">%s</font></p>' % (basename, mycgi.ID_WARN)
		if dt == 'csCN':
			if len(glob('/EQL1/NSL/WXS/results/CNA/%s*_CS*traj.png' % old_id)) > 0: # old ID
				sname = glob('/EQL1/NSL/WXS/results/CNA/%s*CS*traj.png' % old_id)[0] # old ID
				print '<div><img src="http://119.5.134.58/WXS_CNA/%s"></img></div>' % sname.split('/')[-1]
		if dt == 'ExprCS':
			if len(glob('/EQL1/NSL/RNASeq/results/expression/%s_CS_expr.png' % old_id)) > 0: # old ID
				print '<div><img src="http://119.5.134.58/RSQ_RPKM/%s_CS_expr.png" title="%s"></img><p><font color="red">%s</font></p></div>' % (old_id, mycgi.ID_WARN, mycgi.ID_WARN) # old ID


		print '''
			<table border="1.5" cellpadding="0" cellspacing="0" id="%s">
			<thead>''' % dt

		print '<tr>'
		for colN in colL:
			print '<td><b> %s </b></td>' % colN.split(' ')[-1]
		print '</tr></thead><tbody>'

		# tbody
		for row in data:
			print '<tr>'

			for j in range(len(row)) :
				
				colN = colL[j].split(' ')[-1]

				content = str(row[j]).replace(',',', ').replace('|',', ')

				cls = []
				
				if colN in ('gene_sym','gene_symL','gene_sym1','gene_sym2'):
					geneL = row[j].split(',')

					if any (g in geneL for g in census_gene):
						cls.append("census")
					else:
						cls.append("not_census")

					if any (g in geneL for g in drug_gene):
						cls.append("drugbank")
					else:
						cls.append("not_drugbank")

					if any (g in geneL for g in scrn_gene):
						cls.append("scrn")
					else:
						cls.append("not_scrn")

					if any (g in geneL for g in rtk_gene):
						cls.append("rtk")
					else:
						cls.append("not_rtk")

					if any (g in geneL for g in cs_gene):
						cls.append("cancerscan")
					else:
						cls.append("not_cancerscan")

					linkL = []

					for g in geneL:
						cursor.execute('select 1 from common.hugo where gene_sym="%s"' % g)
						if cursor.fetchone():
							linkL.append('<a href="ircr.py?dbN=%s&geneN=%s" class="%s"> %s </a>' % (dbN,g,' '.join(cls),g))
						else:
							linkL.append('<a class="%s">%s</a>' % (' '.join(cls),g))

					print '<td>%s</td>' % ', '.join(linkL)
					
				elif colN == 'ch_type':
					if 'regulatory' in row[j] or 'TFBS_' in row[j] or 'TF_binding_site_' in row[j]:
						cls.append("regulatory")
					else:
						cls.append("not_regulatory")
					content = '<a class="%s">%s</a>' % (' '.join(cls), content)
					print '<td nowrap> %s </td>' % content
				elif colN == 'nIRCRb':
					if int(row[j])<1:
						cls.append('somatic')
					else:
						cls.append('not_somatic')
					content = '<a class="%s">%s</a>' % (' '.join(cls), content)
					print '<td> %s </td>' % content
				elif colN == 'cosmic':
					tcga = ''
					cosmic=''
					if 'tcga:' in content and dbN=='CancerSCAN':
						tcga = re.search('.*, tcga:(.*)', content).group(1)
						tcga = '''<div class="tooltip_content">%s</div><div class="tooltip_link"><a href="#current">tcga</a></div>''' % (tcga)
					if 'cosmic:' in content and dbN =='CancerSCAN':
						cosmic = re.search('cosmic:(.*), .*', content).group(1)
						cosmic = '''<div class="tooltip_content">%s</div><div class="tooltip_link"><a href="#current">cosmic</a></div>''' % (cosmic)
					print '<td style=white-space:nowrap;">%s%s</td>' % (tcga, cosmic)
				elif colN == 'samp_id':
					print '<td nowrap> <a href="ircr_samp.py?dbN=%s&sId=%s"> %s </a> </td>' % (dbN,content,content) # new ID
				elif 'coord' in colN:
					if content[0] == 'c':
						print '<td nowrap><a href="http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg19&position=%s"> %s </a></td>' % (content,content)
					else:
						print '<td nowrap><a href="http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg19&position=%s"> %s </a></td>' % (content[1:],content)
				else:
					print '<td> %s </td>' % content

			print '</tr>'

		print '</tbody></table>'

	print '</font><br><br>'

	return
示例#5
0
文件: oncoprint.py 项目: SMC1/JK1
<link href="js/jquery.qtip.min.css" type="text/css" rel="stylesheet">
<link href="js/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">

<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/bootstrap/js/bootstrap.min.js"></script>
<script src="js/d3.v2.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/jquery-ui-1.8.14.custom.min.js"></script>
<script src="js/jquery.qtip.min.js"></script>

<script src="./js/MemoSort.js"></script>
<script src="./js/js_oncoprint/oncoprint.js"></script>
<script src="./js/js_oncoprint/QueryGeneData.js"></script>
<script src="./js/oncoprint_demo.js"></script>

<script type="text/javascript">''' % mycgi.db2dsetN(dbN)

if dbN=='ircr1':
	print '''var $ex_EGFR = "Rsq\\rEGFR:SKIP:25-27\\rEGFR:SKIP:25-26\\rEGFR:SKIP:27-27\\rEGFR:3pDEL:24/28\\rEGFR:3pDEL:27/28\\rEGFR:3pDEL:26/28\\rEGFR:SKIP:2-7\\rEGFR:SKIP:12-13\\rEGFR:MUTR:A289\\rEGFR:MUTX:A289\\rEGFR:MUTR:R222\\rEGFR:MUTX:R222\\rEGFR:MUTR:G598\\rEGFR:MUTX:G598\\rEGFR:MUTR:R108\\rEGFR:MUTX:R108\\rEGFR:CNA\\rEGFR:xCN\\rEGFR:RPKM\\rEGFR:EXPR\\rXsq";'''
else:
	print '''var $ex_EGFR = "Rsq\\rEGFR:SKIP:25-27\\rEGFR:SKIP:25-26\\rEGFR:SKIP:27-27\\rEGFR:3pDEL:24/28\\rEGFR:3pDEL:27/28\\rEGFR:3pDEL:26/28\\rEGFR:SKIP:2-7\\rEGFR:SKIP:12-13\\rEGFR:MUTX:A289\\rEGFR:MUTX:R222\\rEGFR:MUTX:G598\\rEGFR:MUTX:R108\\rEGFR:CNA\\rEGFR:RPKM\\rEGFR:EXPR\\rXsq";'''

ex_cs='var $ex_CancerScan = "Rsq\\r'
cs_gene = ['ABL1','AKT1','AKT2','AKT3','ALK','APC','ARID1A','ARID1B','ARID2','ATM','ATRX','AURKA','AURKB','BCL2','BRAF','BRCA1','BRCA2','CDH1','CDK4','CDK6','CDKN2A','CSF1R','CTNNB1','DDR2','EGFR','EPHB4','ERBB2','ERBB3','ERBB4','EWSR1','EZH2','FBXW7','FGFR1','FGFR2','FGFR3','FLT3','GNA11','GNAQ','GNAS','HNF1A','HRAS','IDH1','IDH2','IGF1R','ITK','JAK1','JAK2','JAK3','KDR','KIT','KRAS','MDM2','MET','MLH1','MPL','MTOR','NOTCH1','NPM1','NRAS','NTRK1','PDGFRA','PDGFRB','PIK3CA','PIK3R1','PTCH1','PTCH2','PTEN','PTPN11','RB1','RET','ROS1','SMAD4','SMARCB1','SMO','SRC','STK11','SYK','TMPRSS2','TOP1','TP53','VHL']
for gene in cs_gene:
	ex_cs += '%s:RPKM\\r' % gene
ex_cs+= '";'
print ex_cs

print '''var $ex_IDH1 = "Rsq\\rIDH1:MUTR:R132\\rIDH1:MUTX:R132\\rXsq";
示例#6
0
文件: ircr.py 项目: SMC1/JK1
def main(dbN, geneN):

    (con, cursor) = mycgi.connectDB(db=dbN)

    # prep RNA-Seq data availability table
    cursor.execute("create temporary table t_avail_RNASeq as select distinct samp_id from rpkm_gene_expr")

    # prep exonSkip info
    cursor.execute(
        'select delExons,frame,loc1,loc2, count(*) cnt from splice_skip where gene_sym = "%s" and nPos>=5 group by delExons order by count(*) desc'
        % geneN
    )
    results = cursor.fetchall()

    conditionL_exonSkip = []

    for (delExons, frame, loc1, loc2, cnt) in results:

        if ":Y" in frame:
            frame_code = "in"
        elif ":N" in frame:
            frame_code = "off"
        else:
            frame_code = "utr"

        conditionL_exonSkip.append(
            [
                (
                    "nReads",
                    "splice_skip",
                    'loc1="%s" and loc2="%s" and nPos>=5' % (loc1, loc2),
                    "%3d",
                    "%s<br><sup>(n=%s, %s)</sup>" % (delExons.split(",")[0], cnt, frame_code),
                ),
                # 			('avg(nReads)', 'splice_normal', 'loc1="%s" or loc2="%s"' % (loc1,loc2), '%d') ])
                ("sum(nReads)", "splice_normal", 'loc1="%s"' % (loc1,), "%d"),
            ]
        )

        # prep mutation info
    # 		where gene_symL like "%s%s%s" and ch_type != "synonymous_variant" and ch_type != "nc_transcript_variant,synonymous_variant" and ch_type != "intron_variant,synonymous_variant" \
    if dbN == "CancerSCAN":
        cursor.execute(
            'create temporary table t_mut as \
			select concat(substring(chrom,4,4),":",cast(chrSta as char),ref,">",alt) as ch_pos, ch_dna,ch_aa,ch_type,cosmic from mutation_cs \
			where find_in_set("%s",gene_sym) > 0 and ch_type != "synonymous_variant" and ch_type != "nc_transcript_variant,synonymous_variant" and ch_type != "intron_variant,synonymous_variant" \
			and ch_type != "nc_transcript_variant" and ch_type != "intron_variant,nc_transcript_variant" and ch_type != "intron_variant" and ch_type != "Substitution - coding silent"\
			and nReads_alt<>2 order by ch_type desc'
            % (geneN)
        )
    else:
        cursor.execute(
            'create temporary table t_mut as \
			select concat(substring(chrom,4,4),":",cast(chrSta as char),ref,">",alt) as ch_pos, ch_dna,ch_aa,ch_type,cosmic from mutation_rxsq \
			where find_in_set("%s",gene_symL) > 0 and ch_type != "synonymous_variant" and ch_type != "nc_transcript_variant,synonymous_variant" and ch_type != "intron_variant,synonymous_variant" \
			and ch_type != "nc_transcript_variant" and ch_type != "intron_variant,nc_transcript_variant" and ch_type != "intron_variant" and ch_type != "Substitution - coding silent"\
			and nReads_alt<>2 order by ch_type desc'
            % (geneN)
        )

    cursor.execute("select *,count(*) cnt from t_mut group by ch_pos order by count(*) desc, cosmic desc")
    results = cursor.fetchall()

    conditionL_mutation = []

    for (ch_pos, ch_dna, ch_aa, ch_type, cosmic, cnt) in results:

        ch_aa = ch_aa.replace(",", "<br>")

        if (dbN == "CancerSCAN" and "cosmic" in cosmic) or (dbN != "CancerSCAN" and cosmic):
            cosmic_fmt = '<font color="red">%s</font><br><sup>(n=%d, %s)</sup>'

        else:
            cosmic_fmt = "%s<br><sup>(n=%d, %s)</sup>"

        if ch_aa:
            cnd = ch_aa
        elif ch_dna:
            cnd = ch_dna
        else:
            cnd = ch_pos

        if dbN == "CancerSCAN":
            conditionL_mutation.append(
                [
                    (
                        "nReads_alt",
                        "mutation_cs",
                        'nReads_alt<>2 and concat(substring(chrom,4,4),":",cast(chrSta as char),ref,">",alt)="%s"'
                        % ch_pos,
                        "%d",
                        cosmic_fmt % (cnd, cnt, mutation_map(ch_type, dbN)),
                    ),
                    (
                        "nReads_ref",
                        "mutation_cs",
                        'nReads_alt<>2 and concat(substring(chrom,4,4),":",cast(chrSta as char),ref,">",alt)="%s"'
                        % ch_pos,
                        "%d",
                    ),
                ]
            )
        else:
            conditionL_mutation.append(
                [
                    (
                        "nReads_alt,r_nReads_alt",
                        "mutation_rxsq",
                        'nReads_alt<>2 and concat(substring(chrom,4,4),":",cast(chrSta as char),ref,">",alt)="%s"'
                        % ch_pos,
                        "%d",
                        cosmic_fmt % (cnd, cnt, mutation_map(ch_type, dbN)),
                    ),
                    (
                        "nReads_ref,r_nReads_ref",
                        "mutation_rxsq",
                        'nReads_alt<>2 and concat(substring(chrom,4,4),":",cast(chrSta as char),ref,">",alt)="%s"'
                        % ch_pos,
                        "%d",
                    ),
                ]
            )

            # prep fusion table
    cursor.execute(
        'create temporary table t_fusion as \
		select samp_id,locate(":Y",frame)>1 frame,count(nPos) nEvents \
		from splice_fusion where nPos>=2 and (find_in_set("%s",gene_sym1) or find_in_set("%s",gene_sym2)) group by samp_id, locate(":Y",frame)>1'
        % (geneN, geneN)
    )

    # prep eiJunc info
    cursor.execute(
        'select loc,juncAlias, count(*) cnt from splice_eiJunc where gene_sym="%s" and nReads>=10 group by loc' % geneN
    )
    results = cursor.fetchall()

    conditionL_eiJunc = []

    for (loc, juncAlias, cnt) in results:
        conditionL_eiJunc.append(
            [
                (
                    "nReads",
                    "splice_eiJunc",
                    'loc="%s" and nReads>=10' % loc,
                    "%3d",
                    "%s<br><sup>(n=%s)</sup>" % (juncAlias, cnt),
                ),
                ("sum(nReads)", "splice_normal", 'loc1="%s"' % (loc,), "%d"),
            ]
        )

        # outlier
    outlier_sId = []

    if dbN in ["ircr1", "tcga1", "ccle1"]:
        cursor.execute(
            'select samp_id, expr_MAD from array_gene_expr_MAD mad, gene_expr_stat stat where mad.gene_sym = stat.gene_sym and (mad.expr_MAD >= stat.q75 + 3*(stat.q75 - stat.q25) or mad.expr_MAD <= stat.q25 - 3*(stat.q75 - stat.q25)) and mad.gene_sym = "%s"'
            % geneN
        )
        results3 = cursor.fetchall()

        for i in range(len(results3)):
            outlier_sId.append(results3[i][0])

            ## corrected CN value available?
    cncorr_sId = []
    if dbN in ["ircr1"]:
        cursor.execute('select distinct samp_id from xsq_purity where tumor_frac != "ND"')
        resultsCorr = cursor.fetchall()
        for i in range(len(resultsCorr)):
            cncorr_sId.append(resultsCorr[i][0])
    normal_sId = []
    if dbN in ["ircr1"]:
        cursor.execute("select distinct samp_id from xsq_purity")
        tttt = cursor.fetchall()
        for i in range(len(tttt)):
            normal_sId.append(tttt[i][0])

    conditionL = (
        conditionL_preH[dbN] + conditionL_mutation + conditionL_fusion + conditionL_exonSkip + conditionL_eiJunc
    )

    print '<p><h4>%s status of %s panel <small><a href="http://www.genecards.org/cgi-bin/carddisp.pl?gene=%s">[GeneCard]</a> <a href="http://www.ncbi.nlm.nih.gov/pubmed/?term=%s">[PubMed]</a></small></h4></p>' % (
        geneN,
        mycgi.db2dsetN(dbN),
        geneN,
        geneN,
    )

    # census
    cursor.execute('select tumor_soma, tumor_germ, syndrome, mut_type from common.census where gene_sym="%s"' % geneN)
    census = cursor.fetchall()

    print ('\n<font size=2> <table border="1" cellpadding="0" cellspacing="0">')
    print (
        "<tr>\n<td rowspan=2>Census</td>\n<td>tumor_soma</td>\n<td>tumor_germ</td>\n<td>syndrome</td>\n<td>mut_type</td>\n</tr>\n"
    )

    if len(census) != 0:
        print (
            "<tr>\n<td>%s</td>\n<td>%s</td>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
            % (census[0][0], census[0][1], census[0][2], census[0][3])
        )
    else:
        print ("<tr>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n")

        # drugbank
    cursor.execute('select drug from common.drugbank where gene_sym="%s"' % geneN)
    drug = [x for (x,) in cursor.fetchall()]

    print ('\n<font size=2> <table border="1" cellpadding="0" cellspacing="0">')
    print ("<br><tr>\n<td>Drug</td>\n")
    print ("<td>%s</td>\n</tr>\n" % ("</br>\n".join(drug)))

    # pathway
    cursor.execute('select biocarta_id, biocarta_desc from common.biocarta where gene_sym="%s"' % geneN)
    biocarta = cursor.fetchall()

    cursor.execute('select kegg_id, kegg_desc from common.kegg where gene_sym="%s"' % geneN)
    kegg = cursor.fetchall()

    cursor.execute('select go_id, go_desc from common.go where gene_sym="%s"' % geneN)
    go = cursor.fetchall()

    print ('\n<font size=2> <table border="1" cellpadding="0" cellspacing="0">')
    print ("<br><tr>\n<td>Biocarta</td>\n<td>KEGG</td>\n<td>GO</td>\n</tr>\n")
    print ('<tr><td><div style="width:100%; height:50px; overflow:auto">')
    for (id, desc) in biocarta:
        print ('<a href="http://cgap.nci.nih.gov/Pathways/BioCarta/%s">%s</br>' % (id, desc))
    print ('</td>\n<td><div style="width:100%; height:50px; overflow:auto">')
    for (id, desc) in kegg:
        print ('<a href="http://www.genome.jp/dbget-bin/www_bget?pathway+%s">%s</br>' % (id, desc))
    print ('</td>\n<td><div style="width:100%; height:50px; overflow:auto">')
    for (id, desc) in go:
        print ('<a href="http://amigo.geneontology.org/cgi-bin/amigo/term_details?term=GO:%s">%s</br>' % (id, desc))
    print ("</div></td>\n</tr>\n")

    if dbN == "CancerSCAN":
        cursor.execute(
            """CREATE TEMPORARY TABLE t_id AS SELECT DISTINCT samp_id FROM mutation_cs UNION SELECT DISTINCT samp_id FROM cs_cn"""
        )
    elif dbN == "tcga1":
        cursor.execute(
            "create temporary table t_id as \
		select distinct samp_id from array_gene_expr union select distinct samp_id from array_cn union select distinct samp_id from splice_normal union select distinct samp_id from mutation_rxsq union select distinct samp_id from rpkm_gene_expr"
        )
    else:
        cursor.execute(
            "create temporary table t_id as \
		select distinct samp_id from array_gene_expr union select distinct samp_id from array_cn union select distinct samp_id from splice_normal union select distinct samp_id from mutation_rxsq union select distinct samp_id from rpkm_gene_expr union select distinct samp_id from xsq_cn"
        )

    cursor.execute("alter table t_id add index (samp_id)")

    cursor.execute('create temporary table t_expr as select * from array_gene_expr where gene_sym="%s"' % geneN)
    # cursor.execute('create temporary table t_cn as select * from xsq_cn where gene_sym="%s"' % geneN)

    cursor.execute("alter table t_expr add index (samp_id,gene_sym)")
    # cursor.execute('alter table t_cn add index (samp_id,gene_sym)')

    cursor.execute("select samp_id from t_id left join t_expr using (samp_id) order by z_score desc")
    # cursor.execute('select samp_id from t_id left join t_cn using (samp_id) order by value_log2 desc')

    results = cursor.fetchall()

    numTotSamp = len(results)

    print ('\n<font size=3> <table border="1" cellpadding="0" cellspacing="0">')

    # header: row1
    print '<br><tr>\n<td rowspan=2><div class="verticaltext" align="middle">samples<br><sup>n=%s</sup></div></td>' % numTotSamp,

    for i in range(len(conditionL)):

        row = conditionL[i]

        if type(row) == list:
            row = row[0]

        if i < len(conditionL_preH[dbN]):
            if ("tag" in row[1]) or ("t_avail" in row[1]) or ("subtype" in row[1]) or ("purity" in row[1]):
                cursor.execute("select count(*) from %s where %s" % (row[1], row[2]))
            elif "loh" in row[1]:
                cursor.execute(
                    "select count(distinct samp_id) from xsq_purity"
                )  # of samples for which purity pipeline was applied = # of samples with matched blood exome
            else:
                cursor.execute('select count(*) from %s where %s and gene_sym ="%s"' % (row[1], row[2], geneN))

            count = cursor.fetchone()
            if "MAD" in row[4]:
                print (
                    '<td rowspan=2 align="middle"><div class="verticaltext">%s, n=%s)</sup></div></td>'
                    % (row[-1], count[0])
                )
            else:
                print (
                    '<td rowspan=2 align="middle"><div class="verticaltext">%s<br><sup>(n=%s)</sup></div></td>'
                    % (row[-1], count[0])
                )
        else:
            if i == len(conditionL_preH[dbN]) and len(conditionL_mutation) > 0:
                print ('<td align="middle" colspan=%s>mutation (mt/wt)</td>' % len(conditionL_mutation))
            elif i == len(conditionL_preH[dbN]) + len(conditionL_mutation):
                print (
                    '<td align="middle" colspan=%s><a href="ircr_samp.py?dbN=%s&dType=Fusion">fusion</a></td>'
                    % (len(conditionL_fusion), dbN)
                )
            elif (
                i == len(conditionL_preH[dbN]) + len(conditionL_mutation) + len(conditionL_fusion)
                and len(conditionL_exonSkip) > 0
            ):
                print (
                    '<td align="middle" colspan=%s><a href="ircr_samp.py?dbN=%s&dType=ExonSkipping">exonSkip</a> (mt/wt)</td>'
                    % (len(conditionL_exonSkip), dbN)
                )
            elif (
                i
                == len(conditionL_preH[dbN])
                + len(conditionL_mutation)
                + len(conditionL_fusion)
                + len(conditionL_exonSkip)
                and len(conditionL_eiJunc) > 0
            ):
                print (
                    '<td align="middle" colspan=%s><a href="ircr_samp.py?dbN=%s&dType=3pDeletion">3p deletion</a> (mt/wt)</td>'
                    % (len(conditionL_eiJunc), dbN)
                )

    print ("\n</tr>\n")

    # header: row2
    print "<tr>\n",

    for i in range(len(conditionL)):

        row = conditionL[i]

        if type(row) == list:
            row = row[0]

        if i < len(conditionL_preH[dbN]):
            pass
        else:
            print ('<td height="100"><div class="verticaltext" align="middle">%s</div></td>' % row[-1])

    print ("\n</tr>\n")

    for (sId,) in results:

        print "<tr>",
        # 		print '<td nowrap><a href="ircr_samp.py?dbN=%s&sId=%s">%s</td>' % (dbN,sId,sId),
        new_id = mycgi.get_new_id(sId)
        print '<td nowrap><a href="ircr_samp.py?dbN=%s&sId=%s">%s</td>' % (dbN, new_id, new_id),

        d_flag = None
        r_flag = None

        for row in conditionL:

            outlier = None

            if type(row) == list:
                row_wt = row[1]
                row = row[0]
            else:
                row_wt = None

            (col, tbl, cnd, fmt) = row[:4]

            cursor.execute('show columns from %s like "gene_sym"' % tbl)

            if cursor.fetchone():
                cnd += ' and gene_sym="%s"' % geneN

            if tbl == "mutation_rxsq":
                cursor.execute('select distinct %s from %s where samp_id="%s" and (%s)' % (col, tbl, sId, cnd))
            else:
                cursor.execute('select %s from %s where samp_id="%s" and (%s)' % (col, tbl, sId, cnd))

            results2 = cursor.fetchall()

            if len(results2) > 1:
                print sId
                raise Exception

            if type(row) == tuple and row[-1] == "RSq":

                if len(results2) > 0:
                    r_flag = True
                else:
                    r_flag = False

            if type(row) == tuple and row[-1] == "XSq":

                if len(results2) > 0:
                    d_flag = True
                else:
                    d_flag = False

            if sId not in normal_sId:  # flag for matched normal
                p_flag = False
            else:
                p_flag = True

            if type(row) == tuple and row[-1] == "expr<br><sup>(MAD":

                if sId in outlier_sId:
                    outlier = True
                else:
                    outlier = False

            if len(results2) == 1:  # and results2[0][0] not in (0,'0'):

                value = ("%s" % fmt) % results2[0][0]

                if len(results2[0]) >= 2:
                    n_value = ("%s" % fmt) % results2[0][1]
                else:
                    n_value = 0

                if row_wt:

                    (col, tbl, cnd, fmt) = row_wt[:4]

                    if tbl == "mutation_rxsq":
                        cursor.execute('select distinct %s from %s where samp_id="%s" and %s' % (col, tbl, sId, cnd))
                    else:
                        cursor.execute('select %s from %s where samp_id="%s" and %s' % (col, tbl, sId, cnd))

                    results_wt = cursor.fetchone()

                    n_count_wt = 0

                    if results_wt[0]:
                        count_wt = ("%s" % fmt) % results_wt[0]
                    else:
                        count_wt = 0

                    if len(results_wt) >= 2:
                        count_wt = ("%s" % fmt) % results_wt[0]
                        n_count_wt = ("%s" % fmt) % results_wt[1]

                    if row[1] == "mutation_rxsq":

                        # 						if int(n_value)!=0 and int(n_count_wt)!=0 and int(value)!=0 and int(count_wt)!=0:
                        if int(n_value) != 0 and int(value) != 0:
                            if (
                                int(value) > (int(value) + int(count_wt)) * cutoff
                                and int(n_value) > (int(n_value) + int(n_count_wt)) * cutoff
                            ):
                                print "<td><font color=red><b>%s</b></font><sub>/%s</sub>,<font color=468847><b>%s</b><sub>/%s</sub></font></td>" % (
                                    value,
                                    count_wt,
                                    n_value,
                                    n_count_wt,
                                ),
                            elif int(n_value) > (int(n_value) + int(n_count_wt)) * cutoff:
                                print "<td>%s<sub>/%s</sub>,<font color=468847><b>%s</b><sub>/%s</sub></font></td>" % (
                                    value,
                                    count_wt,
                                    n_value,
                                    n_count_wt,
                                ),
                            elif int(value) > (int(value) + int(count_wt)) * cutoff:
                                print "<td><font color=red><b>%s</b></font><sub>/%s</sub>,<font color=468847>%s<sub>/%s</sub></font></td>" % (
                                    value,
                                    count_wt,
                                    n_value,
                                    n_count_wt,
                                ),
                            else:
                                print "<td>%s<sub>/%s</sub>,<font color=468847>%s<sub>/%s</sub></font></td>" % (
                                    value,
                                    count_wt,
                                    n_value,
                                    n_count_wt,
                                ),

                        elif int(value) == 0 and int(count_wt) == 0:  ## no exome
                            if int(n_value) > (int(n_value) + int(n_count_wt)) * cutoff:
                                print "<td><font color=468847><b>%s</b><sub>/%s</sub></font></td>" % (
                                    n_value,
                                    n_count_wt,
                                ),
                            else:
                                print "<td><font color=468847>%s<sub>/%s</sub></font></td>" % (n_value, n_count_wt),
                        elif int(n_value) == 0 and int(n_count_wt) == 0:  ## no normal
                            if int(value) > (int(value) + int(count_wt)) * cutoff:
                                print "<td><font color=red><b>%s</b></font><sub>/%s</sub></td>" % (value, count_wt),
                            else:
                                print "<td>%s<sub>/%s</sub></td>" % (value, count_wt),

                    else:
                        if int(value) > (int(value) + int(count_wt)) * cutoff:
                            tmp = row[4].split("<br>")[0].split("/")
                            if len(tmp) > 1 and tmp[0] == tmp[1]:
                                print "<td>%s<sub>/%s</sub></td>" % (value, count_wt),
                            else:
                                print "<td><font color=red><b>%s</b></font><sub>/%s</sub></td>" % (value, count_wt),
                        else:
                            print "<td>%s<sub>/%s</sub></td>" % (value, count_wt),

                else:
                    if row[1] == "t_fusion":
                        html_content = ""
                        if row[4] == "in":
                            print '<a name="%s"></a>' % sId
                            html_content = mycgi.compose_fusion_table(cursor, dbN, geneN, sId, "in")
                            print """
									<td><div class="tooltip_content">%s</div><div class="tooltip_link"><a href="#current">%s</a></div></td>
									""" % (
                                html_content,
                                value,
                            )
                        else:
                            html_content = mycgi.compose_fusion_table(cursor, dbN, geneN, sId, "off")
                            print """
									<td><div class="tooltip_content">%s</div><div class="tooltip_link"><a href="#current">%s</a></div></td>
									""" % (
                                html_content,
                                value,
                            )
                    elif outlier:
                        print "<td><font color=red><b>%s</b></font></td>" % value

                    elif tbl == "array_cn" or tbl == "cs_cn":  ##aCGH
                        (cl, bL) = cn_format(value)
                        print "<td><font color=%s>%s%s%s</font></td>" % (cl, bL[0], value, bL[1])
                    elif tbl == "xsq_cn":
                        (cl1, bL1) = cn_format(value)

                        if sId in cncorr_sId:
                            cursor.execute('select %s from xsq_cn_corr where samp_id="%s" and (%s)' % (col, sId, cnd))
                            val_corr = ("%s" % fmt) % cursor.fetchone()[0]
                            (cl2, bL2) = cn_format(val_corr)
                            print "<td><font color=%s>%s%s%s</font>,<font color=%s>%s%s%s</font></td>" % (
                                cl1,
                                bL1[0],
                                value,
                                bL1[1],
                                cl2,
                                bL2[0],
                                val_corr,
                                bL2[1],
                            )
                        else:
                            print "<td><font color=%s>%s%s%s</font></td>" % (cl1, bL1[0], value, bL1[1])
                    else:
                        print "<td>%s</td>" % value

            else:
                # grey out
                if (
                    (r_flag == False and row[1] in ("splice_skip", "t_fusion", "splice_eiJunc", "rpkm_gene_expr"))
                    or (r_flag == False and d_flag == False and row[1] in ("mutation_rxsq"))
                    or ((d_flag == False or p_flag == False) and row[1] in ("xsq_loh"))
                ):
                    print "<td bgcolor=silver></td>"
                else:
                    print "<td></td>"

        print "</tr>"

    print ("\n</table> </font>\n")
    return
示例#7
0
文件: ircr.py 项目: SMC1/JK1
		});

	})
})

</script>

</head>
<body>
<div class="row-fluid">
<div class="span12" style="margin-left:10px; margin-top:10px;">
<form method='get' class="form-inline">
<select name='dbN' style="width:120px; height:23px; font-size:9pt">
""" % (
    geneN,
    mycgi.db2dsetN(dbN),
)

mycgi.dbOptions(dbN)

print """
</select>
<input type='text' name='geneN' value='%s' style="width:130px; height:15px; font-size:9pt">
<input type='submit' class="btn btn-small" value='Submit'>
</form>

""" % (
    geneN
)

main(dbN, geneN)
示例#8
0
$(document).ready(function() {

    $('#ex_EGFR').click(function () {
		$('#qText').val($ex_EGFR)
	});

	$('#ex_IDH1').click(function() { 
		$('#qText').val($ex_IDH1)
	});

})

</script>

</head>''' % mycgi.db2dsetN(dbN)


print '''
<body>
<div class='row-fluid'>
<div class="span1"></div>
<div class="span12">
<h2>Oncoprint <small> (%s) </small></h2>
''' % (mycgi.db2dsetN(dbN),)


print '<dl><dt><i class="icon-search"></i> Input (per line):</dt><dd>[sample info] OR [gene name]:[mutation type]:[mutation value] OR [(qId,col,tbl,cnd)]</dd></dl>'

print '<dl><dt><i class="icon-tags"></i> [sample info]</dt>'
for scut in ['Rsq','Xsq']:
示例#9
0
$(document).ready(function() {

    $('#ex_EGFR').click(function () {
		$('#qText').val($ex_EGFR)
	});

	$('#ex_IDH1').click(function() { 
		$('#qText').val($ex_IDH1)
	});

})

</script>

</head>''' % mycgi.db2dsetN(dbN)

print '''
<body>
<div class='row-fluid'>
<div class="span1"></div>
<div class="span12">
<h2>Oncoprint <small> (%s) </small></h2>
''' % (mycgi.db2dsetN(dbN), )

print '<dl><dt><i class="icon-search"></i> Input (per line):</dt><dd>[sample info] OR [gene name]:[mutation type]:[mutation value] OR [(qId,col,tbl,cnd)]</dd></dl>'

print '<dl><dt><i class="icon-tags"></i> [sample info]</dt>'
for scut in ['Rsq', 'Xsq']:
    print '<dd><i class="icon-chevron-down"></i>  %s: %s </dd>' % (
        scut, str(sampInfoH[scut]))