-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
159 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from functools import partial | ||
try: | ||
# Python 2 | ||
from ConfigParser import ConfigParser | ||
except ImportError: | ||
# Python 3 | ||
from configparser import ConfigParser | ||
|
||
from qiita_db.study import Study, StudyPerson | ||
from qiita_db.user import User | ||
|
||
|
||
def make_study_from_cmd(owner, title, info): | ||
|
||
# Parse the configuration file | ||
config = ConfigParser() | ||
config.readfp(info) | ||
|
||
optional = dict(config.items('optional')) | ||
get_optional = lambda name: optional.get(name, None) | ||
get_required = partial(config.get, 'required') | ||
infodict = {} | ||
infodict['funding'] = get_optional('funding') | ||
infodict['timeseries_type_id'] = get_required('timeseries_type_id') | ||
infodict['metadata_complete'] = get_required('metadata_complete') | ||
infodict['mixs_compliant'] = get_required('mixs_compliant') | ||
infodict['most_recent_contact'] = get_optional('most_recent_contact') | ||
infodict['number_samples_collected'] = get_required( | ||
'number_samples_collected') | ||
infodict['number_samples_promised'] = get_required( | ||
'number_samples_promised') | ||
infodict['portal_type_id'] = get_required('portal_type_id') | ||
infodict['reprocess'] = get_required('reprocess') | ||
infodict['spatial_series'] = get_optional('spatial_series') | ||
infodict['study_alias'] = get_required('study_alias') | ||
infodict['study_description'] = get_required('study_description') | ||
infodict['study_abstract'] = get_required('study_abstract') | ||
infodict['vamps_id'] = get_optional('vamps_id') | ||
emp_person_name_email = get_optional('emp_person_name') | ||
if emp_person_name_email is not None: | ||
emp_name, emp_email = emp_person_name_email.split(',') | ||
infodict['emp_person_id'] = StudyPerson.create(emp_name.strip(), | ||
emp_email.strip()) | ||
lab_name_email = get_optional('lab_person') | ||
if lab_name_email is not None: | ||
lab_name, lab_email = lab_name_email.split(',') | ||
infodict['lab_person_id'] = StudyPerson.create(lab_name.strip(), | ||
lab_email.strip()) | ||
pi_name_email = get_required('principal_investigator') | ||
pi_name, pi_email = pi_name_email.split(',') | ||
infodict['principal_investigator_id'] = StudyPerson.create( | ||
pi_name.strip(), pi_email.strip()) | ||
# this will eventually change to using the Experimental Factory Ontolgoy | ||
# names | ||
efo_ids = get_required('efo_ids') | ||
efo_ids = [x.strip() for x in efo_ids.split(',')] | ||
|
||
Study.create(User(owner), title, efo_ids, infodict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from unittest import TestCase, main | ||
from StringIO import StringIO | ||
try: | ||
# Python 2 | ||
from ConfigParser import NoOptionError | ||
except ImportError: | ||
# Python 3 | ||
from configparser import NoOptionError | ||
|
||
from qiita_db.commands import make_study_from_cmd | ||
from qiita_db.study import StudyPerson | ||
from qiita_db.user import User | ||
from qiita_core.util import qiita_test_checker | ||
|
||
|
||
@qiita_test_checker() | ||
class TestMakeStudyFromCmd(TestCase): | ||
def setUp(self): | ||
StudyPerson.create('SomeDude', 'somedude@foo.bar', | ||
'111 fake street', '111-121-1313') | ||
User.create('test@test.com', 'password') | ||
self.config1 = """ | ||
[required] | ||
timeseries_type_id = 1 | ||
metadata_complete = True | ||
mixs_compliant = True | ||
number_samples_collected = 50 | ||
number_samples_promised = 25 | ||
portal_type_id = 3 | ||
principal_investigator = SomeDude, somedude@foo.bar | ||
reprocess = False | ||
study_alias = 'test study' | ||
study_description = 'test study description' | ||
study_abstract = 'study abstract' | ||
efo_ids = 1,2,3,4 | ||
[optional] | ||
lab_person = SomeDude, somedude@foo.bar | ||
funding = 'funding source' | ||
vamps_id = vamps_id | ||
""" | ||
self.config2 = """ | ||
[required] | ||
timeseries_type_id = 1 | ||
metadata_complete = True | ||
number_samples_collected = 50 | ||
number_samples_promised = 25 | ||
portal_type_id = 3 | ||
principal_investigator = SomeDude, somedude@foo.bar | ||
reprocess = False | ||
study_alias = 'test study' | ||
study_description = 'test study description' | ||
study_abstract = 'study abstract' | ||
efo_ids = 1,2,3,4 | ||
[optional] | ||
lab_person = SomeDude, somedude@foo.bar | ||
funding = 'funding source' | ||
vamps_id = vamps_id | ||
""" | ||
|
||
def test_make_study_from_cmd(self): | ||
fh = StringIO(self.config1) | ||
make_study_from_cmd('test@test.com', 'newstudy', fh) | ||
sql = ("select study_id from qiita.study where email = %s and " | ||
"study_title = %s") | ||
study_id = self.conn_handler.execute_fetchone(sql, ('test@test.com', | ||
'newstudy')) | ||
self.assertTrue(study_id is not None) | ||
|
||
fh2 = StringIO(self.config2) | ||
with self.assertRaises(NoOptionError): | ||
make_study_from_cmd('test@test.com', 'newstudy2', fh2) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters