Skip to content

Instantly share code, notes, and snippets.

@JEEN
Created December 6, 2016 07:01
Show Gist options
  • Save JEEN/8468637c31dd428b09dfa3f7353e4fd4 to your computer and use it in GitHub Desktop.
Save JEEN/8468637c31dd428b09dfa3f7353e4fd4 to your computer and use it in GitHub Desktop.
map2.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 '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";
}
@JEEN
Copy link
Author

JEEN commented Dec 6, 2016

$  perl map2.pl genome_mapping_update.txt result1.txt > result2.txt

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