Beginning Perl for Bioinformatics-chapter4 习题

#!/usr/bin/perl -w

# @Date    : 2017-03-28 00:41:52
# @Author  : Shixiang Wang (w_shixiang@163.com)
# @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  = <PROTEINFILE>;
close PROTEINFILE;

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

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
    原文作者:王诗翔
    原文地址: https://www.jianshu.com/p/750590ddff44
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞