This tutorial outlines the basics concepts in computer science such as variables, operators, selecting/iteration, pseudo code and regular expressions.
Learning outcomes
- Recognise data types and variables
- Describe arithmetic, relational and logic operators
- Execute selection and iteration workflows
- Express algorithms in pseudocode
- Implement regular expressions
Prerequisites
It is recommended that you have Notepad++ (Windows) or BBEdit (Mac) for the regular expressions tasks; most default Linux editors can do these.
Approximate time to finish tutorial
- Lecture: 1.5 hours
- Tasks within lectures: 1 hour
- Additional advanced tasks: 1 hour
- Pre/post surveys: 10 minutes
Order of tutorial
Please do the pre-learning quiz, then watch the presentation.
During the presentation there are points to stop and do exercises, which are linked below. The answers to the questions in the exercises are linked within each one.
Once finished the tutorial, take the post-learing quiz.
Concepts in Computer Programming Pre-tutorial Survey
Presentation slides
Concepts in Computer Programming Post-tutorial Survey
Tasks from slides with sample answers
Sequence and iteration
- Initialise a variable with a certain real value. Write a statement that will add 10 to the variable if it is less than 10 and divide the variable by 10 if it is greater than or equal to 10
Click here for answer
- Write a for loop that will iterate from 1 to 10 and at each stage get the modulus 2 of the variable
Click here for answer
- Initialise a variable to be value 1. Write a while loop that continues until that variable is 100. Inside the loop, if the number is less than 10, get the number to the power of itself. If it is between 10 and 50, take away 5 from the number. If it is above 50, add 1 to the number
Click here for answer
* Note: the algorithm is worded ambiguously where it states 'between 10 and 50' and should be more specific saying "between 10 and 50 included" or similar. * This is specifically like this to make you think about ambiguity * Note 2: This loop will actually never finish because the first step of the loop is 1^1 which is 1, so it will never increase and thus run forever. * This is specifically done to make you think about covering all scenarios. Probably best to start at 2 or add a clause to capture such casesPseudocode
- Ask the user for 2 numbers and print out their product (i.e. multiply them together)
Click here for answer
- Read in a string of letters and check if it is a valid DNA string
Click here for answer
- Check if a string conforms to the pattern “patient_000000” where the 6 digits can be any numbers between 0-9
- Hint: use phrases like ‘starts with’, ‘ends with’, ‘followed by’
Click here for answer
- Do the following steps
- Read in 5 separate numbers
- Calculate the average of the five numbers
- Find the smallest (minimum) and largest (maximum) of the five entered numbers.
- Write out the three results found with a message describing what they are
Click here for answer
Regular expressions
These should be done in Notepad++ or BBEdit Create a file with the following content:
>seq1
ACTGC
>seq2
AACTG
>seq3
TTTCC
>seq4
AACCC
- Find all sequence names (i.e. seq followed by a number)
- Sequence names are lines that begin with >
Click here for answer
- Find the first nucleotide of each sequence
Click here for answer
- Replace all ‘seq’ in sequence names with ‘sample’
- Sequence names are lines that begin with >
Click here for answer
- Add a tab character followed by ‘function’ to the end of each sequence name
Click here for answer
- Find an AA at the start of a line and move it to the end of the line
Click here for answer
Additional (advanced) tasks
- Write pseudocode that will check if a year is a leap year
- Write pseudocode to search a fasta file for every occurrence of a specific DNA motif
- In a file of bacterial species names, change the full name (e.g. Mycobacterium tuberculosis) to the shortened name (e.g. M. tuberculosis), no matter what the species name is