Debian Codegraph @

metastudentPkg/lib/groupB/perl/GOfunctions.pm

raw
1 package GOfunctions;
2
3
4 use strict;
5
6
7 # -- parameter --
8 #my $GOprefix = 'GO:';
9 my $GOseperator = ',';
10 my @GOrelationships = ("1","14");
11 # 1 - is_a ; 13 - negatively_regulates; 14 - part_of; 15 - positively_regulates; 16 - regulates
12
13 my @goterm;
14 my @goterm2termarray;
15 my %gonr = ();
16 my %goterm2term = ();
17
18
19 my $filegoterm;
20 my $filegoterm2term;
21
22 sub import {
23
24 $filegoterm = $_[0];
25 $filegoterm2term = $_[1];
26
27
28 open(GOTERM, "< $filegoterm") or die "could not open goterm file! ($filegoterm) \n";
29 (@goterm) = <GOTERM>; # read file into list
30 close(GOTERM);
31
32 open(GOTERM2TERM, "< $filegoterm2term") or die "could not open goterm2term file! ($filegoterm2term)\n";
33 (@goterm2termarray) = <GOTERM2TERM>; # read file into list
34 close(GOTERM2TERM);
35
36
37 # -- creat hash for Term2Nr --
38
39 foreach my $go (@goterm) {
40
41 my @tmp = split(/\t/,$go);
42 $gonr{$tmp[3]} = $tmp[0];
43 }
44
45 # -- creat hash to find parents --
46
47 foreach my $line (@goterm2termarray) {
48
49 my @tmp = split(/\t/,$line);
50
51 my $relation = 0;
52 foreach my $rel(@GOrelationships) {
53 if($tmp[1] eq $rel) {$relation = 1}
54 }
55
56 if($relation) { # only chosen relationships
57
58 if (exists $goterm2term{$tmp[3]}) { # if it has a relationship
59 my @tmp2 = @{$goterm2term{$tmp[3]}};
60 push(@tmp2,$tmp[2]);
61 $goterm2term{$tmp[3]} = [@tmp2];
62 } else {
63 my @tmp2 = ();
64 push(@tmp2,"$tmp[2]");
65 $goterm2term{"$tmp[3]"} = [@tmp2];
66 }
67 }
68 }
69 }
70
71
72
73
74
75
76
77
78
79
80
81
82 # -- functions --
83
84 sub goNR2TERM {
85
86 my @tmp = split(/\t/,$goterm[$_[0]-1]);
87 return $tmp[3];
88 }
89
90 sub goTERM2NR {
91
92 return $gonr{$_[0]};
93 }
94
95 sub goFilter {
96
97 my @goarray = @_;
98 my @gofiltered = ();
99
100 foreach my $go (@goarray) {
101 my $nr = goTERM2NR($go);
102 next unless $nr;
103
104 my @split = split(/\t/,$goterm[$nr -1]);
105
106 if($split[2] eq 'molecular_function' || $split[2] eq 'biological_process' || $split[2] eq 'cellular_component') {
107
108 push(@gofiltered,$go);
109 }
110 }
111 return @gofiltered;
112 }
113
114 sub getType {
115 my $self = shift @_;
116 my $term = shift @_;
117
118 my $nr = goTERM2NR($term);
119 return undef unless $nr;
120
121 my @split = split(/\t/, $goterm[$nr -1]);
122 return uc(substr($split[2], 0,1));
123 }
124
125 sub goAddPath {
126
127 my @GO = @_;
128
129 foreach my $go(@GO) {
130 #my $go = substr($GO[$i],length($GOprefix));
131
132 my @parents = ();
133 my $nr = goTERM2NR($go);
134 if(defined $nr && defined $goterm2term{ $nr } ) {
135 @parents = @{$goterm2term{ goTERM2NR($go) }};
136 }
137
138 foreach my $parent(@parents) {
139 $parent = goNR2TERM($parent);
140 #$parent = $GOprefix.$parent;
141
142 if('GO:' eq substr($parent,0,3)) { # check that it is a GO nr
143
144 my $new = 1; # check that it is new
145 foreach my $tmp(@GO) {
146
147 if($parent eq $tmp) {
148 $new = 0;
149 }
150 }
151 if($new) {push(@GO,$parent)};
152 }
153 }
154 }
155
156 return keys %{{ map { $_ => 1 } @GO }}; # make sure no double
157 }
158
159 1;