Skip to content

Instantly share code, notes, and snippets.

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

Christopher Bare cbare

👹
¯\_(ツ)_/¯
View GitHub Profile
@cbare
cbare / add_terms_of_use.py
Last active October 6, 2015 22:58
Let's say you want to create a REGISTER button for a challenge. In order to join the challenge, participants have to agree to a terms of use document. Here's how to do it.
import json
## First we'll create a terms-of-use object that refers to the participant
## team for the challenge, which in this case has ID 3328713. The termsOfUse
## contains the HTML that will be displayed in a panel of the registration
## wizard.
## http://rest.synapse.org/org/sagebionetworks/repo/model/AccessRequirement.html
tou = {
'accessType': 'PARTICIPATE',
'concreteType': 'org.sagebionetworks.repo.model.TermsOfUseAccessRequirement',
@cbare
cbare / smc_add_new_sample.py
Created September 9, 2015 00:00
Add a new sample to the SMC-DNA challenge
## SMC-DNA challenges are configured by entries in the table smc-dna-config,
## which lives in the MutationCallingChallengeStaging project, here:
## https://www.synapse.org/#!Synapse:syn4686078
## To add a new sample:
## create new evaluation queue (one for each of SNV, SV and possibly indel)
evaluation_snv = syn.store(Evaluation(
name="synthetic.challenge.set6.snv",
@cbare
cbare / feature_extraction_pipeline.py
Created August 27, 2015 18:02
An example of how to use Synapse Tables to store intermediate results in a feature extraction pipeline.
##==========================================================
## Tables Pipeline Example
##
## An example of using Synapse tables to store raw data and
## intermediate steps to extract features for downstream
## analysis
##==========================================================
import synapseclient
from synapseclient import Activity
from synapseclient import Entity, Project, Folder, File
@cbare
cbare / get_leaderboard.R
Created May 13, 2015 19:52
Read the leaderboard information for the Prostate Cancer DREAM Challenge into a data.frame
library(plyr)
library(synapseClient)
synapseLogin('chris.bare')
## Q1a = 3317421, Q1b = 3317433, Q2 = 3317446
## https://www.synapse.org/#!Synapse:syn2762531/wiki/72477
## metrics in the query may need to change for different questions
eid = '3317421'
@cbare
cbare / synapse_upload_directory_tree.py
Last active August 29, 2015 14:18
Added use of SQLite to cache information about what files have already been uploaded. NOT foolproof, but faster that checking in Synapse.
#!/usr/bin/env python
"""
Recursively upload a directory structure to a Synapse project (synapse.org).
Examples::
synapse_upload_directory_tree <PROJECT ID> -user <EMAIL> --pass <PASS> --top <TOP DIRECTORY>
synapse_upload_directory_tree syn3207152 --user [email protected] --pass XXXXXX --top brains
synapse_upload_directory_tree syn3207152 --user [email protected]
@cbare
cbare / update_external_url.py
Created March 20, 2015 21:49
Update the URL of a File within Synapse
import synapseclient
syn = synapseclient.Synapse()
syn.login()
## create the entity
e = syn.store(File("http://google.com/", name="google", parent="syn3361147", synapseStore=False))
## should work, but doesn't
## e = syn.store(File("http://google.com/testing1", name="google", parent="syn3361147"), synapseStore=False)
@cbare
cbare / add_participants_to_team.py
Created March 13, 2015 05:23
Example of how to add participants with pending join requests to a team
import synapseclient
from synapseclient.exceptions import SynapseError
team_id = "3325290"
approved_participant_ids = ["377358", "3321663"]
syn = synapseclient.Synapse()
## log in using cached API key.
@cbare
cbare / pilot-63_annotation_cleaning_code_scraps.py
Created February 14, 2015 00:23
Code scraps for cleaning annotations on pilot-63 VCF files.
from itertools import izip
import argparse
import os
import re
import sys
import synapseclient
import synapseclient.utils as utils
from synapseclient import Project, File, Folder, Activity
from synapseclient import Schema, Column, Table, Row, RowSet, as_table_columns
import pandas as pd
@cbare
cbare / list_challenge_participants.py
Last active August 29, 2015 14:15
List Challenge Participants
import synapseclient
syn = synapseclient.Synapse()
syn.login()
# ID for challenge participants team
team_id = ??
results = list(syn._GET_paginated('/teamMembers/{id}'.format(id=team_id)))
print "Number of participants:", len(results)
@cbare
cbare / get_synthetic_challenge_4_submissions.py
Last active August 29, 2015 14:10
Read leaderboards and submission queue, build submission tarballs and metadata as .csv
################################################################
## get submissions and metadata for Synthetic challenge 4
################################################################
import synapseclient
from synapseclient import Activity
from synapseclient import Entity, Project, Folder, File
from synapseclient import Evaluation, Submission, SubmissionStatus
import os
import pandas as pd