Skip to content

Instantly share code, notes, and snippets.

@JEEN
Last active December 6, 2016 06:51
Show Gist options
  • Save JEEN/43c1d016f41fee8316bb334188f28b6e to your computer and use it in GitHub Desktop.
Save JEEN/43c1d016f41fee8316bb334188f28b6e to your computer and use it in GitHub Desktop.
map1.pl
use strict;
use warnings;
use Text::CSV_XS;
use Data::Printer;
my $csv = Text::CSV_XS->new({ binary => 1, sep_char => "\t" });
open my $fh, "<", $ARGV[0] or die $!;
open my $fh2, "<", $ARGV[1] or die $!;
# 1. 키맵 생성
my %map = ();
while(my $row = $csv->getline($fh)) {
$map{$row->[0]} = $row->[1];
}
my $count = 0;
while(my $row = $csv->getline($fh2)) {
if ($row->[2] && $row->[2] eq 'exon') {
my $description = $row->[8];
my ($val) = $description =~ /Parent=([^;]+);/;
my $str = join(",", map { my $r = $_; $r =~ s/^0:+//g; $map{$r} ? $map{$r} : $r; } split ",", $val);
$row->[8] =~ s/Parent=[^;]+;/Parent=$str;/;
}
elsif ($row->[2] && $row->[2] =~ /^(?:gene|mRNA)$/) {
my $description = $row->[8];
my ($val) = $description =~ /Alias=([^;]+);/;
my $str = join(",", map { my $r = $_; $r =~ s/^0:+//g; $map{$r} ? $map{$r} : $r; } split ",", $val);
$row->[8] =~ s/Alias=[^;]+;/Alias=$str;/;
}
print join("\t", @{ $row })."\n";
}
@JEEN
Copy link
Author

JEEN commented Dec 6, 2016

$ perl map.pl genome_mapping_update.txt iceplant_gene.gff > result1.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment