Mercurial > repos > chawhwa > neuma
comparison NEUMA-1.2.1/merge_LVKM.pl @ 0:c44c43d185ef draft default tip
NEUMA-1.2.1 Uploaded
author | chawhwa |
---|---|
date | Thu, 08 Aug 2013 00:46:13 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c44c43d185ef |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 if(@ARGV<4) { print "usage: $0 genewise/isoformwise[g/i] EUMAcut LVKM_out_dir NR(1/0) > output.gLVKM(iLVKM).merged\n"; exit; } | |
4 my $option = shift @ARGV; #either g or i | |
5 my $EUMAcut = shift @ARGV; | |
6 my $LVKM_dir = shift @ARGV; | |
7 my $NR_option = shift @ARGV; | |
8 | |
9 my $suffix = $option."LVKM"; | |
10 | |
11 my @sample_list = split/\n/,`ls -1 $LVKM_dir`; | |
12 for my $i (0..$#sample_list){ | |
13 if($NR_option eq '1'){ | |
14 if($sample_list[$i] =~ /\.\d+.-NR.[gi]LVKM$/) { $samples{$`}=1; } | |
15 } | |
16 else { | |
17 if($sample_list[$i] =~ /\.\d+.[gi]LVKM$/) { $samples{$`}=1; } | |
18 } | |
19 } | |
20 | |
21 @sample_list = keys %samples; | |
22 | |
23 | |
24 for my $sample (@sample_list){ | |
25 next if($sample eq ''); | |
26 my $file; | |
27 if($NR_option eq '1'){ | |
28 $file = "$LVKM_dir/$sample.$EUMAcut.-NR.$suffix"; | |
29 } | |
30 else { | |
31 $file = "$LVKM_dir/$sample.$EUMAcut.$suffix"; | |
32 } | |
33 | |
34 print STDERR "$file\n"; #DEBUGGING | |
35 open IN,$file or die "Can't open LVKM file $file\n"; | |
36 <IN>; | |
37 while(<IN>){ | |
38 chomp; | |
39 | |
40 my $gene; | |
41 if($option eq 'g'){ | |
42 my ($gid,$symbol,$expr) = (split/\t/)[0,1,2]; | |
43 $gene = "$gid\t$symbol"; | |
44 $EXPR{$gene}{$sample} = $expr; | |
45 } | |
46 elsif($option eq 'i'){ | |
47 my ($gid,$symbol,$NM,$expr) = (split/\t/)[0,1,2,3]; | |
48 $gene = "$gid\t$symbol\t$NM"; | |
49 $EXPR{$gene}{$sample} = $expr; | |
50 } | |
51 } | |
52 close IN; | |
53 } | |
54 | |
55 | |
56 | |
57 $"="\t"; | |
58 if($option eq 'g') { print "gene.id\tgene.symbol\t@sample_list\n"; } | |
59 elsif($option eq 'i') { print "gene.id\tgene.symbol\tisoform\t@sample_list\n"; } | |
60 for my $gene (keys %EXPR){ | |
61 print "$gene"; | |
62 for my $sample (@sample_list){ | |
63 if(exists ${$EXPR{$gene}}{$sample}){ | |
64 print "\t$EXPR{$gene}{$sample}"; | |
65 } | |
66 else { print "\tNA"; } | |
67 } | |
68 print "\n"; | |
69 } | |
70 | |
71 | |
72 |