Skip to content

Commit

Permalink
ex-183 (jebene) pushed column specification file validation upstream to
Browse files Browse the repository at this point in the history
validate_args
  • Loading branch information
jebene committed Mar 30, 2015
1 parent da03f67 commit ef43c7c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 44 deletions.
20 changes: 9 additions & 11 deletions jacquard/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,14 @@
"or this expression may be irrelevant.")

def _read_col_spec(col_spec):
if not os.path.isfile(col_spec):
raise utils.UsageError(("The column specification file [{}] could "
"not be read. "
"Review inputs/usage and try again."),
col_spec)

spec_file = open(col_spec, "r")
columns = []

for line in spec_file:
columns.append(line.rstrip())

spec_file.close()

return columns


##TODO: hook this idea up -- change method
def _disambiguate_column_names(column_header, info_header):
overlap = 0
Expand Down Expand Up @@ -128,8 +119,15 @@ def get_required_input_output_types():
return ("file", "file")

#TODO (cgates): Validate should actually validate
def validate_args(dummy):
pass
def validate_args(args):
if args.column_specification:
if not os.path.isfile(args.column_specification):
raise utils.UsageError(("The column specification file [{}] could "
"not be read. Review inputs/usage and "
"try again."),
args.column_specification)

_read_col_spec(args.column_specification)

def execute(args, dummy_execution_context):
#for the moment, there is no good place to put the execution context
Expand Down
55 changes: 22 additions & 33 deletions test/expand_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
#pylint: disable=global-statement, star-args, too-few-public-methods, invalid-name
#pylint: disable=too-many-public-methods
from __future__ import absolute_import

from argparse import Namespace
from test.vcf_test import MockVcfReader
import os

from testfixtures import TempDirectory

import jacquard.expand as expand
import jacquard.logger
import jacquard.utils as utils
import jacquard.vcf as vcf
import os
import test.mock_logger
import test.test_case as test_case
from test.vcf_test import MockVcfReader


class ExpandTestCase(test_case.JacquardBaseTestCase):
def setUp(self):
Expand Down Expand Up @@ -223,43 +227,28 @@ def test_predict_output(self):
self.assertEquals(expected_desired_output_files,
desired_output_files)


def test_execute_colSpecValid(self):
with TempDirectory() as input_dir,\
TempDirectory() as output_dir,\
TempDirectory() as col_spec_dir:
col_spec_dir.write("col_spec.txt", "foo\nbar")
def test_validate_args_colSpecValid(self):
with TempDirectory() as col_spec_dir:
col_spec_dir.write("col_spec.txt", "chrom\npos\ninfo")
col_spec_file = os.path.join(col_spec_dir.path, "col_spec.txt")
input_dir.write("summarized.vcf", "##source=strelka\n#foo")
input_file = os.path.join(input_dir.path, "summarized.vcf")
output_file = os.path.join(output_dir.path, "expanded.txt")
args = Namespace(input=input_file,
original_output=output_file,
output=output_file,
column_specification=col_spec_file)

expand.execute(args, ["extra_header1", "extra_header2"])
args = Namespace(input="input.txt",
output="expanded.txt",
column_specification=col_spec_file)
expand.validate_args(args)
self.ok()

def test_execute_colSpecInvalid(self):
with TempDirectory() as input_dir,\
TempDirectory() as output_dir,\
TempDirectory() as col_spec_dir:
col_spec_dir.write("col_spec.txt", "foo\nbar")
input_dir.write("summarized.vcf", "##source=strelka\n#foo")
input_file = os.path.join(input_dir.path, "summarized.vcf")
output_file = os.path.join(output_dir.path, "expanded.txt")
args = Namespace(input=input_file,
output=output_file,
column_specification=col_spec_dir.path)
def test_validate_args_colSpecInvalid(self):
with TempDirectory() as col_spec_dir:
col_spec_dir.write("col_spec.txt", "chrom\npos\ninfo")

args = Namespace(input="input.txt",
output="expanded.txt",
column_specification=col_spec_dir.path)
self.assertRaisesRegexp(utils.UsageError,
"The column specification file .* could "
"not be read. Review inputs/usage and "
"try again",
expand.execute,
args,
["extra_header1", "extra_header2"])
"The column specification file .* could not be read. Review inputs/usage and try again",
expand.validate_args,
args)

class ExpandFunctionalTestCase(test_case.JacquardBaseTestCase):
def test_expand(self):
Expand Down

0 comments on commit ef43c7c

Please sign in to comment.