Skip to content

Instantly share code, notes, and snippets.

View StephenFordham's full-sized avatar

Stephen Fordham StephenFordham

View GitHub Profile
@StephenFordham
StephenFordham / N_glycosylation_pattern.py
Created April 8, 2019 07:56
N_glycosylation_pattern
N_glycosylation_pattern = 'N[^P][ST][^P]'
@StephenFordham
StephenFordham / Character_groups_example.py
Created April 8, 2019 08:00
Character_groups_example
import re
N_glycosylation_pattern = 'N[^P][ST][^P]'
# putting a caret ^ at the start of the group will negate it
# and match any character that is not in that group
Protein_seq = 'YHWKYELIQNNSNEFC'
if re.search(N_glycosylation_pattern, Protein_seq):
print("N-glycosylation site motif found")
htt_pattern = '(CAG|CAA){18,}'
# just like with substrings we can leave out the lower and upper limits
# here, we will match the pattern 18 or more times
import re
htt_pattern = '(CAG|CAA){18,}'
htt_mRNA = open('C:/Users/apsciuser/Downloads/htt_gene.fasta').read()
match = re.findall(htt_pattern, htt_mRNA)
print("The number of polyQ repeats found are: " + str(len(match)))
# Console output
# The number of polyQ repeats found are: 1
@StephenFordham
StephenFordham / Using_the_search_function.py
Last active April 8, 2019 08:11
Getting started with re.search
import re
DNA = 'GAGCGCTAGCCAAA'
match = re.search(pattern='AAA', string=DNA)
# match = re.search('AAA', 'DNA')
print(match)
<re.Match object; span=(11, 14), match='AAA'>
@StephenFordham
StephenFordham / Regex_search_DNA.py
Last active April 8, 2019 08:12
Regex Example 2
import re
DNA = 'GAGCGCTAGCCAAA'
if re.search('AAA', DNA):
print("Tri-nucleotide found!")
#console output
# Tri-nucleotide found!
import re
DNA = 'GAGCGCTAGCCAAA'
match = re.search('AAA', DNA)
print(match.start())
#11
print(match.end())
#14
print(match.span())
# (11,14)
DNA = 'ATCGACCGGGTTT'
if re.search('CCGGG', DNA) or re.search('CCCGG', DNA):
print('Restriction enzyme found!')
if re.search('CC(G|C)GG', DNA):
print('Restriction enzyme found!')
@StephenFordham
StephenFordham / ORF.py
Last active April 8, 2019 08:16
RegexExample5
open_reading_frame = 'AUG.*(AA|AG|GA)'
@StephenFordham
StephenFordham / Inframe_ORF.py
Last active April 8, 2019 08:17
RegexExample6
inframe_open_reading_frame = 'AUG(...)*U(AA|AG|GA)'