Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • uloeber
    Member
    • Mar 2013
    • 44

    #1

    Parsing Blast xml using Perl (BioPerl)

    Hi people,
    I'd like to resolve the following problem(s):

    I'm trying to resolve the structure of reads, partial of retroviral origin, partial of host genomic origin. In addition, I'd like to detect primer binding sites for a certain primer pair.

    My approach was to blast my sequences against the virus, the genome and the primer. In theory I could construct one big database, but for the primers I used blastn, while megablast was much faster and appropriate for the other two databases.

    Eyeballing the results, I can "easily" determine virus,genome and primer. Now I tried to parse my blast results to filter out overlapping hit (the genome has multiple insertions of the virus which will match every viral structure and I only want to extract genome hits without any overlap to any other db ref).

    important would be, that a genomic hit overlapping with any other hits will be sorted out (marked with x)

    Right at the beginning, the following problem came up:
    Parsing blast xml with BioPerls SearchIO gives me only one query all the time! Here is the test code I used:

    Code:
    #! /usr/bin/perl -w
    use strict;
    use Bio::Perl;
    use Bio::SearchIO;
    
    my $hitcountMAN=0;
    my $test;
    
      # Get the report 
    my  $searchio = Bio::SearchIO  ->new (
                                            -format => 'blastxml',
                                            -file   => $ARGV[0]);
    
    while(my $result = $searchio->next_result){
            my  $algorithm_type =  $result->algorithm;
            my $algorithm_version = $result ->algorithm_version;
    
            while (my $hit = $result->next_hit) {
                    my  $sseqid = $hit->name ;
                    my $qseqid= $result->query_description;
    #               print "$qseqid\t$sseqid\n";
    
    #initialize test
    
                    if($hitcountMAN==0){
                            $test=$qseqid;
                    }
    
                    if($qseqid!~$test){
                            print "new qseqid: $test\n";
                            $test=$qseqid;
                    }
                    $hitcountMAN++;
            }
    # Lets do some statistics
            my $resultcount=$searchio->result_count();
            my $hitcount=$result->num_hits;
    
            print "SearchIO parsed result from $ARGV[0]: $algorithm_type\t $algorithm_version\t $resultcount result(s) with $hitcount hit(s)\n";
    }
    
    open (INFILE, $ARGV[0]) or die $!;
    my @blastxml=<INFILE>;
    close INFILE;
    I would be very glad if anyone could tell me where I went into the wrong direction. The script should work with any blastxml output.

    If you have other suggestions solving the general problem, please tell me.

    Thanks in advance!
  • uloeber
    Member
    • Mar 2013
    • 44

    #2
    Update

    Okay, I gave up on bioperl and wrapped my tabular output.
    I got a multidimensional hash structure now.
    How may I compare all qstart/qend values of %result{$consensus} and keep only the once which do not overlap or overlap more then a given tolerance?
    $result{$qseqid}{$count}{'qstart'}
    $result{$qseqid}{$count}{'qend'}

    Any suggestions?

    Code:
    #! /usr/bin/perl -w
    use strict;
    
    
    #input -outfmt "6 qseqid sseqid qlen qstart qend slen sstart send length pident evalue"
    open (INPUT, $ARGV[0]) or die $!;
    my @blastin=<INPUT>;
    close INPUT;
    
    my $lqseqid="";
    my %result;
    my $count=0;
    my @primres;
    my @primer=("LTR","pol");
    my @virus=("KoRV");
    my %subres;
    
    foreach my $line(@blastin){
            chomp $line;
            my @array=split "\t",$line;
            my $qseqid=$array[0];
    #       my $sseqid=$array[1];
    #       my $qlen=$array[2];
    #       my $qstart=$array[3];
    #       my $qend=$array[4];
    #       my $slen=$array[5];
    #       my $sstart=$array[6];
    #       my $send=$array[7];
    #       my $length=$array[8];
            if($qseqid=~$lqseqid){
                    $result{$qseqid}{$count}{'qseqid'}=$array[0];
                    $result{$qseqid}{$count}{'sseqid'}=$array[1];
                    $result{$qseqid}{$count}{'qlen'}=$array[2];
    #For later comparison, it's important, that the smaller position always is the start position
                    if($array[3]<$array[4]){
                            $result{$qseqid}{$count}{'qstart'}=$array[3];
                            $result{$qseqid}{$count}{'qend'}=$array[4];
                    }
                    else{
                            $result{$qseqid}{$count}{'qstart'}=$array[4];
                            $result{$qseqid}{$count}{'qend'}=$array[3];
                    }
                    $result{$qseqid}{$count}{'slen'}=$array[5];
                    $result{$qseqid}{$count}{'sstart'}=$array[6];
                    $result{$qseqid}{$count}{'send'}=$array[7];
                    $result{$qseqid}{$count}{'length'}=$array[8];
     $count++;
            }
            else{
                    $lqseqid=$qseqid;
                    $count=0;
            }
    } 
    #print "Key: $_ and Value: $result{$_}\n" foreach(keys%result);
    #access toplevel (qseqid)
    foreach my $consensus(keys%result){
                    my $hitnum=keys%{$result{$consensus}};
    #               print "$consensus\t$hitnum\n";          #print the number of hits for each query
            foreach my $hit(keys %{$result{$consensus}}){
    
    #check primers depending on lenth ratio (alignment length/subject length) and sseqid
                    my $lengthratio=0.9;
                    for (@primer){
                            if($result{$consensus}{$hit}{length}/$result{$consensus}{$hit}{slen}>=$lengthratio){
    
                                    if($result{$consensus}{$hit}{sseqid} =~ $_ ){           #compares sseqid to all elements of @primer match TRUE
    #                                       push @primres, "$result{$consensus}{$hit}{qseqid}\t$result{$consensus}{$hit}{sseqid}\t$result{$consensus}{$hit}{qstart}\t$result{$consensus}{$hit}{qend}\t$result{$$
    #                                       print "$result{$consensus}{$hit}";
                                    }
                            }
    # other subjects (not in primer list)                                 
                            else{                    #compares sseqid to all elements of @primer match FALSE
                                    foreach(@virus){
                                            if($result{$consensus}{$hit}{sseqid} =~ $_){
                                                    # search non overlapping significant hits
    
                                            }
                                            else{
                                                    # search uncovered (non viral) regions
                                            }
                                    }
                            }
                    }
    
            }
    }

    Comment

    Latest Articles

    Collapse

    • SEQadmin2
      Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
      by SEQadmin2



      Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

      Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
      ...
      10-14-2026, 09:55 AM
    • SEQadmin2
      New Genomics Technologies Take Aim at Long-Standing Limits
      by SEQadmin2


      Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

      We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
      ...
      09-28-2026, 10:25 AM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by SEQadmin2, 10-22-2026, 11:13 AM
    0 responses
    29 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-22-2026, 10:48 AM
    0 responses
    22 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-15-2026, 10:52 AM
    0 responses
    39 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-14-2026, 05:39 AM
    0 responses
    45 views
    0 reactions
    Last Post SEQadmin2  
    Working...