Leser: 22
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
#!C:/STRAWB~1/perl/bin/perl.exe -w print "Enter a file containing DNA or RNA:\n\n"; $DNA = <STDIN>; chomp $DNA; unless(open(DNAFILE, $DNA)){ print "File not found\n\n"; } @DNA = <DNAFILE>; $DNA = join('',@DNA); $DNA =~ s/\s//g; #Überprüfen ob file DNA oder RNA enthält @BASE_DNA = ("A","C","T","G"); #Für jedes Element wird nun überprüft, ob es einem Nukleotid entspricht, #jedesmal, wenn die Bedingung erfüllt ist wird der count von $i erhöht #Dabei wird bei jedem U, das im String vorkommt der RNA-count um 1 erhöht for($pos = 0; $pos < length $DNA; ++$pos){ $place = substr($DNA, $pos, 1); if(grep {$place eq $_} @BASE_DNA){ ++$i_DNA; } elsif($place =~ /U/){ ++$i_RNA; } } $i_RNA += $i_DNA; #Da die RNA aus allen U plus den anderen Basen besteht #wenn nun $i nicht der Länge der Sequenz entspricht, war mindestens 1 Element kein Nukleotid if($i_DNA eq length $DNA){ print "Sequence successfully identified as DNA\n\n"; } elsif($i_RNA eq length $DNA){ print "Sequence succesfully identified as RNA\n\n"; } else { print "Sequence is whether DNA nor RNA\n\n"; } #DNA wird in RNA umgeschrieben $RNA = $DNA; $RNA =~ s/T/U/ig; #print "The RNA sequence is:\n\n"; #print "$RNA\n\n"; #unpack kann auch als alternative zu split verwendet werden wobei dann "A1" x length $RNA benutzt würde @triplets = unpack("A3" x (length ($RNA)/3), $RNA); #Initialisierung der CODONS @Ala = ("GCU","GCC","GCA","GCG"); @Cys = ("UGU","UGC"); @Asp = ("GAU","GAC"); @Glu = ("GAA","GAG"); @Phe = ("UUU","UUC"); @Gly = ("GGU","GGC","GGA","GGG"); @His = ("CAU","CAC"); @Ile = ("AUU","AUC","AUA"); @Lys = ("AAA","AAG"); @Leu = ("CUU","CUC","CUA","CUG","UUA","UUG"); @Met = ("AUG"); @Asn = ("AAU","AAC"); @Pro = ("CCU","CCC","CCA","CCG"); @Gln = ("CAA","CAG"); @Arg = ("CGU","CGC","CGA","CGG","AGA","AGG"); @Ser = ("AGU","AGC","UCU","UCC","UCA","UCG"); @Thr = ("ACU","ACC","ACA","ACG"); @Val = ("GUU","GUC","GUA","GUG"); @Trp = ("UGG"); @Tyr = ("UAU","UAC"); @STOP = ("UAA","UAG","UGA","UGG"); #Jedes Triplet wird nun ausgetauscht durch den 1-lettercode seiner Aminosäure foreach $trip (@triplets){ if(grep{$trip eq $_} @Ala){ $trip = A; ++$ala; } elsif(grep{$trip eq $_} @Cys){ $trip = C; ++$cys } elsif(grep{$trip eq $_} @Asp){ $trip = D; ++$asp; } elsif(grep{$trip eq $_} @Glu){ $trip = E; ++$glu } elsif(grep{$trip eq $_} @Phe){ $trip = F; ++$phe; } elsif(grep{$trip eq $_} @Gly){ $trip = G; ++$gly; } elsif(grep{$trip eq $_} @His){ $trip = H; ++$his } elsif(grep{$trip eq $_} @Ile){ $trip = I; ++$ile } elsif(grep{$trip eq $_} @Lys){ $trip = K; ++$lys; } elsif(grep{$trip eq $_} @Leu){ $trip = L; ++$leu; } elsif(grep{$trip eq $_} @Met){ $trip = M; ++$met; } elsif(grep{$trip eq $_} @Asn){ $trip = N; ++$asn; } elsif(grep{$trip eq $_} @Pro){ $trip = P; ++$pro; } elsif(grep{$trip eq $_} @Gln){ $trip = Q; ++$gln; } elsif(grep{$trip eq $_} @Arg){ $trip = R; ++$arg; } elsif(grep{$trip eq $_} @Ser){ $trip = S; ++$ser; } elsif(grep{$trip eq $_} @Thr){ $trip = T; ++$thr; } elsif(grep{$trip eq $_} @Val){ $trip = V; ++$val; } elsif(grep{$trip eq $_} @Trp){ $trip = W; ++$trp; } elsif(grep{$trip eq $_} @Tyr){ $trip = Y; ++$tyr } elsif(grep{$trip eq $_} @STOP){ $trip = "!STOP!"; } } #Berechnung des prozentualen Vorkommen jeder Aminosäure $tot = @triplets; $ALA = $ala / $tot * 100; $CYS = $cys / $tot * 100; $ASP = $asp / $tot * 100; $GLU = $glu / $tot * 100; $PHE = $phe / $tot * 100; $GLY = $gly / $tot * 100; $HIS = $his / $tot * 100; $ILE = $ile / $tot * 100; $LYS = $lys / $tot * 100; $LEU = $leu / $tot * 100; $MET = $met / $tot * 100; $ASN = $asn / $tot * 100; $PRO = $pro / $tot * 100; $GLN = $gln / $tot * 100; $ARg = $arg / $tot * 100; $SER = $ser / $tot * 100; $THR = $thr / $tot * 100; $VAL = $val / $tot * 100; $TRP = $trp / $tot * 100; $TYR = $tyr / $tot * 100; $triplets_spaced = join( " " ,@triplets); $file = "Protein"; #Das ganze wird auf das File Protein geschrieben open(PROTEINFILE , ">$file"); print PROTEINFILE "$triplets_spaced\n\n"; printf PROTEINFILE "Ala = %1.2f%\n\n", $ALA; printf PROTEINFILE "Cys = %1.2f%\n\n", $CYS; printf PROTEINFILE "Asp = %1.2f%\n\n", $ASP; printf PROTEINFILE "Glu = %1.2f%\n\n", $GLU; printf PROTEINFILE "Phe = %1.2f%\n\n", $PHE; printf PROTEINFILE "Gly = %1.2f%\n\n", $GLY; printf PROTEINFILE "His = %1.2f%\n\n", $HIS; printf PROTEINFILE "Ile = %1.2f%\n\n", $ILE; printf PROTEINFILE "Lys = %1.2f%\n\n", $LYS; printf PROTEINFILE "Leu = %1.2f%\n\n", $LEU; printf PROTEINFILE "Met = %1.2f%\n\n", $MET; printf PROTEINFILE "Asn = %1.2f%\n\n", $ASN; printf PROTEINFILE "Pro = %1.2f%\n\n", $PRO; printf PROTEINFILE "Gln = %1.2f%\n\n", $GLN; printf PROTEINFILE "Arg = %1.2f%\n\n", $ARg; printf PROTEINFILE "Ser = %1.2f%\n\n", $SER; printf PROTEINFILE "Thr = %1.2f%\n\n", $THR; printf PROTEINFILE "Val = %1.2f%\n\n", $VAL; printf PROTEINFILE "Trp = %1.2f%\n\n", $TRP; printf PROTEINFILE "Tyr = %1.2f%\n\n", $TYR; close PROTEINFILE; print "Proteinsequence written on 'Protein'\n\n"; exit;
1 2 3 4 5 6 7 8 9 10 11
$DNA = <STDIN>; chomp $DNA; unless(open(DNAFILE, $DNA)){ print "File not found\n\n"; } @DNA = <DNAFILE>; $DNA = join('',@DNA); $DNA =~ s/\s//g;
Quote$i_RNA += $i_DNA; #Da die RNA aus allen U plus den anderen Basen besteht
1 2 3 4 5
#DNA wird in RNA umgeschrieben $RNA = $DNA; $RNA =~ s/T/U/ig;[/perl][/quote] Kürzer, schneller, besser:[code=perl](my $RNA = $DNA) =~ tr/tT/U/;
QuoteCode (perl): (dl )1 2 3 4 5 6 7 8 9 10 11 12 13 14#Initialisierung der CODONS @Ala = ("GCU","GCC","GCA","GCG"); @Cys = ("UGU","UGC"); @Asp = ("GAU","GAC"); @Glu = ("GAA","GAG"); @Phe = ("UUU","UUC"); @Gly = ("GGU","GGC","GGA","GGG"); @His = ("CAU","CAC"); #... foreach $trip ( @triplets ) { #... }
1 2 3 4 5 6 7 8 9 10 11 12
my %hash = ( GCU => 'A', GCC => 'A', #... usw ); my %ergebnis; for my $trip ( @triplets ) { my $key = $hash{$trip}; $ergebnis{$key}++; }
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
#!C:/STRAWB~1/perl/bin/perl.exe -w use strict; use warnings; my $proteinfile = "Protein"; print "Enter a file containing DNA or RNA:\n\n"; my $DNA = <STDIN>; chomp $DNA; if(-f $DNA) { local $/=undef; open(DNAFILE, $DNA) or die "ERROR open File: $DNA ($!)\n"; $DNA = <DNAFILE>; close DNAFILE; } else { print "File not found\n"; print "using \"$DNA\" as sequence \n\n"; } $DNA =~ s/\s//g; #Überprüfen ob file DNA oder RNA enthält my $i_DNA = $DNA=~tr/ACTG//; my $i_RNA = $DNA=~tr/U//; my $i_RNA += $i_DNA; #Da die RNA aus allen U plus den anderen Basen besteht #wenn nun $i nicht der Länge der Sequenz entspricht, war mindestens 1 Element kein Nukleotid if($i_DNA == length $DNA) { print "Sequence successfully identified as DNA\n\n"; } elsif($i_RNA == length $DNA) { print "Sequence succesfully identified as RNA\n\n"; } else { print "Sequence is whether DNA nor RNA\n\n"; print "cannot continue!\n\n"; exit(); } #DNA wird in RNA umgeschrieben (my $RNA = $DNA) =~ s/T/U/ig; #print "The RNA sequence is:\n\n"; #print "$RNA\n\n"; #unpack kann auch als alternative zu split verwendet werden wobei dann "A1" x length $RNA benutzt würde my @triplets = unpack("A3" x (length ($RNA)/3), $RNA); #Initialisierung der CODONS my %CODONS=(); my %TRIPLETS=(); $CODONS{ala}={letter=>'A', count=>0}; $TRIPLETS{GCU}=$CODONS{ala}; $TRIPLETS{GCC}=$CODONS{ala}; $TRIPLETS{GCA}=$CODONS{ala}; $TRIPLETS{GCG}=$CODONS{ala}; $CODONS{cys}={letter=>'C', count=>0}; $TRIPLETS{UGU}=$CODONS{cys}; $TRIPLETS{UGC}=$CODONS{cys}; $CODONS{asp}={letter=>'D', count=>0}; $TRIPLETS{GAU}=$CODONS{asp}; $TRIPLETS{GAG}=$CODONS{asp}; $CODONS{glu}={letter=>'E', count=>0}; $TRIPLETS{GAA}=$CODONS{glu}; $TRIPLETS{GAG}=$CODONS{glu}; $CODONS{phe}={letter=>'F', count=>0}; $TRIPLETS{UUU}=$CODONS{phe}; $TRIPLETS{UUC}=$CODONS{phe}; $CODONS{gly}={letter=>'G', count=>0}; $TRIPLETS{GGU}=$CODONS{gly}; $TRIPLETS{GGC}=$CODONS{gly}; $TRIPLETS{GGA}=$CODONS{gly}; $TRIPLETS{GGG}=$CODONS{gly}; $CODONS{his}={letter=>'H', count=>0}; $TRIPLETS{CAU}=$CODONS{his}; $TRIPLETS{CAC}=$CODONS{his}; $CODONS{ile}={letter=>'I', count=>0}; $TRIPLETS{AUU}=$CODONS{ile}; $TRIPLETS{AUC}=$CODONS{ile}; $TRIPLETS{AUA}=$CODONS{ile}; $CODONS{lys}={letter=>'K', count=>0}; $TRIPLETS{AAA}=$CODONS{lys}; $TRIPLETS{AAG}=$CODONS{lys}; $CODONS{leu}={letter=>'L', count=>0}; $TRIPLETS{CUU}=$CODONS{leu}; $TRIPLETS{CUC}=$CODONS{leu}; $TRIPLETS{CUA}=$CODONS{leu}; $TRIPLETS{CUG}=$CODONS{leu}; $TRIPLETS{UUA}=$CODONS{leu}; $TRIPLETS{UUG}=$CODONS{leu}; $CODONS{met}={letter=>'M', count=>0}; $TRIPLETS{AUG}=$CODONS{met}; $CODONS{asn}={letter=>'N', count=>0}; $TRIPLETS{AAU}=$CODONS{asn}; $TRIPLETS{AAC}=$CODONS{asn}; $CODONS{pro}={letter=>'P', count=>0}; $TRIPLETS{CCU}=$CODONS{pro}; $TRIPLETS{CCC}=$CODONS{pro}; $TRIPLETS{CCA}=$CODONS{pro}; $TRIPLETS{CCG}=$CODONS{pro}; $CODONS{gln}={letter=>'Q', count=>0}; $TRIPLETS{CAA}=$CODONS{gln}; $TRIPLETS{CAG}=$CODONS{gln}; $CODONS{arg}={letter=>'R', count=>0}; $TRIPLETS{CGU}=$CODONS{arg}; $TRIPLETS{CGC}=$CODONS{arg}; $TRIPLETS{CGA}=$CODONS{arg}; $TRIPLETS{CGG}=$CODONS{arg}; $TRIPLETS{AGA}=$CODONS{arg}; $TRIPLETS{AGG}=$CODONS{arg}; $CODONS{ser}={letter=>'S', count=>0}; $TRIPLETS{AGU}=$CODONS{ser}; $TRIPLETS{AGC}=$CODONS{ser}; $TRIPLETS{UCU}=$CODONS{ser}; $TRIPLETS{UCC}=$CODONS{ser}; $TRIPLETS{UCA}=$CODONS{ser}; $TRIPLETS{UCG}=$CODONS{ser}; $CODONS{thr}={letter=>'T', count=>0}; $TRIPLETS{ACU}=$CODONS{thr}; $TRIPLETS{ACC}=$CODONS{thr}; $TRIPLETS{ACA}=$CODONS{thr}; $TRIPLETS{ACG}=$CODONS{thy}; $CODONS{val}={letter=>'V', count=>0}; $TRIPLETS{GUU}=$CODONS{val}; $TRIPLETS{GUC}=$CODONS{val}; $TRIPLETS{GUA}=$CODONS{val}; $TRIPLETS{GUG}=$CODONS{val}; $CODONS{trp}={letter=>'W', count=>0}; $TRIPLETS{UUG}=$CODONS{trp}; $CODONS{tyr}={letter=>'Y', count=>0}; $TRIPLETS{UAU}=$CODONS{tyr}; $TRIPLETS{UAC}=$CODONS{tyr}; $CODONS{stop}={letter=>'!STOP!', count=>0}; $TRIPLETS{UAA}=$CODONS{stop}; $TRIPLETS{UAG}=$CODONS{stop}; $TRIPLETS{UGA}=$CODONS{stop}; $TRIPLETS{UGG}=$CODONS{stop}; #Jedes Triplet wird nun ausgetauscht durch den 1-lettercode seiner Aminosäure foreach $trip (@triplets) { $TRIPLETS{uc($trip)}->{count}++; $trip = $TRIPLETS{uc($trip)}->{letter}; } #Berechnung des prozentualen Vorkommen jeder Aminosäure my $tot = keys(%CODONS); $trip->{percent}=$_->{count}/$tot*100 for (values(%CODONS)); #Das ganze wird auf das File Protein geschrieben open(PROTEINFILE , '>', $proteinfile) or die("ERROR open file ($proteinfile) ($!)\n"); print PROTEINFILE join( " " ,@triplets)."\n\n"; for (keys(%CODONS)) { printf PROTEINFILE "%s = %1.2f%\n\n", $_, $CODONS{$_}->{percent}; } close PROTEINFILE; print "Proteinsequence written on 'Protein'\n\n";
$_->{percent}=$_->{count}/$tot*100 for (values(%CODONS));