Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • canisirius
    Junior Member
    • Nov 2011
    • 5

    Creating index for Annovar database file

    Hi,

    Anybody has idea how to create index file for the Annovar annotation database files.

    I am running Annovar with snp135_NonFlagged annotation file and it is taking a lot of time compared to snp135 which has .idx file.

    Thanks
  • lottpaul
    Junior Member
    • May 2013
    • 1

    #2
    Creating Annovar Index

    The Annovar idx format is as follows:

    1. File is tab separated.

    2. First Line: #BIN <BiN SIZE> <File Size>

    3. Remaining lines:
    <Chromosome> <BIN Starting Position> <Starting position in File> <Ending position in File>

    In Perl, the following routine would create the index of the file in a hash (dictionary/map), then you'd just need to print it out:

    Code:
    #!/usr/bin perl;
    use warnings;
    use strict;
    
    die "$0 <Annovar Database File> <BIN Size>" unless @ARGV == 2;
    my $input_file = $ARGV[0];
    my $bin_size = $ARGV[1];
     
    if (!-e $input_file) {
    	die "$input_file not found\n";
    }
    
    my $file_size = -s $input_file;
    
    my %index;
    open(my $in, "<", $input_file) or die "Couldn't open $input_file for indexing\n";
    
    my $previous_file_position = tell $in;
    
    while (my $ln = <$in>) {
    	
    	#Check input file. Some are (chr,start,stop) and others are (id,chr,start,stop).
    	#If you have the latter you'll need to change the next line to account for the id column   
    	my ($chr,$start,$stop) = split "\t", $ln;
    	my $bin_start = int($start/$bin_size) * $bin_size;
    	my $current_file_position = tell $in;
    
    	if (!exists $index{$chr}->{$bin_start}) {
    		$index{$chr}->{$bin_start} = [$previous_file_position, $current_file_position];
    	}
    	else{
    		$index{$chr}->{$bin_start}->[1] = $current_file_position;
    	}
    	
    	$previous_file_position = $current_file_position;
    }
    
    close $in;
    
    print "#BIN\t$bin_size\t$file_size\n";
    foreach my $chr ((1,10..19,2,20,21,22,3..9,"MT","X","Y")){ #Ordered array to match other Annovar idx files
    	foreach my $index_region (sort keys %{$index{$chr}}){
    		my $start	= $index{$chr}->{$index_region}->[0];
    		my $stop	= $index{$chr}->{$index_region}->[1];
    		print "$chr\t$index_region\t$start\t$stop\n";
    	}
    }
    I've checked the output against a couple idx files (clinvar20140702, AFR.sites.2012) provided by Annovar and get perfect agreement.
    Last edited by lottpaul; 05-29-2015, 07:42 AM. Reason: Complete Code

    Comment

    • molgen2
      Junior Member
      • May 2015
      • 1

      #3
      The script is not working for me. I get an error message ("$current_position" requires explicit package name). After changing $current_position to $current_file_position in line 27, I get error messages 'Argument "chr4" isn't numeric in division (/) at ./makeannovarindex.pl line 23, <$in> line 20493.'

      then I change line 22 from
      my ($chr,$start,$stop) = split "\t", $ln;
      to
      my ($junk,$chr,$start,$stop) = split "\t", $ln;

      the errors stop, but get no output (except for line 1: "#BIN 1000 24679810")

      Does anybody experience the same issues? Could anyone get this script working?

      Comment

      • canisirius
        Junior Member
        • Nov 2011
        • 5

        #4
        Hi,

        First of, thanks to lottpaul for providing the solutions.

        I have modified a line or two, I suppose. So I am attaching the script that I used finally.

        Following is the command, I used to run the script.

        Code:
        perl compileAnnnovarIndex.pl hg19_snp138NonFlagged.txt 1000 > hg19_snp138NonFlagged.txt.idx
        I hope it works for you too.
        Attached Files

        Comment

        Latest Articles

        Collapse

        • SEQadmin2
          From Collection to Sequencing: Why Sample Preparation and Preservation Define Sequencing Data
          by SEQadmin2


          Data variability is still an issue in sequencing technologies despite the advances in reproducibility and accuracy of these platforms. But the problem does not originate in the sequencing itself, but in the previous steps, before the sample reaches the sequencer.


          The first step is collection, followed by preservation and sample preparation for analysis. Most scientists overlook those steps, but not being careful might just be skewing the experiment’s results.
          ...
          06-02-2026, 10:05 AM
        • SEQadmin2
          Single-Cell Sequencing at an Inflection Point: Early Impacts of New Platforms and Emerging Trends
          by SEQadmin2


          With the launch of new single-cell sequencing platforms in 2026, the field stands at an exciting inflection point. This article surveys the most impactful advances in the field and discusses how they’re reshaping research in cancer, immunology, and beyond.


          Introduction

          Single-cell sequencing technologies have undergone remarkable advances over the past decade, transitioning from low-throughput experimental approaches to highly scalable platforms capable of...
          05-22-2026, 06:42 AM
        • SEQadmin2
          Environmental Genomics in the Age of NGS: From Microbes to Conservation Strategies
          by SEQadmin2

          Studying ecosystems means dealing with complex, multi-species communities that are hard to observe at scale. This complexity, however, hides many important questions to be answered, from how biogeochemical cycles work and how climate change can affect species distribution to how conservation strategies can work best.


          Genomics, particularly since the expansion of NGS, has transformed ecosystem ecology. By sequencing environmental DNA, we can now assess biodiversity without direct...
          05-06-2026, 09:04 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by SEQadmin2, Today, 08:59 AM
        0 responses
        10 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 06-02-2026, 12:03 PM
        0 responses
        21 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 06-02-2026, 11:40 AM
        0 responses
        17 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 05-28-2026, 11:40 AM
        0 responses
        31 views
        0 reactions
        Last Post SEQadmin2  
        Working...