Skip to content

Instantly share code, notes, and snippets.

View svigneau's full-sized avatar

Sebastien Vigneau svigneau

View GitHub Profile
@svigneau
svigneau / sell_all_stocks_on_robinhood.R
Created April 30, 2021 01:29
Sell all you RobinHood stocks at once.
# This script allows to sell all your stocks on RobinHood at once using the RobinHood API.
# Only use if you understand what it does!
# install.packages("RobinHood")
library(RobinHood)
my_username <- "username" # replace with your username (should not contain any R special characters)
my_password <- "password" # replace with your password (should not contain any R special characters)
# Two-factor authentication needs to be turned off in order to connect using your password.
@svigneau
svigneau / AnnotStackSummary.R
Last active February 17, 2023 15:19
This script illustrates how to add one label per stack in a stacked bar chart using ggplot in R.
# This script illustrates how to add one label per stack in a stacked bar chart using ggplot in R.
# In this case, labels indicate the sum of values represented in each bar stack.
# The idea is to create as many labels as bars, but assign text to only one label per stack, then plot labels according to stack height.
# Data
df <- data.frame(stack=factor(rep(c("A", "B", "C"), each=3)), cat=factor(rep(c("X", "Y", "Z"), times=3)), val=1:9)
# Compute sum
totals <- as.vector(by(df$val, df$stack, sum))
# Calculate label position
pos <- rep(totals + 1, each=3)
@svigneau
svigneau / RDavidQuery.R
Last active March 2, 2022 16:12
This snippet illustrates how to query David from R, using the RDAVIDWebService package.
# This snippet illustrates how to query David from R, using the RDAVIDWebService package.
# Load RDAVIDWebService.
library("RDAVIDWebService")
# Create a DAVIDWebService object connected to David, using your registration email.
# To register, go to: http://david.abcc.ncifcrf.gov/content.jsp?file=WS.html.
david <- DAVIDWebService$new(email='[email protected]')
# Define foreground and background gene lists.
@svigneau
svigneau / GeneToRefseq.R
Last active August 29, 2015 13:57
Example snippet showing how to query BioMart from R, to find mRNA Refseq Ids associated with mouse gene symbols.
# This snippet queries BioMart to find mRNA Refseq Ids associated with mouse gene symbols.
# Load biomaRt.
library(biomaRt)
# Get vector of gene symbols from a table loaded in R.
genes <- mytable$Gene
# Choose BioMart database and dataset.
mart <- useMart("ensembl", dataset="mmusculus_gene_ensembl")
# Specify filter used to read input values.
# A list of possible filters can be retrieved using listFilters.
@svigneau
svigneau / run_cmd_wrapper.sh
Created March 19, 2014 17:29
This script is a wrapper to run a command on all files from a set of directories, and output to directories with matching names.
#!/bin/bash
# Wrapper to run a command on all files from a set of directories, and output to directories with matching names.
# Parameters need to be edited according to your data structure.
# The parameters here assume a project directory containing:
# - a "src" directory, from which are run this script and the executable used in the command.
# - a "data" directory, containing input directories that can be called using regular expressions. The input directories are named with an underscore-separated suffix indicating file format.
# - a "munge" directory, where output directories will be created with names matching those of the input directories, using a different underscore-separated suffix to indicate the output file format.
src_path=../src # Directory of the executable used in command -- edit with yours.
@svigneau
svigneau / tab3col_to_bedgraph.pl
Last active August 29, 2015 13:56
This script converts a tsv file, with columns "chr", "start" and "value", to bedGraph format.
#!/usr/bin/perl
# Description: This script converts a 3 columns tabular format, where columns are chr, start, value, to bedGraph format. Input file may be compressed as .gz.
# Coordinates in both input and bedGraph output are assumed to be 0-based (http://genome.ucsc.edu/goldenPath/help/bedgraph.html).
# Usage: tab3col_to_bedgraph.pl --tab input.tsv --bedgraph output.bedgraph
# --tab : specify input file in 3 columns tabular format, where columns are chr, start, value.
# --bedgraph : specify output file in bedgraph format.
# Credits: This script was written by Sebastien Vigneau ([email protected]) in Alexander Gimelbrant lab (Dana-Farber Cancer Institute).
@svigneau
svigneau / bedgraph_to_wig.pl
Last active February 24, 2024 01:22
Perl script to convert bedGraph to fixedStep wig format with defined step size.
#!/usr/bin/perl
# Description: This script converts bedGraph to fixedStep wig format with defined step size. Input file may be compressed as .gz.
# Coordinates in bedGraph input are assumed to be 0-based (http://genome.ucsc.edu/goldenPath/help/bedgraph.html).
# Coordinates in wig output are 1-based (http://genome.ucsc.edu/goldenPath/help/wiggle.html).
# Usage: bedgraph_to_wig.pl --bedgraph input.bedgraph --wig output.wig --step step_size [--compact]
# --bedgraph : specify input file in bedGraph format.
# --wig : specify output file in fixedStep format.
# --step : specify step size. Note that span is set to be identical to step.
@svigneau
svigneau / mergeDeluxe.R
Last active August 29, 2015 13:56
R function to merge dataframes, appending a specified name for each dataframe to the corresponding columns
## Function ##
# Function to merge dataframes, appending the original dataframe name to the corresponding columns
mergeDeluxe <- function (tomerge, by, all=T, pos="after", sep="_") {
# tomerge: list of dataframes
# by: name of column to use as a join to merge dataframes
# all: whether to keep non-matching lines, as defined in R base "merge" function
# pos: if "after", the dataframe name is appended as a suffix; if "before", it is appended as a prefix
# sep: separator to use when appending dataframe name