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
        Current Approaches to Protein Sequencing
        by seqadmin


        Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
        04-04-2024, 04:25 PM
      • seqadmin
        Strategies for Sequencing Challenging Samples
        by seqadmin


        Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
        03-22-2024, 06:39 AM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by seqadmin, 04-11-2024, 12:08 PM
      0 responses
      30 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 04-10-2024, 10:19 PM
      0 responses
      32 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 04-10-2024, 09:21 AM
      0 responses
      28 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 04-04-2024, 09:00 AM
      0 responses
      53 views
      0 likes
      Last Post seqadmin  
      Working...
      X