Skip to content

Instantly share code, notes, and snippets.

@araastat
araastat / ggkm.R
Last active July 6, 2018 17:39
Plotting a Kaplan-Meier curve using ggplot. ggkmTable.R adds a table below the plot showing numbers at risk at different times.
#’ Create a Kaplan-Meier plot using ggplot2
#’
#’ @param sfit a \code{\link[survival]{survfit}} object
#’ @param returns logical: if \code{TRUE}, return an ggplot object
#’ @param xlabs x-axis label
#’ @param ylabs y-axis label
#’ @param ystratalabs The strata labels. \code{Default = levels(summary(sfit)$strata)}
#’ @param ystrataname The legend name. Default = “Strata”
#’ @param timeby numeric: control the granularity along the time-axis
#’ @param main plot title
@araastat
araastat / tocsv.py
Created March 5, 2014 13:06
Export each sheet of a xls/xlsx file to csv
import pandas as pd
import xlrd as xd
def xls2csv(f, index=False, header=True):
wb = xd.open_workbook(f)
snames=[]
for s in wb.sheets():
snames.append(s.name)
for s in snames:
x = pd.read_excel(f,s)
#!/usr/bin/env python
import sys
import re
f = open('Bibliography_ToddArnedtGrant.txt','r')
Todd = f.readlines()
f.close()
f = open('Bibliography_SoniaDuffyGrant.txt','r')
#!/home/abhijit/anaconda/bin/python
import re
def getauthor(x):
authlist = x.split('.')[0]
bl = authlist.split(',')
bl = [u.lstrip().replace(' ',', ') for u in bl]
bl = [u.replace('et al','"et al"') for u in bl]
out = 'author = {'+' and '.join(bl)+'}'
#! /usr/bin/env python
"""
The MIT License (MIT)
Copyright (c) 2013 Hannes Bretschneider
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
"""Simple utility script for semi-gracefully downgrading v3 notebooks to v2"""
import io
import os
import sys
from IPython.nbformat import current
def heading_to_md(cell):
"""turn heading cell into corresponding markdown"""
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@araastat
araastat / leuk.py
Created November 22, 2013 18:25 — forked from fonnesbeck/leuk.ipynb
{
"metadata": {
"name": "Survival Example"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{