Skip to content

Instantly share code, notes, and snippets.

#! /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
#!/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
import sys
import re
f = open('Bibliography_ToddArnedtGrant.txt','r')
Todd = f.readlines()
f.close()
f = open('Bibliography_SoniaDuffyGrant.txt','r')
@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)
@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