-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatt_attempt.pl
185 lines (151 loc) · 4.83 KB
/
matt_attempt.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/perl
use warnings;
use strict;
#This script will take a CGH array input file and parse through to produce a hash of gene names and the corresponding patients and metrics (i.e. ABPOEC3G => chr22:..-.. => NA12891 => p-val=0.05 cnv=2)#
#This is a subroutine and will be transferred over to a module with other parsing subroutines.
my $input = shift;
my $filtered = shift;
my $cnv_cutoff = shift;
unless ($cnv_cutoff){$cnv_cutoff =0}
open(IN, '<', $input) or die "can't open file $input $!\n";
my @features;
my %genes;
my $sample;
#--------------------------------------------------------------------#
# Open the file and parse through each line.
#--------------------------------------------------------------------#
while(my $line = <IN>){
chomp $line;
@features = split("\t",$line);
my $id;
my $chr;
my $start;
my $stop;
my $probeset;
my $cnv;
my @multiple;
#--------------------------------------------------------------------#
# Look for the sample name i.e. NA12891.
#--------------------------------------------------------------------#
if($features[0] =~ /US_/){
$sample = $features[0];
}
elsif(($features[8]<0.05) && ($features[9])){
$id = $features[9];
$id = uc($id);
#--------------------------------------------------------------------#
# If the gene list has multiple genes separated by commas, this
# separates the criteria per each gene.
#--------------------------------------------------------------------#
if($id =~ /.+,\s.+/){
@multiple = split(/, /,$id);
foreach my $individualgene (@multiple){
$chr = $features[1];
$start = $features[3];
$stop = $features[4];
$probeset = $chr . ':' . $start . '-' . $stop;
if($cnv_cutoff == 0){
if($features[6]>$cnv_cutoff){
$cnv = $features[6];
}
elsif($features[7]<$cnv_cutoff){
$cnv = $features[7];
}
}
else{
if ($cnv_cutoff > 0){
if($features[6]>$cnv_cutoff){
$cnv = $features[6];
}
else{next;}
}
if ($cnv_cutoff < 0){
if($features[7]<$cnv_cutoff){
$cnv = $features[7];
}
else{next;}
}}
$genes{$individualgene}{$probeset} = $sample;
# $genes{$individualgene}{$probeset}{$sample;
}
}
#--------------------------------------------------------------------#
# If the gene list has only ONE gene, populate the hash with the
# criteria from that line.
#--------------------------------------------------------------------#
else{
$chr = $features[1];
$start = $features[3];
$stop = $features[4];
$probeset = $chr . ':' . $start . '-' . $stop;
if($cnv_cutoff == 0){
if($features[6]>$cnv_cutoff){
$cnv = $features[6];
}
elsif($features[7]<$cnv_cutoff){
$cnv = $features[7];
}
}
else{
if ($cnv_cutoff > 0){
if($features[6]>$cnv_cutoff){
$cnv = $features[6];
}
else{next;}
}
if ($cnv_cutoff < 0){
if($features[7]<$cnv_cutoff){
$cnv = $features[7];
}
else{next;}
}
}
$genes{$id}{$probeset} = $sample;
# $genes{$id}{$probeset}{$sample}{'CNV'} = $cnv;
}
}
}
# return %genes;
open(MATCH,'<',$filtered) or die "can't open file $filtered $!\n";
print 'Gene',"\t",'Probeset',"\t",'Sample',"\t",'log2',"\t",'PVAL',"\t",'EXONTRUE',"\n";
my @feat_filt;
#my $sample;
#-----------------------------------------------------------------------------------------------------#
# This portion of the script takes the file based on Omer's stringencies (yet without sample names) #
# and matches the probeset to that in the parsed unfiltered data occupying %genes. Result is to print #
# out a file with the header and the gene name with the correspnding sample that matches and the info #
# from the stringent file. #
#-----------------------------------------------------------------------------------------------------#
while(my $filt_line = <MATCH>){
chomp $filt_line;
@feat_filt = split("\t",$filt_line);
my $id_filt;
my $chr_filt;
my $start_filt;
my $stop_filt;
my $probeset_filt;
my $log2;
my $PVAL;
my $EXONTRUE;
my $sample_match;
if($feat_filt[6] !~ /NA/){
$chr_filt = $feat_filt[0];
$start_filt = $feat_filt[1];
$stop_filt = $feat_filt[2];
$id_filt = $feat_filt[6];
$log2 = $feat_filt[4];
$PVAL = $feat_filt[5];
$EXONTRUE = $feat_filt[9];
$probeset_filt = $chr_filt . ':' . $start_filt . '-' . $stop_filt;
$sample_match = $genes{$id_filt}{$probeset_filt};
if($sample_match){
print "$id_filt","\t","$probeset_filt","\t","$sample_match","\t","$log2","\t","$PVAL","\t","$EXONTRUE\n";
}
else{
next;
}
}
else{
next;
}
}