#!/usr/bin/perl -w # Autor: Lea Scheer # Datum: 25.01.2021 # Dieses Programm gibt die Anzahl an Gyanin, Cytosin, Thymin und Adenin einer eingegebenen Primersequenz an, # berechnet GC- und AT-Gehalt, die Schmelz- und Annelingtemperatur # Speichert alles in der Datei "primersequenz.txt" #################################### # Eingabe #Aufforderung zur Eingabe der Primersequenz in 5'->3' Richtung print "Bitte geben Sie ihre Primersequenz in 5'->3' Richtung an:"; print "\t"; # Verarbeitung # Deklarieren und Zuordnen der eingegebenen Primersequenzenz einer Variablen chomp ($primer = <STDIN>); # Deklarieren und Zuordnen einer Variablen um Ursprungssequenz nicht zuverändern $primer_anzahl = $primer; # Länge des Primers berechnen $length_primer = length $primer; # Anzahl an Gyanin angeben $anzahl_g = ($primer_anzahl =~ s/g/g/gi); # Anzahl an Cytosin angeben $anzahl_c = ($primer_anzahl =~ s/c/c/gi); # Anzahl an Thymin angeben $anzahl_t = ($primer_anzahl =~ s/t/t/gi); # Anzahl an Adenin angeben $anzahl_a = ($primer_anzahl =~ s/a/a/gi); # GC-Gehalt berechnen $gc_gehalt = ($anzahl_g + $anzahl_c)/($anzahl_t + $anzahl_a + $anzahl_g + $anzahl_c) *100; # AT-Gehalt berechnen $at_gehalt = ($anzahl_a + $anzahl_t)/($anzahl_g + $anzahl_c + $anzahl_a + $anzahl_t) *100; # Schmelztemperatur berechnen $schmelz_temp = 4*($anzahl_g + $anzahl_c) + 2*($anzahl_a + $anzahl_t); # Annelingtemperatur berechnen $anneling_temp = $schmelz_temp -2; # Speichern der Informationen in der Datei "primersequenz.txt" # öffnen der Datei FILE-Handle open (FILE, ">primersequenz.txt"); # Ablegen der Informationen zum Primer in der Datei "primersequenz.txt" print FILE "\n"; print FILE "Die von Ihnen eingegebene Primersequenz lautet:\t$primer"; print FILE "\n\n"; print FILE "Über den Primer lässt sich folgendes sagen:"; print FILE "\n"; print FILE "Länge: \t $length_primer Basen"; print FILE "\n"; print FILE "Anzahl an Gyanin:\t$anzahl_g"; print FILE "\n"; print FILE "Anzahl an Cytosin:\t$anzahl_c"; print FILE "\n"; print FILE "Anzahl an Thymin:\t$anzahl_t"; print FILE "\n"; print FILE "Anzahl an Adenin:\t$anzahl_a"; print FILE "\n"; print FILE "GC-Gehalt: \t$gc_gehalt%"; print FILE "\n"; print FILE "At-Gehalt: \t$at_gehalt%"; print FILE "\n"; print FILE "Schmelztemperatur:\t$schmelz_temp°C"; print FILE "\n"; print FILE "Annelingemperatur:\t$anneling_temp°C"; print FILE "\n"; # Schliesen der Datei FILE-Handle close FILE; # Ausgabe # Ausgabe der eingegebenen Primersequenz print "\n"; print "Die von Ihnen eingegebene Primersequenz lautet:\t$primer"; # Ausgabe der Informationen des Primers print "\n\n"; print "Über den Primer lässt sich folgendes sagen:"; print "\n"; # Laenge print "Länge: \t $length_primer Basen"; print "\n"; # Anzahl einzelnen Basen print "Anzahl an Gyanin:\t$anzahl_g"; print "\n"; print "Anzahl an Cytosin:\t$anzahl_c"; print "\n"; print "Anzahl an Thymin:\t$anzahl_t"; print "\n"; print "Anzahl an Adenin:\t$anzahl_a"; print "\n"; # GC-Gehalt print "GC-Gehalt: \t$gc_gehalt%"; print "\n"; # AT-Gehalt print "At-Gehalt: \t$at_gehalt%"; print "\n"; # Schmelz- und Annelingtemperatur print "Schmelztemperatur:\t$schmelz_temp°C"; print "\n"; print "Annelingemperatur:\t$anneling_temp°C"; print "\n\n"; #Info über Speicherung print "All diese Informationen wurden in der Datei primersequenz.txt gespeichert"; # Beenden des Algorihmus exit;
Write, Run & Share Perl code online using OneCompiler's Perl online compiler for free. It's one of the robust, feature-rich online compilers for Perl language, running on the latest version 5.22.1. Getting started with the OneCompiler's Perl compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Perl
and start coding.
OneCompiler's Perl online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Perl program which takes name as input and prints hello message with your name.
my $name = <STDIN>;
print "Hello $name.\n";
Perl(Practical Extraction and Report Language) is especially desined for text processing by Larry Wall.
There is no need to specify the type of the data in Perl as it is loosely typed language.
Type | Description | Usage |
---|---|---|
Scalar | Scalar is either a number or a string or an address of a variable(reference) | $var |
Arrays | Array is an ordered list of scalars, you can access arrays with indexes which starts from 0 | @arr = (1,2,3) |
Hash | Hash is an unordered set of key/value pairs | %ul = (1,'foo', 2, 'bar) |
In Perl, there is no need to explicitly declare variables to reserve memory space. When you assign a value to a variable, declaration happens automatically.
$var-name =value; #scalar-variable
@arr-name = (values); #Array-variables
%hashes = (key-value pairs); # Hash-variables
If, If-else, Nested-Ifs are used when you want to perform a certain set of operations based on conditional expressions.
if(conditional-expression){
//code
}
if(conditional-expression){
//code if condition is true
}else{
//code if condition is false
}
if(condition-expression1){
//code if above condition is true
}else if(condition-expression2){
//code if above condition is true
}
else if(condition-expression3){
//code if above condition is true
}
...
else{
//code if all the conditions are false
}
There is no case or switch in perl, instead we use given and when to check the code for multiple conditions.
given(expr){
when (value1)
{//code if above value is matched;}
when (value2)
{//code if above value is matched;}
when (value3)
{//code if above value is matched;}
default
{//code if all the above cases are not matched.}
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
// code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Sub-routines are similar to functions which contains set of statements. Usually sub-routines are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
sub subroutine_name
{
# set of Statements
}
subroutine_name();
subroutine_name(arguments-list); // if arguments are present