Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

Francesco G. Brundu fbrundu

💭
I may be slow to respond.
View GitHub Profile
@fbrundu
fbrundu / check_unique.sh
Last active Aug 29, 2015
Check if a line is composed by unique words.
View check_unique.sh
# line number after ==
# change \\t with the delimiter you want to use instead of tab for splitting to words
words_count=$(awk 'NR==5{print}' data.csv | tr \\t \\n | wc -l)
unique_words_count=$(awk 'NR==5{print}' data.csv | tr \\t \\n | uniq | wc -l)
if [[ "$words_count" -ne "$unique_words_counts" ]]; then
echo "Not unique"
else
echo "Unique"
@fbrundu
fbrundu / tsv2gct.py
Created Feb 24, 2015
Transform tab separated matrix to gct file
View tsv2gct.py
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 / l2r_fsel_srs.py
Created Feb 24, 2015
Log2ratio transformation, feature selection and simple random sampling on a gene expression matrix
View l2r_fsel_srs.py
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 / tcga_correct_samplenames.py
Created Mar 5, 2015
Correct a TCGA assembled tsv file (tab delimited), formatting sample names for tsv columns
View tcga_correct_samplenames.py
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])
View skeleton-ipython-css
<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 / custom.css
Created Apr 6, 2015
Custom css for ipython3 notebook
View custom.css
.CodeMirror, div.prompt.input_prompt, div.prompt.output_prompt, pre {
font-family: "Inconsolata for Powerline";
font-size: 100%;
}
@fbrundu
fbrundu / fastcluster_to_k.py
Last active Dec 30, 2015
Get k clusters from pandas dataframe using fastcluster. Use fastcluster to make a hierarchical clustering cropped to k clusters.
View fastcluster_to_k.py
import fastcluster as fc
import pandas as pd
import scipy.cluster.hierarchy as sch
# define total number of cluster to obtain
k = 5
# define matrix path
mat_path = 'matrix.txt'
@fbrundu
fbrundu / consensus_array.py
Last active Dec 30, 2015
Generate consensus array from pandas DataFrame (NaN values are ignored)
View consensus_array.py
import pandas as pd
# load data
mat = pd.read_table('class_matrix.txt', index_col=0)
# initialize consensus array
consensus_a = pd.Series(index=mat.index)
# define columns subset on which compute consensus
# in this case all columns are used
@fbrundu
fbrundu / jprob_cmatrix.py
Last active Dec 30, 2015
Generation of a joint probability consensus matrix from pandas dataframe
View jprob_cmatrix.py
import numpy as np
import pandas as pd
# load data
mat = pd.read_table('matrix.txt', index_col=0)
# get classes
classes = np.unique(mat.values)
classes = classes[~np.isnan(classes)]
@fbrundu
fbrundu / .vimrc
Last active Mar 7, 2017
My vimrc
View .vimrc
" no vi-compatible
set nocompatible
let g:python_host_prog=$HOME.'/.pyenv/versions/neovim2/bin/python'
let g:python3_host_prog=$HOME.'/.pyenv/versions/neovim3/bin/python'
" Setting up Vundle - the vim plugin bundler
let iCanHazVundle=1
let vundle_readme=expand('~/.vim/bundle/vundle/README.md')
if !filereadable(vundle_readme)
You can’t perform that action at this time.