Skip to content
Snippets Groups Projects
Commit 4acb6045 authored by aknecht2's avatar aknecht2
Browse files

Standardized and cleaned up test folder. All files no loaded from base...

Standardized and cleaned up test folder.  All files no loaded from base locations.  Each test class has a __name__ == __main__ to run just the individual test case.
parent 978dc45d
No related branches found
No related tags found
No related merge requests found
Showing
with 103 additions and 2237 deletions
......@@ -4,23 +4,24 @@ import yaml
import os
import sys
# auth.yaml
# ========
# host: database url
# username: database username
# password: database password
auth_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "auth.yaml")
if not os.path.isfile(auth_file):
print "Please create a file at [%s] containing host, username, and password." % (auth_file,)
sys.exit(1)
with open(auth_file, "r") as rh:
auth = yaml.load(rh)
class DatabaseTestCase(unittest.TestCase):
@classmethod
def setUpClass(self):
# auth.yaml
# ========
# host: database url
# username: database username
# password: database password
auth_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "auth.yaml")
if not os.path.isfile(auth_file):
print "Please create a file at [%s] containing host, username, and password." % (auth_file,)
sys.exit(1)
with open(auth_file, "r") as rh:
auth = yaml.load(rh)
print "Setting up database connection..."
self.mdb = chipathlon.db.MongoDB(auth["host"], auth["username"], auth["password"])
return
......
import unittest
from database_tests import DatabaseTestCase
# NOTE: These tests can be fragile! Everytime encode updates their
# database they often switch around accession numbers. If you perform
# a database update you may need to adjust the accession numbers in this
# file
class SampleExistanceTests(DatabaseTestCase):
def test_sample_exists(self):
print "Testing accession: ENCFF000RCB, file_type: fastq"
valid, msg, data = self.mdb.get_sample("ENCFF000RCB", "fastq")
self.assertTrue(valid)
print "Testing accession: ENCFF001HZS, file_type: fastq"
valid, msg, data = self.mdb.get_sample("ENCFF001HZS", "fastq")
self.assertTrue(valid, msg=msg)
def test_sample_without_file_type(self):
print "Testing accession: ENCFF000RCB, file_type: bam"
valid, msg, data = self.mdb.get_sample("ENCFF000RCB", "bam")
self.assertFalse(valid)
print "Testing accession: ENCFF001HZS, file_type: bam"
valid, msg, data = self.mdb.get_sample("ENCFF001HZS", "bam")
self.assertFalse(valid, msg=msg)
def test_sample_without_accession(self):
print "Testing accession: ASDF, file_type: fastq"
valid, msg, data = self.mdb.get_sample("ASDF", "fastq")
self.assertFalse(valid)
self.assertFalse(valid, msg=msg)
if __name__ == "__main__":
unittest.TextTestRunner(verbosity=2).run(
unittest.TestLoader().loadTestsFromTestCase(SampleExistanceTests)
)
import unittest
import os
from chipathlon.genome import Genome
class GenomeTests(unittest.TestCase):
def setUp(self):
self.base_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "genome")
return
def test_valid_bwa_genome(self):
genome = Genome("grch38p6", "bwa", "test/genome/grch38p6.fna", "test/genome/grch38p6.chrom.sizes")
genome = Genome(
"grch38p6",
"bwa",
os.path.join(self.base_path, "grch38p6.fna"),
os.path.join(self.base_path, "grch38p6.chrom.sizes")
)
self.assertTrue(genome.is_valid(), msg=genome.get_error_string())
def test_valid_bowtie2_genome(self):
genome = Genome("grch38p6", "bowtie2", "test/genome/grch38p6.fna", "test/genome/grch38p6.chrom.sizes")
genome = Genome(
"grch38p6",
"bowtie2",
os.path.join(self.base_path, "grch38p6.fna"),
os.path.join(self.base_path, "grch38p6.chrom.sizes")
)
self.assertTrue(genome.is_valid(), msg=genome.get_error_string())
def test_invalid_bwa_genome(self):
genome = Genome("mm9", "bwa", "test/genome/mm9.fna", "test/genome/mm9.chrom.sizes")
genome = Genome(
"mm9",
"bwa",
os.path.join(self.base_path, "mm9.fna"),
os.path.join(self.base_path, "mm9.chrom.sizes")
)
self.assertFalse(genome.is_valid(), msg=genome.get_error_string())
def test_invalid_bowtie2_genome(self):
genome = Genome("mm9", "bowtie2", "test/genome/mm9.fna", "test/genome/mm9.chrom.sizes")
genome = Genome(
"mm9",
"bowtie2",
os.path.join(self.base_path, "mm9.fna"),
os.path.join(self.base_path, "mm9.chrom.sizes")
)
self.assertFalse(genome.is_valid(), msg=genome.get_error_string())
def test_missing_chrom_sizes(self):
genome = Genome("mm9", "bowtie2", "test/genome/mm9.fna", "not/a/file")
genome = Genome(
"mm9",
"bowtie2",
os.path.join(self.base_path, "mm9.fna"),
"not/a/file"
)
self.assertFalse(genome.is_valid(), msg=genome.get_error_string())
def test_missing_base_file(self):
genome = Genome("mm9", "bwa", "not/a/file", "test/genome/mm9.chrom.sizes")
genome = Genome(
"mm9",
"bwa",
"not/a/file",
os.path.join(self.base_path, "mm9.chrom.sizes")
)
self.assertFalse(genome.is_valid(), msg=genome.get_error_string())
if __name__ == "__main__":
unittest.TextTestRunner(verbosity=2).run(
unittest.TestLoader().loadTestsFromTestCase(GenomeTests)
)
import unittest
from database_tests import DatabaseTestCase
class InsertResultsTests(DatabaseTestCase):
def setUp(self):
print "setting up insert..."
super(self.__class__, self).setUp()
self.result_id = ""
return
def tearDown(self):
print "tearing down insert..."
if self.result_id:
self.mdb.delete_result(self.result_id)
super(self.__class__, self).tearDown()
return
def test_insert_bed(self):
print "Inserting sample bed file..."
valid, msg, result_id = self.mdb.save_bed(
"test/insert_tests/sample.bed",
[],
["ENCFF000RCB"],
{"align_tool": "bowtie2", "read_end": "single"}
)
if valid:
self.result_id = result_id
print msg
self.assertTrue(valid)
return
def test_insert_peak(self):
print "Inserting sample peak file..."
valid, msg, result_id = self.mdb.save_peak(
"test/insert_tests/sample.narrowPeak",
["ENCFF000RCB"],
["ENCFF000RCB"],
{"align_tool": "bwa", "read_end": "single", "peak_tool": "macs2"}
)
if valid:
self.result_id = result_id
print msg
self.assertTrue(valid)
return
control_ids:
- !!python/unicode 'ENCSR000BKT'
experiment_ids: []
other:
- information
result_type: bed
This diff is collapsed.
This diff is collapsed.
notify:
pegasus_home: "/usr/share/pegasus/"
email: "avi@kurtknecht.com"
profile:
pegasus:
style: "glite"
condor:
grid_resource: "pbs"
universe: "vanilla"
env:
PATH: "/work/walia/common/pymodules/anaconda/bin"
PYTHONPATH: "/work/walia/common/pymodules/anaconda/lib/python2.7/site-packages/"
bwa_sai_to_sam:
arguments: null
walltime: 2000
memory: 2000
bwa_align_single:
arguments:
"-q": 5
"-l": 32
"-k": 2
"-t": 1
walltime: 2000
memory: 2000
bwa_align_paired:
arguments:
"-t": 1
walltime: 2000
memory: 2000
bowtie2_align_single:
arguments: null
walltime: 2000
memory: 2000
bowtie2_align_paired:
arguments: null
walltime: 2000
memory: 2000
samtools_sam_to_bam:
arguments: null
walltime: 2000
memory: 2000
bedtools_bam_to_bed:
arguments: null
walltime: 2000
memory: 2000
macs2_callpeak:
arguments: null
walltime: 2000
memory: 8000
picard_mark_duplicates:
arguments: null
walltime: 2000
memory: 2000
picard_sort_sam:
arguments: null
walltime: 2000
memory: 2000
r_spp_nodups:
arguments: null
walltime: 2000
memory: 2000
samtools_remove_duplicates:
arguments: null
walltime: 2000
memory: 2000
samtools_filter_bam:
arguments: null
walltime: 2000
memory: 2000
runs:
- experiment: "ENCSR922MYB"
align: bwa
peak: spp
- experiment: "ENCSR992MYB"
align: bowtie2
peak: spp
genomes:
bwa:
hg19: "/path/to/genome/base"
mm9: "/path/to/genome/base"
bowtie2:
hg19: "/path/to/genome/base"
mm9: "/path/to/genome/base"
import unittest
import os
from database_tests import DatabaseTestCase
from chipathlon.run_parser import RunParser
class RunParserTests(DatabaseTestCase):
def setUp(self):
self.base_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "run_parser")
return
def test_valid_parse(self):
parser = RunParser("test/run_parser/run_valid.yaml", self.mdb)
parser = RunParser(os.path.join(self.base_path, "run_valid.yaml"), self.mdb)
self.assertTrue(parser.is_valid(), parser.get_error_string())
def test_missing_keys(self):
parser = RunParser("test/run_parser/run_missing_keys.yaml", self.mdb)
parser = RunParser(os.path.join(self.base_path, "run_missing_keys.yaml"), self.mdb)
self.assertFalse(parser.is_valid(), msg=parser.get_error_string())
def test_no_genome(self):
parser = RunParser("test/run_parser/run_no_genome.yaml", self.mdb)
parser = RunParser(os.path.join(self.base_path, "run_no_genome.yaml"), self.mdb)
self.assertFalse(parser.is_valid(), msg=parser.get_error_string())
def test_idr_invalid_signal(self):
parser = RunParser("test/run_parser/run_idr_invalid_signal.yaml", self.mdb)
parser = RunParser(os.path.join(self.base_path, "run_idr_invalid_signal.yaml"), self.mdb)
self.assertFalse(parser.is_valid(), msg=parser.get_error_string())
def test_idr_not_enough_signals(self):
parser = RunParser("test/run_parser/run_idr_not_enough_signals.yaml", self.mdb)
parser = RunParser(os.path.join(self.base_path, "run_idr_not_enough_signals.yaml"), self.mdb)
self.assertFalse(parser.is_valid(), msg=parser.get_error_string())
def test_peak_type_invalid(self):
parser = RunParser("test/run_parser/run_peak_type_invalid.yaml", self.mdb)
parser = RunParser(os.path.join(self.base_path, "run_peak_type_invalid.yaml"), self.mdb)
self.assertFalse(parser.is_valid(), msg=parser.get_error_string())
if __name__ == "__main__":
unittest.TextTestRunner(verbosity=2).run(
unittest.TestLoader().loadTestsFromTestCase(RunParserTests)
)
......@@ -3,15 +3,16 @@ from chipathlon.workflow_job import WorkflowJob
import yaml
import os
class WorkflowJobTests(unittest.TestCase):
def setUp(self):
self.base_path = os.path.dirname(os.path.abspath(__file__))
self.base_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "workflow_job")
return
def test_invalid_base(self):
job = WorkflowJob(
"%s/workflow_job/invalid_base.yaml" % (self.base_path,),
os.path.join(self.base_path, "invalid_base.yaml"),
{},
debug=True
)
......@@ -20,7 +21,7 @@ class WorkflowJobTests(unittest.TestCase):
def test_no_file_type(self):
job = WorkflowJob(
"%s/workflow_job/no_file_type.yaml" % (self.base_path,),
os.path.join(self.base_path, "no_file_type.yaml"),
{},
debug=True
)
......@@ -29,7 +30,7 @@ class WorkflowJobTests(unittest.TestCase):
def test_missing_resources(self):
job = WorkflowJob(
"%s/workflow_job/missing_resources.yaml" % (self.base_path,),
os.path.join(self.base_path, "missing_resources.yaml"),
{},
debug=True
)
......@@ -38,7 +39,7 @@ class WorkflowJobTests(unittest.TestCase):
def test_bad_resources(self):
job = WorkflowJob(
"%s/workflow_job/bad_resources.yaml" % (self.base_path,),
os.path.join(self.base_path, "bad_resources.yaml"),
{},
debug=True
)
......@@ -47,7 +48,7 @@ class WorkflowJobTests(unittest.TestCase):
def test_bad_arguments(self):
job = WorkflowJob(
"%s/workflow_job/bad_arguments.yaml" % (self.base_path,),
os.path.join(self.base_path, "bad_arguments.yaml"),
{},
debug=True
)
......@@ -56,7 +57,7 @@ class WorkflowJobTests(unittest.TestCase):
def test_bad_references(self):
job = WorkflowJob(
"%s/workflow_job/bad_references.yaml" % (self.base_path,),
os.path.join(self.base_path, "bad_references.yaml"),
{},
debug=True
)
......@@ -65,7 +66,7 @@ class WorkflowJobTests(unittest.TestCase):
def test_valid_job(self):
job = WorkflowJob(
"%s/workflow_job/download_from_encode.yaml" % (self.base_path,),
os.path.join(self.base_path, "download_from_encode.yaml"),
{},
debug=True
)
......
bwa_sai_to_sam:
arguments: None
walltime: 2000
memory: 2000
bwa_align_single:
arguments:
"-q": 5
"-l": 32
"-k": 2
"-t": 1
walltime: 2000
memory: 2000
bwa_align_paired:
arguments:
"-t": 1
walltime: 2000
memory: 2000
samtools_sam_to_bam:
arguments: None
walltime: 2000
memory: 2000
bwa_sai_to_sam:
arguments: None
walltime: 2000
memory: 2000
bwa_align_single:
arguments:
"-q": 5
"-l": 32
"-k": 2
"-t": 1
walltime: 2000
memory: 2000
bwa_align_paired:
arguments:
"-M": ""
walltime: 2000
memory: 2000
samtools_sam_to_bam:
arguments: None
walltime: 2000
memory: 2000
INVALID YAML FILE
bwa_sai_to_sam:
arguments: None
walltime: 2000
memory: 2000
bwa_align_single:
arguments:
"-q": 5
"-l": 32
"-k": 2
"-t": 1
walltime: 2000
memory: 2000
bwa_align_paired:
arguments: None
walltime: 2000
memory: 2000
batman: nana
samtools_sam_to_bam:
arguments: None
walltime: 2000
memory: 2000
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment