Skip to content

add suport for python3 #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions doc/_update_doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
master_doc = 'index'

# General information about the project.
project = u'BaseSpacePy'
copyright = u'2014, Illumina'
project = 'BaseSpacePy'
copyright = '2014, Illumina'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -183,8 +183,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'BaseSpacePy.tex', u'BaseSpacePy Documentation',
u'Illumina', 'manual'),
('index', 'BaseSpacePy.tex', 'BaseSpacePy Documentation',
'Illumina', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -213,8 +213,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'basespacepy', u'BaseSpacePy Documentation',
[u'Illumina'], 1)
('index', 'basespacepy', 'BaseSpacePy Documentation',
['Illumina'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -227,8 +227,8 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'BaseSpacePy', u'BaseSpacePy Documentation',
u'Illumina', 'BaseSpacePy', 'One line description of project.',
('index', 'BaseSpacePy', 'BaseSpacePy Documentation',
'Illumina', 'BaseSpacePy', 'One line description of project.',
'Miscellaneous'),
]

Expand Down
22 changes: 11 additions & 11 deletions examples/0_Browsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,32 @@

# First, let's grab the genome with id=4
myGenome = myAPI.getGenomeById('4')
print "\nThe Genome is " + str(myGenome)
print "We can get more information from the genome object"
print 'Id: ' + myGenome.Id
print 'Href: ' + myGenome.Href
print 'DisplayName: ' + myGenome.DisplayName
print("\nThe Genome is " + str(myGenome))
print("We can get more information from the genome object")
print('Id: ' + myGenome.Id)
print('Href: ' + myGenome.Href)
print('DisplayName: ' + myGenome.DisplayName)

# Get a list of all genomes
allGenomes = myAPI.getAvailableGenomes()
print "\nGenomes \n" + str(allGenomes)
print("\nGenomes \n" + str(allGenomes))

# Let's have a look at the current user
user = myAPI.getUserById('current')
print "\nThe current user is \n" + str(user)
print("\nThe current user is \n" + str(user))

# Now list the projects for this user
myProjects = myAPI.getProjectByUser()
print "\nThe projects for this user are \n" + str(myProjects)
print("\nThe projects for this user are \n" + str(myProjects))

# We can also achieve this by making a call using the 'user instance'
myProjects2 = user.getProjects(myAPI)
print "\nProjects retrieved from the user instance \n" + str(myProjects2)
print("\nProjects retrieved from the user instance \n" + str(myProjects2))

# List the runs available for the current user
runs = user.getRuns(myAPI)
print "\nThe runs for this user are \n" + str(runs)
print("\nThe runs for this user are \n" + str(runs))

# In the same manner we can get a list of accessible user runs
runs = user.getRuns(myAPI)
print "\nRuns retrieved from user instance \n" + str(runs)
print("\nRuns retrieved from user instance \n" + str(runs))
26 changes: 13 additions & 13 deletions examples/1_AccessingFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,40 @@

# Let's list all the AppResults and samples for these projects
for singleProject in myProjects:
print "# " + str(singleProject)
print("# " + str(singleProject))
appResults = singleProject.getAppResults(myAPI)
print " The App results for project " + str(singleProject) + " are \n\t" + str(appResults)
print(" The App results for project " + str(singleProject) + " are \n\t" + str(appResults))
samples = singleProject.getSamples(myAPI)
print " The samples for project " + str(singleProject) + " are \n\t" + str(samples)
print(" The samples for project " + str(singleProject) + " are \n\t" + str(samples))
#
## we'll take a further look at the files belonging to the sample and
##analyses from the last project in the loop above
for a in appResults:
print "# " + a.Id
print("# " + a.Id)
ff = a.getFiles(myAPI)
print ff
print(ff)
for s in samples:
print "Sample " + str(s)
print("Sample " + str(s))
ff = s.getFiles(myAPI)
print ff
print(ff)


## Now let's do some work with files
## we'll grab a BAM by id and get the coverage for an interval + accompanying meta-data
myBam = myAPI.getFileById('9895890')
print myBam
print(myBam)
cov = myBam.getIntervalCoverage(myAPI,'chr','1','100')
print cov
print(cov)
try:
covMeta = myBam.getCoverageMeta(myAPI,'chr')
except Exception as e:
print "Coverage metadata may not be available for this BAM file: %s" % str(e)
print("Coverage metadata may not be available for this BAM file: %s" % str(e))
else:
print covMeta
print(covMeta)
#
## and a vcf file
myVCF = myAPI.getFileById('9895892')
varMeta = myVCF.getVariantMeta(myAPI)
print varMeta
print(varMeta)
var = myVCF.filterVariant(myAPI,'chr','1', '25000')
print var
print(var)
24 changes: 12 additions & 12 deletions examples/2_AppTriggering.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,30 @@

# Using the basespaceApi we can request the appSession object corresponding to the AppSession id supplied
myAppSession = myAPI.getAppSession()
print myAppSession
print(myAppSession)

# An app session contains a referal to one or more appLaunchObjects which reference the data module
# the user launched the app on. This can be a list of projects, samples, or a mixture of objects
print "\nType of data the app was triggered on can be seen in 'references'"
print myAppSession.References
print("\nType of data the app was triggered on can be seen in 'references'")
print(myAppSession.References)

# We can also get a handle to the user who started the AppSession
print "\nWe can get a handle for the user who triggered the app\n" + str(myAppSession.UserCreatedBy)
print("\nWe can get a handle for the user who triggered the app\n" + str(myAppSession.UserCreatedBy))

# Let's have a closer look at the appSessionLaunchObject
myReference = myAppSession.References[0]
print "\nWe can get out information such as the href to the launch object:"
print myReference.HrefContent
print "\nand the specific type of that object:"
print myReference.Type
print("\nWe can get out information such as the href to the launch object:")
print(myReference.HrefContent)
print("\nand the specific type of that object:")
print(myReference.Type)


# Now we will want to ask for more permission for the specific reference object
print "\nWe can get out the specific project objects by using 'content':"
print("\nWe can get out the specific project objects by using 'content':")
myReference = myReference.Content
print myReference
print "\nThe scope string for requesting read access to the reference object is:"
print myReference.getAccessStr(scope='write')
print(myReference)
print("\nThe scope string for requesting read access to the reference object is:")
print(myReference.getAccessStr(scope='write'))

# We can easily request write access to the reference object so our App can start contributing analysis
# by default we ask for write permission and authentication for a device
Expand Down
38 changes: 19 additions & 19 deletions examples/3_Authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from BaseSpacePy.api.BaseSpaceAPI import BaseSpaceAPI
import time
import webbrowser
import cPickle as Pickle
import pickle as Pickle
import os

"""
Expand Down Expand Up @@ -50,13 +50,13 @@

# First, get the verification code and uri for scope 'browse global'
deviceInfo = myAPI.getVerificationCode('browse global')
print "\n URL for user to visit and grant access: "
print deviceInfo['verification_with_code_uri']
print("\n URL for user to visit and grant access: ")
print(deviceInfo['verification_with_code_uri'])

## PAUSE HERE
# Have the user visit the verification uri to grant us access
print "\nPlease visit the uri within 15 seconds and grant access"
print deviceInfo['verification_with_code_uri']
print("\nPlease visit the uri within 15 seconds and grant access")
print(deviceInfo['verification_with_code_uri'])
webbrowser.open_new(deviceInfo['verification_with_code_uri'])
time.sleep(15)
## PAUSE HERE
Expand All @@ -68,22 +68,22 @@
myAPI.updatePrivileges(code)

# As a reference the provided access-token can be obtained from the BaseSpaceApi object
print "\nMy Access-token:"
print myAPI.getAccessToken()
print("\nMy Access-token:")
print(myAPI.getAccessToken())


# Let's try and grab all available genomes with our new api!
allGenomes = myAPI.getAvailableGenomes()
print "\nGenomes \n" + str(allGenomes)
print("\nGenomes \n" + str(allGenomes))


# If at a later stage we wish to initialize a BaseSpaceAPI object when we already have
# an access-token from a previous sessions, this may simply be done by initializing the BaseSpaceAPI
# object using the key-word AccessToken.
myToken = myAPI.getAccessToken()
myAPI.setAccessToken(myToken)
print "\nA BaseSpaceAPI instance was updated with an access-token: "
print myAPI
print("\nA BaseSpaceAPI instance was updated with an access-token: ")
print(myAPI)

#################### Web-based verification #################################
# The scenario where the authentication is done through a web-browser
Expand All @@ -94,8 +94,8 @@
BSapiWeb = BaseSpaceAPI(profile='DEFAULT')
userUrl= BSapiWeb.getWebVerificationCode('browse global','http://localhost',state='myState')

print "\nHave the user visit:"
print userUrl
print("\nHave the user visit:")
print(userUrl)

webbrowser.open_new(userUrl)

Expand All @@ -121,8 +121,8 @@

# Get current user
user= myAPI.getUserById('current')
print user
print myAPI
print(user)
print(myAPI)

#### Here some work goes on

Expand All @@ -136,7 +136,7 @@

# Imagine the current request is done, we will simulate this by deleting the api instance
myAPI = None
print "\nTry printing the removed API, we get: " + str(myAPI)
print("\nTry printing the removed API, we get: " + str(myAPI))


# Next request in the session with id = id123 comes in
Expand All @@ -145,10 +145,10 @@
f = open(mySessionId)
myAPI = Pickle.load(f)
f.close()
print
print "We got the API back!"
print myAPI
print()
print("We got the API back!")
print(myAPI)
else:
print "Looks like we haven't stored anything for this session yet"
print("Looks like we haven't stored anything for this session yet")
# create a BaseSpaceAPI for the first time

24 changes: 12 additions & 12 deletions examples/4_AppResultUpload.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,41 +49,41 @@
# Assuming we have write access to the project
# we will list the current App Results for the project
appRes = p.getAppResults(myAPI,statuses=['Running'])
print "\nThe current running AppResults are \n" + str(appRes)
print("\nThe current running AppResults are \n" + str(appRes))

# now let's do some work!
# to create an appResults for a project, simply give the name and description
appResults = p.createAppResult(myAPI,"testing","this is my results",appSessionId='')
print "\nSome info about our new app results"
print appResults
print appResults.Id
print "\nThe app results also comes with a reference to our AppSession"
print("\nSome info about our new app results")
print(appResults)
print(appResults.Id)
print("\nThe app results also comes with a reference to our AppSession")
myAppSession = appResults.AppSession
print myAppSession
print(myAppSession)

# we can change the status of our AppSession and add a status-summary as follows
myAppSession.setStatus(myAPI,'needsattention',"We worked hard, but encountered some trouble.")
print "\nAfter a change of status of the app sessions we get\n" + str(myAppSession)
print("\nAfter a change of status of the app sessions we get\n" + str(myAppSession))
# we'll set our appSession back to running so we can do some more work
myAppSession.setStatus(myAPI,'running',"Back on track")


### Let's list all AppResults again and see if our new object shows up
appRes = p.getAppResults(myAPI,statuses=['Running'])
print "\nThe updated app results are \n" + str(appRes)
print("\nThe updated app results are \n" + str(appRes))
appResult2 = myAPI.getAppResultById(appResults.Id)
print appResult2
print(appResult2)

## Now we will make another AppResult
## and try to upload a file to it
appResults2 = p.createAppResult(myAPI,"My second AppResult","This one I will upload to")
appResults2.uploadFile(myAPI, '/home/mkallberg/Desktop/testFile2.txt', 'BaseSpaceTestFile.txt', '/mydir/', 'text/plain')
print "\nMy AppResult number 2 \n" + str(appResults2)
print("\nMy AppResult number 2 \n" + str(appResults2))

## let's see if our new file made it
appResultFiles = appResults2.getFiles(myAPI)
print "\nThese are the files in the appResult"
print appResultFiles
print("\nThese are the files in the appResult")
print(appResultFiles)
f = appResultFiles[-1]

# we can even download our newly uploaded file
Expand Down
Loading