| 1 |
# Copyright (C) 2012 by Laszlo Kajan, Technical University of Munich, Germany |
| 2 |
# |
| 3 |
# This program is free software; you can redistribute it and/or modify |
| 4 |
# it under the same terms as Perl itself, either Perl version 5.8.8 or, |
| 5 |
# at your option, any later version of Perl 5 you may have available. |
| 6 |
# /usr/share/perl/5.10.1/ExtUtils/typemap |
| 7 |
TYPEMAP |
| 8 |
parser_driver* O_OBJECT |
| 9 |
std::string T_PV |
| 10 |
rostlab::blast::result T_RO_BLAST_RES |
| 11 |
|
| 12 |
OUTPUT |
| 13 |
T_RO_BLAST_RES |
| 14 |
{ |
| 15 |
if( $var.empty ) XSRETURN_UNDEF; |
| 16 |
|
| 17 |
// PERL_HASH(hash, key, klen) |
| 18 |
struct phashval { U32 operator()( const char* key, const U32 klen ){ U32 ret; PERL_HASH(ret, key, klen); return ret; } }; |
| 19 |
static U32 h_bit_score = phashval()( "bit_score", 9 ); |
| 20 |
static U32 h_desc = phashval()( "desc", 4 ); |
| 21 |
static U32 h_e_value = phashval()( "e_value", 7 ); |
| 22 |
static U32 h_gaps = phashval()( "gaps", 4 ); |
| 23 |
static U32 h_identities = phashval()( "identities", 10 ); |
| 24 |
static U32 h_match_line = phashval()( "match_line", 10 ); |
| 25 |
static U32 h_method = phashval()( "method", 6 ); |
| 26 |
static U32 h_name = phashval()( "name", 4 ); |
| 27 |
static U32 h_positives = phashval()( "positives", 9 ); |
| 28 |
static U32 h_q_ali = phashval()( "q_ali", 5 ); |
| 29 |
static U32 h_q_end = phashval()( "q_end", 5 ); |
| 30 |
static U32 h_q_frame = phashval()( "q_frame", 7 ); |
| 31 |
static U32 h_q_start = phashval()( "q_start", 7 ); |
| 32 |
static U32 h_q_strand = phashval()( "q_strand", 8 ); |
| 33 |
static U32 h_raw_score = phashval()( "raw_score", 9 ); |
| 34 |
static U32 h_s_ali = phashval()( "s_ali", 5 ); |
| 35 |
static U32 h_s_end = phashval()( "s_end", 5 ); |
| 36 |
static U32 h_s_frame = phashval()( "s_frame", 7 ); |
| 37 |
static U32 h_s_start = phashval()( "s_start", 7 ); |
| 38 |
static U32 h_s_strand = phashval()( "s_strand", 8 ); |
| 39 |
|
| 40 |
static U32 h_ECompoAdjustModes[rostlab::blast::hsp::eNumCompoAdjustModes] = { phashval()( "", 0), phashval()( "Composition-based stats", 23), phashval()( "Compositional matrix adjust", 27), phashval()( "", 0) }; |
| 41 |
|
| 42 |
AV* references = (AV *)sv_2mortal((SV *)newAV()); |
| 43 |
AV* rounds = (AV *)sv_2mortal((SV *)newAV()); |
| 44 |
AV* onelines = (AV *)sv_2mortal((SV *)newAV()); |
| 45 |
AV* hits = (AV *)sv_2mortal((SV *)newAV()); |
| 46 |
|
| 47 |
for( std::vector<std::string>::const_iterator r_i = $var.references.begin(), r_end = $var.references.end(); r_i != r_end; ++r_i ) |
| 48 |
av_push(references, newSVpvn( r_i->c_str(), r_i->size() )); |
| 49 |
for( std::vector<rostlab::blast::round>::const_iterator r_i = $var.rounds.begin(), r_end = $var.rounds.end(); r_i != r_end; ++r_i ) |
| 50 |
{ |
| 51 |
HV* round = (HV *)sv_2mortal((SV *)newHV()); |
| 52 |
hv_store(round, "oneline_idx", 11, newSVuv( r_i->oneline_idx ), 0); |
| 53 |
hv_store(round, "oneline_cnt", 11, newSVuv( r_i->oneline_cnt ), 0); |
| 54 |
hv_store(round, "hit_idx", 7, newSVuv( r_i->hit_idx ), 0); |
| 55 |
hv_store(round, "hit_cnt", 7, newSVuv( r_i-> hit_cnt ), 0); |
| 56 |
hv_store(round, "oneline_new_idx", 15, r_i->oneline_new_idx != rostlab::blast::round::noidx ? newSVuv( r_i->oneline_new_idx ) : &PL_sv_undef, 0); |
| 57 |
hv_store(round, "oneline_new_cnt", 15, newSVuv( r_i->oneline_new_cnt ), 0); |
| 58 |
av_push(rounds, newRV_inc((SV *)round)); |
| 59 |
} |
| 60 |
for( std::vector<rostlab::blast::oneline>::const_iterator o_i = $var.onelines.begin(), o_end = $var.onelines.end(); o_i != o_end; ++o_i ) |
| 61 |
{ |
| 62 |
HV* oneline = (HV *)sv_2mortal((SV *)newHV()); |
| 63 |
hv_store(oneline, "name", 4, newSVpvn( o_i->name.c_str(), o_i->name.size() ), h_name); |
| 64 |
hv_store(oneline, "desc", 4, o_i->desc.empty() ? &PL_sv_undef : newSVpvn( o_i->desc.c_str(), o_i->desc.size() ), h_desc); |
| 65 |
hv_store(oneline, "bit_score", 9, newSVnv( o_i->bit_score ), h_bit_score); |
| 66 |
hv_store(oneline, "e_value", 7, newSVnv( o_i->e_value ), h_e_value); |
| 67 |
av_push(onelines, newRV_inc((SV *)oneline)); |
| 68 |
} |
| 69 |
for( std::vector<rostlab::blast::hit>::const_iterator h_i = $var.hits.begin(), h_end = $var.hits.end(); h_i != h_end; ++h_i ) |
| 70 |
{ |
| 71 |
AV* hsps = (AV *)sv_2mortal((SV *)newAV()); |
| 72 |
for( std::vector<rostlab::blast::hsp>::const_iterator hsp_i = h_i->hsps.begin(), hsp_end = h_i->hsps.end(); hsp_i != hsp_end; ++hsp_i ) |
| 73 |
{ |
| 74 |
std::string method = rostlab::blast::hsp::methodstr( hsp_i->method ); |
| 75 |
|
| 76 |
HV* hsp = (HV *)sv_2mortal((SV *)newHV()); |
| 77 |
hv_store(hsp, "bit_score", 9, newSVnv( hsp_i->bit_score ), h_bit_score); |
| 78 |
hv_store(hsp, "raw_score", 9, newSVuv( hsp_i->raw_score ), h_raw_score); |
| 79 |
hv_store(hsp, "e_value", 7, newSVnv( hsp_i->e_value ), h_e_value); |
| 80 |
hv_store(hsp, "method", 6, newSVpvn_share( method.c_str(), method.size(), 0), h_ECompoAdjustModes[hsp_i->method]); |
| 81 |
hv_store(hsp, "identities", 10, newSVuv( hsp_i->identities ), h_identities); |
| 82 |
hv_store(hsp, "positives", 9, newSVuv( hsp_i->positives ), h_positives); |
| 83 |
hv_store(hsp, "gaps", 4, newSVuv( hsp_i->gaps ), h_gaps); |
| 84 |
hv_store(hsp, "q_strand", 8, hsp_i->q_strand.empty() ? &PL_sv_undef : newSVpvn_share( hsp_i->q_strand.c_str(), hsp_i->q_strand.length(), 0), h_q_strand); |
| 85 |
hv_store(hsp, "s_strand", 8, hsp_i->s_strand.empty() ? &PL_sv_undef : newSVpvn_share( hsp_i->s_strand.c_str(), hsp_i->s_strand.length(), 0), h_s_strand); |
| 86 |
hv_store(hsp, "q_frame", 7, hsp_i->q_frame == 32 ? &PL_sv_undef : newSViv( hsp_i->q_frame ), h_q_frame); |
| 87 |
hv_store(hsp, "s_frame", 7, hsp_i->s_frame == 32 ? &PL_sv_undef : newSViv( hsp_i->s_frame ), h_s_frame); |
| 88 |
hv_store(hsp, "q_start", 7, newSVuv( hsp_i->q_start ), h_q_start); |
| 89 |
hv_store(hsp, "q_ali", 5, newSVpvn( hsp_i->q_ali.c_str(), hsp_i->q_ali.size() ), h_q_ali); |
| 90 |
hv_store(hsp, "q_end", 5, newSVuv( hsp_i->q_end ), h_q_end); |
| 91 |
hv_store(hsp, "match_line", 10, newSVpvn( hsp_i->match_line.c_str(), hsp_i->match_line.size() ), h_match_line); |
| 92 |
hv_store(hsp, "s_start", 7, newSVuv( hsp_i->s_start ), h_s_start); |
| 93 |
hv_store(hsp, "s_ali", 5, newSVpvn( hsp_i->s_ali.c_str(), hsp_i->s_ali.size() ), h_s_ali); |
| 94 |
hv_store(hsp, "s_end", 5, newSVuv( hsp_i->s_end ), h_s_end); |
| 95 |
av_push(hsps, newRV_inc((SV *)hsp)); |
| 96 |
} |
| 97 |
|
| 98 |
HV* hit = (HV *)sv_2mortal((SV *)newHV()); |
| 99 |
hv_store(hit, "name", 4, newSVpvn( h_i->name.c_str(), h_i->name.size() ), 0); |
| 100 |
hv_store(hit, "desc", 4, h_i->desc.empty() ? &PL_sv_undef : newSVpvn( h_i->desc.c_str(), h_i->desc.size() ), 0); |
| 101 |
hv_store(hit, "length", 6, newSVuv( h_i->length ), 0); |
| 102 |
hv_store(hit, "hsps", 4, newRV_inc((SV *)hsps), 0); |
| 103 |
av_push(hits, newRV_inc((SV *)hit)); |
| 104 |
} |
| 105 |
|
| 106 |
HV* res = (HV *)sv_2mortal((SV *)newHV()); |
| 107 |
hv_store(res, "blast_version", 13, newSVpvn( $var.blast_version.c_str(), $var.blast_version.size() ), 0); |
| 108 |
hv_store(res, "references", 10, newRV_inc((SV *)references), 0); |
| 109 |
hv_store(res, "rounds", 6, newRV_inc((SV *)rounds), 0); |
| 110 |
hv_store(res, "q_name", 6, newSVpvn( $var.q_name.c_str(), $var.q_name.size() ), 0); |
| 111 |
hv_store(res, "q_desc", 6, $var.q_desc.empty() ? &PL_sv_undef : newSVpvn( $var.q_desc.c_str(), $var.q_desc.size() ), 0); |
| 112 |
hv_store(res, "q_length", 8, newSVuv( $var.q_length ), 0); |
| 113 |
hv_store(res, "db_name", 7, newSVpvn( $var.db_name.c_str(), $var.db_name.size() ), 0); |
| 114 |
hv_store(res, "db_nseq", 7, newSVuv( $var.db_nseq ), 0); |
| 115 |
hv_store(res, "db_nletter", 10, newSVuv( $var.db_nletter ), 0); |
| 116 |
hv_store(res, "onelines", 8, newRV_inc((SV *)onelines), 0); |
| 117 |
hv_store(res, "converged", 9, newSViv( $var.converged ), 0); |
| 118 |
hv_store(res, "hits", 4, newRV_inc((SV *)hits), 0); |
| 119 |
hv_store(res, "tail", 4, newSVpvn( $var.tail.c_str(), $var.tail.size() ), 0 ); |
| 120 |
|
| 121 |
$arg = newRV_inc((SV*)res); |
| 122 |
} |
| 123 |
# vim:noet:ts=4:ai: |