in reply to Re^3: awk 2 perl oneliner
in thread awk 2 perl oneliner

Thank you very many, almut ;-). Now I have an efficient way to extract sequences from a fasta file (doing bioinformatics stuff). It is more than 10times faster than the awk oneliner from my first post.
Here is almuts code slighly adjusted. It can be used to extract sequences from a multifasta file.


usage extract-seq.pl file1 file2 cat file1 AV12349 J234054 . . cat file2 >AV12349 AAACCGTACCTAGAACAGTA ACAGTACA >J434594 ACCGTTAGTACGATACA . .

file1 contains ID to extract, file2 contains sequences in multifasta format. output will be written
to the file extracted.seqs


#!/usr/bin/perl $output = "extracted.seqs"; open (OUT,">$output") or die; # create names lookup table from first file while (<>) { chomp; $names{$_} = 1; last if eof; } $/ = "\n>"; # set input record separator # scan second file while (<>) { s/^>//; #remove leading ">" s/>$//; #remove trailing ">" if (/^([\w\d]+)/ && $names{$1}) { print OUT ">$_";} }