Tutorial 1. Introduction to Synapse Python API

  • For detailed hands on instructions using python API please visit getting started guide
  • If you have any questions about python API please feel free to post them on the python API forum

In [1]:
1 + 1


Out[1]:
2

In [2]:
#import the synapse python API
import synapseclient
from synapseclient import Wiki, File, Project, Folder

%run 'synapse_demo_utils_functions.ipynb'

1. Login to synapse using the API


In [ ]:
#login using locally stored credentials
syn = synapseclient.login()

Project and Data Management on Synapse

2. Create a new project on synapse


In [ ]:
myProj = Project(name='Cell Lines Analysis %s' % randomword(5))
myProj = syn.store(myProj)
print 'Created project with synapse id: %s' % myProj.id

2.1 Alternatively start with a project created from the synapse website


In [5]:
#this project was created on synapse website
#myProj = 'synXXX'
#myProj = syn.get(myProj)

3. Create a Project Wiki


In [6]:
projWiki = Wiki(title='Data Summary', owner = myProj )

4. Push text content into a Wiki


In [7]:
markdown = '''
* Cell growth look normally distributed

* There is evidence of inverse growth between these two cell lines 
'''
projWiki['markdown'] = markdown
projWiki = syn.store(projWiki)

5. Organizing Data: creating folder & file entities


In [ ]:
results_folder = Folder(name='results', parent=myProj)
results_folder = syn.store(results_folder)

raw_data_file = File("data/cell_lines_raw_data.csv", parent=results_folder)
raw_data_file = syn.store(raw_data_file)

5.1 Upload a plot


In [ ]:
plot1 = File("images/plot_1.png", parent=results_folder)
plot1 = syn.store(plot1)

Let's check what we have done till now


In [10]:
syn.onweb(myProj)

4.2 Keeping track of our analysis: Provenance


In [ ]:
used_data = [raw_data_file]
code = ['https://github.com/Sage-Bionetworks/synapseTutorials']

plot2 = File("images/plot_2.png", parent=results_folder)
plot2 = syn.store(plot2, used=used_data, executed=code)

Push the plots to Wiki


In [14]:
wiki = syn.getWiki(myProj)
md = """
#Cell line analysis
* Cell growth look normally distributed
* There is evidence of inverse growth between these two cell lines 

${{image?synapseId={plot1_id}&align=None&scale=50}}

${{image?synapseId={plot2_id}&align=None&scale=50}}
"""
wiki['markdown'] = md.format(plot1_id=plot1.id, plot2_id=plot2.id)
wiki = syn.store(wiki)

In [13]:
syn.onweb(myProj)

5. Finally: clean up

(only because this was a demo)


In [20]:
syn.delete(myProj)