Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
36c01b0
Change RawDataTab to PrepTemplateTab
josenavas May 22, 2015
d51b299
Hooking all related with raw data creation
josenavas May 23, 2015
2720331
Adding all bits for raw data deletion
josenavas May 23, 2015
c85e180
Adding bits for adding an existing raw data to a prep template
josenavas May 23, 2015
7394084
Adding bits for updating investigation type
josenavas May 23, 2015
f174eef
Adding preprocessing bits
josenavas May 24, 2015
5035ba0
Merge branch '1084-qiita-ware' into 1084-qiita-pet
josenavas May 24, 2015
8488071
Merge branch '1084-prep-template' into 1084-qiita-pet
josenavas May 25, 2015
40043e6
Removing left out print code
josenavas May 25, 2015
412046c
Making sure that all return pages go to the 'prep_template_tab' inste…
josenavas May 25, 2015
5feb3d9
Removing leftover code
josenavas May 25, 2015
07b7e65
Adding ability to (un)link raw data files
josenavas May 25, 2015
308ce03
Solving merge conflicts
josenavas May 25, 2015
fdaa7e7
Disabling processing if raw data has no files attached
josenavas May 25, 2015
8378311
Merge branch '1084-data' into 1084-qiita-pet
josenavas May 25, 2015
900a391
Fixing qiita_pet tests
josenavas May 25, 2015
ecd494e
Fixing test_data_studies/commands.sh
josenavas May 25, 2015
66f72c6
Making sure tests clean the environment
josenavas May 25, 2015
ee9183d
Fixing tests in travis
josenavas May 25, 2015
f65e9da
My ~~friend~~ PEP8...
josenavas May 25, 2015
1258155
Merge branch 'fix-1084' of https://github.com/biocore/qiita into 1084…
josenavas May 28, 2015
0826895
Addressing some comments
josenavas May 29, 2015
94ca93e
Fixing accordions width
josenavas May 29, 2015
10a69d8
Addressing more comments
josenavas May 29, 2015
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
2 changes: 1 addition & 1 deletion qiita_db/test/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def test_update_preprocessed_data_from_cmd(self):
# 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, exp_fps)
self.assertEqual(obs_fps, sorted(exp_fps))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'assertItemsEqual' would be better here, since it would eliminate the sorting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other checks in this tests depend on these 2 lists being in the same order. Leaving the sort.


# Check that the checksums have been updated
sql = "SELECT checksum FROM qiita.filepath WHERE filepath_id=%s"
Expand Down
7 changes: 6 additions & 1 deletion qiita_db/test/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ def test_delete(self):
RawData.delete(rd.id, self.pt1.id)

# Clear the files so we can actually remove the RawData
study_id = rd.studies[0]
path_for_removal = join(get_mountpoint("uploads")[0][1], str(study_id))
self._clean_up_files.extend([join(path_for_removal,
basename(f).split('_', 1)[1])
for _, f, _ in rd.get_filepaths()])
rd.clear_filepaths()

RawData.delete(rd.id, self.pt1.id)
Expand Down Expand Up @@ -545,7 +550,7 @@ def test_get_filepaths(self):
"preprocessed_fastq"),
(5, join(self.db_test_ppd_dir, '1_seqs.demux'),
"preprocessed_demux")]
self.assertEqual(obs, exp)
self.assertItemsEqual(obs, exp)

def test_processed_data(self):
"""Correctly returns the processed data id"""
Expand Down
6 changes: 5 additions & 1 deletion qiita_db/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,11 @@ def test_move_upload_files_to_trash(self):

# create file to move to trash
fid, folder = get_mountpoint("uploads")[0]
open(join(folder, '1', test_filename), 'w').write('test')
test_fp = join(folder, '1', test_filename)
with open(test_fp, 'w') as f:
f.write('test')

self.files_to_remove.append(test_fp)

exp = [(fid, 'this_is_a_test_file.txt'), (fid, 'uploaded_file.txt')]
obs = get_files_from_uploads_folders("1")
Expand Down
61 changes: 56 additions & 5 deletions qiita_pet/handlers/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from .util import check_access

from qiita_ware.context import submit
from qiita_ware.dispatchable import add_files_to_raw_data, unlink_all_files
from qiita_ware.dispatchable import (add_files_to_raw_data, unlink_all_files,
create_raw_data)

from qiita_db.study import Study
from qiita_db.exceptions import QiitaDBUnknownIDError
from qiita_db.util import get_mountpoint
from qiita_db.metadata_template import PrepTemplate

from os.path import join, exists

Expand All @@ -28,13 +30,61 @@ def get(self, job_id):
self.redirect('/')


class CreateRawData(BaseHandler):
@authenticated
def post(self):
pt_id = self.get_argument('prep_template_id')
raw_data_filetype = self.get_argument('filetype')
barcodes_str = self.get_argument('barcodes')
forward_reads_str = self.get_argument('forward')
sff_str = self.get_argument('sff')
fasta_str = self.get_argument('fasta')
qual_str = self.get_argument('qual')
reverse_reads_str = self.get_argument('reverse')

pt = PrepTemplate(pt_id)
study_id = pt.study_id

def _split(x):
return x.split(',') if x else []
filepaths, fps = [], []
fps.append((_split(barcodes_str), 'raw_barcodes'))
fps.append((_split(fasta_str), 'raw_fasta'))
fps.append((_split(qual_str), 'raw_qual'))
fps.append((_split(forward_reads_str), 'raw_forward_seqs'))
fps.append((_split(reverse_reads_str), 'raw_reverse_seqs'))
fps.append((_split(sff_str), 'raw_sff'))

# We need to retrieve the full path for all the files, as the
# arguments only contain the file name. Since we don't know in which
# mountpoint the data lives, we retrieve all of them and we loop
# through all the files checking if they exist or not.
for _, f in get_mountpoint("uploads", retrieve_all=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a comment describing this block, it took me a while to understand it 👓

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

f = join(f, str(study_id))
for fp_set, filetype in fps:
for t in fp_set:
ft = join(f, t)
if exists(ft):
filepaths.append((ft, filetype))

job_id = submit(self.current_user.id, create_raw_data,
raw_data_filetype, pt, filepaths)

self.render('compute_wait.html',
job_id=job_id, title='Adding raw data',
completion_redirect=(
'/study/description/%s?top_tab=prep_template_tab'
'&sub_tab=%s' % (study_id, pt_id)))


class AddFilesToRawData(BaseHandler):
@authenticated
def post(self):

# vars to add files to raw data
study_id = self.get_argument('study_id')
raw_data_id = self.get_argument('raw_data_id')
prep_template_id = self.get_argument('prep_template_id')
barcodes_str = self.get_argument('barcodes')
forward_reads_str = self.get_argument('forward')
sff_str = self.get_argument('sff')
Expand Down Expand Up @@ -75,8 +125,8 @@ def _split(x):
self.render('compute_wait.html',
job_id=job_id, title='Adding files to your raw data',
completion_redirect=(
'/study/description/%s?top_tab=raw_data_tab&sub_tab=%s'
% (study_id, raw_data_id)))
'/study/description/%s?top_tab=prep_template_tab'
'&sub_tab=%s' % (study_id, prep_template_id)))


class UnlinkAllFiles(BaseHandler):
Expand All @@ -85,6 +135,7 @@ def post(self):
# vars to remove all files from a raw data
study_id = self.get_argument('study_id', None)
raw_data_id = self.get_argument('raw_data_id', None)
prep_template_id = self.get_argument('prep_template_id', None)

study_id = int(study_id) if study_id else None

Expand All @@ -101,5 +152,5 @@ def post(self):
self.render('compute_wait.html', job_id=job_id,
title='Removing files from your raw data',
completion_redirect=(
'/study/description/%s?top_tab=raw_data_tab&sub_tab=%s'
% (study_id, raw_data_id)))
'/study/description/%s?top_tab=prep_template_tab&'
'sub_tab=%s' % (study_id, prep_template_id)))
5 changes: 2 additions & 3 deletions qiita_pet/handlers/preprocessing_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ def post(self):
self.render('compute_wait.html',
job_id=job_id, title='Preprocessing',
completion_redirect='/study/description/%d?top_tab='
'raw_data_tab&sub_tab=%s&prep_tab=%s'
% (study_id, raw_data.id,
prep_template_id))
'prep_template_tab&sub_tab=%s'
% (study_id, prep_template_id))
95 changes: 33 additions & 62 deletions qiita_pet/handlers/study_handlers/description_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ def add_to_sample_template(self, study, user, callback):

callback((msg, msg_level, None, None, None))

def create_raw_data(self, study, user, callback):
"""Adds a (new) raw data to the study
def add_raw_data(self, study, user, callback):
"""Adds an existing raw data to the study

Parameters
----------
Expand All @@ -328,41 +328,20 @@ def create_raw_data(self, study, user, callback):
msg = "Raw data successfully added"
msg_level = "success"

# Get the arguments needed to create a raw data object
filetype = self.get_argument('filetype', None)
previous_raw_data = self.get_argument('previous_raw_data', None)
# Get the arguments to add the raw data
pt_id = self.get_argument('prep_template_id')
raw_data_id = self.get_argument('raw_data_id')

if filetype and previous_raw_data:
# The user selected a filetype and an existing raw data
msg = ("You can not specify both a new raw data and a previously "
"used one")
msg_level = "danger"
elif filetype:
# We are creating a new raw data object
try:
rd_id = RawData.create(filetype, [study]).id
except (TypeError, QiitaDBColumnError, QiitaDBExecutionError,
QiitaDBDuplicateError, IOError, ValueError, KeyError,
CParserError) as e:
msg = html_error_message % (
"creating a new raw data object for study:",
str(study.id), str(e))
msg_level = "danger"
elif previous_raw_data:
previous_raw_data = previous_raw_data.split(',')
raw_data = [RawData(rd) for rd in previous_raw_data]
study.add_raw_data(raw_data)
rd_id = raw_data[0].id
else:
# The user did not provide a filetype neither an existing raw data
# If using the interface, we should never reach this if, but
# better be safe than sorry
msg = ("You should choose a filetype for a new raw data or "
"choose a raw data previously used")
msg_level = "danger"
rd_id = None
prep_template = PrepTemplate(pt_id)
raw_data = RawData(raw_data_id)

callback((msg, msg_level, 'raw_data_tab', rd_id, None))
try:
prep_template.raw_data = raw_data
except QiitaDBError as e:
msg = html_error_message % ("adding the raw data",
str(raw_data_id), str(e))

callback((msg, msg_level, 'prep_template_tab', pt_id, None))

def add_prep_template(self, study, user, callback):
"""Adds a prep template to the system
Expand All @@ -380,10 +359,9 @@ def add_prep_template(self, study, user, callback):
msg = "Your prep template was added"
msg_level = "success"

# If we are on this function, the arguments "raw_data_id",
# "prep_template" and "data_type_id" must be defined. If not,
# If we are on this function, the arguments "prep_template" and
# "data_type_id" must be defined. If not,
# let tornado raise its error
raw_data_id = self.get_argument('raw_data_id')
prep_template = self.get_argument('prep_template')
data_type_id = self.get_argument('data_type_id')

Expand All @@ -398,8 +376,6 @@ def add_prep_template(self, study, user, callback):
investigation_type, user_defined_investigation_type,
new_investigation_type)

# Make sure that the id is an integer
raw_data_id = _to_int(raw_data_id)
# Get the upload base directory
_, base_path = get_mountpoint("uploads")[0]
# Get the path to the prep template
Expand All @@ -414,8 +390,8 @@ def add_prep_template(self, study, user, callback):
warnings.simplefilter("always")

# deleting previous uploads and inserting new one
pt_id = self.remove_add_prep_template(fp_rpt, raw_data_id,
study, data_type_id,
pt_id = self.remove_add_prep_template(fp_rpt, study,
data_type_id,
investigation_type)

# join all the warning messages into one. Note that this info
Expand All @@ -433,7 +409,7 @@ def add_prep_template(self, study, user, callback):
basename(fp_rpt), str(e))
msg_level = "danger"

callback((msg, msg_level, 'raw_data_tab', raw_data_id, pt_id))
callback((msg, msg_level, 'prep_template_tab', pt_id, None))

def make_public(self, study, user, callback):
"""Makes the current study public
Expand Down Expand Up @@ -547,7 +523,6 @@ def update_investigation_type(self, study, user, callback):
'edit-new-investigation-type', None)

pt = PrepTemplate(prep_id)
rd_id = pt.raw_data

investigation_type = self._process_investigation_type(
edit_investigation_type, edit_user_defined_investigation_type,
Expand All @@ -561,9 +536,9 @@ def update_investigation_type(self, study, user, callback):
msg_level = "danger"

if ppd_id == 0:
top_tab = "raw_data_tab"
sub_tab = rd_id
prep_tab = prep_id
top_tab = "prep_template_tab"
sub_tab = prep_id
prep_tab = None
else:
top_tab = "preprocessed_data_tab"
sub_tab = ppd_id
Expand Down Expand Up @@ -604,12 +579,11 @@ def remove_add_study_template(self, raw_data, study_id, fp_rsp):
Study(study_id))
remove(fp_rsp)

def remove_add_prep_template(self, fp_rpt, raw_data_id, study,
data_type_id, investigation_type):
def remove_add_prep_template(self, fp_rpt, study, data_type_id,
investigation_type):
"""add prep templates"""
pt_id = PrepTemplate.create(load_template_to_dataframe(fp_rpt),
RawData(raw_data_id), study,
_to_int(data_type_id),
study, _to_int(data_type_id),
investigation_type=investigation_type).id
remove(fp_rpt)
return pt_id
Expand Down Expand Up @@ -730,21 +704,18 @@ def delete_raw_data(self, study, user, callback):
is done
"""
raw_data_id = int(self.get_argument('raw_data_id'))
prep_template_id = int(self.get_argument('prep_template_id'))

try:
RawData.delete(raw_data_id, study.id)
msg = ("Raw data %d has been deleted from study: "
"<b><i>%s</i></b>" % (raw_data_id, study.title))
RawData.delete(raw_data_id, prep_template_id)
msg = ("Raw data %d has been deleted from prep_template %d"
% (raw_data_id, prep_template_id))
msg_level = "success"
tab = 'study_information_tab'
tab_id = None
except Exception as e:
msg = "Couldn't remove %d raw data: %s" % (raw_data_id, str(e))
msg = "Couldn't remove raw data %d: %s" % (raw_data_id, str(e))
msg_level = "danger"
tab = 'raw_data_tab'
tab_id = raw_data_id

callback((msg, msg_level, tab, tab_id, None))
callback((msg, msg_level, "prep_template_tab", prep_template_id, None))

def delete_prep_template(self, study, user, callback):
"""Delete the selected prep template
Expand All @@ -771,7 +742,7 @@ def delete_prep_template(self, study, user, callback):
msg = ("Couldn't remove prep template: %s" % str(e))
msg_level = "danger"

callback((msg, msg_level, 'raw_data_tab', prep_id, None))
callback((msg, msg_level, 'prep_template_tab', prep_id, None))

def delete_preprocessed_data(self, study, user, callback):
"""Delete the selected preprocessed data
Expand Down Expand Up @@ -850,7 +821,7 @@ def post(self, study_id):
process_sample_template=self.process_sample_template,
update_sample_template=self.update_sample_template,
extend_sample_template=self.add_to_sample_template,
create_raw_data=self.create_raw_data,
add_raw_data=self.add_raw_data,
add_prep_template=self.add_prep_template,
make_public=self.make_public,
approve_study=self.approve_study,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def get(self, arguments):
# The prep template has been provided
template = self._get_template(PrepTemplate, prep_template)
back_button_path = (
"/study/description/%s?top_tab=raw_data_tab&sub_tab=%s"
"&prep_tab=%s" % (study_id, template.raw_data, template.id))
"/study/description/%s?top_tab=prep_template_tab&sub_tab=%s"
% (study_id, template.id))
elif sample_template:
# The sample template has been provided
template = self._get_template(SampleTemplate, sample_template)
Expand Down
Loading