本文整理汇总了Python中qiita_db.data.PreprocessedData类的典型用法代码示例。如果您正苦于以下问题:Python PreprocessedData类的具体用法?Python PreprocessedData怎么用?Python PreprocessedData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PreprocessedData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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 = PreprocessedData(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)
示例2: delete_preprocessed_data
def delete_preprocessed_data(self, study, user, callback):
"""Delete the selected preprocessed 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
"""
ppd_id = int(self.get_argument('preprocessed_data_id'))
try:
PreprocessedData.delete(ppd_id)
msg = ("Preprocessed data %d has been deleted" % ppd_id)
msg_level = "success"
ppd_id = None
except Exception as e:
msg = ("Couldn't remove preprocessed data %d: %s" %
(ppd_id, str(e)))
msg_level = "danger"
callback((msg, msg_level, 'preprocessed_data_tab', ppd_id, None))
示例3: test_get_filepaths
def test_get_filepaths(self):
"""Correctly returns the filepaths to the preprocessed files"""
ppd = PreprocessedData(1)
obs = ppd.get_filepaths()
exp = [(join(self.db_test_ppd_dir, '1_seqs.fna'), 4),
(join(self.db_test_ppd_dir, '1_seqs.qual'), 5)]
self.assertEqual(obs, exp)
示例4: post
def post(self, preprocessed_data_id):
# make sure user is admin and can therefore actually submit to EBI
if User(self.current_user).level != 'admin':
raise HTTPError(403, "User %s cannot submit to EBI!" %
self.current_user)
submission_type = self.get_argument('submission_type')
if submission_type not in ['ADD', 'MODIFY']:
raise HTTPError(403, "User: %s, %s is not a recognized submission "
"type" % (self.current_user, submission_type))
msg = ''
msg_level = 'success'
preprocessed_data = PreprocessedData(preprocessed_data_id)
state = preprocessed_data.submitted_to_insdc_status()
if state == 'submitting':
msg = "Cannot resubmit! Current state is: %s" % state
msg_level = 'danger'
elif state == 'success' and submission_type == "ADD":
msg = "Cannot resubmit! Current state is: %s, use MODIFY" % state
msg_level = 'danger'
else:
channel = self.current_user
job_id = submit(channel, submit_to_ebi, int(preprocessed_data_id),
submission_type)
self.render('compute_wait.html', user=self.current_user,
job_id=job_id, title='EBI Submission',
completion_redirect='/compute_complete/%s' % job_id)
return
self.display_template(preprocessed_data_id, msg, msg_level)
示例5: test_is_submitted_to_insdc
def test_is_submitted_to_insdc(self):
"""is_submitted_to_insdc works correctly"""
# False case
pd = PreprocessedData(1)
self.assertTrue(pd.is_submitted_to_insdc())
# True case
pd = PreprocessedData(2)
self.assertFalse(pd.is_submitted_to_insdc())
示例6: test_submitted_to_insdc_status
def test_submitted_to_insdc_status(self):
"""submitted_to_insdc_status works correctly"""
# False case
pd = PreprocessedData(1)
self.assertEqual(pd.submitted_to_insdc_status(), 'submitting')
# True case
pd = PreprocessedData(2)
self.assertEqual(pd.submitted_to_insdc_status(), 'not submitted')
示例7: _insert_preprocessed_data
def _insert_preprocessed_data(study, params, prep_template, slq_out,
**kwargs):
"""Inserts the preprocessed data to the database
Parameters
----------
study : Study
The study to preprocess
params : BaseParameters
The parameters to use for preprocessing
prep_template : PrepTemplate
The prep template to use for the preprocessing
slq_out : str
Path to the split_libraries_fastq.py output directory
kwargs: ignored
Necessary to include to support execution via moi.
Raises
------
ValueError
If the preprocessed output directory does not contain all the expected
files
"""
from os.path import exists, join
from functools import partial
from qiita_db.data import PreprocessedData
# The filepaths that we are interested in are:
# 1) seqs.fna -> demultiplexed fasta file
# 2) seqs.fastq -> demultiplexed fastq file
# 3) seqs.demux -> demultiplexed HDF5 file
path_builder = partial(join, slq_out)
fasta_fp = path_builder('seqs.fna')
fastq_fp = path_builder('seqs.fastq')
demux_fp = path_builder('seqs.demux')
log_fp = path_builder('split_library_log.txt')
# Check that all the files exist
if not (exists(fasta_fp) and exists(demux_fp) and exists(log_fp)):
raise ValueError("The output directory %s does not contain all the "
"expected files." % slq_out)
filepaths = [(fasta_fp, "preprocessed_fasta"),
(demux_fp, "preprocessed_demux"),
(log_fp, "log")]
if exists(fastq_fp):
filepaths.append((fastq_fp, "preprocessed_fastq"))
PreprocessedData.create(study, params._table, params.id, filepaths,
prep_template)
# Change the prep_template status to success
prep_template.preprocessing_status = 'success'
示例8: test_update_preprocessed_data_from_cmd
def test_update_preprocessed_data_from_cmd(self):
exp_ppd = PreprocessedData(Study(1).preprocessed_data()[0])
exp_fps = exp_ppd.get_filepaths()
# The original paths mush exist, but they're not included in the test
# so create them here
for _, fp, _ in exp_fps:
with open(fp, 'w') as f:
f.write("")
next_fp_id = get_count('qiita.filepath') + 1
exp_fps.append(
(next_fp_id,
join(self.db_ppd_dir, "%s_split_library_log.txt" % exp_ppd.id),
'log'))
ppd = update_preprocessed_data_from_cmd(self.test_slo, 1)
# Check that the modified preprocessed data is the correct one
self.assertEqual(ppd.id, exp_ppd.id)
# Check that the filepaths returned are correct
# We need to sort the list returned from the db because the ordering
# on that list is based on db modification time, rather than id
obs_fps = sorted(ppd.get_filepaths())
self.assertEqual(obs_fps, sorted(exp_fps))
# Check that the checksums have been updated
sql = "SELECT checksum FROM qiita.filepath WHERE filepath_id=%s"
# Checksum of the fasta file
obs_checksum = self.conn_handler.execute_fetchone(
sql, (obs_fps[0][0],))[0]
self.assertEqual(obs_checksum, '3532748626')
# Checksum of the fastq file
obs_checksum = self.conn_handler.execute_fetchone(
sql, (obs_fps[1][0],))[0]
self.assertEqual(obs_checksum, '2958832064')
# Checksum of the demux file
# The checksum is generated dynamically, so the checksum changes
# We are going to test that the checksum is not the one that was
# before, which corresponds to an empty file
obs_checksum = self.conn_handler.execute_fetchone(
sql, (obs_fps[2][0],))[0]
self.assertTrue(isinstance(obs_checksum, str))
self.assertNotEqual(obs_checksum, '852952723')
self.assertTrue(len(obs_checksum) > 0)
# Checksum of the log file
obs_checksum = self.conn_handler.execute_fetchone(
sql, (obs_fps[3][0],))[0]
self.assertEqual(obs_checksum, '626839734')
示例9: test_get_filepaths
def test_get_filepaths(self):
"""Correctly returns the filepaths to the preprocessed files"""
ppd = PreprocessedData(1)
obs = ppd.get_filepaths()
exp = [(5, join(self.db_test_ppd_dir, '1_seqs.fna'),
"preprocessed_fasta"),
(6, join(self.db_test_ppd_dir, '1_seqs.qual'),
"preprocessed_fastq"),
(7, join(self.db_test_ppd_dir, '1_seqs.demux'),
"preprocessed_demux")]
self.assertEqual(obs, exp)
示例10: submit_VAMPS
def submit_VAMPS(preprocessed_data_id):
"""Submit preprocessed data to VAMPS
Parameters
----------
preprocessed_data_id : int
The preprocesssed data id
"""
preprocessed_data = PreprocessedData(preprocessed_data_id)
study = Study(preprocessed_data.study)
sample_template = SampleTemplate(study.sample_template)
prep_template = PrepTemplate(preprocessed_data.prep_template)
status = preprocessed_data.submitted_to_vamps_status()
if status in ('submitting', 'success'):
raise ValueError("Cannot resubmit! Current status is: %s" % status)
preprocessed_data.update_vamps_status('submitting')
# Generating a tgz
targz_folder = mkdtemp(prefix=qiita_config.working_dir)
targz_fp = join(targz_folder, '%d_%d_%d.tgz' % (study.id,
prep_template.id,
preprocessed_data.id))
targz = taropen(targz_fp, mode='w:gz')
# adding sample/prep
samp_fp = join(targz_folder, 'sample_metadata.txt')
sample_template.to_file(samp_fp)
targz.add(samp_fp, arcname='sample_metadata.txt')
prep_fp = join(targz_folder, 'prep_metadata.txt')
prep_template.to_file(prep_fp)
targz.add(prep_fp, arcname='prep_metadata.txt')
# adding preprocessed data
for _, fp, fp_type in preprocessed_data.get_filepaths():
if fp_type == 'preprocessed_fasta':
targz.add(fp, arcname='preprocessed_fasta.fna')
targz.close()
# submitting
cmd = ("curl -F user=%s -F pass='%s' -F [email protected]%s -F "
"press=UploadFile %s" % (qiita_config.vamps_user,
qiita_config.vamps_pass,
targz_fp,
qiita_config.vamps_url))
obs, _, _ = system_call(cmd)
exp = ("<html>\n<head>\n<title>Process Uploaded File</title>\n</head>\n"
"<body>\n</body>\n</html>")
if obs != exp:
preprocessed_data.update_vamps_status('failure')
return False
else:
preprocessed_data.update_vamps_status('success')
return True
示例11: test_create_error_data_type
def test_create_error_data_type(self):
with self.assertRaises(IncompetentQiitaDeveloperError):
PreprocessedData.create(self.study,
"preprocessed_sequence_illumina_params",
self.params_id, self.filepaths,
data_type="Metabolomics")
with self.assertRaises(IncompetentQiitaDeveloperError):
PreprocessedData.create(self.study,
"preprocessed_sequence_illumina_params",
self.params_id, self.filepaths,
data_type="Metabolomics",
prep_template=self.prep_template)
示例12: processor
def processor(preprocessed_data_id, param_id, param_constructor):
"""Dispatch the processor work"""
preprocessed_data = PreprocessedData(preprocessed_data_id)
params = param_constructor(param_id)
sp = StudyProcessor()
try:
process_out = sp(preprocessed_data, params)
except Exception as e:
error_msg = ''.join(format_exception_only(e, exc_info()))
preprocessed_data.processing_status = "failed: %s" % error_msg
process_out = None
return process_out
示例13: _get_template_variables
def _get_template_variables(self, preprocessed_data_id, callback):
"""Generates all the variables needed to render the template
Parameters
----------
preprocessed_data_id : int
The preprocessed data identifier
callback : function
The callback function to call with the results once the processing
is done
Raises
------
HTTPError
If the preprocessed data does not have a log file
"""
# Get the objects and check user privileges
ppd = PreprocessedData(preprocessed_data_id)
study = Study(ppd.study)
check_access(self.current_user, study, raise_error=True)
# Get the return address
back_button_path = self.get_argument(
'back_button_path',
'/study/description/%d?top_tab=preprocessed_data_tab&sub_tab=%s'
% (study.id, preprocessed_data_id))
# Get all the filepaths attached to the preprocessed data
files_tuples = ppd.get_filepaths()
# Group the files by filepath type
files = defaultdict(list)
for _, fp, fpt in files_tuples:
files[fpt].append(fp)
try:
log_path = files['log'][0]
except KeyError:
raise HTTPError(500, "Log file not found in preprocessed data %s"
% preprocessed_data_id)
with open(log_path, 'U') as f:
contents = f.read()
contents = contents.replace('\n', '<br/>')
contents = contents.replace('\t', ' ')
title = 'Preprocessed Data: %d' % preprocessed_data_id
callback((title, contents, back_button_path))
示例14: test_delete_advanced
def test_delete_advanced(self):
# testing that we can not remove cause preprocessed data has been
# submitted to EBI or VAMPS
ppd = PreprocessedData.create(
self.study, self.params_table,
self.params_id, self.filepaths, prep_template=self.prep_template)
# fails due to VAMPS submission
ppd.update_vamps_status('success')
with self.assertRaises(QiitaDBStatusError):
PreprocessedData.delete(ppd.id)
ppd.update_vamps_status('failed')
ppd = PreprocessedData(1)
with self.assertRaises(QiitaDBStatusError):
PreprocessedData.delete(ppd.id)
示例15: test_processing_status_setter_valueerror
def test_processing_status_setter_valueerror(self):
"""Raises an error if the processing status is not recognized"""
ppd = PreprocessedData.create(self.study, self.params_table,
self.params_id, self.filepaths,
data_type="18S")
with self.assertRaises(ValueError):
ppd.processing_status = 'not a valid state'