Last active
December 21, 2022 01:40
-
-
Save piroyon/b4b5194de6c14f70c353685037ad4c8e to your computer and use it in GitHub Desktop.
Get FPKM and TPM from a result gtf file of stringtie
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Getopt::Std; | |
use Pod::Usage; | |
pod2usage() unless @ARGV; | |
=pod | |
=head1 NAME | |
getTPM.pl - Get FPKM and TPM from a result gtf file of stringtie | |
=head1 SYNOPSIS | |
getTPM.pl [option] ballgown/your_data1/your_data1.gtf | |
Option: -f | |
0: FPKM and TPM (default) | |
1: FPKM | |
2: TPM | |
=head1 OPTIONS | |
=over 8 | |
=item B<-f|--format> | |
0: FPKM and TPM (default) | |
1: FPKM only | |
2: TPM only | |
=cut | |
my $format = '0'; | |
getopts('f:'); | |
our($opt_f); | |
$format = $opt_f if ($opt_f); | |
my %hash=(); | |
my $gtf = pop @ARGV; | |
open G, $gtf or die"$!"; | |
while(<G>) { | |
next if (/^#/); | |
chomp; | |
my @g = split(/\t/); | |
if ($g[2] eq 'transcript') { | |
my @dsc = split(/;/, $g[8]); | |
my $name = ''; | |
foreach my $i (@dsc) { | |
$i =~ /(\S+)\s+(\S+)/; | |
my $tit = $1; | |
my $val = $2; | |
$val =~ s/"//g; | |
if ($tit eq 'transcript_id') { | |
$name = $val; | |
} elsif ($tit eq 'FPKM') { | |
$hash{$name}{'f'} = $val; | |
} elsif ($tit eq 'TPM') { | |
$hash{$name}{'t'} = $val; | |
} | |
} | |
} | |
} | |
close G; | |
foreach my $j (keys %hash) { | |
if ($format eq '0') { | |
print "$j\t$hash{$j}{'f'}\t$hash{$j}{'t'}\n" | |
} elsif ($format eq '1') { | |
print "$j\t$hash{$j}{'f'}\n" | |
} elsif ($format eq '2') { | |
print "$j\t$hash{$j}{'t'}\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment