本文整理汇总了Python中qiita_db.data.PreprocessedData类的典型用法代码示例。如果您正苦于以下问题:Python PreprocessedData类的具体用法?Python PreprocessedData怎么用?Python PreprocessedData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PreprocessedData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:DarcyMyers,项目名称:qiita,代码行数:31,代码来源:vamps_handlers.py
示例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))
开发者ID:adamrp,项目名称:qiita,代码行数:26,代码来源:description_handlers.py
示例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)
开发者ID:teravest,项目名称:qiita,代码行数:7,代码来源:test_data.py
示例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)
开发者ID:BrindhaBioinfo,项目名称:qiita,代码行数:32,代码来源:ebi_handlers.py
示例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())
开发者ID:teravest,项目名称:qiita,代码行数:8,代码来源:test_data.py
示例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')
开发者ID:BrindhaBioinfo,项目名称:qiita,代码行数:8,代码来源:test_data.py
示例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'
开发者ID:jwdebelius,项目名称:qiita,代码行数:55,代码来源:processing_pipeline.py
示例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')
开发者ID:MarkBruns,项目名称:qiita,代码行数:54,代码来源:test_commands.py
示例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)
开发者ID:BrindhaBioinfo,项目名称:qiita,代码行数:11,代码来源:test_data.py
示例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
开发者ID:jenwei,项目名称:qiita,代码行数:58,代码来源:commands.py
示例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)
开发者ID:BrindhaBioinfo,项目名称:qiita,代码行数:12,代码来源:test_data.py
示例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
开发者ID:jwdebelius,项目名称:qiita,代码行数:14,代码来源:dispatchable.py
示例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))
开发者ID:adamrp,项目名称:qiita,代码行数:49,代码来源:description_handlers.py
示例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)
开发者ID:jenwei,项目名称:qiita,代码行数:16,代码来源:test_data.py
示例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'
开发者ID:zonca,项目名称:qiita,代码行数:7,代码来源:test_data.py
示例16: test_create_data_type_only
def test_create_data_type_only(self):
# Check that the returned object has the correct id
obs = PreprocessedData.create(self.study, self.params_table,
self.params_id, self.filepaths,
data_type="18S")
self.assertEqual(obs.id, 3)
# Check that the preprocessed data have been correctly added to the DB
obs = self.conn_handler.execute_fetchall(
"SELECT * FROM qiita.preprocessed_data WHERE "
"preprocessed_data_id=3")
# preprocessed_data_id, preprocessed_params_table,
# preprocessed_params_id, submitted_to_insdc_status,
# ebi_submission_accession, ebi_study_accession, data_type_id,
# link_filepaths_status, vamps_status, processing_status
exp = [[3, "preprocessed_sequence_illumina_params", 1,
'not submitted', None, None, 2, 'idle', 'not submitted',
'not_processed']]
self.assertEqual(obs, exp)
# Check that the preprocessed data has been linked with its study
obs = self.conn_handler.execute_fetchall(
"SELECT * FROM qiita.study_preprocessed_data WHERE "
"preprocessed_data_id=3")
exp = [[1, 3]]
self.assertEqual(obs, exp)
# Check that the files have been copied to right location
exp_fna_fp = join(self.db_test_ppd_dir,
"3_%s" % basename(self.fna_fp))
self.assertTrue(exists(exp_fna_fp))
self._clean_up_files.append(exp_fna_fp)
exp_qual_fp = join(self.db_test_ppd_dir,
"3_%s" % basename(self.qual_fp))
self.assertTrue(exists(exp_qual_fp))
self._clean_up_files.append(exp_qual_fp)
# Check that the filepaths have been correctly added to the DB
obs_id = self.conn_handler.execute_fetchone(
"SELECT count(1) from qiita.filepath")[0]
obs = self.conn_handler.execute_fetchall(
"SELECT * FROM qiita.filepath WHERE filepath_id=%d or "
"filepath_id=%d" % (obs_id - 1, obs_id))
exp_fna_fp = "3_%s" % basename(self.fna_fp)
exp_qual_fp = "3_%s" % basename(self.qual_fp)
# filepath_id, path, filepath_type_id
exp = [[obs_id - 1, exp_fna_fp, 4, '852952723', 1, 3],
[obs_id, exp_qual_fp, 5, '852952723', 1, 3]]
self.assertEqual(obs, exp)
# Check that the preprocessed data have been correctly
# linked with the filepaths
obs = self.conn_handler.execute_fetchall(
"SELECT * FROM qiita.preprocessed_filepath WHERE "
"preprocessed_data_id=3")
# preprocessed_data_id, filepath_id
self.assertEqual(obs, [[3, obs_id - 1], [3, obs_id]])
开发者ID:zonca,项目名称:qiita,代码行数:58,代码来源:test_data.py
示例17: test_ebi_study_accession
def test_ebi_study_accession(self):
new = PreprocessedData.create(
self.study, self.params_table,
self.params_id, self.filepaths, prep_template=self.prep_template,
ebi_submission_accession=self.ebi_submission_accession,
ebi_study_accession=self.ebi_study_accession)
new.ebi_study_accession = 'EBI12345-DD'
self.assertEqual(new.ebi_study_accession, 'EBI12345-DD')
开发者ID:BrindhaBioinfo,项目名称:qiita,代码行数:9,代码来源:test_data.py
示例18: test_set_ebi_submission_accession
def test_set_ebi_submission_accession(self):
new = PreprocessedData.create(
self.study, self.params_table, self.params_id, self.filepaths,
raw_data=self.raw_data,
ebi_submission_accession=self.ebi_submission_accession,
ebi_study_accession=self.ebi_study_accession)
new.ebi_submission_accession = 'EBI12345-CC'
self.assertEqual(new.ebi_submission_accession, 'EBI12345-CC')
开发者ID:Jorge-C,项目名称:qiita,代码行数:9,代码来源:test_data.py
示例19: 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 = PreprocessedData(preprocessed_data_id)
except QiitaDBUnknownIDError:
raise HTTPError(404, "PreprocessedData %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:jenwei,项目名称:qiita,代码行数:44,代码来源:vamps_handlers.py
示例20: 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 = PreprocessedData(preprocessed_data_id)
except QiitaDBUnknownIDError:
raise HTTPError(404, "PreprocessedData %d does not exist!" %
preprocessed_data_id)
else:
user = User(self.current_user)
if user.level != 'admin':
raise HTTPError(403, "No permissions of admin, "
"get/EBISubmitHandler: %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.metadata_headers()))]
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('ebi_submission.html', user=self.current_user,
study_title=study.title, stats=stats, message=msg,
study_id=study.id, level=msg_level,
preprocessed_data_id=preprocessed_data_id,
investigation_type=prep_template.investigation_type)
开发者ID:BrindhaBioinfo,项目名称:qiita,代码行数:43,代码来源:ebi_handlers.py
注:本文中的qiita_db.data.PreprocessedData类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论