Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0

    Codon translation help


    print "###THIS PROGRAM GIVES PEPTIDE SEQUENCE TO A NUCLEOTIDE CHAIN###\n\n\n";
    print "Enter sequence1\n";
    chomp($dna = <STDIN>);

    %codon = ("TTT" => "F", "TTC" => "F", "TTG" => "L", "TTA" => "L", "TCT" => "S", "TCC" => "S", "TCA" => "S", "TCG" => "S", "TAT" => "Y",
    "TAC" => "Y", "TCA" => "stop", "TAG" => "stop", "TGT" => "C", "TGC" => "C", "TGA" => "stop", "TGG" => "W", "CTT" => "L", "CTC" => "L",
    "CTA" => "L", "CTG" => "L", "CCT" => "P", "CCC" => "P", "CCA" => "P", "CCG" => "P", "CAT" => "H", "CAC" => "H", "CAA" => "Q", "CAG" => "Q",
    "CGT" => "R", "CGC" => "R", "CGA" => "R", "CGG" => "R", "ATT" => "I", "ATG" => "M", "ATC" => "I", "ATA" => "I", "ACT" => "T", "ACC" => "T",
    "ACG" => "T", "ACA" => "T", "AAT" => "N", "AAC" => "N", "AAA" => "K", "AAG" => "K", "AGT" => "S", "AGC" => "S", "AGA" => "R", "AGG" => "R",
    "GTT" => "V", "GTC" => "V", "GTA" => "V", "GTG" => "V", "GCT" => "A", "GCC" => "A", "GCA" => "A", "GCG" => "A", "GAT" => "D", "GAC" => "D",
    "GAA" => "Z", "GAG" => "Z", "GGT" => "G", "GGC" => "G", "GGA" => "G", "GGG" => "G");

    for($num=0; $num <length $dna; $num= $num+3)
    {
    $singlebase =substr $dna, $num, 3;

    $seq= $seq.$codon{$singlebase};
    print "$seq\n";

    }

    print "The given DNA sequence is : \t$dna\n";
    print "The corresponding peptide is : \t $seq \n";



    Please help me to rewrite this code in an alternative manner..
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    842
    Rep Power
    496
    I think that using an hash to store your translation list is probably the best method.

    One major improvement would be to use:

    Code:
    use strict;
    use warnings;
    which will force you to declare your variables, but help you a lot finding possible coding errors or dagneroius construct.

    From there on, what would you want to rewrite differently?

    The only thing that I could suggest is to rewrite you for loop:

    Code:
    for($num=0; $num <length $dna; $num= $num+3)
    in a more perlish manner with a "for my $seq (1..$max)" type of synyax, but this is really a matter of style and taste, and, in this specific case, it might turn out to be more complicated for you, don't do it in that case.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0
    Thanks sir but did u test the code with the loop u suggested ...
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0
    can u help me in wrting a more small code i.e a consise one...
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    842
    Rep Power
    496
    I did not propose any code, so I for sure did not test it (anyway, I don't have any data to test anything).

    Ther only way I can think of to make your code shorter is to make your hash assignment simpler:

    Code:
    my %codon = (TTT => F, TTC => F, TTG => L, TTA => L, TCT => S, TCC => S, TCA => S, TCG => S, TAT => Y, 
    TAC => Y, TCA => stop, TAG => stop, TGT => C, TGC => C, TGA => stop, TGG => W, CTT => L, CTC => L, 
    CTA => L, CTG => L, CCT => P, CCC => P, CCA => P, CCG => P, CAT => H, CAC => H, CAA => Q, CAG => Q, 
    CGT => R, CGC => R, CGA => R, CGG => R, ATT => I, ATG => M, ATC => I, ATA => I, ACT => T, ACC => T, 
    ACG => T, ACA => T, AAT => N, AAC => N, AAA => K, AAG => K, AGT => S, AGC => S, AGA => R, AGG => R, 
    GTT => V, GTC => V, GTA => V, GTG => V, GCT => A, GCC => A, GCA => A, GCG => A, GAT => D, GAC => D, 
    GAA => Z, GAG => Z, GGT => G, GGC => G, GGA => G, GGG => G);
    You could even make it still shorter with something like this:

    Code:
    my %codon = qw (TTT F TTC F TTG L TTA L TCT S TCC S TCA S TCG S TAT Y 
    TAC Y TCA stop TAG stop TGT C TGC C TGA stop TGG W CTT L CTC L 
    CTA L CTG L CCT P CCC P CCA P CCG P CAT H CAC H CAA Q CAG Q 
    CGT R CGC R CGA R CGG R ATT I ATG M ATC I ATA I ACT T ACC T 
    ACG T ACA T AAT N AAC N AAA K AAG K AGT S AGC S AGA R AGG R 
    GTT V GTC V GTA V GTG V GCT A GCC A GCA A GCG A GAT D GAC D 
    GAA Z GAG Z GGT G GGC G GGA G GGG G);
    but I would not recommend that, because the hash structure is much less readable.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0
    thanks sir..it worked...the hash table is not a problem it's working absolutely fine.


    Originally Posted by Laurent_R
    I did not propose any code, so I for sure did not test it (anyway, I don't have any data to test anything).

    Ther only way I can think of to make your code shorter is to make your hash assignment simpler:

    Code:
    my %codon = (TTT => F, TTC => F, TTG => L, TTA => L, TCT => S, TCC => S, TCA => S, TCG => S, TAT => Y, 
    TAC => Y, TCA => stop, TAG => stop, TGT => C, TGC => C, TGA => stop, TGG => W, CTT => L, CTC => L, 
    CTA => L, CTG => L, CCT => P, CCC => P, CCA => P, CCG => P, CAT => H, CAC => H, CAA => Q, CAG => Q, 
    CGT => R, CGC => R, CGA => R, CGG => R, ATT => I, ATG => M, ATC => I, ATA => I, ACT => T, ACC => T, 
    ACG => T, ACA => T, AAT => N, AAC => N, AAA => K, AAG => K, AGT => S, AGC => S, AGA => R, AGG => R, 
    GTT => V, GTC => V, GTA => V, GTG => V, GCT => A, GCC => A, GCA => A, GCG => A, GAT => D, GAC => D, 
    GAA => Z, GAG => Z, GGT => G, GGC => G, GGA => G, GGG => G);
    You could even make it still shorter with something like this:

    Code:
    my %codon = qw (TTT F TTC F TTG L TTA L TCT S TCC S TCA S TCG S TAT Y 
    TAC Y TCA stop TAG stop TGT C TGC C TGA stop TGG W CTT L CTC L 
    CTA L CTG L CCT P CCC P CCA P CCG P CAT H CAC H CAA Q CAG Q 
    CGT R CGC R CGA R CGG R ATT I ATG M ATC I ATA I ACT T ACC T 
    ACG T ACA T AAT N AAC N AAA K AAG K AGT S AGC S AGA R AGG R 
    GTT V GTC V GTA V GTG V GCT A GCC A GCA A GCG A GAT D GAC D 
    GAA Z GAG Z GGT G GGC G GGA G GGG G);
    but I would not recommend that, because the hash structure is much less readable.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0

    protein database problem


    I have to import a file I know how to do that but after importing I have to do matmatecal operation on that imported data..so need help,how to do that.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    842
    Rep Power
    496
    We cannot help without any details on what exactly you want to do and on the nature of your data.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0

    code help


    $str="ATOM 1 N MET A 1 -16.243 -19.569 -22.090 1.00 0.00 N ";
    $str1="ATOM 3 C MET A 1 -16.228 -17.215 -22.811 1.00 0.00 C ";
    $str2="ATOM 8 CE MET A 1 -11.262 -20.355 -22.879 1.00 0.00 C ";
    $x=substr $str,32,7;
    $y=substr $str1,32,8;
    $z=substr $str,32,9;
    print "$x\n";
    print "$y\n";
    print "$z\n";


    this is my code and with this I have to find the distance between the mentioned x,y and z.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    842
    Rep Power
    496
    Originally Posted by krushnach80
    $x=substr $str,32,7;
    $y=substr $str1,32,8;
    $z=substr $str,32,9;
    Your determination of $x, $y and $z does not make sense to me. In particular, $x and $z start at the same offset on the same string, with just a different length. There must be an error.

    Otherwise, I do not know how you are supposed to calculate a distance between such values.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0

    help for calculating distance


    open INP, "pro.pdb";
    open OUT, ">pdbfile.txt";
    while (<INP>)
    {
    if (/^ATOM/)
    {
    print OUT $_;
    }
    }
    and after this I get some out put in pdbfile.txt which contains the information about the x,y,z cordinate and i have to calcualte the distance.
    ATOM 1 N MET A 1 -16.243 -19.569 -22.090 1.00 0.00 N
    ATOM 2 CA MET A 1 -15.489 -18.287 -22.014 1.00 0.00 C
    ATOM 3 C MET A 1 -16.228 -17.215 -22.811 1.00 0.00 C
    ATOM 4 O MET A 1 -15.859 -16.902 -23.943 1.00 0.00 O
    ATOM 5 CB MET A 1 -14.083 -18.488 -22.587 1.00 0.00 C
    ATOM 6 CG MET A 1 -13.144 -18.985 -21.484 1.00 0.00 C
    ATOM 7 SD MET A 1 -11.427 -18.775 -22.013 1.00 0.00 S
    ATOM 8 CE MET A 1 -11.262 -20.355 -22.879 1.00 0.00 C
    ATOM 9 H1 MET A 1 -16.256 -20.018 -21.153 1.00 0.00 H
    ATOM 10 H2 MET A 1 -15.782 -20.203 -22.775 1.00 0.00 H
    ATOM 11 H3 MET A 1 -17.220 -19.380 -22.394 1.00 0.00 H
    ATOM 12 HA MET A 1 -15.415 -17.977 -20.983 1.00 0.00 H
    ATOM 13 HB2 MET A 1 -14.120 -19.218 -23.384 1.00 0.00 H
    ATOM 14 HB3 MET A 1 -13.714 -17.551 -22.974 1.00 0.00 H
    ATOM 15 HG2 MET A 1 -13.314 -18.418 -20.581 1.00 0.00 H
    ATOM 16 HG3 MET A 1 -13.337 -20.031 -21.292 1.00 0.00 H



    So these is what I have to calculate
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    842
    Rep Power
    496
    The one thing I can tell you is that you can't use ther substr function to extract values from these lines, since these lines are not always equal (sometimes the value stats on character 19, sometimes on character 20). You'll have to use regular expressions or split the line on spaces.

    I can tell you how to extract those values, but if you want some help on calculating the distance, you have to define what you mean by distance and how to calculate that. I have absolutely no clue on what the content of this file means, I do not know what a PDB file is, so you have to give this information if you want some help (at least from me, other people around here might know better).
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0

    help for calculating distance


    pdb file is a protein database file where the crystallographic data of protein are given
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0

    help for calculating distance


    okay sir tell me how to extract these values the three coloums are the x,y,z coordinate and I have to use those coordinate to find the distance
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,954
    Rep Power
    1225
    Here's a code snippet showing how you can split the line into fields.

    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use Data::Dumper;
    
    my $str = 'ATOM 1 N MET A 1 -16.243 -19.569 -22.090 1.00 0.00 N';
    
    # split the sting on whitespace into separate fields
    my @fields = split /\s+/, $str;
    print Dumper \@fields;
    
    # extract the 3 fields using an array slice
    my ($x, $y, $z) = (split /\s+/, $str)[6,7,8];
    print Dumper ($x, $y, $z);
    outputs:
    Code:
    $VAR1 = [
              'ATOM',
              '1',
              'N',
              'MET',
              'A',
              '1',
              '-16.243',
              '-19.569',
              '-22.090',
              '1.00',
              '0.00',
              'N'
            ];
    $VAR1 = '-16.243';
    $VAR2 = '-19.569';
    $VAR3 = '-22.090';
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo