Last active
December 6, 2016 06:51
-
-
Save JEEN/43c1d016f41fee8316bb334188f28b6e to your computer and use it in GitHub Desktop.
map1.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} |
Author
JEEN
commented
Dec 6, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment