Skip to content

Instantly share code, notes, and snippets.

@slavailn
Created April 26, 2016 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slavailn/899934b56e30621d3a38ba2d417335eb to your computer and use it in GitHub Desktop.
Save slavailn/899934b56e30621d3a38ba2d417335eb to your computer and use it in GitHub Desktop.
#! /usr/bin/perl
use strict; use warnings;
# This script will parce a fasta file and create
# a hash where keys are fasta ids (everything after '>')
# and values are fasta sequences of arbitrary length (could be
# DNA, RNA, protein). I'm not checking the symbols in the sequence
my $fasta_file = shift or die "Please, provide a fasta file: $!\n";
open( my $fasta_fh, "<", $fasta_file) or die "Cannot open fasta file: $!\n";
my %id2seq;
my $id = ();
while ( my $line=<$fasta_fh> )
{
chomp $line;
if ( $line =~ m/^>(.+)/ )
{
$id = $1;
}
else
{
$id2seq{$id} .= $line
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment