Connect with us

Bioinformatics Programming

Linux ‘sed’ command in Perl programming

Published

on

When it comes to handling large data files to process, it becomes very difficult to write programs for the beginners, especially when you have to execute another script within one. For this purpose, the Linux operating system offers several advantages for bioinformatics programming such as ‘awk’ and ‘sed’ one-liners, they prove to be of great help!

The sed command is a stream editor that parses and performs basic text transformations on a file or an input stream from a pipeline. sed allows restricting the command to certain lines or characters. It reads text line-by-line, removes trailing newline, and stores them into an empty data buffer known as pattern space, on which the specified commands are executed. It is an amazing utility but the documentation is a bit difficult.

Syntax:
sed OPTIONS... [SCRIPT] [INPUTFILE]

In bioinformatics, sometimes we need to edit large fasta files, which is quite difficult and tedious when done manually. The replacement and deletion commands of sed are most widely used, which can edit more than five thousands of sequences in a few seconds.

sed substitution command:
sed 's/regexp/replacement/g' input > output

or to modify the input file without getting output in another file, -i option is used:

sed -i input 's/regexp/replacement/g'

It has a vast range of applications in bioinformatics programming such as:

  • one can easily edit or modify the fasta headers in a file consisting of a large number of sequences,
  • can search for a particular expression present within the sequences,
  • can delete text in between the lines, or in terms of bioinformatics, it can easily delete a specific number of residues from specific lines,
  • can handle large data files, and so on.

In Perl, sed command can be easily executed using exec(), system(), qx//, or backticks (``) depending on the need of the program. The similarity between the sed and Perl is that they use similar identifiers and/ characters. For example,

[table id=2 /]

If you want to insert five blank spaces at the beginning of each line, then the following can be used:

$ sed 's/^/     /'

Again, here ‘^’ is used for recognizing the first character in a line in Perl and sed.

Further reading:

https://www.computerhope.com/unix/used.htm

http://www.grymoire.com/Unix/Sed.html#uh-47

Dr. Muniba is a Bioinformatician based in New Delhi, India. She has completed her PhD in Bioinformatics from South China University of Technology, Guangzhou, China. She has cutting edge knowledge of bioinformatics tools, algorithms, and drug designing. When she is not reading she is found enjoying with the family. Know more about Muniba

Advertisement
Click to comment

You must be logged in to post a comment Login

Leave a Reply

Bioinformatics Programming

tanimoto_similarities.py: A Python script to calculate Tanimoto similarities of multiple compounds using RDKit.

Published

on

tanimoto_similarities.py: A Python script to calculate Tanimoto similarities of multiple compounds using RDKit.

RDKit [1] is a very nice cheminformatics software. It allows us to perform a wide range of operations on chemical compounds/ ligands. We have provided a Python script to perform fingerprinting using Tanimoto similarity on multiple compounds using RDKit. (more…)

Continue Reading

Bioinformatics Programming

How to commit changes to GitHub repository using vs code?

Published

on

How to commit changes to GitHub repository using vs code?

In this article, we are providing a few commands that are used to commit changes to GitHub repositories using VS code terminal.

(more…)

Continue Reading

Bioinformatics Programming

Extracting first and last residue from helix file in DSSP format.

Published

on

Extracting first and last residue from helix file in DSSP format.

Previously, we have provided a tutorial on using dssp_parser to extract all helices including long and short separately. Now, we have provided a new python script to find the first and last residue in each helix file. (more…)

Continue Reading

LATEST ISSUE

ADVERT