File: typemap

package info (click to toggle)
librg-blast-parser-perl 0.03-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 164 kB
  • sloc: perl: 37; makefile: 5
file content (123 lines) | stat: -rw-r--r-- 7,301 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#   Copyright (C) 2012 by Laszlo Kajan, Technical University of Munich, Germany
#   
#   This program is free software; you can redistribute it and/or modify
#   it under the same terms as Perl itself, either Perl version 5.8.8 or,
#   at your option, any later version of Perl 5 you may have available.
# /usr/share/perl/5.10.1/ExtUtils/typemap
TYPEMAP
parser_driver*		O_OBJECT
std::string			T_PV
rostlab::blast::result	T_RO_BLAST_RES

OUTPUT
T_RO_BLAST_RES
	{
		if( $var.empty ) XSRETURN_UNDEF;

		// PERL_HASH(hash, key, klen)
		struct phashval { U32 operator()( const char* key, const U32 klen ){ U32 ret; PERL_HASH(ret, key, klen); return ret; } };
		static U32 h_bit_score = phashval()( "bit_score", 9 );
		static U32 h_desc = phashval()( "desc", 4 );
		static U32 h_e_value = phashval()( "e_value", 7 );
		static U32 h_gaps = phashval()( "gaps", 4 );
		static U32 h_identities = phashval()( "identities", 10 );
		static U32 h_match_line = phashval()( "match_line", 10 );
		static U32 h_method = phashval()( "method", 6 );
		static U32 h_name = phashval()( "name", 4 );
		static U32 h_positives = phashval()( "positives", 9 );
		static U32 h_q_ali = phashval()( "q_ali", 5 );
		static U32 h_q_end = phashval()( "q_end", 5 );
		static U32 h_q_frame = phashval()( "q_frame", 7 );
		static U32 h_q_start = phashval()( "q_start", 7 );
		static U32 h_q_strand = phashval()( "q_strand", 8 );
		static U32 h_raw_score = phashval()( "raw_score", 9 );
		static U32 h_s_ali = phashval()( "s_ali", 5 );
		static U32 h_s_end = phashval()( "s_end", 5 );
		static U32 h_s_frame = phashval()( "s_frame", 7 );
		static U32 h_s_start = phashval()( "s_start", 7 );
		static U32 h_s_strand = phashval()( "s_strand", 8 );

		static U32 h_ECompoAdjustModes[rostlab::blast::hsp::eNumCompoAdjustModes] = { phashval()( "", 0), phashval()( "Composition-based stats", 23), phashval()( "Compositional matrix adjust", 27), phashval()( "", 0) };

		AV* references = (AV *)sv_2mortal((SV *)newAV());
		AV* rounds = (AV *)sv_2mortal((SV *)newAV());
		AV* onelines = (AV *)sv_2mortal((SV *)newAV());
		AV* hits = (AV *)sv_2mortal((SV *)newAV());

		for( std::vector<std::string>::const_iterator r_i = $var.references.begin(), r_end = $var.references.end(); r_i != r_end; ++r_i )
			av_push(references, newSVpvn( r_i->c_str(), r_i->size() ));
		for( std::vector<rostlab::blast::round>::const_iterator r_i = $var.rounds.begin(), r_end = $var.rounds.end(); r_i != r_end; ++r_i )
		{
			HV* round = (HV *)sv_2mortal((SV *)newHV());
			hv_store(round, "oneline_idx", 11, newSVuv( r_i->oneline_idx ), 0);
			hv_store(round, "oneline_cnt", 11, newSVuv( r_i->oneline_cnt ), 0);
			hv_store(round, "hit_idx", 7, newSVuv( r_i->hit_idx ), 0);
			hv_store(round, "hit_cnt", 7, newSVuv( r_i-> hit_cnt ), 0);
			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);
			hv_store(round, "oneline_new_cnt", 15, newSVuv( r_i->oneline_new_cnt ), 0);
			av_push(rounds, newRV_inc((SV *)round));
		}
		for( std::vector<rostlab::blast::oneline>::const_iterator o_i = $var.onelines.begin(), o_end = $var.onelines.end(); o_i != o_end; ++o_i )
		{
			HV* oneline = (HV *)sv_2mortal((SV *)newHV());
			hv_store(oneline, "name", 4, newSVpvn( o_i->name.c_str(), o_i->name.size() ), h_name);
			hv_store(oneline, "desc", 4, o_i->desc.empty() ? &PL_sv_undef : newSVpvn( o_i->desc.c_str(), o_i->desc.size() ), h_desc);
			hv_store(oneline, "bit_score", 9, newSVnv( o_i->bit_score ), h_bit_score);
			hv_store(oneline, "e_value", 7, newSVnv( o_i->e_value ), h_e_value);
			av_push(onelines, newRV_inc((SV *)oneline));
		}
		for( std::vector<rostlab::blast::hit>::const_iterator h_i = $var.hits.begin(), h_end = $var.hits.end(); h_i != h_end; ++h_i )
		{
			AV* hsps = (AV *)sv_2mortal((SV *)newAV());
			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 )
			{
				std::string method = rostlab::blast::hsp::methodstr( hsp_i->method );

				HV* hsp = (HV *)sv_2mortal((SV *)newHV());
				hv_store(hsp, "bit_score", 9, newSVnv( hsp_i->bit_score ), h_bit_score);
				hv_store(hsp, "raw_score", 9, newSVuv( hsp_i->raw_score ), h_raw_score);
				hv_store(hsp, "e_value", 7, newSVnv( hsp_i->e_value ), h_e_value);
				hv_store(hsp, "method", 6, newSVpvn_share( method.c_str(), method.size(), 0), h_ECompoAdjustModes[hsp_i->method]);
				hv_store(hsp, "identities", 10, newSVuv( hsp_i->identities ), h_identities);
				hv_store(hsp, "positives", 9, newSVuv( hsp_i->positives ), h_positives);
				hv_store(hsp, "gaps", 4, newSVuv( hsp_i->gaps ), h_gaps);
				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);
				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);
				hv_store(hsp, "q_frame", 7, hsp_i->q_frame == 32 ? &PL_sv_undef : newSViv( hsp_i->q_frame ), h_q_frame);
				hv_store(hsp, "s_frame", 7, hsp_i->s_frame == 32 ? &PL_sv_undef : newSViv( hsp_i->s_frame ), h_s_frame);
				hv_store(hsp, "q_start", 7, newSVuv( hsp_i->q_start ), h_q_start);
				hv_store(hsp, "q_ali", 5, newSVpvn( hsp_i->q_ali.c_str(), hsp_i->q_ali.size() ), h_q_ali);
				hv_store(hsp, "q_end", 5, newSVuv( hsp_i->q_end ), h_q_end);
				hv_store(hsp, "match_line", 10, newSVpvn( hsp_i->match_line.c_str(), hsp_i->match_line.size() ), h_match_line);
				hv_store(hsp, "s_start", 7, newSVuv( hsp_i->s_start ), h_s_start);
				hv_store(hsp, "s_ali", 5, newSVpvn( hsp_i->s_ali.c_str(), hsp_i->s_ali.size() ), h_s_ali);
				hv_store(hsp, "s_end", 5, newSVuv( hsp_i->s_end ), h_s_end);
				av_push(hsps, newRV_inc((SV *)hsp));
			}

			HV* hit = (HV *)sv_2mortal((SV *)newHV());
			hv_store(hit, "name", 4, newSVpvn( h_i->name.c_str(), h_i->name.size() ), 0);
			hv_store(hit, "desc", 4, h_i->desc.empty() ? &PL_sv_undef : newSVpvn( h_i->desc.c_str(), h_i->desc.size() ), 0);
			hv_store(hit, "length", 6, newSVuv( h_i->length ), 0);
			hv_store(hit, "hsps", 4, newRV_inc((SV *)hsps), 0);
			av_push(hits, newRV_inc((SV *)hit));
		}

		HV* res = (HV *)sv_2mortal((SV *)newHV());
		hv_store(res, "blast_version", 13, newSVpvn( $var.blast_version.c_str(), $var.blast_version.size() ), 0);
		hv_store(res, "references", 10, newRV_inc((SV *)references), 0);
		hv_store(res, "rounds", 6, newRV_inc((SV *)rounds), 0);
		hv_store(res, "q_name", 6, newSVpvn( $var.q_name.c_str(), $var.q_name.size() ), 0);
		hv_store(res, "q_desc", 6, $var.q_desc.empty() ? &PL_sv_undef : newSVpvn( $var.q_desc.c_str(), $var.q_desc.size() ), 0);
		hv_store(res, "q_length", 8, newSVuv( $var.q_length ), 0);
		hv_store(res, "db_name", 7, newSVpvn( $var.db_name.c_str(), $var.db_name.size() ), 0);
		hv_store(res, "db_nseq", 7, newSVuv( $var.db_nseq ), 0);
		hv_store(res, "db_nletter", 10, newSVuv( $var.db_nletter ), 0);
		hv_store(res, "onelines", 8, newRV_inc((SV *)onelines), 0);
		hv_store(res, "converged", 9, newSViv( $var.converged ), 0);
		hv_store(res, "hits", 4, newRV_inc((SV *)hits), 0);
		hv_store(res, "tail", 4, newSVpvn( $var.tail.c_str(), $var.tail.size() ), 0 );

		$arg = newRV_inc((SV*)res);
	}
# vim:noet:ts=4:ai: