Bio-FastParsers

 view release on metacpan or  search on metacpan

t/blast_table.t  view on Meta::CPAN

        [ 'gi|11465907|ref|NC_001872.1|', 'gi|11465907|ref|NC_001872.1|', 100, 799, 0, 0, 19148, 21544, 19148, 21544, 0, 1897, 1, 1, 19148, 21544, 19148, 21544 ],
        [ 'gi|11465907|ref|NC_001872.1|', 'gi|11465907|ref|NC_001872.1|', 100, 818, 0, 0, 5454, 3001, 5454, 3001, 0, 1835, -1, -1, 3001, 5454, 3001, 5454 ],
        [ 'gi|11465907|ref|NC_001872.1|', 'gi|11465907|ref|NC_001872.1|', 100, 806, 0, 0, 15511, 17928, 15511, 17928, 0, 1715, 1, 1, 15511, 17928, 15511, 17928 ],
        [ 'gi|11465907|ref|NC_001872.1|', 'gi|11465907|ref|NC_001872.1|', 100, 630, 0, 0, 7729, 9618, 7729, 9618, 0, 1425, 1, 1, 7729, 9618, 7729, 9618 ],
        [ 'gi|11465907|ref|NC_001872.1|', 'gi|11465907|ref|NC_001872.1|', 100, 656, 0, 0, 11545, 13512, 11545, 13512, 0, 1401, 1, 1, 11545, 13512, 11545, 13512 ],
        [ 'gi|11465907|ref|NC_001872.1|', 'gi|11465907|ref|NC_001872.1|', 100, 645, 0, 0, 6324, 8258, 6324, 8258, 0, 1389, 1, 1, 6324, 8258, 6324, 8258 ],
        [ 'gi|11465907|ref|NC_001872.1|', 'gi|11465907|ref|NC_001872.1|', 100, 564, 0, 0, 14135, 12444, 14135, 12444, 0, 1266, -1, -1, 12444, 14135, 12444, 14135 ],
        [ 'gi|11465907|ref|NC_001872.1|', 'gi|11465907|ref|NC_001872.1|', 100, 465, 0, 0, 2393, 999, 2393, 999, 0, 1037, -1, -1, 999, 2393, 999, 2393 ],
    ]
);

check_hits(
    file('test', 'tblastx.m9'), [
        [ 'gi|11465907|ref|NC_001872.1|', 'gi|11465907|ref|NC_001872.1|', 100 ],
    ]
);

check_queries(
    file('test', 'tblastx.m9'), [
        [ 'gi|11465907|ref|NC_001872.1|', 'gi|11465907|ref|NC_001872.1|', 100 ],
    ]
);


check_hsps(
    file('test', 'bug-next-hit-blastp.m9'), [
        [ 'seq1', 'gnl|684364|328773696', 62.21, 217, 81, 1, 1, 216, 51, 267, 6e-86, 257, 1, 1, 1, 216, 51, 267 ],
        [ 'seq2', 'gnl|684364|328773696', 67.53, 194, 63, 0, 22, 215, 74, 267, 3e-87, 261, 1, 1, 22, 215, 74, 267 ],
    ]
);

check_hits(
    file('test', 'bug-next-hit-blastp.m9'), [
        [ 'seq1', 'gnl|684364|328773696', 62.21 ],
        [ 'seq2', 'gnl|684364|328773696', 67.53 ],
    ]
);

check_queries(
    file('test', 'bug-next-hit-blastp.m9'), [
        [ 'seq1', 'gnl|684364|328773696', 62.21 ],
        [ 'seq2', 'gnl|684364|328773696', 67.53 ],
    ]
);


check_hsps(
    file('test', 'usearch-global.m8'), [
        [ '36329|PFD0780w', 'gnl|Gln_40|PF3D7_0416100', 100.0, 826, 0, 0, 1, 826, 1, 826, undef, undef, 1, 1, 1, 826, 1, 826 ],
        [ '5823|PBANKA_071810', 'gnl|Gln_40|PF3D7_0416100', 42.3, 833, 294, 11, 1, 656, 1, 826, undef, undef, 1, 1, 1, 656, 1, 826 ],
    ]
);


sub check_hsps {
    my $infile = shift;
    my $exp_hsps_ref = shift;

    my @methods = qw(
        query_id hit_id
        percent_identity hsp_length mismatches gaps
        query_from  query_to
          hit_from    hit_to
        evalue bit_score
        query_strand
          hit_strand
        query_start query_end
          hit_start   hit_end
    );

    ok my $report = $class->new( file => $infile ), 'Blast::Table constructor';
    isa_ok $report, $class, $infile;

    my $n = 0;
    my @queries;
    my @hits;
    while ( my $exp_hsp = shift @{ $exp_hsps_ref } ) {
        my $hsp = $report->next_hsp;
        ok $hsp, 'Blast::Table::Hsp constructor';
        isa_ok $hsp, $class . '::Hsp';
        cmp_deeply [ map { $hsp->$_ } @methods ], $exp_hsp,
            'got expected values for all methods for hsp-' . $n++;
        push @queries, [ $hsp->query_start, $hsp->query_end ];
        push @hits,    [ $hsp->hit_start,   $hsp->hit_end   ];
    }

    ok((List::AllUtils::all { $_->[0] < $_->[1] } @queries),
        'got expected coordinates for queries');
    ok((List::AllUtils::all { $_->[0] < $_->[1] } @hits),
        'got expected coordinates for hits');

    return;
}


sub check_hits {
    my $infile = shift;
    my $exp_hsps_ref = shift;

    my $report = $class->new( file => $infile );

    while ( my $exp_hsp = shift @{ $exp_hsps_ref } ) {
        my $hsp = $report->next_hit;
        cmp_deeply [ $hsp->query_id, $hsp->hit_id, $hsp->percent_identity + 0 ],
            $exp_hsp, 'got expected next hit';
    }

    return;
}


sub check_queries {
    my $infile = shift;
    my $exp_hsps_ref = shift;

    my $report = $class->new( file => $infile );

    while ( my $exp_hsp = shift @{ $exp_hsps_ref } ) {
        my $hsp = $report->next_query;
        cmp_deeply [ $hsp->query_id, $hsp->hit_id, $hsp->percent_identity + 0 ],
            $exp_hsp, 'got expected next query';
    }

    return;
}

# TODO: test multi-query reports

done_testing;



( run in 0.539 second using v1.01-cache-2.11-cpan-39bf76dae61 )