Skip to content

Commit

Permalink
ex-289 (cgates): adjusted varscan validation to allow empty HC files.…
Browse files Browse the repository at this point in the history
… Some pep8 cleanup.
  • Loading branch information
cgates committed Sep 2, 2015
1 parent 27a3ab2 commit c0d6f2e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion jacquard/variant_caller_transforms/varscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,15 @@ def _get_hc_file_pattern(args):
def _validate_filter_file(file_reader):
column_header = 0
file_reader.open()
file_is_empty = True
for line in file_reader.read_lines():
file_is_empty = False
if line.startswith("chrom\tposition"):
column_header = line
break
file_reader.close()

if column_header:
if column_header or file_is_empty:
return file_reader

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions test/expand_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def test_validate_args_colSpecValid(self):
input_file = os.path.join(input_dir.path, "input.vcf")
input_dir.write("col_spec.txt", b"chrom\npos\ninfo")
col_spec_file = os.path.join(input_dir.path, "col_spec.txt")

args = Namespace(input=input_file,
output="expanded.txt",
selected_columns_file=col_spec_file)
Expand Down Expand Up @@ -286,7 +286,7 @@ def test_validate_args_colSpecIsEmpty(self):
"The selected_columns_file .* has no rows. Review inputs/usage and try again",
expand.validate_args,
args)

def test_validate_args_checkInputIfVCF(self):
with TempDirectory() as input_dir:
input_dir.write("input.vcf", b"123")
Expand Down
4 changes: 2 additions & 2 deletions test/merge_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ def test_init_includeAllFlag(self):
# "Unable to process command-line arguments. Neither --include_cells nor --include_rows can be specified if --include_all is specified.",
# merge._Filter,
# args)
#
#
# args = Namespace(include_all=True, include_cells=False, include_rows=True)
# self.assertRaisesRegexp(utils.UsageError,
# "Unable to process command-line arguments. Neither --include_cells nor --include_rows can be specified if --include_all is specified.",
# merge._Filter,
# args)
#
#
# args = Namespace(include_all=True, include_cells=True, include_rows=False)
# self.assertRaisesRegexp(utils.UsageError,
# "Unable to process command-line arguments. Neither --include_cells nor --include_rows can be specified if --include_all is specified.",
Expand Down
10 changes: 8 additions & 2 deletions test/variant_caller_transforms/varscan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ def test_validate_vcf_hc_pairs_raisesIfMissingHcFiles(self):
vcf_hc_pairs = [(MockFileReader("A.vcf"), MockFileReader("A.hc")),
(MockFileReader("B.vcf"), None)]
self.assertRaisesRegexp(utils.UsageError,
"The VarScan VCF file \[B.vcf\] has no matching high-confidence file.",
"The VarScan VCF file \[B.vcf\] has no matching high-confidence file.",
self.caller._validate_vcf_hc_pairs,
vcf_hc_pairs)

def test_validate_vcf_hc_pairs_raisesIfNoMissingVcfFiles(self):
vcf_hc_pairs = [(MockFileReader("A.vcf"), MockFileReader("A.hc")),
(None, MockFileReader("B.hc"))]
self.assertRaisesRegexp(utils.UsageError,
"The VarScan high-confidence file \[B.hc\] has no matching VCF file.",
"The VarScan high-confidence file \[B.hc\] has no matching VCF file.",
self.caller._validate_vcf_hc_pairs,
vcf_hc_pairs)

Expand All @@ -232,6 +232,12 @@ def test_get_hc_file_pattern_invalidRegex(self):
varscan.Varscan._get_hc_file_pattern,
args)

def test_validate_filter_file_emptyFile(self):
file_reader = MockFileReader("p1.hc.fpfilter.pass", [])
caller = varscan.Varscan()
valid_reader = caller._validate_filter_file(file_reader)
self.assertEquals("p1.hc.fpfilter.pass", valid_reader.file_name)

def test_validate_filter_file_validFile(self):
file_reader = MockFileReader("p1.hc.fpfilter.pass", ["chrom\tposition"])
caller = varscan.Varscan()
Expand Down

0 comments on commit c0d6f2e

Please sign in to comment.