本文整理汇总了Python中qiita_db.artifact.Artifact类的典型用法代码示例。如果您正苦于以下问题:Python Artifact类的具体用法?Python Artifact怎么用?Python Artifact使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Artifact类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: artifact_delete_req
def artifact_delete_req(artifact_id, user_id):
"""Deletes the artifact
Parameters
----------
artifact_id : int
Artifact being acted on
user_id : str
The user requesting the action
Returns
-------
dict
Status of action, in the form {'status': status, 'message': msg}
status: status of the action, either success or error
message: Human readable message for status
"""
pd = Artifact(int(artifact_id))
access_error = check_access(pd.study.id, user_id)
if access_error:
return access_error
try:
Artifact.delete(int(artifact_id))
except QiitaDBArtifactDeletionError as e:
return {'status': 'error',
'message': str(e)}
return {'status': 'success',
'message': ''}
开发者ID:yimsea,项目名称:qiita,代码行数:28,代码来源:artifact.py
示例2: approve_study
def approve_study(self, study, user, callback):
"""Approves the current study if and only if the current user is admin
Parameters
----------
study : Study
The current study object
user : User
The current user object
callback : function
The callback function to call with the results once the processing
is done
"""
if _approve(user.level):
pd_id = int(self.get_argument('pd_id'))
pd = Artifact(pd_id)
pd.visibility = 'private'
_propagate_visibility(pd)
msg = "Processed data approved"
msg_level = "success"
else:
msg = ("The current user does not have permission to approve "
"the processed data")
msg_level = "danger"
callback((msg, msg_level, "processed_data_tab", pd_id, None))
开发者ID:anupriyatripathi,项目名称:qiita,代码行数:25,代码来源:description_handlers.py
示例3: delete_processed_data
def delete_processed_data(self, study, user, callback):
"""Delete the selected processed data
Parameters
----------
study : Study
The current study object
user : User
The current user object
callback : function
The callback function to call with the results once the processing
is done
"""
pd_id = int(self.get_argument('processed_data_id'))
try:
Artifact.delete(pd_id)
msg = ("Processed data %d has been deleted" % pd_id)
msg_level = "success"
pd_id = None
except Exception as e:
msg = ("Couldn't remove processed data %d: %s" %
(pd_id, str(e)))
msg_level = "danger"
callback((msg, msg_level, 'processed_data_tab', pd_id, None))
开发者ID:anupriyatripathi,项目名称:qiita,代码行数:26,代码来源:description_handlers.py
示例4: post
def post(self, preprocessed_data_id):
# make sure user is admin and can therefore actually submit to VAMPS
if self.current_user.level != "admin":
raise HTTPError(403, "User %s cannot submit to VAMPS!" % self.current_user.id)
msg = ""
msg_level = "success"
preprocessed_data = Artifact(preprocessed_data_id)
state = preprocessed_data.submitted_to_vamps_status()
demux = [path for _, path, ftype in preprocessed_data.get_filepaths() if ftype == "preprocessed_demux"]
demux_length = len(demux)
if state in ("submitting", "success"):
msg = "Cannot resubmit! Current state is: %s" % state
msg_level = "danger"
elif demux_length != 1:
msg = "The study doesn't have demux files or have too many" % state
msg_level = "danger"
else:
channel = self.current_user.id
job_id = submit(channel, submit_to_VAMPS, int(preprocessed_data_id))
self.render(
"compute_wait.html",
job_id=job_id,
title="VAMPS Submission",
completion_redirect="/compute_complete/%s" % job_id,
)
return
self.display_template(preprocessed_data_id, msg, msg_level)
开发者ID:mivamo1214,项目名称:qiita,代码行数:31,代码来源:vamps_handlers.py
示例5: test_check_artifact_access
def test_check_artifact_access(self):
# "Study" artifact
a = Artifact(1)
# The user has access
u = User('[email protected]')
check_artifact_access(u, a)
# Admin has access to everything
admin = User('[email protected]')
check_artifact_access(admin, a)
# Demo user doesn't have access
demo_u = User('[email protected]')
with self.assertRaises(HTTPError):
check_artifact_access(demo_u, a)
# "Analysis" artifact
a = Artifact(8)
a.visibility = 'private'
check_artifact_access(u, a)
check_artifact_access(admin, a)
with self.assertRaises(HTTPError):
check_artifact_access(demo_u, a)
check_artifact_access(User('[email protected]'), a)
a.visibility = 'public'
check_artifact_access(demo_u, a)
开发者ID:ElDeveloper,项目名称:qiita,代码行数:26,代码来源:test_base_handlers.py
示例6: post
def post(self, preprocessed_data_id):
user = self.current_user
# make sure user is admin and can therefore actually submit to VAMPS
if user.level != 'admin':
raise HTTPError(403, "User %s cannot submit to VAMPS!" %
user.id)
msg = ''
msg_level = 'success'
plugin = Software.from_name_and_version('Qiita', 'alpha')
cmd = plugin.get_command('submit_to_VAMPS')
artifact = Artifact(preprocessed_data_id)
# Check if the artifact is already being submitted to VAMPS
is_being_submitted = any(
[j.status in ('queued', 'running')
for j in artifact.jobs(cmd=cmd)])
if is_being_submitted == 'submitting':
msg = "Cannot resubmit! Data is already being submitted"
msg_level = 'danger'
self.display_template(preprocessed_data_id, msg, msg_level)
else:
params = Parameters.load(
cmd, values_dict={'artifact': preprocessed_data_id})
job = ProcessingJob.create(user, params, True)
job.submit()
self.redirect('/study/description/%s' % artifact.study.study_id)
开发者ID:josenavas,项目名称:QiiTa,代码行数:28,代码来源:vamps_handlers.py
示例7: write_demux_files
def write_demux_files(self, prep_template, generate_hdf5=True):
"""Writes a demux test file to avoid duplication of code"""
fna_fp = join(self.temp_dir, 'seqs.fna')
demux_fp = join(self.temp_dir, 'demux.seqs')
if generate_hdf5:
with open(fna_fp, 'w') as f:
f.write(FASTA_EXAMPLE)
with File(demux_fp, "w") as f:
to_hdf5(fna_fp, f)
else:
with open(demux_fp, 'w') as f:
f.write('')
if prep_template.artifact is None:
ppd = Artifact.create(
[(demux_fp, 6)], "Demultiplexed", prep_template=prep_template,
can_be_submitted_to_ebi=True, can_be_submitted_to_vamps=True)
else:
params = Parameters.from_default_params(
DefaultParameters(1),
{'input_data': prep_template.artifact.id})
ppd = Artifact.create(
[(demux_fp, 6)], "Demultiplexed",
parents=[prep_template.artifact], processing_parameters=params,
can_be_submitted_to_ebi=True, can_be_submitted_to_vamps=True)
return ppd
开发者ID:anupriyatripathi,项目名称:qiita,代码行数:26,代码来源:test_commands.py
示例8: copy_raw_data
def copy_raw_data(prep_template, artifact_id):
"""Creates a new raw data by copying from artifact_id
Parameters
----------
prep_template : qiita_db.metadata_template.prep_template.PrepTemplate
The template to attach the artifact
artifact_id : int
The id of the artifact to duplicate
Returns
-------
dict of {str: str}
A dict of the form {'status': str, 'message': str}
"""
from qiita_db.artifact import Artifact
status = 'success'
msg = ''
try:
Artifact.copy(Artifact(artifact_id), prep_template)
except Exception as e:
# We should hit this exception rarely (that's why it is an
# exception) since at this point we have done multiple checks.
# However, it can occur in weird cases, so better let the GUI know
# that this failed
return {'status': 'danger',
'message': "Error creating artifact: %s" % str(e)}
return {'status': status, 'message': msg}
开发者ID:carlyboyd,项目名称:qiita,代码行数:31,代码来源:dispatchable.py
示例9: delete_raw_data
def delete_raw_data(self, study, user, callback):
"""Delete the selected raw data
Parameters
----------
study : Study
The current study object
user : User
The current user object
callback : function
The callback function to call with the results once the processing
is done
"""
raw_data_id = int(self.get_argument('raw_data_id'))
prep_template_id = int(self.get_argument('prep_template_id'))
try:
Artifact.delete(raw_data_id)
msg = ("Raw data %d has been deleted from prep_template %d"
% (raw_data_id, prep_template_id))
msg_level = "success"
except Exception as e:
msg = "Couldn't remove raw data %d: %s" % (raw_data_id, str(e))
msg_level = "danger"
callback((msg, msg_level, "prep_template_tab", prep_template_id, None))
开发者ID:anupriyatripathi,项目名称:qiita,代码行数:26,代码来源:description_handlers.py
示例10: test_patch_artifact_ajax_handler
def test_patch_artifact_ajax_handler(self):
a = Artifact(1)
self.assertEqual(a.name, 'Raw data 1')
arguments = {'op': 'replace', 'path': '/name/', 'value': 'NEW_NAME'}
response = self.patch('/artifact/1/', data=arguments)
self.assertEqual(response.code, 200)
self.assertEqual(a.name, 'NEW_NAME')
a.name = 'Raw data 1'
开发者ID:ElDeveloper,项目名称:qiita,代码行数:8,代码来源:test_base_handlers.py
示例11: test_download
def test_download(self):
# check success
response = self.get('/download/1')
self.assertEqual(response.code, 200)
self.assertEqual(response.body.decode('ascii'), (
"This installation of Qiita was not equipped with nginx, so it "
"is incapable of serving files. The file you attempted to "
"download is located at raw_data/1_s_G1_L001_sequences.fastq.gz"))
self.assertEqual(
response.headers['Content-Disposition'],
"attachment; filename=1_1_s_G1_L001_sequences.fastq.gz")
# other tests to validate the filename
response = self.get('/download/2')
self.assertEqual(
response.headers['Content-Disposition'],
"attachment; filename=1_1_s_G1_L001_sequences_barcodes.fastq.gz")
response = self.get('/download/3')
self.assertEqual(
response.headers['Content-Disposition'],
"attachment; filename=2_1_seqs.fna")
response = self.get('/download/18')
self.assertEqual(
response.headers['Content-Disposition'],
"attachment; filename=1_prep_1_19700101-000000.txt")
response = self.get('/download/22')
self.assertEqual(
response.headers['Content-Disposition'],
"attachment; filename=7_biom_table.biom")
# failure
response = self.get('/download/1000')
self.assertEqual(response.code, 403)
# directory
a = Artifact(1)
fd, fp = mkstemp(suffix='.html')
close(fd)
with open(fp, 'w') as f:
f.write('\n')
self._clean_up_files.append(fp)
dirpath = mkdtemp()
fd, fp2 = mkstemp(suffix='.txt', dir=dirpath)
close(fd)
with open(fp2, 'w') as f:
f.write('\n')
self._clean_up_files.append(dirpath)
a.set_html_summary(fp, support_dir=dirpath)
for x in a.filepaths:
if x['fp_type'] == 'html_summary_dir':
break
response = self.get('/download/%d' % x['fp_id'])
self.assertEqual(response.code, 200)
fp_name = basename(fp2)
dirname = basename(dirpath)
self.assertEqual(response.body.decode('ascii'),
"- 1 /protected/FASTQ/1/%s/%s FASTQ/1/%s/%s\n" % (
dirname, fp_name, dirname, fp_name))
开发者ID:antgonza,项目名称:qiita,代码行数:58,代码来源:test_download.py
示例12: test_artifact_patch_request
def test_artifact_patch_request(self):
a = Artifact(1)
test_user = User('[email protected]')
self.assertEqual(a.name, 'Raw data 1')
artifact_patch_request(test_user, 1, 'replace', '/name/',
req_value='NEW_NAME')
self.assertEqual(a.name, 'NEW_NAME')
# Reset the name
a.name = 'Raw data 1'
# No access
with self.assertRaises(QiitaHTTPError):
artifact_patch_request(User('[email protected]'), 1, 'replace',
'/name/', req_value='NEW_NAME')
# Incorrect path parameter
with self.assertRaises(QiitaHTTPError):
artifact_patch_request(test_user, 1, 'replace',
'/name/wrong/', req_value='NEW_NAME')
# Missing value
with self.assertRaises(QiitaHTTPError):
artifact_patch_request(test_user, 1, 'replace', '/name/')
# Wrong attribute
with self.assertRaises(QiitaHTTPError):
artifact_patch_request(test_user, 1, 'replace',
'/wrong/', req_value='NEW_NAME')
# Wrong operation
with self.assertRaises(QiitaHTTPError):
artifact_patch_request(test_user, 1, 'add', '/name/',
req_value='NEW_NAME')
# Changing visibility
self.assertEqual(a.visibility, 'private')
artifact_patch_request(test_user, 1, 'replace', '/visibility/',
req_value='sandbox')
self.assertEqual(a.visibility, 'sandbox')
# Admin can change to private
artifact_patch_request(User('[email protected]'), 1, 'replace',
'/visibility/', req_value='private')
self.assertEqual(a.visibility, 'private')
# Test user can't change to private
with self.assertRaises(QiitaHTTPError):
artifact_patch_request(test_user, 1, 'replace', '/visibility/',
req_value='private')
# Unkown req value
with self.assertRaises(QiitaHTTPError):
artifact_patch_request(test_user, 1, 'replace', '/visibility/',
req_value='wrong')
开发者ID:ElDeveloper,项目名称:qiita,代码行数:56,代码来源:test_base_handlers.py
示例13: artifact_patch_request
def artifact_patch_request(user_id, req_op, req_path, req_value=None,
req_from=None):
"""Modifies an attribute of the artifact
Parameters
----------
user_id : str
The id of the user performing the patch operation
req_op : str
The operation to perform on the artifact
req_path : str
The prep information and attribute to patch
req_value : str, optional
The value that needs to be modified
req_from : str, optional
The original path of the element
Returns
-------
dict of {str, str}
A dictionary with the following keys:
- status: str, whether if the request is successful or not
- message: str, if the request is unsuccessful, a human readable error
"""
if req_op == 'replace':
req_path = [v for v in req_path.split('/') if v]
if len(req_path) != 2:
return {'status': 'error',
'message': 'Incorrect path parameter'}
artifact_id = req_path[0]
attribute = req_path[1]
# Check if the user actually has access to the artifact
artifact = Artifact(artifact_id)
access_error = check_access(artifact.study.id, user_id)
if access_error:
return access_error
if not req_value:
return {'status': 'error',
'message': 'A value is required'}
if attribute == 'name':
artifact.name = req_value
return {'status': 'success',
'message': ''}
else:
# We don't understand the attribute so return an error
return {'status': 'error',
'message': 'Attribute "%s" not found. '
'Please, check the path parameter' % attribute}
else:
return {'status': 'error',
'message': 'Operation "%s" not supported. '
'Current supported operations: replace' % req_op}
开发者ID:yimsea,项目名称:qiita,代码行数:56,代码来源:artifact.py
示例14: test_get_artifact_summary_handler
def test_get_artifact_summary_handler(self):
a = Artifact(1)
# Add a summary to the artifact
fd, fp = mkstemp(suffix=".html")
close(fd)
with open(fp, 'w') as f:
f.write('<b>HTML TEST - not important</b>\n')
a = Artifact(1)
a.set_html_summary(fp)
self._files_to_remove.extend([fp, a.html_summary_fp[1]])
summary = relpath(a.html_summary_fp[1], qiita_config.base_data_dir)
response = self.get('/artifact/html_summary/%s' % summary)
self.assertEqual(response.code, 200)
self.assertEqual(response.body, '<b>HTML TEST - not important</b>\n')
开发者ID:ElDeveloper,项目名称:qiita,代码行数:15,代码来源:test_base_handlers.py
示例15: post
def post(self, study_id, prep_id):
study = self.safe_get_study(study_id)
if study is None:
return
prep_id = to_int(prep_id)
try:
p = PrepTemplate(prep_id)
except QiitaDBUnknownIDError:
self.fail('Preparation not found', 404)
return
if p.study_id != study.id:
self.fail('Preparation ID not associated with the study', 409)
return
artifact_deets = json_decode(self.request.body)
_, upload = get_mountpoint('uploads')[0]
base = os.path.join(upload, study_id)
filepaths = [(os.path.join(base, fp), fp_type)
for fp, fp_type in artifact_deets['filepaths']]
try:
art = Artifact.create(filepaths,
artifact_deets['artifact_type'],
artifact_deets['artifact_name'],
p)
except QiitaError as e:
self.fail(str(e), 406)
return
self.write({'id': art.id})
self.set_status(201)
self.finish()
开发者ID:antgonza,项目名称:qiita,代码行数:34,代码来源:study_preparation.py
示例16: artifact_status_put_req
def artifact_status_put_req(artifact_id, user_id, visibility):
"""Set the status of the artifact given
Parameters
----------
artifact_id : int
Artifact being acted on
user_id : str
The user requesting the action
visibility : {'sandbox', 'awaiting_approval', 'private', 'public'}
What to change the visibility to
Returns
-------
dict
Status of action, in the form {'status': status, 'message': msg}
status: status of the action, either success or error
message: Human readable message for status
"""
if visibility not in get_visibilities():
return {'status': 'error',
'message': 'Unknown visiblity value: %s' % visibility}
pd = Artifact(int(artifact_id))
access_error = check_access(pd.study.id, user_id)
if access_error:
return access_error
user = User(str(user_id))
status = 'success'
msg = 'Artifact visibility changed to %s' % visibility
# Set the approval to private if needs approval and admin
if visibility == 'private':
if not qiita_config.require_approval:
pd.visibility = 'private'
# Set the approval to private if approval not required
elif user.level == 'admin':
pd.visibility = 'private'
# Trying to set approval without admin privileges
else:
status = 'error'
msg = 'User does not have permissions to approve change'
else:
pd.visibility = visibility
return {'status': status,
'message': msg}
开发者ID:yimsea,项目名称:qiita,代码行数:46,代码来源:artifact.py
示例17: artifact_summary_post_request
def artifact_summary_post_request(user_id, artifact_id):
"""Launches the HTML summary generation and returns the job information
Parameters
----------
user_id : str
The user making the request
artifact_id : int or str
The artifact id
Returns
-------
dict of objects
A dictionary containing the artifact summary information
{'status': str,
'message': str,
'job': list of [str, str, str]}
"""
artifact_id = int(artifact_id)
artifact = Artifact(artifact_id)
access_error = check_access(artifact.study.id, user_id)
if access_error:
return access_error
# Check if the summary is being generated or has been already generated
command = Command.get_html_generator(artifact.artifact_type)
jobs = artifact.jobs(cmd=command)
jobs = [j for j in jobs if j.status in ['queued', 'running', 'success']]
if jobs:
# The HTML summary is either being generated or already generated.
# Return the information of that job so we only generate the HTML
# once
job = jobs[0]
else:
# Create a new job to generate the HTML summary and return the newly
# created job information
job = ProcessingJob.create(
User(user_id),
Parameters.load(command, values_dict={'input_data': artifact_id}))
job.submit()
return {'status': 'success',
'message': '',
'job': [job.id, job.status, job.step]}
开发者ID:yimsea,项目名称:qiita,代码行数:45,代码来源:artifact.py
示例18: display_template
def display_template(self, preprocessed_data_id, msg, msg_level):
"""Simple function to avoid duplication of code"""
preprocessed_data_id = int(preprocessed_data_id)
try:
preprocessed_data = Artifact(preprocessed_data_id)
except QiitaDBUnknownIDError:
raise HTTPError(404, "Artifact %d does not exist!" % preprocessed_data_id)
else:
user = self.current_user
if user.level != "admin":
raise HTTPError(403, "No permissions of admin, " "get/VAMPSSubmitHandler: %s!" % user.id)
prep_template = PrepTemplate(preprocessed_data.prep_template)
sample_template = SampleTemplate(preprocessed_data.study)
study = Study(preprocessed_data.study)
stats = [
("Number of samples", len(prep_template)),
("Number of metadata headers", len(sample_template.categories())),
]
demux = [path for _, path, ftype in preprocessed_data.get_filepaths() if ftype == "preprocessed_demux"]
demux_length = len(demux)
if not demux_length:
msg = "Study does not appear to have demultiplexed " "sequences associated"
msg_level = "danger"
elif demux_length > 1:
msg = "Study appears to have multiple demultiplexed files!"
msg_level = "danger"
elif demux_length == 1:
demux_file = demux[0]
demux_file_stats = demux_stats(demux_file)
stats.append(("Number of sequences", demux_file_stats.n))
msg_level = "success"
self.render(
"vamps_submission.html",
study_title=study.title,
stats=stats,
message=msg,
study_id=study.id,
level=msg_level,
preprocessed_data_id=preprocessed_data_id,
)
开发者ID:mivamo1214,项目名称:qiita,代码行数:44,代码来源:vamps_handlers.py
示例19: artifact_graph_get_req
def artifact_graph_get_req(artifact_id, direction, user_id):
"""Creates graphs of ancestor or descendant artifacts from given one
Parameters
----------
artifact_id : int
Artifact ID to get graph for
direction : {'ancestors', 'descendants'}
What direction to get the graph in
Returns
-------
dict of lists of tuples
A dictionary containing the edge list representation of the graph,
and the node labels. Formatted as:
{'status': status,
'message': message,
'edge_list': [(0, 1), (0, 2)...],
'node_labels': [(0, 'label0'), (1, 'label1'), ...]}
Notes
-----
Nodes are identified by the corresponding Artifact ID.
"""
access_error = check_access(Artifact(artifact_id).study.id, user_id)
if access_error:
return access_error
if direction == 'descendants':
G = Artifact(int(artifact_id)).descendants
elif direction == 'ancestors':
G = Artifact(int(artifact_id)).ancestors
else:
return {
'status': 'error',
'message': 'Unknown directon %s' % direction
}
node_labels = [(n.id, ' - '.join([n.name, n.artifact_type]))
for n in G.nodes()]
return {'edge_list': [(n.id, m.id) for n, m in G.edges()],
'node_labels': node_labels,
'status': 'success',
'message': ''}
开发者ID:yimsea,项目名称:qiita,代码行数:44,代码来源:artifact.py
示例20: make_sandbox
def make_sandbox(self, study, user, callback):
"""Reverts the current study to the 'sandbox' status
Parameters
----------
study : Study
The current study object
user : User
The current user object
callback : function
The callback function to call with the results once the processing
is done
"""
pd_id = int(self.get_argument('pd_id'))
pd = Artifact(pd_id)
pd.visibility = 'sandbox'
_propagate_visibility(pd)
msg = "Processed data reverted to sandbox"
msg_level = "success"
callback((msg, msg_level, "processed_data_tab", pd_id, None))
开发者ID:anupriyatripathi,项目名称:qiita,代码行数:20,代码来源:description_handlers.py
注:本文中的qiita_db.artifact.Artifact类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论