本文整理汇总了Python中synapseclient.File.annotations方法的典型用法代码示例。如果您正苦于以下问题:Python File.annotations方法的具体用法?Python File.annotations怎么用?Python File.annotations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类synapseclient.File
的用法示例。
在下文中一共展示了File.annotations方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload
# 需要导入模块: from synapseclient import File [as 别名]
# 或者: from synapseclient.File import annotations [as 别名]
def upload(args,syn):
if args.dataType == "rnaseq":
parentId = "syn6034916"
pipeline = "syn6126122"
dataType = "RNASeq"
elif args.dataType == "dnaseq":
parentId = "syn6034751"
pipeline = "syn6126123"
dataType = "TargDNASeq"
elif args.dataType == "snparray":
parentId = "syn6038475"
pipeline = "syn6126121"
dataType = "SNParray"
elif args.dataType == "exparray":
parentId = "syn6038915"
pipeline = "syn6126120"
dataType = "expression_microarray"
elif args.dataType == "exome":
parentId = "syn6115597"
dataType = "exome"
pipeline = ""
else:
raise ValueError("dataType needs to be rnaseq/dnaseq/snparray/exparray/exome")
if args.workflow is not None:
workflow = syn.get(pipeline,downloadFile=False)
workflow.path = args.workflow
workflow.name = os.path.basename(args.workflow)
workflow = syn.store(workflow)
pipeline = workflow.id
fileEnt = File(args.input,parent=parentId)
fileEnt.annotations = temp.to_dict('index').values()[0]
fileEnt.dataType = dataType
fileEnt.sampleId = sampleId
fileEnt = syn.store(fileEnt,used = pipeline)
return(fileEnt.id)
示例2: _copyFile
# 需要导入模块: from synapseclient import File [as 别名]
# 或者: from synapseclient.File import annotations [as 别名]
def _copyFile(syn, entity, destinationId, version=None, updateExisting=False, setProvenance="traceback",
skipCopyAnnotations=False):
"""
Copies most recent version of a file to a specified synapse ID.
:param entity: A synapse ID of a File entity
:param destinationId: Synapse ID of a folder/project that the file wants to be copied to
:param version: Can specify version of a file.
Default to None
:param updateExisting: Can choose to update files that have the same name
Default to False
:param setProvenance: Has three values to set the provenance of the copied entity:
traceback: Sets to the source entity
existing: Sets to source entity's original provenance (if it exists)
None: No provenance is set
:param skipCopyAnnotations: Skips copying the annotations
Default is False
"""
ent = syn.get(entity, downloadFile=False, version=version, followLink=False)
# CHECK: If File is in the same parent directory (throw an error) (Can choose to update files)
if not updateExisting:
existingEntity = syn.findEntityId(ent.name, parent=destinationId)
if existingEntity is not None:
raise ValueError('An entity named "%s" already exists in this location. File could not be copied'
% ent.name)
profile = syn.getUserProfile()
# get provenance earlier to prevent errors from being called in the end
# If traceback, set activity to old entity
if setProvenance == "traceback":
act = Activity("Copied file", used=ent)
# if existing, check if provenance exists
elif setProvenance == "existing":
try:
act = syn.getProvenance(ent.id)
except SynapseHTTPError as e:
if e.response.status_code == 404:
act = None
else:
raise e
elif setProvenance is None or setProvenance.lower() == 'none':
act = None
else:
raise ValueError('setProvenance must be one of None, existing, or traceback')
# Grab entity bundle
bundle = syn._getEntityBundle(ent.id, version=ent.versionNumber, bitFlags=0x800 | 0x1)
fileHandle = synapseclient.utils.find_data_file_handle(bundle)
createdBy = fileHandle['createdBy']
# CHECK: If the user created the file, copy the file by using fileHandleId else copy the fileHandle
if profile.ownerId == createdBy:
newdataFileHandleId = ent.dataFileHandleId
else:
copiedFileHandle = copyFileHandles(syn, [fileHandle], ["FileEntity"], [bundle['entity']['id']],
[fileHandle['contentType']], [fileHandle['fileName']])
# Check if failurecodes exist
copyResult = copiedFileHandle['copyResults'][0]
if copyResult.get("failureCode") is not None:
raise ValueError("%s dataFileHandleId: %s" % (copyResult["failureCode"],
copyResult['originalFileHandleId']))
newdataFileHandleId = copyResult['newFileHandle']['id']
new_ent = File(dataFileHandleId=newdataFileHandleId, name=ent.name, parentId=destinationId)
# Set annotations here
if not skipCopyAnnotations:
new_ent.annotations = ent.annotations
# Store provenance if act is not None
if act is not None:
new_ent = syn.store(new_ent, activity=act)
else:
new_ent = syn.store(new_ent)
# Leave this return statement for test
return new_ent['id']
示例3: _copyFile
# 需要导入模块: from synapseclient import File [as 别名]
# 或者: from synapseclient.File import annotations [as 别名]
def _copyFile(syn, entity, destinationId, version=None, update=False, setProvenance="traceback"):
"""
Copies most recent version of a file to a specified synapse ID.
:param entity: A synapse ID of a File entity
:param destinationId: Synapse ID of a folder/project that the file wants to be copied to
:param version: Can specify version of a file.
Default to None
:param update: Can choose to update files that have the same name
Default to False
:param setProvenance: Has three values to set the provenance of the copied entity:
traceback: Sets to the source entity
existing: Sets to source entity's original provenance (if it exists)
None: No provenance is set
"""
ent = syn.get(entity, downloadFile=False, version=version, followLink=False)
#CHECK: If File is in the same parent directory (throw an error) (Can choose to update files)
if not update:
search = syn.query('select name from entity where parentId =="%s"'%destinationId)
for i in search['results']:
if i['entity.name'] == ent.name:
raise ValueError('An item named "%s" already exists in this location. File could not be copied'%ent.name)
profile = syn.getUserProfile()
# get provenance earlier to prevent errors from being called in the end
# If traceback, set activity to old entity
if setProvenance == "traceback":
act = Activity("Copied file", used=ent)
# if existing, check if provenance exists
elif setProvenance == "existing":
try:
act = syn.getProvenance(ent.id)
except SynapseHTTPError as e:
# Should catch the 404
act = None
elif setProvenance is None or setProvenance.lower() == 'none':
act = None
else:
raise ValueError('setProvenance must be one of None, existing, or traceback')
#Grab file handle createdBy annotation to see the user that created fileHandle
fileHandleList = syn.restGET('/entity/%s/version/%s/filehandles'%(ent.id,ent.versionNumber))
#NOTE: May not always be the first index (need to filter to make sure not PreviewFileHandle)
#Loop through to check which dataFileHandles match and return createdBy
# Look at convenience function
for fileHandle in fileHandleList['list']:
if fileHandle['id'] == ent.dataFileHandleId:
createdBy = fileHandle['createdBy']
break
else:
createdBy = None
#CHECK: If the user created the file, copy the file by using fileHandleId else hard copy
if profile.ownerId == createdBy:
new_ent = File(name=ent.name, parentId=destinationId)
new_ent.dataFileHandleId = ent.dataFileHandleId
else:
#CHECK: If the synapse entity is an external URL, change path and store
if ent.externalURL is None: #and ent.path == None:
#####If you have never downloaded the file before, the path is None
store = True
#This needs to be here, because if the file has never been downloaded before
#there wont be a ent.path
ent = syn.get(entity,downloadFile=store,version=version)
path = ent.path
else:
store = False
ent = syn.get(entity,downloadFile=store,version=version)
path = ent.externalURL
new_ent = File(path, name=ent.name, parentId=destinationId, synapseStore=store)
#Set annotations here
new_ent.annotations = ent.annotations
#Store provenance if act is not None
if act is not None:
new_ent = syn.store(new_ent, activity=act)
else:
new_ent = syn.store(new_ent)
#Leave this return statement for test
return new_ent['id']