Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering :: Bio-Informatics',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2.7',
],

keywords='genomics structural variants sv bioinformatics',

packages=find_packages(exclude=['tests']),
include_package_data=True,

install_requires=['svtyper==0.7.1', 'numpy', 'scipy', 'statsmodels', 'pandas==0.19.2', 'setuptools',
install_requires=['svtyper==0.7.1', 'numpy', 'scipy', 'statsmodels', 'pandas', 'setuptools',
'google-auth',
'google-cloud-storage',
'google-compute-engine',
Expand Down
2 changes: 1 addition & 1 deletion svtools/afreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def numeric_alleles(gt_string):
gt = gt_string.split('/')
if len(gt) == 1:
gt = gt_string.split('|')
return map(int, gt)
return [int(x) for x in gt]

def execute(self, output_handle=sys.stdout):
in_header = True
Expand Down
2 changes: 1 addition & 1 deletion svtools/bedpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def retrieve_svtype(self):

def retrieve_af(self):
try:
af = re.split('=', ''.join(filter(lambda x: x.startswith('AF='), self.info.split(';'))))[1]
af = float(re.split('=', ''.join(filter(lambda x: x.startswith('AF='), self.info.split(';'))))[1])
except IndexError:
af = None
return af
Expand Down
4 changes: 2 additions & 2 deletions svtools/breakpoint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys

import l_bp
from exceptions import MissingProbabilitiesException
from . import l_bp
from .exceptions import MissingProbabilitiesException

class BreakpointInterval(object):
'''
Expand Down
2 changes: 1 addition & 1 deletion svtools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class SupportAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
support_string = 'For further help or to report a bug, please open an issue on the svtools repository: https://github.com/hall-lab/svtools/issues'
print support_string
print(support_string)
sys.exit()

def svtools_cli_parser():
Expand Down
5 changes: 5 additions & 0 deletions svtools/sv_classifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function

import argparse, sys, copy, gzip, math
import numpy as np
Expand Down Expand Up @@ -434,6 +435,8 @@ def sv_classify(vcf_in, vcf_out, gender_file, sex_chrom_names, exclude_file, ae_
outf.write("varid\torig_svtype\tsvlen\tnum_pos_samps\tnb_support\tls_support\thybrid_support\thas_rd_support\n")

for line in vcf_in:
if isinstance(line, bytes):
line = line.decode()
if in_header:
if line[0] == '#':
header.append(line)
Expand Down Expand Up @@ -543,6 +546,8 @@ def get_ae_dict(ae_path):
ae_bedfile = open(ae_path, 'r')
ae_dict = {}
for line in ae_bedfile:
if isinstance(line, bytes):
line = line.decode()
v = line.rstrip().split('\t')
if len(v) < 4:
continue
Expand Down
2 changes: 1 addition & 1 deletion svtools/vcf/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def add_header(self, header):
self.other_meta.append(line.rstrip())
elif line[0] == '#' and line[1] != '#':
self.sample_list = line.rstrip().split('\t')[9:]
for i in xrange(0, len(self.sample_list)):
for i in range(0, len(self.sample_list)):
if self.sample_list[i] not in self.sample_indices:
self.sample_indices[self.sample_list[i]] = i + 9
else:
Expand Down
4 changes: 2 additions & 2 deletions svtools/vcfpaste.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def open_files(self):
self.vcf_files = []
# parse the vcf files to paste
for path in self.vcf_file_names:
self.vcf_files.append(InputStream(path, self.tempdir))
self.vcf_files.append(InputStream(path, self.tempdir))

def write_header(self, output_handle=sys.stdout):
master = self.vcf_files[0]
while 1:
Expand Down
2 changes: 2 additions & 0 deletions svtools/vcftobedpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def vcfToBedpe(vcf_file, bedpe_out):
sec_bnds = dict()
v = []
for line in vcf_file:
if isinstance(line, bytes):
line = line.decode()
if in_header:
if line[0:2] == '##':
if line.split('=')[0] == '##fileformat':
Expand Down
6 changes: 3 additions & 3 deletions svtools/vcftobedpeconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def adjust_coordinate(vcf_variant, info_tag, start, end):
of the tag (if it exists)
'''
if info_tag in vcf_variant.info:
span = map(int, vcf_variant.info[info_tag].split(','))
span = [int(x) for x in vcf_variant.info[info_tag].split(',')]
if len(span) != 2:
raise ValueError('Invalid value for tag {0}. Require 2 values to adjust coordinates.'.format(info_tag))
return (start + span[0], end + span[1])
Expand Down Expand Up @@ -137,7 +137,7 @@ def convert(self, primary_variant, secondary_variant=None):



fields = map(str, [
fields = [str(x) for x in [
c1,
max(s1, 0),
max(e1, 0),
Expand All @@ -158,7 +158,7 @@ def convert(self, primary_variant, secondary_variant=None):
orig_alt_b,
info_a,
info_b,
])
]]
if vcf_variant.get_format_string() is not None:
fields += [vcf_variant.get_format_string(), vcf_variant.get_gt_string()]
return Bedpe(fields)
Expand Down
4 changes: 2 additions & 2 deletions tests/bedpe_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ def test_retrieve_svtype(self):
def test_retrieve_af(self):
entry1 = [ '1', '200', '300', '2', '300', '400', '777_1', '57', '+', '-', 'BND', 'PASS', '.', '.', '.', '.', '.', '.', 'SVTYPE=BND;AF=0.2', 'SVTYPE=BND;AF=0.2' ]
b1 = Bedpe(entry1)
self.assertEqual(b1.retrieve_af(), '0.2')
self.assertEqual(b1.retrieve_af(), 0.2)
entry2 = [ '1', '200', '300', '2', '300', '400', '777_1', '57', '+', '-', 'BND', 'PASS', '.', '.', '.', '.', '.', '.', 'SVTYPE=BND', 'SVTYPE=BND' ]
b2 = Bedpe(entry2)
self.assertIsNone(b2.retrieve_af())
entry3 = [ '1', '200', '300', '2', '300', '400', '777_1', '57', '+', '-', 'BND', 'PASS', '.', '.', '.', '.', '.', '.', 'SVTYPE=BND;AF=0.2;FIN_AF=0.01', 'SVTYPE=BND;AF=0.2;FIN_AF=0.01' ]
b3 = Bedpe(entry3)
self.assertEqual(b3.retrieve_af(), '0.2')
self.assertEqual(b3.retrieve_af(), 0.2)

def test_str(self):
# Note that we are testing float to float equivalence. Actually passing in an integer will result in it being converted to float with
Expand Down
2 changes: 1 addition & 1 deletion tests/breakpoint_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_init(self):
self.assertEqual(fixed_slop.right.p, [1e-100, 0.025, 0.25, 0.45, 0.25, 0.025, 1e-100])

percent_slop = Breakpoint(test_line, percent_slop = 0.2)
print percent_slop
print(percent_slop)
self.assertEqual(percent_slop.left.p, [1e-100, 0.025, 0.25, 0.45, 0.25, 0.025, 1e-100])
self.assertEqual(percent_slop.right.p, [1e-100, 0.025, 0.25, 0.45, 0.25, 0.025, 1e-100])

Expand Down
4 changes: 2 additions & 2 deletions tests/cluster_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_add(self):
c.add(b1, None)
self.assertEqual(c.size, 1)
self.assertEqual(c.sv_event, 'BND')
self.assertEqual(c.filter, '0.2')
self.assertEqual(c.filter, 0.2)
self.assertEqual(c.chrom_a, '1')
self.assertEqual(c.min_a, 200)
self.assertEqual(c.max_a, 300)
Expand All @@ -74,7 +74,7 @@ def test_add(self):
c.add(b2, None)
self.assertEqual(c.size, 2)
self.assertEqual(c.sv_event, 'BND')
self.assertEqual(c.filter, '0.3')
self.assertEqual(c.filter, 0.3)
self.assertEqual(c.chrom_a, '1')
self.assertEqual(c.min_a, 195)
self.assertEqual(c.max_a, 305)
Expand Down
2 changes: 1 addition & 1 deletion tests/file_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def expected_output_file_path(self, test_name):

def test_forward_conversions(self):
for test_name in self._test_names:
print test_name
print(test_name)
self.convert_and_diff_output(self.forward_convert,
self.input_file_path(test_name),
self.expected_output_file_path(test_name))
Expand Down
23 changes: 14 additions & 9 deletions tests/reclassifier_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import svtools.sv_classifier
import gzip

def decode(x):
if isinstance(x, bytes):
return x.decode()
return x

class IntegrationTest_sv_classify(TestCase):

def test_chromosome_prefix(self):
Expand All @@ -27,11 +32,11 @@ def test_integration_nb(self):
temp_descriptor, temp_output_path = tempfile.mkstemp(suffix='.vcf')
sex=open(sex_file, 'r')
sex_chrom_names = set(('X', 'Y'))
with gzip.open(input, 'rb') as input_handle, os.fdopen(temp_descriptor, 'w') as output_handle:
with gzip.open(input, 'r') as input_handle, os.fdopen(temp_descriptor, 'w') as output_handle:
svtools.sv_classifier.run_reclassifier(input_handle, output_handle, sex, sex_chrom_names, annot, 0.9, None, 1.0, 0.2, train, 'naive_bayes', diags_file)
expected_lines = gzip.open(expected_result, 'rb').readlines()
expected_lines = [decode(x) for x in gzip.open(expected_result, 'r').readlines()]
expected_lines[1] = '##fileDate=' + time.strftime('%Y%m%d') + '\n'
produced_lines = open(temp_output_path).readlines()
produced_lines = [x.decode() for x in open(temp_output_path).readlines()]
diff = difflib.unified_diff(produced_lines, expected_lines, fromfile=temp_output_path, tofile=expected_result)
os.remove(temp_output_path)
os.remove(diags_file)
Expand All @@ -53,11 +58,11 @@ def test_integration_ls(self):
temp_descriptor, temp_output_path = tempfile.mkstemp(suffix='.vcf')
sex=open(sex_file, 'r')
sex_chrom_names = set(('X', 'Y'))
with gzip.open(input, 'rb') as input_handle, os.fdopen(temp_descriptor, 'w') as output_handle:
with gzip.open(input, 'r') as input_handle, os.fdopen(temp_descriptor, 'w') as output_handle:
svtools.sv_classifier.run_reclassifier(input_handle, output_handle, sex, sex_chrom_names, annot, 0.9, None, 1.0, 0.2, train, 'large_sample', diags_file)
expected_lines = gzip.open(expected_result, 'rb').readlines()
expected_lines = [decode(x) for x in gzip.open(expected_result, 'r').readlines()]
expected_lines[1] = '##fileDate=' + time.strftime('%Y%m%d') + '\n'
produced_lines = open(temp_output_path).readlines()
produced_lines = [decode(x) for x in open(temp_output_path).readlines()]
diff = difflib.unified_diff(produced_lines, expected_lines, fromfile=temp_output_path, tofile=expected_result)
os.remove(temp_output_path)
os.remove(diags_file)
Expand All @@ -80,11 +85,11 @@ def test_integration_hyb(self):
temp_descriptor, temp_output_path = tempfile.mkstemp(suffix='.vcf')
sex=open(sex_file, 'r')
sex_chrom_names = set(('X', 'Y'))
with gzip.open(input, 'rb') as input_handle, os.fdopen(temp_descriptor, 'w') as output_handle:
with gzip.open(input, 'r') as input_handle, os.fdopen(temp_descriptor, 'w') as output_handle:
svtools.sv_classifier.run_reclassifier(input_handle, output_handle, sex, sex_chrom_names, annot, 0.9, None, 1.0, 0.2, train, 'hybrid', diags_file)
expected_lines = gzip.open(expected_result, 'rb').readlines()
expected_lines = [decode(x) for x in gzip.open(expected_result, 'r').readlines()]
expected_lines[1] = '##fileDate=' + time.strftime('%Y%m%d') + '\n'
produced_lines = open(temp_output_path).readlines()
produced_lines = [decode(x) for x in open(temp_output_path).readlines()]
diff = difflib.unified_diff(produced_lines, expected_lines, fromfile=temp_output_path, tofile=expected_result)
os.remove(temp_output_path)
os.remove(diags_file)
Expand Down
9 changes: 7 additions & 2 deletions tests/util_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import os
import svtools.utils as su

def decode(x):
if isinstance(x, bytes):
return x.decode()
return x

class InputStreamTest(TestCase):
def test_init_hyphen(self):
new_handle = su.InputStream('-')
Expand All @@ -26,7 +31,7 @@ def test_context_manager(self):
with su.InputStream(test_input) as stream:
temporary_obj = stream
for line in stream:
sys.stdout.write(line)
sys.stdout.write(decode(line))
self.assertTrue(temporary_obj.closed)

def test_plain_iteration(self):
Expand All @@ -36,7 +41,7 @@ def test_plain_iteration(self):

stream = su.InputStream(test_input)
for line in stream:
sys.stdout.write(line)
sys.stdout.write(decode(line))
stream.close()
self.assertTrue(stream.handle.closed)

Expand Down