Skip to content

Analysis refactor sync with master - DEPENDS ON #2138 #2139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
221 commits
Select commit Hold shift + click to select a range
3601c29
fix #1505
antgonza Jan 2, 2017
0d6788e
improving some GUI stuff
antgonza Jan 3, 2017
12406cc
improving some GUI stuff - missing lines
antgonza Jan 3, 2017
958fcbe
pull upstream master
antgonza Jan 4, 2017
a57ef23
addressing all comments
antgonza Jan 5, 2017
2ead7a6
ready for review
antgonza Jan 5, 2017
73a78e7
fix #1987
antgonza Jan 16, 2017
e64a22a
Merge pull request #2036 from antgonza/fix-1505
josenavas Jan 16, 2017
0dcae8b
Merge pull request #2047 from antgonza/fix-1987
josenavas Jan 17, 2017
4a5bbbc
initial commit
antgonza Jan 18, 2017
f99975c
requested changes
antgonza Jan 18, 2017
ed899a8
Merge pull request #2049 from antgonza/add-processing-suggestions
josenavas Jan 18, 2017
d508320
fix filter job list
antgonza Jan 18, 2017
025cc1e
Merge pull request #2050 from antgonza/fix-filter-job-list
josenavas Jan 18, 2017
599bcde
Fixing server cert (#2051)
josenavas Jan 19, 2017
d12ccfe
fix get_studies
antgonza Jan 20, 2017
b33983b
flake8
antgonza Jan 20, 2017
b4f1b1f
fix #503
antgonza Jan 20, 2017
62a1b93
fix #2010
antgonza Jan 20, 2017
2e36141
fix #1913
antgonza Jan 21, 2017
e006e20
fix errors
antgonza Jan 21, 2017
c174693
Merge pull request #2052 from antgonza/fix-get_studies
josenavas Jan 23, 2017
131dd6a
Merge pull request #2053 from antgonza/fix-by-blinking
josenavas Jan 23, 2017
ccb55bd
addressing @josenavas comment
antgonza Jan 24, 2017
dfe2e83
flake8
antgonza Jan 24, 2017
15fcceb
Merge pull request #2056 from antgonza/fix-1913
josenavas Jan 24, 2017
7f97f2a
fix #1010
antgonza Jan 26, 2017
9eb9dbb
fix #1066 (#2058)
antgonza Jan 26, 2017
23104d7
addressing @josenavas comments
antgonza Jan 27, 2017
1f1e826
fix #1961
antgonza Jan 27, 2017
19a9dda
fix #1837
antgonza Jan 27, 2017
19889f9
Automatic jobs & new stats (#2057)
antgonza Jan 27, 2017
4e380e0
Merge pull request #2060 from antgonza/fix-1961
wasade Jan 28, 2017
6f0dd71
generalizing this functionality
antgonza Jan 28, 2017
a7925b8
Merge branch 'master' of https://github.com/biocore/qiita into fix-1805
antgonza Jan 28, 2017
9d3fa5c
fix #1805
antgonza Jan 29, 2017
a70163b
adding button
antgonza Jan 29, 2017
1626859
fix errors
antgonza Jan 29, 2017
ed9fc65
fix #1816
antgonza Jan 29, 2017
ade8cbe
fixing failures tests
antgonza Jan 30, 2017
4b19b45
fix #1959
antgonza Jan 30, 2017
d9b41e8
addressing @josenavas comments
antgonza Feb 1, 2017
5ef06ae
addressing @josenavas comments
antgonza Feb 2, 2017
5e3504a
fixing error
antgonza Feb 2, 2017
d10096a
Merge branch 'master' of https://github.com/biocore/qiita into fix-1010
antgonza Feb 2, 2017
661342f
fixed?
antgonza Feb 2, 2017
fcd249b
addressing @josenavas comments
antgonza Feb 3, 2017
f3c1216
Merge pull request #2063 from antgonza/fix-1816
josenavas Feb 3, 2017
a91a6fd
Merge pull request #2064 from antgonza/fix-1959
tanaes Feb 3, 2017
7b9fa6f
addressing @wasade comments
antgonza Feb 3, 2017
33bcbe5
Merge pull request #2059 from antgonza/fix-1010
josenavas Feb 3, 2017
5e4bd9b
Merge branch 'master' of https://github.com/biocore/qiita into fix-1837
antgonza Feb 3, 2017
8bf3d6e
fix flake8
antgonza Feb 3, 2017
7807bac
Merge pull request #2061 from antgonza/fix-1837
josenavas Feb 3, 2017
6360675
generate biom and metadata release (#2066)
antgonza Feb 3, 2017
811b7a7
database changes to fix 969
antgonza Feb 3, 2017
751d4ad
adding delete
antgonza Feb 3, 2017
65a86df
addressing @josenavas comments
antgonza Feb 3, 2017
b1817dd
addressing @ElDeveloper comments
antgonza Feb 4, 2017
18d77e1
duh!
antgonza Feb 4, 2017
01c656c
Merge pull request #2071 from antgonza/fix-969-db
josenavas Feb 6, 2017
53188a6
fix generate_biom_and_metadata_release (#2072)
antgonza Feb 7, 2017
1ab4e3b
Fixing merge conflicts with master
josenavas Feb 8, 2017
1e8332e
Merge branch 'analysis-refactor' of https://github.com/biocore/qiita …
josenavas Feb 9, 2017
cb67d3d
Removing qiita ware code that will not be used anymore
josenavas Feb 9, 2017
5a5127d
Merge branch 'analysis-refactor' of https://github.com/biocore/qiita …
josenavas Feb 9, 2017
0033480
Organizing the handlers and new analysis description page
josenavas Feb 9, 2017
3e3f6e1
fixing timestamp
antgonza Feb 9, 2017
6a20c1b
rm formats
antgonza Feb 9, 2017
a1b3c90
st -> pt
antgonza Feb 9, 2017
3809ad5
Connecting the analysis creation and making interface responsive
josenavas Feb 9, 2017
067f14f
Addressing @antgonza's comments
josenavas Feb 10, 2017
cf4862d
Solving merge conflicts
josenavas Feb 10, 2017
3b07151
Initial artifact GUI refactor
josenavas Feb 10, 2017
a6595a9
Removing unused code
josenavas Feb 10, 2017
6343b49
Merge branch 'analysis-refactor-gui-part2' into analysis-refactor-gui…
josenavas Feb 10, 2017
a3505c2
moving to ISO 8601 - wow :'(
antgonza Feb 13, 2017
c8113ea
fix errors
antgonza Feb 13, 2017
f4835d5
addressing @wasade comments
antgonza Feb 13, 2017
f731768
Adding can_edit call to the analysis
josenavas Feb 14, 2017
7542658
Fixing artifact rest API since not all artifacts have study
josenavas Feb 14, 2017
e0180e8
Adding can_be_publicized call to analysis
josenavas Feb 15, 2017
f55ca5c
Adding QiitaHTTPError to handle errors gracefully
josenavas Feb 15, 2017
1fa4b19
Adding safe_execution contextmanager
josenavas Feb 15, 2017
b61ae87
Fixing typo
josenavas Feb 15, 2017
bb68303
Adding qiita test checker
josenavas Feb 15, 2017
b31a025
Adapting some artifact handlers
josenavas Feb 15, 2017
378d7ff
Fixing merge conflicts
josenavas Feb 15, 2017
444da08
Merge branch 'analysis-refactor-gui-part2' into analysis-refactor-gui…
josenavas Feb 15, 2017
f6b4c46
Abstracting the graph reloading and adding some documentation
josenavas Feb 15, 2017
e9d3af3
Fixing typo
josenavas Feb 15, 2017
69b6412
Merge branch 'analysis-refactor-gui-part3' into analysis-refactor-gui…
josenavas Feb 15, 2017
60cd430
Fixing changing artifact visibility
josenavas Feb 15, 2017
be099cb
Fixing delete
josenavas Feb 15, 2017
819e9a5
Fixing artifact deletion
josenavas Feb 15, 2017
e941fa7
Adding default parameters to the commands
josenavas Feb 15, 2017
d6ebcb4
Fixing processing page
josenavas Feb 15, 2017
6ada2ba
Fixing variable name
josenavas Feb 15, 2017
7d70a38
fixing private/public studies
antgonza Feb 15, 2017
e8ca9db
Changing bdiv metrics to single choice
josenavas Feb 15, 2017
4bf4808
Merge pull request #2080 from antgonza/fix-private_public-stats-page
josenavas Feb 15, 2017
aa68a21
Merge pull request #2075 from antgonza/fix-timestamp
wasade Feb 15, 2017
0c6ffa7
sanbox-to-sandbox
antgonza Feb 15, 2017
586660b
flake8
antgonza Feb 15, 2017
6cdc574
Fixing patch
josenavas Feb 15, 2017
7bae13e
fixing other issues
antgonza Feb 16, 2017
cf801a4
Merge pull request #2082 from antgonza/sanbox-to-sandbox
josenavas Feb 16, 2017
7c2454e
adding share documentation
antgonza Mar 3, 2017
c2eb6ae
psycopg2 <= 2.7
antgonza Mar 3, 2017
aeeac62
psycopg2 < 2.7
antgonza Mar 3, 2017
2795046
Merge pull request #2085 from antgonza/sharing-help
josenavas Mar 3, 2017
a77b040
Various small fixes to be able to run tests on the plugins
josenavas Mar 15, 2017
ff9eda9
Merging with master
josenavas Mar 15, 2017
6145976
Adding private module
josenavas Mar 15, 2017
7153efb
Fixing processing job completion
josenavas Mar 15, 2017
46dd73d
Fixing patch 52
josenavas Mar 16, 2017
08eafaa
Fixing call
josenavas Mar 16, 2017
b1a3e99
Fixing complete
josenavas Mar 17, 2017
c9580b7
small fixes
josenavas Mar 17, 2017
56b7da5
init commit
antgonza Mar 21, 2017
ba2745b
fixing conflicts
antgonza Mar 21, 2017
8e3ec27
fixing errors
antgonza Mar 21, 2017
890d465
fixing errors due to update
antgonza Mar 21, 2017
55fe223
Making the download work
josenavas Mar 21, 2017
d96da86
Fixing tests
josenavas Mar 22, 2017
0c136c6
working status
antgonza Mar 22, 2017
a9bc599
adding tags, the right way!
antgonza Mar 22, 2017
0af93ff
fix error
antgonza Mar 22, 2017
1859c88
Addressing @antgonza's comments
josenavas Mar 22, 2017
e90ad50
Adding missing test
josenavas Mar 22, 2017
587e5bf
Ignoring tgz - thanks @antgonza
josenavas Mar 24, 2017
56d8b0a
addressing @josenavas comments
antgonza Mar 25, 2017
2fd68bf
list study tags
antgonza Mar 26, 2017
c457554
fix error
antgonza Mar 26, 2017
bba8f03
adding tags to public
antgonza Mar 27, 2017
8ef50c1
adding docs
antgonza Mar 27, 2017
e6a65a3
addressing @wasade comment
antgonza Mar 27, 2017
208bac3
Merge pull request #2093 from antgonza/fix-1805
wasade Mar 27, 2017
fd0b879
addressing @josenavas and @wasade comments
antgonza Mar 27, 2017
d6f5223
addressing @wasade request
antgonza Mar 27, 2017
2369a5e
erge branch 'master' of https://github.com/biocore/qiita into listing…
antgonza Mar 27, 2017
d3555ac
Merge pull request #2088 from antgonza/adding-tags
wasade Mar 27, 2017
fdb6723
Merge branch 'master' of https://github.com/biocore/qiita into listin…
antgonza Mar 27, 2017
31dae8d
fix #2091
antgonza Mar 29, 2017
e306f32
option 2: @ElDeveloper and @josenavas
antgonza Mar 29, 2017
64e7225
Merge pull request #2095 from antgonza/fix-2091
josenavas Mar 29, 2017
d803f42
Merge pull request #2092 from antgonza/listing-tags
wasade Mar 29, 2017
8f6d193
A minimal REST API for Qiita (#2094)
ElDeveloper Mar 30, 2017
e07a880
ENH/DOC: update/add samples to sample information via rest (#2097)
wasade Apr 2, 2017
c309aa6
Changing how artifact visibility works (#2098)
antgonza Apr 4, 2017
1acc9b2
fixing edit check access
antgonza Apr 5, 2017
a8946bf
Merge pull request #2100 from antgonza/fix-edit_check_access
tanaes Apr 5, 2017
28e18fe
fix
antgonza Apr 5, 2017
a60cec2
Merge pull request #2101 from antgonza/patch-53_fix
josenavas Apr 5, 2017
dc254ba
fix #2086
antgonza Apr 6, 2017
b6eb3bd
flak8
antgonza Apr 6, 2017
6ad9a35
addressing @ElDeveloper comments + fixes
antgonza Apr 6, 2017
17341a0
adding the final changes
antgonza Apr 10, 2017
cc7f0d0
fix failures
antgonza Apr 10, 2017
2b8d608
get_qiita_version -> generate_biom_and_metadata_release
antgonza Apr 10, 2017
4765055
download raw data
antgonza Apr 10, 2017
0f0be35
adding missing empty files
antgonza Apr 10, 2017
dc0b029
Adding endpoint to retrieve list of person (#2103)
josenavas Apr 10, 2017
56a20b4
fix #2086 (#2102)
antgonza Apr 10, 2017
c31ea7d
fixing conflicts
antgonza Apr 10, 2017
324a385
addressing @wasade comments and fix errors
antgonza Apr 11, 2017
f7b61e7
fix error?
antgonza Apr 11, 2017
5c598c7
rm vfabu + addressing @wasade and @josenavas comments + fix errors
antgonza Apr 11, 2017
7d1ea83
just being dumb!
antgonza Apr 11, 2017
bef4640
Merge pull request #2104 from antgonza/download-raw-data
wasade Apr 11, 2017
5489845
Deblur quality mention (#2107)
wasade Apr 18, 2017
6c91bd8
Revised rst values used for section headers (#2108)
wasade Apr 18, 2017
85d4aa7
Solving merge conflicts
josenavas Apr 24, 2017
1ffa231
Solving merge conflicts
josenavas Apr 24, 2017
9e14cc6
Merge branch 'analysis-refactor-gui-part5' into analysis-refactor-gui…
josenavas Apr 24, 2017
4cd34d2
Merge branch 'analysis-refactor-gui-part6' into analysis-refactor-gui…
josenavas Apr 24, 2017
bf33527
Solving merge conflicts
josenavas Apr 25, 2017
3529556
Adding processing handlers
josenavas Apr 25, 2017
b5c7fd5
Fixing latlongs (#2120)
josenavas Apr 28, 2017
4ecff71
public studies are being shown in the user own studies
antgonza Apr 29, 2017
cde1294
fix #2069 - adding tests
antgonza Apr 29, 2017
219f479
flake8
antgonza Apr 29, 2017
50bfc4a
Merge pull request #2122 from antgonza/user-kept-public-study
josenavas Apr 29, 2017
ca5a331
Fixing url and bug on processing job workflow
josenavas May 1, 2017
b934d68
Adding the private script runner
josenavas May 1, 2017
fa00d60
Adding is_analysis column to the command
josenavas May 1, 2017
b2ac959
Adding retrieval of commands excluding analysis commands
josenavas May 1, 2017
0326a63
Addressing bug on retrieving information from redis
josenavas May 1, 2017
cd6b61c
Enabling the command register endpoint to provide if the command is a…
josenavas May 4, 2017
0dd5496
Improving study list speed (#2123)
antgonza May 4, 2017
2282e74
fixing download buttons show (#2127)
antgonza May 4, 2017
d3b72ce
connecting tutorials to CMI
antgonza May 6, 2017
504b83e
adding link in main page
antgonza May 6, 2017
e9f86d2
fixing prep getting-started
antgonza May 6, 2017
7d7a399
mv complex designs
antgonza May 7, 2017
30141ad
fix idents
antgonza May 7, 2017
659cb94
Merge pull request #2130 from antgonza/connecting-with-cmi-workshops
May 9, 2017
cccb1d4
Addressing @antgonza's comments
josenavas May 16, 2017
0a584f3
Addressing @wasade's comments
josenavas May 16, 2017
a33d14f
Supporting multiple choice
josenavas May 17, 2017
66986ab
Adding documentation
josenavas May 17, 2017
1f47f06
limiting number of jobs retrieved
antgonza May 19, 2017
3e36212
Modifying handler to pass allow_change_optionals
josenavas May 22, 2017
e04d03d
Solving merge conflicts
josenavas May 22, 2017
dc3a51e
returning optional parameters
josenavas May 22, 2017
12235a7
Addressing bug found by @antgonza
josenavas May 22, 2017
9bb1fd5
Merge pull request #2134 from antgonza/limit-jobs
wasade May 22, 2017
f5c5811
Enabling changing the default parameters
josenavas May 22, 2017
08554e1
Adding correct class
josenavas May 22, 2017
04a0c26
Allowing user to change default parameters
josenavas May 24, 2017
4330dae
Fixing bug with commands listing
josenavas May 24, 2017
4afa539
Enabling arbitrary htmls in the summary
josenavas May 31, 2017
6a0c7fc
Prepping for merge hell
josenavas May 31, 2017
b6c11b8
Fixing merge conflicts
josenavas May 31, 2017
3b8acdc
Addressing @wasade's comments
josenavas May 31, 2017
389ea9f
Merge branch 'analysis-refactor-allow-users-change-dflt-params' into …
josenavas May 31, 2017
bdf7cb1
Merge branch 'analysis-refactor-embed-html' into analysis-refactor-sy…
josenavas May 31, 2017
29b6acf
Merge branch 'analysis-refactor' of https://github.com/biocore/qiita …
josenavas Jun 1, 2017
b35e07c
Addressing @antgonza's comment
josenavas Jun 1, 2017
8128120
Merge branch 'analysis-refactor-embed-html' into analysis-refactor-sy…
josenavas Jun 1, 2017
ddd50ad
Merge branch 'analysis-refactor' of https://github.com/biocore/qiita …
josenavas Jun 1, 2017
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
18 changes: 17 additions & 1 deletion qiita_core/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

from qiita_core.util import (
send_email, qiita_test_checker, execute_as_transaction, get_qiita_version,
is_test_environment)
is_test_environment, get_release_info)
from qiita_db.meta_util import generate_biom_and_metadata_release
import qiita_db as qdb


Expand Down Expand Up @@ -64,6 +65,21 @@ def test_get_qiita_version(self):
# testing just the version
self.assertEqual(exp_version, qdb.__version__)

def test_get_release_info(self):
# making sure there is a release
generate_biom_and_metadata_release('private')
# just checking that is not empty cause the MD5 will change on every
# run
md5sum, filepath, timestamp = get_release_info('private')
self.assertNotEqual(md5sum, '')
self.assertNotEqual(filepath, '')
self.assertNotEqual(timestamp, '')

md5sum, filepath, timestamp = get_release_info('public')
self.assertEqual(md5sum, '')
self.assertEqual(filepath, '')
self.assertEqual(timestamp, '')


if __name__ == '__main__':
main()
30 changes: 30 additions & 0 deletions qiita_core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from os.path import dirname
from git import Repo
from git.exc import InvalidGitRepositoryError
from moi import r_client

from qiita_core.qiita_settings import qiita_config
from qiita_pet import __version__ as qiita_pet_lib_version
Expand Down Expand Up @@ -141,3 +142,32 @@ def get_qiita_version():
sha = ''

return (qiita_pet_lib_version, sha)


def get_release_info(study_status='public'):
"""Returns the study status release MD5

Parameters
----------
study_status : str, optional
The study status to search for. Note that this should always be set
to 'public' but having this exposed helps with testing. The other
options are 'private' and 'sandbox'

Returns
------
str, str, str
The release MD5, filepath and timestamp
"""
portal = qiita_config.portal
md5sum = r_client.get('%s:release:%s:md5sum' % (portal, study_status))
filepath = r_client.get('%s:release:%s:filepath' % (portal, study_status))
timestamp = r_client.get('%s:release:%s:time' % (portal, study_status))
if md5sum is None:
md5sum = ''
if filepath is None:
filepath = ''
if timestamp is None:
timestamp = ''

return md5sum, filepath, timestamp
30 changes: 17 additions & 13 deletions qiita_db/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,11 @@ def create(cls, filepaths, artifact_type, name=None, prep_template=None,

Notes
-----
The visibility of the artifact is set by default to `sandbox`
The timestamp of the artifact is set by default to `datetime.now()`
The value of `submitted_to_vamps` is set by default to `False`
The visibility of the artifact is set by default to `sandbox` if
prep_template is passed but if parents is passed we will inherit the
most closed visibility.
The timestamp of the artifact is set by default to `datetime.now()`.
The value of `submitted_to_vamps` is set by default to `False`.
"""
# We need at least one file
if not filepaths:
Expand Down Expand Up @@ -689,19 +691,21 @@ def visibility(self, value):
only applies when the new visibility is more open than before.
"""
with qdb.sql_connection.TRN:
# In order to correctly propagate the visibility we need to find
# the root of this artifact and then propagate to all the artifacts
sql = "SELECT * FROM qiita.find_artifact_roots(%s)"
qdb.sql_connection.TRN.add(sql, [self.id])
root_id = qdb.sql_connection.TRN.execute_fetchlast()
root = qdb.artifact.Artifact(root_id)
# these are the ids of all the children from the root
ids = [a.id for a in root.descendants.nodes()]

sql = """UPDATE qiita.artifact
SET visibility_id = %s
WHERE artifact_id = %s"""
qdb.sql_connection.TRN.add(
sql, [qdb.util.convert_to_id(value, "visibility"), self.id])
WHERE artifact_id IN %s"""
vis_id = qdb.util.convert_to_id(value, "visibility")
qdb.sql_connection.TRN.add(sql, [vis_id, tuple(ids)])
qdb.sql_connection.TRN.execute()
# In order to correctly propagate the visibility upstream, we need
# to go one step at a time. By setting up the visibility of our
# parents first, we accomplish that, since they will propagate
# the changes to its parents
for p in self.parents:
visibilites = [[d.visibility] for d in p.descendants.nodes()]
p.visibility = qdb.util.infer_status(visibilites)

@property
def artifact_type(self):
Expand Down
126 changes: 117 additions & 9 deletions qiita_db/meta_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
from __future__ import division

from moi import r_client
from os import stat
from os import stat, makedirs, rename
from os.path import join, relpath, exists
from time import strftime, localtime
import matplotlib.pyplot as plt
import matplotlib as mpl
Expand All @@ -34,8 +35,11 @@
from StringIO import StringIO
from future.utils import viewitems
from datetime import datetime
from tarfile import open as topen, TarInfo
from hashlib import md5

from qiita_core.qiita_settings import qiita_config
from qiita_core.configuration_manager import ConfigurationManager
import qiita_db as qdb


Expand Down Expand Up @@ -126,14 +130,21 @@ def validate_filepath_access_by_user(user, filepath_id):
# the prep access is given by it's artifacts, if the user has
# access to any artifact, it should have access to the prep
# [0] cause we should only have 1
a = qdb.metadata_template.prep_template.PrepTemplate(
pid[0]).artifact
if (a.visibility == 'public' or a.study.has_access(user)):
return True
pt = qdb.metadata_template.prep_template.PrepTemplate(
pid[0])
a = pt.artifact
# however, the prep info file could not have any artifacts attached
# , in that case we will use the study access level
if a is None:
return qdb.study.Study(pt.study_id).has_access(user)
else:
for c in a.descendants.nodes():
if (c.visibility == 'public' or c.study.has_access(user)):
return True
if (a.visibility == 'public' or a.study.has_access(user)):
return True
else:
for c in a.descendants.nodes():
if ((c.visibility == 'public' or
c.study.has_access(user))):
return True
return False
# analyses
elif anid:
Expand Down Expand Up @@ -305,7 +316,8 @@ def get_lat_longs():
WHERE table_name SIMILAR TO 'sample_[0-9]+'
AND table_schema = 'qiita'
AND column_name IN ('latitude', 'longitude')
AND SPLIT_PART(table_name, '_', 2)::int IN %s;"""
AND SPLIT_PART(table_name, '_', 2)::int IN %s
GROUP BY table_name HAVING COUNT(column_name) = 2;"""
qdb.sql_connection.TRN.add(sql, [tuple(portal_table_ids)])

sql = [('SELECT CAST(latitude AS FLOAT), '
Expand All @@ -319,3 +331,99 @@ def get_lat_longs():
qdb.sql_connection.TRN.add(sql)

return qdb.sql_connection.TRN.execute_fetchindex()


def generate_biom_and_metadata_release(study_status='public'):
"""Generate a list of biom/meatadata filepaths and a tgz of those files

Parameters
----------
study_status : str, optional
The study status to search for. Note that this should always be set
to 'public' but having this exposed helps with testing. The other
options are 'private' and 'sandbox'
"""
studies = qdb.study.Study.get_by_status(study_status)
qiita_config = ConfigurationManager()
working_dir = qiita_config.working_dir
portal = qiita_config.portal
bdir = qdb.util.get_db_files_base_dir()
time = datetime.now().strftime('%m-%d-%y %H:%M:%S')

data = []
for s in studies:
# [0] latest is first, [1] only getting the filepath
sample_fp = relpath(s.sample_template.get_filepaths()[0][1], bdir)

for a in s.artifacts(artifact_type='BIOM'):
if a.processing_parameters is None:
continue

cmd_name = a.processing_parameters.command.name

# this loop is necessary as in theory an artifact can be
# generated from multiple prep info files
human_cmd = []
for p in a.parents:
pp = p.processing_parameters
pp_cmd_name = pp.command.name
if pp_cmd_name == 'Trimming':
human_cmd.append('%s @ %s' % (
cmd_name, str(pp.values['length'])))
else:
human_cmd.append('%s, %s' % (cmd_name, pp_cmd_name))
human_cmd = ', '.join(human_cmd)

for _, fp, fp_type in a.filepaths:
if fp_type != 'biom' or 'only-16s' in fp:
continue
fp = relpath(fp, bdir)
# format: (biom_fp, sample_fp, prep_fp, qiita_artifact_id,
# human readable name)
for pt in a.prep_templates:
for _, prep_fp in pt.get_filepaths():
if 'qiime' not in prep_fp:
break
prep_fp = relpath(prep_fp, bdir)
data.append((fp, sample_fp, prep_fp, a.id, human_cmd))

# writing text and tgz file
ts = datetime.now().strftime('%m%d%y-%H%M%S')
tgz_dir = join(working_dir, 'releases')
if not exists(tgz_dir):
makedirs(tgz_dir)
tgz_name = join(tgz_dir, '%s-%s-building.tgz' % (portal, study_status))
tgz_name_final = join(tgz_dir, '%s-%s.tgz' % (portal, study_status))
txt_hd = StringIO()
with topen(tgz_name, "w|gz") as tgz:
# writing header for txt
txt_hd.write(
"biom_fp\tsample_fp\tprep_fp\tqiita_artifact_id\tcommand\n")
for biom_fp, sample_fp, prep_fp, artifact_id, human_cmd in data:
txt_hd.write("%s\t%s\t%s\t%s\t%s\n" % (
biom_fp, sample_fp, prep_fp, artifact_id, human_cmd))
tgz.add(join(bdir, biom_fp), arcname=biom_fp, recursive=False)
tgz.add(join(bdir, sample_fp), arcname=sample_fp, recursive=False)
tgz.add(join(bdir, prep_fp), arcname=prep_fp, recursive=False)

txt_hd.seek(0)
info = TarInfo(name='%s-%s-%s.txt' % (portal, study_status, ts))
info.size = len(txt_hd.buf)
tgz.addfile(tarinfo=info, fileobj=txt_hd)

with open(tgz_name, "rb") as f:
md5sum = md5()
for c in iter(lambda: f.read(4096), b""):
md5sum.update(c)

rename(tgz_name, tgz_name_final)

vals = [
('filepath', tgz_name_final[len(working_dir):], r_client.set),
('md5sum', md5sum.hexdigest(), r_client.set),
('time', time, r_client.set)]
for k, v, f in vals:
redis_key = '%s:release:%s:%s' % (portal, study_status, k)
# important to "flush" variables to avoid errors
r_client.delete(redis_key)
f(redis_key, v)
Loading