This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## follow redirects, including rePOSTing, with the requests library. | |
| ###################################################################### | |
| import requests | |
| ## authentication with no redirects | |
| ans = requests.post(url=endp_prod + "/session", data=json.dumps(d), headers=h) | |
| ## results in a successful login | |
| ans.status_code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## first, let's dump some data into a file | |
| python generate_random_data.py > data.txt | |
| ## Create a project in synapse | |
| synapse create -name "provenance test project" Project | |
| ## Add a couple of entities to our project, first a Data entity... | |
| synapse add -parentid syn1661878 -name "data.txt" -description "My randomly generated data" data.txt | |
| ## ...and a Code entity that holds the script |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Loading with files in the R synapse client | |
| ################################################## | |
| ## If you haven't already, install the synapse R client | |
| # source('http://depot.sagebase.org/CRAN.R') | |
| # pkgInstall(c("synapseClient")) | |
| library(synapseClient) | |
| ## list the files in a project |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## | |
| ## upload a file with the synapse fileHandle service | |
| ############################################################ | |
| ## import the synapse library and sign in | |
| import synapseclient | |
| syn = synapseclient.Synapse() | |
| syn.login('[email protected]', 'secret') | |
| ## the file we're going to upload |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Dynamic(dict): | |
| """Dynamic objects are just bags of properties, some of which may happen to be functions""" | |
| def __init__(self, **kwargs): | |
| self.__dict__ = self | |
| self.update(kwargs) | |
| def __setattr__(self, name, value): | |
| import types | |
| if isinstance(value, types.FunctionType): | |
| self[name] = types.MethodType(value, self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import synapseclient | |
| import re, sys | |
| import requests | |
| syn = synapseclient.Synapse() | |
| syn.login('[email protected]', 'secret') | |
| repoEndPoint = 'https://repo-prod.prod.sagebase.org/repo/v1' | |
| headers = {'Accept': 'application/json', 'sessionToken': syn.sessionToken} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## | |
| ## example session with the python synapse client | |
| ## Note: You'll have to insert your credentials and a project ID | |
| ###################################################################### | |
| ## import the synapse library and sign in | |
| import synapseclient | |
| syn = synapseclient.Synapse() | |
| syn.login('[email protected]', 'secret') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## An example of regular expressions using capture groups | |
| ## in R. See: | |
| ## http://stackoverflow.com/questions/14700799/r-regex-gsub-extract-part-of-pattern/14714370#14714370 | |
| ############################################################ | |
| # example data | |
| data <- | |
| "Station lat lon | |
| 1940 K01R 31-08N 092-34W | |
| 1941 K01T 28-08N 094-24W |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Playing with Earthquake Data | |
| ======================================================== | |
| This is a little example inspired by Jeff Leek's [Data analysis class](https://class.coursera.org/dataanalysis-001/). Jeff pointed us towards some data from the [US Geological Survey](http://www.usgs.gov/) on earthquakes. I believe these are the earthquakes for the last 7 days. I decided to see what I could do with it. | |
| ```{r} | |
| fileUrl <- "http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M1.txt" | |
| download.file(fileUrl,destfile="./data/earthquake_7day.csv",method="curl") | |
| eq <- read.csv("./data/earthquake_7day.csv") | |
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import collections | |
| class DictObject(collections.MutableMapping): | |
| def __init__(self, *args, **kwargs): | |
| for arg in args: | |
| if isinstance(arg, collections.Mapping): | |
| self.__dict__.update(arg) | |
| self.__dict__.update(kwargs) |