-
Notifications
You must be signed in to change notification settings - Fork 0
Add files via upload #1
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
Open
StudentMAGe
wants to merge
6
commits into
master
Choose a base branch
from
feature
base: master
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.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9fdd09a
Add files via upload
StudentMAGe a3d9de4
Update DNA-RNAclasses.py
StudentMAGe f69beec
Update DNA-RNAclasses.py
StudentMAGe 8058e52
Update DNA-RNAclasses.py
StudentMAGe dd7e6bc
Update DNA-RNAclasses.py
StudentMAGe 9ebdcaa
Update DNA-RNAclasses.py
StudentMAGe 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
|
|
||
| # coding: utf-8 | ||
|
|
||
| # In[ ]: | ||
|
|
||
|
|
||
| # Dna class. Inherited from str class. | ||
| class Dna(str): | ||
|
Lonishin marked this conversation as resolved.
|
||
| def __init__(self, sequence): | ||
| DNAcharlist = ('A', 'C', 'G', 'T', 'S', 'W', 'R', | ||
| 'Y', 'K', 'M', 'B', 'D', 'H', 'V', 'N') | ||
| badseq = False | ||
| trueseq = '' | ||
| for char in sequence: | ||
| if char.upper() in DNAcharlist: | ||
| trueseq += char | ||
| else: | ||
| badseq = True | ||
| continue | ||
| self.sequence = trueseq | ||
| if badseq: | ||
| print ('While initializing Dna object non-DNA characters were omitted') | ||
|
StudentMAGe marked this conversation as resolved.
|
||
| if len (sequence) == 0: | ||
| print ('Empty DNA sequence was created. Using gc() function will return None') | ||
|
|
||
| def __repr__(self): | ||
|
Lonishin marked this conversation as resolved.
|
||
| return (self.sequence) | ||
|
|
||
| def __str__(self): | ||
| return (self.sequence) | ||
|
|
||
| # transcribe function returns transcription | ||
| # in coordinates [transcr_start : transcr_end] | ||
| # as an Rna class object | ||
| # whole sequence is transcribed by default | ||
| def transcribe(self, transcr_start = 1, transcr_end = None): | ||
|
StudentMAGe marked this conversation as resolved.
|
||
| if transcr_end == None: | ||
| transcr_end = len(self) | ||
| Rnatext = self.sequence[(transcr_start-1):transcr_end].replace('T', 'U').replace('t', 'u') | ||
| return Rna(Rnatext) | ||
|
|
||
| # gc() function returns None if sequence length is 0 | ||
| # or all characters are ambiguous | ||
| def gc(self): | ||
| DNAgcdict = {'A': 0, 'C': 1, 'G': 1, 'T': 0, 'S': 1, 'W': 0} | ||
| notforgc = ['R', 'Y', 'K', 'M', 'B', 'D', 'H', 'V', 'N'] | ||
| gcs = 0 | ||
| definedbps = len(self.sequence) | ||
| if len(self.sequence) == 0: | ||
| return None | ||
| for char in self.sequence: | ||
| if char in notforgc: | ||
| definedbps -= 1 | ||
| else: | ||
| gcs += DNAgcdict[char.upper()] | ||
| if definedbps == 0: | ||
| return None | ||
| else: | ||
| return (round(gcs / definedbps, 2)) | ||
|
|
||
| # reverse_complement() function returns Dna object | ||
| # of complementary strand in 5' - 3' orientation | ||
| def reverse_complement(self): | ||
| DNArcdict = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A', | ||
| 'S': 'W', 'W': 'S', 'R': 'Y', 'Y': 'R', | ||
| 'K': 'M', 'M': 'K', 'B': 'V', 'D': 'H', | ||
| 'H': 'D', 'V': 'B', 'N': 'N'} | ||
| rcseq = '' | ||
| for char in self.sequence: | ||
| if char.isupper(): | ||
| rcseq = DNArcdict[char] + rcseq | ||
| else: | ||
| rcseq = DNArcdict[char.upper()].lower() + rcseq | ||
| return Dna(rcseq) | ||
|
|
||
|
|
||
| # Rna class. Inherited from str class. Same as Dna, | ||
| # except transcribe() function is impossible | ||
| class Rna(str): | ||
| def __init__(self, sequence): | ||
| RNAcharlist = ('A', 'C', 'G', 'U', 'S', 'W', 'R', | ||
| 'Y', 'K', 'M', 'B', 'D', 'H', 'V', 'N') | ||
| badseq = False | ||
| trueseq = '' | ||
| for char in sequence: | ||
| if char.upper() in RNAcharlist: | ||
| trueseq += char | ||
| else: | ||
| badseq = True | ||
| continue | ||
| self.sequence = trueseq | ||
| if badseq: | ||
| print ('While initializing Rna object non-RNA characters were omitted') | ||
| if len (sequence) == 0: | ||
| print ('Empty RNA sequence was created. Using gc() function will return None') | ||
|
|
||
| def __repr__(self): | ||
| return (self.sequence) | ||
|
|
||
| def __str__(self): | ||
| return (self.sequence) | ||
|
|
||
| # gc() function returns None if sequence length is 0 | ||
| # or all characters are ambiguous | ||
| def gc(self): | ||
| RNAgcdict = {'A': 0, 'C': 1, 'G': 1, 'U': 0, 'S': 1, 'W': 0} | ||
| notforgc = ['R', 'Y', 'K', 'M', 'B', 'D', 'H', 'V', 'N'] | ||
| gcs = 0 | ||
| definedbps = len(self.sequence) | ||
| if len(self.sequence) == 0: | ||
| return None | ||
| for char in self.sequence: | ||
| if char in notforgc: | ||
| definedbps -= 1 | ||
| else: | ||
| gcs += RNAgcdict[char.upper()] | ||
| if definedbps == 0: | ||
| return None | ||
| else: | ||
| return (round(gcs / definedbps, 2)) | ||
|
|
||
| # reverse_complement() function returns Rna object | ||
| # of complementary sequence in 5' - 3' orientation | ||
| def reverse_complement(self): | ||
| RNArcdict = {'A': 'U', 'C': 'G', 'G': 'C', 'U': 'A', | ||
| 'S': 'W', 'W': 'S', 'R': 'Y', 'Y': 'R', | ||
| 'K': 'M', 'M': 'K', 'B': 'V', 'D': 'H', | ||
| 'H': 'D', 'V': 'B', 'N': 'N'} | ||
| rcseq = '' | ||
| for char in self.sequence: | ||
| if char.isupper(): | ||
| rcseq = RNArcdict[char] + rcseq | ||
| else: | ||
| rcseq = RNArcdict[char.upper()].lower() + rcseq | ||
| return Rna(rcseq) | ||
|
|
||
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.