Skip to content

Commit

Permalink
Merge pull request #16 from martinghunt/MSPcrunch_output
Browse files Browse the repository at this point in the history
Msp crunch output
  • Loading branch information
aslett1 committed Oct 9, 2015
2 parents b16fbb4 + d47e287 commit 0da0641
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
26 changes: 26 additions & 0 deletions pymummer/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,29 @@ def __str__(self):
self.ref_name,
self.qry_name])


def to_msp_crunch(self):
'''Returns the alignment as a line in MSPcrunch format. The columns are space-separated and are:
1. score
2. percent identity
3. match start in the query sequence
4. match end in the query sequence
5. query sequence name
6. subject sequence start
7. subject sequence end
8. subject sequence name'''

# we don't know the alignment score. Estimate it. This approximates 1 for a match.
aln_score = int(self.percent_identity * 0.005 * (self.hit_length_ref + self.hit_length_qry))

return ' '.join(str(x) for x in [
aln_score,
'{0:.2f}'.format(self.percent_identity),
self.qry_start + 1,
self.qry_end + 1,
self.qry_name,
self.ref_start + 1,
self.ref_end + 1,
self.ref_name
])

8 changes: 8 additions & 0 deletions pymummer/tests/alignment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,11 @@ def test_str(self):
a = alignment.Alignment('\t'.join(l_in))
self.assertEqual(str(a), '\t'.join(l_out))


def test_to_msp_crunch(self):
'''Test to_msp_crunch'''
l_in = ['100', '110', '1', '10', '10', '11', '80.00', '123', '456', '-1', '0', 'ref', 'qry']
a = alignment.Alignment('\t'.join(l_in))
expected = '8 80.00 1 10 qry 100 110 ref'
self.assertEqual(expected, a.to_msp_crunch())

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

setup(
name='pymummer',
version='0.4.0',
version='0.5.0',
description='Wrapper for MUMmer',
packages = find_packages(),
author='Martin Hunt, Nishadi De Silva',
Expand Down

0 comments on commit 0da0641

Please sign in to comment.