Skip to content

Commit

Permalink
CH13
Browse files Browse the repository at this point in the history
Sebastian Bassi committed Jul 10, 2017
1 parent f8cd09a commit aac8104
Showing 8 changed files with 65 additions and 0 deletions.
6 changes: 6 additions & 0 deletions code/ch13/cleanseq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import re
regex = re.compile(' |\d|\n|\t')
seq = ''
for line in open('../../samples/pMOSBlue.txt'):
seq += regex.sub('', line)
print(seq)
7 changes: 7 additions & 0 deletions code/ch13/countinfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import re, sys
myregex = re.compile(sys.argv[2])
i = 0
with open(sys.argv[1]) as fh:
for line in fh:
i += len(myregex.findall(line))
print(i)
5 changes: 5 additions & 0 deletions code/ch13/deletecg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import re
regex = re.compile("(?:GC){3,}")
seq = 'ATGATCGTACTGCGCGCTTCATGTGATGCGCGCGCGCAGACTATAAG'
print('Before: {0}'.format(seq))
print('After: {0}'.format(regex.sub('', seq)))
9 changes: 9 additions & 0 deletions code/ch13/findTAT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import re
seq = "ATATAAGATGCGCGCGCTTATGCGCGCA"
rgx = re.compile("TAT")
i = 1
for mo in rgx.finditer(seq):
print('Ocurrence {0}: {1}'.format(i, mo.group()))
print('Position: From {0} to {1}'.format(mo.start(),
mo.end()))
i += 1
8 changes: 8 additions & 0 deletions code/ch13/regexsys1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import re, sys
myregex = re.compile(sys.argv[2])
counter = 0
with open(sys.argv[1]) as fh:
for line in fh:
if myregex.search(line):
counter += 1
print(counter)
16 changes: 16 additions & 0 deletions code/ch13/searchinfasta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import re
pattern = "[LIVM]{2}.RL[DE].{4}RLE"
with open('../../samples/Q5R5X8.fas') as fh:
fh.readline() # Discard the first line.
seq = ""
for line in fh:
seq += line.strip()
rgx = re.compile(pattern)
result = rgx.search(seq)
patternfound = result.group()
span = result.span()
leftpos = span[0]-10
if leftpos<0:
leftpos = 0
print(seq[leftpos:span[0]].lower() + patternfound +
seq[span[1]:span[1]+10].lower())
9 changes: 9 additions & 0 deletions samples/Q5R5X8.fas
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
>Q5R5X8|CAP2_PONPY CAP 2 - Pongo pygmaeus (Orangutan).
MANMQGLVERLERAVSRLESLSAESHRPPGNCGEVNGVIGGVAPSVEAFDKLMDSMVAEF
LKNSRILAGDVETHAEMVHSAFQAQRAFLLMASQYQQPHENDVAALLKPISEKIQEIQTF
RERNRGSNMFNHLSAVSESIPALGWIAVSPKPGPYVKEMNDAATFYTNRVLKDYKHSDLR
HVDWVKSYLNIWSELQAYIKEHHTTGLTWSKTGPVASTVSAFSVLSSGPGLPPPPPPPPP
PGPPPLLENEGKKEESSPSRSALFAQLNQGEAITKGLRHVTDDQKTYKNPSLRAQGGQTR
SPTKSHTPSPTSPKSYPSQKHAPVLELEGKKWRVEYQEDRNDLVISETELKQVAYIFKCE
KSTLQIKGKVNSIIIDNCKKLGLVFDNVVGIVEVINSQDIQIQVMGRVPTISINKTEGCH
IYLSEDALDCEIVSAKSSEMNILIPQDGDYREFPIPEQFKTAWDGSKLITEPAEIMA
5 changes: 5 additions & 0 deletions samples/pMOSBlue.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 ATGACCATGA TTACGCCAAG CTCTAATACG ACTCACTATA GGGAAAGCTT GCATGCCTGC

61 AGGTCGACTC TAGAGGATCT ACTAGTCATA TGGATATCGG ATCCCCGGGT ACCGAGCTCG

121 AATTCACTGG CCGTCGTTTT

0 comments on commit aac8104

Please sign in to comment.