Bioinformatics/Subsequence: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 206: | Line 206: | ||
GCTA does not occur |
GCTA does not occur |
||
</pre> |
</pre> |
||
=={{header|Python}}== |
|||
{{works with|Python|3.8}} |
|||
{{libheader|regex}} |
|||
<lang python> |
|||
from random import choice |
|||
import regex as re |
|||
import time |
|||
def generate_sequence(n: int ) -> list: |
|||
return "".join([ choice(['A','C','G','T']) for _ in range(n) ]) |
|||
def dna_findall(needle: str, haystack: str) -> None: |
|||
if sum(1 for _ in re.finditer(needle, haystack, overlapped=True)) == 0: |
|||
print("No matches found") |
|||
else: |
|||
print(f"Found {needle} at the following indices: ") |
|||
for match in re.finditer(needle, haystack, overlapped=True): |
|||
print(f"{match.start()}:{match.end()} ") |
|||
dna_seq = generate_sequence(200) |
|||
sample_seq = generate_sequence(4) |
|||
c = 1 |
|||
for i in dna_seq: |
|||
print(i, end="") if c % 20 != 0 else print(f"{i}") |
|||
c += 1 |
|||
print(f"\nSearch Sample: {sample_seq}") |
|||
dna_findall(sample_seq, dna_seq) |
|||
</lang> |
|||
{{out}} |
|||
TTGCCCCTGTACTGAGCCCA |
|||
TAAGCTTGCACTCAAGGTTT |
|||
TGCCCCCTCATATTATAACG |
|||
CATCCATTATACAAAACCGA |
|||
TACCCTTCCGCATATTATGA |
|||
AAAGTGGCGAAGTGCCTTGA |
|||
TTTGCATTCATAGTACAACG |
|||
GTGCAAAAGCATTGTATGTC |
|||
TCACATTTACATGGGAAATG |
|||
CCTAGTAGGTGCAAGACCTG |
|||
Search Sample: TACA |
|||
Found TACA at the following indices: |
|||
69:73 |
|||
133:137 |
|||
167:171 |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |