Skip to content

Instantly share code, notes, and snippets.

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

Christopher Bare cbare

👹
¯\_(ツ)_/¯
View GitHub Profile
@cbare
cbare / runAttractorInCRCSC.py
Last active August 29, 2015 14:08
runAttractorInCRCSC: A sample analysis script for use in the [Mad Scientist Stu demo](https://www.synapse.org/#!Help:Collaboratorium)
###########################################################
##
## runAttractorInCRCSC
##
## A sample data analysis for use with the Mad Scientist
## Stu demo of Synapse:
## https://www.synapse.org/#!Help:Collaboratorium
###########################################################
"""
Perform Step 5 of the Mad Scientist Stu Synapse Tutorial.
@cbare
cbare / recursive_download.py
Last active April 18, 2016 03:59
Recursively download the contents of a Project or Folder from Synapse
import os
import shutil
import synapseclient
from synapseclient import Project, Folder, Entity, File
syn = synapseclient.login()
def download(entity, directory=None, verbose=False, indent=0):
"""
@cbare
cbare / wikipedia_revision_grabber.py
Created June 3, 2014 00:57
Retrieve the last 100 revisions of a wikipedia article
import synapseclient
from synapseclient import File, Project, Folder
syn = synapseclient.login()
## get latest 100 revisions of a wikipedia article
url = "http://en.wikipedia.org/w/api.php?action=query&titles=Crimea&prop=revisions&rvprop=ids|timestamp|flags|content&rvlimit=100&format=json"
response = requests.get(url)
crimea = response.json()
@cbare
cbare / recursive_upload.py
Last active January 30, 2021 02:50
Example of how to upload a directory hierarchy into a Synapse project
import synapseclient
from synapseclient import Synapse, File, Folder, Project
import os
def upload_recursive(directory, parent):
for item in os.listdir(directory):
if os.path.isdir(os.path.join(directory,item)):
print "%s/" % os.path.basename(item)
folder = syn.store(Folder(os.path.basename(item), parent=parent))
upload_recursive(directory=os.path.join(directory, item), parent=folder)
@cbare
cbare / grep_git_objects.py
Last active August 29, 2015 14:01
Find lost stuff in a git repository
############################################################
## Find lost stuff in a git repository ##
## ##
## run in the root of your git repo ##
## Usage: python grep_git_objects.py <target> ##
############################################################
import os
import sys
import subprocess
@cbare
cbare / download_synapse_files.py
Created April 2, 2014 19:45
Demonstrate how to script file download from Synapse
import os
import synapseclient
syn = synapseclient.Synapse()
syn.login() # insert credentials here, unless you have a cached API key.
## ADChallenge_WorkingGroup (syn2343636) Files » ADNI » Genetics » GWAS
folder_id = 'syn2362101'
## Get all children of the parent folder
@cbare
cbare / challenge-intro.template.md
Created February 5, 2014 17:27
Template for Synapse challenges

##Background Why is this an important question and why is it interesting for the participants?

##Registration

${{jointeam?teamId={team[id]}&showProfileForm=true&isMemberMessage=You have successfully joined the {name}}}

##Data description What data types and how many samples are provided. The Data Description page has more details.

@cbare
cbare / tox_challenge_writeup_example.md
Created December 5, 2013 14:57
Synapse markdown example for Tox Challenge writeups.
@cbare
cbare / clean_participant_data.R
Created October 24, 2013 22:37
Read challenge participant data from Synapse for the purpose of extracting the participant's locations. The locations will be used to construct a map.
## A script to read participant data out of Synapse and
## (help) clean it up.
##
## J. Christopher Bare
## [email protected]
## Oct. 24, 2013
############################################################
## read evaluations
ev1 <- synGetEvaluation(1917695)
@cbare
cbare / bulk_acl_manipulation.py
Last active December 24, 2015 06:38
A Python script for bulk manipulation of ACLs in Synapse
import collections
import synapseclient
from synapseclient.utils import id_of
syn = synapseclient.Synapse()
syn.login()
def copy_acl(source_entity, destination_entities, overwrite_existing=False):
acl = syn._getACL(source_entity)
for key in ['id','url','etag','creationDate']: