Beginning Perl for Bioinformatics-chapter4 习题

#!/usr/bin/perl -w

# @Date    : 2017-03-28 00:41:52
# @Author  : Shixiang Wang ([email protected])
# @Link    : http://blog.sciencenet.cn/home.php?mod=space&uid=3238131

# exe 4-2 stores an integer in a variable and then prints it out
$integers = 1234;
print $integers;

# exe 4-3 Print DNA in lowercase; print the DNA in uppercase
$DNAs = 'ACGTacgtACTCgtac';
$DNAs =~ tr/acgt/ACGT/;
print $DNAs,"\n";
$DNAs =~ tr/ACTG/acgt/;
print $DNAs,"\n";

# exe 4-4 Use the string directives \U and \L for upper- and lowercase.
$DNAs1 = 'ACGTacgtACTCgtac';
print "\U$DNAs1\n";
print "\L$DNAs1\n";

# exe 4-5 1  Reverse transcribe RNA to DNA
$RNAs = 'ACGUacGuugac';
$RNAs =~ tr/uU/tT/;
print $RNAs,"\n";

# exe 4-5 2
$RNAs = 'ACGUacGuugac';
$RNAs =~ s/u/t/g;
$RNAs =~ s/U/T/g;
print $RNAs,"\n";


# exe 4-6 
# Read two files of data, and print the content of the first followed by the contents of the second.
# I will use pep data twice.
$File_name = 'NM_021964fragment.pep';
open(PROTEINFILE, $File_name);

@protein  = ;
close PROTEINFILE;

$File_name = 'NM_021964fragment.pep';
open(PROTEINFILE, $File_name);
@protein1 = ;

print @protein,@protein1;
close PROTEINFILE;

# exe4-7 
# Write a program to read a file, and then print its lines in reverse order, the last line first.

print "\n\n\n";
print $protein1[2];
print $protein1[1];
print $protein1[0];


# method 2
print "method2\n";
while(@protein1){
    print pop @protein1;
}


# method 3
print "method3\n";
print reverse @protein

你可能感兴趣的:(Beginning Perl for Bioinformatics-chapter4 习题)