Home > Visualization > Main text

Links to all types of plot


Tag: plot, visualization

<!DOCTYPE html>

Untitled
In [1]:
sns.set(style="ticks")
sns.set_context("poster")
from adjustText import adjust_text
In [2]:
f = '../data/HEK293T.duplex.RBP.stat.bed'
df = pd.read_csv(f, header=0, index_col=0, sep='\t')
color_category = []
for i in df.iterrows():
    i = i[1]
    if float(i['pct(cover RRI) 1']) >= 0.05 and float(i['pvalue']) <= 0.01 and float(i['oddsratio']) >= 1.5:
        color_category.append('high')
    elif float(i['pvalue']) <= 0.01 and float(i['oddsratio']) >= 1.5:
        color_category.append('weak')
    else:
        color_category.append('none')
df['enrich level'] = color_category
df.head()
Out[2]:
# cover RRI 1 pct(cover RRI) 1 # all RRI 1 # cover RRI 2 pct(cover RRI) 2 # all RRI 2 obs/exp log2(obs/exp) oddsratio pvalue enrich level
AGO1 2017 0.039053 51648 1236 0.023931 51648 1.631877 0.706532 1.631877 9.116186e-42 weak
AGO2 1352 0.026177 51648 1088 0.021066 51648 1.242647 0.313417 1.242647 1.375318e-07 none
AGO3 561 0.010862 51648 296 0.005731 51648 1.895270 0.922404 1.895270 1.331809e-19 weak
AGO4 244 0.004724 51648 187 0.003621 51648 1.304813 0.383843 1.304813 6.806662e-03 none
ALKBH5 613 0.011869 51648 439 0.008500 51648 1.396355 0.481666 1.396355 9.296654e-08 none
In [57]:
fig,ax=plt.subplots(figsize=(10,12))

df['size'] = 0.01
sns.scatterplot(x='log2(obs/exp)', y='pct(cover RRI) 1', hue='enrich level', data=df, size='size')

xs = df[df['enrich level']!='none']['log2(obs/exp)']
ys = df[df['enrich level']!='none']['pct(cover RRI) 1']
ss = df[df['enrich level']!='none'].index

texts = []
for x, y, s in zip(xs, ys, ss):
    texts.append(plt.text(x, y, s))
    
# adjust_text(texts, only_move={'text': 'y'})


plt.ylabel('Percentage of interacting regions')
Out[57]:
Text(0,0.5,'Percentage of interacting regions')
In [64]:
pd.concat([df, df], axis=1).shape
Out[64]:
(48, 24)
In [7]:
pd.DataFrame(df['enrich level'].value_counts())
Out[7]:
enrich level
none 34
weak 8
high 6
In [ ]:
1   198
2  2497
3  1274
4   506
5   217
6   349
In [8]:
a = [1,2,3]
In [9]:
a.extend([4,5])
a
Out[9]:
[1, 2, 3, 4, 5]
In [10]:
np.random.seed(1234)
In [13]:
import random
In [16]:
random.sample(a, 2)
Out[16]:
[4, 5]
In [18]:
from scipy import stats
In [19]:
stats.pearsonr(a, a)
Out[19]:
(1.0, 0.0)

If you link this blog, please refer to this page, thanks!
Post link:https://tsinghua-gongjing.github.io/posts/roc.html

Previous: GTF files