0% found this document useful (0 votes)
2 views

Perl Program

This document is a Perl program report detailing various programming exercises conducted by a student named Surabhi Sahoo in the Computer Programming Laboratory. It includes multiple programs demonstrating string concatenation, DNA sequence manipulation, array functions, and case conversion, along with their respective algorithms, code, and outputs. The report serves as a practical application of Perl programming concepts in a biotechnology context.

Uploaded by

2160113
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Perl Program

This document is a Perl program report detailing various programming exercises conducted by a student named Surabhi Sahoo in the Computer Programming Laboratory. It includes multiple programs demonstrating string concatenation, DNA sequence manipulation, array functions, and case conversion, along with their respective algorithms, code, and outputs. The report serves as a practical application of Perl programming concepts in a biotechnology context.

Uploaded by

2160113
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

SCHOOL OF BIOTECHNOLOGY

Computer Programming Laboratory(CS 1093)


Spring Session (2021-22)

Perl Program Report


IMTH-2
2ND SEMESTER
NAME- Surabhi Sahoo.
ROLL NO.-2160113
SECTION-B
FACULTY- Dr. Rajani Kanta Mahapatra.

1
TO CHECK IF PERL IS INSTALLED AND THE VERSION OF THE
INSTALLED PERL

Microsoft Windows [Version 10.0.22000.556]


(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>perl -v

This is perl 5, version 32, subversion 1 (v5.32.1) built for MSWin32-x64-


multi-thread

Copyright 1987-2021, Larry Wall

Perl may be copied only under the terms of either the Artistic License or
the GNU General Public License, which may be found in the Perl 5 source
kit.

Complete documentation for Perl, including FAQ lists, should be found


on this system using "man perl" or "perldoc perl". If you have access to
the Internet, point your browser at http://www.perl.org/, the Perl
Home Page.

2
PROGRAM 1
Part - A
AIM-To concatenate the given two sequences using dot operator

ALGORITHM-
1. Using print command to print a statement
2.Assigning two strings to two singular variable respectively.
3.Print the two strings respectively.
4.Using dot operator(.)join the two strings and simultaneously assign it to
a third singular variable
5.Print the concatenated string.
6.Use the exit command to end the program

CODE-
#!/usr/bin/perl
print"The first name is:";
$A='BIO';
print"$A\n";
print"The second name is:";
$B='CHEMISTRY';
print"$B\n";
$C=$A.$B;
print"The joined sequence is:";
print"$C\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd/

C:\>cd strawberry

C:\Strawberry>prog1.pl

3
The first name is:BIO
The second name is:CHEMISTRY
The joined sequence is:BIOCHEMISTRY

Part - B
AIM-To concatenate the given two sequences using string interpolation
method

ALGORITHM-
1. Using a print command to print a statement.
2. Assigning two strings to two singular variables respectively.
3.Print the two strings respectively.
4.Using string interpolation method to join the two strings and
simultaneously assign it to a third singular variable
5.Print the concatenated string.
6.Use the exit command to end the program

CODE-
#!/usr/bin/perl
print"The first name is:";
$A='BIO';
print"$A\n";
print"The second name is:";
$B='CHEMISTRY';
print"$B\n";
$C="$A$B";
print"The joined sequence is:";
print"$C\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

4
C:\>cd strawberry

C:\Strawberry>prog1a.pl
The first name is:BIO
The second name is:CHEMISTRY
The joined sequence is:BIOCHEMISTRY

NOTE-
$DNA - Scalar variable used to store a single variable at a particular
time.
@DNA - Array variable used to store multiple data in a single string.
Dot operator(.) - used to join data of 2 scalar variable and once joined
assigned to a 3rd variable.
String interpolation - another method to join strings, also uses a third
variable to store the concatenated variable

PROGRAM 2
AIM-To display the content of “Substitution” operator,”Binding” operator
& “Global” operator.

ALGORITHM-
1. Using a print command to print a statement.
2. Using a scalar variable to store a DNA sequence.
3. Printing the above DNA using print command.
4. Storing the DNA in another scalar variable.
5. Using the substitution operator & binding operator to convert
Thymine(T) to Uracil(U) to convert the DNA to RNA.
6. Print a statement.
7. Print the RNA.
8. Exit command to end the program.

CODE-
#!/usr/bin/perl
$dna='ATGCATTTGC';
print"The DNA sequence is:";
5
print"$dna\n";
$rna=$dna;
$rna =~ s/T/U/g;
print"The RNA sequence is:";
print"$rna\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>prog2.pl
The DNA sequence is:ATGCATTTGC
The RNA sequence is:AUGCAUUUGC

NOTE-
Binding operator (=~) - used on variables containing strings;it means
apply the operation on the right to the string in the variable on left.
Substitute operator (s) - indicates it’s a substitution;after second \
comes U which is the element replacing T.
g- stands for “global”;means make this substitution throughout the entire
string.

PROGRAM 3
AIM-To display the content of Reverse Program Writing.

ALGORITHM-
1. Use scalar variable to store a DNA sequence.
2. Print command to print statement.
3. Print command to print the DNA.
4. Reverse function to store the reverse DNA & store in a scalar variable.

6
5. Print the reverse DNA.
6. Exit command to end program.

CODE-
#!/usr/bin/perl
$DNA='ATGC';
print"The DNA sequence is ";
print"$DNA\n";
$DNA1=reverse($DNA);
print"The reverse DNA sequence is ";
print"$DNA1\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>prog3.pl
The DNA sequence is ATGC
The reverse DNA sequence is CGTA

PROGRAM 4
AIM-To display the content of “Reverse” & “Transliterate” operator

ALGORITHM-
1.Print command to print a statement.
2.Scalar variable to store a DNA sequence.
3.Print command to print the DNA.
4.Reverse function to store the reverse DNA & store in a scalar variable.
5.Print the reverse DNA.
6.Use transliterate operator to make complement of DNA & store in a
scalar variable.
7
7.Print the complement DNA.
8.Exit command to end program.

CODE-
#!/usr/bin/perl
$DNA='ACCTAGGT';
print"The DNA sequence is ";
print"$DNA\n";
$DNA1=reverse($DNA);
print"The reverse DNA sequence is ";
print"$DNA1\n";
$DNA1 =~ tr/ATGC/TACG/;
print"The compliment sequence is ";
print"$DNA1\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Strawberry>cd\

C:\>cd strawberry

C:\Strawberry>prog4.pl
The DNA sequence is ACCTAGGT
The reverse DNA sequence is TGGATCCA
The compliment sequence is ACCTAGGT

NOTE-
Transliterate operator (tr) - translates a set of character into new
characters all at once.
Reverse function (reverse) - reverse order of elements including
strings.
PROGRAM 5

8
AIM-To display the Content of “Array” Function

LOGARITHM-
1. Use a array variable to store a multiple numbers in a array.
2. Print command to print a statement.
3. Print the whole array.
4. Print command to print a statement.
5. Print statement the first element of the array by using the position.
6. Exit command to end program.

CODE-
#!/usr/bin/perl
@n=('1','2','3','4','5');
print"The array is ";
print"@n\n";
print"The first element of the array is ";
print"$n[0]";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>prog5.pl
The array is 1 2 3 4 5
The first element of the array is 1

NOTE-
[]-used to designate position of the element to be printed in an array.
@n - array variable to store multiple elemnts.

9
PROGRAM 6
AIM-To display the content of “Sort” function in an array.

ALGORITHM-
1. Use array variable to store a array.
2. Use sort function to arrange the numbers in the array in ascending
order.
3. Print the sorted array using print command.
4. Exit command to end the program.

CODE-
#!/usr/bin/perl
@n=('18','11','14','17','15');
@n=sort(@number);
print"@n\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>prog6.pl
11 14 15 17 18

NOTE-
Sort function (sort) - used to arrange all the elements(numbers &
alphabets) in ascending order.
To find the position of an (n-1) formulae is used,counting in an array starts
from 0,n=position mentioned in question.

10
PROGRAM 7
Part - A
AIM-To display the content of “Sort” & “Reverse” function in an array.

ALGORITHM-
1. Use a array variable to store an array of numbers.
2. Use the sort function to arrange the array in ascending order and store
in another variable.
3. Use reverse function to arrange the sorted array in descending order
and store in another array variable.
4. Print the reverse array using print command.
5. Exit command to end the program.

CODE-
#!/usr/bin/perl
@n=('18','11','14','17','15');
@n1=sort(@number);
@n2=reverse(@number1);
print”@n1\n”;
print"@n2\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>prog7.pl
11 14 15 17 18
18 17 15 14 11

11
Part - B
(using an array of alphabets)
CODE-
#!/usr/bin/perl
@n=('k','a','h','n','u','i');
@n1=sort(@number);
@n2=reverse(@number1);
print"@n1\n";
print"@n2\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>prog7a.pl
ahiknu
unkiha

Part - C
(using an array of words)
CODE-
#!/usr/bin/perl
@n=('Aditi','Khushi','Prerna','Jahnavi','Sipra',);
@n1=sort(@n);
@n2=reverse(@n1);
print"@n1\n";
print"@n2\n";
exit;

12
OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>prog7b.pl
Aditi Jahnavi Khushi Prerna Sipra
Sipra Prerna Khushi Jahnavi Aditi

PROGRAM 8
Part - A
AIM-To display the content of “Splice “ function in an array.

LOGARITHM-
1. Print command to print a statement.
2. Array variable to store an array.
3. Print command to print the array.
4. Print command to print a statement.
5. Using Splice function to insert an element in array at a particular
position.
6. Print the modified array after splice.
7. Exit command to end the program.

CODE-
#!/usr/bin/perl
print"The original array is:";
@a=('a','e','i','o');
print"@a\n";
print"The modified array is:";
splice(@a,2,0,'x');
print"@a\n";

13
Exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>prog8.pl
The original array is:a e i o
The modified array is:a e x i o

Part - B
AIM-To use “Splice function on an array then restoring the original array.

LOGARITHM-
1. Print command to print a statement.
2. Using array variable to assign an array.
3. Print command to print array.
4. Using splice function on array.
5. Print command to print spliced array.
6. Splice command to restore the original array.
7. Printing original array using print command.
8. Exit command to end program.

CODE-
#!/usr/bin/perl
print"The original array is:";
@a=('a','e','i','o');
print"@a\n";
print"The modified array is:";
splice(@a,2,3,'g');
print"@a\n";
print"Restoring the original array:";
14
splice(@a,2,1,'i','o');
print"@a\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>8asplice.pl
The original array is:a e i o
The modified array is:a e g
Restoring the original array:a e i o

NOTE-
Splice function (splice)-remove & return a certain number of elements
from an array.
Syntax - splice(@array,offset,length,replacement list)
@array - the array being used
Offset - position at which the element is to inserted
Length - no. of elements to be removed including offset
Replacement list - elements to be placed in place of removed elements

PROGRAM 9
Part - A
AIM-To display “Uppercase” & “Lowercase” function.

LOGARITHM-
1. Assign a string to a scalar variable.
2. Print command to print the above scalar variable.
3. Use another scalar variable to store the above scalar variable after
conversion to uppercase by using uppercase function.

15
4. Print the uppercase scalar variable using print command.
5. Use a third scalar variable to store the above uppercase variable after
conversion to lowercase using lowercase function.
6. Print command to print the third scalar variable.
7. Exit command to end program.

CODE-
#!/usr/bin/perl
$a='atgc';
print"The DNA sequence in lower case is:";
print"$a\n";
$b=uc($a);
print"The DNA sequence in upper case is:";
print"$b\n";
$c=lc($b);
print"The final DNA sequence in lower case is:";
print"$c\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry
C:\Strawberry>9uppercase.pl
The DNA sequence in lower case is:atgc
The DNA sequence in upper case is:ATGC
The final DNA sequence in lower case is:atgc

Part - B
LOGARITHM-
1. Assign a string to a scalar variable.
2. Print command to print the scalar variable.
3. Converting the variable to lowercase using lowercase function.

16
4. Printing the modified variable with print command.
5. Converting the variable to uppercase using uppercase function.
6. Printing the modified uppercase variable by print command.
7. Exit command to end the program.

CODE-
#!/usr/bin/perl
$a='KIIT SCHOOL OF BIOTECHNOLOGY';
print"The name of college is ";
print"$a\n";
$a=lc($a);
print"The name of the college in lower case is ";
print"$a\n";
$a=uc($a);
print"The name of college in upper case is ";
print"$a\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry
C:\Strawberry>9auppercase.pl
The name of college is KIIT SCHOOL OF BIOTECHNOLOGY
The name of the college in lower case is kiit school of biotechnology
The name of college in upper case is KIIT SCHOOL OF BIOTECHNOLOGY

NOTE-
Uppercase function (uc) - used to convert lowercase characters to
uppercase characters.
Lowercase function (lc)-used to convert uppercase characters to
lowercase.
17
PROGRAM 10
AIM-To display the content of “Pop” function in an array.

ALGORITHM-
1. Print command to print a statement.
2. Use array variable to store a array of numbers.
3. Print statement to print the array.
4. Using the pop function.
5. Print command to print statement.
6. Print command to print array after the pop function.
7. Exit command to end program.

CODE-
#!/usr/bin/perl
print"The original array is:";
@a=('1','2','3','4');
print"@a\n";
pop(@a);
print"The array after it is popped:";
print"@a\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry
C:\Strawberry>10pop.pl
The original array is:1 2 3 4
The array after it is popped:1 2 3

NOTE-
18
Pop func.(pop)- removes last element of an array
PROGRAM 11
AIM-To display the content of “Shift” function in an array.

ALGORITHM-
1. Print command to print a statement.
2. Array variable to store a array of numbers.
3. Print statement to print array.
4. Use shift function on the array
5. Print command to print a statement.
6. Print command to print array after shift function.
7. Exit command to end program.

CODE-
#!/usr/bin/perl
print"The original array is:";
@a=('1','2','3','4');
print"@a\n";
shift(@a);
print"The array after it is shifted is ";
print"@a\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry
C:\Strawberry>11shift.pl
The original array is:1 2 3 4
The array after it is shifted is 2 3 4

NOTE-

19
Shift function(shift)-removes first element of an array
PROGRAM 12
AIM-To display the content of “Unshift” function in an array.

ALGORITHM-
1. Print command to print a statement.
2. Array variable to store array of numbers.
3. Print statement to print the array.
4. Scalar variable to store a number.
5. Use unshift function on array.
6. Print command to print array after unshift command.
7. Exit command to end program.

CODE-
#!/usr/bin/perl
print"The original array is:";
@a=('1','2','3','4');
print"@a\n";
$u='0';
unshift(@a,$u);
print "The array after unshift is ";
print"@a\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry
C:\Strawberry>12unshift.pl
The original array is:1 2 3 4
The array after unshift is 0 1 2 3 4

20
Unshift function[unshift(@array,$elements to be inserted)]- inserts
elements at the beginning of an array.
PROGRAM 13
AIM-To display content of “Push” function in an array.

ALGORITHM-
1. Print command to print an array.
2. Array variable to input an array of numbers.
3. Print command to print array.
4. Scalar variable to store a number.
5. Use push command on the array.
6. Print command to print array after push function.
7.Exit command to end program.

CODE-
#!/usr/bin/perl
print"The original array is:";
@a=('1','2','3','4');
print"@a\n";
$r='5';
push(@a,$r);
print"The array after push operation is ";
print"@a\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved

C:\Users\KIIT>cd\

C:\>cd strawberry
C:\Strawberry>13push.pl
The original array is:1 2 3 4
The array after push operation is 1 2 3 4 5

21
Push function[push(@array,$element to be inserted)]-inserts elements at
the end of an array
PROGRAM 14
Part - A
AIM-To arrange an array “WITHOUT” using the Sort function.

ALGORITHM-
1.Array variable to store an array of numbers.
2.Use pop function to remove the last element of array.
3. Use shift function to remove the first element of array.
4. Scalar variable to store a number.
5. Use of unshift function to add a number to start of array.
6. Use of splice function to add elements to the 2nd position in the array.
7. Use of splice function to add elements to the 4th position in the array
and delete the element next to it .
8. Print command to print a statement.
9. Print command to print the arranged array.
10.Exit command to end program.

CODE-
#!/usr/bin/perl
@n=('20','8','17','1','23','13');
pop(@n);
shift(@n);
$a='1';
unshift(@n,$a);
splice(@n,2,0,'13');
splice(@n,4,1,'20');
print"The arranged array is ";
print"@n\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.
22
C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>14test.pl
The arranged array is 1 8 13 17 20 23

Part - B
LOGARITHM-
1. Array variable to input an array of strings.
2. Print command to print a statement.
3. Print command to print the original array.
4. Pop function to remove the last element.
5. Scalar variable to store a string.
6. Unshift command to add a string at beginning of array.
7. Splice command to add two strings and remove two strings from 2nd
position of array.
8. Print command to print the sorted array.
9. Exit command to end program.

CODE-
#!/usr/bin/perl
@a=('London','Paris','NewYork','Sydney','HongKong');
print"The original array is ";
print"@a\n";
pop(@a);
$x='HongKong';
unshift(@a,$x);
splice(@a,2,2,'NewYork','Paris');
print"The sorted array is ";
print"@a\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]

23
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>14atest.pl
The original array is London Paris NewYork Sydney HongKong
The sorted array is HongKong London NewYork Paris Sydney

PROGRAM 15
AIM-To “Read a file” saved in the computer.

LOGARITHM-
1. Print command to print a statement.
2. Use a scalar variable to store the input using standard input device.
3. “Chomp” function to remove white spaces at the beginning of file.
4. Use “open” function to open ‘$file’.
5. Assigning the file to an array variable.
6. Use “close” function to close ‘$file’.
7. Use “join” function to read the file as a single line.
8. Use of substitution operator to remove white spaces present in between
the file.
9.“Split” function to separate out each character of file.
10.Print command to print the input file.
11.Exit command to end program.

CODE-
#!/usr/bin/perl
print"Enter the file:";
$file=<STDIN>;
chomp($file);
open(DNAFILE,$file);
@DNA=<DNAFILE>;
close DNAFILE;
$DNA=join('',@DNA);
24
$DNA=~ s/\s//g;
@DNA=split('',$DNA);
print"@DNA\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>15filehandle.pl
Enter the file:DNA.txt
AAATTTTTGGCCCAATGGCCTGCAATG

NOTE-
<STDIN>-standard input device;device from which input to the system is
taken,it can be specified if the input is to come from a specific disk file.
Chomp function[chomp(variable in which file is stored)]-remove
white spaces from the beginning of the file.
Open function[open(name of file in device,variable in which it is
stored)-to open the file for compiler to read.
Close function[open(name of file in device,variable in which it is
stored)-to close the file.
Join function[join(‘’,variable in which file is stored)]-if the file has
multiple lines then perl compiler will treat it as a single line.
Split function[split(‘’,variable in which file stored)]-separate each
character in a file to make compiler easily read the file.

PROGRAM 16
AIM-To find if a DNA sequence is “GUANINE CYTOSINE rich”.
LOGARITHM-
25
1. Print command to print a statement.
2. Scalar variable to store a file containing DNA sequence located in the
strawberry bin folder, using standard device input.
3. Use of “chomp” function to remove white spaces at the beginning of
DNA sequence.
4. “Open” function to open the DNA sequence.
5. Assigning the file of DNA sequence to an array variable.
6. “Close” function to close file of DNA sequence.
7. Use “Join” function to make the perl compiler read the whole DNA
sequence in file as a single line as the sequence may be written in multiple
lines.
8. Use of substitution operator to remove white space present in between
the DNA sequence.
9. Use of “Split” function to separate each “Nucleotide” of the DNA
sequence for compiler to easily read the file.
10.Print command to print the DNA sequence.
11.Assigning 4 scalar variables(initials of nucleotide in DNA) with value 0.
12.Use of “foreach” to run a loop.
13.Use of bracket({) to mark start of the loop
14.Use of “if” conditional statement to check the given condition.
15.Adding 1 to the scalar variable if condition is true.
16.Use of “elsif” conditional statement to check for a given condition if the
above “if” statement is false
17.Adding 1 to scalar variables according to the conditions.
18.Closing the “foreach” loop using }.
19.Print command to print the values of scalar variables after the
execution of the loop and conditional statements.
20.Scalar variable to store sum of two numbers.
21.Print command to print the scalar variable having sum of two variable.
22.Scalar variable to store the sum of all the scalar variable used in the
conditional statement.
23.Print command to print the above scalar variable.
24.Scalar variable to store percentage of nucleotides in DNA sequence.
25.Print command to print the above percent.
26.Conditional statement “if” to check if the above percent is >=50%.
27.Print command to print a statement if above condition is true.
28.Conditional statement “else” if the “if” statement is false.
26
29.Print command to print statement if “else” is executed.
30.Exit command to end program.

CODE-
#!/usr/bin/perl
print"Enter the file:";
$file=<STDIN>;
chomp($file);
open(DNAFILE,$file);
@DNA=<DNAFILE>;
close DNAFILE;
$DNA=join('',@DNA);
$DNA=~ s/\s//g;
@DNA=split('',$DNA);
print"@DNA\n";
$A=0;
$T=0;
$G=0;
$C=0;
foreach $base(@DNA)
{
if ($base eq 'A')
{
$A++;
}
elsif($base eq 'C')
{
$C++
}
elsif($base eq 'T')
{
$T++
}
elsif($base eq 'G')
{
$G++
}
27
}
print "The no. of A are=$A\n";
print "The no. of C are=$C\n";
print "The no. of T are=$T\n";
print "The no. of G are=$G\n";
$gc=$G+$C;
print"The no. of GC are ";
print"$gc\n";
$total=$A+$C+$T+$G;
print"The total content of base is ";
print"$total\n";
$gc_percent=$gc/$total*100;
print"The GC percent is ";
print"$gc_percent\n";
if ($gc_percent ge '0.5')
{
print "Sequence is GC rich\n";
}
else
{
print "Sequence is not GC rich\n";
}
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>16dna.pl
Enter the file:DNA1.txt
AATTGGGCCCGGAAATTTTTTGGGGCCCATCGCCATTT
AGACCCATGCGGGTTAACC
The no. of A are=12
28
The no. of C are=15
The no. of T are=15
The no. of G are=15
The no. of GC are 30
The total content of base is 57
The GC percent is 52.6315789473684
Sequence is GC rich

NOTE-
Foreach loop- executes a block of statements enclosed within curly
brackets & and sets the control variable (var) to be each element of the
list in turn
Syntax - foreach var (@list) { [statements to be executed ]}
If conditional statement- used to check is a condition is true and
executes a command according to the result
Else conditional statement- executed when the if condition is false
Elsif conditional statement- used to give multiple conditions to check
when the if conditional statement is false and a executed a command if
any of the elsif conditions are true

PROGRAM 17
AIM-To find if a protein sequence is “Hydrophobic rich”.
LOGARITHM-
1.Print command to print a statement.
2.Scalar variable to store a file containing PROTEIN sequence located in
the strawberry bin folder, using standard device input.
3.Use of “chomp” function to remove white spaces at the beginning of
PROTEIN sequence.
4.“Open” function to open the PROTEIN sequence.
5.Assigning the file of PROTEIN sequence to an array variable.
6.“Close” function to close file of PROTEIN sequence.
7.Use “Join” function to make the perl compiler read the whole PROTEIN
sequence in file as a single line as the sequence may be written in multiple
lines.

29
8.Use of substitution operator to remove white space present in between
the PROTEIN sequence.
9.Use of “Split” function to separate each “Amino Acid” of the PROTEIN
sequence for compiler to easily read the file.
10.Print command to print the PROTEIN sequence.
11.Assigning 7 scalar variables (initials of the amino acids) with value 0, to
keep count of the number of the different amino acids in the protein
sequence.
12.Assigning a scalar variable “z” with value 0 to keep count of total
amino acid in the protein sequence.
13.Use of “foreach” to run a loop.
14.Use of bracket({) to mark start of the loop
15.Use of “if” conditional statement to check the given condition.
16.Adding 1 to the scalar variable if condition is true.
17.Use of “elsif” conditional statement to check for a given condition if the
above “if” statement is false
18.Adding 1 to scalar variables according to the conditions.
19.Closing the “foreach” loop using }.
20.Print command to print the values of scalar variables after the
execution of the loop and conditional statements.
21.Using a scalar variable “P” to store sum of all the hydrophobic amino
acids from the scalar variables used to store count of each amino acid.
22.Print command to print count of hydrophobic amino acid and total no
of amino acid.
23.Using scalar variable “percent” to store the percentage of hydrophobic
amino acid in the protein sequence.
24.Print command to print the percentage of hydrophobic amino acid.
25.Using “if” statement to check if the percentage of hydrophobic amino
acid is greater than equal to 50%.
26.Print command to print statement “Sequence is hydrophobic rich” if
condition true.
27.“Else” statement if above condition is false.
28.Print command to print “Sequence Is not hydrophobic rich” if condition
false.
29.Closing the conditional statements.
30.Exit command to end program.

30
CODE-
#!/usr/bin/perl
print"Enter the file:";
$file=<STDIN>;
chomp($file);
open(PROTEINFILE,$file);
@PROTEIN=<PROTEINFILE>;
close PROTEINFILE;
$PROTEIN=join('',@PROTEIN);
$PROTEIN=~ s/\s//g;
@PROTEIN=split('',$PROTEIN);
print"@PROTEIN\n";
$A=0;
$V=0;
$L=0;
$I=0;
$P=0;
$F=0;
$C=0;
$z=0;
foreach $base(@PROTEIN)
{
$z++;
if ($base eq 'A')
{
$A++;
}
elsif ($base eq 'V')
{
$V++;
}
elsif ($base eq 'L')
{
$V++;
}
elsif ($base eq 'I')
{
31
$I++;
}
elsif ($base eq 'P')
{
$P++;
}
elsif ($base eq 'F')
{
$F++;
}
elsif ($base eq 'C')
{
$C++;
}
}
print"The no. of Alanine are=$A\n";
print"The no. of Valine are=$V\n";
print"The no. of Leucine are=$L\n";
print"The no. of Isoleucine are=$I\n";
print"The no. of Proline are=$P\n";
print"The no. of Phenylalanine are=$F\n";
print"The no. of Cystenine are=$C\n";
$P=$A+$V+$L+$I+$P+$F+$C;
print"The total hydrophobic amino acids are=$P\n";
print"The total count of amino acids=$z\n";
$percent=$P/$z*100;
print"The hydrophobic percentage is ";
print"$percent\n";
if ($percent ge 0.5)
{
print"Sequence is hydrophobic rich";
}
else
{
print"Sequence is not hydrophobic rich";
}
exit;
32
OUTPUT
Microsoft Windows [Version 10.0.22000.556]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>17protein.pl
Enter the file:PROTEIN.txt
MGKDDVIESGAGGGEFAAKDYTDPPPAPLIDAAELGSW
SLYRAVIAEFIATLLFLYITVATVIGYKHQTDASASGADA
ACGGVGVLGIAWAFGGMIFVLVYCTAGISGGHINPAVT
FGLFLARKVSLVRALLYIVAQCLGAICGVGLVKAFQSAYF
DRYGGGANSLASGYSRGTGFGAEIIGTFVLVYTVFSATD
PKRNARDSHVPVLAPLPIGFAVFMVHLATIPVTGTGINP
ARSLGAAVIYNKDKPWDDHWIFWVGPLVGAAIAAFYH
QYILRAGAIKALGSFRSNA
The no. of Alanine are=44
The no. of Valine are=49
The no. of Leucine are=0
The no. of Isoleucine are=22
The no. of Proline are=13
The no. of Phenylalanine are=17
The no. of Cystenine are=4
The total hydrophobic amino acids are=149
The total count of amino acids=290
The hydrophobic percentage is 51.3793103448276
Sequence is hydrophobic rich

PROGRAM 18
AIM-If a motif is present in a DNA or PROTEIN sequence.
LOGARITHM-
1.Print command to print a statement.

33
2.Scalar variable to store a file containing PROTEIN/DNA sequence located
in the strawberry bin folder, using standard device input.
3.Use of “chomp” function to remove white spaces at the beginning of
PROTEIN/DNA sequence.
4.“Open” function to open the PROTEIN/DNA sequence.
5.Assigning the file of PROTEIN/DNA sequence to an array variable.
6.“Close” function to close file of PROTEIN/DNA sequence.
7.Use “Join” function to make the perl compiler read the whole
PROTEIN/DNA sequence in file as a single line as the sequence may be
written in multiple lines.
8.Use of substitution operator to remove white space present in between
the PROTEIN/DNA sequence.
9.Use of “Split” function to separate each “Amino Acid” of the
PROTEIN /”Nucleotide” of the DNA sequence for compiler to easily read
the file.
10.Print command to print the PROTEIN/DNA sequence.
11.Scalar variable “motif” to store the motif that needs to be detected in
the DNA/PROTEIN sequence, using standard device input[STDIN].
12.Using “chomp” function to remove white spaces present in the entered
motif.
13.Using “if” statement to check is motif is present in sequence.
14.Print command to print “motif present” if condition true.
15.“Else” statement if the above condition false.
16.Print command to print “motif absent” if condition false.
17.Exit command to end program.

Part - A
CODE-
#!/usr/bin/perl
print"Enter the file:";
$file=<STDIN>;
chomp($file);
open(DNAFILE,$file);
@DNA=<DNAFILE>;
close DNAFILE;
$DNA=join('',@DNA);
$DNA=~ s/\s//g;
34
@DNA=split('',$DNA);
print"@DNA\n";
print"enter the motif\n";
$motif=<STDIN>;
chomp $motif;
if ($DNA=~/$motif/)
{
print"Motif present\n";
}
else
{
print "Motif absent\n";
}
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.675]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>18motif.pl
Enter the file:DNA.txt
AAATTTTTGGCCCAATGGCCTGCAATG
enter the motif
ATG
Motif present
Part - B
CODE-
#!/usr/bin/perl
print"Enter the file:";
$file=<STDIN>;
chomp($file);
open(PROTEINFILE,$file);
@PROTEIN=<PROTEINFILE>;
35
close PROTEINFILE;
$PROTEIN=join('',@PROTEIN);
$PROTEIN=~ s/\s//g;
@PROTEIN=split('',$PROTEIN);
print"@PROTEIN\n";
print"enter the motif\n";
$motif=<STDIN>;
chomp $motif;
if ($PROTEIN=~/$motif/)
{
print"motif present\n";
}
else
{
print "motif absent\n";
}

OUTPUT-
Microsoft Windows [Version 10.0.22000.675]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>18amotif.pl
Enter the file:PROTEIN.txt
MGKDDVIESGAGGGEFAAKDYTDPPPAPLIDAAELGSW
SLYRAVIAEFIATLLFLYITVATVIGYKHQTDASASGADA
ACGGVGVLGIAWAFGGMIFVLVYCTAGISGGHINPAVT
FGLFLARKVSLVRALLYIVAQCLGAICGVGLVKAFQSAYF
DRYGGGANSLASGYSRGTGFGAEIIGTFVLVYTVFSATD
PKRNARDSHVPVLAPLPIGFAVFMVHLATIPVTGTGINP
ARSLGAAVIYNKDKPWDDHWIFWVGPLVGAAIAAFYH
QYILRAGAIKALGSFRSNA
enter the motif
AGA
36
Motif present

PROGRAM 19
AIM- To display content of “Scalar” function.
LOGARITHM-
1. Array variable to store an array.
2. Print command to print the above array.
3. Print command to print a statement.
4. Using a scalar variable to store the length of the array by using the
“scalar” function.
5. Print command to print the length of the array.
6. Exit command to end program.

CODE-
#!/usr/bin/perl
@A=('V','Y','U','E','A');
print"The array is: ";
print"@A\n";
print"The length of the array is ";
$l= (scalar(@A));
print"$l\n";
exit;

OUTPUT-
Microsoft Windows [Version 10.0.22000.675]
(c) Microsoft Corporation. All rights reserved.

C:\Users\KIIT>cd\

C:\>cd strawberry

C:\Strawberry>19length.pl

37
The array is: V Y U E A
The length of the array is 5

NOTE-
Scalar function(scalar)- used to find the length of an array
Syntax - (scalar(@[the array whose length is to be found]))
END

38

You might also like