Skip to content

Commit

Permalink
Merge pull request #38 from broadinstitute/hm-fix-long-fragment-length
Browse files Browse the repository at this point in the history
Fix --cluster-from-fragments bug with long fragment length
  • Loading branch information
haydenm committed Jun 12, 2020
2 parents 8c86806 + ad5e062 commit 8d42266
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion catch/genome.py
Expand Up @@ -83,7 +83,7 @@ def fragments(seq):
if include_full_end and len(fragment) < fragment_length:
# This is at the end of seq; instead, use the last
# fragment_length nt
yield seq[(len(seq) - fragment_length):]
yield seq[max(0, len(seq) - fragment_length):]
else:
yield fragment

Expand Down
7 changes: 7 additions & 0 deletions catch/tests/test_genome.py
Expand Up @@ -92,6 +92,13 @@ def test_break_into_fragments_from_one_seq_with_full_end(self):
OrderedDict([('0', 'ATC'), ('1', 'GTT'), ('2', 'TAA')]))
self.assertEqual(broken, expected_genome)

def test_break_into_fragments_from_one_seq_with_full_end_and_long_fragment(self):
genome_one = genome.Genome.from_one_seq('ATCGTTAA')
broken = genome_one.break_into_fragments(12, include_full_end=True)
expected_genome = genome.Genome.from_chrs(
OrderedDict([('0', 'ATCGTTAA')]))
self.assertEqual(broken, expected_genome)

def test_break_into_fragments_from_chrs(self):
genome_two_chrs = genome.Genome.from_chrs(
OrderedDict([("chr1", 'ATCGTTAA'), ("chr2", 'AATTCCGGG')]))
Expand Down

0 comments on commit 8d42266

Please sign in to comment.