-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconvert_bim_allele.pl
executable file
·514 lines (433 loc) · 22.7 KB
/
convert_bim_allele.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
#!/usr/bin/env perl
use warnings;
use strict;
use Carp;
use Pod::Usage;
use Getopt::Long;
our $VERSION = '$Revision: 87a93fbdbc7fb54dadc30cc526acab51d337dfce $';
our $LAST_CHANGED_DATE = '$LastChangedDate: 2013-02-08 11:10:50 -0800 (Fri, 08 Feb 2013) $';
our ($verbose, $help, $man);
our ($bimfile, $snptablefile);
our ($outfile, $intype, $outtype, $replacezero, $force, $autoflip, $strandfile);
GetOptions('verbose|v'=>\$verbose, 'help|h'=>\$help, 'man|m'=>\$man, 'outfile=s'=>\$outfile, 'intype=s'=>\$intype, 'outtype=s'=>\$outtype,
'replacezero'=>\$replacezero, 'force'=>\$force, 'autoflip'=>\$autoflip, 'strandfile=s'=>\$strandfile) or pod2usage ();
$help and pod2usage (-verbose=>1, -exitval=>1, -output=>\*STDOUT);
$man and pod2usage (-verbose=>2, -exitval=>1, -output=>\*STDOUT);
@ARGV or pod2usage (-verbose=>0, -exitval=>1, -output=>\*STDOUT);
@ARGV == 2 or pod2usage ("Syntax error");
($bimfile, $snptablefile) = @ARGV;
$intype or print STDERR "NOTICE: The default --intype of 'ilmn12' is assumed for bimfile $bimfile\n" and $intype = 'ilmn12';
$outtype or print STDERR "NOTICE: The default --outtype of 'dbsnp' is assumed as output format\n" and $outtype = 'dbsnp';
$intype eq 'top12' and $intype = 'ilmn12';
$intype eq $outtype and pod2usage ("Error in argument: the --intype $intype cannot be identical to --outtype $outtype");
$intype =~ m/^(ilmn12|ilmnab|top|dbsnp|forward)$/ or pod2usage ("Error in argument: the --intype $intype cannot be procesed (supported intype are ilmn12, ilmnab, top, dbsnp, forward)!");
$autoflip and $intype eq 'dbsnp' || pod2usage ("Error in argument: the --autoflip argument can be used only when --intype is 'dbsnp'");
$outtype eq 'forward' and defined $strandfile || pod2usage ("Error in argument: please specify --strandfile when '-outtype' is 'forward'");
$intype eq 'forward' and defined $strandfile || pod2usage ("Error in argument: please specify --strandfile when '-intype' is 'forward'");
defined $strandfile and $outtype eq 'forward' || $intype eq 'forward' || pod2usage ("Error in argument: the --strandfile is supported only when '-intype' or '-outtype' is 'forward'");
my ($ilmn_strand, $cust_strand, $indel, $no_anno) = readSNPTableFile ($snptablefile);
my $strandinfo;
$strandfile and $strandinfo = readStrandfile ($strandfile, $ilmn_strand);
writeBim ($bimfile, $ilmn_strand, $cust_strand, $outfile, $indel, $no_anno, $strandinfo);
sub readStrandfile {
my ($strandfile, $ilmn_strand) = @_;
my (%strandinfo);
my ($pos, $neg) = (0, 0);
open (STRAND, $strandfile) or die "Error: cannot read strandfile $strandfile: $!\n";
while (<STRAND>) {
s/[\r\n]+$//;
my @field = split (/\t/, $_);
$field[1] eq '+' or $field[1] eq '-' or die "Error: invalid record found in strandfile $strandfile: <$_>\n";
$ilmn_strand->{$field[0]} or next; #skip markers not useful for the BIM file
$strandinfo{$field[0]} = $field[1];
$field[1] eq '+' and $pos++;
$field[1] eq '-' and $neg++;
}
print STDERR "NOTICE: Finished reading $pos positive strand and $neg negative strand\n";
return (\%strandinfo);
}
sub writeBim {
my ($bimfile, $ilmn_strand, $cust_strand, $outfile, $indel, $no_anno, $strandinfo) = @_;
my (@indel);
my %rev = ('A'=>'T', 'C'=>'G', 'G'=>'C', 'T'=>'A');
my ($without_strand) = (0);
open (BIM, $bimfile) or confess "Error: cannot read from bimfile $bimfile: $!";
if ($outfile) {
open (STDOUT, ">$outfile") or confess "Error: cannot write to output file $outfile: $!";
print STDERR "NOTICE: The new bim file will be written to $outfile ... ";
}
my $flipcount;
while (<BIM>) {
s/[\r\n]+$//;
my @record = split (/\s+/, $_);
@record == 6 or confess "Error: invalid record found in bimfile $bimfile (6 tab/space-delimited records expected): <$_>\n";
if ($indel->{$record[1]}) {
$verbose and print STDERR "WARNING: the SNP $record[1] in bimfile $bimfile is annotated as indel in SNPTable file (removal from BIM file is recommended)\n";
push @indel, $record[1];
}
if ($no_anno->{$record[1]}) {
confess "Error: the SNP $record[1] in bimfile $bimfile is annotated as ALLELE UNKNOWN (CNV marker?) in SNPTable file (remove it from BIM file before conversion)\n";
}
$ilmn_strand->{$record[1]} or confess "Error: the SNP $record[1] in bimfile $bimfile is not annotated in SNPTable file\n";
my ($allele1, $allele2) = @record[4,5]; #same the allele identity since we'll modify record[4,5] below
$allele1 and not $allele2 and confess "FATAL ERROR: the minor allele for SNP $record[1] is $allele1 but major allele is a zero allele in BIM file $bimfile\n";
if ($intype eq 'ilmn12' or $intype eq 'ilmnab') {
if ($intype eq 'ilmnab') {
$record[4] =~ tr/AB/12/;
$record[5] =~ tr/AB/12/;
$record[4] =~ m/^0|1|2$/ and $record[5] =~ m/^0|1|2$/ or confess "Error: invalid allele designation (0/A/B expected based on --intype of ilmnab): <$_>\n";
} else {
$record[4] =~ m/^0|1|2$/ and $record[5] =~ m/^0|1|2$/ or confess "Error: invalid allele designation (0/1/2 expected based on --intype of ilmn12): <$_>\n";
}
if ($record[4] == 0) {
$record[5] == 1 and $record[4] = 2;
$record[5] == 2 and $record[4] = 1;
$record[5] == 0 and ($record[4], $record[5]) = (1, 2); #randomly assign 1 and 2, since no genotype call is generated for this SNP
}
if ($outtype eq 'dbsnp' or $outtype eq 'top') {
my $a12 = ($outtype eq 'dbsnp' ? $cust_strand->{$record[1]} : $ilmn_strand->{$record[1]}) or confess "Error: the SNP $record[1] in bimfile $bimfile is not annotated in SNP Table file $snptablefile\n";
my @a = split (//, $a12);
if ($record[4] == 1) {
@record[4,5] = @a[0,1];
} else {
@record[4,5] = @a[1,0];
}
} elsif ($outtype eq 'forward') {
my $a12 = $cust_strand->{$record[1]};
my @a = split (//, $a12);
if (not defined $strandinfo->{$record[1]}) {
@a = (0, 0);
$without_strand++;
} elsif ($strandinfo->{$record[1]} eq '-') {
@a = ($rev{$a[0]}, $rev{$a[1]});
} elsif ($strandinfo->{$record[1]} eq '+') {
1;
} else { #for those without strand information, make the genotype as zero as it is undetermined
@a = (0, 0);
}
if ($record[4] == 1) {
@record[4,5] = @a[0,1];
} else {
@record[4,5] = @a[1,0];
}
} elsif ($outtype eq 'ilmnab') {
$record[4] =~ tr/12/AB/;
$record[5] =~ tr/12/AB/;
} elsif ($outtype eq 'ilmn12') {
$record[4] =~ tr/AB/12/;
$record[5] =~ tr/AB/12/;
}
} elsif ($intype eq 'top') {
$record[4] =~ m/^[ACTG0]$/ and $record[5] =~ m/^[ACTG0]$/ or confess "Error: invalid alleles found in BIM file (the -intype of 'top' indicates possible alleles as ACGT0): <$_>\n";
if ($outtype eq 'ilmn12' or $outtype eq 'ilmnab') {
my $a12 = $ilmn_strand->{$record[1]} or confess "Error: the SNP $record[1] in bimfile $bimfile is not annotated in SNP Table file\n";
my @a = split (//, $a12);
if ($record[5] eq '0') {
@record[4,5] = (1, 2); #randomly assign 1 and 2, since no genotype call is generated for this SNP
} else {
if ($record[5] eq $a[1]) {
$record[4] and $record[4] eq $a[0] || confess "Error: the SNP $record[1] top allele is annotated as '@a' in snptable file, but is shown as '@record[4,5]' in BIM file\n";
@record[4,5] = (1,2);
} elsif ($record[5] eq $a[0]) {
$record[4] and $record[4] eq $a[1] || confess "Error: the SNP $record[1] top allele is annotated as '@a' in snptable file, but is shown as '@record[4,5]' in BIM file\n";
@record[4,5] = (2,1);
} else {
if ($force) {
warn "Error: the SNP $record[1] top allele is annotated as '@a' in snptable file, but is shown as '@record[4,5]' in BIM file. Treated as zero allele in output\n";
@record[4,5] = (0, 0);
} else {
confess "Error: the SNP $record[1] top allele is annotated as '@a' in snptable file, but is shown as '@record[4,5]' in BIM file\n";
}
}
}
if ($outtype eq 'ilmnab') {
$record[4] =~ tr/12/AB/;
$record[5] =~ tr/12/AB/;
}
} elsif ($outtype eq 'dbsnp') {
my $a12 = $ilmn_strand->{$record[1]} or confess "Error: the SNP $record[1] in bimfile $bimfile is not annotated in SNP Table file\n";
my @a = split (//, $a12);
my $b12 = $cust_strand->{$record[1]} or confess "Error: the SNP $record[1] in bimfile $bimfile is not annotated in SNP Table file\n";
my @b = split (//, $b12);
if ($record[5] eq '0') {
$record[4] and confess "Error: the SNP $record[1] major allele is annotated as 0 but minor allele is $record[4] in BIM file $bimfile\n";
@record[4,5] = @b; #randomly assign alleles, since no genotype call is generated for this SNP
} else {
if ($record[5] eq $a[1]) {
$record[4] and $record[4] eq $a[0] || confess "Error: the SNP $record[1] top allele is annotated as '@a' in snptable file, but is shown as '@record[4,5]' in BIM file\n";
@record[4,5] = @b[0,1];
} elsif ($record[5] eq $a[0]) {
$record[4] and $record[4] eq $a[1] || confess "Error: the SNP $record[1] top allele is annotated as '@a' in snptable file, but is shown as '@record[4,5]' in BIM file\n";
@record[4,5] = @b[1,0];
} else {
if ($force) {
warn "Error: the SNP $record[1] top allele is annotated as '@a' in snptable file, but is shown as '@record[4,5]' in BIM file; Treated as zero allele in output\n";
@record[4,5] = (0, 0);
} else {
confess "Error: the SNP $record[1] top allele is annotated as '@a' in snptable file, but is shown as '@record[4,5]' in BIM file\n";
}
}
}
}
} elsif ($intype eq 'dbsnp' or $intype eq 'forward') {
$record[4] =~ m/[ACGT0]$/ and $record[5] =~ m/^[ACGT0]$/ or confess "Error: invalid alleles found in BIM file (the -intype of 'dbsnp' indicates possible alleles as ACGT0): <$_>\n";
if ($intype eq 'forward') { #convert forward to dbSNP first
$strandinfo->{$record[1]} or die "Error: strand information for $record[1] is not found in strandfile\n";
if ($strandinfo->{$record[1]} eq '-') {
$record[4] = complement($record[4]);
$record[5] = complement($record[5]);
} elsif ($strandinfo->{$record[1]} eq '+') {
1;
}
}
if ($outtype eq 'ilmn12' or $outtype eq 'ilmnab') {
my $a12 = $cust_strand->{$record[1]} or confess "Error: the SNP $record[1] in bimfile $bimfile is not annotated in SNP Table file\n";
my @a = split (//, $a12);
if ($record[5] eq '0') {
$record[4] and confess "Error: the SNP $record[1] major allele is annotated as 0 but minor allele is $record[4] in BIM file $bimfile\n";
@record[4,5] = (1,2); #this SNP has no genotyping call in all subjects
} else {
#when intype is dbSNP, check the allele correspondence and flip alleles when necessary
if ($autoflip and not pairnt ($record[4], $record[5])) {
if ($record[4] eq '0') {
if ($record[5] eq complement($a[0]) or $record[5] eq complement($a[1])) {
$record[5] = complement ($record[5]);
$flipcount++;
}
} elsif ($record[4] eq complement($a[0]) and $record[5] eq complement($a[1]) or $record[4] eq complement($a[1]) and $record[5] eq complement($a[0]) ) {
@record[4,5] = (complement($record[4]), complement ($record[5]));
$flipcount++;
}
}
if ($record[5] eq $a[0]) {
$record[4] and $record[4] eq $a[1] || confess "Error: the SNP $record[1] forward strand allele is annotated as '@a' in snptable file, but is shown as '@record[4,5]' in BIM file\n";
@record[4,5] = (2,1);
} elsif ($record[5] eq $a[1]) {
$record[4] and $record[4] eq $a[0] || confess "Error: the SNP $record[1] forward strand allele is annotated as '@a' in snptable file, but is shown as '@record[4,5]' in BIM file\n";
@record[4,5] = (1,2);
} else {
if ($force) {
warn "Error: the SNP $record[1] forward strand allele is annotated as '@a' in snptable file, but is shown as '@record[4,5]' in BIM file; Treated as zero allele in output\n";
@record[4,5] = (0, 0);
} else {
die "Error: the SNP $record[1] forward strand allele is annotated as '@a' in snptable file, but is shown as '@record[4,5]' in BIM file\n";
}
}
}
if ($outtype eq 'ilmnab') {
$record[4] =~ tr/12/AB/;
$record[5] =~ tr/12/AB/;
}
} elsif ($outtype eq 'top') {
my $a12 = $ilmn_strand->{$record[1]} or confess "Error: the SNP $record[1] in bimfile $bimfile is not annotated in SNP Table file\n";
my @a = split (//, $a12);
my $b12 = $cust_strand->{$record[1]} or confess "Error: the SNP $record[1] in bimfile $bimfile is not annotated in SNP Table file\n";
my @b = split (//, $b12);
if ($record[5] eq '0') {
$record[4] and confess "Error: the SNP $record[1] major allele is annotated as 0 but minor allele is $record[4] in BIM file $bimfile\n";
@record[4,5] = @a;
} else {
if ($record[5] eq $b[0]) {
$record[4] and $record[4] eq $b[1] || confess "Error: the SNP $record[1] forward strand allele is annotated as '@b' in snptable file, but is shown as '@record[4,5]' in BIM file\n";
@record[4,5] = @a[1,0];
} elsif ($record[5] eq $b[1]) {
$record[4] and $record[4] eq $b[0] || confess "Error: the SNP $record[1] forward strand allele is annotated as '@b' in snptable file, but is shown as '@record[4,5]' in BIM file\n";
@record[4,5] = @a[0,1];
} else {
if ($force) {
warn "Error: the SNP $record[1] forward strand allele is annotated as '@b' in snptable file, but is shown as '@record[4,5]' in BIM file; Treated as zero allele in output\n";
@record[4,5] = (0, 0);
} else {
confess "Error: the SNP $record[1] forward strand allele is annotated as '@b' in snptable file, but is shown as '@record[4,5]' in BIM file\n";
}
}
}
}
} else {
pod2usage ("Error in argument: the -intype of $intype is not supported by the program yet!");
}
if (not $replacezero) { #if --replacezero is not set, then do not automatically change the unobserved allele to the actual allele
$allele1 eq '0' and $record[4] = 0;
$allele2 eq '0' and $record[5] = 0;
}
print join("\t", @record), "\n";
}
close (BIM);
print STDERR "Done\n";
$flipcount and print STDERR "NOTICE: the auto-flipping function was performed on $flipcount SNPs in the input BIM file\n";
@indel and print STDERR "WARNING: ${\(scalar @indel)} indels (examples:", join (',', splice (@indel, 0, 3)), ") are included in the output file\n";
$without_strand and print STDERR "WARNING: $without_strand markers have no strand information and their genotypes are treated as zero\n";
}
sub pairnt {
@_ == 2 or die "Error: subroutine pairnt() requires two arguments: <@_>\n";
my ($nt1, $nt2) = @_;
if ($nt1 eq 'A' and $nt2 eq 'T' or $nt1 eq 'T' and $nt2 eq 'A' or $nt1 eq 'C' and $nt2 eq 'G' or $nt1 eq 'G' and $nt2 eq 'C') {
return 1;
} else {
return 0;
}
}
sub complement {
my ($nt) = @_;
$nt =~ tr/ACGT/TGCA/;
return $nt;
}
sub readSNPTableFile {
my ($snptablefile) = @_;
my ($name_index, $snp_index, $ilmn_index, $cust_index);
my @record;
my %rev = ('A'=>'T', 'C'=>'G', 'G'=>'C', 'T'=>'A');
my (%ilmn_strand, %cust_strand, @indel, @no_anno);
open (SNPTABLE, $snptablefile) or confess "Error: cannot read from SNP Table file $snptablefile: $!";
print STDERR "NOTICE: Reading SNP Table file $snptablefile ...";
$_ = <SNPTABLE>;
s/[\r\n]+$//;
@record = split (/\t/, $_);
@record >= 4 or confess "Error: invalid record found in SNP Table file $snptablefile (at least 4 tab-delimited fields expected): <$_>\n";
for my $i (0 .. @record-1) {
$record[$i] eq "Name" and $name_index = $i;
$record[$i] eq "SNP" and $snp_index = $i;
$record[$i] eq "ILMN Strand" and $ilmn_index = $i;
$record[$i] eq "Customer Strand" and $cust_index = $i;
}
defined $name_index and defined $snp_index and defined $ilmn_index and defined $cust_index or confess "Error: cannot find Name, SNP, ILMN Strand or Customer Strand column in the first line of SNP Table file $snptablefile: <$_>\n";
while (<SNPTABLE>) {
s/[\r\n]+$//;
@record = split (/\t/, $_);
@record >= 4 or confess "Error: invalid record found in SNP Table file $snptablefile (at least 4 tab-delimited fields expected): <$_>\n";
my ($name, $snp, $ilmn, $cust) = @record[$name_index, $snp_index, $ilmn_index, $cust_index];
$ilmn = uc $ilmn; #sometimes is is annotated as Bot and Top
$cust = uc $cust;
if ($snp eq '[D/I]' or $snp eq '[I/D]') { #for example, rs17838100 is an insertion/deletion polymorphism
$ilmn =~ m/^[PM]$/ and $cust =~ m/^[PM]$/ or confess "Error: invalid ILMN/Customer Strand found for insertiion/deletion ('P' or 'M' expected): <$ilmn> or <$cust> in <$_>\n";
push @indel, $name;
$snp =~ s/[\[\]\/]//g;
$ilmn_strand{$name} = $snp;
$cust_strand{$name} = $snp;
next;
}
if ($snp eq '[N/A]') {
push @no_anno, $name;
next;
}
if ($ilmn eq 'P' or $cust eq 'P') {
push @no_anno, $name;
next;
}
$ilmn =~ m/^TOP|BOT$/ or confess "Error: invalid ILMN Strand found ('TOP' or 'BOT' expected): <$ilmn> in <$_>\n";
$cust =~ m/^TOP|BOT$/ or confess "Error: invalid Customer Strand found ('TOP' or 'BOT' expected): <$cust> in <$_>\n";
$snp =~ m#^\[(\w)/(\w)\]$# or confess "Error: Invalid SNP allele designation found: <$snp>\n";
my ($a1, $a2) = ($1, $2);
if ($ilmn eq 'TOP') {
if ($cust eq 'TOP') {
$ilmn_strand{$name} = $a1 . $a2;
$cust_strand{$name} = $a1 . $a2;
} elsif ($cust eq 'BOT') {
$ilmn_strand{$name} = $a1 . $a2;
$cust_strand{$name} = $rev{$a1} . $rev{$a2};
} else {
confess "Error: Neither TOP nor BOT is specified for the Customer strand: <$cust>\n";
}
} elsif ($ilmn eq 'BOT') {
if ($cust eq 'TOP') {
$ilmn_strand{$name} = $rev{$a1} . $rev{$a2};
$cust_strand{$name} = $rev{$a1} . $rev{$a2};
} elsif ($cust eq 'BOT') {
$ilmn_strand{$name} = $rev{$a1} . $rev{$a2};
$cust_strand{$name} = $a1 . $a2;
} else {
confess "Error: Neither TOP nor BOT is specified for the Customer strand: <$cust>\n";
}
} else {
confess "Error: Neither TOP nor BOT is specified for the ILMN strand: <$ilmn>\n";
}
}
close (SNPTABLE);
print STDERR " Done with ${\(scalar keys %ilmn_strand)} SNPs\n";
@indel and print STDERR "NOITCE: ${\(scalar @indel)} insertion/deletion polymorphism are annotated in $snptablefile (examples:", join (',', splice (@indel, 0, 3)), ")\n";
@no_anno and print STDERR "WARNING: ${\(scalar @no_anno)} ALLELE UNKNOWN markers are annotated in $snptablefile (example:", join (',', splice (@no_anno, 0, 3)), ")\n";
my %indel = map {$_, 1} @indel;
my %no_anno = map {$_, 1} @no_anno;
return (\%ilmn_strand, \%cust_strand, \%indel, \%no_anno);
}
=head1 SYNOPSIS
convert_bim_allele.pl [arguments] <bimfile> <snptablefile>
Optional arguments:
-h, --help print help message
-m, --man print complete documentation
-v, --verbose use verbose output
--intype <ilmn12|ilmnab|top|dbsnp|forward> specify input type
--outtype <ilmn12|ilmnab|top|dbsnp|forward> specify output type
--force force execution when allele mismatch is detected (output zero allele)
--replacezero replace the zero (unobserved) allele by known allele (default: output zero allele)
--outfile <file> specify output file name (default: STDOUT)
--autoflip automatically flip strand where appropriate
--strandfile <file> specify a file with dbSNP strand information
Function: convert a BIM file so that the allele names are changed to the
specified outtype.
Notes: ilmn12=Illumina AB allele designation coded as 1 and 2
ilmnab=Illumina AB allele designation
top =Illumina Top Allele call
dbsnp =dbSNP (not necessarily forward) allele designation
forward=forward strand in reference genome
Example: convert_bim_allele.pl old.bim hh550_610.snptable -outfile new.bim -intype ilmnab -outtype top
convert_bim_allele.pl old.bim hh550_610.snptable -outfile new.bim -intype top -outtype dbsnp
=head1 OPTIONS
=over 8
=item B<--help>
print a brief usage message and detailed explanation of options.
=item B<--man>
print the complete manual of the program.
=item B<--verbose>
use verbose output.
=item B<--intype>
specify the intype of allele names in the BIM file. The type can be ilmn12 (1/2
designation), ilmnab (A/B designation), top (TOP allele) and dbsnp (allele in
forward strand), with the ilmn12 being the default option.
=item B<--outtype>
specify the outtype of allele names in the generated new BIM file. The dbsnp is
the default output option.
==item B<--force>
force the program to continue (but print out a warning message) when allele
mismatch (between input BIM file and the SNPTABLE file) is detected, so that
users can inspect all the mismatches based on the warning message. The alleles
with strand mismatch will be printed out as 0. Normally, when this occurs, the
program will throw out an error and stop; this argument helps user to manually
inspect all SNPs showing these problems (usually caused by the use of different
genome assemblies).
=item B<--replacezero>
replace unobserved alleles in BIM file by the predicted actual allele from the
SNPTABLE file. When both alleles are unobserved (SNP has no genotyping call at
all), two alleles are randomly assigned. When one allele is unobserved
(annotated as zero in the BIM file), it will be filled in based on the other
allele.
=item B<--outfile>
specify the output file. When the argument is not specified, the output will be
printed to the STDOUT.
=item B<--autoflip>
automaticallly flip the allele strands, when dbSNP is the input type, and when
the allele designation for input differ from those in the SNPTableFile.
=item B<--strandfile>
specify a file with dbSNP strand information. This file can be generated by the
user, for example, first download
http://hgdownload.cse.ucsc.edu/goldenPath/hg19/database/snp138.txt.gz then "cut
-f 5,7 snp138.txt > strandfile".
=back
=head1 DESCRIPTION
This program is used to convert allele names in a BIM file, based on specified
-intype and -outtype arguments in the command line. BIM file is a file generated
by the PLINK software when creating a binary PED file with --make-bed argument.
The BIM file contains information, including allele names, for each SNP.
One common use of the allele name conversion is to do imputation analysis, since
such analysis typically requires that allele names follow forward strand
designation of the dbSNP data.
=head2 Annotation mistake in HapMap or dbSNP
Since human genome assembly is not perfect, there is no doubt that annotation
mistakes exist in databases. Generally speaking, only dozens of mistakes should
be present for each chromoome.
The mistakes can be several types:
1. The forward allele is annotated errananeouly in HapMap haplotype phasing file.
2. Discordant strand designation in different sequencing builds, or different
SNP submission batches.
=back
=cut