-
-
Save wyim-pgl/aed95a4d96371e891b1c9bc20124582c to your computer and use it in GitHub Desktop.
map2.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 'gene') { | |
my ($name_str) = $row->[8] =~ /Name=([^;]+);/; | |
my ($alias_str) = $row->[8] =~ /Alias=([^;]+);/; | |
$name_str .= '0'; | |
$alias_str = join(",", map { $_.'0' } split ',', $alias_str); | |
$row->[8] =~ s/Name=([^;]+);/Name=$name_str;/; | |
$row->[8] =~ s/Alias=([^;]+);/Alias=$alias_str;/; | |
} | |
elsif ($row->[2] && $row->[2] eq 'exon') { | |
my ($parent_str) = $row->[8] =~ /Parent=([^;]+);/; | |
for my $parent_col (split ",", $parent_str) { | |
$row->[8] =~ s/Parent=([^;]+);/Parent=$parent_col;/; | |
print join("\t", @{ $row })."\n"; | |
} | |
next; | |
} | |
print join("\t", @{ $row })."\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment