Merge pull request #3987 from solgenomics/topic/description_to_text
[sgn.git] / bin / replace_accessions_in_vcf.pl
blob9202e3fd760bfa77c32c7a5cd46c635f5b0e4a45
2 use strict;
4 use Hash::Case::Preserve;
6 my $vcf_file = shift;
7 my $equivalence_file = shift;
10 open(my $E, "<", $equivalence_file) || die "Can't open $equivalence_file\n";
12 tie my %ids, 'Hash::Case::Preserve';
13 while (<$E>) {
14 chomp;
16 my ($original_id, $modified_id, $new_id, $match_type, $stock_type) = split /\t/;
17 $ids{$original_id} = $new_id;
20 close($E);
22 open(my $V, "<", $vcf_file) || die "Can't open $vcf_file\n";
24 while (<$V>) {
25 chomp();
27 if ($_ =~ m/^\#CHROM/) {
28 print STDERR "Parsing ids in vcf file...\n";
29 my @F = split /\t/;
30 my $count = 0;
31 foreach my $f (@F) {
32 $count++;
33 if (exists($ids{$f}) && ($ids{$f} ne $f)) {
34 print STDERR "replace $f with $ids{$f} ($count), ";
35 $f = $ids{$f};
38 my $line = join("\t", @F);
39 print "$line\n";
41 else {
42 print $_."\n";