DOC

Lab1variables

By Melissa Turner,2014-04-15 14:14
8 views 0
Lab1variables

    Lab 1: Perl语言环境部署及变量练习 Objects:

    LINUXWINDOWS Perl编程环境部署!

    掌握在Linux环境下编写Perl程序!

    掌握标量变量;scalars?的用法!

    掌握数列变量;arrays?的用法!

    掌握散列变量;hash?的用法。

PERL安装

    LINUX,一般PERL编译环境在LINUX操作系统安装后即已安装好! WINDOWS,下载ActivePerl并按提示安装。

登录Linux服务器

    使用Xming登录Linux服务器?点击保存的config文件?输入用户密码点完

    成。

使用gedit编辑Perl程序

    在命令行中输入gedit &后回车(在命令后加上&是让程序在后台运行?不然的话在编辑程序时命令行不能运行其他命令)

    gedit的编辑窗口编辑perl程序代码?注意选择View->Highlight Mode->Scripts->Perl选项?方便阅读程序代码。

程序运行

    在命令行中输入perl 程序文件名

要求

    完成ABC中任意一组题目?相关数据在public目录下。

Part A

    Assuming that there is an input file containing the PKC Beta-1 protein sequence and the file name is pkc_beta_1.seq.

     1. Using UNIX commands cat or more, display the PKC Beta-1 protein

    sequence contained in pkc_beta_1.seq.

     Write a Perl script and do the following:

    2. Read in the PKC Beta-1 protein sequence from an external file and print the sequence on the screen.

     3. Count how many amino acids that the protein sequence contains. Print the number on the screen.(提示用length())

     4. Given an average molecular weight of 110 daltons per amino acid, calculate the estimated molecular weight of the protein sequence in kilodaltons. Print the result on the screen.

Part B

    Assuming that there is an input file, dna_1.seq that contains a DNA sequence.

    Write a new Perl script and do the following:

    5. Read in a DNA sequence from dna_1.seq and print the sequence on the

    screen.

    6. Transcribe this DNA sequence into an RNA sequence. Print both DNA and RNA sequences on the screen. (提示用tr///)

    7. This time, take the DNA sequence and calculate its reverse complement. Print the DNA sequence and its reverse complement on the screen. (提示用tr///

    reverse())

    Part C

    Assuming that there are two input files, homo_sapiens_1.seq and

    homo_sapiens_2.seq both of which contain a DNA sequence to be translated into proteins.

     Write a new Perl script and do the following:

    8. Read in a DNA sequence from homo_sapiens_1.seq and print the sequence

    on the screen.

     9. Count how many nucleotides the sequence contains and print the number on the screen.

     10. Calculate the number of amino acids in the resulting protein (three nucleotides code for one amino acid) and print the number on the screen.;提

    示用int()到整?

     11. Read in a DNA sequence from homo_sapiens_2.seq and print the

    sequence on the screen.

    12. Count how many nucleotides the sequence contains and print the number on the screen.

    13 Calculate the number of amino acids in the resulting protein and print the number on the screen. Do you notice anything weird?

    Variables: Arrays

    Part A

    1. Read in the DNA sequence from the input file dna_1.seq into a

    string.

    2. Write a loop to distribute the characters of the string into

    elements of an array of codons three characters at a time. That

    is, extract the codons from the string and put them into an array.

    (substr($seq,$i,3))

    3. Write out the array with blanks between each element. Part B

    Write a separate short script for each of the following, each one starting with reading in the DNA sequence as above.

    4. Remove the first element from the array of codons and splice in

    the codon "TTC" after the third codon remaining afterwords.

    5. Count how many A's, C's, G's, T's, extraneous characters, there

    are in the original DNA sequence.

    Hint: make a copy of the sequence, record its length, and proceed

    to delete the A's, C's, G's, T's, in turn, recording the length left

    each time.

    Part C

    This part does not involve any input data. This part is the most complicated programming part of this lab.

    6. Write a script to compute the number of possible alignments for

    strings of length 6, as follows.

    a. Write a script to create an array A of 6 elements with each

    entry set to the value 1. This corresponds to all the ways

    to match an empty string.

    b. Use a loop to create a second array B of 6 elements in

    thwhich the i element contains the number of ways to

    match a string of length 1 with a string of length i:

    while ($i < 6) {

     $B[$i] = $B[$i-1] + $A[$i-1] + $A[$i];

     $i = $i + 1;

     }

    c. Move the contents of array B into A by means of a simple

    assignment or a loop.

    d. Print out the two arrays A and B, followed by a blank line.

    Make sure the elements of each array are separated so

    one can read them.

    e. Put the steps b-c-d inside another loop to repeat b-c-d

    five (6) times in all.

    7. Hint: Use the above code snippets in parts of your code, but

    keep in mind that these code snippets are incomplete. For

    example, they do not include the statements to initialize your

    loop variables.

     Q

    In a Perl script, create an array containing four codons 'ATG', 'GTC', 'CGA', 'TTG' (follow this order).

    In the following exercises, specify whether each operation is done in a list/array context or scalar context. In order to get the correct answer, you must try these operations in a Perl script.

    Assuming that the array name is @some_array:

1. @my_array = @some_array; __________________

    Print @my_array on the screen. What is its value?

2. $some = @some_array; __________________

    Print $some on the screen. What is its value?

3. $some = "@some_array"; __________________

    Print $some on the screen. What is its value?

4. ($some) = @some_array; __________________

    Print $some on the screen. What is its value?

    5. ($some2, $some3) = @some_array; __________________ Print $some2 and $some3 on the screen. What are their values?

6. $some = reverse @some_array;

     a) Briefly explain what this statement generates.

    b) I would like reverse the elements in @some_array so that the first item is "TTG" and the last item is "ATG". How would you change the above statement to achieve this goal?

    7. How would you re-write these two statements by forcing scalar context in the print command?

    $some = reverse @some_array;

    Print "$some\n";

Report this document

For any questions or suggestions please email
cust-service@docsford.com