Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
1,060 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
>seq1 | ||
ATGGCGTCTTGGCCTTAAAAGCTC | ||
>seq2 | ||
ATGGCGTCTTGGCCTTAAAAGCTC | ||
>seq3 | ||
ATGGCGTCTTGGCCTTAAAAGCTC | ||
>seq4 | ||
ATGGCGTCTTGGCCTTAAAAGCTC |
50 changes: 50 additions & 0 deletions
50
lecture_scripts/problem_solutions/set_1_1/unix_commands.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Log into your machine or account. What is the full path to your home directory? | ||
> pwd | ||
How many files does it contain? | ||
## look for names that do not end with "/" | ||
> ls -F | ||
How many directories? | ||
## look for names that end with "/" | ||
> ls -F | ||
|
||
Without using a text editor examine the contents of the file sequences.fasta. | ||
How many lines does this file contain? | ||
> wc -l sequences.fasta | ||
How many characters? | ||
> wc -c sequences.fasta | ||
What is the first line of this file? | ||
> head -1 sequences.fasta | ||
What are the last 3 lines? | ||
> tail -3 sequences.fasta | ||
How many sequences are in the file? | ||
## grep will only print the lines that contain ">" in the file (headers) | ||
## pipe the result to "wc -l" to count the number of lines | ||
> grep ">" sequences.fasta | wc -l | ||
|
||
Rename sequences.fasta to something more informative of the sequences the file contains. | ||
> mv sequences.fasta my_random_sequences.fasta | ||
|
||
Create a directory called fasta | ||
> mkdir fasta | ||
|
||
Copy the fasta file that you renamed to the fasta directory | ||
> cp my_random_sequences.fasta fasta | ||
|
||
Verify that the file is within the fasta directory | ||
## you can visually inspect the output from "ls fasta/" or use | ||
## "ls fasta/my_random_sequences.fasta" directly to see if the file | ||
## is there - if it lists, it's fine, otherwise it will given an error | ||
> ls fasta/my_random_sequences.fasta | ||
|
||
Delete the the original file that you used for copying | ||
> rm my_random_sequences.fasta | ||
|
||
Copy a directory | ||
## copy "fasta" directory and its contents to "fasta_copy" | ||
## the "-r" flag tells "cp" to copy recursively | ||
> cp -r fasta fasta_copy | ||
|
||
Remove a directory | ||
## remove the "fasta" directory and its contents | ||
## the "-r" flag tells "rm" to copy recursively | ||
> rm -r fasta |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/perl | ||
## add.pl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
##first value - get it from the command line arguments | ||
my $value1 = shift; | ||
|
||
## second value - get it from the command line arguments | ||
my $value2 = shift; | ||
|
||
## add the two numbers | ||
my $sum = $value1 + $value2; | ||
|
||
## print the sum of the two numbers | ||
print $sum, "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/perl | ||
## reversec.pl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
## get the sequence from the arguments | ||
my $sequence = shift; | ||
|
||
## reverse the sequence | ||
my $reverse_sequence = reverse $sequence; | ||
|
||
## complement the reverse sequence | ||
## tr/// modifies the content of the string directly so we'll first make a copy | ||
my $reverse_complement_sequence = $reverse_sequence; | ||
## now complement the reverse sequence | ||
$reverse_complement_sequence =~ tr/ACGT/TGCA/; | ||
|
||
## print the reverse complemented sequence | ||
print "output: $reverse_complement_sequence\n"; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/perl | ||
## add.pl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
##first value - get it from the command line arguments | ||
my $value1 = shift; | ||
|
||
## second value - get it from the command line arguments | ||
my $value2 = shift; | ||
|
||
## check that both values are defined | ||
if (not defined $value1 or not defined $value2) { | ||
print "Please provide two numbers.\n"; | ||
} | ||
## check that both values are positive numbers | ||
elsif ($value1 < 0 or $value2 < 0) { | ||
print "Please provide two positive numbers.\n"; | ||
} | ||
## only run the rest of the program if the values are OK | ||
|
||
else { | ||
|
||
## add the two numbers | ||
my $sum = $value1 + $value2; | ||
|
||
## print the sum of the two numbers | ||
print $sum, "\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/perl | ||
## even_odd.pl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
## create file myresult.txt and open it for writing output | ||
open OUT, ">", "myresult.txt" or die "Error writing to file: $!\n"; | ||
|
||
## open numbers.txt for reading | ||
open IN, "<", "numbers.txt" or die "Error reading file: $!\n"; | ||
|
||
## read each line in the file | ||
while (my $number = <IN>) { | ||
|
||
## remove the newline | ||
chomp $number; | ||
|
||
## check if the number is even -- we can use the modulus operator to see | ||
## the remainder when the number is divided by 2; if it's 0, then it's | ||
## even | ||
if ($number % 2 == 0) { | ||
|
||
## check whether the number is less than 24 | ||
if ($number < 24) { | ||
|
||
## print the number | ||
print "$number\n"; | ||
} | ||
|
||
} | ||
## odd number | ||
else { | ||
|
||
## compute the factorial of the number | ||
my $factorial = 1; | ||
## go through each value from $number down to 1 | ||
for (my $i = $number; $i > 0; $i--) { | ||
## multiply the existing result by the new lower number | ||
$factorial *= $i; | ||
} | ||
|
||
## print the factorial | ||
print OUT "$factorial\n"; | ||
|
||
} | ||
|
||
} | ||
|
||
## close the file handles | ||
close IN; | ||
close OUT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
1.1962222086548e+56 | ||
1 | ||
8.22283865417792e+33 | ||
120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
22 | ||
45 | ||
1 | ||
2 | ||
31 | ||
32 | ||
72 | ||
24 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/perl | ||
## order.pl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
## get the first argument | ||
my $string1 = shift; | ||
|
||
## get the second argument | ||
my $string2 = shift; | ||
|
||
## check that $string1 is "less than or equal" $string2 (already ordered) | ||
if ($string1 le $string2) { | ||
print "right order\n"; | ||
} | ||
## otherwise $string1 is "more than" $string2 | ||
else { | ||
print "wrong order\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/perl | ||
## pali.pl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
## get the string argument | ||
my $string = shift; | ||
|
||
## lowercase $string so that comparisons are case insensitive | ||
my $lower_case_string = lc $string; | ||
|
||
## remove whitespace from the string | ||
## we want to apply the substitution globally to remove ALL occurences | ||
## since s/// works on the string itself, we'll first make a copy | ||
my $lower_case_clean_string = $lower_case_string; | ||
## we can use s/// to remove the whitespace | ||
$lower_case_clean_string =~ s/\s//g; | ||
## we can remove all non alphanumerical characters | ||
$lower_case_clean_string =~ s/\W//g; | ||
|
||
## get the reverse of the string | ||
my $reverse_lower_case_clean_string = reverse $lower_case_clean_string; | ||
|
||
## check that forward and reverse strings are the same - if they're the same, we have a palindrome | ||
if ($lower_case_clean_string eq $reverse_lower_case_clean_string) { | ||
print "yes!\n"; | ||
} | ||
## otherwise the strings aren't the same | ||
else { | ||
print "no!\n"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/perl | ||
## percent.pl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
## get the first number argument | ||
my $number1 = shift; | ||
|
||
## get the second number argument | ||
my $number2 = shift; | ||
|
||
## check that the sum of the two numbers does not equal to 0 | ||
if ($number1 + $number2 != 0) { | ||
## calculate the percentage | ||
my $percentage = $number1 / ($number1 + $number2) * 100; | ||
## use printf to print a nicely formatted percentage | ||
printf "%.2f%%\n", $percentage; | ||
} | ||
## otherwise the sum equals to 0 | ||
else { | ||
print "You are trying to trick me!\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/perl | ||
## reorder.pl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
## get the first argument | ||
my $string1 = shift; | ||
|
||
## get the second argument | ||
my $string2 = shift; | ||
|
||
## if $string1 is "less than or equal" $string2 (already ordered) | ||
if ($string1 le $string2) { | ||
print "$string1 $string2\n"; | ||
} | ||
## otherwise $string1 is "more than" $string2 (swap them) | ||
else { | ||
print "$string2 $string1\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/perl | ||
## same.pl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
## prompt user for the first string | ||
print "Enter string 1: "; | ||
## get the first string from the user input | ||
my $string1 = <>; | ||
|
||
## prompt user for the second string | ||
print "Enter string 2: "; | ||
## get the second string from the user input | ||
my $string2 = <>; | ||
|
||
## make both $string1 and $string2 lower case so that the comparison is | ||
## case insensitive | ||
my $lower_case_string1 = lc $string1; | ||
my $lower_case_string2 = lc $string2; | ||
|
||
## check to see if $lower_case_string1 and $lower_case_string2 are "equal" | ||
if ($lower_case_string1 eq $lower_case_string2) { | ||
print "same\n"; | ||
} | ||
## otherwise they're different | ||
else { | ||
print "different\n"; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/perl | ||
## divide.pl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
## get the first number argument | ||
my $dividend = shift; | ||
|
||
## get the second number argument | ||
my $divisor = shift; | ||
|
||
## if both arguments have not been provided, bail out | ||
die "Two numbers are required\n" if not defined $dividend or not defined $divisor; | ||
|
||
## if both numbers are not positive, bail out | ||
die "Both numbers have to be positive\n" if $dividend < 0 or $divisor < 0; | ||
|
||
## if divisor is 0, bail out | ||
die "Divisor cannot be zero\n" if $divisor == 0; | ||
|
||
## calculate the quotient | ||
my $quotient = $dividend / $divisor; | ||
|
||
## print quotient | ||
print "$quotient\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/perl | ||
## line_length.pl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
## get the filename argument | ||
my $file = shift; | ||
|
||
## total length of the file | ||
my $total_length = 0; | ||
|
||
## number of lines in the file | ||
my $number_of_lines = 0; | ||
|
||
## open a filehandle to access the file | ||
open IN, "<", $file or die "Error reading $file: $!\n"; | ||
|
||
## read each line of the file | ||
while (my $line = <IN>) { | ||
|
||
## remove the newline | ||
chomp $line; | ||
|
||
## add to the count of lines | ||
$number_of_lines++; | ||
|
||
## get the length of the line | ||
my $length = length $line; | ||
|
||
## print the length of the line to STDOUT | ||
print "Line length for line $number_of_lines: $length\n"; | ||
|
||
## add to the total length of the file up to this line | ||
$total_length += $length; | ||
} | ||
|
||
## calculate the average line length | ||
my $average_line_length = $total_length / $number_of_lines; | ||
|
||
## print the average line length to STDOUT | ||
print "Average line length: $average_line_length\n"; | ||
|
||
## close filehandles | ||
close IN; |
Oops, something went wrong.