-
Notifications
You must be signed in to change notification settings - Fork 49
Updates to opencloning_datamodels #490
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
Draft
manulera
wants to merge
11
commits into
cloning-history-bjorn
Choose a base branch
from
cloning-history-bjorn-manu
base: cloning-history-bjorn
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1e817b4
enable higher opencloning-linkml versions
manulera 5a6c7d3
support and test edge case from #488
manulera 5028df8
starting to work on better serialization
manulera c22d42d
simplify serialization to avoid having to use kwargs, instead define …
manulera 7d89f65
fix tests (happens because TARGET_MODEL was not behaving properly in …
manulera 4404482
update notebook output
manulera e5d5270
add some repositories
manulera b47b060
add the rest of the models
manulera 242bc4d
add and test oligonucleotide hybridization
manulera 2dfd703
update to latest model version
manulera e95e860
comment Location out
manulera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| This module contains the functions for oligonucleotide hybridization. | ||
| """ | ||
|
|
||
| from pydna.common_sub_strings import common_sub_strings | ||
| from Bio.Seq import reverse_complement | ||
| from pydna.primer import Primer | ||
| from pydna.dseqrecord import Dseqrecord | ||
| from pydna.dseq import Dseq | ||
| from pydna.opencloning_models import OligoHybridizationSource, SourceInput | ||
|
|
||
|
|
||
| def oligonucleotide_hybridization_overhangs( | ||
| fwd_oligo_seq: str, rvs_oligo_seq: str, minimal_annealing: int | ||
| ) -> list[int]: | ||
| """ | ||
| Returns possible overhangs between two oligos given a minimal annealing length, and | ||
| returns an error if mismatches are found. | ||
|
|
||
| see https://github.com/manulera/OpenCloning_backend/issues/302 for notation | ||
|
|
||
| >>> from pydna.oligonucleotide_hybridization import oligonucleotide_hybridization_overhangs | ||
| >>> oligonucleotide_hybridization_overhangs("ATGGC", "GCCAT", 3) | ||
| [0] | ||
| >>> oligonucleotide_hybridization_overhangs("aATGGC", "GCCAT", 5) | ||
| [-1] | ||
| >>> oligonucleotide_hybridization_overhangs("ATGGC", "GCCATa", 5) | ||
| [1] | ||
| >>> oligonucleotide_hybridization_overhangs("ATGGC", "GCCATaaGCCAT", 5) | ||
| [0, 7] | ||
|
|
||
| If the minimal annealing length is longer than the length of the shortest oligo, it returns an empty list. | ||
|
|
||
| >>> oligonucleotide_hybridization_overhangs("ATGGC", "GCCATaaGCCAT", 100) | ||
| [] | ||
|
|
||
| If it's possible to anneal for ``minimal_annealing`` length, but with mismatches, it raises an error. | ||
|
|
||
| >>> oligonucleotide_hybridization_overhangs("cATGGC", "GCCATa", 5) | ||
| Traceback (most recent call last): | ||
| ... | ||
| ValueError: The oligonucleotides can anneal with mismatches | ||
| """ | ||
| matches = common_sub_strings( | ||
| fwd_oligo_seq.lower(), | ||
| reverse_complement(rvs_oligo_seq.lower()), | ||
| minimal_annealing, | ||
| ) | ||
|
|
||
| for pos_fwd, pos_rvs, length in matches: | ||
|
|
||
| if (pos_fwd != 0 and pos_rvs != 0) or ( | ||
| pos_fwd + length < len(fwd_oligo_seq) | ||
| and pos_rvs + length < len(rvs_oligo_seq) | ||
| ): | ||
| raise ValueError("The oligonucleotides can anneal with mismatches") | ||
|
|
||
| # Return possible overhangs | ||
| return [pos_rvs - pos_fwd for pos_fwd, pos_rvs, length in matches] | ||
|
|
||
|
|
||
| def oligonucleotide_hybridization( | ||
| fwd_primer: Primer, rvs_primer: Primer, minimal_annealing: int | ||
| ) -> list[Dseqrecord]: | ||
| """ | ||
| Returns a list of Dseqrecord objects representing the hybridization of two primers. | ||
|
|
||
| >>> from pydna.primer import Primer | ||
| >>> from pydna.oligonucleotide_hybridization import oligonucleotide_hybridization | ||
| >>> fwd_primer = Primer("ATGGC") | ||
| >>> rvs_primer = Primer("GCCA") | ||
| >>> oligonucleotide_hybridization(fwd_primer, rvs_primer, 3)[0].seq | ||
| Dseq(-5) | ||
| ATGGC | ||
| ACCG | ||
|
|
||
| Multiple values can be returned: | ||
|
|
||
| >>> rvs_primer2 = Primer("GCCATaaGCCAT") | ||
| >>> oligonucleotide_hybridization(fwd_primer, rvs_primer2, 3)[0].seq | ||
| Dseq(-12) | ||
| ATGGC | ||
| TACCGaaTACCG | ||
| >>> oligonucleotide_hybridization(fwd_primer, rvs_primer2, 3)[1].seq | ||
| Dseq(-12) | ||
| ATGGC | ||
| TACCGaaTACCG | ||
|
|
||
| If no possible overhangs are found, it returns an empty list. | ||
|
|
||
| >>> oligonucleotide_hybridization(fwd_primer, rvs_primer, 100) | ||
| [] | ||
|
|
||
| If there are mismatches given the minimal annealing length, it raises an error. | ||
|
|
||
| >>> fwd_primer3 = Primer("cATGGC") | ||
| >>> rvs_primer3 = Primer("GCCATa") | ||
| >>> oligonucleotide_hybridization(fwd_primer3, rvs_primer3, 5) | ||
| Traceback (most recent call last): | ||
| ... | ||
| ValueError: The oligonucleotides can anneal with mismatches | ||
| """ | ||
| possible_overhangs = oligonucleotide_hybridization_overhangs( | ||
| str(fwd_primer.seq), str(rvs_primer.seq), minimal_annealing | ||
| ) | ||
| sources = [ | ||
| OligoHybridizationSource( | ||
| overhang_crick_3prime=pos, | ||
| input=[SourceInput(sequence=fwd_primer), SourceInput(sequence=rvs_primer)], | ||
| ) | ||
| for pos in possible_overhangs | ||
| ] | ||
| return [ | ||
| Dseqrecord( | ||
| Dseq( | ||
| str(fwd_primer.seq), | ||
| str(rvs_primer.seq), | ||
| ovhg=source.overhang_crick_3prime, | ||
| ), | ||
| source=source, | ||
| ) | ||
| for source in sources | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.