Connect with us

Bioinformatics Programming

How to extract fasta sequences from a multi-fasta file based on matching headers in a separate file?

Tariq Abdullah

Published

on

This is a simple Perl script to extract FASTA sequences from a large fasta file depending on the matching fasta headers present in another file.

For example, your fasta sequences are present in a file named, “input.fa” and the headers are in another file called “headers.txt”.

#! /usr/bin/perl
use warnings;
use strict;
my $headerfile = 'headers.txt';
my $input = 'input.fa';
open( HEADERFILE, '<', $headerfile ) or die $!;
chomp ( my @headers = map { split } <$headerfile> );    #splitting lines on whitespaces.
close HEADERFILE;
my %seqs;
open( INPUTFILE, '<', $input ) or die $!;
{
local $/ = '';         #Reading until blank line
while ( <$input> ) {
     my ( $header, $sequence ) = m/>\s*(\S+)\n(.*)/ms;
     $sequences{$header} = $sequence;
}
open( my $seqsfile, ">", "input.fa" );
foreach my $header (@headers) {
             if ( $sequences{$header} ) {
                       print $header, "\n";
                       print $sequences{$header}, "\n";
             }
}

close( $seqsfile );
}

close INPUTFILE;
exit;

Tariq is founder of Bioinformatics Review and CEO at IQL Technologies. His areas of expertise include algorithm design, phylogenetics, MicroArray, Plant Systematics, and genome data analysis. If you have questions, reach out to him via his homepage.

Bioinformatics Programming

sminalog_analysis.py – A new Python script to fetch top binding affinities from SMINA log file

Dr. Muniba Faiza

Published

on

sminalog_analysis.py – A new Python script to fetch top binding affinities from SMINA log file

In one of our previous posts, we provided a Python script for the virtual screening analysis of Autodock Vina. This script analyzes all log files obtained from docking of multiple ligands to a receptor and provides the binding affinities for top poses from each file. In this article, we are publishing a new Python script for the virtual screening analysis of SMINA [1]. (more…)

Continue Reading

Bioinformatics Programming

Installing Pycharm on Ubuntu (Linux)

Tariq Abdullah

Published

on

Installing pycharm on Ubuntu

Pycharm [1] is an integrated development environment (IDE) for developers. It combines Python developer tools and provides an easy graphical user interface. In this article, we are going to install Pycharm on Ubuntu. (more…)

Continue Reading

Algorithms

vs_Analysis.py: A Python Script to Analyze Virtual Screening Results of Autodock Vina

Dr. Muniba Faiza

Published

on

VS-Analysis: A Python Script to Analyze Virtual Screening Results of Autodock Vina

The output files obtained as a result of virtual screening (VS) using Autodock Vina may be large in number. It is difficult or quite impossible to analyze them manually. Therefore, we are providing a Python script to fetch top results (i.e., compounds showing low binding affinities). (more…)

Continue Reading

LATEST ISSUE

ADVERT