-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtruncbg.pl
executable file
·66 lines (54 loc) · 1.48 KB
/
truncbg.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
#! /usr/bin/perl
####################
# truncwig.pl - given a chrom.sizes file and a single chromosome vstep wig file, truncate the wig so it doesn't go past the end of chrom.
# By Madelaine Marchin
# 7/2009
####################
use strict;
use DBI;
use lib "/home/mcm";
use Locations;
use POSIX;
my ($pos,$value,$chromsizes_filename,$wig_filename,$contents,@chromsizes,@wig,$junk,$rest,$wigchrom,$chrom,$length,$maxlen);
$chromsizes_filename = $ARGV[0];
$wig_filename = $ARGV[1];
$contents = get_file_data($chromsizes_filename);
@chromsizes = split(/\n/,$contents);
$contents = get_file_data($wig_filename);
@wig = split(/\n/,$contents);
foreach my $line (@chromsizes)
{
($chrom,$length) = split("\t",$line);
$hash{$chrom} = $length;
}
foreach my $line (@wig)
{
($chrom,$start,$end,$value) = split("\t",$line);
if($end < $hash{$chrom})
{
print "$line\n";
}
else
{
# print "$chrom\t$start\t$end\t$hash{$chrom}\n";
}
}
######################################################
# subroutine get_file_data
# arguments: filename
# purpose: gets data from file given filename;
# returns file contents
######################################################
sub get_file_data
{
my($filename) = @_;
my @filedata = ();
unless( open(GET_FILE_DATA, $filename))
{
print STDERR "Cannot open file \"$filename\": $!\n\n";
exit;
}
@filedata = <GET_FILE_DATA>;
close GET_FILE_DATA;
return join('',@filedata);
}