#! perl -slw use strict; use Inline::Files; use Data::Dump qw[ pp ]; use constant { SEQ => 0, POS => 1, ACT => 2, REP => 3 }; my %seqs = map{ split "\n", $_ } ; pp \%seqs; my @edits = [ split ' ', ]; while( 1 ) { my @bits = split ' ', ; if( defined $bits[ 0 ] and $bits[ 0 ] eq $edits[ 0 ][ 0 ] ) { push @edits, \@bits; next; } for my $edit ( sort{ $b->[POS] <=> $a->[POS] } @edits ) { if( $edit->[ACT] eq 'I' ) { substr( $seqs{ '>' . $edit->[SEQ] }, $edit->[POS]-1, 0, $edit->[REP] ); } elsif( $edit->[ACT] eq 'D' ) { substr( $seqs{ '>' . $edit->[SEQ] }, $edit->[POS]-1, 1, '' ); } else { ## replace substr( $seqs{ '>' . $edit->[SEQ] }, $edit->[POS]-1, 1, $edit->[REP] ); } } last unless defined $bits[ 0 ]; @edits = \@bits; } pp \%seqs; __FASTA__ >I CATCAGTATAAAATGACTAGTAGCTAGATACCACAGATACGATACAACA >II TACCACAGATACGATACAACACATCAGTATAAAATGACTAGTAGCAGAC __EDITS__ I 2 I I I 4 D X I 5 R G I 7 I C II 1 D X II 2 I I II 3 R T II 5 D X II 8 R T II 10 I I