>I
CATCAGTATAAAATGACTAGTAGCTAGATACCACAGATACGATACAACA
>II
TACCACAGATACGATACAACACATCAGTATAAAATGACTAGTAGCAGAC
####
I 2 A G
I 4 C T
I 5 A G
I 7 T C
II 1 T C
II 2 A G
II 3 C T
II 5 A C
II 8 G T
II 10 T G
####
$F0 = DNA sequence the changes should be made to
$F1 = Letter position that is involved in the change
$F2 = Pre-existing letter
$F3 = Replacement letter
####
#!/usr/bin/env perl
use strict;
use warnings;
use Bio::SeqIO;
#Read and store .FASTA file
my %sequences;
my $seqio = Bio::SeqIO->new(-file => $ARGV[0]);
while(my $seqobj = $seqio->next_seq) {
my $id = $seqobj->display_id;
my $seq = $seqobj->seq;
$sequences{$id} = $seq;
}
#Variant Input File & Output
my $variants = $ARGV[1];
open IN, '<', $variants or die "$!";
open OUT, '>', 'output.txt' or die "$!";
#Loops
my $iteration = 0;
foreach my $key (sort keys%sequences) {
$iteration ++;
my $value = $sequences{$key};
while () {
my (@F) = split("\t", $_);
if ($F[0] eq $key) {
substr($value,0,$F[1]) = $F[3];
} else {
last
}
}
print OUT ">$key\n$value" if $iteration=~1;
print OUT "\n>$key\n$value" if $iteration>1;
}
####
substr($value,$F[1]-1,1) = $F[3];
use 'next' instead of 'last'
added seek(IN,0,0);