Shared Flashcard Set

Details

Perl
Beginning Perl for Bioinformatics
43
Computer Science
Undergraduate 1
03/29/2011

Additional Computer Science Flashcards

 


 

Cards

Term
English
Definition
Perl
Term
what is the binding operator
Definition
"=~"
Term
what does the binding operator mean
Definition
apply the operation on the right to the string on the left
Term
what is an array
Definition
variable that stores multiple scalars
Term
test for string equality
Definition
eq
Term
test for numerical equality
Definition
"=="
Term
what should you always do with systems calls
Definition
check for failure e.g. when trying to open a file, always check that the filename exists using unless loop
Term
what does this mean
/^\s*$/
Definition
regular expression //
^ from the beginning of the string
\s : whitespace, tab, newline, formfeed
* is zero or more times there
$ to the end of the string
Term
$MATCH
Definition
$& the string matched by the last successful pattern match
Term
simple pattern match
Definition
$sequence =~ /$motif/
**This returns a boolean**
the result is given by $&
Term
quickest count
Definition
$A = ($sequence =~ tr/Aa//);
Term
count A's in sequence using a while loop
Definition
while ($sequence =~ /a/ig) {
$A++;
}
** i means case insensitive
++ g means global - i.e. stop when you get to end of sequence
Term
@_
Definition
within a subroutine the array @_ contains the parameters that were passed to the subroutine
Term
naming your arguments in a subroutin
Definition
my($dna, $protein, $gene_name) = @_;
Term
$0
Definition
is the name of the program in question
Term
# read in the DNA from the command line
Definition
my($DNA) = $ARGV[0];
Term
@ARGV
Definition
contains the command line arguments intended for the script
Term
$ARGV[0]
Definition
first argument from command line arguments NOT the programs name
Term
subroutine with multiple arguments
Definition
sub routine() {
my($scalar, $array, $hash) = @_;
$$scalar++;
join(@$array);
join(%$hash);
return blah;
}
** NB changes to arguments in subroutine are carried into main routine
Term
call this subroutine
Definition
routine(\$scalar, \@array, \%hash);
Term
grep function
Definition
@LIST = grep(EXPRESSION, @ARRAY);

Perl's grep() function runs a regular expression on each element of an array, and returns only the elements that evaluate to true.

@myNames = ('Jacob', 'Michael', 'Joshua', 'Matthew', 'Alexander', 'Andrew');
@grepNames = grep(!/^A/, @myNames);

In the above example, the regular expression is looking for any value that does not start with a capital A. After sifting through the contents of the @myNames array, the value of @grepNames becomes ('Jacob', 'Michael', 'Joshua', 'Matthew').
Term
length string
Definition
$ice="cold";
$length_ice = length ($ice);
Term
the substring function
Definition
$portion = substr($string_variable, start number, length);
Term
three things to remember about modules
Definition
1. suffix is .pm
2. when they are CALLED the suffix is not used: use BegPerlBioinformatics
3. the last line in the module must be 1;
Term
declare array
Definition
my @array = ('a','b','c');
Term
seed a random number generator
Definition
srand(seed);
Term
current time
Definition
time
Term
give the number of elements in an array
Definition
scalar @array
Term
remove the fractional part of the number $number
Definition
int($number)
Term
return a random number greater than 0 and less than $number
Definition
rand($number)
Term
add $sentence to $story
Definition
$story .= $sentence;
Term
a popular way to pick a perl seed
Definition
time|$$
(combining the time and the ID of the perl programme that is currently running
Term
do-until loops
Definition
do {} until ();
Term
specific element if an array
Definition
$array[int]
Term
code for random element in an array
Definition
$array[int rand scalar @array]
Term
really fast code for random element in an array
Definition
$array[rand @array]
Term
what do you need to remember before calling rand
Definition
to seed srand beforehand
Term
random position in a string
Definition
int(rand(length($string)))
which is the same as
int rand length $string
Term
in a string replace char at position $position with $newchar
Definition
substr($string, $position, 1, $newchar);
Term
initialise an empty array
Definition
my @array = ();
Term
what does the push function do
Definition
Perl's push() function is used to push a value or values onto the end of an array, which increases the number of elements. The new values then become the last elements in the array.
push(@array,$string)
Term
turn a decimal into a percent
Definition
int($number*100)
Term
how to select all combinations of two elements from a set:
Definition
Nested loop:
for (my $i=0; $i<10; $i++) {
for (my $j = $i+1; $j<10; $j++) {
}
}
Supporting users have an ad free experience!