0% found this document useful (0 votes)
9 views

Lab04

Uploaded by

ixvvy1012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Lab04

Uploaded by

ixvvy1012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Qatar University CMPS 101: Intro.

to CS
College of Engineering Lab. Section
Department of Computer Science & Engineering Fall 2024

Linux Lab for Bioinformatics#04


Obj ectives

• Soft & Hard Links


• The SWAP hidden File; problem and solution
• Pipe & Redirection
• Practical application; convert fastq file to a text file with only DNS sequences.

RegEx Syntax

1. Enclose within single quotation


2. Use the forward slash as delimiter
3. Use the backslash to configure a special character
4. Use the operation, d (delete), s (search-and-replace), a (add), and p (print)
5. Use any of the following metacharacters. If it is non-special, then add the escape (backslash)
character.

Metacharacters Special? Description


1 . Yes Matches with any single character
2 ? No Matches 0 or 1 times only
3 * Yes Matches 0 or more times
4 + No Matches 1 or more times
5 ^ Yes matches the beginning of the line.
6 $ Yes matches the end of the line.
7 {N} No Matches exactly N times
8 [abc] Yes Matches only of the characters
9 | No Matches either/or

Preparation

1. Create a new directory, name as lab04 → mkdir lab04


2. With the cd (change directory) command, switch to this new directory →cd lab04
3. Inside lab04 directory, create two sub-directories; dir1 and dir2
4. Execute the tree command to verify the contents of lab04 directory. It should be empty.

Page 1 of 5
CMPS 101 / Lab Section / Fall 2024 / © Amelle Bedair
Task#1: Har d Linked Files

Note: For all commands, never move out from lab04 directory, it should always be the working
directory, i.e. never use the cd command again.

1. Run vim hello.txt command. In the editor, enter the “Hello” and “How are you”, each on a
separate line. Then, save and close
vim dir1/hello.txt
2. Run the tree command

3. List the properties of the hello.txt file. How much is the link count?

ls -l dir1 # List the contents of dir1


total 4
-rw-r--r-- 1 [owner-name] [group-name] [file-size] [date & time] . . .
Note:
• On the 1st line, the number that appears after the word "total" indicates the total
number of blocks used by the files and directories listed in that directory. These blocks
represent the amount of disk space used by the files in the directory (in units of 512-byte-
per-blocks by default, though this can vary depending on the file system).
• On the 2nd line, after the file permission, the number represents the count of hard links to
the file or directory, i.e. the link count. When you see that this number is 1, it means that
the file has only one hard link, which is the default when the file is first created.

4. In dir2 directory, create a hard-link to the hello.txt

ln dir1/hello.txt dir2/

5. Run the tree command

6. List the properties of the dir1/hello.txt file. How much is the link count?

ls -l dir1 # List (in long format) the contents of dir1


total 4
-rw-r--r-- 2 [owner-name] [group-name] [file-size] [date & time] . . .

Page 2 of 5
CMPS 101 / Lab Section / Fall 2024 / © Amelle Bedair
7. List the properties of the dir2/hello.txt file. How much is the link count?

ls -l dir2 # List (in long format) the contents of dir2


total 4
-rw-r--r-- 2 [owner-name] [group-name] [file-size] [date & time] . . .

8. Show the contents of hello.txt file in directory dir2


$ cat dir2/hello.txt
Hello
How are You?

9. With the Vim editor, add the “Have a nice day” line to the hello.txt located in dir1 directory.
Save and close.

10. Display the contents of both hello.txt files

cat dir1/hello.txt
cat dir2/hello.txt

Observation: Same output

11. With the Vim editor, add "===========" at the top and bottom lines to the hello.txt located in
dir2 directory. Save and close.

12. Display the contents of both hello.txt files. Are they identical?

cat dir1/hello.txt
cat dir2/hello.txt

Task#2: The SWAP Hidden File

1. With Vim, create the bad.txt file. Type your name and hit Ctrl+ZZ instead of Shift+ZZ. On the
Terminal, you will see [1]+ Stopped vim bad.txt

2. Try to run the vim bad.txt command. Vim will display the following message “Found a swap
file by the name ".bad.txt.swp" which means that Vim detected an incomplete session from a
previous edit of the same file. This usually happens when Vim is not closed properly.

3. Enter the tree command with the -a option to see the swap hidden file.

4. Remove (delete) the swap hidden file → rm .bad.txt.swp

5. Run the vim bad.txt command. Vim will open but with no text, because in step-1, you
incorrectly closed the Vim.

Page 3 of 5
CMPS 101 / Lab Section / Fall 2024 / © Amelle Bedair
Task#3: File Access Per mission

1. Use the tree command with the -p option to see the permission of each file

2. What permissions are given to dir1/hello.txt?

3. Use the symbol way to change the permission of dir1/hello.txt as requested;

• Add the write permission to the group users


• Remove the write permission from the group users
• Give only execute permission to other users
• Did commands change the file permission of hello.txt in dir2 directory?

4. Use the Octal way, in one command, set the permission of dir2/hello.txt as indicated;

• To the owner, give; read, write and execute permissions


• To the group users, give; read and execute permissions
• To the other users, give only execute permission
• What is the total permission code in Octal?

Task#4: Piping

1. Run Vim with colors.txt file name. Then copy-and-paste the following data

Blue,carpet
Red,chair
Red,window
green,sofa
Blue,lamp
Green,picture frame
red,table
Red,cups
blue,board

2. Fill the table.


Requirement Linux Command with Options & Regex
Extract the 1st column
Convert to lower-case
Sort
Count each color
Sort based on the count value
Print only the 1st line

3. In one pipe, create the command sequence to print the least used color; i.e. 2 green
Note: build the command line in sequence to observe the result of each step.

Page 4 of 5
CMPS 101 / Lab Section / Fall 2024 / © Amelle Bedair
Task#5: Processing FASTQC File

1. In Vim, copy-and-paste the following sequence. Save as dna.fstq FastQC format.

@fqlib5:334:VVDJXFE:4:5:7053:1012/1
CCTTTTCCCGCAGTCGTCAGCAGTAAGTGTGCGACCGGTAGTTCAAAAGGGGAATATCACCCGCTATTTTGCGAATACTAG
AGCCTCGGTTCACGCAAGCA
+
GFGDDB@CJCHDBDBDB@JACCIE@J@GD@FHFADAIEA@@ABBEADHBFH@CIEFBBHGCHEJHEAIHAAIHBGEH@EDG
AEEC@FGEABAHE@FAI@IC
@fqlib5:334:VVDJXFE:7:33:2310:7985/1
ACGTGGCCGTCCTTTTGCCAGATATCGGTAAGAGAGTTCTAGCTAAGATAATATCAATCCGCGAATGTCAGAGGGAGTGTT
TCCCTTCCGGGGAAGCAAAT
+
GDGE@DBJJCBHCGFEBHDGEI@JA@GHEHA@CCJGCGGDJGBACIBGECDDBGBHI@GBAEBBJD@@BAFBHAHEHJCBG
FGCA@GJ@IAAIJDHG@IDC

2. Run the cat -n dna.fstq command. You should see only eight lines. If not, then open Vim and
join the DNA sequence lines and the Quality Score lines.

Note: When you copy-and-paste from PDF file;


• Long lines are distributed among multiple lines.
• Empty lines are removed
• Different hidden characters may be added
3. Requirements

From the dna.fstq Quality Control File, find the Linux commands to display the number of A
nucleotide. Hint: Use redirection.

Note: After each operation, run the cat command to display the contents of the generated file.

Algorithm; i.e. follow these steps

1. Use dna.fstq data file to generate the dna1 file after deleting the Identifier line; i.e. line starting
with the @ symbol

2. Use dna1 data file to generate dna2 after deleting the Quality line; i.e. the line below the Plus
line. Then, run the cat dna2 to verify the result of the operation.

3. Use dna2 data file to generate dna3 after deleting the Plus line. Then, run the cat dna3 to
verify the result of the operation.

4. Use dna3 data file to generate dna4 after joining all lines.

5. Use dna4 data file to generate dna5 after deleting all characters except the 'A' character

6. Count the number of 'A's in dna5 file.

7. Optional: You can delete the generated file. rm dna1 dna2 dna3 dna4 dna5 (list the files
you want to delete, separated by spaces.)

Page 5 of 5
CMPS 101 / Lab Section / Fall 2024 / © Amelle Bedair

You might also like