Difficulty: beginner
Estimated Time: 10-15 minutes

In this tutorial we will be learning how to open and search files. We will be concentrating on fastq files because who doesn't love bioinformatics? <3

For the uninitiated fastq is a popular format for storing DNA sequences. You can read about this format here.

Note:

Commands can be transcribed from the left to the terminal on the right or clicked.

If clicked, the command will be run in the terminal on the right and you will see the results straight away.

Always try to type these commands yourself as this will make it easier to get the hang of it!

We will be covering:

  • How to print a file to your screen
  • How to print the first/last part of files to your screen
  • How to do line counts, word counts etc of a file
  • How to create new files from the output of commands (> and >>)
  • How to be a bioinformatician pipe (|) like a pro
Command Description
pwd Print your working directory
ls List the contents of a particular path
man Find and open the man page for a command
cat Concatenate files and print them to screen
head Output the first part of files to screen
tail Output the last part of files to screen
wc Print counts of lines, words and bytes for files

Amber Wright

Things we've covered:

  • How to print a file to your screen
  • How to print the first/last part of files to your screen
  • How to do line counts, word counts etc of a file
  • How to create new files from the output of commands (> and >>)
  • How to be a bioinformatician pipe (|) like a pro
Command Description
pwd Print your working directory
ls List the contents of a particular path
man Find and open the man page for a command
cat Concatenate files and print them to screen
head Output the first part of files to screen
tail Output the last part of files to screen
wc Print counts of lines, words and bytes for files
seq Print a list of numbers

Now you're ready to do other things!

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Tutorial 4: Reading files again

Step 1 of 5

Step 1: Reading a file

hello

Like in tutorial 1, let's check where we are and what is in our directory;

pwd

ls

These commands should show that we are in:

/home/scrapbook/tutorial

And in this folder we have two files: sample.fastq and small_file.txt

These are files that we will be playing with during this tutorial. The fastq file is copied from the fastq example on wikipedia.

Let's read these files! We will be using a program called cat. This program concatenates files and prints them onto your screen. Let's give it a go:

cat sample.fastq

You will see that the file contains 5 reads which are suspiciously similar to one another (with the exception of the ID line).

Now let's check out small_file.txt

cat small_file.txt

Let's open the man page for cat (remember you can leave the man page by typing q):

man cat

NAME         
       cat - concatenate files and print on the standard output
SYNOPSIS
       cat [OPTION]... [FILE]...

q

OK, so this is telling us that you can run cat with any number of optional arguments followed by any number of filepaths. It also means you can run cat with no arguments at all!

Let's give multiple files a go - what do you think will happen?

cat small_file.txt small_file.txt

first line
second line
third line
fourth line
fifth line
first line
second line
third line
fourth line
fifth line

It just prints (or cats) the contents of the two files one after the other.

Now how about running cat on its own?

cat

Hmm, nothing is going? The command isn't ending? How do we stop it?

ctrl + c

This will interrupt this command - what was happening? It was waiting for some input to cat to screen. We will talk about this later in this tutorial so keep this question in your mind!

Questions

  1. Print to screen sample.fastq twice in one command.
    Answer cat sample.fastq sample.fastq