Skip to content

Instantly share code, notes, and snippets.

View fbrundu's full-sized avatar
💭
I may be slow to respond.

Francesco G. Brundu fbrundu

💭
I may be slow to respond.
View GitHub Profile
#%%
# Compute posterior of theta from coin tosses
#%%
%config InlineBackend.figure_format = 'retina'
#%%
from matplotlib import pyplot as plt
import numpy as np
import seaborn as sns
@fbrundu
fbrundu / makeenv.sh
Created April 5, 2017 13:16
Use local R installation
alias R="<path_to_R>/R-X.Y.Z/bin/R"
export R_LIBS="<path_to_R>/packages"
export PATH="<path_to_R>/R-X.Y.Z/bin:${PATH}"
@fbrundu
fbrundu / gdc_tcga.py
Created March 27, 2017 14:39
Retrieve TCGA gene expression data using GDC api
# -*- coding: utf-8 -*-
import logging as log
import pandas as pd
import requests as rq
class TCGA:
def __init__(self, gdc_url='https://gdc-api.nci.nih.gov', per_page=100,
@fbrundu
fbrundu / onedark-vivid.terminal
Created March 8, 2017 08:58
one dark vivid macOS terminal scheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBlackColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
LjExNzY0NzA1ODggMC4xMjk0MTE3NjQ3IDAuMTUyOTQxMTc2NQAQAYAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
@fbrundu
fbrundu / custom.css
Created April 6, 2015 17:17
Custom css for ipython3 notebook
.CodeMirror, div.prompt.input_prompt, div.prompt.output_prompt, pre {
font-family: "Inconsolata for Powerline";
font-size: 100%;
}
<style>
html {
font-size: 62.5% !important; }
body {
font-size: 1.5em !important; /* currently ems cause chrome bug misinterpreting rems on body element */
line-height: 1.6 !important;
font-weight: 400 !important;
font-family: "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif !important;
color: #222 !important; }
@fbrundu
fbrundu / tcga_correct_samplenames.py
Created March 5, 2015 14:51
Correct a TCGA assembled tsv file (tab delimited), formatting sample names for tsv columns
import pandas as pd
import sys
import re
tcga_tsv = sys.argv[1]
tcga = pd.read_table(tcga_tsv, sep='\t', index_col=0)
oldcolumns = tcga.columns.tolist()
newcolumns = ['-'.join(re.findall(r'TCGA[^_]*', oc)[0].split('-')[:4])
@fbrundu
fbrundu / l2r_fsel_srs.py
Created February 24, 2015 18:00
Log2ratio transformation, feature selection and simple random sampling on a gene expression matrix
import pandas as pd
import numpy as np
import sys
import random as rnd
csv = sys.argv[1]
out = sys.argv[2]
df = pd.read_table(csv, sep='\t', index_col=0)
@fbrundu
fbrundu / tsv2gct.py
Created February 24, 2015 13:08
Transform tab separated matrix to gct file
import pandas as pd
import sys
import glob
import os
# input / output directory
input_dir = sys.argv[1]
# input file extension
input_ext = sys.argv[2]
# cardinality of index columns (rownames)
@fbrundu
fbrundu / binom.md
Last active February 17, 2021 18:12
Calculate binomial probability in Python with SciPy

If you bet on "red" at roulette, you have chance 18/38 of winning. Suppose you make a sequence of independent bets on “red” at roulette, with the decision that you will stop playing once you have won 5 times. What is the chance that after 15 bets you are still playing?

We use [binomial][1] probability mass function. To calculate the probability, you have to estimate the probability of having up to 4 successful bets after the 15th. So the final probability will be the sum of the probability to get 0 successful bets in 15 bets, plus the probability to get 1 successful bet, ..., to the probability of having 4 successful bets in 15 bets.

To achieve it:

import scipy.stats as ss

n = 15         # Number of total bets

p = 18./38 # Probability of getting "red" at the roulette