Skip to content

Commit 0364a0b

Browse files
committed
merge upstream/master
2 parents 688b549 + ea2c573 commit 0364a0b

File tree

10 files changed

+309
-129
lines changed

10 files changed

+309
-129
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ install:
1616
- pip install coveralls
1717
- pip install .
1818
script:
19-
- qiita_db make_test_env
19+
- qiita_env make_test_env
2020
- nosetests --with-doctest
2121
- pep8 qiita_db qiita_core qiita_pet setup.py
2222
# we need to run the test suite from setup.py for coveralls to grab the info

INSTALL.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Qiita is a python package, with support for python 2.7 and 3.2, that depends on
1515
* [NumPy](https://github.com/numpy/numpy)
1616
* [Pandas](http://pandas.pydata.org/)
1717
* [QIIME development version](https://github.com/biocore/qiime)
18+
* [future](http://python-future.org/)
19+
* [bcrypt](https://github.com/pyca/bcrypt/)
20+
* [redis](https://github.com/andymccurdy/redis-py)
1821

1922
And on the following packages:
2023

@@ -35,7 +38,7 @@ Once you have [PostgresSQL](http://www.postgresql.org/download/) and [redis](htt
3538
echo "export QIITA_CONFIG_FP=$QIITA_DIR/qiita_core/support_files/config_demo.txt" >> ~/.bashrc
3639
source ~/.bashrc
3740
pip install https://github.com/biocore/qiita/archive/master.zip
38-
qiita_db make_demo_env
41+
qiita_env make_demo_env
3942
```
4043
## If using other operating systems that are not Ubuntu
4144

@@ -48,4 +51,4 @@ createuser -s postgres -d
4851
If you receive the following error, you can ignore this step and continue with the qiita installation:
4952
```bash
5053
createuser: creation of new role failed: ERROR: role "postgres" already exists
51-
```
54+
```

qiita_db/commands.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from functools import partial
2+
try:
3+
# Python 2
4+
from ConfigParser import ConfigParser
5+
except ImportError:
6+
# Python 3
7+
from configparser import ConfigParser
8+
9+
from qiita_db.study import Study, StudyPerson
10+
from qiita_db.user import User
11+
12+
13+
def make_study_from_cmd(owner, title, info):
14+
15+
# Parse the configuration file
16+
config = ConfigParser()
17+
config.readfp(info)
18+
19+
optional = dict(config.items('optional'))
20+
get_optional = lambda name: optional.get(name, None)
21+
get_required = partial(config.get, 'required')
22+
required_fields = ['timeseries_type_id', 'mixs_compliant',
23+
'number_samples_collected', 'number_samples_promised',
24+
'portal_type_id', 'reprocess', 'study_alias',
25+
'study_description', 'study_abstract',
26+
'metadata_complete']
27+
optional_fields = ['funding', 'most_recent_contact', 'spatial_series',
28+
'vamps_id']
29+
infodict = {}
30+
for value in required_fields:
31+
infodict[value] = get_required(value)
32+
33+
for value in optional_fields:
34+
optvalue = get_optional(value)
35+
if optvalue is not None:
36+
infodict[value] = optvalue
37+
38+
emp_person_name_email = get_optional('emp_person_name')
39+
if emp_person_name_email is not None:
40+
emp_name, emp_email = emp_person_name_email.split(',')
41+
infodict['emp_person_id'] = StudyPerson.create(emp_name.strip(),
42+
emp_email.strip())
43+
lab_name_email = get_optional('lab_person')
44+
if lab_name_email is not None:
45+
lab_name, lab_email = lab_name_email.split(',')
46+
infodict['lab_person_id'] = StudyPerson.create(lab_name.strip(),
47+
lab_email.strip())
48+
pi_name_email = get_required('principal_investigator')
49+
pi_name, pi_email = pi_name_email.split(',')
50+
infodict['principal_investigator_id'] = StudyPerson.create(
51+
pi_name.strip(), pi_email.strip())
52+
# this will eventually change to using the Experimental Factory Ontolgoy
53+
# names
54+
efo_ids = get_required('efo_ids')
55+
efo_ids = [x.strip() for x in efo_ids.split(',')]
56+
57+
Study.create(User(owner), title, efo_ids, infodict)

qiita_db/job.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ def create(cls, datatype, command, options, analysis):
9797
Job object
9898
The newly created job
9999
"""
100-
if cls.exists(datatype, command, options):
101-
raise QiitaDBDuplicateError(
102-
"Job", "datatype: %s, command: %s, options: %s"
103-
% (datatype, command, options))
100+
# IGNORING EXISTS FOR DEMO
101+
# if cls.exists(datatype, command, options):
102+
# raise QiitaDBDuplicateError(
103+
# "Job", "datatype: %s, command: %s, options: %s"
104+
# % (datatype, command, options))
104105

105106
# Get the datatype and command ids from the strings
106107
conn_handler = SQLConnectionHandler()
@@ -114,8 +115,8 @@ def create(cls, datatype, command, options, analysis):
114115
sql = ("INSERT INTO qiita.{0} (data_type_id, job_status_id, "
115116
"command_id, options) VALUES "
116117
"(%s, %s, %s, %s) RETURNING job_id").format(cls._table)
117-
job_id = conn_handler.execute_fetchone(sql, (datatype_id, command_id,
118-
1, opts_json))[0]
118+
job_id = conn_handler.execute_fetchone(sql, (datatype_id, 1,
119+
command_id, opts_json))[0]
119120

120121
# add job to analysis
121122
sql = ("INSERT INTO qiita.analysis_job (analysis_id, job_id) VALUES "

qiita_db/study.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -551,22 +551,21 @@ def create(cls, name, email, address=None, phone=None):
551551
-------
552552
New StudyPerson object
553553
554-
Raises
555-
------
556-
QiitaDBDuplicateError
557-
Person already exists
558554
"""
559555
if cls.exists(name, email):
560-
raise QiitaDBDuplicateError(
561-
"StudyPerson", "name: %s, email: %s" % (name, email))
556+
sql = ("SELECT study_person_id from qiita.{0} WHERE name = %s and"
557+
" email = %s".format(cls._table))
558+
conn_handler = SQLConnectionHandler()
559+
spid = conn_handler.execute_fetchone(sql, (name, email))
562560

563561
# Doesn't exist so insert new person
564-
sql = ("INSERT INTO qiita.{0} (name, email, address, phone) VALUES"
565-
" (%s, %s, %s, %s) RETURNING "
566-
"study_person_id".format(cls._table))
567-
conn_handler = SQLConnectionHandler()
568-
spid = conn_handler.execute_fetchone(sql, (name, email, address,
569-
phone))
562+
else:
563+
sql = ("INSERT INTO qiita.{0} (name, email, address, phone) VALUES"
564+
" (%s, %s, %s, %s) RETURNING "
565+
"study_person_id".format(cls._table))
566+
conn_handler = SQLConnectionHandler()
567+
spid = conn_handler.execute_fetchone(sql, (name, email, address,
568+
phone))
570569
return cls(spid[0])
571570

572571
# Properties

qiita_db/test/test_commands.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from unittest import TestCase, main
2+
from future.utils.six import StringIO
3+
try:
4+
# Python 2
5+
from ConfigParser import NoOptionError
6+
except ImportError:
7+
# Python 3
8+
from configparser import NoOptionError
9+
10+
from qiita_db.commands import make_study_from_cmd
11+
from qiita_db.study import StudyPerson
12+
from qiita_db.user import User
13+
from qiita_core.util import qiita_test_checker
14+
15+
16+
@qiita_test_checker()
17+
class TestMakeStudyFromCmd(TestCase):
18+
def setUp(self):
19+
StudyPerson.create('SomeDude', 'somedude@foo.bar',
20+
'111 fake street', '111-121-1313')
21+
User.create('test@test.com', 'password')
22+
self.config1 = CONFIG_1
23+
self.config2 = CONFIG_2
24+
25+
def test_make_study_from_cmd(self):
26+
fh = StringIO(self.config1)
27+
make_study_from_cmd('test@test.com', 'newstudy', fh)
28+
sql = ("select study_id from qiita.study where email = %s and "
29+
"study_title = %s")
30+
study_id = self.conn_handler.execute_fetchone(sql, ('test@test.com',
31+
'newstudy'))
32+
self.assertTrue(study_id is not None)
33+
34+
fh2 = StringIO(self.config2)
35+
with self.assertRaises(NoOptionError):
36+
make_study_from_cmd('test@test.com', 'newstudy2', fh2)
37+
38+
CONFIG_1 = """[required]
39+
timeseries_type_id = 1
40+
metadata_complete = True
41+
mixs_compliant = True
42+
number_samples_collected = 50
43+
number_samples_promised = 25
44+
portal_type_id = 3
45+
principal_investigator = SomeDude, somedude@foo.bar
46+
reprocess = False
47+
study_alias = 'test study'
48+
study_description = 'test study description'
49+
study_abstract = 'study abstract'
50+
efo_ids = 1,2,3,4
51+
[optional]
52+
lab_person = SomeDude, somedude@foo.bar
53+
funding = 'funding source'
54+
vamps_id = vamps_id
55+
"""
56+
57+
CONFIG_2 = """[required]
58+
timeseries_type_id = 1
59+
metadata_complete = True
60+
number_samples_collected = 50
61+
number_samples_promised = 25
62+
portal_type_id = 3
63+
principal_investigator = SomeDude, somedude@foo.bar
64+
reprocess = False
65+
study_alias = 'test study'
66+
study_description = 'test study description'
67+
study_abstract = 'study abstract'
68+
efo_ids = 1,2,3,4
69+
[optional]
70+
lab_person = SomeDude, somedude@foo.bar
71+
funding = 'funding source'
72+
vamps_id = vamps_id
73+
"""
74+
75+
if __name__ == "__main__":
76+
main()

qiita_db/test/test_job.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ def test_exists_not_there(self):
5252

5353
def test_create(self):
5454
"""Makes sure creation works as expected"""
55-
new = Job.create("18S", "Beta Diversity",
55+
# make first job
56+
new = Job.create("18S", "Alpha Diversity",
5657
self.options, Analysis(1))
5758
self.assertEqual(new.id, 4)
5859
# make sure job inserted correctly
5960
obs = self.conn_handler.execute_fetchall("SELECT * FROM qiita.job "
6061
"WHERE job_id = 4")
61-
exp = [[4, 2, 2, 1, '{"option1":false,"option2":25,"option3":"NEW"}',
62+
exp = [[4, 2, 1, 3, '{"option1":false,"option2":25,"option3":"NEW"}',
6263
None]]
6364
self.assertEqual(obs, exp)
6465
# make sure job added to analysis correctly
@@ -68,12 +69,29 @@ def test_create(self):
6869
exp = [[1, 4]]
6970
self.assertEqual(obs, exp)
7071

71-
def test_create_exists(self):
72-
"""Makes sure creation doesn't duplicate a job"""
73-
with self.assertRaises(QiitaDBDuplicateError):
74-
Job.create("16S", "Summarize Taxa",
75-
{'option1': True, 'option2': 12, 'option3': 'FCM'},
76-
Analysis(1))
72+
# make second job with diff datatype and command to test column insert
73+
new = Job.create("16S", "Beta Diversity",
74+
self.options, Analysis(1))
75+
self.assertEqual(new.id, 5)
76+
# make sure job inserted correctly
77+
obs = self.conn_handler.execute_fetchall("SELECT * FROM qiita.job "
78+
"WHERE job_id = 5")
79+
exp = [[5, 1, 1, 2, '{"option1":false,"option2":25,"option3":"NEW"}',
80+
None]]
81+
self.assertEqual(obs, exp)
82+
# make sure job added to analysis correctly
83+
obs = self.conn_handler.execute_fetchall("SELECT * FROM "
84+
"qiita.analysis_job WHERE "
85+
"job_id = 5")
86+
exp = [[1, 5]]
87+
self.assertEqual(obs, exp)
88+
89+
# def test_create_exists(self):
90+
# """Makes sure creation doesn't duplicate a job"""
91+
# with self.assertRaises(QiitaDBDuplicateError):
92+
# Job.create("16S", "Summarize Taxa",
93+
# {'option1': True, 'option2': 12, 'option3': 'FCM'},
94+
# Analysis(1))
7795

7896
def test_retrieve_datatype(self):
7997
"""Makes sure datatype retriveal is correct"""

qiita_db/test/test_study.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
from qiita_db.study import Study, StudyPerson
1010
from qiita_db.investigation import Investigation
1111
from qiita_db.user import User
12-
from qiita_db.exceptions import (QiitaDBDuplicateError, QiitaDBColumnError,
13-
QiitaDBStatusError)
12+
from qiita_db.exceptions import QiitaDBColumnError, QiitaDBStatusError
1413

1514
# -----------------------------------------------------------------------------
1615
# Copyright (c) 2014--, The Qiita Development Team.
@@ -36,8 +35,9 @@ def test_create_studyperson(self):
3635
'111 fake street', '111-121-1313']])
3736

3837
def test_create_studyperson_already_exists(self):
39-
with self.assertRaises(QiitaDBDuplicateError):
40-
StudyPerson.create('LabDude', 'lab_dude@foo.bar')
38+
obs = StudyPerson.create('LabDude', 'lab_dude@foo.bar')
39+
self.assertEqual(obs.name, 'LabDude')
40+
self.assertEqual(obs.email, 'lab_dude@foo.bar')
4141

4242
def test_retrieve_name(self):
4343
self.assertEqual(self.studyperson.name, 'LabDude')

0 commit comments

Comments
 (0)