I have used BEDtools to convert bam file into bed format.
How to convert bed to wig file? Thanks.
How to convert bed to wig file? Thanks.
You are currently viewing the SEQanswers forums as a guest, which limits your access. Click here to register now, and join the discussion
#!/usr/bin/perl -w
use strict;
#This script takes in a standard .bed file (chromstart in column 2, chromend in column 3) and converts it to a .wig file
my $file = $ARGV[0]; my $file2 = substr($file, 0, - 4); my $outfile = "$file2.wig"; #get input filename, replace extension
my $bp = 0;
my @data = 0;
my $read = 0;
my @hits = ();
open (IN, "<$file") || die "the file $file did not open $!\n"; #open file specified by user
open (OUT, ">> $outfile") || die " $!\n"; #open the output file
while(<IN>){ #for each line
my @column = split("\t"); #split on tab
my $start = $column[1]; #start bp is column 2
my $end = $column[2]; #end bp is column 3
chomp($end);
my $length = $end-$start; #determinet length of read
$read++; #increase counter by 1
# print "Read $read starts at $start and ends at $end and is $length bp long.\n"; #troubleshooting line to make sure each line is being read correctly
for(my $bp = $start; $bp <= $end; $bp++){ #from first to last bp of read
$hits[$bp]++; #increment corresponding position by one
# print "bp $bp now has @hits[$bp] hit(s)\n"; #troubleshooting line to monitor hits at each bp
}
}
close IN;
my $count = 0;
my $item = 0;
my $site = 0;
foreach $item (@hits){ #for each line of hits
$site++; #increase the count at that site
if (defined $item){ #will print out for all non-zero sites
print OUT "$site\t$item\n";
$count++;
}
}
print "There were $read reads.\n$count sites (individual bp's) had at least one hit.\n";
close OUT;
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by SEQadmin2, Yesterday, 11:08 AM
|
0 responses
7 views
0 reactions
|
Last Post
by SEQadmin2
Yesterday, 11:08 AM
|
||
|
Started by SEQadmin2, 06-30-2026, 05:37 AM
|
0 responses
11 views
0 reactions
|
Last Post
by SEQadmin2
06-30-2026, 05:37 AM
|
||
|
Started by SEQadmin2, 06-26-2026, 11:10 AM
|
0 responses
19 views
0 reactions
|
Last Post
by SEQadmin2
06-26-2026, 11:10 AM
|
||
|
Whole-Genome Sequencing Traces Faroe Islands Ancestry to a North Atlantic Founder Population
by SEQadmin2
Started by SEQadmin2, 06-17-2026, 06:09 AM
|
0 responses
53 views
0 reactions
|
Last Post
by SEQadmin2
06-17-2026, 06:09 AM
|
Comment