Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Fixing software
  • Loading branch information
josenavas committed Nov 12, 2015
commit bdad3e0dee146efb7a3e7a5617294c0e000cd7ac
7 changes: 4 additions & 3 deletions qiita_db/software.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,16 @@ def commands(self):

Returns
-------
list of int
The command identifiers
list of qiita_db.software.Command
The commands attached to this software package
"""
with qdb.sql_connection.TRN:
sql = """SELECT command_id
FROM qiita.software_command
WHERE software_id = %s"""
qdb.sql_connection.TRN.add(sql, [self.id])
return qdb.sql_connection.TRN.execute_fetchflatten()
return [Command(cid)
for cid in qdb.sql_connection.TRN.execute_fetchflatten()]

@property
def publications(self):
Expand Down
93 changes: 52 additions & 41 deletions qiita_db/test/test_software.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@
from unittest import TestCase, main

from qiita_core.util import qiita_test_checker
from qiita_db.software import Command, Software, Parameters
from qiita_db.exceptions import QiitaDBDuplicateError
import qiita_db as qdb


@qiita_test_checker()
class CommandTests(TestCase):
def setUp(self):
self.software = Software(1)
self.software = qdb.software.Software(1)

def test_exists(self):
self.assertFalse(Command.exists(self.software, "donotexists"))
self.assertTrue(Command.exists(self.software, "split_libraries.py"))
self.assertFalse(qdb.software.Command.exists(
self.software, "donotexists"))
self.assertTrue(qdb.software.Command.exists(
self.software, "split_libraries.py"))

def test_create_error_duplicate(self):
with self.assertRaises(QiitaDBDuplicateError):
Command.create(
with self.assertRaises(qdb.exceptions.QiitaDBDuplicateError):
qdb.software.Command.create(
self.software, "Test Command", "This is a command for testing",
"split_libraries.py", "preprocessed_spectra_params")

def test_create(self):
obs = Command.create(
obs = qdb.software.Command.create(
self.software, "Test Command", "This is a command for testing",
"test_command.py", "preprocessed_spectra_params")
self.assertEqual(obs.name, "Test Command")
Expand All @@ -38,33 +39,35 @@ def test_create(self):
self.assertEqual(obs.parameters_table, "preprocessed_spectra_params")

def test_name(self):
self.assertEqual(Command(1).name, "Split libraries FASTQ")
self.assertEqual(Command(2).name, "Split libraries")
self.assertEqual(qdb.software.Command(1).name, "Split libraries FASTQ")
self.assertEqual(qdb.software.Command(2).name, "Split libraries")

def test_description(self):
self.assertEqual(
Command(1).description,
qdb.software.Command(1).description,
"Demultiplexes and applies quality control to FASTQ data")
self.assertEqual(
Command(2).description,
qdb.software.Command(2).description,
"Demultiplexes and applies quality control to FASTA data")

def test_cli(self):
self.assertEqual(Command(1).cli, "split_libraries_fastq.py")
self.assertEqual(Command(2).cli, "split_libraries.py")
self.assertEqual(qdb.software.Command(1).cli,
"split_libraries_fastq.py")
self.assertEqual(qdb.software.Command(2).cli, "split_libraries.py")

def test_parameters_table(self):
self.assertEqual(Command(1).parameters_table,
self.assertEqual(qdb.software.Command(1).parameters_table,
"preprocessed_sequence_illumina_params")
self.assertEqual(Command(2).parameters_table,
self.assertEqual(qdb.software.Command(2).parameters_table,
"preprocessed_sequence_454_params")


@qiita_test_checker()
class SoftwareTests(TestCase):
def test_create(self):
obs = Software.create("New Software", "0.1.0",
"This is adding a new software for testing")
obs = qdb.software.Software.create(
"New Software", "0.1.0",
"This is adding a new software for testing")
self.assertEqual(obs.name, "New Software")
self.assertEqual(obs.version, "0.1.0")
self.assertEqual(obs.description,
Expand All @@ -74,36 +77,38 @@ def test_create(self):

def test_create_with_publications(self):
exp_publications = [['10.1000/nmeth.f.101', '12345678']]
obs = Software.create("Published Software", "1.0.0",
"Another testing software",
publications=exp_publications)
obs = qdb.software.Software.create(
"Published Software", "1.0.0", "Another testing software",
publications=exp_publications)
self.assertEqual(obs.name, "Published Software")
self.assertEqual(obs.version, "1.0.0")
self.assertEqual(obs.description, "Another testing software")
self.assertEqual(obs.commands, [])
self.assertEqual(obs.publications, exp_publications)

def test_name(self):
self.assertEqual(Software(1).name, "QIIME")
self.assertEqual(qdb.software.Software(1).name, "QIIME")

def test_version(self):
self.assertEqual(Software(1).version, "1.9.1")
self.assertEqual(qdb.software.Software(1).version, "1.9.1")

def test_description(self):
exp = ("Quantitative Insights Into Microbial Ecology (QIIME) is an "
"open-source bioinformatics pipeline for performing microbiome "
"analysis from raw DNA sequencing data")
self.assertEqual(Software(1).description, exp)
self.assertEqual(qdb.software.Software(1).description, exp)

def test_commands(self):
self.assertEqual(Software(1).commands, [1, 2, 3])
exp = [qdb.software.Command(1), qdb.software.Command(2),
qdb.software.Command(3)]
self.assertEqual(qdb.software.Software(1).commands, exp)

def test_publications(self):
self.assertEqual(Software(1).publications,
self.assertEqual(qdb.software.Software(1).publications,
[['10.1038/nmeth.f.303', '20383131']])

def test_add_publications(self):
tester = Software(1)
tester = qdb.software.Software(1)
self.assertEqual(tester.publications,
[['10.1038/nmeth.f.303', '20383131']])
tester.add_publications([['10.1000/nmeth.f.101', '12345678']])
Expand All @@ -115,22 +120,22 @@ def test_add_publications(self):
@qiita_test_checker()
class ParametersTests(TestCase):
def test_init(self):
obs = Parameters(1, Command(1))
obs = qdb.software.Parameters(1, qdb.software.Command(1))
self.assertEqual(obs.id, 1)
self.assertEqual(obs._table, "preprocessed_sequence_illumina_params")
self.assertEqual(obs.command, Command(1))
self.assertEqual(obs.command, qdb.software.Command(1))

def test_exists(self):
cmd = Command(1)
obs = Parameters.exists(
cmd = qdb.software.Command(1)
obs = qdb.software.Parameters.exists(
cmd, max_bad_run_length=3, min_per_read_length_fraction=0.75,
sequence_max_n=0, rev_comp_barcode=False,
rev_comp_mapping_barcodes=False, rev_comp=False,
phred_quality_threshold=3, barcode_type="golay_12",
max_barcode_errors=1.5)
self.assertTrue(obs)

obs = Parameters.exists(
obs = qdb.software.Parameters.exists(
cmd, max_bad_run_length=3, min_per_read_length_fraction=0.75,
sequence_max_n=0, rev_comp_barcode=False,
rev_comp_mapping_barcodes=False, rev_comp=False,
Expand All @@ -139,8 +144,8 @@ def test_exists(self):
self.assertFalse(obs)

def test_create(self):
cmd = Command(1)
obs = Parameters.create(
cmd = qdb.software.Command(1)
obs = qdb.software.Parameters.create(
"test_create", cmd, max_bad_run_length=3,
min_per_read_length_fraction=0.75, sequence_max_n=0,
rev_comp_barcode=False, rev_comp_mapping_barcodes=False,
Expand All @@ -158,31 +163,37 @@ def test_create(self):
self.assertEqual(obs.command, cmd)

def test_iter(self):
cmd = Command(1)
obs = list(Parameters.iter(cmd))
exp = [Parameters(i, cmd) for i in range(1, 8)]
cmd = qdb.software.Command(1)
obs = list(qdb.software.Parameters.iter(cmd))
exp = [qdb.software.Parameters(i, cmd) for i in range(1, 8)]
self.assertEqual(obs, exp)

def test_name(self):
self.assertEqual(Parameters(1, Command(1)).name, "Defaults")
self.assertEqual(
qdb.software.Parameters(1, qdb.software.Command(1)).name,
"Defaults")

def test_values(self):
exp = {'min_per_read_length_fraction': 0.75,
'max_barcode_errors': 1.5, 'max_bad_run_length': 3,
'rev_comp': False, 'phred_quality_threshold': 3,
'rev_comp_barcode': False, 'sequence_max_n': 0,
'barcode_type': 'golay_12', 'rev_comp_mapping_barcodes': False}
self.assertEqual(Parameters(1, Command(1)).values, exp)
self.assertEqual(
qdb.software.Parameters(1, qdb.software.Command(1)).values, exp)

def test_to_str(self):
exp = ("--barcode_type 'golay_12' --max_bad_run_length '3' "
"--max_barcode_errors '1.5' "
"--min_per_read_length_fraction '0.75' "
"--phred_quality_threshold '3' --sequence_max_n '0'")
self.assertEqual(Parameters(1, Command(1)).to_str(), exp)
self.assertEqual(
qdb.software.Parameters(1, qdb.software.Command(1)).to_str(), exp)

def test_command(self):
self.assertEqual(Parameters(1, Command(1)).command, Command(1))
self.assertEqual(
qdb.software.Parameters(1, qdb.software.Command(1)).command,
qdb.software.Command(1))

if __name__ == '__main__':
main()