Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Gene 12 Column BED file

    Hello,
    I'd like a gene level 12 column bed file for Ensembl v65 Mus musculus, however I cannot find such a file (those in the ensembl archive site are 12 column transcript bed files).

    This file should contain one 12 column bed entry per gene, with all exons from all transcripts merged if necessary (eg boundaries extended if the exons overlap).

    Does anyone know if such a file exists?

    Alternatively, I can make one, but would like to avoid having to code it myself. At my disposal I have a GTF file, and can make a 12 column transcript BED file. BEDtools has the mergeBed tool, however this merges by exon coordinates, not gene ID.

    Has anyone coded this?

    Cheers!

  • #2
    I ended up coding it up. Only briefly tested but seems to do the trick, hope it's useful if anyone else needs such a script. Requires Bedtools.

    Code:
    #! /usr/bin/perl -w
    
    # merge the exons from all transcripts for a given gene into a single 12 col bed line
    # for each individual gene.
    
    # Requires BEDTools to be installed and in $PATH
    
    # ARGV[0] is a transcript BED file (eg as downloaded from ensembl)
    # ARGV[1] is a tab delimited text file with geneID<tab>transcriptID for every transcript
    # ARGV[2] is a working directory for tmp files.
    
    # prints new BED file to STDOUT.
    
    use strict;
    use warnings;
    use Data::Dumper;
    
    my $usage = "usage: perl $0 <transcriptBedFile> <transcript2GeneFile> <workingdir>\n";
    
    my $txBedFile = shift or die $usage;
    my $tx2GeneFile = shift or die $usage;
    my $workingdir = shift or die $usage;
    
    
    # load all the transcripts and gene info
    my %gene2tx = ();
    open(TX2GENE, $tx2GeneFile) or die;
    while (<TX2GENE>) {
    	chomp;
    	my @d = split/\t/;
    	push(@{$gene2tx{$d[0]}}, $d[1]);
    }
    close TX2GENE;
    
    # load all the bed lines:
    my %bed = ();
    open(TXBED, $txBedFile) or die;
    while (<TXBED>) {
    	my @d = split/\t/;
    	$bed{$d[3]} = $_;
    }
    close TXBED;
    
    
    # for each gene write all 12 col transcript lines, transform to a 6 col bed, sort, then merge exons, load, and write new
    # bed file.
    foreach my $gene (keys %gene2tx) {
    	my @transcripts = @{$gene2tx{$gene}};
    	my $geneTx12Bed = "$workingdir/$gene.tx.12.bed";
    	my $geneTx6Bed = "$workingdir/$gene.tx.6.bed";
    	my $geneExonsBed = "$workingdir/$gene.exons.merged.bed";
    	
    	open(TX12, ">$geneTx12Bed") or die "Failed to write to $geneTx12Bed: $!\n";
    	foreach my $tx (@transcripts) { print TX12 $bed{$tx}; }
    	close TX12;
    	
    	system "bed12ToBed6 -i $geneTx12Bed | sort -k1,1 -k2,2n > $geneTx6Bed";
    	system "mergeBed -i $geneTx6Bed | sort -k1,1 -k2,2n > $geneExonsBed";
    
    	my $strand = `cut -f 6 $geneTx6Bed | sort | uniq`;
    	chomp $strand;
    
    	open(EXONS, "$geneExonsBed") or die "Faield to read from $geneExonsBed: $!\n";
    	my $geneChr = undef;
    	my $geneChrStart = undef;
    	my $geneChrEnd = undef;
    	my @exonStarts = ();
    	my @exonLengths = ();
    	while (<EXONS>) {
    		chomp;
    		my ($chr, $start, $end) = split /\t/;
    		unless(defined($geneChrStart)) {
    			$geneChrStart = $start;
    			$geneChr = $chr;
    		}
    
    		push(@exonStarts, $start - $geneChrStart);
    		push(@exonLengths, ($end - $start));
    		$geneChrEnd = $end;
    	}
    	
    	my @bedLine = (
    		$geneChr,
    		$geneChrStart,
    		$geneChrEnd,
    		$gene,
    		0,
    		$strand,
    		$geneChrStart,
    		$geneChrEnd,
    		0,
    		scalar (@exonStarts),
    		join(",",@exonLengths).",",
    		join(",",@exonStarts).",",
    		);
    	
    	print join("\t", @bedLine),"\n";
    	
    	system "rm $geneTx12Bed $geneTx6Bed $geneExonsBed";
    }

    Comment


    • #3
      Hey Obifro,

      Cool job!!! I was about to code for a script when I came across your post. It saved me some time. Thanks.

      Comment

      Latest Articles

      Collapse

      • seqadmin
        Non-Coding RNA Research and Technologies
        by seqadmin




        Non-coding RNAs (ncRNAs) do not code for proteins but play important roles in numerous cellular processes including gene silencing, developmental pathways, and more. There are numerous types including microRNA (miRNA), long ncRNA (lncRNA), circular RNA (circRNA), and more. In this article, we discuss innovative ncRNA research and explore recent technological advancements that improve the study of ncRNAs.

        Nobel Prize for MicroRNA Discovery
        This week,...
        10-07-2024, 08:07 AM
      • seqadmin
        Recent Developments in Metagenomics
        by seqadmin





        Metagenomics has improved the way researchers study microorganisms across diverse environments. Historically, studying microorganisms relied on culturing them in the lab, a method that limits the investigation of many species since most are unculturable1. Metagenomics overcomes these issues by allowing the study of microorganisms regardless of their ability to be cultured or the environments they inhabit. Over time, the field has evolved, especially with the advent...
        09-23-2024, 06:35 AM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by seqadmin, Today, 06:35 AM
      0 responses
      7 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, Yesterday, 02:44 PM
      0 responses
      7 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 10-11-2024, 06:55 AM
      0 responses
      15 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 10-02-2024, 04:51 AM
      0 responses
      111 views
      0 likes
      Last Post seqadmin  
      Working...
      X