Photoshop Tutorials for dummies to geeks

click

1)#pick an aa and keeps guessing correct print"enter a aa\n"; $aa=<stdin>; chomp $aa; $ret=&raa; until($aa eq $ret) { $ret=&raa; } print"correct\n"; sub raa { my(@ama)=('a','m','d','p','e','g'); $am=$ama[int rand scalar @ama]; return $am; } 2)#guess nucleotide keeps propting till correct match print"enter a nuc"; $unucl=<stdin>; chomp $unucl; $ret=&rnucl; until($ret eq $unucl) { print"enter a nuc"; $unucl=<stdin>; chomp $unucl; } print"correct"; sub rnucl { my(@nucl)=('a','c','t','g'); return $nucl [int rand scalar @nucl]; } 3)#translation my $dna = 'CGACGTCGA'; for( $i=0; $i < (length($dna) - 2) ; $i += 3) { $codon = substr($dna,$i,3); $protein .= &codon2aa($codon); } print "I translated the DNA\n\n$dna\n\n into the protein\n\n$protein\n\n"; sub codon2aa { my($codon) = @_; my(%genetic_code) = ( 'CGA' => 'S', # Serine 'ZZZ' => 'S', # Serine 'ZZZ' => 'G'); if ( $genetic_code{$codon}) { return ($genetic_code{$codon}); } else { print "Bad codon \"$codon\"!!\n"; } } 4)#atomic coord from pdb open(pdb,"1c1f.pdb"); @pdb_file=<pdb>; close(pdb); foreach $line (@pdb_file) { if($line =~ /^ATOM/) { push(@atomrecord,$line); } } $size=@atomrecord; %results =(); foreach my $record (@atomrecord) { my $number = substr($record, 6, 5); # columns 7-11 my $x = substr($record, 30, 8); # columns 31-38 my $y = substr($record, 38, 8); # columns 39-46 my $z = substr($record, 46, 8); # columns 47-54 my $element = substr($record, 76, 2); # columns 77-78 $number =~ s/^\s*//; $element =~ s/^\s*//; $results{$number} = "$number $x $y $z $element"; } for($i=1;$i<=$size;$i++) { print $results{$i},"\n"; } 5)#extract annotation and seq from gb open(gen,"sequences.gb"); @gbfile=<gen>; close(gen); $in_sequence=0; foreach $line (@gbfile) { if($line =~ /^\/\/\n/) { last; } elsif($in_sequence) { $dna .= $line; } elsif( $line =~ /^ORIGIN/) { $in_sequence=1; } else { push(@annotation,$line); } } $dna =~ s/[\s0-9]//g; print"The DNA sequence is \n$dna\n"; print"The Annotation is \n@annotation\n"; 6)#extract seq from pdb open(pdb,"1c1f.pdb"); @pdb_file=<pdb>; close(pdb); foreach $line (@pdb_file) { if($line =~ /^SEQRES/) { push(@record,$line); } } $lastchain =''; $sequence =''; @results =(); foreach my $line (@record) { $thischain= substr($line, 11, 1); $residues= substr($line, 19, 52); if($lastchain eq "") { $sequence = $residues; } elsif($thischain eq $lastchain) { $sequence .= $residues; } elsif ($sequence) { push(@results, $sequence); $sequence = $residues; } $lastchain=$thischain; } push(@results, $sequence); 7)#count g in command line my($USAGE) = "$0 DNA"; unless(@ARGV) { print $USAGE; exit; } my($dna) = $ARGV[0]; my($num_of_Gs) = &countG ( $dna ); print "\nThe DNA $dna has $num_of_Gs G\'s in it!\n\n"; sub countG { my($dna) = @_; my($count) = 0; $count = ( $dna =~ tr/Gg//); return $count; } 8)#ex of pass by ref my @i = ('1', '2', '3'); my @j = ('a', 'b', 'c'); print "In main program before calling subroutine: i = @i\n"; print "In main program before calling subroutine: j = @j\n"; reference_sub(\@i,\@j); print "In main program after calling subroutine: i = @i\n"; print "In main program after calling subroutine: j = @j\n"; sub reference_sub { my($i, $j) = @_; print "In subroutine : i = @$i\n"; print "In subroutine : j = @$j\n"; push(@$i, '4'); shift(@$j); } 9)#making res map %res_enzyme=( EcoRI => 'GAATTC', HindIII => 'AAGCTT'); $seq='CGATCGAGAATTCACACTAGCTGAATTCACGATCGATGAATTCAAGCTT'; print"Enter the Restriction Enzyme Name\n"; $enzyme=<stdin>; chomp $enzyme; if($res_enzyme{$enzyme}) { $site=$res_enzyme{$enzyme}; } else { print"Restriction Enzyme not found\n"; exit; } @location=&res_map($seq,$site); print"A restriction site for $enzyme at locations:\n @location\n"; sub res_map { my($seq,$site)=@_; @position=(); while($seq =~ /$site/ig) { push(@positions,pos($seq) - length($&) +1); } return @positions; } 10)#mutation $DNA = 'AAAAAAAAA'; $mutant = &mutate($DNA); print "\nMutate DNA\n\n"; print "\nHere is the original DNA:\n $DNA\n"; print "\nHere is the mutant DNA:\n $mutant\n"; print "\nHere are 10 more successive mutations:\n\n"; for ($i=0 ; $i < 10 ; ++$i) { $mutant = &mutate($mutant); print "$mutant\n"; } sub mutate { my($dna) = @_; my($position) = &randomposition($dna); my($newbase) = &randomnucleotide(@nucleotides); substr($dna,$position,2,$newbase); return $dna; } sub randomposition { my($string) = @_; return int rand length $string; } sub randomnucleotide { my(@nucleotides) = ('A', 'C', 'G', 'T'); return $nucleotides[int rand scalar @nucleotides]; } 11)#parsing gb antn using array open(gen,"sequences.gb"); @gbfile=<gen>; close(gen); $in_sequence=0; foreach $line (@gbfile) { if($line =~ /^LOCUS/) { $line =~ s/^LOCUS\s*//; $locus = $line; } elsif($line =~ /^DEFINITION/) { $line =~ s/^DEFINITION\s*//; $definition = $line; } elsif($line =~ /^ACCESSION/) { $line =~ s/^ACCESSION\s*//; $accession = $line; } elsif($line =~ /^ ORGANISM/) { $line =~ s/^\s*ORGANISM\s*//; $organism = $line; } } print "*** LOCUS ***\n"; print "$locus\n"; print "*** Defeinition ***\n"; print "$definition\n"; print "*** ACCESSION ***\n"; print "$accession\n"; print "*** ORGANISM ***\n"; print "$organism\n"; 12)#pitfalls of not using my variable $dna = 'AAAAA'; $result = &A_to_T($dna); print "I changed all the A's in $dna to T's and got $result\n\n"; sub A_to_T { my($input) = @_; $dna = $input; $dna =~ s/A/T/g; return $dna; } 13)#similarity print"enter first seqence\n"; $a=<stdin>; chomp($a); print"enter second sequence\n"; $b=<stdin>; chomp($b); $i=0; @split1=split(//,$a); @split2=split(//,$b); $j=0; $k=0; $s1=@split1; $s2=@split2; while($j < $s1) { if($split1[$j] eq $split2[$k]) { $i++; } $j++; $k++; } print"no of similar elemens are $i\n"; $sim=$i/$s1*100; print"%age sim=$sim";