Skip to content

Instantly share code, notes, and snippets.

View cbare's full-sized avatar
👹
¯\_(ツ)_/¯

Christopher Bare cbare

👹
¯\_(ツ)_/¯
View GitHub Profile
@cbare
cbare / guess.py
Created September 26, 2013 22:59
Try to guess a lottery number randomly. This code is part of a demo of the evaluation features of the Synapse platform at this URL: https://www.synapse.org/#!Synapse:syn1901865
import random
guess = sorted([random.randrange(1,60) for z in range(0,5)])
filename = 'my-entry.txt'
with open(filename, 'w') as f:
f.write(', '.join([str(x) for x in guess]))
f.write('\n')
@cbare
cbare / test_evaluation.py
Created August 27, 2013 01:47
Test out evaluation features of Synapse with numpy arrays.
import numpy as np
import random
import uuid
import synapseclient
from synapseclient import File, Folder, Project
from synapseclient import Evaluation, Submission, SubmissionStatus
def read_matrix(filepath):
@cbare
cbare / get_stats.py
Last active December 20, 2015 21:09
A total one-off hack to crawl Synapse and compile stats on public entities for auditing of data governance compliance. A modification of an earlier gist: synapse_stats.py https://gist.github.com/cbare/4686667
##
## Collect statistics for auditing Synapse usage and governance
######################################################################
import synapseclient
from synapseclient.utils import id_of
from datetime import datetime as Datetime
import re, sys
import requests
ROOT = 'syn4489'
@cbare
cbare / synapse_magic.py
Last active January 8, 2016 19:28
Synapse magic for IPython.Put this file in `~/.ipython/profile_default/startup`, then log into Synapse by typing %synapse at the IPython prompt.
from __future__ import print_function
from IPython.core.magic import (Magics, magics_class, line_magic)
@magics_class
class SynapseMagics(Magics):
"""
IPython magic for Synapse. In an interactive IPython session, you can
conveniently import the key Synapse objects and log in.
To log in as your default user (according to your ~/.synapseCache/.session file)::
@cbare
cbare / uuid.R
Last active January 11, 2019 10:07
A snippet of R code to generate a version 4 (random) UUID.
## Version 4 UUIDs have the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
## where x is any hexadecimal digit and y is one of 8, 9, A, or B
## e.g., f47ac10b-58cc-4372-a567-0e02b2c3d479
uuid <- function(uppercase=FALSE) {
hex_digits <- c(as.character(0:9), letters[1:6])
hex_digits <- if (uppercase) toupper(hex_digits) else hex_digits
y_digits <- hex_digits[9:12]
@cbare
cbare / generate_guesses.py
Created June 19, 2013 23:27
Demonstrate the evaluation features in Synapse. Submit entries to a dummy evaluation, score them (randomly), and generate a leader board from the results.
import filecmp
import os
import random
import synapseclient
from synapseclient import Activity, File, Folder, Project
import uuid
## create synapse object and log in
syn = synapseclient.Synapse()
syn.login()
@cbare
cbare / test_command_line.py
Last active December 17, 2015 02:38
Slightly modified version of command line Synapse Client for Python -- for debugging command line problems
import argparse
import os
import shutil
import sys
import synapseclient
from synapseclient import Activity
import synapseclient.version_check as version_check
import signal
import json
@cbare
cbare / external_file_handle_test.py
Created May 2, 2013 19:38
Try out support for external file handles in Synapse
##
## Try out support for external file handles in Synapse
######################################################################
import synapseclient
from synapseclient.entity import File, Project, Folder
syn = synapseclient.Synapse()
syn.login()
## create a sandbox project
project = Project('Uniquely named temporary project')
@cbare
cbare / delete_test_projects.py
Last active March 29, 2016 20:53
Got a bunch of junky old test projects in Synapse that you need to get rid of? If the projects are named with UUIDs, this script will find them and delete them.
from __future__ import print_function
from __future__ import unicode_literals
import synapseclient
import re
import sys
## make sure we really want to delete stuff
not_kidding = len(sys.argv) > 1 and sys.argv[1] == '--not-kidding'
if not not_kidding:
@cbare
cbare / GeneRequest.py
Created March 20, 2013 03:34
Get gene information from NCBI's EUTILs web services
## Example code for getting gene information from NCBI
## using EUTILS.
## To install dependencies:
## pip install lxml
## pip install requests
############################################################
import requests
from lxml import etree as ET
import re