-
Notifications
You must be signed in to change notification settings - Fork 13
/
lesson15a_examples.pl
49 lines (41 loc) · 1.31 KB
/
lesson15a_examples.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Cambridge Perl course
# Lesson 15a Examples
use strict;
use warnings;
# Finding a stop codon
my $dna = 'ACTTGATAG';
if ($dna =~ /TAG/) {
print "$dna contains a stop codon\n";
}
else {
print "No stop codons found";
}
# Using wildcards, character classes and anchors
$dna = "ACAGGAGGATCTACTGCAGGCCAGCGCGAAGAGACTCATATAGGCAGACGAGAACGTAG";
if ($dna =~ /CTGCAG/) {
print "Found PstI recognition site\n";
}
if ($dna =~ /GA.TC/) {
print "Found HinfI recognition site\n";
}
if ($dna =~ /[AG]GATC[TC]/) {
print "Found XhoII recognition site\n";
}
if ($dna =~ /TAG$/) {
print "Found STOP codon at the end of the sequence\n";
}
# Using digit, word and whitespace classes and multiple matches
foreach my $genename ("BRCA1","BRCA11","BRCA 1","BRCA1 gene") {
if ($genename =~ /^\w+\d$/) {
print "$genename contains one or more word characters, one digit, and nothing else\n";
}
else {
print "$genename contains something other than one or more word characters, one digit and nothing else\n";
}
if ($genename =~ /\w+\s*\d+/) {
print "$genename contains one or more word characters, optional whitespace and one or more digits\n";
}
else {
print "$genename contains something other than one or more word characters, optional whitespace and one or more digits\n";
}
}