Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SW_cuda modual #155

Open
Zhu-Siqi opened this issue Feb 27, 2024 · 8 comments
Open

SW_cuda modual #155

Zhu-Siqi opened this issue Feb 27, 2024 · 8 comments

Comments

@Zhu-Siqi
Copy link

Zhu-Siqi commented Feb 27, 2024

Hi,

I want to do some end-to-end training using your sw_cuda modual. But it seems that I don't how it works. My code:

from deepblast.sw_cuda import SmithWatermanDecoder
device = torch.device('cuda:0')

ddp = SmithWatermanDecoder(operator='softmax')
match = torch.randn(100, 120, 108).requires_grad_(True)
gap = torch.randn(100, 120, 108).requires_grad_(True)
aln = ddp.decode(match.to(device), gap.to(device))

In my understanding, aln should return the probability of alignment. However, the aln tensor always get 0 in the first row and column, which means aln don't return what I want. So is my code wrong, or I just misunderstand the output of ddp.decode?

@mortonjt
Copy link
Collaborator

mortonjt commented Feb 27, 2024 via email

@Zhu-Siqi
Copy link
Author

Zhu-Siqi commented Feb 27, 2024

Thanks for your quick reply!

I have used my model to create the match and gap scoring matrices, and expect to use your differentiable_sw modual to get the alignment prediction. In other words, I have match scoring matrix M # (size: a*b) and gap scoring matrix G # (size: a*b), a and b are the lengths of two sequence. Now, I want to get a align matrix A # (size: a*b) and A[i][j] is the predicted alignment of the ith and jth residue. How can I get such a align matrix from your differentiable_sw modual?

Due to the lack of comments, it is a little difficult to understand the result returned by SmithWatermanDecoder. Could you explain what the aln tensor means and add some comments in your code? Your code is elegantly written but lacks comments, which hinders its readability XD. As I just want to use a modual from your work instead of finetuning your model, the comments are not enough to tell me where I can start my work.

@mortonjt
Copy link
Collaborator

mortonjt commented Feb 27, 2024 via email

@Zhu-Siqi
Copy link
Author

Does the aln matrix means the expected alignment between the two proteins? Why do I always get 0 in the first row and column of aln matrix and 1 as the last element of 'aln' matrix? The picture below shows the result of my test code.
Because I define the match and gap scoring matrices randomly, the locations of gap should be different. Do I confuse what the align matrix means or give the inappropriate inputs?
图片

@Zhu-Siqi
Copy link
Author

After running your test code (https://github.com/flatironinstitute/deepblast/blob/master/deepblast/tests/test_sw.py), I also get the same result.

@mortonjt
Copy link
Collaborator

Hi yes this is by construction -- we zero out the first row / column to make autograd work ...

@Zhu-Siqi
Copy link
Author

Zhu-Siqi commented Apr 13, 2024

Thanks! I understand the zeros in the first row and column. However, why is the last element always one? If so, it means that the last element is always aligned.

Thanks again for your reply! I also look forward to see an example like https://github.com/spetti/SMURF/blob/main/examples/SSW_examples/sw_in_tensorflow_pytorch.ipynb. Your work is similar with it. However, without a good example file, I couldn't follow your work well :(

@mortonjt
Copy link
Collaborator

Got it. Yes we generate those types of alignment visualizations as depicted in the tensorboard readouts.
https://github.com/flatironinstitute/deepblast/blob/master/deepblast/trainer.py#L248-L251

We are currently in the middle of doing a overhaul of the tutorials, more updates to come by July

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants