forked from WGLab/PennCNV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan_region.pl
executable file
·1377 lines (1109 loc) · 59.8 KB
/
scan_region.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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
use warnings;
use strict;
use Carp;
use Pod::Usage;
use Getopt::Long;
our $VERSION = '$Revision: bbb13c8a31de6a6e9a1e71ca347a7d02a855a27b $';
our $LAST_CHANGED_DATE = '$LastChangedDate: 2011-01-17 01:16:59 -0800 (Mon, 17 Jan 2011) $';
our ($verbose, $help, $man);
our ($queryfile, $dbfile);
our ($snp_flag, $score_threshold, $normscore_threshold, $overlap, $dbregion, $append, $condense_query, $mce_flag, $phastcons_flag, $evofold_flag, $tfbs_flag,
$wgrna_flag, $refgene_flag, $segdup_flag, $knowngene_flag, $test_flag, $anno_flag, $refcds_flag, $refexon_flag,
$autoexpand, $expandleft, $expandright, $expandmax, $bothside, $strand, $minoverlap, $kgxref, $reflink, $name2_flag, $quiet, $maxoverlap, $expanddb,
$maxquerydbratio, $minquerydbratio, $mindbfrac, $maxdbfrac, $minqueryfrac, $maxqueryfrac, $queryinfo);
GetOptions('verbose|v'=>\$verbose, 'help|h'=>\$help, 'man|m'=>\$man, 'snp_flag'=>\$snp_flag, 'score_threshold=f'=>\$score_threshold,
'normscore_threshold=i'=>\$normscore_threshold, 'overlap'=>\$overlap, 'dbregion'=>\$dbregion,
'append'=>\$append, 'condense_query'=>\$condense_query,
'mce_flag'=>\$mce_flag, 'phastcons_flag'=>\$phastcons_flag, 'evofold_flag'=>\$evofold_flag, 'tfbs_flag'=>\$tfbs_flag, 'wgrna_flag'=>\$wgrna_flag,
'refgene_flag'=>\$refgene_flag, 'segdup_flag'=>\$segdup_flag, 'knowngene_flag'=>\$knowngene_flag, 'test_flag'=>\$test_flag, 'anno_flag'=>\$anno_flag,
'refcds_flag'=>\$refcds_flag, 'refexon_flag'=>\$refexon_flag,
'expandleft=s'=>\$expandleft, 'expandright=s'=>\$expandright, 'expandmax=s'=>\$expandmax, 'bothside'=>\$bothside, 'expanddb=s'=>\$expanddb,
'strand=s'=>\$strand, 'kgxref=s'=>\$kgxref, 'reflink=s'=>\$reflink, 'name2_flag'=>\$name2_flag, 'quiet'=>\$quiet,
'minoverlap=f'=>\$minoverlap, 'maxoverlap=f'=>\$maxoverlap, 'maxquerydbratio=f'=>\$maxquerydbratio, 'minquerydbratio=f'=>\$minquerydbratio,
'mindbfrac=f'=>\$mindbfrac, 'maxdbfrac=f'=>\$maxdbfrac, 'minqueryfrac=f'=>\$minqueryfrac, 'maxqueryfrac=f'=>\$maxqueryfrac,
'queryinfo'=>\$queryinfo) 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");
($queryfile, $dbfile) = @ARGV;
#preparing default parameters
$snp_flag and pod2usage ("Error in argument: the --snp_flag argument is in development");
$strand and $strand =~ m/^(plus|minus|forward|reverse)$/ || pod2usage ("Error in argument: the --strand argument can be set as only plus (forward) or minus (reverse)");
$minoverlap ||= 0;
$expandleft ||= 0; $expandright ||= 0; $expandmax ||= 0;
if ($expandmax) {
$expandmax =~ s/k$/000/i; $expandmax =~ s/m$/000000/i;
$expandmax =~ m/^\d+$/ or pod2usage ("Error in argument: the --expandmax argument should be a positive integer (suffix of k and m are acceptable)");
$expandleft || $expandright and pod2usage ("Error in argument: please do not specify --expandleft or --expandright when --expandmax is specified");
}
if ($expandleft) {
$expandleft =~ s/k$/000/i; $expandleft =~ s/m$/000000/i;
$expandleft =~ m/^\d+$/ or pod2usage ("Error in argument: the --expandleft argument should be a positive integer (suffix of k and m are acceptable)");
}
if ($expandright) {
$expandright =~ s/k$/000/i; $expandright =~ s/m$/000000/i;
$expandright =~ m/^\d+$/ or pod2usage ("Error in argument: the --expandright argument should be a positive integer (suffix of k and m are acceptable)");
}
if ($expanddb) {
$expanddb =~ s/k$/000/i; $expanddb =~ s/m$/000000/i;
$expanddb =~ m/^\d+$/ or pod2usage ("Error in argument: the --expanddb argument should be a positive integer (suffix of k and m are acceptable)");
}
$name2_flag and $refgene_flag || pod2usage ("Error in argument: please do not specify --name2_flag unless --refgene_flag is specified");
$kgxref and $knowngene_flag || pod2usage ("Error in argument: please do not specify --kgxref unless --knowngene_flag is specified");
$reflink and $refgene_flag || $refexon_flag || $refcds_flag || pod2usage ("Error in argument: please do not specify --reflink unless --refgene_flag/refexon_flag/refcds_flag is specified");
$queryinfo and $dbregion || pod2usage "Error in argument: the --qinfo argument can be used only if --dbregion is specified";
if ($minoverlap or $maxoverlap or $minquerydbratio or $maxquerydbratio or $mindbfrac or $maxdbfrac or $minqueryfrac or $maxqueryfrac) {
if ($mce_flag or $evofold_flag or $tfbs_flag or $wgrna_flag or $segdup_flag or $anno_flag or $knowngene_flag or $refgene_flag or $refcds_flag or $refexon_flag or $phastcons_flag) {
pod2usage ("Error in argument: the --minoverlap, --maxoverlap, --minquerydbratio, --maxquerydbratio, --mindbfrac, --maxdbfrac, --minqueryfrac, --maxqueryfrac arguments are applicable only to plain DB-file format");
}
my @arg = sort {$a<=>$b} ($minoverlap||0, $maxoverlap||0, $minquerydbratio||0, $mindbfrac||0, $maxdbfrac||0, $minqueryfrac||0, $maxqueryfrac||0);
$arg[0] >=0 and $arg[$#arg]<=1 or pod2usage ("Error in argument: the --minoverlap, --maxoverlap, --minquerydbratio, --maxquerydbratio, --mindbfrac, --maxdbfrac, --minqueryfrac, --maxqueryfrac arguments must be between 0 and 1");
}
if ($score_threshold or $normscore_threshold) {
if ($mce_flag or $evofold_flag or $tfbs_flag or $wgrna_flag or $segdup_flag or $anno_flag) {
pod2usage ("Error in argument: the --score_threshold or --normscore_threshold arguments are applicable only to selected UCSC annotation formats");
}
}
if ($expandmax or $expandleft or $expandright or $expanddb) {
unless ($mce_flag or $evofold_flag or $tfbs_flag or $wgrna_flag or $segdup_flag or $anno_flag or $knowngene_flag or $refgene_flag or $refcds_flag or $refexon_flag or $phastcons_flag) {
pod2usage ("Error in argument: the --expandmax, --expandleft, --expandright or --expanddb arguments are NOT applicable to plain DB-file format");
}
}
if ($mce_flag or $evofold_flag or $tfbs_flag or $wgrna_flag or $segdup_flag or $anno_flag) {
my ($chr_loc, $count_query_bp) = readChrLoc ($queryfile);
$condense_query and ($chr_loc, $count_query_bp) = condenseOverlap ($chr_loc);
$count_query_bp or print STDERR "WARNING: there is NOTHING in query to scan\n" and exit(0); #there is no query regions in the query-location-file
if ($mce_flag) {
scanUCSCRegion ($chr_loc, $dbfile, $count_query_bp, 'mce');
} elsif ($evofold_flag) {
scanUCSCRegion ($chr_loc, $dbfile, $count_query_bp, 'evofold');
} elsif ($tfbs_flag) {
scanUCSCRegion ($chr_loc, $dbfile, $count_query_bp, 'tfbs');
} elsif ($wgrna_flag) {
scanUCSCRegion ($chr_loc, $dbfile, $count_query_bp, 'wgrna');
} elsif ($segdup_flag) {
scanUCSCRegion ($chr_loc, $dbfile, $count_query_bp, 'segdup');
} elsif ($anno_flag) {
scanUCSCRegion ($chr_loc, $dbfile, $count_query_bp, 'anno');
}
} elsif ($knowngene_flag or $refgene_flag or $refcds_flag or $refexon_flag) {
if ($knowngene_flag) {
scanUCSCGene ($queryfile, $dbfile, 0, 'knowngene', $kgxref, $name2_flag);
} elsif ($refgene_flag) {
scanUCSCGene ($queryfile, $dbfile, 0, 'refgene', $kgxref, $name2_flag);
} elsif ($refcds_flag) {
scanUCSCGene ($queryfile, $dbfile, 0, 'refcds', $kgxref, $name2_flag);
} elsif ($refexon_flag) {
scanUCSCGene ($queryfile, $dbfile, 0, 'refexon', $kgxref, $name2_flag);
}
} elsif ($phastcons_flag) { #special treatment for phsatcons file
my ($chr_loc, $count_query_bp) = readChrLoc ($queryfile);
$count_query_bp or print STDERR "WARNING: there is NOTHING in query to scan\n" and exit(0); #there is no query regions in the query-location-file
print STDERR "NOTICE: the --phastcons flag requires condensing query regions into a set of non-overlapping regions\n";
($chr_loc, $count_query_bp) = condenseOverlap ($chr_loc);
scanPhastCons ($chr_loc, $dbfile, $count_query_bp);
} elsif ($test_flag) {
scanRegion ($queryfile, $dbfile);
} else {
scanRegion ($queryfile, $dbfile);
}
sub readChrLoc {
my ($queryfile) = @_;
my ($count_query_bp, $count_query_region, %chr_loc);
if ($queryfile eq 'stdin') {
*QUERY = *STDIN;
} else {
open (QUERY, $queryfile) or confess "Error: cannot read from query file $queryfile: $!"; #!
}
while (<QUERY>) {
/\S/ or next; #skip empty lines
s/[\r\n]+$//; #get rid of newline characters
m/^(chr)?(\w+):(\d+)(\-(\d+))?(.*)/ or confess "Error: invalid record in chromosome file: <$_>"; #might contain only one locatoin (SNP) or a start-end (for chromosome regions)
my ($chr, $loc_start, $loc_end, $other_info) = ($2, $3, $5, $6);
my $switch = 0; #switch start and end position
defined $loc_end or $loc_end = $loc_start;
defined $other_info or $other_info = '';
if ($loc_start > $loc_end) { #in-del mutation such as rs34899723 in human
$switch = 1;
($loc_start, $loc_end) = ($loc_end, $loc_start);
}
push @{$chr_loc{$chr}}, [$loc_start, $loc_end, $other_info, $switch];
$count_query_bp += ($loc_end-$loc_start+1);
$count_query_region++;
}
for my $chr (keys %chr_loc) {
@{$chr_loc{$chr}} = sort {$a->[0] <=> $b->[0]} @{$chr_loc{$chr}}; #sort the chr_location by the start position for each chr
}
$verbose and print STDERR "NOTICE: A total of $count_query_bp (possibly overlapped) base pairs found in $queryfile in ${\(scalar keys %chr_loc)} chromosomes: " , join (" ", sort keys %chr_loc), "\n";
return (\%chr_loc, $count_query_bp, $count_query_region);
}
sub scanPhastCons {
my ($chr_loc, $dbfile, $count_query_bp) = @_;
my ($chr, $start, $current_loc, $step, $qloc, $qpointer);
my ($count_db_bp, $count_db_bp_found) = (0, 0);
my (%chr_finish, %chr_pointer);
open (DB, $dbfile) or confess "Error: cannot read from database file $dbfile: $!";
while (<DB>) {
if (m/^fixedStep chrom=chr(\w+) start=(\d+) step=(\d+)$/) {
#$verbose and print STDERR "NOTICE: next header $_";
($chr, $start, $current_loc, $step) = ($1, $2-1, $2-1, $3); #the next line is the real start (so first minus 1 to get the real start)
$qloc = $chr_loc->{$chr} || undef;
$qpointer = $chr_pointer{$chr} || 0;
$step == 1 or confess "Error: multiple steps found in phastcons file";
} else {
length ($_) == 6 or die "Error: invalid record in db file: <$_>";
$current_loc++;
$count_db_bp++;
$verbose and $count_db_bp =~ m/000000$/ and print STDERR "NOTICE: Processing chr $chr in $count_db_bp base of dbfile $dbfile with $count_db_bp_found/$count_query_bp interested base pairs found in overlapping regions\n";
$qloc or next; #the $qloc is the query location array for this chromosome
$chr_finish{$chr} and next;
for my $i ($qpointer .. @$qloc-1) {
my ($qstart, $qend, $qinfo, $qswitch) = @{$qloc->[$i]};
if ($qend < $current_loc) {
$chr_pointer{$chr} = $i;
$i == @$qloc-1 and $chr_finish{$chr} = 1; #this chromosome is DONE
next;
} elsif ($qstart > $current_loc) {
last;
} else {
$count_db_bp_found++;
print $overlap?"$chr:$current_loc-$current_loc$qinfo":"$chr:$qstart-$qend$qinfo";
print $append?"\t$_":"\n";
}
}
}
}
}
sub scanRegion {
my ($queryfile, $dbfile) = @_;
my ($db_chr_loc, $count_db_bp, $count_db_region) = readChrLoc ($dbfile);
($db_chr_loc, $count_db_bp, $count_db_region) = condenseOverlap ($db_chr_loc); #condense overlapping regions in DB file into consensus regions
my ($chr_loc, $count_query_bp, $count_query_region) = readChrLoc ($queryfile);
$count_query_bp or print STDERR "WARNING: there is NOTHING in queryfile $queryfile to scan\n" and exit(0); #there is no query regions in the query-location-file
$condense_query and ($chr_loc, $count_query_bp, $count_query_region) = condenseOverlap ($chr_loc); #--condense_query is rarely necessary to be used
my ($count_db_bp_found, %chr_finish, %chr_pointer) = (0);
for my $chr (sort sortChr keys %$db_chr_loc) {
for my $nextregion (@{$db_chr_loc->{$chr}}) {
my ($start, $end) = @$nextregion;
my $qloc = $chr_loc->{$chr} or next; #skip this chromosome because query does not have anything on it
$chr_finish{$chr} and next; #skip this chromosome because it has been finished processing by query
my $pointer = $chr_pointer{$chr} || 0; #current pointer for this chromosome
for my $i ($pointer .. @$qloc-1) {
my ($qstart, $qend, $qinfo, $qswitch) = @{$qloc->[$i]};
if (defined $maxquerydbratio and ($qend-$qstart+1)/($end-$start+1) > $maxquerydbratio) {
next; #maximum allowable query/db size ratio difference (query is too big to claim overlap/similarity with db)
}
if (defined $minquerydbratio and ($qend-$qstart+1)/($end-$start+1) < $minquerydbratio) {
next; #minimum allowable query/db size ratio difference (query is too small to claim overlap/similarity with db)
}
if ($qend < $start) { #query end is before the start position of this db region
#db: <------------------------->
#query: <--->
$chr_pointer{$chr} = $i; #move the pointer only when qend<start (I thought this for a long time)
$i == @$qloc-1 and $chr_finish{$chr} = 1; #this chromosome is DONE
next;
} elsif ($qend <= $end) { #move pointer to this region? (probably NOT, especially when one query overlap with another)
if ($qstart >= $start) { #query contained completely within db region
#db: <-------------------------->
#query: <------------------>
$count_db_bp_found += ($qend-$qstart+1);
if (defined $minoverlap) {
1; #query is contained within hit
}
if (defined $maxoverlap) {
($qend-$qstart+1)/($end-$start+1) > $maxoverlap and next;
}
if (defined $mindbfrac) {
($qend-$qstart+1)/($end-$start+1) < $mindbfrac and next;
}
if (defined $maxdbfrac) {
($qend-$qstart+1)/($end-$start+1) > $maxdbfrac and next;
}
if (defined $minqueryfrac) {
1;
}
if (defined $maxqueryfrac) {
1;
}
if ($dbregion) {
print "chr$chr:$start-$end", $queryinfo?$qinfo:""; #there is no qinfo for db region
} else {
print "chr$chr:$qstart-$qend$qinfo";
}
print "\n";
} else { #query overlap but upstream of db region
#db: <------------------------->
#query: <---------------------->
$count_db_bp_found += ($qend-$start+1);
if (defined $minoverlap) {
if (($qend-$start+1)/($qend-$qstart+1) < $minoverlap and ($qend-$start+1)/($end-$start+1) < $minoverlap) {
next;
}
}
if (defined $maxoverlap) {
if (($qend-$start+1)/($qend-$qstart+1) > $maxoverlap and ($qend-$start+1)/($end-$start+1) > $maxoverlap) {
next;
}
}
if (defined $mindbfrac) {
($qend-$start+1)/($end-$start+1) < $mindbfrac and next;
}
if (defined $maxdbfrac) {
($qend-$start+1)/($end-$start+1) > $maxdbfrac and next;
}
if (defined $minqueryfrac) {
($qend-$start+1)/($qend-$qstart+1) < $minqueryfrac and next;
#print "$queryinfo ($qend-$start+1)/($qend-$qstart+1) < $minqueryfrac\n";
}
if (defined $maxqueryfrac) {
($qend-$start+1)/($qend-$qstart+1) > $maxqueryfrac and next;
}
if ($dbregion) {
print $overlap?"chr$chr:$start-$qend$qinfo":"chr$chr:$start-$end", $queryinfo?$qinfo:"";
} else {
print $overlap?"chr$chr:$start-$qend$qinfo":"chr$chr:$qstart-$qend$qinfo";
}
print "\n";
}
} elsif ($qstart <= $end) {
if ($qstart >= $start) { #query overlap but downstream of db region
#db: <------------------------>
#query: <----------------------->
$count_db_bp_found += ($end-$qstart+1);
if (defined $minoverlap) {
if (($end-$qstart+1)/($qend-$qstart+1) < $minoverlap and ($end-$qstart+1)/($end-$start+1) < $minoverlap) {
next;
}
}
if (defined $maxoverlap) {
if (($end-$qstart+1)/($qend-$qstart+1) > $maxoverlap and ($end-$qstart+1)/($end-$start+1) > $maxoverlap) {
next;
}
}
if (defined $mindbfrac) {
($end-$qstart+1)/($end-$start+1) < $mindbfrac and next;
}
if (defined $maxdbfrac) {
($end-$qstart+1)/($end-$start+1) > $maxdbfrac and next;
}
if (defined $minqueryfrac) {
($end-$qstart+1)/($qend-$qstart+1) < $minqueryfrac and next;
}
if (defined $maxqueryfrac) {
($end-$qstart+1)/($qend-$qstart+1) > $maxqueryfrac and next;
}
#print "$queryinfo ($end-$start+1)/($qend-$qstart+1)\n";
if ($dbregion ) {
print $overlap?"chr$chr:$qstart-$end$qinfo":"chr$chr:$start-$end", $queryinfo?$qinfo:"";
} else {
print $overlap?"chr$chr:$qstart-$end$qinfo":"chr$chr:$qstart-$qend$qinfo";
}
print "\n";
} else { #db region completely contained within query
#db: <------------------------->
#query: <------------------------------>
$count_db_bp_found += ($end-$start+1);
if (defined $minoverlap) {
1;
}
if (defined $maxoverlap) {
($end-$start+1)/($qend-$qstart+1) > $maxoverlap and next;
}
if (defined $mindbfrac) {
1;
}
if (defined $maxdbfrac) {
1;
}
if (defined $minqueryfrac) {
($end-$start+1)/($qend-$qstart+1) < $minqueryfrac and next;
#print "$queryinfo ($end-$start+1)/($qend-$qstart+1)\n";
}
if (defined $maxqueryfrac) {
($end-$start+1)/($qend-$qstart+1) > $maxqueryfrac and next;
#print "$queryinfo ($end-$start+1)/($qend-$qstart+1)\n";
}
if ($dbregion) {
print $overlap?"chr$chr:$start-$end$qinfo":"chr$chr:$start-$end", $queryinfo?$qinfo:"";
} else {
print $overlap?"chr$chr:$start-$end$qinfo":"chr$chr:$qstart-$qend$qinfo";
}
print "\n";
}
} else {
#db: <---------->
#query: <----------------------->
last; #should examine next db region
}
}
}
$verbose and $count_db_region =~ m/00000$/ and print STDERR "NOTICE: Processing chr $chr in $count_db_region line of template file $dbfile with $count_db_bp_found/$count_query_bp interested base pairs found in overlapping regions\n";
}
$verbose and print STDERR "NOTICE: Total of $count_db_region template chr_regions (total of $count_db_bp) examined and found $count_db_bp_found / $count_query_bp (${\($count_db_bp_found / $count_query_bp)}) interested base pairs that belong to these template regions\n";
}
#this subroutine is used to scan various files downloaded from UCSC table browser (usually tab-delimited files). Many of them have the same or similar file formats
sub scanUCSCRegion {
my ($chr_loc, $dbfile, $count_query_bp, $dbtype) = @_;
my (%chr_warning, %chr_finish, %chr_pointer); #warning for no chr information in query file, chr in query has been finished processing, pointer to current query chr info
my ($count_db_bp, $count_db_region, $count_db_bp_found, $count_db_region_found) = (0, 0, 0, 0);
my @record;
my ($chr, $start, $end, $score, $normscore); #score is defined as LOD for MCE, Z for TFBS and conf for Evofold; normscore is between 0-1000
open (DB, $dbfile) or confess "Error: cannot read from database file $dbfile: $!";
while (<DB>) {
s/[\r\n]+$//; #deleting the newline characters
@record = split (/\t/, $_);
$record[0] eq '#bin' and next; #comment line
if ($dbtype eq 'mce') {
@record == 6 or confess "Error: invalid record in dbfile $dbfile (expecting 10 fields in evofold file): <$_>";
($chr, $start, $end, $score, $normscore) = ($record[1], $record[2], $record[3], $record[4], $record[5]);
$score =~ s/^lod=// or confess "Error: invalid lod score designation (no 'lod=' found) in dbfile $dbfile: <$_>";
} elsif ($dbtype eq 'evofold') {
@record == 10 or confess "Error: invalid record in dbfile $dbfile (expecting 10 fields in evofold file): <$_>";
($chr, $start, $end, $score, $normscore) = ($record[1], $record[2], $record[3], $record[5], $record[5]);
} elsif ($dbtype eq 'tfbs') {
@record == 8 or confess "Error: invalid record in dbfile $dbfile (expecting 10 fields in evofold file): <$_>";
($chr, $start, $end, $score, $normscore) = ($record[1], $record[2], $record[3], $record[7], $record[5]);
} elsif ($dbtype eq 'wgrna') {
@record == 10 or confess "Error: invalid record in dbfile $dbfile (expecting 10 fields in evofold file): <$_>";
($chr, $start, $end, $score, $normscore) = ($record[1], $record[2], $record[3], $record[5], $record[5]);
} elsif ($dbtype eq 'segdup') {
@record == 30 or confess "Error; invalid record in dbfile $dbfile (expecting 30 fields in segdup file): <$_>";
($chr, $start, $end, $score, $normscore) = @record[1, 2, 3, 5, 5];
} elsif ($dbtype eq 'anno') {
($chr, $start, $end, $score, $normscore) = @record[1, 2, 3, 5, 5];
} else {
confess "Error: the dbtype $dbtype cannot be handled by the current program";
}
if ($dbtype =~ m/^(mce|evofold|tfbs|wgrna|segdup|anno)$/) {
$score_threshold and $score < $score_threshold and next; #if --score_threshold is set, the low scoring segment will be skipped
$normscore_threshold and $normscore < $normscore_threshold and next; #if --normscore_threshold is set, the low scoring segment will be skipped
$start++; #due to the zero-opening coordinate system in UCSC
}
$chr =~ s/^chr// or confess "Error: invalid chromosome designation (no 'chr' found) in dbfile $dbfile: <$_>";
$count_db_region++;
$count_db_bp += ($end-$start+1);
my $qloc = $chr_loc->{$chr} or next; #skip this chromosome because query does not have anything on it
$chr_finish{$chr} and next; #skip this chromosome because it has been finished processing by query
my $pointer = $chr_pointer{$chr} || 0; #current pointer for this chromosome
for my $i ($pointer .. @$qloc-1) {
my ($qstart, $qend, $qinfo, $qswitch) = @{$qloc->[$i]};
if ($qend < $start) { #query end is before the start position of this db region
#db: <------------------------->
#query: <--->
$chr_pointer{$chr} = $i; #move the pointer only when qend<start (I thought this for a long time)
$i == @$qloc-1 and $chr_finish{$chr} = 1; #this chromosome is DONE
next;
} elsif ($qend <= $end) { #move pointer to this region? (probably NOT, especially when one query overlap with another)
if ($qstart >= $start) { #query contained completely within db region
#db: <-------------------------->
#query: <------------------>
$count_db_bp_found += ($qend-$qstart+1);
if ($dbregion) {
print "chr$chr:$start-$end"; #there is no qinfo for db region
} else {
print "chr$chr:$qstart-$qend$qinfo";
}
$append and print "\t$score\t$normscore";
print "\n";
} else { #query overlap but upstream of db region
#db: <------------------------->
#query: <---------------------->
$count_db_bp_found += ($qend-$start+1);
if ($minoverlap) {
if (($qend-$start+1)/($qend-$qstart+1) < $minoverlap and ($qend-$start+1)/($end-$start+1) < $minoverlap) {
next;
}
}
if ($dbregion) {
print $overlap?"chr$chr:$start-$qend$qinfo":"chr$chr:$start-$end";
} else {
print $overlap?"chr$chr:$start-$qend$qinfo":"chr$chr:$qstart-$qend$qinfo";
}
$append and print "\t$score\t$normscore";
print "\n";
}
} elsif ($qstart <= $end) {
if ($qstart >= $start) { #query overlap but downstream of db region
#db: <------------------------>
#query: <----------------------->
$count_db_bp_found += ($end-$qstart+1);
if ($minoverlap) {
if (($end-$qstart+1)/($qend-$qstart+1) < $minoverlap and ($end-$qstart+1)/($end-$start+1) < $minoverlap) {
next;
}
}
if ($dbregion ) {
print $overlap?"chr$chr:$qstart-$end$qinfo":"chr$chr:$start-$end";
} else {
print $overlap?"chr$chr:$qstart-$end$qinfo":"chr$chr:$qstart-$qend$qinfo";
}
$append and print "\t$score\t$normscore";
print "\n";
} else { #db region completely contained within query
#db: <------------------------->
#query: <------------------------------>
$count_db_bp_found += ($end-$start+1);
if ($dbregion) {
print $overlap?"chr$chr:$start-$end$qinfo":"chr$chr:$start-$end";
} else {
print $overlap?"chr$chr:$start-$end$qinfo":"chr$chr:$qstart-$qend$qinfo";
}
$append and print "\t$score\t$normscore";
print "\n";
}
} else {
last; #should examine next db region
}
}
$verbose and $count_db_region =~ m/00000$/ and print STDERR "NOTICE: Processing chr $chr in $count_db_region line of template file $dbfile with $count_db_bp_found/$count_query_bp interested base pairs found in overlapping regions\n";
}
$quiet or print STDERR "NOTICE: Total of $count_db_region template chr_regions (total of $count_db_bp) examined and found $count_db_bp_found / $count_query_bp (${\($count_db_bp_found / $count_query_bp)}) interested base pairs that belong to these template regions\n";
}
#this subroutine scan a queryfile against a knownGene file or refGene file from UCSC to identify the nearby genes for each query_region in queryfile
#instead of scanning each line in the template file, I decided to just read everything in memory, then process each query sequentially. this is conceptually different and opposite the scanDBRegion subroutine
sub scanUCSCGene {
my ($queryfile, $dbfile, $count_query_bp, $dbtype, $kgxref, $name2_flag) = @_;
my (%chr_warning, %chr_finish, %chr_pointer); #warning for no chr information in query file, chr in query has been finished processing, pointer to current query chr info
my ($count_db_bp, $count_db_region) = (0, 0);
my (%db_chr_loc);
my ($name, $chr, $dbstrand, $start, $end, $cdsstart, $cdsend, $exoncount, $exonstart, $exonend);
my ($gene_xref);
open (DB, $dbfile) or confess "Error: cannot read from database file $dbfile: $!";
while (<DB>) {
m/^#/ and next; #comment line
s/[\r\n]+$//; #deleting the newline characters
my @record = split (/\t/, $_);
if ($dbtype eq 'knowngene') {
@record == 12 or confess "Error: invalid record in dbfile $dbfile (expecting 12 fields in knownGene file): <$_>";
($name, $chr, $dbstrand, $start, $end, $cdsstart, $cdsend) = @record[0..6]; #human hg17
} elsif ($dbtype eq 'refgene' or $dbtype eq 'refcds' or $dbtype eq 'refexon') {
if (@record == 16) {
($name, $chr, $dbstrand, $start, $end, $cdsstart, $cdsend, $exoncount, $exonstart, $exonend) = @record[1..10]; #human hg18, mouse
$name2_flag and $name = $record[12];
} elsif (@record == 10) {
($name, $chr, $dbstrand, $start, $end, $cdsstart, $cdsend, $exoncount, $exonstart, $exonend) = @record; #rat, human hg17
$name2_flag and pod2usage ("Error in argument: the --name2_flag argument can be used only for refGene table with name2 annotations (such as those in hg18 and mm8 database)");
} else {
confess "Error: invalid record in template-location-file $dbfile (expecting 16 or 10 tab-delimited fields in refGene file): <$_>";
}
} else {
confess "Error: unknown dbtype flat: $dbtype\n";
}
if (defined $strand) { #only consider a particular strand (by default both strand will be considered)
$strand eq 'plus' || $strand eq 'forward' and $dbstrand eq '+' || next;
$strand eq 'minus' || $strand eq 'reverse' and $dbstrand eq '-' || next;
}
if ($expanddb) { #expand the definition of gene
$start -= $expanddb;
$end += $expanddb;
}
if ($dbtype eq 'knowngene' or $dbtype eq 'refgene') {
$start++; #due to the zero-opening coordinate system in UCSC
$chr =~ s/^chr// or confess "Error: invalid chromosome designation (no 'chr' found) in dbfile $dbfile: <$_>";
$count_db_region++;
$count_db_bp += ($end-$start+1);
push @{$db_chr_loc{$chr}}, [$start, $end, $name];
} elsif ($dbtype eq 'refcds') {
$cdsstart++; #due to the zero-opening coordinate system in UCSC
$chr =~ s/^chr// or confess "Error: invalid chromosome designation (no 'chr' found) in dbfile $dbfile: <$_>\n";
$count_db_region++;
$count_db_bp += ($cdsend-$cdsstart+1);
push @{$db_chr_loc{$chr}}, [$cdsstart, $cdsend, $name];
} elsif ($dbtype eq 'refexon') {
$chr =~ s/^chr// or confess "Error: invalid chromosome designation (no 'chr' found) in dbfile $dbfile: <$_>\n";
my @exonstart = split (/,/, $exonstart);
my @exonend = split (/,/, $exonend);
@exonstart == @exonend or confess "Error: invalid exon annotation in dbfile $dbfile (exonstart=@exonstart exonend=@exonend): <$_>\n";
map {$_++} @exonstart;
for my $i (0 .. @exonstart-1) {
$count_db_region++;
$count_db_bp += ($exonend[$i]-$exonstart[$i]+1);
push @{$db_chr_loc{$chr}}, [$exonstart[$i], $exonend[$i], $name];
}
}
}
for my $chr (sort keys %db_chr_loc) { #sort dbregion to make sure that smaller regions occur before bigger ones
@{$db_chr_loc{$chr}} = sort {$a->[0] <=> $b->[0] or $a->[1] <=> $b->[1]} @{$db_chr_loc{$chr}};
}
$verbose and print STDERR "NOTICE: Total of $count_db_region dbregions are found in $dbfile with $count_db_bp base pairs\n";
#now scan each query_loc against all sorted db entry in the template file
#by default, any gene/transcript/cds/exon overlapping with query will be printed out
#if no gene/transcript/cds/exon overlap, then the closest gene (as specified by --expandmax) will be printed out
#db: --------- ------------------- ----- ---------------
# -------- ------------------------- --- ------------- ----------
#query: <-------> <-------------------------->
# <---------> <-->
# <-->
if ($kgxref) { #in the output, rather than using gene identifier (name), use the corresponding gene symbol in the known gene cross-reference file
$gene_xref = readKgXref ($kgxref);
} elsif ($reflink) {
$gene_xref = readRefLink ($reflink);
}
if ($queryfile eq 'stdin') {
*QUERY = *STDIN;
} else {
open (QUERY, $queryfile) or confess "Error: cannot read from queryfile $queryfile: $!";
}
while (<QUERY>) {
s/[\r\n]+$//; #get rid of newline characters
/\S/ or next; #skip empty lines
m/^(chr)?(\w+):(\d+)(\-(\d+))?(.*)/ or confess "Error: invalid record in chromosome file: <$_>"; #might contain only one locatoin (SNP) or a start-end (for chromosome regions)
my ($chr, $qstart, $qend, $qinfo, $qswitch) = ($2, $3, $5||$3, $6||'');
if ($qstart > $qend) {
$qswitch = 1;
($qstart, $qend) = ($qend, $qstart);
}
my (@closest_gene, $closest_dist, @overlap);
my ($qstart_expand, $qend_expand) = ($qstart - $expandmax, $qend + $expandmax);
$expandleft and $qstart_expand = $qstart - $expandleft;
$expandright and $qend_expand = $qend + $expandright;
my $dbloc = $db_chr_loc{$chr};
if (not $dbloc) { #for example, when chr is 22_random, there is NO genes there
print "$chr:$qstart-$qend$qinfo\tNOT_FOUND\tNOT_FOUND\n";
next;
}
for my $j (0 .. @$dbloc-1) {
my ($dbstart, $dbend, $dbname) =@{$dbloc->[$j]};
$qstart_expand > $dbend and next; #the dbend has not reached expanded query yet
if ($qend >= $dbstart and $qstart <= $dbend) { #overlap found between query and db!
push @overlap, $dbname;
}
if (not @overlap and $expandleft || $expandright || $expandmax) {
if ($qend_expand >= $dbstart and $qstart_expand <= $dbend) { #overlap found between expanded query and db
my $dist;
if ($qend <= $dbstart) {
$dist = $dbstart-$qend;
} else {
$dist = $qstart-$dbend;
}
if ($closest_dist and $dist < $closest_dist) {
$closest_dist = $dist;
@closest_gene = $dbname;
} elsif (not defined $closest_dist or $dist == $closest_dist) {
$closest_dist = $dist;
push @closest_gene, $dbname;
}
}
}
$qend_expand < $dbstart and last; #the dbstart has passed expanded query
}
if ($kgxref or $reflink) {
@overlap = map {$gene_xref->{$_} || $_} @overlap;
@closest_gene = map {$gene_xref->{$_} || $_} @closest_gene;
}
my %seen;
@overlap = sort grep {!$seen{$_}++} @overlap;
@closest_gene = sort grep {!$seen{$_}++} @closest_gene;
if (@overlap) {
print "chr$chr:$qstart-$qend$qinfo\t", join(",", @overlap), "\t0\n";
} elsif (@closest_gene) {
print "chr$chr:$qstart-$qend$qinfo\t", join(",", @closest_gene), "\t$closest_dist\n";
} else {
print "chr$chr:$qstart-$qend$qinfo\tNOT_FOUND\tNOT_FOUND\n";
}
}
}
#sometimes two exons enclose with each other, sometimes two regions locate in two strands so have overlaps, so it is important to eliminate overlap positions
#this subroutine reduce overlaps, when feeded with a series of chromosome regions in two arrays, one for start position and one for end position
sub condenseOverlap {
my ($chr_loc) = @_;
my ($length, $newlength, $newcount) = (0, 0, 0);
for my $chr (keys %$chr_loc) {
my @loc = @{$chr_loc->{$chr}};
my @newloc;
my $pointer = 0;
my ($prestart, $preend) = ($loc[0]->[0], $loc[0]->[1]);
$length += $loc[0]->[1]-$loc[0]->[0]+1;
while (1) {
$pointer++; #process next segment
$pointer == @loc and last; #finish processing the loc array
$length += ($loc[$pointer]->[1]-$loc[$pointer]->[0]+1);
if ($loc[$pointer]->[0] <= $preend) { #start of next element less than end of previous element
if ($loc[$pointer]->[1] >= $preend) { #make sure the next element is not contained within the previous element
$preend = $loc[$pointer]->[1];
}
} else {
push @newloc, [$prestart, $preend, '', ''];
$newlength += ($preend-$prestart+1);
($prestart, $preend) = ($loc[$pointer]->[0], $loc[$pointer]->[1]);
}
}
push @newloc, [$prestart, $preend, '', '']; #process the last element
$newlength += ($preend-$prestart+1);
$newcount += @newloc;
$chr_loc->{$chr} = \@newloc;
}
$verbose and print STDERR "NOTICE: After cleaning query, the length of query changes from $length to $newlength\n";
return ($chr_loc, $newlength, $newcount);
}
sub sortChr {
my ($a, $b) = @_; #this line is required for functioning properly and I do not know why
if ($a =~ m/^(\d+)$/) {
if ($b =~ m/^(\d+)$/) {
return $a<=>$b;
} else {
return -1;
}
} elsif ($b =~ m/^(\d+)$/) {
return 1;
} else {
return $a cmp $b;
}
}
sub readKgXref {
my ($inputfile) = @_;
my (%gene_xref);
open (XREF, $inputfile) or confess "Error: cannot read from kgxref file $inputfile: $!";
while (<XREF>) {
m/^#/ and next;
my @record = split (/\t/, $_);
if ($gene_xref{$record[0]}) { #BC003168 occur twice in kgxref file (OSBPL10, BC003168)
if ($gene_xref{$record[0]} =~ m/^(BC|AK)\d+$/) {
$gene_xref{$record[0]} = $record[4];
}
} else {
$gene_xref{$record[0]} = $record[4];
}
}
close (XREF);
return (\%gene_xref);
}
sub readRefLink {
my ($inputfile) = @_;
my (%gene_xref);
open (REFLINK, $inputfile) or confess "Error: cannot read from refLink file $inputfile: $!";
while (<REFLINK>) {
m/^#/ and next;
my @record = split (/\t/, $_);
$gene_xref{$record[2]} = $record[0];
}
close (REFLINK);
return (\%gene_xref);
}
=head1 SYNOPSIS
scan_region.pl [arguments] <query-file> <DB-file>
Optional arguments:
-h, --help print help message
-m, --man print complete documentation
-v, --verbose use verbose output
Flags specifying type of db-file
--mce_flag dbfile is UCSC MCE annotation file
--evofold_flag dbfile is UCSC EvoFold annotation file
--tfbs_flag dbfile is UCSC TFBS annotation file
--wgrna_flag dbfile is UCSC wgRna annotation file
--knowngene_flag dbfile is UCSC knownGene annotation file
--refgene_flag dbfile is UCSC refGene annotation file
--phastcons_flag dbfile is UCSC phastcons conservation score file
--anno_flag dbfile is in generic UCSC annotation database format
--refexon_flag dbfile is UCSC refGene with exon annotation
--refcds_flag dbfile is UCSC refGene with coding sequence annotation
Criteria for defining query-db match
--condense_query condense and eliminate overlapping regions in query
--score_threshold <float> score threshold for db in UCSC annotation file
--normscore_threshold <float> normalized score threshold for db in UCSC annotation file
--minoverlap <float> minimum portion of overlap (either query or db) to decide query-db match
--maxoverlap <float> maximum portion of overlap (either query or db) to decide query-db match
--minquerydbratio <float> minimum query to db length ratio to decide match
--maxquerydbratio <float> maximum query to db length ratio to decide match
--mindbfrac <float> minimum fraction of db in overlap
--maxdbfrac <float> maximum fraction of db in overlap
--minqueryfrac <float> minimum fraction of query in overlap
--maxqueryfrac <float> maximum fraction of query in overlap
Expansion of query to find match:
--expandleft <int> expand left side of query regions (overwrite --expandmax)
--expandright <int> expand right side of query regions (overwrite --expandmax)
--expandmax <int> size of maximum expansion for query region to find overlap
Expansion of db to find match:
--expanddb <int> expand definition of gene/cds/exon at both sides
dbfile-specific arguments:
--kgxref <file> use gene symbol in known gene xref file in output
--reflink <file> use gene symbol in refGene link file in output
--name2_flag use name2 annotation in refGene file in output
Input/output options:
--quiet suppress printing progress messages
--append append extra information from annotation file to output
--dbregion print db region (default is to print query region)
--queryinfo force to print query info when --dbregion is used
--overlap print overlapped portion of region only
Function: scan genomic regions in a query-file against a DB-file which contains
chromosome locations for various genomics features
Example: scan_region.pl query.txt refGene.txt -refgene -reflink refLink.txt
scan_region.pl query.txt db.txt
scan_region.pl cnvcall.txt centromere.txt -minqueryfrac 0.5
Version: $LastChangedDate: 2011-01-17 01:16:59 -0800 (Mon, 17 Jan 2011) $
=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<--overlap>
instead of printing the query region, only print the overlapped portion of the
query region and template region.
=item B<--dbregion>
print the region in DB file, rather than query file, when an overlapped
hit is found
=item B<--append>
append the score and normscore for the overlapped template region to the output
for DB files downloaded as UCSC tables.
=item B<--condense_query>
condense overlapped regions in the query file into non-overlapped regions. When
this argument is set, the annotation for each query (the strings after the
chromosome location in each line of the query file) will not in the output.
=item B<--minoverlap>
the minimum percentage of overlap between query and DB chromosome region to
infer a matching event. By default, even a single base pair overlap will be
considered as overlap, but a lot of times people prefer to use something like
0.5 (50% overlap) to make sure that the query and DB regions have high
concordance. This argument operates by OR operation: if overlap for either query
or DB exceed the specified criteria, it will be treated as passing the criteria.
=item B<--maxoverlap>
the maximum percentage of overlap between query and DB chromosome region to
infer a matching event.
=item B<--minquerydbratio>
minimum query to db length ratio to infer a matching event
=item B<--maxquerydbratio>
maximum query to db length ratio to infer a matching event
=item B<--mindbfrac>
minimum fraction of db in overlap to infer a matching event
=item B<--maxdbfrac>
maximum fraction of db in overlap to infer a matching event
=item B<--minqueryfrac>
minimum fraction of query in overlap to infer a matching event
=item B<--maxdbfrac>
maximum fraction of query in overlap to infer a matching event
=item B<--score_threshold>
specify the score threshold in the DB file to include in the search for
overlaps. This argument is file format dependent.
=item B<--normscore_threshold>
specify the normalized score threshold in the DB file to include in the
search for overlaps. This argument is file format dependent.
=item B<--mce_flag>
specify that the DB file is in MCE format from UCSC genome browser
=item B<--evofold_flag>
specify that the DB file is in EvoFold format from UCSC genome browser
=item B<--tfbs_flag>
specify that the DB file is in TFBS format from UCSC genome browser
=item B<--wgrna_flag>
specify that the DB file is in WGRNA format from UCSC genome browser
=item B<--anno_flag>
generic UCSC genome browser annotation database format (first a few columns are
bin, chrom, chromStart, chromEnd, name)
=item B<--knowngene_flag>
specify that the DB file is in knownGene format from UCSC genome browser
=item B<--refgene_flag>
specify that the DB file is in refGene format from UCSC genome browser
=item B<--refcds_flag>
specify that the DB file is in refGene format from UCSC genome browser, but user
is only interested in the overlap of coding region (first exon to last exon).
=item B<--refexon_flag>
specify that the DB file is in refGene format from UCSC genome browser, but user
is only interested in the overlap of query with exons.
=item B<--phastcons_flag>
specify that the DB file is in phastcons format from UCSC genome browser
=item B<--expandleft>
expand the query region on the left side (5' in forward strand, 3' in reverse
strand) to find overlap (used in conjunction with --refgene or --knowngene
argument)
=item B<--expandright>
expand the query region on the right side (3' in forward strand, 5' in reverse
strand) to find overlap (used in conjunction with --refgene or --knowngene
argument)
=item B<--expandmax>
maximum expansion size of the query region on both side to find at least one
overlap (used in junction with --refgene or --knowngene argument). After query
expansion, only the closet gene will be printed; other genes, even if
overlapping with the query after expansion, will not be printed.
=item B<--expanddb>
expand the chromosome region specified in the DB-file to find overlap with the
query regions.
=item B<--reflink>
specify a cross-reference file for the RefGene track in UCSC genome browser,
so that in the output, the gene identifier (gene name or refseq id) are replaced
by the gene symbol specified in the link file. (If not found in the reflink
file, the gene identifiers are still used)
=item B<--kgxref>
specify a cross-reference file for the knownGene track in UCSC genome browser,
so that in the output, the gene identifier (gene name or refseq id) are replaced
by the gene symbol specified in the kgxref file. (If not found in the kgxref
file, the gene identifiers are still used)
=item B<--name2_flag>
this argument is used in conjunction with the --refgene argument, to specify
that the alternative gene symbol in the "name2" field in the refGene file be
printed in the output.
=back
=head1 DESCRIPTION
This program is used to scan chromosome regions from a query-location-file
against a db-location-file that has been sorted by chromosome and start
location. Both the query-location-file and the db-location-file contains one
chromosome location per line. GENERALLY SPEAKING, THE DB FILE MUST BE SORTED BY