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
        Advancing Precision Medicine for Rare Diseases in Children
        by seqadmin




        Many organizations study rare diseases, but few have a mission as impactful as Rady Children’s Institute for Genomic Medicine (RCIGM). “We are all about changing outcomes for children,” explained Dr. Stephen Kingsmore, President and CEO of the group. The institute’s initial goal was to provide rapid diagnoses for critically ill children and shorten their diagnostic odyssey, a term used to describe the long and arduous process it takes patients to obtain an accurate...
        12-16-2024, 07:57 AM
      • seqadmin
        Recent Advances in Sequencing Technologies
        by seqadmin



        Innovations in next-generation sequencing technologies and techniques are driving more precise and comprehensive exploration of complex biological systems. Current advancements include improved accessibility for long-read sequencing and significant progress in single-cell and 3D genomics. This article explores some of the most impactful developments in the field over the past year.

        Long-Read Sequencing
        Long-read sequencing has seen remarkable advancements,...
        12-02-2024, 01:49 PM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by seqadmin, 12-17-2024, 10:28 AM
      0 responses
      27 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 12-13-2024, 08:24 AM
      0 responses
      43 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 12-12-2024, 07:41 AM
      0 responses
      29 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 12-11-2024, 07:45 AM
      0 responses
      42 views
      0 likes
      Last Post seqadmin  
      Working...
      X