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

Basic tokenizer #6

Merged
merged 4 commits into from
Jan 16, 2021
Merged

Basic tokenizer #6

merged 4 commits into from
Jan 16, 2021

Conversation

MacDoc77
Copy link
Contributor

No description provided.

tokenizer Outdated
@@ -0,0 +1,24 @@
import numpy as np

def tokenizer(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions use imperative language.

@MacDoc77 MacDoc77 linked an issue Jan 16, 2021 that may be closed by this pull request
tokenizer Outdated
Comment on lines 13 to 21
for x in nucleotide_sequence:
if x == "A" or x == "a":
arr.append([0,counter]) # Map A to 0
elif x == "C" or x == "c":
arr.append([1,counter]) # Map C to 1
elif x == "G" or x == "g":
arr.append([2,counter]) # Map G to 2
elif x == "T" or x == "t":
arr.append([3,counter]) # Map T to 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be faster here. Try defining a dict {'A': 0, 'C': 1, 'G': 2, 'T': 3} as a "Rosetta Stone" for tokenizing the base pairs

tokenizer Outdated
elif x == "T" or x == "t":
arr.append([3,counter]) # Map T to 3
counter += 1 # Increment counter
np_arr = np.array(arr) # Convert finished array to a numpy array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaks single-responsibility principle. The function name claims it tokenizes a string, not additionally constructing a NumPy array.

Copy link
Contributor

@Lev1ty Lev1ty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not doing position embeddings at this point. Waiting on wet lab feedback on where to set zero position.

@MacDoc77 MacDoc77 merged commit 3ad1c75 into main Jan 16, 2021
"G" : 2,
"T" : 3
} # Declares the integers that correspond to each nucleotide
# counter = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the counter for clarity

Comment on lines +19 to +20
for x in nucleotide_sequence:
arr.append(mappings[x]) # Adds a converted nucleotide to the end of the array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be replaced with a list comprehension, something like [mappings[x] for x in sequence]. List comprehensions are generally faster than for loops

@Lev1ty Lev1ty mentioned this pull request Jan 16, 2021
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

Successfully merging this pull request may close these issues.

Make tokenizer for gene sequences
2 participants