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

How to obtain ligand structures in PDB format from PDB ligand IDs?

Published

on

How to obtain ligand structures in PDB format from PDB ligand IDs?

Previously, we provided a similar script to download ligand SMILES from PDB ligand IDs. In this article, we are downloading PDB ligand structures from their corresponding IDs. (more…)

Continue Reading

Bioinformatics Programming

How to obtain SMILES of ligands using PDB ligand IDs?

Published

on

How to obtain SMILES of ligands using PDB ligand IDs?

Fetching SMILE strings for a given number of SDF files of chemical compounds is not such a trivial task. We can quickly obtain them using RDKit or OpenBabel. But what if you don’t have SDF files of ligands in the first place? All you have is Ligand IDs from PDB. If they are a few then you can think of downloading SDF files manually but still, it seems time-consuming, especially when you have multiple compounds to work with. Therefore, we provide a Python script that will read all Ligand IDs and fetch their SDF files, and will finally convert them into SMILE strings. (more…)

Continue Reading

Bioinformatics Programming

How to get secondary structure of multiple PDB files using DSSP in Python?

Published

on

How to get secondary structure of multiple PDB files using DSSP in Python?

In this article, we will obtain the secondary structure of multiple PDB files present in a directory using DSSP [1]. You need to have DSSP installed on your system. (more…)

Continue Reading

LATEST ISSUE

ADVERT