Bash exercise using GitHub’s codespace
Follow the instructions below to complete this exercise, and put your answers to the questions into the Exercise 2 quiz on Canvas.
Your project repository
Make your copy and open your codespace
Go to the Comp Bio project template on GitHub, and follow the instructions in its README under the following two sections ONLY:
- “Make your own copy of this repository”: Name your repository
bash-intro, and choose Public - “Open your codespace”: When you get a “Do you trust the authors of the files in this folder?” pop-up, click “Trust Folder & Continue”
Stop and come back here once you get to “Set up your project environment” (don’t set up the environment; we don’t need it for this exercise).
- “Make your own copy of this repository”: Name your repository
Once your codespace is ready, you should see your files on the left side of VS Code and a terminal at the bottom. Click in the terminal and check that you’re in your project’s folder:
Terminal
pwd ls -apwd(print working directory) tells you what directory (“folder”) you are in, which should be/workspaces/comp-bio-project. This folder you are in is called your working directory.ls -alists all files and directories in your working directory. When you run this command, you should seeREADME.mdand a folder named.devcontainer(plus a folder named.git; more on that below).
The terminal is the Bash command line running on a Linux computer in the cloud. All of the commands in this exercise are typed in the terminal.
Creating a new directory and copying files into it
Using the terminal, navigate to your home directory:
Terminal
cd ~Create a new directory called “exercise2”
Terminal
mkdir exercise2Use the
curlcommand to download ananswer1.txtfile from our class GitHub repo into your newexercise2directory:Terminal
curl -L -o exercise2/answer1.txt https://raw.githubusercontent.com/phyletica/intro-to-comp-bio/refs/heads/main/notebooks/data/answer1.txtUse the
curlcommand again to download theSARS-CoV-2.fastafile from our class GitHub repo into your newexercise2directory:Terminal
curl -L -o exercise2/SARS-CoV-2.fasta https://raw.githubusercontent.com/phyletica/intro-to-comp-bio/refs/heads/main/notebooks/data/SARS-CoV-2.fastaNow, move into the “exercise2” directory and confirm the files you downloaded are there:
Terminal
cd exercise2 ls
Question 1
Use the command line (terminal) to see what is in the answer1.txt file. Enter what you find in the file into Question 1 of the Exercise 2 quiz on Canvas.
- Hint: The commands
catorlesswould be useful. I would normally encourage you to use themancommand to learn more about these commands, butmandoesn’t work by default in GitHub’s Codespaces. As an alternative, go to the Linux man pages online and use the search bar near the bottom of the page to search for the commandscatandless.
Your GitHub codespace is temporary. It stops on its own after 30 minutes of inactivity, and GitHub deletes codespaces that haven’t been used for 30 days, even if they contain work you haven’t pushed to GitHub. Your work is only safe once you have committed it and pushed it to GitHub (you’ll learn how in Part 1).
Manipulating sequence data
The “SARS-CoV-2.fasta” file contains nucleotide sequence data from different strains of the SARS-CoV-2 virus. The sequences are in a format called FASTA. The FASTA format looks like:
>Name1
AATCGGCTA
>Name2
ATTCGCCTA
Question 2
Use the command line to determine the number of sequences in the “SARS-CoV-2.fasta” file.
Notice all sequences start with a “>” character to specify the seqence’s name. We can use that to count the sequences efficiently. Try:
Terminal
grep ">" SARS-CoV-2.fastaNOTE: Putting quotes around the
>character is important, because in the Bash language, this character is normally used to redirect output!grepis a very useful command for finding string patterns. You can learn more about it by searching forgrepat the Linux man pages online.grepworks okay for this small FASTA file, but what if there were 1000s of sequences in the file? You wouldn’t want to count them “by hand!”We can use the
wccommand (word count) for counting the sequences. Try:Terminal
grep ">" SARS-CoV-2.fasta | wc -lThe pipe (
|) character converts, or “pipes”, the output of one command to input to another command.wc -lwill count the number of lines output bygrep
Put the number of sequences into Question 2 of the Exercise 2 quiz on Canvas.
Question 3
What does the -l flag in the wc -l do? Hint: use the Linux man pages online to find out!
Question 4
What is your output for the following command?
Terminal
whoamiQuestion 5
What is your output for the following command?
Terminal
echo $MACHTYPEQuestion 6
What is your output for the following command?
Terminal
uname -aQuestion 7
What does the -a flag do in the uname -a command? Hint: use the Linux man pages online to find out!