Git Product home page Git Product logo

Comments (4)

vishnubob avatar vishnubob commented on August 22, 2024

Thanks for the bug report. I just pushed a fixed for this, and added your example to the unit tests. I moved the match and mismatch scores to the Matrix class. If you wish to customize your match and mismatch values, you can create your own Matrix instance, and pass it as part of the Aligner constructor. In the future, I intend to add more support for ambiguity bases and protein alignments, which is why I broke the Matrix into its own class.

from ssw.

ksahlin avatar ksahlin commented on August 22, 2024

Thank you, this solves a big part of my problem. Here is the new output

>>> print(alignment.alignment_report())
Score = 40, Matches = 29, Mismatches = 9, Insertions = 0, Deletions = 0

ref   4   AGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAG
          ||*|||*|||*|||*|||*|||*|||*|||*|||*|||
query 1   AGGTAGGTAGGTAGGTAGGTAGGTAGGTAGGTAGGTAG

It seems like the last two characters are cut from this alignment, probably because they contain one mismatch and one match so the score is 0 for these two last characters --- and one alignment is returned. I thought I can solve it by letting e.g. mismatch = -1 and match =1. I issued:

>>> score_matrix = ssw.ScoreMatrix(match=2,mismatch=-1)
>>> aligner = ssw.Aligner(ref_seq, matrix=score_matrix, gap_open=1, gap_extend=1)
>>> alignment = aligner.align(query_seq)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kxs624/.pyenv/versions/2.7.9/lib/python2.7/site-packages/ssw/sswobj.py", line 95, in align
    res = self._align(query, reference, flags, filter_score, filter_distance, mask_length)
  File "/Users/kxs624/.pyenv/versions/2.7.9/lib/python2.7/site-packages/ssw/sswobj.py", line 104, in _align
    _query = self.matrix.convert_sequence_to_ints(query)
  File "/Users/kxs624/.pyenv/versions/2.7.9/lib/python2.7/site-packages/ssw/sswobj.py", line 62, in convert_sequence_to_ints
    return _seq_type(*seq_generator)
  File "/Users/kxs624/.pyenv/versions/2.7.9/lib/python2.7/site-packages/ssw/sswobj.py", line 61, in <genexpr>
    seq_generator = (self.symbol_map[symbol.upper()] for symbol in seq)
KeyError: 'A'

from ssw.

vishnubob avatar vishnubob commented on August 22, 2024

The problem is that you need to use the DNA_ScoreMatrix, since ScoreMatrix has no alphabet defined.

reference = "CCC" + "AGCT" * 10
query = "AGGT" * 10
score_matrix = ssw.DNA_ScoreMatrix(match=2, mismatch=-1)
aligner = ssw.Aligner(matrix=score_matrix)
alignment = aligner.align(query, reference)
print(alignment.alignment_report())
Score = 50, Matches = 30, Mismatches = 10, Insertions = 0, Deletions = 0

ref   4   AGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCT
          ||*|||*|||*|||*|||*|||*|||*|||*|||*|||*|
query 1   AGGTAGGTAGGTAGGTAGGTAGGTAGGTAGGTAGGTAGGT

from ssw.

ksahlin avatar ksahlin commented on August 22, 2024

Thank you, that solves it!

from ssw.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.