From cab3ef9de554774c998be081aed74043b80e1842 Mon Sep 17 00:00:00 2001 From: birney Date: Thu, 16 Sep 1999 13:33:28 +0000 Subject: [PATCH] added extensions svn path=/bioperl-ext/branches/ewan/; revision=620 --- Bio/Ext/Align/Align.pm | 51 + Bio/Ext/Align/Align.xs | 3313 ++++++++++++ Bio/Ext/Align/Makefile.PL | 21 + Bio/Ext/Align/blosum62.bla | 31 + Bio/Ext/Align/libs/aln.c | 2587 ++++++++++ Bio/Ext/Align/libs/aln.h | 977 ++++ Bio/Ext/Align/libs/alnconvert.c | 586 +++ Bio/Ext/Align/libs/alnconvert.h | 253 + Bio/Ext/Align/libs/alnrange.c | 908 ++++ Bio/Ext/Align/libs/alnrange.h | 297 ++ Bio/Ext/Align/libs/asciibtcanvas.c | 464 ++ Bio/Ext/Align/libs/asciibtcanvas.h | 126 + Bio/Ext/Align/libs/basematrix.c | 370 ++ Bio/Ext/Align/libs/basematrix.h | 274 + Bio/Ext/Align/libs/btcanvas.c | 361 ++ Bio/Ext/Align/libs/btcanvas.h | 334 ++ Bio/Ext/Align/libs/codon.c | 743 +++ Bio/Ext/Align/libs/codon.h | 462 ++ Bio/Ext/Align/libs/commandline.c | 226 + Bio/Ext/Align/libs/commandline.h | 133 + Bio/Ext/Align/libs/complexconsensi.c | 677 +++ Bio/Ext/Align/libs/complexconsensi.h | 327 ++ Bio/Ext/Align/libs/complexevalset.c | 437 ++ Bio/Ext/Align/libs/complexevalset.h | 220 + Bio/Ext/Align/libs/complexsequence.c | 1004 ++++ Bio/Ext/Align/libs/complexsequence.h | 426 ++ Bio/Ext/Align/libs/compmat.c | 708 +++ Bio/Ext/Align/libs/compmat.h | 353 ++ Bio/Ext/Align/libs/database.h | 30 + Bio/Ext/Align/libs/dna.c | 292 ++ Bio/Ext/Align/libs/dna.h | 234 + Bio/Ext/Align/libs/dnamatrix.c | 416 ++ Bio/Ext/Align/libs/dnamatrix.h | 252 + Bio/Ext/Align/libs/dpenvelope.c | 517 ++ Bio/Ext/Align/libs/dpenvelope.h | 276 + Bio/Ext/Align/libs/dyna.h | 42 + Bio/Ext/Align/libs/dynlibcross.c | 81 + Bio/Ext/Align/libs/dynlibcross.h | 54 + Bio/Ext/Align/libs/histogram.c | 1565 ++++++ Bio/Ext/Align/libs/histogram.h | 506 ++ Bio/Ext/Align/libs/hscore.c | 1441 ++++++ Bio/Ext/Align/libs/hscore.h | 621 +++ Bio/Ext/Align/libs/linesubs.c | 230 + Bio/Ext/Align/libs/linesubs.h | 50 + Bio/Ext/Align/libs/makefile | 51 + Bio/Ext/Align/libs/packaln.c | 793 +++ Bio/Ext/Align/libs/packaln.h | 328 ++ Bio/Ext/Align/libs/probability.c | 584 +++ Bio/Ext/Align/libs/probability.h | 444 ++ Bio/Ext/Align/libs/protein.c | 336 ++ Bio/Ext/Align/libs/protein.h | 238 + Bio/Ext/Align/libs/proteindb.c | 524 ++ Bio/Ext/Align/libs/proteindb.h | 247 + Bio/Ext/Align/libs/proteinsw.c | 2882 +++++++++++ Bio/Ext/Align/libs/proteinsw.h | 343 ++ Bio/Ext/Align/libs/seqaligndisplay.c | 277 + Bio/Ext/Align/libs/seqaligndisplay.h | 123 + Bio/Ext/Align/libs/sequence.c | 1491 ++++++ Bio/Ext/Align/libs/sequence.h | 613 +++ Bio/Ext/Align/libs/sequencedb.c | 1402 ++++++ Bio/Ext/Align/libs/sequencedb.h | 445 ++ Bio/Ext/Align/libs/sw.h | 6963 ++++++++++++++++++++++++++ Bio/Ext/Align/libs/sw_wrap.c | 183 + Bio/Ext/Align/libs/sw_wrap.h | 106 + Bio/Ext/Align/libs/wisebase.h | 52 + Bio/Ext/Align/libs/wiseconfig.c | 272 + Bio/Ext/Align/libs/wiseconfig.h | 52 + Bio/Ext/Align/libs/wiseerror.c | 580 +++ Bio/Ext/Align/libs/wiseerror.h | 323 ++ Bio/Ext/Align/libs/wisefile.c | 364 ++ Bio/Ext/Align/libs/wisefile.h | 168 + Bio/Ext/Align/libs/wisememman.c | 109 + Bio/Ext/Align/libs/wisememman.h | 89 + Bio/Ext/Align/libs/wiseoverlay.c | 92 + Bio/Ext/Align/libs/wiseoverlay.h | 74 + Bio/Ext/Align/libs/wiserandom.c | 71 + Bio/Ext/Align/libs/wiserandom.h | 72 + Bio/Ext/Align/libs/wisestring.c | 1109 ++++ Bio/Ext/Align/libs/wisestring.h | 530 ++ Bio/Ext/Align/libs/wisetime.c | 55 + Bio/Ext/Align/libs/wisetime.h | 57 + Bio/Ext/Align/test.pl | 37 + Bio/Ext/Align/typemap | 351 ++ README | 24 + 84 files changed, 46130 insertions(+) create mode 100644 Bio/Ext/Align/Align.pm create mode 100644 Bio/Ext/Align/Align.xs create mode 100755 Bio/Ext/Align/Makefile.PL create mode 100644 Bio/Ext/Align/blosum62.bla create mode 100644 Bio/Ext/Align/libs/aln.c create mode 100644 Bio/Ext/Align/libs/aln.h create mode 100644 Bio/Ext/Align/libs/alnconvert.c create mode 100644 Bio/Ext/Align/libs/alnconvert.h create mode 100644 Bio/Ext/Align/libs/alnrange.c create mode 100644 Bio/Ext/Align/libs/alnrange.h create mode 100644 Bio/Ext/Align/libs/asciibtcanvas.c create mode 100644 Bio/Ext/Align/libs/asciibtcanvas.h create mode 100644 Bio/Ext/Align/libs/basematrix.c create mode 100644 Bio/Ext/Align/libs/basematrix.h create mode 100644 Bio/Ext/Align/libs/btcanvas.c create mode 100644 Bio/Ext/Align/libs/btcanvas.h create mode 100644 Bio/Ext/Align/libs/codon.c create mode 100644 Bio/Ext/Align/libs/codon.h create mode 100644 Bio/Ext/Align/libs/commandline.c create mode 100644 Bio/Ext/Align/libs/commandline.h create mode 100644 Bio/Ext/Align/libs/complexconsensi.c create mode 100644 Bio/Ext/Align/libs/complexconsensi.h create mode 100644 Bio/Ext/Align/libs/complexevalset.c create mode 100644 Bio/Ext/Align/libs/complexevalset.h create mode 100644 Bio/Ext/Align/libs/complexsequence.c create mode 100644 Bio/Ext/Align/libs/complexsequence.h create mode 100644 Bio/Ext/Align/libs/compmat.c create mode 100644 Bio/Ext/Align/libs/compmat.h create mode 100644 Bio/Ext/Align/libs/database.h create mode 100644 Bio/Ext/Align/libs/dna.c create mode 100644 Bio/Ext/Align/libs/dna.h create mode 100644 Bio/Ext/Align/libs/dnamatrix.c create mode 100644 Bio/Ext/Align/libs/dnamatrix.h create mode 100644 Bio/Ext/Align/libs/dpenvelope.c create mode 100644 Bio/Ext/Align/libs/dpenvelope.h create mode 100644 Bio/Ext/Align/libs/dyna.h create mode 100644 Bio/Ext/Align/libs/dynlibcross.c create mode 100644 Bio/Ext/Align/libs/dynlibcross.h create mode 100644 Bio/Ext/Align/libs/histogram.c create mode 100644 Bio/Ext/Align/libs/histogram.h create mode 100644 Bio/Ext/Align/libs/hscore.c create mode 100644 Bio/Ext/Align/libs/hscore.h create mode 100644 Bio/Ext/Align/libs/linesubs.c create mode 100644 Bio/Ext/Align/libs/linesubs.h create mode 100644 Bio/Ext/Align/libs/makefile create mode 100644 Bio/Ext/Align/libs/packaln.c create mode 100644 Bio/Ext/Align/libs/packaln.h create mode 100644 Bio/Ext/Align/libs/probability.c create mode 100644 Bio/Ext/Align/libs/probability.h create mode 100644 Bio/Ext/Align/libs/protein.c create mode 100644 Bio/Ext/Align/libs/protein.h create mode 100644 Bio/Ext/Align/libs/proteindb.c create mode 100644 Bio/Ext/Align/libs/proteindb.h create mode 100644 Bio/Ext/Align/libs/proteinsw.c create mode 100644 Bio/Ext/Align/libs/proteinsw.h create mode 100644 Bio/Ext/Align/libs/seqaligndisplay.c create mode 100644 Bio/Ext/Align/libs/seqaligndisplay.h create mode 100644 Bio/Ext/Align/libs/sequence.c create mode 100644 Bio/Ext/Align/libs/sequence.h create mode 100644 Bio/Ext/Align/libs/sequencedb.c create mode 100644 Bio/Ext/Align/libs/sequencedb.h create mode 100644 Bio/Ext/Align/libs/sw.h create mode 100644 Bio/Ext/Align/libs/sw_wrap.c create mode 100644 Bio/Ext/Align/libs/sw_wrap.h create mode 100644 Bio/Ext/Align/libs/wisebase.h create mode 100755 Bio/Ext/Align/libs/wiseconfig.c create mode 100644 Bio/Ext/Align/libs/wiseconfig.h create mode 100644 Bio/Ext/Align/libs/wiseerror.c create mode 100644 Bio/Ext/Align/libs/wiseerror.h create mode 100644 Bio/Ext/Align/libs/wisefile.c create mode 100644 Bio/Ext/Align/libs/wisefile.h create mode 100644 Bio/Ext/Align/libs/wisememman.c create mode 100644 Bio/Ext/Align/libs/wisememman.h create mode 100644 Bio/Ext/Align/libs/wiseoverlay.c create mode 100644 Bio/Ext/Align/libs/wiseoverlay.h create mode 100644 Bio/Ext/Align/libs/wiserandom.c create mode 100644 Bio/Ext/Align/libs/wiserandom.h create mode 100644 Bio/Ext/Align/libs/wisestring.c create mode 100644 Bio/Ext/Align/libs/wisestring.h create mode 100644 Bio/Ext/Align/libs/wisetime.c create mode 100644 Bio/Ext/Align/libs/wisetime.h create mode 100755 Bio/Ext/Align/test.pl create mode 100644 Bio/Ext/Align/typemap create mode 100644 README diff --git a/Bio/Ext/Align/Align.pm b/Bio/Ext/Align/Align.pm new file mode 100644 index 0000000..c61bace --- /dev/null +++ b/Bio/Ext/Align/Align.pm @@ -0,0 +1,51 @@ + + + +package Bio::Ext::Align; + +use vars qw($AUTOLOAD @ISA @EXPORT_OK $dl_debug); +use Exporter; +use Carp; +use strict; + +use DynaLoader; + + +@ISA = qw(Exporter DynaLoader); +# Items to export into callers namespace by default. Note: do not export +# names by default without a very good reason. Use EXPORT_OK instead. +# Do not simply export all your public functions/methods/constants. + +sub AUTOLOAD { + # This AUTOLOAD is used to 'autoload' constants from the constant() + # XS function. If a constant is not found then control is passed + # to the AUTOLOAD in AutoLoader. + + my $constname; + ($constname = $AUTOLOAD) =~ s/.*:://; + my $val = constant($constname, @_ ? $_[0] : 0); + if ($! != 0) { + if ($! =~ /Invalid/) { + $AutoLoader::AUTOLOAD = $AUTOLOAD; + goto &AutoLoader::AUTOLOAD; + } + else { + croak "Your vendor has not defined Test macro $constname"; + } + } + eval "sub $AUTOLOAD { $val }"; + goto &$AUTOLOAD; +} + +BEGIN { + $dl_debug = 40; +} + +bootstrap Bio::Ext::Align; # hopefully has the correct things... + +# Preloaded methods go here. + +# Autoload methods go after __END__, and are processed by the autosplit program. + +1; +__END__ diff --git a/Bio/Ext/Align/Align.xs b/Bio/Ext/Align/Align.xs new file mode 100644 index 0000000..2a44e4e --- /dev/null +++ b/Bio/Ext/Align/Align.xs @@ -0,0 +1,3313 @@ + +#ifdef __cplusplus +extern "C" { +#endif +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" +#ifdef __cplusplus +} +#endif + +#include "sw.h" + + +static int +not_here(s) +char *s; +{ + croak("%s not implemented on this architecture", s); + return -1; +} + +static double +constant(name, arg) +char *name; +int arg; +{ + errno = 0; + switch (*name) { + } + errno = EINVAL; + return 0; + +not_there: + errno = ENOENT; + return 0; +} + + +MODULE = Bio::Ext::Align PACKAGE = Bio::Ext::Align + + +double +constant(name,arg) + char * name + int arg + + +PROTOTYPES: ENABLE + +void +error_on(type) + int type; + CODE: + bp_sw_error_on(type); + + +void +error_off(type) + int type; + CODE: + bp_sw_error_off(type); + + +MODULE = Bio::Ext::Align PACKAGE = Bio::Ext::Align::AlnBlock + +void +bit_ascii_AlnBlock(alb,ofp) + bp_sw_AlnBlock * alb + FILE * ofp + CODE: + bp_sw_bit_ascii_AlnBlock(alb,ofp); + + + +void +dump_ascii_AlnBlock(alb,ofp) + bp_sw_AlnBlock * alb + FILE * ofp + CODE: + bp_sw_dump_ascii_AlnBlock(alb,ofp); + + + +bp_sw_AlnBlock * +hard_link_AlnBlock(obj) + bp_sw_AlnBlock * obj + CODE: + RETVAL = bp_sw_hard_link_AlnBlock(obj); + OUTPUT: + RETVAL + + + +bp_sw_AlnBlock * +AlnBlock_alloc_std() + CODE: + RETVAL = bp_sw_AlnBlock_alloc_std(); + OUTPUT: + RETVAL + + + +boolean +set_start(obj,start) + bp_sw_AlnBlock * obj + bp_sw_AlnColumn * start + CODE: + RETVAL = bp_sw_replace_start_AlnBlock(obj,bp_sw_hard_link_AlnColumn(start)); + OUTPUT: + RETVAL + + + +bp_sw_AlnColumn * +start(obj) + bp_sw_AlnBlock * obj + INIT: +bp_sw_AlnColumn * temp; + CODE: + temp = bp_sw_hard_link_AlnColumn(bp_sw_access_start_AlnBlock(obj)); + RETVAL = temp; + OUTPUT: + RETVAL + + + +bp_sw_AlnSequence * +seq(obj,i) + bp_sw_AlnBlock * obj + int i + INIT: +bp_sw_AlnSequence * temp; + CODE: + temp = bp_sw_hard_link_AlnSequence(bp_sw_access_seq_AlnBlock(obj,i)); + RETVAL = temp; + OUTPUT: + RETVAL + + + +int +length_seq(obj) + bp_sw_AlnBlock * obj + CODE: + RETVAL = bp_sw_length_seq_AlnBlock(obj); + OUTPUT: + RETVAL + + + +int +flush_seq(obj) + bp_sw_AlnBlock * obj + CODE: + RETVAL = bp_sw_flush_AlnBlock(obj); + OUTPUT: + RETVAL + + + +boolean +add_seq(obj,add) + bp_sw_AlnBlock * obj + bp_sw_AlnSequence * add + CODE: + RETVAL = bp_sw_add_AlnBlock(obj,bp_sw_hard_link_AlnSequence(add)); + OUTPUT: + RETVAL + + + +boolean +set_length(obj,length) + bp_sw_AlnBlock * obj + int length + CODE: + RETVAL = bp_sw_replace_length_AlnBlock(obj,length); + OUTPUT: + RETVAL + + + +int +length(obj) + bp_sw_AlnBlock * obj + CODE: + RETVAL = bp_sw_access_length_AlnBlock(obj); + OUTPUT: + RETVAL + + + +boolean +set_score(obj,score) + bp_sw_AlnBlock * obj + int score + CODE: + RETVAL = bp_sw_replace_score_AlnBlock(obj,score); + OUTPUT: + RETVAL + + + +int +score(obj) + bp_sw_AlnBlock * obj + CODE: + RETVAL = bp_sw_access_score_AlnBlock(obj); + OUTPUT: + RETVAL + + + + +bp_sw_AlnBlock * +new(class) + char * class + PPCODE: + bp_sw_AlnBlock * out; + out = bp_sw_AlnBlock_alloc_std(); + ST(0) = sv_newmortal(); + sv_setref_pv(ST(0),class,(void*)out); + XSRETURN(1); + +void +DESTROY(obj) + bp_sw_AlnBlock * obj + CODE: + bp_sw_free_AlnBlock(obj); + +void +each_seq(obj) + bp_sw_AlnBlock * obj + PPCODE: + int i=0; + int len; + SV* temp; + len = bp_sw_length_seq_AlnBlock(obj); + for(i=0;i 'Bio::Ext::Align', + 'VERSION' => '0.1', + 'LIBS' => ['-lm'], # e.g., '-lm' + 'DEFINE' => '-DPOSIX -DNOERROR', # e.g., '-DHAVE_SOMETHING' + 'INC' => '-I./libs', # e.g., '-I/usr/include/other' + 'MYEXTLIB' => 'libs/libsw$(LIB_EXT)', + 'clean' => { 'FILES' => 'libs/*.o libs/*.a' } +); + +sub MY::postamble{ +' +$(MYEXTLIB): + DEFINE=\'$(DEFINE)\'; CC=\'$(PERLMAINCC)\'; export DEFINE INC CC; \ + cd libs && $(MAKE) CC=$(CC) libsw$(LIB_EXT) -e + +'; +} diff --git a/Bio/Ext/Align/blosum62.bla b/Bio/Ext/Align/blosum62.bla new file mode 100644 index 0000000..02f19b2 --- /dev/null +++ b/Bio/Ext/Align/blosum62.bla @@ -0,0 +1,31 @@ +# Matrix made by matblas from blosum62.iij +# * column uses minimum score +# BLOSUM Clustered Scoring Matrix in 1/2 Bit Units +# Blocks Database = /data/blocks_5.0/blocks.dat +# Cluster Percentage: >= 62 +# Entropy = 0.6979, Expected = -0.5209 + A R N D C Q E G H I L K M F P S T W Y V B Z X * + 4 -1 -2 -2 0 -1 -1 0 -2 -1 -1 -1 -1 -2 -1 1 0 -3 -2 0 -2 -1 0 -4 +-1 5 0 -2 -3 1 0 -2 0 -3 -2 2 -1 -3 -2 -1 -1 -3 -2 -3 -1 0 -1 -4 +-2 0 6 1 -3 0 0 0 1 -3 -3 0 -2 -3 -2 1 0 -4 -2 -3 3 0 -1 -4 +-2 -2 1 6 -3 0 2 -1 -1 -3 -4 -1 -3 -3 -1 0 -1 -4 -3 -3 4 1 -1 -4 + 0 -3 -3 -3 9 -3 -4 -3 -3 -1 -1 -3 -1 -2 -3 -1 -1 -2 -2 -1 -3 -3 -2 -4 +-1 1 0 0 -3 5 2 -2 0 -3 -2 1 0 -3 -1 0 -1 -2 -1 -2 0 3 -1 -4 +-1 0 0 2 -4 2 5 -2 0 -3 -3 1 -2 -3 -1 0 -1 -3 -2 -2 1 4 -1 -4 + 0 -2 0 -1 -3 -2 -2 6 -2 -4 -4 -2 -3 -3 -2 0 -2 -2 -3 -3 -1 -2 -1 -4 +-2 0 1 -1 -3 0 0 -2 8 -3 -3 -1 -2 -1 -2 -1 -2 -2 2 -3 0 0 -1 -4 +-1 -3 -3 -3 -1 -3 -3 -4 -3 4 2 -3 1 0 -3 -2 -1 -3 -1 3 -3 -3 -1 -4 +-1 -2 -3 -4 -1 -2 -3 -4 -3 2 4 -2 2 0 -3 -2 -1 -2 -1 1 -4 -3 -1 -4 +-1 2 0 -1 -3 1 1 -2 -1 -3 -2 5 -1 -3 -1 0 -1 -3 -2 -2 0 1 -1 -4 +-1 -1 -2 -3 -1 0 -2 -3 -2 1 2 -1 5 0 -2 -1 -1 -1 -1 1 -3 -1 -1 -4 +-2 -3 -3 -3 -2 -3 -3 -3 -1 0 0 -3 0 6 -4 -2 -2 1 3 -1 -3 -3 -1 -4 +-1 -2 -2 -1 -3 -1 -1 -2 -2 -3 -3 -1 -2 -4 7 -1 -1 -4 -3 -2 -2 -1 -2 -4 + 1 -1 1 0 -1 0 0 0 -1 -2 -2 0 -1 -2 -1 4 1 -3 -2 -2 0 0 0 -4 + 0 -1 0 -1 -1 -1 -1 -2 -2 -1 -1 -1 -1 -2 -1 1 5 -2 -2 0 -1 -1 0 -4 +-3 -3 -4 -4 -2 -2 -3 -2 -2 -3 -2 -3 -1 1 -4 -3 -2 11 2 -3 -4 -3 -2 -4 +-2 -2 -2 -3 -2 -1 -2 -3 2 -1 -1 -2 -1 3 -3 -2 -2 2 7 -1 -3 -2 -1 -4 + 0 -3 -3 -3 -1 -2 -2 -3 -3 3 1 -2 1 -1 -2 -2 0 -3 -1 4 -3 -2 -1 -4 +-2 -1 3 4 -3 0 1 -1 0 -3 -4 0 -3 -3 -2 0 -1 -4 -3 -3 4 1 -1 -4 +-1 0 0 1 -3 3 4 -2 0 -3 -3 1 -1 -3 -1 0 -1 -3 -2 -2 1 4 -1 -4 + 0 -1 -1 -1 -2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -2 0 0 -2 -1 -1 -1 -1 -1 -4 +-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 1 diff --git a/Bio/Ext/Align/libs/aln.c b/Bio/Ext/Align/libs/aln.c new file mode 100644 index 0000000..7697c81 --- /dev/null +++ b/Bio/Ext/Align/libs/aln.c @@ -0,0 +1,2587 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "aln.h" + +/* Function: at_end_AlnColumn(alc) + * + * Descrip: This tells you whether the AlnColumn is at the + * end without passing NULL's around + * + * + * + * Arg: alc [READ ] AlnColumn [AlnColumn *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 116 "aln.dy" +boolean at_end_AlnColumn(AlnColumn * alc) +{ + if( alc->next == NULL ) + return 1; + return 0; +} + + +/* Function: bio_start_AlnUnit(alu) + * + * Descrip: Tells the bio-coordinate of the + * start point of this alnunit + * + * + * Arg: alu [UNKN ] Undocumented argument [AlnUnit *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 129 "aln.dy" +int bio_start_AlnUnit(AlnUnit * alu) +{ + if( alu->seq == NULL ) { + warn("A mis-connected AlnUnit (no sequence!) - Returning a start as if start == 1"); + return alu->start + 1 + 1; + } + + return alu->start + alu->seq->bio_start + 1; +} + +/* Function: bio_end_AlnUnit(alu) + * + * Descrip: Tells the bio-coordinate of the + * end point of this alnunit + * + * + * Arg: alu [UNKN ] Undocumented argument [AlnUnit *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 144 "aln.dy" +int bio_end_AlnUnit(AlnUnit * alu) +{ + if( alu->seq == NULL ) { + warn("A mis-connected AlnUnit (no sequence!) - Returning a start as if start == 1"); + return alu->end + 1; + } + + return alu->end + alu->seq->bio_start; +} + + + +/* Function: swallow_AlnColumn_multiple(master,eaten,comp_func) + * + * Descrip: This function will 'swallow' any number of AlnColumns as long + * as the comparison function of the labels match (the basic + * comp function would be something like strcmp(a,b) == 0 ? TRUE : FALSE) + * The columns are 'swallowed' into master and come from eaten. (these + * columns could be in the same linked list, though it only makes sense + * if the master is before the eaten). + * + * It returns the first column that it could not swallow. + * + * you use this to collapse regions of the label alignment. + * + * + * Arg: master [UNKN ] column which will eat other columns [AlnColumn *] + * Arg: eaten [UNKN ] column which will be consumed [AlnColumn *] + * Arg: comp_func [FUNCP] comparison function for label set [boolean (*comp_func] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +# line 172 "aln.dy" +AlnColumn * swallow_AlnColumn_multiple(AlnColumn * master,AlnColumn * eaten,boolean (*comp_func)(char *,char *)) +{ + register int i; + + + for(i=0;eaten != NULL; eaten = eaten->next) { + if( swallow_AlnColumn(master,eaten,comp_func) == FALSE ) + break; + } + + return eaten; +} + + +/* Function: swallow_AlnColumn_number(master,eaten,num,comp_func) + * + * Descrip: Basicaly the same as /swallow_AlnColumn_mulitple but there is a maximum number + * of columns it will swallow + * + * + * Arg: master [UNKN ] column which will eat other columns [AlnColumn *] + * Arg: eaten [UNKN ] column which will be consumed [AlnColumn *] + * Arg: num [UNKN ] max number of columns to eat [int] + * Arg: comp_func [FUNCP] comparison function for label set [boolean (*comp_func] + * + * Return [UNKN ] number of columns eaten [int] + * + */ +# line 196 "aln.dy" +int swallow_AlnColumn_number(AlnColumn * master,AlnColumn * eaten,int num,boolean (*comp_func)(char *,char *)) +{ + register int i; + + for(i=0;i < num && eaten != NULL; eaten = eaten->next) { + if( swallow_AlnColumn(master,eaten,comp_func) == FALSE ) + break; + } + + return i; +} + + +/* Function: swallow_AlnColumn(master,eaten,comp_func) + * + * Descrip: This is the function that actually does the 'swallowing'. It will + * try to swallow eaten into master. If comp_func does not give us an + * ok (actually using /can_swallow_AlnColumn it returns FALSE. Otherwise + * it moves on the end of AlnColumn in master to eaten and adds the + * score of eaten to master. + * + * + * Arg: master [UNKN ] column which will eat [AlnColumn *] + * Arg: eaten [UNKN ] column which will dissappear into master if eatable [AlnColumn *] + * Arg: comp_func [FUNCP] comparison function for labels [boolean (*comp_func] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 220 "aln.dy" +boolean swallow_AlnColumn(AlnColumn * master,AlnColumn * eaten,boolean (*comp_func)(char *,char *)) +{ + register int i; + + if( can_swallow_AlnColumn(master,eaten,comp_func) == FALSE ) { + return FALSE; + } + + for(i=0;ilen;i++) { + master->alu[i]->end = eaten->alu[i]->end; + + /*** ok, for the moment, only add the 1st score, but eventually ***/ + /*** we should add all of them... ***/ + + master->alu[i]->score[0] += eaten->alu[i]->score[0]; + } + + + + return TRUE; +} + +/* Function: can_swallow_AlnColumn(comp_func,master,eaten) + * + * Descrip: checks to see if two columns are mergable from comp_func. + * First uses /identical_labels_in_AlnColumn to see if labels can be merged + * Then checks that starts in master are greater than starts in eaten + * + * + * Arg: comp_func [UNKN ] Undocumented argument [NullString] + * Arg: master [UNKN ] Undocumented argument [AlnColumn *] + * Arg: eaten [UNKN ] Undocumented argument [AlnColumn *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 248 "aln.dy" +boolean can_swallow_AlnColumn(AlnColumn * master,AlnColumn * eaten,boolean (*comp_func)(char *,char *)) +{ + register int i; + + if( identical_labels_in_AlnColumn(master,eaten,comp_func) == FALSE ) + return FALSE; + + for(i=0;ilen;i++) + if( master->alu[i]->start >= eaten->alu[i]->start) { + warn("In trying to compare to AlnColumns, have some 'eatable' starts greater than master starts %d %d in row %d",master->alu[i]->start,eaten->alu[i]->start,i); + return FALSE; + } + + return TRUE; +} + + +/* Function: identical_labels_in_AlnColumn(comp_func,one,two) + * + * Descrip: checks to see if two AlnColumns has mergable labels by + * comp_func. calls /identical_labels_in_AlnUnits for + * the actual comparison. + * + * + * Arg: comp_func [UNKN ] Undocumented argument [NullString] + * Arg: one [UNKN ] Undocumented argument [AlnColumn *] + * Arg: two [UNKN ] Undocumented argument [AlnColumn *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 271 "aln.dy" +boolean identical_labels_in_AlnColumn(AlnColumn * one,AlnColumn * two,boolean (*comp_func)(char *,char *)) +{ + register int i; + + if( one->len != two->len ) { + warn("Attempting to see if two AlnColumns with *different numbers of units* %d,%d are identical...serious problem",one->len,two->len); + return FALSE; + } + + for(i=0;ilen;i++) { + if( identical_labels_in_AlnUnits(one->alu[i],two->alu[i],comp_func) == FALSE ) + return FALSE; + } + + return TRUE; +} + +/* Function: identical_labels_in_AlnUnits(comp_func,one,two) + * + * Descrip: actually calls the comp_func for the label compairson + * + * + * Arg: comp_func [UNKN ] Undocumented argument [NullString] + * Arg: one [UNKN ] Undocumented argument [AlnUnit *] + * Arg: two [UNKN ] Undocumented argument [AlnUnit *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 292 "aln.dy" +boolean identical_labels_in_AlnUnits(AlnUnit * one,AlnUnit * two,boolean (*comp_func)(char *,char *)) +{ + if( (*comp_func)(one->text_label,two->text_label) == TRUE ) + return TRUE; + else return FALSE; +} + + +/* Function: replace_and_free_AlnColumn_with_one(start,end,insert) + * + * Descrip: Linked list manipulation function + * + * Puts insert between start and end, and free's from start->next + * onwards. *Beware* if start is linked to end before calling this + * function thsi wil free end and everything chained to it. Think + * before you call this! + * + * + * Arg: start [UNKN ] Undocumented argument [AlnColumn *] + * Arg: end [UNKN ] Undocumented argument [AlnColumn *] + * Arg: insert [UNKN ] Undocumented argument [AlnColumn *] + * + */ +# line 308 "aln.dy" +void replace_and_free_AlnColumn_with_one(AlnColumn * start,AlnColumn * end,AlnColumn * insert) +{ + replace_AlnColumn_with_one(start,end,insert); + + free_AlnColumn(start->next); +} + + + +/* Function: replace_AlnColumn_with_one(start,end,insert) + * + * Descrip: Linked list manipulation function + * + * places insert between start and end. If start/end are not + * continuous then it will loop out the start/end region + * + * + * Arg: start [UNKN ] Undocumented argument [AlnColumn *] + * Arg: end [UNKN ] Undocumented argument [AlnColumn *] + * Arg: insert [UNKN ] Undocumented argument [AlnColumn *] + * + */ +# line 323 "aln.dy" +void replace_AlnColumn_with_one(AlnColumn * start,AlnColumn * end,AlnColumn * insert) +{ + start->next = insert; + insert->next = end->next; + end->next = NULL; + +} + + +/* Function: insert_AlnColumn(start,insert) + * + * Descrip: Linked list manipulation function + * + * places insert just after start: links insert + * up to what start was linked to + * + * + * Arg: start [UNKN ] Undocumented argument [AlnColumn *] + * Arg: insert [UNKN ] Undocumented argument [AlnColumn *] + * + */ +# line 338 "aln.dy" +void insert_AlnColumn(AlnColumn * start,AlnColumn * insert) +{ + insert->next = start->next; + start->next = insert; +} + + +/* Function: go_back_n_AlnColumn(alb,start,n) + * + * Descrip: Linked list movement function + * + * A nasty function to reverse up a singly linked list by going to + * the start and coming back until you are in the current position. yuk. + * + * + * Arg: alb [UNKN ] Undocumented argument [AlnBlock *] + * Arg: start [UNKN ] Undocumented argument [AlnColumn *] + * Arg: n [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +# line 351 "aln.dy" +AlnColumn * go_back_n_AlnColumn(AlnBlock * alb,AlnColumn * start,int n) +{ + /*** really quite hacky ****/ + + AlnColumn * cursor; + AlnColumn * back; + register int i; + + for(i=0,cursor = alb->start;i < n && cursor != NULL && cursor != start;i++,cursor = cursor->next) + ; + + if( i < n ) { + return NULL; /** should I post an error? **/ + } + + for(back = alb->start;cursor != NULL && cursor != start;cursor = cursor->next, back = back->next) + ; + + if( cursor == NULL ) { + warn("could not find you AlnColumn in AlnBlock at all... so could not get xxx positions back"); + return NULL; + } + + return back; +} + + + /*******************************/ + /* show functions for aln block*/ + /* */ + /* these are really basic and */ + /* should use alndisplay for */ + /* ascii display */ + /*******************************/ + +/* Function: dump_ascii_AlnBlock(alb,ofp) + * + * Descrip: Dumps the alignment in rereadable ascii form. + * + * Not really for human consumption + * + * + * Arg: alb [UNKN ] AlnBlock to dump [AlnBlock *] + * Arg: ofp [UNKN ] File stream to dump to [FILE *] + * + */ +# line 394 "aln.dy" +void dump_ascii_AlnBlock(AlnBlock * alb,FILE * ofp) +{ + int i; + AlnColumn * alc; + + for(alc=alb->start;alc != NULL;alc = alc->next) { + fprintf(ofp,"[%d:%d \"%s\" %d]",alc->alu[0]->start,alc->alu[0]->end,alc->alu[0]->text_label,alc->alu[0]->score[0]); + + for(i=1;ilen;i++) { + fprintf(ofp,",[%d:%d \"%s\" %d]",alc->alu[i]->start,alc->alu[i]->end,alc->alu[i]->text_label,alc->alu[i]->score[0]); + } + + fprintf(ofp,"\n"); + } + + fprintf(ofp,"\\"); + +} + +/* Function: bit_ascii_AlnBlock(alb,ofp) + * + * Descrip: Should not be here... + * + * + * Arg: alb [UNKN ] AlnBlock to dump [AlnBlock *] + * Arg: ofp [UNKN ] File stream to dump to [FILE *] + * + */ +# line 419 "aln.dy" +void bit_ascii_AlnBlock(AlnBlock * alb,FILE * ofp) +{ + int i; + AlnColumn * alc; + + for(alc=alb->start;alc != NULL;alc = alc->next) { + fprintf(ofp,"%3.2f ",(double)Score2Bits(alc->alu[0]->score[0])); + fprintf(ofp,"[%d:%d \"%s\" %d]",alc->alu[0]->start,alc->alu[0]->end,alc->alu[0]->text_label,alc->alu[0]->score[0]); + + for(i=1;ilen;i++) { + fprintf(ofp,",[%d:%d \"%s\" %d]",alc->alu[i]->start,alc->alu[i]->end,alc->alu[i]->text_label,alc->alu[i]->score[0]); + } + + fprintf(ofp,"\n"); + } + + +} + +/* Function: read_ascii_dump_AlnBlock(ifp) + * + * Descrip: Reads an ascii dumped alignment + * + * + * Arg: ifp [UNKN ] File stream to read from [FILE *] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +# line 443 "aln.dy" +AlnBlock * read_ascii_dump_AlnBlock(FILE * ifp) +{ + char buffer[MAXLINE]; + AlnBlock * out; + AlnColumn ** attach; + AlnColumn * new; + + out = AlnBlock_alloc_std(); + + attach = &out->start; + + while( fgets(buffer,MAXLINE,ifp) != NULL ) { + if( strstartcmp(buffer,"//") == 0 ) + break; + + new = read_dumped_ascii_AlnColumn_line(buffer); + if( new == NULL ){ + warn("Unable to read entire AlnBlock. Returning no alignment"); + free_AlnBlock(out); + return NULL; + } + + *attach = new; + attach = &new->next; + } + return out; + +} + +/* Function: read_dumped_ascii_AlnColumn_line(line) + * + * Descrip: Reads one line of an ascii dumped alignment + * + * + * Arg: line [UNKN ] line to be read [char *] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +# line 478 "aln.dy" +AlnColumn * read_dumped_ascii_AlnColumn_line(char * line) +{ + char ** base, **bstr; + AlnUnit * alu; + AlnColumn * out; + + int start; + int end; + int score; + char buffer[128]; /* implies max label 128 characters. Worrying? */ + + out = AlnColumn_alloc_len(2); /** most times we are reading in pairwise alignments **/ + + /** split on comma, then sscanf each one **/ + + base = bstr = breakstring_protect(line,",","\""); + + for(;*bstr != NULL;bstr++) { + sscanf(*bstr,"[%d,%d \"%s\" %d",&start,&end,buffer,&score); + alu = AlnUnit_alloc(); + + alu->start = start; + alu->end = end; + alu->score[0] = score; + alu->text_label = stringalloc(buffer); + + add_AlnColumn(out,alu); + } + + return out; +} + + +/* Function: show_flat_AlnBlock(alb,ofp) + * + * Descrip: Shows the AlnBlock in vaguely human + * readable form + * + * + * Arg: alb [UNKN ] AlnBlock to show [AlnBlock *] + * Arg: ofp [UNKN ] output [FILE *] + * + */ +# line 519 "aln.dy" +void show_flat_AlnBlock(AlnBlock * alb,FILE * ofp) +{ + AlnColumn * alc; + register int i; + + for(i=0,alc = alb->start;alc != NULL;alc = alc->next,i++) { + fprintf(ofp,"Column %d:\n",i); + show_flat_AlnColumn(alc,ofp); + } +} + +/* Function: show_flat_AlnColumn(alc,ofp) + * + * Descrip: sub for show_flat_AlnBlock + * + * + * Arg: alc [UNKN ] Undocumented argument [AlnColumn *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 534 "aln.dy" +void show_flat_AlnColumn(AlnColumn * alc,FILE * ofp) +{ + register int i; + for(i=0;ilen;i++) { + fprintf(ofp,"Unit %2d- ",i); + show_flat_AlnUnit(alc->alu[i],ofp); + } + fprintf(ofp,"\n"); + +} + +/* Function: show_flat_AlnUnit(alu,ofp) + * + * Descrip: sub for show_flat_AlnUnit + * + * + * Arg: alu [UNKN ] Undocumented argument [AlnUnit *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 549 "aln.dy" +void show_flat_AlnUnit(AlnUnit * alu,FILE * ofp) +{ + fprintf(ofp,"[%4d-%4d] [%s]\n",alu->start,alu->end,alu->text_label == NULL ? "No Label" : alu->text_label); +} + + +/* Function: read_flat_AlnUnit_line(line,ret_pos) + * + * Descrip: Not used currently. To read in the flat output + * format + * + * + * Arg: line [UNKN ] Undocumented argument [char *] + * Arg: ret_pos [UNKN ] Undocumented argument [int *] + * + * Return [UNKN ] Undocumented return value [AlnUnit *] + * + */ +# line 560 "aln.dy" +AlnUnit * read_flat_AlnUnit_line(char * line,int * ret_pos) +{ + AlnUnit * out; + char buffer[MAXLINE]; + int start; + int end; + int pos; + int num; + + sscanf(line,"Unit %d- Start: [%d], End: [%d] Label: number [%d] text [%s]",&pos,&start,&end,&num,buffer); + + out = AlnUnit_alloc(); + if( out == NULL ) + return NULL; + + out->start = start; + out->end = end; + out->label = num; + out->text_label = stringalloc(buffer); + + if( ret_pos != NULL ) + *ret_pos = pos; + + return out; +} + + /***********************************/ + /* movement functions around Aln's */ + /***********************************/ + +/* Function: get_second_end_AlnColumn(alb) + * + * Descrip: Not sure if this is used! + * + * + * Arg: alb [UNKN ] Undocumented argument [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +# line 593 "aln.dy" +AlnColumn * get_second_end_AlnColumn(AlnBlock * alb) +{ + AlnColumn * end = NULL; + AlnColumn * prev = NULL; + + for(end = alb->start;end->next != NULL;prev = end,end = end->next) + ; + + return prev; +} + + +/* Function: get_end_AlnColumn(alb) + * + * Descrip: To get to the last AlnColumn. If this was + * a doubly linked list, life would be much easier + * + * + * Arg: alb [UNKN ] Undocumented argument [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +# line 609 "aln.dy" +AlnColumn * get_end_AlnColumn(AlnBlock * alb) +{ + AlnColumn * end; + + for(end = alb->start;end->next != NULL;end = end->next) + ; + + return end; +} + +/* Function: link_AlnUnits_AlnBlock(alb) + * + * Descrip: Links up all AlnUnits to their parent + * sequences + * + * + * Arg: alb [UNKN ] Undocumented argument [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 623 "aln.dy" +boolean link_AlnUnits_AlnBlock(AlnBlock * alb) +{ + AlnSequence * aseq; + AlnUnit * au; + int i; + + for(i=0;ilen;i++) { + aseq = alb->seq[i]; + for(au = aseq->start;au != NULL;au++) { + au->seq = aseq; + } + } + + return TRUE; +} + + + + + + /************************************/ + /* constructors/deconstructors to */ + /* deal with linked list aspect of */ + /* data */ + /************************************/ + +/* Function: new_pairwise_AlnColumn(void) + * + * Descrip: Function as a constructor for the special + * case of a pairwise alignment. Makes an + * AlnColumn and puts in two AlnUnits all ready + * to be linked in. + * + * + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +# line 655 "aln.dy" +AlnColumn * new_pairwise_AlnColumn(void) +{ + AlnColumn * out; + + out = AlnColumn_alloc_len(2); + add_AlnColumn(out,AlnUnit_alloc()); + add_AlnColumn(out,AlnUnit_alloc()); + + return out; +} + +/* Function: free_AlnColumn(obj) + * + * Descrip: Specilased deconstructor needed because + * of linked list nature of the data structure + * + * + * Arg: obj [UNKN ] Undocumented argument [AlnColumn *] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +# line 671 "aln.dy" +AlnColumn * free_AlnColumn(AlnColumn * obj) +{ + + if( obj == NULL ) { + warn("passed a NULL object into free_AlnColumn!"); + return NULL; + } + + if( obj->dynamite_hard_link > 1 ) { + obj->dynamite_hard_link--; + return NULL; + } + + if( obj->next != NULL ) + free_AlnColumn(obj->next); + if( obj->alu != NULL ) + ckfree(obj->alu); /*** units free'd from linked list ***/ + + ckfree(obj); + + return NULL; +} + +/* Function: free_AlnUnit(obj) + * + * Descrip: Specilased deconstructor needed because + * of linked list nature of the data structure + * + * + * Arg: obj [UNKN ] Undocumented argument [AlnUnit *] + * + * Return [UNKN ] Undocumented return value [AlnUnit *] + * + */ +# line 699 "aln.dy" +AlnUnit * free_AlnUnit(AlnUnit * obj) +{ + if( obj == NULL ) + return NULL; + + if( obj->dynamite_hard_link > 1 ) { + obj->dynamite_hard_link--; + return NULL; + } + + if( obj->next != NULL ) + free_AlnUnit(obj->next); + + ckfree(obj); + return NULL; +} + + +# line 743 "aln.c" +/* Function: hard_link_AlnUnit(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnUnit *] + * + * Return [UNKN ] Undocumented return value [AlnUnit *] + * + */ +AlnUnit * hard_link_AlnUnit(AlnUnit * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a AlnUnit object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: AlnUnit_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnUnit *] + * + */ +AlnUnit * AlnUnit_alloc(void) +{ + AlnUnit * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(AlnUnit *) ckalloc (sizeof(AlnUnit))) == NULL) { + warn("AlnUnit_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->start = 0; + out->end = 0; + out->label = 0; + /* score[AlnUnitSCORENUMBER] is an array: no default possible */ + out->in_column = TRUE; + + + return out; +} + + +/* Function: swap_AlnColumn(list,i,j) + * + * Descrip: swap function: an internal for qsort_AlnColumn + * swaps two positions in the array + * + * + * Arg: list [UNKN ] List of structures to swap in [AlnUnit **] + * Arg: i [UNKN ] swap position [int] + * Arg: j [UNKN ] swap position [int] + * + */ +/* swap function for qsort function */ +void swap_AlnColumn(AlnUnit ** list,int i,int j) +{ + AlnUnit * temp; + temp=list[i]; + list[i]=list[j]; + list[j]=temp; +} + + +/* Function: qsort_AlnColumn(list,left,right,comp) + * + * Descrip: qsort - lifted from K&R + * sorts the array using quicksort + * Probably much better to call sort_AlnColumn which sorts from start to end + * + * + * Arg: list [UNKN ] List of structures to swap in [AlnUnit **] + * Arg: left [UNKN ] left position [int] + * Arg: right [UNKN ] right position [int] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void qsort_AlnColumn(AlnUnit ** list,int left,int right,int (*comp)(AlnUnit * ,AlnUnit * )) +{ + int i,last; + if( left >= right ) + return; + + + swap_AlnColumn(list,left,(left+right)/2); + last = left; + for ( i=left+1; i <= right;i++) { + if( (*comp)(list[i],list[left]) < 0) + swap_AlnColumn (list,++last,i); + } + swap_AlnColumn (list,left,last); + qsort_AlnColumn(list,left,last-1,comp); + qsort_AlnColumn(list,last+1,right,comp); +} + + +/* Function: sort_AlnColumn(obj,comp) + * + * Descrip: sorts from start to end using comp + * sorts the array using quicksort by calling qsort_AlnColumn + * + * + * Arg: obj [UNKN ] Object containing list [AlnColumn *] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void sort_AlnColumn(AlnColumn * obj,int (*comp)(AlnUnit *, AlnUnit *)) +{ + qsort_AlnColumn(obj->alu,0,obj->len-1,comp); + return; +} + + +/* Function: expand_AlnColumn(obj,len) + * + * Descrip: Really an internal function for add_AlnColumn + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnColumn *] + * Arg: len [UNKN ] Length to add one [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean expand_AlnColumn(AlnColumn * obj,int len) +{ + + + if( obj->maxlen > obj->len ) { + warn("expand_AlnColumn called with no need"); + return TRUE; + } + + + if( (obj->alu = (AlnUnit ** ) ckrealloc (obj->alu,sizeof(AlnUnit *)*len)) == NULL) { + warn("ckrealloc failed for expand_AlnColumn, returning FALSE"); + return FALSE; + } + obj->maxlen = len; + return TRUE; +} + + +/* Function: add_AlnColumn(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnColumn *] + * Arg: add [OWNER] Object to add to the list [AlnUnit *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +/* will expand function if necessary */ +boolean add_AlnColumn(AlnColumn * obj,AlnUnit * add) +{ + if( obj->len >= obj->maxlen) { + if( expand_AlnColumn(obj,obj->len + AlnColumnLISTLENGTH) == FALSE) + return FALSE; + } + + + obj->alu[obj->len++]=add; + return TRUE; +} + + +/* Function: flush_AlnColumn(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnColumn *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int flush_AlnColumn(AlnColumn * obj) +{ + int i; + + + for(i=0;ilen;i++) { + if( obj->alu[i] != NULL) { + free_AlnUnit(obj->alu[i]); + obj->alu[i] = NULL; + } + } /* end of for i over list length */ + + + obj->len = 0; + return i; +} + + +/* Function: AlnColumn_alloc_std(void) + * + * Descrip: Equivalent to AlnColumn_alloc_len(AlnColumnLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * AlnColumn_alloc_std(void) +{ + return AlnColumn_alloc_len(AlnColumnLISTLENGTH); +} + + +/* Function: AlnColumn_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * AlnColumn_alloc_len(int len) +{ + AlnColumn * out;/* out is exported at the end of function */ + + + /* Call alloc function: return NULL if NULL */ + /* Warning message alread in alloc function */ + if((out = AlnColumn_alloc()) == NULL) + return NULL; + + + /* Calling ckcalloc for list elements */ + if((out->alu = (AlnUnit ** ) ckcalloc (len,sizeof(AlnUnit *))) == NULL) { + warn("Warning, ckcalloc failed in AlnColumn_alloc_len"); + return NULL; + } + out->len = 0; + out->maxlen = len; + + + return out; +} + + +/* Function: hard_link_AlnColumn(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnColumn *] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * hard_link_AlnColumn(AlnColumn * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a AlnColumn object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: AlnColumn_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * AlnColumn_alloc(void) +{ + AlnColumn * out;/* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(AlnColumn *) ckalloc (sizeof(AlnColumn))) == NULL) { + warn("AlnColumn_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->alu = NULL; + out->len = out->maxlen = 0; + + + return out; +} + + +/* Function: hard_link_AlnSequence(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnSequence *] + * + * Return [UNKN ] Undocumented return value [AlnSequence *] + * + */ +AlnSequence * hard_link_AlnSequence(AlnSequence * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a AlnSequence object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: AlnSequence_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnSequence *] + * + */ +AlnSequence * AlnSequence_alloc(void) +{ + AlnSequence * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(AlnSequence *) ckalloc (sizeof(AlnSequence))) == NULL) { + warn("AlnSequence_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->start = NULL; + out->data_type = 0; + out->bio_start = 1; + out->bio_end = -1; + + + return out; +} + + +/* Function: free_AlnSequence(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnSequence *] + * + * Return [UNKN ] Undocumented return value [AlnSequence *] + * + */ +AlnSequence * free_AlnSequence(AlnSequence * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a AlnSequence obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->start != NULL) + free_AlnUnit(obj->start); + /* obj->data is linked in */ + + + ckfree(obj); + return NULL; +} + + +/* Function: swap_AlnBlock(list,i,j) + * + * Descrip: swap function: an internal for qsort_AlnBlock + * swaps two positions in the array + * + * + * Arg: list [UNKN ] List of structures to swap in [AlnSequence **] + * Arg: i [UNKN ] swap position [int] + * Arg: j [UNKN ] swap position [int] + * + */ +/* swap function for qsort function */ +void swap_AlnBlock(AlnSequence ** list,int i,int j) +{ + AlnSequence * temp; + temp=list[i]; + list[i]=list[j]; + list[j]=temp; +} + + +/* Function: qsort_AlnBlock(list,left,right,comp) + * + * Descrip: qsort - lifted from K&R + * sorts the array using quicksort + * Probably much better to call sort_AlnBlock which sorts from start to end + * + * + * Arg: list [UNKN ] List of structures to swap in [AlnSequence **] + * Arg: left [UNKN ] left position [int] + * Arg: right [UNKN ] right position [int] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void qsort_AlnBlock(AlnSequence ** list,int left,int right,int (*comp)(AlnSequence * ,AlnSequence * )) +{ + int i,last; + if( left >= right ) + return; + + + swap_AlnBlock(list,left,(left+right)/2); + last = left; + for ( i=left+1; i <= right;i++) { + if( (*comp)(list[i],list[left]) < 0) + swap_AlnBlock (list,++last,i); + } + swap_AlnBlock (list,left,last); + qsort_AlnBlock(list,left,last-1,comp); + qsort_AlnBlock(list,last+1,right,comp); +} + + +/* Function: sort_AlnBlock(obj,comp) + * + * Descrip: sorts from start to end using comp + * sorts the array using quicksort by calling qsort_AlnBlock + * + * + * Arg: obj [UNKN ] Object containing list [AlnBlock *] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void sort_AlnBlock(AlnBlock * obj,int (*comp)(AlnSequence *, AlnSequence *)) +{ + qsort_AlnBlock(obj->seq,0,obj->len-1,comp); + return; +} + + +/* Function: expand_AlnBlock(obj,len) + * + * Descrip: Really an internal function for add_AlnBlock + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnBlock *] + * Arg: len [UNKN ] Length to add one [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean expand_AlnBlock(AlnBlock * obj,int len) +{ + + + if( obj->maxlen > obj->len ) { + warn("expand_AlnBlock called with no need"); + return TRUE; + } + + + if( (obj->seq = (AlnSequence ** ) ckrealloc (obj->seq,sizeof(AlnSequence *)*len)) == NULL) { + warn("ckrealloc failed for expand_AlnBlock, returning FALSE"); + return FALSE; + } + obj->maxlen = len; + return TRUE; +} + + +/* Function: add_AlnBlock(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnBlock *] + * Arg: add [OWNER] Object to add to the list [AlnSequence *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +/* will expand function if necessary */ +boolean add_AlnBlock(AlnBlock * obj,AlnSequence * add) +{ + if( obj->len >= obj->maxlen) { + if( expand_AlnBlock(obj,obj->len + AlnBlockLISTLENGTH) == FALSE) + return FALSE; + } + + + obj->seq[obj->len++]=add; + return TRUE; +} + + +/* Function: flush_AlnBlock(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int flush_AlnBlock(AlnBlock * obj) +{ + int i; + + + for(i=0;ilen;i++) { + if( obj->seq[i] != NULL) { + free_AlnSequence(obj->seq[i]); + obj->seq[i] = NULL; + } + } /* end of for i over list length */ + + + obj->len = 0; + return i; +} + + +/* Function: AlnBlock_alloc_std(void) + * + * Descrip: Equivalent to AlnBlock_alloc_len(AlnBlockLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * AlnBlock_alloc_std(void) +{ + return AlnBlock_alloc_len(AlnBlockLISTLENGTH); +} + + +/* Function: AlnBlock_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * AlnBlock_alloc_len(int len) +{ + AlnBlock * out; /* out is exported at the end of function */ + + + /* Call alloc function: return NULL if NULL */ + /* Warning message alread in alloc function */ + if((out = AlnBlock_alloc()) == NULL) + return NULL; + + + /* Calling ckcalloc for list elements */ + if((out->seq = (AlnSequence ** ) ckcalloc (len,sizeof(AlnSequence *))) == NULL) { + warn("Warning, ckcalloc failed in AlnBlock_alloc_len"); + return NULL; + } + out->len = 0; + out->maxlen = len; + + + return out; +} + + +/* Function: hard_link_AlnBlock(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * hard_link_AlnBlock(AlnBlock * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a AlnBlock object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: AlnBlock_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * AlnBlock_alloc(void) +{ + AlnBlock * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(AlnBlock *) ckalloc (sizeof(AlnBlock))) == NULL) { + warn("AlnBlock_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->start = NULL; + out->seq = NULL; + out->len = out->maxlen = 0; + out->length = 0; + out->score = 0; + + + return out; +} + + +/* Function: free_AlnBlock(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * free_AlnBlock(AlnBlock * obj) +{ + int i; + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a AlnBlock obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->start != NULL) + free_AlnColumn(obj->start); + if( obj->seq != NULL) { + for(i=0;ilen;i++) { + if( obj->seq[i] != NULL) + free_AlnSequence(obj->seq[i]); + } + ckfree(obj->seq); + } + + + ckfree(obj); + return NULL; +} + + +/* Function: swap_AlnBlockList(list,i,j) + * + * Descrip: swap function: an internal for qsort_AlnBlockList + * swaps two positions in the array + * + * + * Arg: list [UNKN ] List of structures to swap in [AlnBlock **] + * Arg: i [UNKN ] swap position [int] + * Arg: j [UNKN ] swap position [int] + * + */ +/* swap function for qsort function */ +void swap_AlnBlockList(AlnBlock ** list,int i,int j) +{ + AlnBlock * temp; + temp=list[i]; + list[i]=list[j]; + list[j]=temp; +} + + +/* Function: qsort_AlnBlockList(list,left,right,comp) + * + * Descrip: qsort - lifted from K&R + * sorts the array using quicksort + * Probably much better to call sort_AlnBlockList which sorts from start to end + * + * + * Arg: list [UNKN ] List of structures to swap in [AlnBlock **] + * Arg: left [UNKN ] left position [int] + * Arg: right [UNKN ] right position [int] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void qsort_AlnBlockList(AlnBlock ** list,int left,int right,int (*comp)(AlnBlock * ,AlnBlock * )) +{ + int i,last; + if( left >= right ) + return; + + + swap_AlnBlockList(list,left,(left+right)/2); + last = left; + for ( i=left+1; i <= right;i++) { + if( (*comp)(list[i],list[left]) < 0) + swap_AlnBlockList (list,++last,i); + } + swap_AlnBlockList (list,left,last); + qsort_AlnBlockList(list,left,last-1,comp); + qsort_AlnBlockList(list,last+1,right,comp); +} + + +/* Function: sort_AlnBlockList(obj,comp) + * + * Descrip: sorts from start to end using comp + * sorts the array using quicksort by calling qsort_AlnBlockList + * + * + * Arg: obj [UNKN ] Object containing list [AlnBlockList *] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void sort_AlnBlockList(AlnBlockList * obj,int (*comp)(AlnBlock *, AlnBlock *)) +{ + qsort_AlnBlockList(obj->alb,0,obj->len-1,comp); + return; +} + + +/* Function: expand_AlnBlockList(obj,len) + * + * Descrip: Really an internal function for add_AlnBlockList + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnBlockList *] + * Arg: len [UNKN ] Length to add one [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean expand_AlnBlockList(AlnBlockList * obj,int len) +{ + + + if( obj->maxlen > obj->len ) { + warn("expand_AlnBlockList called with no need"); + return TRUE; + } + + + if( (obj->alb = (AlnBlock ** ) ckrealloc (obj->alb,sizeof(AlnBlock *)*len)) == NULL) { + warn("ckrealloc failed for expand_AlnBlockList, returning FALSE"); + return FALSE; + } + obj->maxlen = len; + return TRUE; +} + + +/* Function: add_AlnBlockList(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnBlockList *] + * Arg: add [OWNER] Object to add to the list [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +/* will expand function if necessary */ +boolean add_AlnBlockList(AlnBlockList * obj,AlnBlock * add) +{ + if( obj->len >= obj->maxlen) { + if( expand_AlnBlockList(obj,obj->len + AlnBlockListLISTLENGTH) == FALSE) + return FALSE; + } + + + obj->alb[obj->len++]=add; + return TRUE; +} + + +/* Function: flush_AlnBlockList(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnBlockList *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int flush_AlnBlockList(AlnBlockList * obj) +{ + int i; + + + for(i=0;ilen;i++) { + if( obj->alb[i] != NULL) { + free_AlnBlock(obj->alb[i]); + obj->alb[i] = NULL; + } + } /* end of for i over list length */ + + + obj->len = 0; + return i; +} + + +/* Function: AlnBlockList_alloc_std(void) + * + * Descrip: Equivalent to AlnBlockList_alloc_len(AlnBlockListLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [AlnBlockList *] + * + */ +AlnBlockList * AlnBlockList_alloc_std(void) +{ + return AlnBlockList_alloc_len(AlnBlockListLISTLENGTH); +} + + +/* Function: AlnBlockList_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [AlnBlockList *] + * + */ +AlnBlockList * AlnBlockList_alloc_len(int len) +{ + AlnBlockList * out; /* out is exported at the end of function */ + + + /* Call alloc function: return NULL if NULL */ + /* Warning message alread in alloc function */ + if((out = AlnBlockList_alloc()) == NULL) + return NULL; + + + /* Calling ckcalloc for list elements */ + if((out->alb = (AlnBlock ** ) ckcalloc (len,sizeof(AlnBlock *))) == NULL) { + warn("Warning, ckcalloc failed in AlnBlockList_alloc_len"); + return NULL; + } + out->len = 0; + out->maxlen = len; + + + return out; +} + + +/* Function: hard_link_AlnBlockList(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnBlockList *] + * + * Return [UNKN ] Undocumented return value [AlnBlockList *] + * + */ +AlnBlockList * hard_link_AlnBlockList(AlnBlockList * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a AlnBlockList object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: AlnBlockList_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnBlockList *] + * + */ +AlnBlockList * AlnBlockList_alloc(void) +{ + AlnBlockList * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(AlnBlockList *) ckalloc (sizeof(AlnBlockList))) == NULL) { + warn("AlnBlockList_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->alb = NULL; + out->len = out->maxlen = 0; + + + return out; +} + + +/* Function: free_AlnBlockList(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnBlockList *] + * + * Return [UNKN ] Undocumented return value [AlnBlockList *] + * + */ +AlnBlockList * free_AlnBlockList(AlnBlockList * obj) +{ + int i; + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a AlnBlockList obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->alb != NULL) { + for(i=0;ilen;i++) { + if( obj->alb[i] != NULL) + free_AlnBlock(obj->alb[i]); + } + ckfree(obj->alb); + } + + + ckfree(obj); + return NULL; +} + + +/* Function: replace_start_AlnBlock(obj,start) + * + * Descrip: Replace member variable start + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnBlock *] + * Arg: start [OWNER] New value of the variable [AlnColumn *] + * + * Return [SOFT ] member variable start [boolean] + * + */ +boolean replace_start_AlnBlock(AlnBlock * obj,AlnColumn * start) +{ + if( obj == NULL) { + warn("In replacement function start for object AlnBlock, got a NULL object"); + return FALSE; + } + obj->start = start; + return TRUE; +} + + +/* Function: access_start_AlnBlock(obj) + * + * Descrip: Access member variable start + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnBlock *] + * + * Return [SOFT ] member variable start [AlnColumn *] + * + */ +AlnColumn * access_start_AlnBlock(AlnBlock * obj) +{ + if( obj == NULL) { + warn("In accessor function start for object AlnBlock, got a NULL object"); + return NULL; + } + return obj->start; +} + + +/* Function: access_seq_AlnBlock(obj,i) + * + * Descrip: Access members stored in the seq list + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the list [AlnBlock *] + * Arg: i [UNKN ] Position in the list [int] + * + * Return [SOFT ] Element of the list [AlnSequence *] + * + */ +AlnSequence * access_seq_AlnBlock(AlnBlock * obj,int i) +{ + if( obj == NULL) { + warn("In accessor function seq for object AlnBlock, got a NULL object"); + return NULL; + } + if( obj->len <= i ) { + warn("In accessor function seq for object AlnBlock, index %%d is greater than list length %%d",i,obj->len); + return NULL; + } + return obj->seq[i]; +} + + +/* Function: length_seq_AlnBlock(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the list [AlnBlock *] + * + * Return [UNKN ] length of the list [int] + * + */ +int length_seq_AlnBlock(AlnBlock * obj) +{ + if( obj == NULL) { + warn("In length function seq for object AlnBlock, got a NULL object"); + return -1; + } + return obj->len; +} + + +/* Function: replace_length_AlnBlock(obj,length) + * + * Descrip: Replace member variable length + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnBlock *] + * Arg: length [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable length [boolean] + * + */ +boolean replace_length_AlnBlock(AlnBlock * obj,int length) +{ + if( obj == NULL) { + warn("In replacement function length for object AlnBlock, got a NULL object"); + return FALSE; + } + obj->length = length; + return TRUE; +} + + +/* Function: access_length_AlnBlock(obj) + * + * Descrip: Access member variable length + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnBlock *] + * + * Return [SOFT ] member variable length [int] + * + */ +int access_length_AlnBlock(AlnBlock * obj) +{ + if( obj == NULL) { + warn("In accessor function length for object AlnBlock, got a NULL object"); + return 0; + } + return obj->length; +} + + +/* Function: replace_score_AlnBlock(obj,score) + * + * Descrip: Replace member variable score + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnBlock *] + * Arg: score [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable score [boolean] + * + */ +boolean replace_score_AlnBlock(AlnBlock * obj,int score) +{ + if( obj == NULL) { + warn("In replacement function score for object AlnBlock, got a NULL object"); + return FALSE; + } + obj->score = score; + return TRUE; +} + + +/* Function: access_score_AlnBlock(obj) + * + * Descrip: Access member variable score + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnBlock *] + * + * Return [SOFT ] member variable score [int] + * + */ +int access_score_AlnBlock(AlnBlock * obj) +{ + if( obj == NULL) { + warn("In accessor function score for object AlnBlock, got a NULL object"); + return 0; + } + return obj->score; +} + + +/* Function: access_alu_AlnColumn(obj,i) + * + * Descrip: Access members stored in the alu list + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the list [AlnColumn *] + * Arg: i [UNKN ] Position in the list [int] + * + * Return [SOFT ] Element of the list [AlnUnit *] + * + */ +AlnUnit * access_alu_AlnColumn(AlnColumn * obj,int i) +{ + if( obj == NULL) { + warn("In accessor function alu for object AlnColumn, got a NULL object"); + return NULL; + } + if( obj->len <= i ) { + warn("In accessor function alu for object AlnColumn, index %%d is greater than list length %%d",i,obj->len); + return NULL; + } + return obj->alu[i]; +} + + +/* Function: length_alu_AlnColumn(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the list [AlnColumn *] + * + * Return [UNKN ] length of the list [int] + * + */ +int length_alu_AlnColumn(AlnColumn * obj) +{ + if( obj == NULL) { + warn("In length function alu for object AlnColumn, got a NULL object"); + return -1; + } + return obj->len; +} + + +/* Function: replace_next_AlnColumn(obj,next) + * + * Descrip: Replace member variable next + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnColumn *] + * Arg: next [OWNER] New value of the variable [AlnColumn *] + * + * Return [SOFT ] member variable next [boolean] + * + */ +boolean replace_next_AlnColumn(AlnColumn * obj,AlnColumn * next) +{ + if( obj == NULL) { + warn("In replacement function next for object AlnColumn, got a NULL object"); + return FALSE; + } + obj->next = next; + return TRUE; +} + + +/* Function: access_next_AlnColumn(obj) + * + * Descrip: Access member variable next + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnColumn *] + * + * Return [SOFT ] member variable next [AlnColumn *] + * + */ +AlnColumn * access_next_AlnColumn(AlnColumn * obj) +{ + if( obj == NULL) { + warn("In accessor function next for object AlnColumn, got a NULL object"); + return NULL; + } + return obj->next; +} + + +/* Function: replace_start_AlnUnit(obj,start) + * + * Descrip: Replace member variable start + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * Arg: start [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable start [boolean] + * + */ +boolean replace_start_AlnUnit(AlnUnit * obj,int start) +{ + if( obj == NULL) { + warn("In replacement function start for object AlnUnit, got a NULL object"); + return FALSE; + } + obj->start = start; + return TRUE; +} + + +/* Function: access_start_AlnUnit(obj) + * + * Descrip: Access member variable start + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * + * Return [SOFT ] member variable start [int] + * + */ +int access_start_AlnUnit(AlnUnit * obj) +{ + if( obj == NULL) { + warn("In accessor function start for object AlnUnit, got a NULL object"); + return 0; + } + return obj->start; +} + + +/* Function: replace_end_AlnUnit(obj,end) + * + * Descrip: Replace member variable end + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * Arg: end [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable end [boolean] + * + */ +boolean replace_end_AlnUnit(AlnUnit * obj,int end) +{ + if( obj == NULL) { + warn("In replacement function end for object AlnUnit, got a NULL object"); + return FALSE; + } + obj->end = end; + return TRUE; +} + + +/* Function: access_end_AlnUnit(obj) + * + * Descrip: Access member variable end + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * + * Return [SOFT ] member variable end [int] + * + */ +int access_end_AlnUnit(AlnUnit * obj) +{ + if( obj == NULL) { + warn("In accessor function end for object AlnUnit, got a NULL object"); + return 0; + } + return obj->end; +} + + +/* Function: replace_label_AlnUnit(obj,label) + * + * Descrip: Replace member variable label + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * Arg: label [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable label [boolean] + * + */ +boolean replace_label_AlnUnit(AlnUnit * obj,int label) +{ + if( obj == NULL) { + warn("In replacement function label for object AlnUnit, got a NULL object"); + return FALSE; + } + obj->label = label; + return TRUE; +} + + +/* Function: access_label_AlnUnit(obj) + * + * Descrip: Access member variable label + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * + * Return [SOFT ] member variable label [int] + * + */ +int access_label_AlnUnit(AlnUnit * obj) +{ + if( obj == NULL) { + warn("In accessor function label for object AlnUnit, got a NULL object"); + return 0; + } + return obj->label; +} + + +/* Function: replace_text_label_AlnUnit(obj,text_label) + * + * Descrip: Replace member variable text_label + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * Arg: text_label [OWNER] New value of the variable [char *] + * + * Return [SOFT ] member variable text_label [boolean] + * + */ +boolean replace_text_label_AlnUnit(AlnUnit * obj,char * text_label) +{ + if( obj == NULL) { + warn("In replacement function text_label for object AlnUnit, got a NULL object"); + return FALSE; + } + obj->text_label = text_label; + return TRUE; +} + + +/* Function: access_text_label_AlnUnit(obj) + * + * Descrip: Access member variable text_label + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * + * Return [SOFT ] member variable text_label [char *] + * + */ +char * access_text_label_AlnUnit(AlnUnit * obj) +{ + if( obj == NULL) { + warn("In accessor function text_label for object AlnUnit, got a NULL object"); + return NULL; + } + return obj->text_label; +} + + +/* Function: replace_next_AlnUnit(obj,next) + * + * Descrip: Replace member variable next + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * Arg: next [OWNER] New value of the variable [AlnUnit *] + * + * Return [SOFT ] member variable next [boolean] + * + */ +boolean replace_next_AlnUnit(AlnUnit * obj,AlnUnit * next) +{ + if( obj == NULL) { + warn("In replacement function next for object AlnUnit, got a NULL object"); + return FALSE; + } + obj->next = next; + return TRUE; +} + + +/* Function: access_next_AlnUnit(obj) + * + * Descrip: Access member variable next + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * + * Return [SOFT ] member variable next [AlnUnit *] + * + */ +AlnUnit * access_next_AlnUnit(AlnUnit * obj) +{ + if( obj == NULL) { + warn("In accessor function next for object AlnUnit, got a NULL object"); + return NULL; + } + return obj->next; +} + + +/* Function: replace_in_column_AlnUnit(obj,in_column) + * + * Descrip: Replace member variable in_column + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * Arg: in_column [OWNER] New value of the variable [boolean] + * + * Return [SOFT ] member variable in_column [boolean] + * + */ +boolean replace_in_column_AlnUnit(AlnUnit * obj,boolean in_column) +{ + if( obj == NULL) { + warn("In replacement function in_column for object AlnUnit, got a NULL object"); + return FALSE; + } + obj->in_column = in_column; + return TRUE; +} + + +/* Function: access_in_column_AlnUnit(obj) + * + * Descrip: Access member variable in_column + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * + * Return [SOFT ] member variable in_column [boolean] + * + */ +boolean access_in_column_AlnUnit(AlnUnit * obj) +{ + if( obj == NULL) { + warn("In accessor function in_column for object AlnUnit, got a NULL object"); + return FALSE; + } + return obj->in_column; +} + + +/* Function: replace_seq_AlnUnit(obj,seq) + * + * Descrip: Replace member variable seq + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * Arg: seq [OWNER] New value of the variable [AlnSequence *] + * + * Return [SOFT ] member variable seq [boolean] + * + */ +boolean replace_seq_AlnUnit(AlnUnit * obj,AlnSequence * seq) +{ + if( obj == NULL) { + warn("In replacement function seq for object AlnUnit, got a NULL object"); + return FALSE; + } + obj->seq = seq; + return TRUE; +} + + +/* Function: access_seq_AlnUnit(obj) + * + * Descrip: Access member variable seq + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnUnit *] + * + * Return [SOFT ] member variable seq [AlnSequence *] + * + */ +AlnSequence * access_seq_AlnUnit(AlnUnit * obj) +{ + if( obj == NULL) { + warn("In accessor function seq for object AlnUnit, got a NULL object"); + return NULL; + } + return obj->seq; +} + + +/* Function: replace_start_AlnSequence(obj,start) + * + * Descrip: Replace member variable start + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnSequence *] + * Arg: start [OWNER] New value of the variable [AlnUnit *] + * + * Return [SOFT ] member variable start [boolean] + * + */ +boolean replace_start_AlnSequence(AlnSequence * obj,AlnUnit * start) +{ + if( obj == NULL) { + warn("In replacement function start for object AlnSequence, got a NULL object"); + return FALSE; + } + obj->start = start; + return TRUE; +} + + +/* Function: access_start_AlnSequence(obj) + * + * Descrip: Access member variable start + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnSequence *] + * + * Return [SOFT ] member variable start [AlnUnit *] + * + */ +AlnUnit * access_start_AlnSequence(AlnSequence * obj) +{ + if( obj == NULL) { + warn("In accessor function start for object AlnSequence, got a NULL object"); + return NULL; + } + return obj->start; +} + + +/* Function: replace_data_type_AlnSequence(obj,data_type) + * + * Descrip: Replace member variable data_type + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnSequence *] + * Arg: data_type [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable data_type [boolean] + * + */ +boolean replace_data_type_AlnSequence(AlnSequence * obj,int data_type) +{ + if( obj == NULL) { + warn("In replacement function data_type for object AlnSequence, got a NULL object"); + return FALSE; + } + obj->data_type = data_type; + return TRUE; +} + + +/* Function: access_data_type_AlnSequence(obj) + * + * Descrip: Access member variable data_type + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnSequence *] + * + * Return [SOFT ] member variable data_type [int] + * + */ +int access_data_type_AlnSequence(AlnSequence * obj) +{ + if( obj == NULL) { + warn("In accessor function data_type for object AlnSequence, got a NULL object"); + return 0; + } + return obj->data_type; +} + + +/* Function: replace_data_AlnSequence(obj,data) + * + * Descrip: Replace member variable data + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnSequence *] + * Arg: data [OWNER] New value of the variable [void *] + * + * Return [SOFT ] member variable data [boolean] + * + */ +boolean replace_data_AlnSequence(AlnSequence * obj,void * data) +{ + if( obj == NULL) { + warn("In replacement function data for object AlnSequence, got a NULL object"); + return FALSE; + } + obj->data = data; + return TRUE; +} + + +/* Function: access_data_AlnSequence(obj) + * + * Descrip: Access member variable data + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnSequence *] + * + * Return [SOFT ] member variable data [void *] + * + */ +void * access_data_AlnSequence(AlnSequence * obj) +{ + if( obj == NULL) { + warn("In accessor function data for object AlnSequence, got a NULL object"); + return NULL; + } + return obj->data; +} + + +/* Function: replace_bio_start_AlnSequence(obj,bio_start) + * + * Descrip: Replace member variable bio_start + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnSequence *] + * Arg: bio_start [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable bio_start [boolean] + * + */ +boolean replace_bio_start_AlnSequence(AlnSequence * obj,int bio_start) +{ + if( obj == NULL) { + warn("In replacement function bio_start for object AlnSequence, got a NULL object"); + return FALSE; + } + obj->bio_start = bio_start; + return TRUE; +} + + +/* Function: access_bio_start_AlnSequence(obj) + * + * Descrip: Access member variable bio_start + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnSequence *] + * + * Return [SOFT ] member variable bio_start [int] + * + */ +int access_bio_start_AlnSequence(AlnSequence * obj) +{ + if( obj == NULL) { + warn("In accessor function bio_start for object AlnSequence, got a NULL object"); + return 0; + } + return obj->bio_start; +} + + +/* Function: replace_bio_end_AlnSequence(obj,bio_end) + * + * Descrip: Replace member variable bio_end + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnSequence *] + * Arg: bio_end [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable bio_end [boolean] + * + */ +boolean replace_bio_end_AlnSequence(AlnSequence * obj,int bio_end) +{ + if( obj == NULL) { + warn("In replacement function bio_end for object AlnSequence, got a NULL object"); + return FALSE; + } + obj->bio_end = bio_end; + return TRUE; +} + + +/* Function: access_bio_end_AlnSequence(obj) + * + * Descrip: Access member variable bio_end + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnSequence *] + * + * Return [SOFT ] member variable bio_end [int] + * + */ +int access_bio_end_AlnSequence(AlnSequence * obj) +{ + if( obj == NULL) { + warn("In accessor function bio_end for object AlnSequence, got a NULL object"); + return 0; + } + return obj->bio_end; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/aln.h b/Bio/Ext/Align/libs/aln.h new file mode 100644 index 0000000..f324c90 --- /dev/null +++ b/Bio/Ext/Align/libs/aln.h @@ -0,0 +1,977 @@ +#ifndef DYNAMITEalnHEADERFILE +#define DYNAMITEalnHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" +#include "probability.h" + + +#define AlnColumnLISTLENGTH 32 +#define AlnBlockLISTLENGTH 32 +#define AlnBlockListLISTLENGTH 32 + +#define AlnUnitSCORENUMBER 8 + +#ifndef DYNAMITE_DEFINED_AlnColumn +typedef struct bp_sw_AlnColumn bp_sw_AlnColumn; +#define AlnColumn bp_sw_AlnColumn +#define DYNAMITE_DEFINED_AlnColumn +#endif + +#ifndef DYNAMITE_DEFINED_AlnUnit +typedef struct bp_sw_AlnUnit bp_sw_AlnUnit; +#define AlnUnit bp_sw_AlnUnit +#define DYNAMITE_DEFINED_AlnUnit +#endif + +#ifndef DYNAMITE_DEFINED_AlnSequence +typedef struct bp_sw_AlnSequence bp_sw_AlnSequence; +#define AlnSequence bp_sw_AlnSequence +#define DYNAMITE_DEFINED_AlnSequence +#endif + +/* Object AlnUnit + * + * Descrip: This is the basic unit of the label alignment. + * It describes a single mark-up over one sequence: + * being a start, an end and a text_label. + * + * + */ +struct bp_sw_AlnUnit { + int dynamite_hard_link; + int start; /* start position in the sequence */ + int end; /* end position in the sequence */ + int label; /* not used */ + char * text_label; /* text label of this position */ + AlnUnit * next; /* next AlnUnit in this sequence */ + int score[AlnUnitSCORENUMBER]; /* a series of scores for this position. */ + boolean in_column; /* not used */ + AlnSequence * seq; + } ; +/* AlnUnit defined */ +#ifndef DYNAMITE_DEFINED_AlnUnit +typedef struct bp_sw_AlnUnit bp_sw_AlnUnit; +#define AlnUnit bp_sw_AlnUnit +#define DYNAMITE_DEFINED_AlnUnit +#endif + + +/* Object AlnColumn + * + * Descrip: This is a coupling of AlnUnits from different sequences. + * Each AlnUnit is meant to represent *the equivalent* piece + * of biological information in some sense (ie, they are + * alignmed), even though quite possibly they are very + * different types of information + * + * + */ +struct bp_sw_AlnColumn { + int dynamite_hard_link; + AlnUnit ** alu; /* list of the AlnUnits in this column */ + int len;/* len for above alu */ + int maxlen; /* maxlen for above alu */ + AlnColumn * next; /* the next AlnColumn in this block */ + } ; +/* AlnColumn defined */ +#ifndef DYNAMITE_DEFINED_AlnColumn +typedef struct bp_sw_AlnColumn bp_sw_AlnColumn; +#define AlnColumn bp_sw_AlnColumn +#define DYNAMITE_DEFINED_AlnColumn +#endif + + +/* Object AlnSequence + * + * Descrip: Each Sequence in an AlnBlock is represented by one of these, and + * in many ways this is an orthogonal way of looking at the alignment + * than the AlnColumns. If you look at the alignment from one + * AlnSequence you will just see the individual labels on this + * sequence + * + * + */ +struct bp_sw_AlnSequence { + int dynamite_hard_link; + AlnUnit * start; /* the first AlnUnit of this sequence */ + int data_type; /* not used */ + void * data; /* not used - don't use! */ + int bio_start; /* start of this sequence in its 'bio' coordinates */ + int bio_end; /* end of this sequence in its 'bio' coordinates */ + } ; +/* AlnSequence defined */ +#ifndef DYNAMITE_DEFINED_AlnSequence +typedef struct bp_sw_AlnSequence bp_sw_AlnSequence; +#define AlnSequence bp_sw_AlnSequence +#define DYNAMITE_DEFINED_AlnSequence +#endif + + +/* Object AlnBlock + * + * Descrip: AlnBlock is the main representation of alignments from Dynamite. Each + * AlnBlock represents any number of 'sequences', of any type, which share + * things in common. The alignment is represented by a series of /AlnColumns + * (linked list) in which each AlnColumn has a series of AlnUnits, each + * Unit being a start/end/text_label triple. Alternatively, one can see + * each sequence in isolation, and not ask what it is aligned to, but rather + * what labels it has on it. + * + * + */ +struct bp_sw_AlnBlock { + int dynamite_hard_link; + AlnColumn * start; /* the first AlnColumn in the alignment */ + AlnSequence ** seq; /* a list of AlnSequences in the alignment */ + int len;/* len for above seq */ + int maxlen; /* maxlen for above seq */ + int length; /* not used */ + int score; /* not used */ + } ; +/* AlnBlock defined */ +#ifndef DYNAMITE_DEFINED_AlnBlock +typedef struct bp_sw_AlnBlock bp_sw_AlnBlock; +#define AlnBlock bp_sw_AlnBlock +#define DYNAMITE_DEFINED_AlnBlock +#endif + + +/* Object AlnBlockList + * + * Descrip: No Description + * + */ +struct bp_sw_AlnBlockList { + int dynamite_hard_link; + AlnBlock ** alb; + int len;/* len for above alb */ + int maxlen; /* maxlen for above alb */ + } ; +/* AlnBlockList defined */ +#ifndef DYNAMITE_DEFINED_AlnBlockList +typedef struct bp_sw_AlnBlockList bp_sw_AlnBlockList; +#define AlnBlockList bp_sw_AlnBlockList +#define DYNAMITE_DEFINED_AlnBlockList +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: at_end_AlnColumn(alc) + * + * Descrip: This tells you whether the AlnColumn is at the + * end without passing NULL's around + * + * + * + * Arg: alc [READ ] AlnColumn [AlnColumn *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_at_end_AlnColumn(AlnColumn * alc); +#define at_end_AlnColumn bp_sw_at_end_AlnColumn + + +/* Function: bio_start_AlnUnit(alu) + * + * Descrip: Tells the bio-coordinate of the + * start point of this alnunit + * + * + * Arg: alu [UNKN ] Undocumented argument [AlnUnit *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_bio_start_AlnUnit(AlnUnit * alu); +#define bio_start_AlnUnit bp_sw_bio_start_AlnUnit + + +/* Function: bio_end_AlnUnit(alu) + * + * Descrip: Tells the bio-coordinate of the + * end point of this alnunit + * + * + * Arg: alu [UNKN ] Undocumented argument [AlnUnit *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_bio_end_AlnUnit(AlnUnit * alu); +#define bio_end_AlnUnit bp_sw_bio_end_AlnUnit + + +/* Function: swallow_AlnColumn_multiple(master,eaten,comp_func) + * + * Descrip: This function will 'swallow' any number of AlnColumns as long + * as the comparison function of the labels match (the basic + * comp function would be something like strcmp(a,b) == 0 ? TRUE : FALSE) + * The columns are 'swallowed' into master and come from eaten. (these + * columns could be in the same linked list, though it only makes sense + * if the master is before the eaten). + * + * It returns the first column that it could not swallow. + * + * you use this to collapse regions of the label alignment. + * + * + * Arg: master [UNKN ] column which will eat other columns [AlnColumn *] + * Arg: eaten [UNKN ] column which will be consumed [AlnColumn *] + * Arg: comp_func [FUNCP] comparison function for label set [boolean (*comp_func] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * bp_sw_swallow_AlnColumn_multiple(AlnColumn * master,AlnColumn * eaten,boolean (*comp_func)(char *,char *)); +#define swallow_AlnColumn_multiple bp_sw_swallow_AlnColumn_multiple + + +/* Function: swallow_AlnColumn_number(master,eaten,num,comp_func) + * + * Descrip: Basicaly the same as /swallow_AlnColumn_mulitple but there is a maximum number + * of columns it will swallow + * + * + * Arg: master [UNKN ] column which will eat other columns [AlnColumn *] + * Arg: eaten [UNKN ] column which will be consumed [AlnColumn *] + * Arg: num [UNKN ] max number of columns to eat [int] + * Arg: comp_func [FUNCP] comparison function for label set [boolean (*comp_func] + * + * Return [UNKN ] number of columns eaten [int] + * + */ +int bp_sw_swallow_AlnColumn_number(AlnColumn * master,AlnColumn * eaten,int num,boolean (*comp_func)(char *,char *)); +#define swallow_AlnColumn_number bp_sw_swallow_AlnColumn_number + + +/* Function: swallow_AlnColumn(master,eaten,comp_func) + * + * Descrip: This is the function that actually does the 'swallowing'. It will + * try to swallow eaten into master. If comp_func does not give us an + * ok (actually using /can_swallow_AlnColumn it returns FALSE. Otherwise + * it moves on the end of AlnColumn in master to eaten and adds the + * score of eaten to master. + * + * + * Arg: master [UNKN ] column which will eat [AlnColumn *] + * Arg: eaten [UNKN ] column which will dissappear into master if eatable [AlnColumn *] + * Arg: comp_func [FUNCP] comparison function for labels [boolean (*comp_func] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_swallow_AlnColumn(AlnColumn * master,AlnColumn * eaten,boolean (*comp_func)(char *,char *)); +#define swallow_AlnColumn bp_sw_swallow_AlnColumn + + +/* Function: replace_and_free_AlnColumn_with_one(start,end,insert) + * + * Descrip: Linked list manipulation function + * + * Puts insert between start and end, and free's from start->next + * onwards. *Beware* if start is linked to end before calling this + * function thsi wil free end and everything chained to it. Think + * before you call this! + * + * + * Arg: start [UNKN ] Undocumented argument [AlnColumn *] + * Arg: end [UNKN ] Undocumented argument [AlnColumn *] + * Arg: insert [UNKN ] Undocumented argument [AlnColumn *] + * + */ +void bp_sw_replace_and_free_AlnColumn_with_one(AlnColumn * start,AlnColumn * end,AlnColumn * insert); +#define replace_and_free_AlnColumn_with_one bp_sw_replace_and_free_AlnColumn_with_one + + +/* Function: replace_AlnColumn_with_one(start,end,insert) + * + * Descrip: Linked list manipulation function + * + * places insert between start and end. If start/end are not + * continuous then it will loop out the start/end region + * + * + * Arg: start [UNKN ] Undocumented argument [AlnColumn *] + * Arg: end [UNKN ] Undocumented argument [AlnColumn *] + * Arg: insert [UNKN ] Undocumented argument [AlnColumn *] + * + */ +void bp_sw_replace_AlnColumn_with_one(AlnColumn * start,AlnColumn * end,AlnColumn * insert); +#define replace_AlnColumn_with_one bp_sw_replace_AlnColumn_with_one + + +/* Function: insert_AlnColumn(start,insert) + * + * Descrip: Linked list manipulation function + * + * places insert just after start: links insert + * up to what start was linked to + * + * + * Arg: start [UNKN ] Undocumented argument [AlnColumn *] + * Arg: insert [UNKN ] Undocumented argument [AlnColumn *] + * + */ +void bp_sw_insert_AlnColumn(AlnColumn * start,AlnColumn * insert); +#define insert_AlnColumn bp_sw_insert_AlnColumn + + +/* Function: go_back_n_AlnColumn(alb,start,n) + * + * Descrip: Linked list movement function + * + * A nasty function to reverse up a singly linked list by going to + * the start and coming back until you are in the current position. yuk. + * + * + * Arg: alb [UNKN ] Undocumented argument [AlnBlock *] + * Arg: start [UNKN ] Undocumented argument [AlnColumn *] + * Arg: n [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * bp_sw_go_back_n_AlnColumn(AlnBlock * alb,AlnColumn * start,int n); +#define go_back_n_AlnColumn bp_sw_go_back_n_AlnColumn + + +/* Function: dump_ascii_AlnBlock(alb,ofp) + * + * Descrip: Dumps the alignment in rereadable ascii form. + * + * Not really for human consumption + * + * + * Arg: alb [UNKN ] AlnBlock to dump [AlnBlock *] + * Arg: ofp [UNKN ] File stream to dump to [FILE *] + * + */ +void bp_sw_dump_ascii_AlnBlock(AlnBlock * alb,FILE * ofp); +#define dump_ascii_AlnBlock bp_sw_dump_ascii_AlnBlock + + +/* Function: bit_ascii_AlnBlock(alb,ofp) + * + * Descrip: Should not be here... + * + * + * Arg: alb [UNKN ] AlnBlock to dump [AlnBlock *] + * Arg: ofp [UNKN ] File stream to dump to [FILE *] + * + */ +void bp_sw_bit_ascii_AlnBlock(AlnBlock * alb,FILE * ofp); +#define bit_ascii_AlnBlock bp_sw_bit_ascii_AlnBlock + + +/* Function: read_ascii_dump_AlnBlock(ifp) + * + * Descrip: Reads an ascii dumped alignment + * + * + * Arg: ifp [UNKN ] File stream to read from [FILE *] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * bp_sw_read_ascii_dump_AlnBlock(FILE * ifp); +#define read_ascii_dump_AlnBlock bp_sw_read_ascii_dump_AlnBlock + + +/* Function: show_flat_AlnBlock(alb,ofp) + * + * Descrip: Shows the AlnBlock in vaguely human + * readable form + * + * + * Arg: alb [UNKN ] AlnBlock to show [AlnBlock *] + * Arg: ofp [UNKN ] output [FILE *] + * + */ +void bp_sw_show_flat_AlnBlock(AlnBlock * alb,FILE * ofp); +#define show_flat_AlnBlock bp_sw_show_flat_AlnBlock + + +/* Function: get_second_end_AlnColumn(alb) + * + * Descrip: Not sure if this is used! + * + * + * Arg: alb [UNKN ] Undocumented argument [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * bp_sw_get_second_end_AlnColumn(AlnBlock * alb); +#define get_second_end_AlnColumn bp_sw_get_second_end_AlnColumn + + +/* Function: get_end_AlnColumn(alb) + * + * Descrip: To get to the last AlnColumn. If this was + * a doubly linked list, life would be much easier + * + * + * Arg: alb [UNKN ] Undocumented argument [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * bp_sw_get_end_AlnColumn(AlnBlock * alb); +#define get_end_AlnColumn bp_sw_get_end_AlnColumn + + +/* Function: link_AlnUnits_AlnBlock(alb) + * + * Descrip: Links up all AlnUnits to their parent + * sequences + * + * + * Arg: alb [UNKN ] Undocumented argument [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_link_AlnUnits_AlnBlock(AlnBlock * alb); +#define link_AlnUnits_AlnBlock bp_sw_link_AlnUnits_AlnBlock + + +/* Function: new_pairwise_AlnColumn(void) + * + * Descrip: Function as a constructor for the special + * case of a pairwise alignment. Makes an + * AlnColumn and puts in two AlnUnits all ready + * to be linked in. + * + * + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * bp_sw_new_pairwise_AlnColumn(void); +#define new_pairwise_AlnColumn bp_sw_new_pairwise_AlnColumn + + +/* Function: free_AlnColumn(obj) + * + * Descrip: Specilased deconstructor needed because + * of linked list nature of the data structure + * + * + * Arg: obj [UNKN ] Undocumented argument [AlnColumn *] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * bp_sw_free_AlnColumn(AlnColumn * obj); +#define free_AlnColumn bp_sw_free_AlnColumn + + +/* Function: free_AlnUnit(obj) + * + * Descrip: Specilased deconstructor needed because + * of linked list nature of the data structure + * + * + * Arg: obj [UNKN ] Undocumented argument [AlnUnit *] + * + * Return [UNKN ] Undocumented return value [AlnUnit *] + * + */ +AlnUnit * bp_sw_free_AlnUnit(AlnUnit * obj); +#define free_AlnUnit bp_sw_free_AlnUnit + + +/* Function: hard_link_AlnUnit(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnUnit *] + * + * Return [UNKN ] Undocumented return value [AlnUnit *] + * + */ +AlnUnit * bp_sw_hard_link_AlnUnit(AlnUnit * obj); +#define hard_link_AlnUnit bp_sw_hard_link_AlnUnit + + +/* Function: AlnUnit_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnUnit *] + * + */ +AlnUnit * bp_sw_AlnUnit_alloc(void); +#define AlnUnit_alloc bp_sw_AlnUnit_alloc + + +/* Function: add_AlnColumn(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnColumn *] + * Arg: add [OWNER] Object to add to the list [AlnUnit *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_AlnColumn(AlnColumn * obj,AlnUnit * add); +#define add_AlnColumn bp_sw_add_AlnColumn + + +/* Function: flush_AlnColumn(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnColumn *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_flush_AlnColumn(AlnColumn * obj); +#define flush_AlnColumn bp_sw_flush_AlnColumn + + +/* Function: AlnColumn_alloc_std(void) + * + * Descrip: Equivalent to AlnColumn_alloc_len(AlnColumnLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * bp_sw_AlnColumn_alloc_std(void); +#define AlnColumn_alloc_std bp_sw_AlnColumn_alloc_std + + +/* Function: AlnColumn_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * bp_sw_AlnColumn_alloc_len(int len); +#define AlnColumn_alloc_len bp_sw_AlnColumn_alloc_len + + +/* Function: hard_link_AlnColumn(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnColumn *] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * bp_sw_hard_link_AlnColumn(AlnColumn * obj); +#define hard_link_AlnColumn bp_sw_hard_link_AlnColumn + + +/* Function: AlnColumn_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +AlnColumn * bp_sw_AlnColumn_alloc(void); +#define AlnColumn_alloc bp_sw_AlnColumn_alloc + + +/* Function: hard_link_AlnSequence(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnSequence *] + * + * Return [UNKN ] Undocumented return value [AlnSequence *] + * + */ +AlnSequence * bp_sw_hard_link_AlnSequence(AlnSequence * obj); +#define hard_link_AlnSequence bp_sw_hard_link_AlnSequence + + +/* Function: AlnSequence_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnSequence *] + * + */ +AlnSequence * bp_sw_AlnSequence_alloc(void); +#define AlnSequence_alloc bp_sw_AlnSequence_alloc + + +/* Function: free_AlnSequence(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnSequence *] + * + * Return [UNKN ] Undocumented return value [AlnSequence *] + * + */ +AlnSequence * bp_sw_free_AlnSequence(AlnSequence * obj); +#define free_AlnSequence bp_sw_free_AlnSequence + + +/* Function: add_AlnBlock(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnBlock *] + * Arg: add [OWNER] Object to add to the list [AlnSequence *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_AlnBlock(AlnBlock * obj,AlnSequence * add); +#define add_AlnBlock bp_sw_add_AlnBlock + + +/* Function: flush_AlnBlock(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_flush_AlnBlock(AlnBlock * obj); +#define flush_AlnBlock bp_sw_flush_AlnBlock + + +/* Function: AlnBlock_alloc_std(void) + * + * Descrip: Equivalent to AlnBlock_alloc_len(AlnBlockLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * bp_sw_AlnBlock_alloc_std(void); +#define AlnBlock_alloc_std bp_sw_AlnBlock_alloc_std + + +/* Function: AlnBlock_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * bp_sw_AlnBlock_alloc_len(int len); +#define AlnBlock_alloc_len bp_sw_AlnBlock_alloc_len + + +/* Function: hard_link_AlnBlock(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * bp_sw_hard_link_AlnBlock(AlnBlock * obj); +#define hard_link_AlnBlock bp_sw_hard_link_AlnBlock + + +/* Function: AlnBlock_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * bp_sw_AlnBlock_alloc(void); +#define AlnBlock_alloc bp_sw_AlnBlock_alloc + + +/* Function: free_AlnBlock(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * bp_sw_free_AlnBlock(AlnBlock * obj); +#define free_AlnBlock bp_sw_free_AlnBlock + + +/* Function: add_AlnBlockList(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnBlockList *] + * Arg: add [OWNER] Object to add to the list [AlnBlock *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_AlnBlockList(AlnBlockList * obj,AlnBlock * add); +#define add_AlnBlockList bp_sw_add_AlnBlockList + + +/* Function: flush_AlnBlockList(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnBlockList *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_flush_AlnBlockList(AlnBlockList * obj); +#define flush_AlnBlockList bp_sw_flush_AlnBlockList + + +/* Function: AlnBlockList_alloc_std(void) + * + * Descrip: Equivalent to AlnBlockList_alloc_len(AlnBlockListLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [AlnBlockList *] + * + */ +AlnBlockList * bp_sw_AlnBlockList_alloc_std(void); +#define AlnBlockList_alloc_std bp_sw_AlnBlockList_alloc_std + + +/* Function: AlnBlockList_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [AlnBlockList *] + * + */ +AlnBlockList * bp_sw_AlnBlockList_alloc_len(int len); +#define AlnBlockList_alloc_len bp_sw_AlnBlockList_alloc_len + + +/* Function: hard_link_AlnBlockList(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnBlockList *] + * + * Return [UNKN ] Undocumented return value [AlnBlockList *] + * + */ +AlnBlockList * bp_sw_hard_link_AlnBlockList(AlnBlockList * obj); +#define hard_link_AlnBlockList bp_sw_hard_link_AlnBlockList + + +/* Function: AlnBlockList_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnBlockList *] + * + */ +AlnBlockList * bp_sw_AlnBlockList_alloc(void); +#define AlnBlockList_alloc bp_sw_AlnBlockList_alloc + + +/* Function: free_AlnBlockList(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnBlockList *] + * + * Return [UNKN ] Undocumented return value [AlnBlockList *] + * + */ +AlnBlockList * bp_sw_free_AlnBlockList(AlnBlockList * obj); +#define free_AlnBlockList bp_sw_free_AlnBlockList + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +int bp_sw_length_seq_AlnBlock(AlnBlock * obj); +#define length_seq_AlnBlock bp_sw_length_seq_AlnBlock +AlnUnit * bp_sw_access_alu_AlnColumn(AlnColumn * obj,int i); +#define access_alu_AlnColumn bp_sw_access_alu_AlnColumn +int bp_sw_length_alu_AlnColumn(AlnColumn * obj); +#define length_alu_AlnColumn bp_sw_length_alu_AlnColumn +int bp_sw_access_start_AlnUnit(AlnUnit * obj); +#define access_start_AlnUnit bp_sw_access_start_AlnUnit +int bp_sw_access_bio_end_AlnSequence(AlnSequence * obj); +#define access_bio_end_AlnSequence bp_sw_access_bio_end_AlnSequence +boolean bp_sw_replace_end_AlnUnit(AlnUnit * obj,int end); +#define replace_end_AlnUnit bp_sw_replace_end_AlnUnit +boolean bp_sw_replace_label_AlnUnit(AlnUnit * obj,int label); +#define replace_label_AlnUnit bp_sw_replace_label_AlnUnit +int bp_sw_access_label_AlnUnit(AlnUnit * obj); +#define access_label_AlnUnit bp_sw_access_label_AlnUnit +boolean bp_sw_replace_start_AlnBlock(AlnBlock * obj,AlnColumn * start); +#define replace_start_AlnBlock bp_sw_replace_start_AlnBlock +boolean bp_sw_replace_text_label_AlnUnit(AlnUnit * obj,char * text_label); +#define replace_text_label_AlnUnit bp_sw_replace_text_label_AlnUnit +AlnColumn * bp_sw_access_start_AlnBlock(AlnBlock * obj); +#define access_start_AlnBlock bp_sw_access_start_AlnBlock +char * bp_sw_access_text_label_AlnUnit(AlnUnit * obj); +#define access_text_label_AlnUnit bp_sw_access_text_label_AlnUnit +boolean bp_sw_replace_length_AlnBlock(AlnBlock * obj,int length); +#define replace_length_AlnBlock bp_sw_replace_length_AlnBlock +boolean bp_sw_replace_bio_start_AlnSequence(AlnSequence * obj,int bio_start); +#define replace_bio_start_AlnSequence bp_sw_replace_bio_start_AlnSequence +boolean bp_sw_replace_next_AlnUnit(AlnUnit * obj,AlnUnit * next); +#define replace_next_AlnUnit bp_sw_replace_next_AlnUnit +boolean bp_sw_replace_score_AlnBlock(AlnBlock * obj,int score); +#define replace_score_AlnBlock bp_sw_replace_score_AlnBlock +AlnUnit * bp_sw_access_next_AlnUnit(AlnUnit * obj); +#define access_next_AlnUnit bp_sw_access_next_AlnUnit +boolean bp_sw_replace_next_AlnColumn(AlnColumn * obj,AlnColumn * next); +#define replace_next_AlnColumn bp_sw_replace_next_AlnColumn +void * bp_sw_access_data_AlnSequence(AlnSequence * obj); +#define access_data_AlnSequence bp_sw_access_data_AlnSequence +boolean bp_sw_replace_in_column_AlnUnit(AlnUnit * obj,boolean in_column); +#define replace_in_column_AlnUnit bp_sw_replace_in_column_AlnUnit +boolean bp_sw_replace_start_AlnUnit(AlnUnit * obj,int start); +#define replace_start_AlnUnit bp_sw_replace_start_AlnUnit +boolean bp_sw_access_in_column_AlnUnit(AlnUnit * obj); +#define access_in_column_AlnUnit bp_sw_access_in_column_AlnUnit +boolean bp_sw_replace_bio_end_AlnSequence(AlnSequence * obj,int bio_end); +#define replace_bio_end_AlnSequence bp_sw_replace_bio_end_AlnSequence +boolean bp_sw_replace_seq_AlnUnit(AlnUnit * obj,AlnSequence * seq); +#define replace_seq_AlnUnit bp_sw_replace_seq_AlnUnit +AlnSequence * bp_sw_access_seq_AlnBlock(AlnBlock * obj,int i); +#define access_seq_AlnBlock bp_sw_access_seq_AlnBlock +AlnSequence * bp_sw_access_seq_AlnUnit(AlnUnit * obj); +#define access_seq_AlnUnit bp_sw_access_seq_AlnUnit +int bp_sw_access_score_AlnBlock(AlnBlock * obj); +#define access_score_AlnBlock bp_sw_access_score_AlnBlock +boolean bp_sw_replace_start_AlnSequence(AlnSequence * obj,AlnUnit * start); +#define replace_start_AlnSequence bp_sw_replace_start_AlnSequence +int bp_sw_access_end_AlnUnit(AlnUnit * obj); +#define access_end_AlnUnit bp_sw_access_end_AlnUnit +AlnUnit * bp_sw_access_start_AlnSequence(AlnSequence * obj); +#define access_start_AlnSequence bp_sw_access_start_AlnSequence +int bp_sw_access_length_AlnBlock(AlnBlock * obj); +#define access_length_AlnBlock bp_sw_access_length_AlnBlock +boolean bp_sw_replace_data_type_AlnSequence(AlnSequence * obj,int data_type); +#define replace_data_type_AlnSequence bp_sw_replace_data_type_AlnSequence +int bp_sw_access_bio_start_AlnSequence(AlnSequence * obj); +#define access_bio_start_AlnSequence bp_sw_access_bio_start_AlnSequence +int bp_sw_access_data_type_AlnSequence(AlnSequence * obj); +#define access_data_type_AlnSequence bp_sw_access_data_type_AlnSequence +AlnColumn * bp_sw_access_next_AlnColumn(AlnColumn * obj); +#define access_next_AlnColumn bp_sw_access_next_AlnColumn +boolean bp_sw_replace_data_AlnSequence(AlnSequence * obj,void * data); +#define replace_data_AlnSequence bp_sw_replace_data_AlnSequence +boolean bp_sw_can_swallow_AlnColumn(AlnColumn * master,AlnColumn * eaten,boolean (*comp_func)(char *,char *)); +#define can_swallow_AlnColumn bp_sw_can_swallow_AlnColumn +boolean bp_sw_identical_labels_in_AlnColumn(AlnColumn * one,AlnColumn * two,boolean (*comp_func)(char *,char *)); +#define identical_labels_in_AlnColumn bp_sw_identical_labels_in_AlnColumn +boolean bp_sw_identical_labels_in_AlnUnits(AlnUnit * one,AlnUnit * two,boolean (*comp_func)(char *,char *)); +#define identical_labels_in_AlnUnits bp_sw_identical_labels_in_AlnUnits +AlnColumn * bp_sw_read_dumped_ascii_AlnColumn_line(char * line); +#define read_dumped_ascii_AlnColumn_line bp_sw_read_dumped_ascii_AlnColumn_line +void bp_sw_show_flat_AlnColumn(AlnColumn * alc,FILE * ofp); +#define show_flat_AlnColumn bp_sw_show_flat_AlnColumn +void bp_sw_show_flat_AlnUnit(AlnUnit * alu,FILE * ofp); +#define show_flat_AlnUnit bp_sw_show_flat_AlnUnit +AlnUnit * bp_sw_read_flat_AlnUnit_line(char * line,int * ret_pos); +#define read_flat_AlnUnit_line bp_sw_read_flat_AlnUnit_line +void bp_sw_swap_AlnColumn(AlnUnit ** list,int i,int j) ; +#define swap_AlnColumn bp_sw_swap_AlnColumn +void bp_sw_qsort_AlnColumn(AlnUnit ** list,int left,int right,int (*comp)(AlnUnit * ,AlnUnit * )); +#define qsort_AlnColumn bp_sw_qsort_AlnColumn +void bp_sw_sort_AlnColumn(AlnColumn * obj,int (*comp)(AlnUnit *, AlnUnit *)); +#define sort_AlnColumn bp_sw_sort_AlnColumn +boolean bp_sw_expand_AlnColumn(AlnColumn * obj,int len); +#define expand_AlnColumn bp_sw_expand_AlnColumn +void bp_sw_swap_AlnBlock(AlnSequence ** list,int i,int j) ; +#define swap_AlnBlock bp_sw_swap_AlnBlock +void bp_sw_qsort_AlnBlock(AlnSequence ** list,int left,int right,int (*comp)(AlnSequence * ,AlnSequence * )); +#define qsort_AlnBlock bp_sw_qsort_AlnBlock +void bp_sw_sort_AlnBlock(AlnBlock * obj,int (*comp)(AlnSequence *, AlnSequence *)); +#define sort_AlnBlock bp_sw_sort_AlnBlock +boolean bp_sw_expand_AlnBlock(AlnBlock * obj,int len); +#define expand_AlnBlock bp_sw_expand_AlnBlock +void bp_sw_swap_AlnBlockList(AlnBlock ** list,int i,int j) ; +#define swap_AlnBlockList bp_sw_swap_AlnBlockList +void bp_sw_qsort_AlnBlockList(AlnBlock ** list,int left,int right,int (*comp)(AlnBlock * ,AlnBlock * )); +#define qsort_AlnBlockList bp_sw_qsort_AlnBlockList +void bp_sw_sort_AlnBlockList(AlnBlockList * obj,int (*comp)(AlnBlock *, AlnBlock *)); +#define sort_AlnBlockList bp_sw_sort_AlnBlockList +boolean bp_sw_expand_AlnBlockList(AlnBlockList * obj,int len); +#define expand_AlnBlockList bp_sw_expand_AlnBlockList + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/alnconvert.c b/Bio/Ext/Align/libs/alnconvert.c new file mode 100644 index 0000000..5ef85e8 --- /dev/null +++ b/Bio/Ext/Align/libs/alnconvert.c @@ -0,0 +1,586 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "alnconvert.h" + + static char * unknown_label = "UNKNOWN_LABEL"; + + +/* Function: add_collapse_label_AlnConvertSet(acs,label1,label2) + * + * Descrip: Not a sensible function. Makes the convert with label1 and label2 + * a collapsable label + * + * + * Arg: acs [UNKN ] Undocumented argument [AlnConvertSet *] + * Arg: label1 [UNKN ] Undocumented argument [char *] + * Arg: label2 [UNKN ] Undocumented argument [char *] + * + */ +# line 36 "alnconvert.dy" +void add_collapse_label_AlnConvertSet(AlnConvertSet * acs,char * label1,char * label2) +{ + int i; + + for(i=0;ilen;i++) + if( strcmp(acs->acu[i]->label1,label1) == 0 && strcmp(acs->acu[i]->label2,label2) == 0 ) + acs->acu[i]->can_collapse = TRUE; + +} + +/* Function: AlnBlock_from_PackAln(acs,*pal) + * + * Descrip: Takes a AlnConvertSet (acs) and a PackAln (pal) + * and blindly converts it to AlnBlock. This is really + * an internal for a dynamite produced dy function + * + * + * Arg: acs [UNKN ] Undocumented argument [AlnConvertSet *] + * Arg: *pal [UNKN ] Undocumented argument [PackAln] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +# line 51 "alnconvert.dy" +AlnBlock * AlnBlock_from_PackAln(AlnConvertSet * acs,PackAln *pal) +{ + AlnBlock * alb; + AlnColumn * prev; + AlnColumn * new; + boolean coll; + int i; + + alb = AlnBlock_alloc_len(2); + + add_AlnBlock(alb,AlnSequence_alloc()); + add_AlnBlock(alb,AlnSequence_alloc()); + + prev = NULL; + alb->score = pal->score; + for(i=1;ilen;i++) { + coll = FALSE; + new=AlnColumn_from_Pal_Convert(acs,pal->pau[i-1],pal->pau[i],prev,&coll); + if( new == NULL ) { + if( coll == FALSE ) { + warn("Unrecoverable error in converting PackAln to AlnBlock... bugging out with partial alignment!"); + return alb; + } + else { + /** ok, was collapsed, just loop back **/ + continue; + } + } + else { + /** got a new AlnColumn **/ + if( prev == NULL ) { + /** then first col **/ + + alb->start = new; + alb->seq[0]->start = new->alu[0]; + alb->seq[1]->start = new->alu[1]; + prev = new; + + } + else { + prev->next = new; + prev->alu[0]->next = new->alu[0]; + prev->alu[1]->next = new->alu[1]; + prev = new; + } + } + + } + + return alb; +} + + +/* Function: AlnColumn_from_Pal_Convert(acs,before,after,prev,was_collapsed) + * + * Descrip: the core of the conversion. + * + * + * Arg: acs [UNKN ] Undocumented argument [AlnConvertSet *] + * Arg: before [UNKN ] Undocumented argument [PackAlnUnit *] + * Arg: after [UNKN ] Undocumented argument [PackAlnUnit *] + * Arg: prev [UNKN ] Undocumented argument [AlnColumn *] + * Arg: was_collapsed [UNKN ] Undocumented argument [boolean *] + * + * Return [UNKN ] Undocumented return value [AlnColumn *] + * + */ +# line 108 "alnconvert.dy" +AlnColumn * AlnColumn_from_Pal_Convert(AlnConvertSet * acs,PackAlnUnit * before,PackAlnUnit * after,AlnColumn * prev,boolean * was_collapsed) +{ + AlnConvertUnit * acu; + AlnColumn * alc; + + + acu = AlnConvertUnit_from_state_and_offset(acs,before->state,after->state,after->i - before->i,after->j - before->j); + + if( acu == NULL) { + warn("Between state [%d,%d,%d] and [%d,%d,%d] got no labels... labelling as UNKNOWN",before->i,before->j,before->state,after->i,after->j,after->state); + alc = new_pairwise_AlnColumn(); + + alc->alu[0]->start = before->i; + alc->alu[0]->end = after->i; + + alc->alu[1]->start = before->j; + alc->alu[1]->end = after->j; + alc->alu[0]->score[0] = alc->alu[1]->score[0] = after->score; + + alc->alu[1]->text_label = alc->alu[0]->text_label = unknown_label; + + return alc; + } + + if( acu->can_collapse == TRUE && prev != NULL && strcmp(prev->alu[0]->text_label,acu->label1) == 0 && strcmp(prev->alu[1]->text_label,acu->label2) == 0 ) { + /*** don't return something, just add into the next one ***/ + prev->alu[0]->end = after->i; + prev->alu[1]->end = after->j; + prev->alu[0]->score[0] += after->score; + prev->alu[1]->score[0] += after->score; + if( was_collapsed != NULL ) { + *was_collapsed = TRUE; + } + return NULL; + } + + /*** else, put away this unit ***/ + + alc = new_pairwise_AlnColumn(); + + if( acu->is_from_special == TRUE ) { + alc->alu[0]->start = after->i -1; + alc->alu[0]->end = after->i; + } else { + alc->alu[0]->start = before->i; + alc->alu[0]->end = after->i; + } + + alc->alu[1]->start = before->j; + alc->alu[1]->end = after->j; + alc->alu[0]->score[0] = alc->alu[1]->score[0] = after->score; + + alc->alu[0]->text_label = acu->label1; + alc->alu[1]->text_label = acu->label2; + + return alc; +} + + +/* Function: AlnConvertUnit_from_state_and_offset(acs,state1,state2,offi,offj) + * + * Descrip: Finds the correct AlnConvertUnit for this state,state,offi,offj + * quad + * + * + * Arg: acs [UNKN ] Undocumented argument [AlnConvertSet *] + * Arg: state1 [UNKN ] Undocumented argument [int] + * Arg: state2 [UNKN ] Undocumented argument [int] + * Arg: offi [UNKN ] Undocumented argument [int] + * Arg: offj [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [AlnConvertUnit *] + * + */ +# line 172 "alnconvert.dy" +AlnConvertUnit * AlnConvertUnit_from_state_and_offset(AlnConvertSet * acs,int state1,int state2,int offi,int offj) +{ + register int i; + + for(i=0;ilen;i++) { + if( acs->acu[i]->state1 == state1 && acs->acu[i]->state2 == state2 && (acs->acu[i]->offi == -1 || acs->acu[i]->offi == offi) && offj == acs->acu[i]->offj) + return acs->acu[i]; + } + return NULL; +} + + +# line 191 "alnconvert.c" +/* Function: hard_link_AlnConvertUnit(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnConvertUnit *] + * + * Return [UNKN ] Undocumented return value [AlnConvertUnit *] + * + */ +AlnConvertUnit * hard_link_AlnConvertUnit(AlnConvertUnit * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a AlnConvertUnit object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: AlnConvertUnit_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnConvertUnit *] + * + */ +AlnConvertUnit * AlnConvertUnit_alloc(void) +{ + AlnConvertUnit * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(AlnConvertUnit *) ckalloc (sizeof(AlnConvertUnit))) == NULL) { + warn("AlnConvertUnit_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->state1 = 0; + out->state2 = 0; + out->offi = 0; + out->offj = 0; + out->can_collapse = FALSE; + out->is_from_special = FALSE; + + + return out; +} + + +/* Function: free_AlnConvertUnit(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnConvertUnit *] + * + * Return [UNKN ] Undocumented return value [AlnConvertUnit *] + * + */ +AlnConvertUnit * free_AlnConvertUnit(AlnConvertUnit * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a AlnConvertUnit obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + /* obj->label1 is linked in */ + /* obj->label2 is linked in */ + + + ckfree(obj); + return NULL; +} + + +/* Function: swap_AlnConvertSet(list,i,j) + * + * Descrip: swap function: an internal for qsort_AlnConvertSet + * swaps two positions in the array + * + * + * Arg: list [UNKN ] List of structures to swap in [AlnConvertUnit **] + * Arg: i [UNKN ] swap position [int] + * Arg: j [UNKN ] swap position [int] + * + */ +/* swap function for qsort function */ +void swap_AlnConvertSet(AlnConvertUnit ** list,int i,int j) +{ + AlnConvertUnit * temp; + temp=list[i]; + list[i]=list[j]; + list[j]=temp; +} + + +/* Function: qsort_AlnConvertSet(list,left,right,comp) + * + * Descrip: qsort - lifted from K&R + * sorts the array using quicksort + * Probably much better to call sort_AlnConvertSet which sorts from start to end + * + * + * Arg: list [UNKN ] List of structures to swap in [AlnConvertUnit **] + * Arg: left [UNKN ] left position [int] + * Arg: right [UNKN ] right position [int] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void qsort_AlnConvertSet(AlnConvertUnit ** list,int left,int right,int (*comp)(AlnConvertUnit * ,AlnConvertUnit * )) +{ + int i,last; + if( left >= right ) + return; + + + swap_AlnConvertSet(list,left,(left+right)/2); + last = left; + for ( i=left+1; i <= right;i++) { + if( (*comp)(list[i],list[left]) < 0) + swap_AlnConvertSet (list,++last,i); + } + swap_AlnConvertSet (list,left,last); + qsort_AlnConvertSet(list,left,last-1,comp); + qsort_AlnConvertSet(list,last+1,right,comp); +} + + +/* Function: sort_AlnConvertSet(obj,comp) + * + * Descrip: sorts from start to end using comp + * sorts the array using quicksort by calling qsort_AlnConvertSet + * + * + * Arg: obj [UNKN ] Object containing list [AlnConvertSet *] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void sort_AlnConvertSet(AlnConvertSet * obj,int (*comp)(AlnConvertUnit *, AlnConvertUnit *)) +{ + qsort_AlnConvertSet(obj->acu,0,obj->len-1,comp); + return; +} + + +/* Function: expand_AlnConvertSet(obj,len) + * + * Descrip: Really an internal function for add_AlnConvertSet + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnConvertSet *] + * Arg: len [UNKN ] Length to add one [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean expand_AlnConvertSet(AlnConvertSet * obj,int len) +{ + + + if( obj->maxlen > obj->len ) { + warn("expand_AlnConvertSet called with no need"); + return TRUE; + } + + + if( (obj->acu = (AlnConvertUnit ** ) ckrealloc (obj->acu,sizeof(AlnConvertUnit *)*len)) == NULL) { + warn("ckrealloc failed for expand_AlnConvertSet, returning FALSE"); + return FALSE; + } + obj->maxlen = len; + return TRUE; +} + + +/* Function: add_AlnConvertSet(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnConvertSet *] + * Arg: add [OWNER] Object to add to the list [AlnConvertUnit *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +/* will expand function if necessary */ +boolean add_AlnConvertSet(AlnConvertSet * obj,AlnConvertUnit * add) +{ + if( obj->len >= obj->maxlen) { + if( expand_AlnConvertSet(obj,obj->len + AlnConvertSetLISTLENGTH) == FALSE) + return FALSE; + } + + + obj->acu[obj->len++]=add; + return TRUE; +} + + +/* Function: flush_AlnConvertSet(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnConvertSet *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int flush_AlnConvertSet(AlnConvertSet * obj) +{ + int i; + + + for(i=0;ilen;i++) { + if( obj->acu[i] != NULL) { + free_AlnConvertUnit(obj->acu[i]); + obj->acu[i] = NULL; + } + } /* end of for i over list length */ + + + obj->len = 0; + return i; +} + + +/* Function: AlnConvertSet_alloc_std(void) + * + * Descrip: Equivalent to AlnConvertSet_alloc_len(AlnConvertSetLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [AlnConvertSet *] + * + */ +AlnConvertSet * AlnConvertSet_alloc_std(void) +{ + return AlnConvertSet_alloc_len(AlnConvertSetLISTLENGTH); +} + + +/* Function: AlnConvertSet_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [AlnConvertSet *] + * + */ +AlnConvertSet * AlnConvertSet_alloc_len(int len) +{ + AlnConvertSet * out;/* out is exported at the end of function */ + + + /* Call alloc function: return NULL if NULL */ + /* Warning message alread in alloc function */ + if((out = AlnConvertSet_alloc()) == NULL) + return NULL; + + + /* Calling ckcalloc for list elements */ + if((out->acu = (AlnConvertUnit ** ) ckcalloc (len,sizeof(AlnConvertUnit *))) == NULL) { + warn("Warning, ckcalloc failed in AlnConvertSet_alloc_len"); + return NULL; + } + out->len = 0; + out->maxlen = len; + + + return out; +} + + +/* Function: hard_link_AlnConvertSet(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnConvertSet *] + * + * Return [UNKN ] Undocumented return value [AlnConvertSet *] + * + */ +AlnConvertSet * hard_link_AlnConvertSet(AlnConvertSet * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a AlnConvertSet object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: AlnConvertSet_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnConvertSet *] + * + */ +AlnConvertSet * AlnConvertSet_alloc(void) +{ + AlnConvertSet * out;/* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(AlnConvertSet *) ckalloc (sizeof(AlnConvertSet))) == NULL) { + warn("AlnConvertSet_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->acu = NULL; + out->len = out->maxlen = 0; + + + return out; +} + + +/* Function: free_AlnConvertSet(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnConvertSet *] + * + * Return [UNKN ] Undocumented return value [AlnConvertSet *] + * + */ +AlnConvertSet * free_AlnConvertSet(AlnConvertSet * obj) +{ + int i; + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a AlnConvertSet obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->acu != NULL) { + for(i=0;ilen;i++) { + if( obj->acu[i] != NULL) + free_AlnConvertUnit(obj->acu[i]); + } + ckfree(obj->acu); + } + + + ckfree(obj); + return NULL; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/alnconvert.h b/Bio/Ext/Align/libs/alnconvert.h new file mode 100644 index 0000000..5e1cb50 --- /dev/null +++ b/Bio/Ext/Align/libs/alnconvert.h @@ -0,0 +1,253 @@ +#ifndef DYNAMITEalnconvertHEADERFILE +#define DYNAMITEalnconvertHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "dyna.h" + +#define AlnConvertSetLISTLENGTH 64 + +struct bp_sw_AlnConvertUnit { + int dynamite_hard_link; + int state1; + int state2; + int offi; + int offj; + char * label1; + char * label2; + boolean can_collapse; + boolean is_from_special; + } ; +/* AlnConvertUnit defined */ +#ifndef DYNAMITE_DEFINED_AlnConvertUnit +typedef struct bp_sw_AlnConvertUnit bp_sw_AlnConvertUnit; +#define AlnConvertUnit bp_sw_AlnConvertUnit +#define DYNAMITE_DEFINED_AlnConvertUnit +#endif + + +struct bp_sw_AlnConvertSet { + int dynamite_hard_link; + AlnConvertUnit ** acu; + int len;/* len for above acu */ + int maxlen; /* maxlen for above acu */ + } ; +/* AlnConvertSet defined */ +#ifndef DYNAMITE_DEFINED_AlnConvertSet +typedef struct bp_sw_AlnConvertSet bp_sw_AlnConvertSet; +#define AlnConvertSet bp_sw_AlnConvertSet +#define DYNAMITE_DEFINED_AlnConvertSet +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: add_collapse_label_AlnConvertSet(acs,label1,label2) + * + * Descrip: Not a sensible function. Makes the convert with label1 and label2 + * a collapsable label + * + * + * Arg: acs [UNKN ] Undocumented argument [AlnConvertSet *] + * Arg: label1 [UNKN ] Undocumented argument [char *] + * Arg: label2 [UNKN ] Undocumented argument [char *] + * + */ +void bp_sw_add_collapse_label_AlnConvertSet(AlnConvertSet * acs,char * label1,char * label2); +#define add_collapse_label_AlnConvertSet bp_sw_add_collapse_label_AlnConvertSet + + +/* Function: AlnBlock_from_PackAln(acs,*pal) + * + * Descrip: Takes a AlnConvertSet (acs) and a PackAln (pal) + * and blindly converts it to AlnBlock. This is really + * an internal for a dynamite produced dy function + * + * + * Arg: acs [UNKN ] Undocumented argument [AlnConvertSet *] + * Arg: *pal [UNKN ] Undocumented argument [PackAln] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * bp_sw_AlnBlock_from_PackAln(AlnConvertSet * acs,PackAln *pal); +#define AlnBlock_from_PackAln bp_sw_AlnBlock_from_PackAln + + +/* Function: hard_link_AlnConvertUnit(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnConvertUnit *] + * + * Return [UNKN ] Undocumented return value [AlnConvertUnit *] + * + */ +AlnConvertUnit * bp_sw_hard_link_AlnConvertUnit(AlnConvertUnit * obj); +#define hard_link_AlnConvertUnit bp_sw_hard_link_AlnConvertUnit + + +/* Function: AlnConvertUnit_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnConvertUnit *] + * + */ +AlnConvertUnit * bp_sw_AlnConvertUnit_alloc(void); +#define AlnConvertUnit_alloc bp_sw_AlnConvertUnit_alloc + + +/* Function: free_AlnConvertUnit(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnConvertUnit *] + * + * Return [UNKN ] Undocumented return value [AlnConvertUnit *] + * + */ +AlnConvertUnit * bp_sw_free_AlnConvertUnit(AlnConvertUnit * obj); +#define free_AlnConvertUnit bp_sw_free_AlnConvertUnit + + +/* Function: add_AlnConvertSet(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnConvertSet *] + * Arg: add [OWNER] Object to add to the list [AlnConvertUnit *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_AlnConvertSet(AlnConvertSet * obj,AlnConvertUnit * add); +#define add_AlnConvertSet bp_sw_add_AlnConvertSet + + +/* Function: flush_AlnConvertSet(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnConvertSet *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_flush_AlnConvertSet(AlnConvertSet * obj); +#define flush_AlnConvertSet bp_sw_flush_AlnConvertSet + + +/* Function: AlnConvertSet_alloc_std(void) + * + * Descrip: Equivalent to AlnConvertSet_alloc_len(AlnConvertSetLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [AlnConvertSet *] + * + */ +AlnConvertSet * bp_sw_AlnConvertSet_alloc_std(void); +#define AlnConvertSet_alloc_std bp_sw_AlnConvertSet_alloc_std + + +/* Function: AlnConvertSet_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [AlnConvertSet *] + * + */ +AlnConvertSet * bp_sw_AlnConvertSet_alloc_len(int len); +#define AlnConvertSet_alloc_len bp_sw_AlnConvertSet_alloc_len + + +/* Function: hard_link_AlnConvertSet(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnConvertSet *] + * + * Return [UNKN ] Undocumented return value [AlnConvertSet *] + * + */ +AlnConvertSet * bp_sw_hard_link_AlnConvertSet(AlnConvertSet * obj); +#define hard_link_AlnConvertSet bp_sw_hard_link_AlnConvertSet + + +/* Function: AlnConvertSet_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnConvertSet *] + * + */ +AlnConvertSet * bp_sw_AlnConvertSet_alloc(void); +#define AlnConvertSet_alloc bp_sw_AlnConvertSet_alloc + + +/* Function: free_AlnConvertSet(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnConvertSet *] + * + * Return [UNKN ] Undocumented return value [AlnConvertSet *] + * + */ +AlnConvertSet * bp_sw_free_AlnConvertSet(AlnConvertSet * obj); +#define free_AlnConvertSet bp_sw_free_AlnConvertSet + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +AlnColumn * bp_sw_AlnColumn_from_Pal_Convert(AlnConvertSet * acs,PackAlnUnit * before,PackAlnUnit * after,AlnColumn * prev,boolean * was_collapsed); +#define AlnColumn_from_Pal_Convert bp_sw_AlnColumn_from_Pal_Convert +AlnConvertUnit * bp_sw_AlnConvertUnit_from_state_and_offset(AlnConvertSet * acs,int state1,int state2,int offi,int offj); +#define AlnConvertUnit_from_state_and_offset bp_sw_AlnConvertUnit_from_state_and_offset +void bp_sw_swap_AlnConvertSet(AlnConvertUnit ** list,int i,int j) ; +#define swap_AlnConvertSet bp_sw_swap_AlnConvertSet +void bp_sw_qsort_AlnConvertSet(AlnConvertUnit ** list,int left,int right,int (*comp)(AlnConvertUnit * ,AlnConvertUnit * )); +#define qsort_AlnConvertSet bp_sw_qsort_AlnConvertSet +void bp_sw_sort_AlnConvertSet(AlnConvertSet * obj,int (*comp)(AlnConvertUnit *, AlnConvertUnit *)); +#define sort_AlnConvertSet bp_sw_sort_AlnConvertSet +boolean bp_sw_expand_AlnConvertSet(AlnConvertSet * obj,int len); +#define expand_AlnConvertSet bp_sw_expand_AlnConvertSet + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/alnrange.c b/Bio/Ext/Align/libs/alnrange.c new file mode 100644 index 0000000..e2e5d7c --- /dev/null +++ b/Bio/Ext/Align/libs/alnrange.c @@ -0,0 +1,908 @@ +#ifdef _cplusplus +extern "C" { +#endif + +#include "alnrange.h" + + +/* Function: show_AlnRangeSet(ars,ofp) + * + * Descrip: shows AlnRangeSet in vaguely human form + * + * + * Arg: ars [UNKN ] Undocumented argument [AlnRangeSet *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 42 "alnrange.dy" +void show_AlnRangeSet(AlnRangeSet * ars,FILE * ofp) +{ + int i; + + for(i=0;ilen;i++) { + show_AlnRange(ars->alr[i],ofp); + } + +} + +/* Function: show_AlnRange(alr,ofp) + * + * Descrip: shows AlnRange in vaguely human form + * + * + * Arg: alr [UNKN ] Undocumented argument [AlnRange *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 55 "alnrange.dy" +void show_AlnRange(AlnRange * alr,FILE * ofp) +{ + fprintf(ofp,"(%d,%d,%d)-(%d,%d,%d) [%d,%d]\n",alr->starti,alr->startj,alr->startstate, +alr->stopi,alr->stopj,alr->stopstate,alr->startscore,alr->stopscore); +} + +/* Function: sort_AlnRangeSet_by_start(ars) + * + * Descrip: Sorts an AlnRangeSet by start of each AlnRange + * + * + * Arg: ars [UNKN ] Undocumented argument [AlnRangeSet *] + * + */ +# line 64 "alnrange.dy" +void sort_AlnRangeSet_by_start(AlnRangeSet * ars) +{ + sort_AlnRangeSet(ars,compare_AlnRange_start); +} + +/* Function: compare_AlnRange_start(one,two) + * + * Descrip: compares to AlnRange for /sort_AlnRangeSet_by_start + * + * + * Arg: one [UNKN ] Undocumented argument [AlnRange *] + * Arg: two [UNKN ] Undocumented argument [AlnRange *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 73 "alnrange.dy" +int compare_AlnRange_start(AlnRange * one,AlnRange * two) +{ + if( one->startj > two->startj) + return 1; + else return -1; +} + + +# line 69 "alnrange.c" +/* Function: hard_link_AlnRange(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnRange *] + * + * Return [UNKN ] Undocumented return value [AlnRange *] + * + */ +AlnRange * hard_link_AlnRange(AlnRange * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a AlnRange object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: AlnRange_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnRange *] + * + */ +AlnRange * AlnRange_alloc(void) +{ + AlnRange * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(AlnRange *) ckalloc (sizeof(AlnRange))) == NULL) { + warn("AlnRange_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->starti = 0; + out->startj = 0; + out->startstate = 0; + out->stopi = 0; + out->stopj = 0; + out->stopstate = 0; + out->startscore = 0; + out->stopscore = 0; + + + return out; +} + + +/* Function: free_AlnRange(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnRange *] + * + * Return [UNKN ] Undocumented return value [AlnRange *] + * + */ +AlnRange * free_AlnRange(AlnRange * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a AlnRange obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + + + ckfree(obj); + return NULL; +} + + +/* Function: swap_AlnRangeSet(list,i,j) + * + * Descrip: swap function: an internal for qsort_AlnRangeSet + * swaps two positions in the array + * + * + * Arg: list [UNKN ] List of structures to swap in [AlnRange **] + * Arg: i [UNKN ] swap position [int] + * Arg: j [UNKN ] swap position [int] + * + */ +/* swap function for qsort function */ +void swap_AlnRangeSet(AlnRange ** list,int i,int j) +{ + AlnRange * temp; + temp=list[i]; + list[i]=list[j]; + list[j]=temp; +} + + +/* Function: qsort_AlnRangeSet(list,left,right,comp) + * + * Descrip: qsort - lifted from K&R + * sorts the array using quicksort + * Probably much better to call sort_AlnRangeSet which sorts from start to end + * + * + * Arg: list [UNKN ] List of structures to swap in [AlnRange **] + * Arg: left [UNKN ] left position [int] + * Arg: right [UNKN ] right position [int] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void qsort_AlnRangeSet(AlnRange ** list,int left,int right,int (*comp)(AlnRange * ,AlnRange * )) +{ + int i,last; + if( left >= right ) + return; + + + swap_AlnRangeSet(list,left,(left+right)/2); + last = left; + for ( i=left+1; i <= right;i++) { + if( (*comp)(list[i],list[left]) < 0) + swap_AlnRangeSet (list,++last,i); + } + swap_AlnRangeSet (list,left,last); + qsort_AlnRangeSet(list,left,last-1,comp); + qsort_AlnRangeSet(list,last+1,right,comp); +} + + +/* Function: sort_AlnRangeSet(obj,comp) + * + * Descrip: sorts from start to end using comp + * sorts the array using quicksort by calling qsort_AlnRangeSet + * + * + * Arg: obj [UNKN ] Object containing list [AlnRangeSet *] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void sort_AlnRangeSet(AlnRangeSet * obj,int (*comp)(AlnRange *, AlnRange *)) +{ + qsort_AlnRangeSet(obj->alr,0,obj->len-1,comp); + return; +} + + +/* Function: expand_AlnRangeSet(obj,len) + * + * Descrip: Really an internal function for add_AlnRangeSet + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnRangeSet *] + * Arg: len [UNKN ] Length to add one [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean expand_AlnRangeSet(AlnRangeSet * obj,int len) +{ + + + if( obj->maxlen > obj->len ) { + warn("expand_AlnRangeSet called with no need"); + return TRUE; + } + + + if( (obj->alr = (AlnRange ** ) ckrealloc (obj->alr,sizeof(AlnRange *)*len)) == NULL) { + warn("ckrealloc failed for expand_AlnRangeSet, returning FALSE"); + return FALSE; + } + obj->maxlen = len; + return TRUE; +} + + +/* Function: add_AlnRangeSet(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnRangeSet *] + * Arg: add [OWNER] Object to add to the list [AlnRange *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +/* will expand function if necessary */ +boolean add_AlnRangeSet(AlnRangeSet * obj,AlnRange * add) +{ + if( obj->len >= obj->maxlen) { + if( expand_AlnRangeSet(obj,obj->len + AlnRangeSetLISTLENGTH) == FALSE) + return FALSE; + } + + + obj->alr[obj->len++]=add; + return TRUE; +} + + +/* Function: flush_AlnRangeSet(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnRangeSet *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int flush_AlnRangeSet(AlnRangeSet * obj) +{ + int i; + + + for(i=0;ilen;i++) { + if( obj->alr[i] != NULL) { + free_AlnRange(obj->alr[i]); + obj->alr[i] = NULL; + } + } /* end of for i over list length */ + + + obj->len = 0; + return i; +} + + +/* Function: AlnRangeSet_alloc_std(void) + * + * Descrip: Equivalent to AlnRangeSet_alloc_len(AlnRangeSetLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * AlnRangeSet_alloc_std(void) +{ + return AlnRangeSet_alloc_len(AlnRangeSetLISTLENGTH); +} + + +/* Function: AlnRangeSet_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * AlnRangeSet_alloc_len(int len) +{ + AlnRangeSet * out; /* out is exported at the end of function */ + + + /* Call alloc function: return NULL if NULL */ + /* Warning message alread in alloc function */ + if((out = AlnRangeSet_alloc()) == NULL) + return NULL; + + + /* Calling ckcalloc for list elements */ + if((out->alr = (AlnRange ** ) ckcalloc (len,sizeof(AlnRange *))) == NULL) { + warn("Warning, ckcalloc failed in AlnRangeSet_alloc_len"); + return NULL; + } + out->len = 0; + out->maxlen = len; + + + return out; +} + + +/* Function: hard_link_AlnRangeSet(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnRangeSet *] + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * hard_link_AlnRangeSet(AlnRangeSet * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a AlnRangeSet object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: AlnRangeSet_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * AlnRangeSet_alloc(void) +{ + AlnRangeSet * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(AlnRangeSet *) ckalloc (sizeof(AlnRangeSet))) == NULL) { + warn("AlnRangeSet_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->score = 0; + out->alr = NULL; + out->len = out->maxlen = 0; + + + return out; +} + + +/* Function: free_AlnRangeSet(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnRangeSet *] + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * free_AlnRangeSet(AlnRangeSet * obj) +{ + int i; + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a AlnRangeSet obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->alr != NULL) { + for(i=0;ilen;i++) { + if( obj->alr[i] != NULL) + free_AlnRange(obj->alr[i]); + } + ckfree(obj->alr); + } + + + ckfree(obj); + return NULL; +} + + +/* Function: replace_score_AlnRangeSet(obj,score) + * + * Descrip: Replace member variable score + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRangeSet *] + * Arg: score [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable score [boolean] + * + */ +boolean replace_score_AlnRangeSet(AlnRangeSet * obj,int score) +{ + if( obj == NULL) { + warn("In replacement function score for object AlnRangeSet, got a NULL object"); + return FALSE; + } + obj->score = score; + return TRUE; +} + + +/* Function: access_score_AlnRangeSet(obj) + * + * Descrip: Access member variable score + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRangeSet *] + * + * Return [SOFT ] member variable score [int] + * + */ +int access_score_AlnRangeSet(AlnRangeSet * obj) +{ + if( obj == NULL) { + warn("In accessor function score for object AlnRangeSet, got a NULL object"); + return 0; + } + return obj->score; +} + + +/* Function: access_alr_AlnRangeSet(obj,i) + * + * Descrip: Access members stored in the alr list + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the list [AlnRangeSet *] + * Arg: i [UNKN ] Position in the list [int] + * + * Return [SOFT ] Element of the list [AlnRange *] + * + */ +AlnRange * access_alr_AlnRangeSet(AlnRangeSet * obj,int i) +{ + if( obj == NULL) { + warn("In accessor function alr for object AlnRangeSet, got a NULL object"); + return NULL; + } + if( obj->len <= i ) { + warn("In accessor function alr for object AlnRangeSet, index %%d is greater than list length %%d",i,obj->len); + return NULL; + } + return obj->alr[i]; +} + + +/* Function: length_alr_AlnRangeSet(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the list [AlnRangeSet *] + * + * Return [UNKN ] length of the list [int] + * + */ +int length_alr_AlnRangeSet(AlnRangeSet * obj) +{ + if( obj == NULL) { + warn("In length function alr for object AlnRangeSet, got a NULL object"); + return -1; + } + return obj->len; +} + + +/* Function: replace_starti_AlnRange(obj,starti) + * + * Descrip: Replace member variable starti + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * Arg: starti [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable starti [boolean] + * + */ +boolean replace_starti_AlnRange(AlnRange * obj,int starti) +{ + if( obj == NULL) { + warn("In replacement function starti for object AlnRange, got a NULL object"); + return FALSE; + } + obj->starti = starti; + return TRUE; +} + + +/* Function: access_starti_AlnRange(obj) + * + * Descrip: Access member variable starti + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * + * Return [SOFT ] member variable starti [int] + * + */ +int access_starti_AlnRange(AlnRange * obj) +{ + if( obj == NULL) { + warn("In accessor function starti for object AlnRange, got a NULL object"); + return 0; + } + return obj->starti; +} + + +/* Function: replace_startj_AlnRange(obj,startj) + * + * Descrip: Replace member variable startj + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * Arg: startj [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable startj [boolean] + * + */ +boolean replace_startj_AlnRange(AlnRange * obj,int startj) +{ + if( obj == NULL) { + warn("In replacement function startj for object AlnRange, got a NULL object"); + return FALSE; + } + obj->startj = startj; + return TRUE; +} + + +/* Function: access_startj_AlnRange(obj) + * + * Descrip: Access member variable startj + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * + * Return [SOFT ] member variable startj [int] + * + */ +int access_startj_AlnRange(AlnRange * obj) +{ + if( obj == NULL) { + warn("In accessor function startj for object AlnRange, got a NULL object"); + return 0; + } + return obj->startj; +} + + +/* Function: replace_startstate_AlnRange(obj,startstate) + * + * Descrip: Replace member variable startstate + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * Arg: startstate [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable startstate [boolean] + * + */ +boolean replace_startstate_AlnRange(AlnRange * obj,int startstate) +{ + if( obj == NULL) { + warn("In replacement function startstate for object AlnRange, got a NULL object"); + return FALSE; + } + obj->startstate = startstate; + return TRUE; +} + + +/* Function: access_startstate_AlnRange(obj) + * + * Descrip: Access member variable startstate + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * + * Return [SOFT ] member variable startstate [int] + * + */ +int access_startstate_AlnRange(AlnRange * obj) +{ + if( obj == NULL) { + warn("In accessor function startstate for object AlnRange, got a NULL object"); + return 0; + } + return obj->startstate; +} + + +/* Function: replace_stopi_AlnRange(obj,stopi) + * + * Descrip: Replace member variable stopi + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * Arg: stopi [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable stopi [boolean] + * + */ +boolean replace_stopi_AlnRange(AlnRange * obj,int stopi) +{ + if( obj == NULL) { + warn("In replacement function stopi for object AlnRange, got a NULL object"); + return FALSE; + } + obj->stopi = stopi; + return TRUE; +} + + +/* Function: access_stopi_AlnRange(obj) + * + * Descrip: Access member variable stopi + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * + * Return [SOFT ] member variable stopi [int] + * + */ +int access_stopi_AlnRange(AlnRange * obj) +{ + if( obj == NULL) { + warn("In accessor function stopi for object AlnRange, got a NULL object"); + return 0; + } + return obj->stopi; +} + + +/* Function: replace_stopj_AlnRange(obj,stopj) + * + * Descrip: Replace member variable stopj + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * Arg: stopj [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable stopj [boolean] + * + */ +boolean replace_stopj_AlnRange(AlnRange * obj,int stopj) +{ + if( obj == NULL) { + warn("In replacement function stopj for object AlnRange, got a NULL object"); + return FALSE; + } + obj->stopj = stopj; + return TRUE; +} + + +/* Function: access_stopj_AlnRange(obj) + * + * Descrip: Access member variable stopj + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * + * Return [SOFT ] member variable stopj [int] + * + */ +int access_stopj_AlnRange(AlnRange * obj) +{ + if( obj == NULL) { + warn("In accessor function stopj for object AlnRange, got a NULL object"); + return 0; + } + return obj->stopj; +} + + +/* Function: replace_stopstate_AlnRange(obj,stopstate) + * + * Descrip: Replace member variable stopstate + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * Arg: stopstate [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable stopstate [boolean] + * + */ +boolean replace_stopstate_AlnRange(AlnRange * obj,int stopstate) +{ + if( obj == NULL) { + warn("In replacement function stopstate for object AlnRange, got a NULL object"); + return FALSE; + } + obj->stopstate = stopstate; + return TRUE; +} + + +/* Function: access_stopstate_AlnRange(obj) + * + * Descrip: Access member variable stopstate + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * + * Return [SOFT ] member variable stopstate [int] + * + */ +int access_stopstate_AlnRange(AlnRange * obj) +{ + if( obj == NULL) { + warn("In accessor function stopstate for object AlnRange, got a NULL object"); + return 0; + } + return obj->stopstate; +} + + +/* Function: replace_startscore_AlnRange(obj,startscore) + * + * Descrip: Replace member variable startscore + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * Arg: startscore [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable startscore [boolean] + * + */ +boolean replace_startscore_AlnRange(AlnRange * obj,int startscore) +{ + if( obj == NULL) { + warn("In replacement function startscore for object AlnRange, got a NULL object"); + return FALSE; + } + obj->startscore = startscore; + return TRUE; +} + + +/* Function: access_startscore_AlnRange(obj) + * + * Descrip: Access member variable startscore + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * + * Return [SOFT ] member variable startscore [int] + * + */ +int access_startscore_AlnRange(AlnRange * obj) +{ + if( obj == NULL) { + warn("In accessor function startscore for object AlnRange, got a NULL object"); + return 0; + } + return obj->startscore; +} + + +/* Function: replace_stopscore_AlnRange(obj,stopscore) + * + * Descrip: Replace member variable stopscore + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * Arg: stopscore [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable stopscore [boolean] + * + */ +boolean replace_stopscore_AlnRange(AlnRange * obj,int stopscore) +{ + if( obj == NULL) { + warn("In replacement function stopscore for object AlnRange, got a NULL object"); + return FALSE; + } + obj->stopscore = stopscore; + return TRUE; +} + + +/* Function: access_stopscore_AlnRange(obj) + * + * Descrip: Access member variable stopscore + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [AlnRange *] + * + * Return [SOFT ] member variable stopscore [int] + * + */ +int access_stopscore_AlnRange(AlnRange * obj) +{ + if( obj == NULL) { + warn("In accessor function stopscore for object AlnRange, got a NULL object"); + return 0; + } + return obj->stopscore; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/alnrange.h b/Bio/Ext/Align/libs/alnrange.h new file mode 100644 index 0000000..fe8d46f --- /dev/null +++ b/Bio/Ext/Align/libs/alnrange.h @@ -0,0 +1,297 @@ +#ifndef DYNAMITEalnrangeHEADERFILE +#define DYNAMITEalnrangeHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "dyna.h" + +#define AlnRangeSetLISTLENGTH 64 +struct bp_sw_AlnRange { + int dynamite_hard_link; + int starti; + int startj; + int startstate; + int stopi; + int stopj; + int stopstate; + int startscore; + int stopscore; + } ; +/* AlnRange defined */ +#ifndef DYNAMITE_DEFINED_AlnRange +typedef struct bp_sw_AlnRange bp_sw_AlnRange; +#define AlnRange bp_sw_AlnRange +#define DYNAMITE_DEFINED_AlnRange +#endif + + +struct bp_sw_AlnRangeSet { + int dynamite_hard_link; + int score; /* over complete alignment */ + AlnRange ** alr; + int len;/* len for above alr */ + int maxlen; /* maxlen for above alr */ + } ; +/* AlnRangeSet defined */ +#ifndef DYNAMITE_DEFINED_AlnRangeSet +typedef struct bp_sw_AlnRangeSet bp_sw_AlnRangeSet; +#define AlnRangeSet bp_sw_AlnRangeSet +#define DYNAMITE_DEFINED_AlnRangeSet +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: show_AlnRangeSet(ars,ofp) + * + * Descrip: shows AlnRangeSet in vaguely human form + * + * + * Arg: ars [UNKN ] Undocumented argument [AlnRangeSet *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_show_AlnRangeSet(AlnRangeSet * ars,FILE * ofp); +#define show_AlnRangeSet bp_sw_show_AlnRangeSet + + +/* Function: show_AlnRange(alr,ofp) + * + * Descrip: shows AlnRange in vaguely human form + * + * + * Arg: alr [UNKN ] Undocumented argument [AlnRange *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_show_AlnRange(AlnRange * alr,FILE * ofp); +#define show_AlnRange bp_sw_show_AlnRange + + +/* Function: sort_AlnRangeSet_by_start(ars) + * + * Descrip: Sorts an AlnRangeSet by start of each AlnRange + * + * + * Arg: ars [UNKN ] Undocumented argument [AlnRangeSet *] + * + */ +void bp_sw_sort_AlnRangeSet_by_start(AlnRangeSet * ars); +#define sort_AlnRangeSet_by_start bp_sw_sort_AlnRangeSet_by_start + + +/* Function: hard_link_AlnRange(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnRange *] + * + * Return [UNKN ] Undocumented return value [AlnRange *] + * + */ +AlnRange * bp_sw_hard_link_AlnRange(AlnRange * obj); +#define hard_link_AlnRange bp_sw_hard_link_AlnRange + + +/* Function: AlnRange_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnRange *] + * + */ +AlnRange * bp_sw_AlnRange_alloc(void); +#define AlnRange_alloc bp_sw_AlnRange_alloc + + +/* Function: free_AlnRange(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnRange *] + * + * Return [UNKN ] Undocumented return value [AlnRange *] + * + */ +AlnRange * bp_sw_free_AlnRange(AlnRange * obj); +#define free_AlnRange bp_sw_free_AlnRange + + +/* Function: add_AlnRangeSet(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnRangeSet *] + * Arg: add [OWNER] Object to add to the list [AlnRange *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_AlnRangeSet(AlnRangeSet * obj,AlnRange * add); +#define add_AlnRangeSet bp_sw_add_AlnRangeSet + + +/* Function: flush_AlnRangeSet(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [AlnRangeSet *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_flush_AlnRangeSet(AlnRangeSet * obj); +#define flush_AlnRangeSet bp_sw_flush_AlnRangeSet + + +/* Function: AlnRangeSet_alloc_std(void) + * + * Descrip: Equivalent to AlnRangeSet_alloc_len(AlnRangeSetLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * bp_sw_AlnRangeSet_alloc_std(void); +#define AlnRangeSet_alloc_std bp_sw_AlnRangeSet_alloc_std + + +/* Function: AlnRangeSet_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * bp_sw_AlnRangeSet_alloc_len(int len); +#define AlnRangeSet_alloc_len bp_sw_AlnRangeSet_alloc_len + + +/* Function: hard_link_AlnRangeSet(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [AlnRangeSet *] + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * bp_sw_hard_link_AlnRangeSet(AlnRangeSet * obj); +#define hard_link_AlnRangeSet bp_sw_hard_link_AlnRangeSet + + +/* Function: AlnRangeSet_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * bp_sw_AlnRangeSet_alloc(void); +#define AlnRangeSet_alloc bp_sw_AlnRangeSet_alloc + + +/* Function: free_AlnRangeSet(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [AlnRangeSet *] + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * bp_sw_free_AlnRangeSet(AlnRangeSet * obj); +#define free_AlnRangeSet bp_sw_free_AlnRangeSet + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +boolean bp_sw_replace_score_AlnRangeSet(AlnRangeSet * obj,int score); +#define replace_score_AlnRangeSet bp_sw_replace_score_AlnRangeSet +int bp_sw_access_startj_AlnRange(AlnRange * obj); +#define access_startj_AlnRange bp_sw_access_startj_AlnRange +boolean bp_sw_replace_startstate_AlnRange(AlnRange * obj,int startstate); +#define replace_startstate_AlnRange bp_sw_replace_startstate_AlnRange +int bp_sw_access_startstate_AlnRange(AlnRange * obj); +#define access_startstate_AlnRange bp_sw_access_startstate_AlnRange +boolean bp_sw_replace_stopscore_AlnRange(AlnRange * obj,int stopscore); +#define replace_stopscore_AlnRange bp_sw_replace_stopscore_AlnRange +boolean bp_sw_replace_stopi_AlnRange(AlnRange * obj,int stopi); +#define replace_stopi_AlnRange bp_sw_replace_stopi_AlnRange +AlnRange * bp_sw_access_alr_AlnRangeSet(AlnRangeSet * obj,int i); +#define access_alr_AlnRangeSet bp_sw_access_alr_AlnRangeSet +int bp_sw_access_stopi_AlnRange(AlnRange * obj); +#define access_stopi_AlnRange bp_sw_access_stopi_AlnRange +boolean bp_sw_replace_starti_AlnRange(AlnRange * obj,int starti); +#define replace_starti_AlnRange bp_sw_replace_starti_AlnRange +boolean bp_sw_replace_stopj_AlnRange(AlnRange * obj,int stopj); +#define replace_stopj_AlnRange bp_sw_replace_stopj_AlnRange +boolean bp_sw_replace_startj_AlnRange(AlnRange * obj,int startj); +#define replace_startj_AlnRange bp_sw_replace_startj_AlnRange +int bp_sw_access_stopj_AlnRange(AlnRange * obj); +#define access_stopj_AlnRange bp_sw_access_stopj_AlnRange +int bp_sw_access_score_AlnRangeSet(AlnRangeSet * obj); +#define access_score_AlnRangeSet bp_sw_access_score_AlnRangeSet +boolean bp_sw_replace_stopstate_AlnRange(AlnRange * obj,int stopstate); +#define replace_stopstate_AlnRange bp_sw_replace_stopstate_AlnRange +int bp_sw_access_starti_AlnRange(AlnRange * obj); +#define access_starti_AlnRange bp_sw_access_starti_AlnRange +int bp_sw_access_stopstate_AlnRange(AlnRange * obj); +#define access_stopstate_AlnRange bp_sw_access_stopstate_AlnRange +int bp_sw_length_alr_AlnRangeSet(AlnRangeSet * obj); +#define length_alr_AlnRangeSet bp_sw_length_alr_AlnRangeSet +boolean bp_sw_replace_startscore_AlnRange(AlnRange * obj,int startscore); +#define replace_startscore_AlnRange bp_sw_replace_startscore_AlnRange +int bp_sw_access_stopscore_AlnRange(AlnRange * obj); +#define access_stopscore_AlnRange bp_sw_access_stopscore_AlnRange +int bp_sw_access_startscore_AlnRange(AlnRange * obj); +#define access_startscore_AlnRange bp_sw_access_startscore_AlnRange +int bp_sw_compare_AlnRange_start(AlnRange * one,AlnRange * two); +#define compare_AlnRange_start bp_sw_compare_AlnRange_start +void bp_sw_swap_AlnRangeSet(AlnRange ** list,int i,int j) ; +#define swap_AlnRangeSet bp_sw_swap_AlnRangeSet +void bp_sw_qsort_AlnRangeSet(AlnRange ** list,int left,int right,int (*comp)(AlnRange * ,AlnRange * )); +#define qsort_AlnRangeSet bp_sw_qsort_AlnRangeSet +void bp_sw_sort_AlnRangeSet(AlnRangeSet * obj,int (*comp)(AlnRange *, AlnRange *)); +#define sort_AlnRangeSet bp_sw_sort_AlnRangeSet +boolean bp_sw_expand_AlnRangeSet(AlnRangeSet * obj,int len); +#define expand_AlnRangeSet bp_sw_expand_AlnRangeSet + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/asciibtcanvas.c b/Bio/Ext/Align/libs/asciibtcanvas.c new file mode 100644 index 0000000..ab532b2 --- /dev/null +++ b/Bio/Ext/Align/libs/asciibtcanvas.c @@ -0,0 +1,464 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "asciibtcanvas.h" + + + +/* Function: new_Ascii_btCanvas(ofp,left,main,right,height) + * + * Descrip: The only function specifically for Ascii bt Canvases. + * + * Use this to make a new btCanvas. Then use functions like + * /get_paste_area_btCanvas to actually use it. Everything + * else is handled by data structures and pointer-to-functions + * which are hidden to you (and be thankful for that!) + * + * The standard /free_btCanvas will free the hidden data structures + * as well + * + * + * Arg: ofp [UNKN ] FILE stream to write the ascii to [FILE *] + * Arg: left [UNKN ] amount of text to reserve on the left [int] + * Arg: main [UNKN ] Undocumented argument [int] + * Arg: right [UNKN ] amount of text to reserve on the right [int] + * Arg: height [UNKN ] height of block [int] + * + * Return [UNKN ] Undocumented return value [btCanvas *] + * + */ +# line 47 "asciibtcanvas.dy" +btCanvas * new_Ascii_btCanvas(FILE * ofp,int left,int main,int right,int height) +{ + btCanvas * out; + Ascii_btc_Data * d; + + out = btCanvas_alloc(); + + d = new_Ascii_btc_Data(ofp,left,main,right,height); + + out->canvas_data = (void *) d; + + out->decons = free_Ascii_btc; + + /* now need to put in correct pointers to functions for + * canvas implementation + */ + out->can_get_paste_area = can_get_bt_Ascii; + out->advance_line = ascii_next_line_btPasteArea; + out->get_paste_area = next_Ascii_btpa; + out->get_reserved_right = get_ascii_right_btPasteArea; + out->get_reserved_left = get_ascii_left_btPasteArea; + + + return out; + +} + + + + +/* Function: next_Ascii_btpa(btc,length) + * + * Descrip: gets the next btPasteArea. Here we con + * people by simply passing out the 'bpa' + * held in canvas and never reallocating it + * (see /free_Ascii_btpa which is already attached to + * the bpa). + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * Arg: length [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +# line 85 "asciibtcanvas.dy" +btPasteArea * next_Ascii_btpa(btCanvas * btc,int length) +{ + Ascii_btc_Data * abd = NULL; + + abd = (Ascii_btc_Data*) btc->canvas_data; + + if( abd->in_use == TRUE ) { + warn("You are already using a btPasteArea on this canvas. Only one at a time! Probably you have not freed the btPasteArea before hand"); + return NULL; + } + + if( abd->current_x + length > abd->main + abd->res_left ) { + warn("Asking for more block than I can give you. You have not tested with can_get_paste_area. Bad boy!"); + return NULL; + } + + abd->in_use = TRUE; + abd->paint_x = abd->current_x; + abd->current_x += length; + abd->bpa->length = length; + return abd->bpa; +} + + +/* Function: paste_char_bt_Ascii(bpa,x,y,c,format) + * + * Descrip: The paste function. Going to get at all the info + * (obviously) through data + * + * + * Arg: bpa [UNKN ] Undocumented argument [btPasteArea *] + * Arg: x [UNKN ] Undocumented argument [int] + * Arg: y [UNKN ] Undocumented argument [int] + * Arg: c [UNKN ] Undocumented argument [char] + * Arg: format [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 114 "asciibtcanvas.dy" +boolean paste_char_bt_Ascii(btPasteArea * bpa,int x,int y,char c,int format) +{ + Ascii_btc_Data * abd = NULL; + + abd = (Ascii_btc_Data*) bpa->canvas_data; + +/* fprintf(stderr,"Printing at %d %d %c\n",x,y,c); */ + abd->scratch[y][abd->paint_x + x] = c; + return TRUE; +} + +/* Function: can_get_bt_Ascii(btc,length) + * + * Descrip: Can get function + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * Arg: length [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 129 "asciibtcanvas.dy" +boolean can_get_bt_Ascii(btCanvas * btc,int length) +{ + Ascii_btc_Data * abd = NULL; + + abd = (Ascii_btc_Data*) btc->canvas_data; + +/* fprintf(stderr,"Current is %d to %d\n",abd->current_x,length); */ + + if( abd->current_x + length >= abd->main + abd->res_left ) + return FALSE; + + +/* fprintf(stderr,"Returning TRUE\n"); */ + + return TRUE; +} + +/* Function: get_ascii_left_btPasteArea(btc) + * + * Descrip: The get left area function. + * Again, con people into thinking that we are + * passing a 'live' bpa + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +# line 152 "asciibtcanvas.dy" +btPasteArea * get_ascii_left_btPasteArea(btCanvas * btc) +{ + Ascii_btc_Data * abd = NULL; + int length; + + abd = (Ascii_btc_Data*) btc->canvas_data; + + length = abd->res_left; + + if( abd->in_use == TRUE ) { + warn("You are already using a btPasteArea on this canvas. Only one at a time! Probably you have not freed the btPasteArea before hand"); + return NULL; + } + + abd->in_use = TRUE; + abd->paint_x = 0; + abd->bpa->length = length; + return abd->bpa; +} + +/* Function: get_ascii_right_btPasteArea(btc) + * + * Descrip: The get right area function. + * Again, con people into thinking that we are + * passing a 'live' bpa + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +# line 178 "asciibtcanvas.dy" +btPasteArea * get_ascii_right_btPasteArea(btCanvas * btc) +{ + Ascii_btc_Data * abd = NULL; + int length; + + abd = (Ascii_btc_Data*) btc->canvas_data; + + length = abd->res_left + abd->main; + + if( abd->in_use == TRUE ) { + warn("You are already using a btPasteArea on this canvas. Only one at a time! Probably you have not freed the btPasteArea before hand"); + return NULL; + } + + abd->in_use = TRUE; + abd->paint_x = 0; + abd->bpa->length = length; + return abd->bpa; +} + +/* Function: ascii_next_line_btPasteArea(btc) + * + * Descrip: Advancement function. + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 202 "asciibtcanvas.dy" +boolean ascii_next_line_btPasteArea(btCanvas * btc) +{ + Ascii_btc_Data * abd = NULL; + int i,len; + +/* fprintf(stderr,"Going to advance\n"); */ + abd = (Ascii_btc_Data*) btc->canvas_data; + + if( abd->in_use == TRUE ) { + warn("You are already using a btPasteArea on this canvas, and now you are asking to advance a line. Ouch"); + return FALSE; + } + len = abd->res_left + abd->main + abd->res_right; + + for(i=0;idepth_scratch;i++) { +/* fprintf(stderr,"About to print %s\n",abd->scratch[i]);*/ + fputs(abd->scratch[i],abd->ofp); + } + fputs("\n\n",abd->ofp); + + for(i=0;idepth_scratch;i++) { + memset(abd->scratch[i],' ',len); + } + + abd->current_x = abd->res_left; + + return TRUE; + +} + + +/* Function: free_Ascii_btpa(obj) + * + * Descrip: Deconstructor for a btPasteArea we are + * going to make. Will be attached on construction + * + * + * Arg: obj [UNKN ] Undocumented argument [btPasteArea *] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +# line 238 "asciibtcanvas.dy" +btPasteArea * free_Ascii_btpa(btPasteArea * obj) +{ + Ascii_btc_Data * abd; + + /* all we have to do is set to FALSE the Ascii_btc_Data pointed to + by canvas_data + */ + + abd = (Ascii_btc_Data*) obj->canvas_data; + + abd->in_use = FALSE; + + return NULL; +} + + + +/* Function: new_Ascii_btc_Data(ofp,left,main,right,height) + * + * Descrip: makes new ascii data. NB. Notice allocation of + * 'dummy' btPasteArea and of the scratch pad. + * + * + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * Arg: left [UNKN ] Undocumented argument [int] + * Arg: main [UNKN ] Undocumented argument [int] + * Arg: right [UNKN ] Undocumented argument [int] + * Arg: height [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [Ascii_btc_Data *] + * + */ +# line 260 "asciibtcanvas.dy" +Ascii_btc_Data * new_Ascii_btc_Data(FILE * ofp,int left,int main,int right,int height) +{ + Ascii_btc_Data * out; + int tot; + int i; + + tot = left + main + right +2; + + out = Ascii_btc_Data_alloc(); + + out->ofp = ofp; + out->res_left = left; + out->main = main; + out->res_right = right; + out->current_x= left; + out->paint_x = left; + + + out->scratch = (char **) ckcalloc(height,sizeof(char *)); + for(i=0;iscratch[i] = (char *) ckcalloc(tot,sizeof(char)); + memset(out->scratch[i],' ',tot-2); + out->scratch[i][tot-1] = '\0'; + out->scratch[i][tot-2] = '\n'; + } + + out->depth_scratch = height; + out->in_use = FALSE; + out->bpa = btPasteArea_alloc(); + out->bpa->height = height; + out->bpa->canvas_data = (void *) out; + out->bpa->decons = free_Ascii_btpa; + out->bpa->paste_char = paste_char_bt_Ascii; + + + + return out; +} + + +/* Function: free_Ascii_btc(btc) + * + * Descrip: Deconstructor for the btcanvas we are going + * to make. This function will be attached to + * the btcanvas on construction + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * + * Return [UNKN ] Undocumented return value [btCanvas *] + * + */ +# line 306 "asciibtcanvas.dy" +btCanvas * free_Ascii_btc(btCanvas * btc) +{ + btc->canvas_data = (void *) free_Ascii_btc_Data((Ascii_btc_Data *)(btc->canvas_data)); + ckfree(btc); + return NULL; +} + + +/* Function: free_Ascii_btc_Data(obj) + * + * Descrip: Specialist deconstructor really for scratch pad + * + * + * Arg: obj [WRITE] Ascii_btc_Data to be zapped [Ascii_btc_Data *] + * + * Return [UNKN ] Undocumented return value [Ascii_btc_Data *] + * + */ +# line 321 "asciibtcanvas.dy" +Ascii_btc_Data * free_Ascii_btc_Data(Ascii_btc_Data * obj) +{ + int i; + + for(i=0;idepth_scratch;i++) { + ckfree(obj->scratch[i]); + } + + ckfree(obj->scratch); + ckfree(obj->bpa); /* very subtle. bpa actually is a complete dummy obj + * calling free_btPasteArea would be **really** bad + */ + ckfree(obj); + + return NULL; +} + + + + +# line 379 "asciibtcanvas.c" +/* Function: hard_link_Ascii_btc_Data(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [Ascii_btc_Data *] + * + * Return [UNKN ] Undocumented return value [Ascii_btc_Data *] + * + */ +Ascii_btc_Data * hard_link_Ascii_btc_Data(Ascii_btc_Data * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a Ascii_btc_Data object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: Ascii_btc_Data_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [Ascii_btc_Data *] + * + */ +Ascii_btc_Data * Ascii_btc_Data_alloc(void) +{ + Ascii_btc_Data * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(Ascii_btc_Data *) ckalloc (sizeof(Ascii_btc_Data))) == NULL) { + warn("Ascii_btc_Data_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->ofp = NULL; + out->current_x = 0; + out->paint_x = 0; + out->res_left = 0; + out->main = 0; + out->res_right = 0; + out->scratch = NULL; + out->depth_scratch = 0; + out->in_use = FALSE; + out->bpa = NULL; + + + return out; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/asciibtcanvas.h b/Bio/Ext/Align/libs/asciibtcanvas.h new file mode 100644 index 0000000..29ec175 --- /dev/null +++ b/Bio/Ext/Align/libs/asciibtcanvas.h @@ -0,0 +1,126 @@ +#ifndef DYNAMITEasciibtcanvasHEADERFILE +#define DYNAMITEasciibtcanvasHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "btcanvas.h" + + +struct bp_sw_Ascii_btc_Data { + int dynamite_hard_link; + FILE * ofp; /* file to write to */ + int current_x; /* position in main line */ + int paint_x; /* painting cursor on the line */ + int res_left; /* amount reserved on left */ + int main; /* main block amount */ + int res_right; /* amount reserved on right */ + char ** scratch; /* scratch pad lines */ + int depth_scratch; /* depth of scratch pad for memory */ + boolean in_use; + btPasteArea * bpa; /* this is what we recycle.. */ + } ; +/* Ascii_btc_Data defined */ +#ifndef DYNAMITE_DEFINED_Ascii_btc_Data +typedef struct bp_sw_Ascii_btc_Data bp_sw_Ascii_btc_Data; +#define Ascii_btc_Data bp_sw_Ascii_btc_Data +#define DYNAMITE_DEFINED_Ascii_btc_Data +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: new_Ascii_btCanvas(ofp,left,main,right,height) + * + * Descrip: The only function specifically for Ascii bt Canvases. + * + * Use this to make a new btCanvas. Then use functions like + * /get_paste_area_btCanvas to actually use it. Everything + * else is handled by data structures and pointer-to-functions + * which are hidden to you (and be thankful for that!) + * + * The standard /free_btCanvas will free the hidden data structures + * as well + * + * + * Arg: ofp [UNKN ] FILE stream to write the ascii to [FILE *] + * Arg: left [UNKN ] amount of text to reserve on the left [int] + * Arg: main [UNKN ] Undocumented argument [int] + * Arg: right [UNKN ] amount of text to reserve on the right [int] + * Arg: height [UNKN ] height of block [int] + * + * Return [UNKN ] Undocumented return value [btCanvas *] + * + */ +btCanvas * bp_sw_new_Ascii_btCanvas(FILE * ofp,int left,int main,int right,int height); +#define new_Ascii_btCanvas bp_sw_new_Ascii_btCanvas + + +/* Function: hard_link_Ascii_btc_Data(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [Ascii_btc_Data *] + * + * Return [UNKN ] Undocumented return value [Ascii_btc_Data *] + * + */ +Ascii_btc_Data * bp_sw_hard_link_Ascii_btc_Data(Ascii_btc_Data * obj); +#define hard_link_Ascii_btc_Data bp_sw_hard_link_Ascii_btc_Data + + +/* Function: Ascii_btc_Data_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [Ascii_btc_Data *] + * + */ +Ascii_btc_Data * bp_sw_Ascii_btc_Data_alloc(void); +#define Ascii_btc_Data_alloc bp_sw_Ascii_btc_Data_alloc + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +btPasteArea * bp_sw_next_Ascii_btpa(btCanvas * btc,int length); +#define next_Ascii_btpa bp_sw_next_Ascii_btpa +boolean bp_sw_paste_char_bt_Ascii(btPasteArea * bpa,int x,int y,char c,int format); +#define paste_char_bt_Ascii bp_sw_paste_char_bt_Ascii +boolean bp_sw_can_get_bt_Ascii(btCanvas * btc,int length); +#define can_get_bt_Ascii bp_sw_can_get_bt_Ascii +btPasteArea * bp_sw_get_ascii_left_btPasteArea(btCanvas * btc); +#define get_ascii_left_btPasteArea bp_sw_get_ascii_left_btPasteArea +btPasteArea * bp_sw_get_ascii_right_btPasteArea(btCanvas * btc); +#define get_ascii_right_btPasteArea bp_sw_get_ascii_right_btPasteArea +boolean bp_sw_ascii_next_line_btPasteArea(btCanvas * btc); +#define ascii_next_line_btPasteArea bp_sw_ascii_next_line_btPasteArea +btPasteArea * bp_sw_free_Ascii_btpa(btPasteArea * obj); +#define free_Ascii_btpa bp_sw_free_Ascii_btpa +Ascii_btc_Data * bp_sw_new_Ascii_btc_Data(FILE * ofp,int left,int main,int right,int height); +#define new_Ascii_btc_Data bp_sw_new_Ascii_btc_Data +btCanvas * bp_sw_free_Ascii_btc(btCanvas * btc); +#define free_Ascii_btc bp_sw_free_Ascii_btc +Ascii_btc_Data * bp_sw_free_Ascii_btc_Data(Ascii_btc_Data * obj); +#define free_Ascii_btc_Data bp_sw_free_Ascii_btc_Data + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/basematrix.c b/Bio/Ext/Align/libs/basematrix.c new file mode 100644 index 0000000..24be1ee --- /dev/null +++ b/Bio/Ext/Align/libs/basematrix.c @@ -0,0 +1,370 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "basematrix.h" + + +static int max_matrix_bytes = COMPILE_BASEMATRIX_MAX_KB; + +/* Function: change_max_BaseMatrix_kbytes(new_kilo_number) + * + * Descrip: This is to change, at run-time the maximum level of bytes basematrix *thinks* + * it can use. This number is *not* used for any actual calls to basematrix + * allocation: it is only used with /get_max_BaseMatrix_kbytes + * + * + * Arg: new_kilo_number [UNKN ] max kilobytes allowed [int] + * + */ +# line 116 "basematrix.dy" +void change_max_BaseMatrix_kbytes(int new_kilo_number) +{ + max_matrix_bytes = new_kilo_number; +} + +/* Function: get_max_BaseMatrix_kbytes(void) + * + * Descrip: returns the max. number of kilobytes suggested as a limited + * to BaseMatrix. + * + * + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 125 "basematrix.dy" +int get_max_BaseMatrix_kbytes(void) +{ + return max_matrix_bytes; +} + +/* Function: can_make_explicit_matrix(leni,lenj,statesize) + * + * Descrip: Just checkes that leni*lenj*statesize/1024 < max_matrix_bytes. + * returns TRUE if so, FALSE if not + * + * + * Arg: leni [UNKN ] Undocumented argument [int] + * Arg: lenj [UNKN ] Undocumented argument [int] + * Arg: statesize [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 134 "basematrix.dy" +boolean can_make_explicit_matrix(int leni,int lenj,int statesize) +{ + if( leni*lenj*statesize/1024 > max_matrix_bytes) + return FALSE; + return TRUE; +} + + +/* Function: basematrix_type_to_string(type) + * + * Descrip: turns a int type to a char string of 'printable' + * types. + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 146 "basematrix.dy" +char * basematrix_type_to_string(int type) +{ + switch (type) { + case BASEMATRIX_TYPE_UNKNOWN : return "Unknown"; + case BASEMATRIX_TYPE_EXPLICIT : return "Explicit"; + case BASEMATRIX_TYPE_LINEAR : return "Linear"; + case BASEMATRIX_TYPE_SHADOW : return "Shadow"; + default : return "Problem in converting type!"; + } + +} + +/* Function: BaseMatrix_alloc_matrix_and_specials(len_spec_poin,len_point,len_array,len_spec_point,len_spec_array) + * + * Descrip: This function allocates the two bits of + * matrix memory, of course returning a decent + * NULL (with memory zapped) if it can't do it + * + * + * Arg: len_spec_poin [UNKN ] length of pointers in special matrix [NullString] + * Arg: len_point [UNKN ] length of pointers in main matrix [int] + * Arg: len_array [UNKN ] length of array in main matrix [int] + * Arg: len_spec_point [UNKN ] Undocumented argument [int] + * Arg: len_spec_array [UNKN ] length of special array [int] + * + * Return [UNKN ] Undocumented return value [BaseMatrix *] + * + */ +# line 168 "basematrix.dy" +BaseMatrix * BaseMatrix_alloc_matrix_and_specials(int len_point,int len_array,int len_spec_point,int len_spec_array) +{ + register int i; + BaseMatrix * out; + + /* use dy matrix for main stuff */ + + if( (out = BaseMatrix_alloc_matrix(len_point,len_array)) == NULL ) { + warn("Unable to allocate %d by %d [%d] int positions in basematrix main matrix",len_point,len_array,len_point*len_array); + return NULL; + } + + out->spec_len = 0; + + if( (out->specmatrix = (int **) ckcalloc(len_spec_point,sizeof(int *))) == NULL ) { + warn("Unable to allocate %d special matrix pointers in basematrix",len_spec_point); + free_BaseMatrix(out); + return NULL; + } + + for(i=0;ispecmatrix[i] = (int *) ckcalloc(len_spec_array,sizeof(int))) == NULL ) { + warn("Unable to allocate the %d'th special array in basematrix for [length: %d]",i,len_spec_array); + + /*** sneaky. Put spec_len = i so that deconstructor will clear-up memory ***/ + + out->spec_len = i; + free_BaseMatrix(out); + return NULL; + } + } + + out->spec_len = len_spec_point; + + + return out; +} + +/* Function: free_BaseMatrix(obj) + * + * Descrip: this is the override deconstructor for basematrix. It will + * free both matrix and special memory + * + * + * Arg: obj [UNKN ] Undocumented argument [BaseMatrix *] + * + * Return [UNKN ] Undocumented return value [BaseMatrix *] + * + */ +# line 211 "basematrix.dy" +BaseMatrix * free_BaseMatrix(BaseMatrix * obj) +{ + int i; + + if( obj == NULL ) { + warn("Trying to free NULL basematrix object. Should be trappable"); + return NULL; + } + + if( obj->dynamite_hard_link > 1 ) { + obj->dynamite_hard_link--; + return NULL; + } + + if(obj->matrix != NULL ) { + for(i=0;ileni;i++) + if( obj->matrix[i] != NULL ) { + ckfree(obj->matrix[i]); + } + free(obj->matrix); + } + + + if( obj->spec_len > 0 ) { + if( obj->specmatrix == NULL ) { + warn("Bad karma. you have a special matrix of length %d, but a NULL specmatrix pointer. I'm not going to free it!",obj->spec_len); + } else { + for(i=0;ispec_len;i++) { + if( obj->specmatrix[i] != NULL ) { + ckfree(obj->specmatrix[i]); + } + } + ckfree(obj->specmatrix); + } /* end of else */ + } /* end of if specials */ + + if( obj->offsetmem != NULL ) + ckfree(obj->offsetmem); + if( obj->setmem != NULL ) + ckfree(obj->setmem); + + + ckfree(obj); + + return NULL; +} + + +# line 189 "basematrix.c" +/* Function: BaseMatrix_alloc_matrix(leni,lenj) + * + * Descrip: Allocates structure and matrix + * + * + * Arg: leni [UNKN ] Length of first dimension of matrix [int] + * Arg: lenj [UNKN ] Length of second dimension of matrix [int] + * + * Return [UNKN ] Undocumented return value [BaseMatrix *] + * + */ +BaseMatrix * BaseMatrix_alloc_matrix(int leni,int lenj) +{ + BaseMatrix * out; /* out is exported */ + register int i; /* for stepping down matrix */ + register int j; /* for stepping across matrix */ + + + /* Call alloc function, return NULL if NULL */ + if((out = BaseMatrix_alloc()) == NULL) + return NULL; + + + /* Allocate memory for matrix */ + if((out->matrix = (int **) ckcalloc (leni,sizeof(int *))) == NULL) { + warn("Memory allocation problem in matrix for BaseMatrix matrix, first pointer set"); + ckfree(out); + return NULL; + } + + + /* Add NULL to all matrix pointers so free can be called */ + for(i=0;imatrix[i] = NULL; + + + /* Allocate each matrix row */ + for(i=0;imatrix[i] = (int *) ckcalloc (lenj,sizeof(int )); + if( out->matrix[i] == NULL) { + warn("Failed alloc on %d, calling free and returning NULL",i); + free_BaseMatrix(out); + return NULL; + } + } + + + for(i=0;imatrix[i][j] = 0; + } + + + out->leni=out->maxleni=leni; + out->lenj=out->maxlenj=lenj; + + + return out; +} + + +/* Function: expand_BaseMatrix(obj,leni,lenj) + * + * Descrip: Expands matrix. Rarely used + * + * + * Arg: obj [UNKN ] Undocumented argument [BaseMatrix *] + * Arg: leni [UNKN ] Undocumented argument [int] + * Arg: lenj [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean expand_BaseMatrix(BaseMatrix * obj,int leni,int lenj) +{ + int i; + int actualj; + + + if( obj == NULL) { + warn("Trying to expand a BaseMatrix but is NULL!"); + return FALSE; + } + + + if( leni <= obj->maxleni && lenj <= obj->maxlenj) + return TRUE; + + + if( obj->maxleni < leni ) { + if( (obj->matrix=(int **) ckrealloc (obj->matrix,sizeof(int *)*leni)) == NULL) + return FALSE; + obj->maxleni=obj->leni=leni; + } + if( lenj > obj->maxlenj ) + actualj = lenj; + else actualj = obj->maxlenj; + for(i=0;ileni;i++) { + if((obj->matrix[i] = (int *) realloc (obj->matrix[i],sizeof(int ) * actualj)) == NULL) + return FALSE; + } + return TRUE; +} + + +/* Function: hard_link_BaseMatrix(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [BaseMatrix *] + * + * Return [UNKN ] Undocumented return value [BaseMatrix *] + * + */ +BaseMatrix * hard_link_BaseMatrix(BaseMatrix * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a BaseMatrix object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: BaseMatrix_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [BaseMatrix *] + * + */ +BaseMatrix * BaseMatrix_alloc(void) +{ + BaseMatrix * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(BaseMatrix *) ckalloc (sizeof(BaseMatrix))) == NULL) { + warn("BaseMatrix_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->type = BASEMATRIX_TYPE_UNKNOWN; + out->matrix = NULL; + out->leni=out->maxleni=0; + out->lenj=out->maxlenj=0; + out->cellsize = 0; + out->queryoffset = 0; + out->targetoffset = 0; + out->spec_len = 0; + out->specmatrix = NULL; + out->offsetmem = NULL; + out->setmem = NULL; + + + return out; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/basematrix.h b/Bio/Ext/Align/libs/basematrix.h new file mode 100644 index 0000000..dbb5e5e --- /dev/null +++ b/Bio/Ext/Align/libs/basematrix.h @@ -0,0 +1,274 @@ +#ifndef DYNAMITEbasematrixHEADERFILE +#define DYNAMITEbasematrixHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif + + +/********************************************************/ +/* Wisetools version 3 file */ +/* */ +/* this file is copyright (c) Ewan Birney 1996 */ +/* this file is part of the wisetools sequence analysis */ +/* package */ +/********************************************************/ + +/********************************************************/ +/* BaseMatrix - structure to hold the memory of */ +/* dynamite made matrices. */ +/* A dynamite support library */ +/* */ +/********************************************************/ + +/***** RCS Info *****************************************/ +/* + $Id$ + + $Log$ + Revision 1.1.1.1 1998/12/11 15:24:26 birney + bioperl after 0.04 + + Revision 1.1 1998/09/09 13:23:55 birney + Added the bp_sw machinery - this is machinery for doing smithwaterman + alignments and associated supporting objects + +# Revision 1.1.1.1 1998/08/28 09:30:47 birney +# Wise2 +# + * Revision 1.9 1997/11/12 13:20:18 birney + * added documentation, cleaned up + * + * Revision 1.8 1997/07/24 15:34:45 birney + * changed matrix size, and made 'IMPOSSIBLY_HIGH_SCORE' + * + * Revision 1.7 1997/02/11 20:42:48 birney + * added max basematrix number and query size for it + * + * Revision 1.6 1997/02/03 16:04:48 birney + * forgot to set spec_len in _and_special function. Ooops! + * + * Revision 1.5 1997/02/03 16:01:30 birney + * added BaseMatrix_alloc_matrix_and_specials, but not tested. + * + * Revision 1.4 1996/11/12 16:41:54 birney + * deconstructor was trying to free NULL'd pointers. (bad boy!) + * + * Revision 1.3 1996/11/11 22:17:22 birney + * tweaked specials to allow clean linear memory. Hacky deconstructor + * though now... + * + * Revision 1.2 1996/10/15 13:00:52 birney + * changed memory behaviour for offsets: caught a memory leak + * + * Revision 1.1 1996/03/03 15:38:44 birney + * Initial revision + * + +*/ +/********************************************************/ + + + +#include "wisebase.h" + +enum basematrix_types { + BASEMATRIX_TYPE_UNKNOWN = 67, + BASEMATRIX_TYPE_EXPLICIT, + BASEMATRIX_TYPE_LINEAR, + BASEMATRIX_TYPE_SHADOW, + BASEMATRIX_TYPE_VERYSMALL +}; + +#define COMPILE_BASEMATRIX_MAX_KB 2000 + + +#define IMPOSSIBLY_HIGH_SCORE 500000 + +struct bp_sw_BaseMatrix { + int dynamite_hard_link; + int type; + int ** matrix; /* NB i,j proper */ + int leni; /* leni for above matrix */ + int maxleni;/* max length for above pointer set */ + int lenj; /* lenj for above matrix */ + int maxlenj;/* max length for above pointer set */ + int cellsize; + int queryoffset; + int targetoffset; + int spec_len; + int ** offsetmatrix; /* complex - this points to an internal matrix of correct offsets (!) */ + int ** specmatrix; /* no longer linked: we have this memory specific... */ + int ** offsetmem; + int ** setmem; + } ; +/* BaseMatrix defined */ +#ifndef DYNAMITE_DEFINED_BaseMatrix +typedef struct bp_sw_BaseMatrix bp_sw_BaseMatrix; +#define BaseMatrix bp_sw_BaseMatrix +#define DYNAMITE_DEFINED_BaseMatrix +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: change_max_BaseMatrix_kbytes(new_kilo_number) + * + * Descrip: This is to change, at run-time the maximum level of bytes basematrix *thinks* + * it can use. This number is *not* used for any actual calls to basematrix + * allocation: it is only used with /get_max_BaseMatrix_kbytes + * + * + * Arg: new_kilo_number [UNKN ] max kilobytes allowed [int] + * + */ +void bp_sw_change_max_BaseMatrix_kbytes(int new_kilo_number); +#define change_max_BaseMatrix_kbytes bp_sw_change_max_BaseMatrix_kbytes + + +/* Function: get_max_BaseMatrix_kbytes(void) + * + * Descrip: returns the max. number of kilobytes suggested as a limited + * to BaseMatrix. + * + * + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_get_max_BaseMatrix_kbytes(void); +#define get_max_BaseMatrix_kbytes bp_sw_get_max_BaseMatrix_kbytes + + +/* Function: can_make_explicit_matrix(leni,lenj,statesize) + * + * Descrip: Just checkes that leni*lenj*statesize/1024 < max_matrix_bytes. + * returns TRUE if so, FALSE if not + * + * + * Arg: leni [UNKN ] Undocumented argument [int] + * Arg: lenj [UNKN ] Undocumented argument [int] + * Arg: statesize [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_can_make_explicit_matrix(int leni,int lenj,int statesize); +#define can_make_explicit_matrix bp_sw_can_make_explicit_matrix + + +/* Function: basematrix_type_to_string(type) + * + * Descrip: turns a int type to a char string of 'printable' + * types. + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_basematrix_type_to_string(int type); +#define basematrix_type_to_string bp_sw_basematrix_type_to_string + + +/* Function: BaseMatrix_alloc_matrix_and_specials(len_spec_poin,len_point,len_array,len_spec_point,len_spec_array) + * + * Descrip: This function allocates the two bits of + * matrix memory, of course returning a decent + * NULL (with memory zapped) if it can't do it + * + * + * Arg: len_spec_poin [UNKN ] length of pointers in special matrix [NullString] + * Arg: len_point [UNKN ] length of pointers in main matrix [int] + * Arg: len_array [UNKN ] length of array in main matrix [int] + * Arg: len_spec_point [UNKN ] Undocumented argument [int] + * Arg: len_spec_array [UNKN ] length of special array [int] + * + * Return [UNKN ] Undocumented return value [BaseMatrix *] + * + */ +BaseMatrix * bp_sw_BaseMatrix_alloc_matrix_and_specials(int len_point,int len_array,int len_spec_point,int len_spec_array); +#define BaseMatrix_alloc_matrix_and_specials bp_sw_BaseMatrix_alloc_matrix_and_specials + + +/* Function: free_BaseMatrix(obj) + * + * Descrip: this is the override deconstructor for basematrix. It will + * free both matrix and special memory + * + * + * Arg: obj [UNKN ] Undocumented argument [BaseMatrix *] + * + * Return [UNKN ] Undocumented return value [BaseMatrix *] + * + */ +BaseMatrix * bp_sw_free_BaseMatrix(BaseMatrix * obj); +#define free_BaseMatrix bp_sw_free_BaseMatrix + + +/* Function: BaseMatrix_alloc_matrix(leni,lenj) + * + * Descrip: Allocates structure and matrix + * + * + * Arg: leni [UNKN ] Length of first dimension of matrix [int] + * Arg: lenj [UNKN ] Length of second dimension of matrix [int] + * + * Return [UNKN ] Undocumented return value [BaseMatrix *] + * + */ +BaseMatrix * bp_sw_BaseMatrix_alloc_matrix(int leni,int lenj); +#define BaseMatrix_alloc_matrix bp_sw_BaseMatrix_alloc_matrix + + +/* Function: hard_link_BaseMatrix(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [BaseMatrix *] + * + * Return [UNKN ] Undocumented return value [BaseMatrix *] + * + */ +BaseMatrix * bp_sw_hard_link_BaseMatrix(BaseMatrix * obj); +#define hard_link_BaseMatrix bp_sw_hard_link_BaseMatrix + + +/* Function: BaseMatrix_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [BaseMatrix *] + * + */ +BaseMatrix * bp_sw_BaseMatrix_alloc(void); +#define BaseMatrix_alloc bp_sw_BaseMatrix_alloc + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +boolean bp_sw_expand_BaseMatrix(BaseMatrix * obj,int leni,int lenj); +#define expand_BaseMatrix bp_sw_expand_BaseMatrix + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/btcanvas.c b/Bio/Ext/Align/libs/btcanvas.c new file mode 100644 index 0000000..e571024 --- /dev/null +++ b/Bio/Ext/Align/libs/btcanvas.c @@ -0,0 +1,361 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "btcanvas.h" + +/* Function: can_get_paste_area_btCanvas(btc,length) + * + * Descrip: This returns whether there is room for length + * of chars in this line. If not, advance a line + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * Arg: length [UNKN ] length of block wanted [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 70 "btcanvas.dy" +boolean can_get_paste_area_btCanvas(btCanvas * btc,int length) +{ + + return ((*btc->can_get_paste_area)(btc,length)); +} + + +/* Function: advance_line_btCanvas(btc) + * + * Descrip: Advances the canvas to the next line + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 81 "btcanvas.dy" +boolean advance_line_btCanvas(btCanvas * btc) +{ + + return ((*btc->advance_line)(btc)); +} + +/* Function: get_reserved_left_btCanvas(btc) + * + * Descrip: This gets a paste-able area at the left hand + * side of block + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +# line 92 "btcanvas.dy" +btPasteArea * get_reserved_left_btCanvas(btCanvas * btc) +{ + return ((*btc->get_reserved_left)(btc)); +} + +/* Function: get_reserved_right_btCanvas(btc) + * + * Descrip: This gets a paste-able area at the right hand + * side of block + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +# line 102 "btcanvas.dy" +btPasteArea * get_reserved_right_btCanvas(btCanvas * btc) +{ + return ((*btc->get_reserved_right)(btc)); +} + + +/* Function: get_paste_area_btCanvas(btc,length) + * + * Descrip: This gets a paste-able area of a certain length from + * the current cursor. NULL on error + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * Arg: length [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +# line 113 "btcanvas.dy" +btPasteArea * get_paste_area_btCanvas(btCanvas * btc,int length) +{ + return ((*btc->get_paste_area)(btc,length)); +} + +/* Function: paste_substr_btPasteArea(bta,x,y,str,len,map_func,dir,format) + * + * Descrip: This will paste the substr of length len (obviously this could + * not be a \0 terminated string) starting from str[0] into btCanvas + * If map_func is non NULL, it converts each of the characters + * using the map_func first. This is surprisingly useful. + * + * map_func can be NULL, in which case the characters are just + * used as seen + * + * Length has to be less than 64 chars + * + * + * Arg: bta [UNKN ] PasteArea to be used [btPasteArea *] + * Arg: x [UNKN ] x position of start of string [int] + * Arg: y [UNKN ] y position of start of string [int] + * Arg: str [READ ] string to get the substr from to be pasted [const char *] + * Arg: len [READ ] length of the substr [int] + * Arg: map_func [FUNCP] Function to specifiy the mapping of chars from str to display [char (*map_func] + * Arg: dir [UNKN ] direction (BC_UP, BC_DOWN, BC_RIGHT, BC_LEFT) [btCanvasDirection] + * Arg: format [UNKN ] format (if recognised by the cnavas) [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 138 "btcanvas.dy" +boolean paste_substr_btPasteArea(btPasteArea * bta,int x,int y,const char * str,int len,char (*map_func)(char),btCanvasDirection dir,int format) +{ + char buf[64]; + const char *run; + int i; + + for(run=str,i=0;i bta->length || y > bta->height ) { + warn("Trying to paste a character into an unpasteable position [%d,%d] into [%d,%d]",x,y,bta->length,bta->height); + return FALSE; + } + + return ((*bta->paste_char))(bta,x,y,c,format); + +} + +/* Function: free_btPasteArea(obj) + * + * Descrip: Specialised deconstructor. Ensures the + * data structures are freed + * + * + * Arg: obj [WRITE] btPasteArea obj to be destroyed [btPasteArea *] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +# line 216 "btcanvas.dy" +btPasteArea * free_btPasteArea(btPasteArea * obj) +{ + return ((*obj->decons))(obj); +} + +/* Function: free_btCanvas(obj) + * + * Descrip: Specialised deconstructor. Ensures the + * data structures are freed + * + * + * Arg: obj [WRITE] btCanvas obj to be destroyed [btCanvas *] + * + * Return [UNKN ] Undocumented return value [btCanvas *] + * + */ +# line 228 "btcanvas.dy" +btCanvas * free_btCanvas(btCanvas * obj) +{ + return ((*obj->decons))(obj); +} + +# line 223 "btcanvas.c" +/* Function: hard_link_btPasteArea(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [btPasteArea *] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +btPasteArea * hard_link_btPasteArea(btPasteArea * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a btPasteArea object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: btPasteArea_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +btPasteArea * btPasteArea_alloc(void) +{ + btPasteArea * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(btPasteArea *) ckalloc (sizeof(btPasteArea))) == NULL) { + warn("btPasteArea_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->type = 0; + out->height = 0; + out->length = 0; + out->paste_char = NULL; + out->canvas_data = NULL; + out->decons = NULL; + + + return out; +} + + +/* Function: hard_link_btCanvas(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [btCanvas *] + * + * Return [UNKN ] Undocumented return value [btCanvas *] + * + */ +btCanvas * hard_link_btCanvas(btCanvas * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a btCanvas object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: btCanvas_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [btCanvas *] + * + */ +btCanvas * btCanvas_alloc(void) +{ + btCanvas * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(btCanvas *) ckalloc (sizeof(btCanvas))) == NULL) { + warn("btCanvas_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->type = 0; + out->height = 0; + out->res_right = 0; + out->res_left = 0; + out->can_get_paste_area = NULL; + out->advance_line = NULL; + out->get_paste_area = NULL; + out->get_reserved_right = NULL; + out->get_reserved_left = NULL; + out->canvas_data = NULL; + out->decons = NULL; + + + return out; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/btcanvas.h b/Bio/Ext/Align/libs/btcanvas.h new file mode 100644 index 0000000..cc6261e --- /dev/null +++ b/Bio/Ext/Align/libs/btcanvas.h @@ -0,0 +1,334 @@ +#ifndef DYNAMITEbtcanvasHEADERFILE +#define DYNAMITEbtcanvasHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" + + +typedef enum btCanvasDirection { + BC_UP, + BC_DOWN, + BC_RIGHT, + BC_LEFT +} btCanvasDirection ; + +/* + * Icky... icky.. icky + * + * Would you believe, some C compilers will not allow typdef's + * inside function to pointer definitions in structures... + * + * Hence - hard coded package names!!!! Yuk!!! + * + */ +#ifndef DYNAMITE_DEFINED_btPastArea +typedef struct bp_sw_btPastArea bp_sw_btPastArea; +#define btPastArea bp_sw_btPastArea +#define DYNAMITE_DEFINED_btPastArea +#endif + +#ifndef DYNAMITE_DEFINED_btCanvas +typedef struct bp_sw_btCanvas bp_sw_btCanvas; +#define btCanvas bp_sw_btCanvas +#define DYNAMITE_DEFINED_btCanvas +#endif + +struct bp_sw_btPasteArea { + int dynamite_hard_link; + int type; + int height; + int length; + boolean (*paste_char)(struct bp_sw_btPasteArea *,int,int,char,int); + void * canvas_data; + struct bp_sw_btPasteArea * (*decons)(struct bp_sw_btPasteArea * bt); + } ; +/* btPasteArea defined */ +#ifndef DYNAMITE_DEFINED_btPasteArea +typedef struct bp_sw_btPasteArea bp_sw_btPasteArea; +#define btPasteArea bp_sw_btPasteArea +#define DYNAMITE_DEFINED_btPasteArea +#endif + + +/* Object btCanvas + * + * Descrip: No Description + * + */ +struct bp_sw_btCanvas { + int dynamite_hard_link; + int type; + int height; + int res_right; + int res_left; + boolean (*can_get_paste_area)(struct bp_sw_btCanvas *,int); + boolean (*advance_line)(struct bp_sw_btCanvas *); + struct bp_sw_btPasteArea * (*get_paste_area)(struct bp_sw_btCanvas *,int); + struct bp_sw_btPasteArea * (*get_reserved_right)(struct bp_sw_btCanvas *); + struct bp_sw_btPasteArea * (*get_reserved_left)(struct bp_sw_btCanvas *); + void * canvas_data; + struct bp_sw_btCanvas * (*decons)(struct bp_sw_btCanvas * btc); + } ; +/* btCanvas defined */ +#ifndef DYNAMITE_DEFINED_btCanvas +typedef struct bp_sw_btCanvas bp_sw_btCanvas; +#define btCanvas bp_sw_btCanvas +#define DYNAMITE_DEFINED_btCanvas +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: can_get_paste_area_btCanvas(btc,length) + * + * Descrip: This returns whether there is room for length + * of chars in this line. If not, advance a line + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * Arg: length [UNKN ] length of block wanted [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_can_get_paste_area_btCanvas(btCanvas * btc,int length); +#define can_get_paste_area_btCanvas bp_sw_can_get_paste_area_btCanvas + + +/* Function: advance_line_btCanvas(btc) + * + * Descrip: Advances the canvas to the next line + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_advance_line_btCanvas(btCanvas * btc); +#define advance_line_btCanvas bp_sw_advance_line_btCanvas + + +/* Function: get_reserved_left_btCanvas(btc) + * + * Descrip: This gets a paste-able area at the left hand + * side of block + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +btPasteArea * bp_sw_get_reserved_left_btCanvas(btCanvas * btc); +#define get_reserved_left_btCanvas bp_sw_get_reserved_left_btCanvas + + +/* Function: get_reserved_right_btCanvas(btc) + * + * Descrip: This gets a paste-able area at the right hand + * side of block + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +btPasteArea * bp_sw_get_reserved_right_btCanvas(btCanvas * btc); +#define get_reserved_right_btCanvas bp_sw_get_reserved_right_btCanvas + + +/* Function: get_paste_area_btCanvas(btc,length) + * + * Descrip: This gets a paste-able area of a certain length from + * the current cursor. NULL on error + * + * + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * Arg: length [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +btPasteArea * bp_sw_get_paste_area_btCanvas(btCanvas * btc,int length); +#define get_paste_area_btCanvas bp_sw_get_paste_area_btCanvas + + +/* Function: paste_substr_btPasteArea(bta,x,y,str,len,map_func,dir,format) + * + * Descrip: This will paste the substr of length len (obviously this could + * not be a \0 terminated string) starting from str[0] into btCanvas + * If map_func is non NULL, it converts each of the characters + * using the map_func first. This is surprisingly useful. + * + * map_func can be NULL, in which case the characters are just + * used as seen + * + * Length has to be less than 64 chars + * + * + * Arg: bta [UNKN ] PasteArea to be used [btPasteArea *] + * Arg: x [UNKN ] x position of start of string [int] + * Arg: y [UNKN ] y position of start of string [int] + * Arg: str [READ ] string to get the substr from to be pasted [const char *] + * Arg: len [READ ] length of the substr [int] + * Arg: map_func [FUNCP] Function to specifiy the mapping of chars from str to display [char (*map_func] + * Arg: dir [UNKN ] direction (BC_UP, BC_DOWN, BC_RIGHT, BC_LEFT) [btCanvasDirection] + * Arg: format [UNKN ] format (if recognised by the cnavas) [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_paste_substr_btPasteArea(btPasteArea * bta,int x,int y,const char * str,int len,char (*map_func)(char),btCanvasDirection dir,int format); +#define paste_substr_btPasteArea bp_sw_paste_substr_btPasteArea + + +/* Function: paste_string_btPasteArea(bta,x,y,str,dir,format) + * + * Descrip: This will paste the '\0' terminated string into x,y in the direction + * specified (up, down, left or right) + * + * + * Arg: bta [UNKN ] PasteArea to be used [btPasteArea *] + * Arg: x [UNKN ] x position of start of string [int] + * Arg: y [UNKN ] y position of start of string [int] + * Arg: str [READ ] string to be pasted [const char *] + * Arg: dir [UNKN ] direction (BC_UP, BC_DOWN, BC_RIGHT, BC_LEFT) [btCanvasDirection] + * Arg: format [UNKN ] format (if recognised by the cnavas) [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_paste_string_btPasteArea(btPasteArea * bta,int x,int y,const char * str,btCanvasDirection dir,int format); +#define paste_string_btPasteArea bp_sw_paste_string_btPasteArea + + +/* Function: paste_char_btPasteArea(bta,x,y,c,format) + * + * Descrip: This will paste one character at x,y into the paste area. + * If the canvas understands the format style, it will take + * notice of it. + * + * + * Arg: bta [UNKN ] Undocumented argument [btPasteArea *] + * Arg: x [UNKN ] Undocumented argument [int] + * Arg: y [UNKN ] Undocumented argument [int] + * Arg: c [UNKN ] Undocumented argument [char] + * Arg: format [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_paste_char_btPasteArea(btPasteArea * bta,int x,int y,char c,int format) ; +#define paste_char_btPasteArea bp_sw_paste_char_btPasteArea + + +/* Function: free_btPasteArea(obj) + * + * Descrip: Specialised deconstructor. Ensures the + * data structures are freed + * + * + * Arg: obj [WRITE] btPasteArea obj to be destroyed [btPasteArea *] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +btPasteArea * bp_sw_free_btPasteArea(btPasteArea * obj); +#define free_btPasteArea bp_sw_free_btPasteArea + + +/* Function: free_btCanvas(obj) + * + * Descrip: Specialised deconstructor. Ensures the + * data structures are freed + * + * + * Arg: obj [WRITE] btCanvas obj to be destroyed [btCanvas *] + * + * Return [UNKN ] Undocumented return value [btCanvas *] + * + */ +btCanvas * bp_sw_free_btCanvas(btCanvas * obj); +#define free_btCanvas bp_sw_free_btCanvas + + +/* Function: hard_link_btPasteArea(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [btPasteArea *] + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +btPasteArea * bp_sw_hard_link_btPasteArea(btPasteArea * obj); +#define hard_link_btPasteArea bp_sw_hard_link_btPasteArea + + +/* Function: btPasteArea_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [btPasteArea *] + * + */ +btPasteArea * bp_sw_btPasteArea_alloc(void); +#define btPasteArea_alloc bp_sw_btPasteArea_alloc + + +/* Function: hard_link_btCanvas(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [btCanvas *] + * + * Return [UNKN ] Undocumented return value [btCanvas *] + * + */ +btCanvas * bp_sw_hard_link_btCanvas(btCanvas * obj); +#define hard_link_btCanvas bp_sw_hard_link_btCanvas + + +/* Function: btCanvas_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [btCanvas *] + * + */ +btCanvas * bp_sw_btCanvas_alloc(void); +#define btCanvas_alloc bp_sw_btCanvas_alloc + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/codon.c b/Bio/Ext/Align/libs/codon.c new file mode 100644 index 0000000..e6b0ae9 --- /dev/null +++ b/Bio/Ext/Align/libs/codon.c @@ -0,0 +1,743 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "codon.h" + +/* Function: read_CodonTable_file(file) + * + * Descrip: Opens filename, reads it as if a Ewan style + * codon table and closes. + * + * + * Arg: file [READ ] filename to open [char *] + * + * Return [OWNER] A codon-table, NULL if error [CodonTable *] + * + */ +# line 77 "codon.dy" +CodonTable * read_CodonTable_file(char * file) +{ + FILE * ifp; + CodonTable * out; + + ifp = openfile(file,"r"); + + if( ifp == NULL) { + warn("Could not open file %s as codon table file",file); + return NULL; + } + + out = read_CodonTable(ifp); + + fclose(ifp); + + return out; +} + +/* Function: read_CodonTable(ifp) + * + * Descrip: reads a codon table from a filestream in Ewan + * format. + * + * As Ewan format is really bad and has no start/stop + * this will effectively read to the end of the file. + * Ooops. + * + * + * Arg: ifp [READ ] file input [FILE *] + * + * Return [UNKN ] Undocumented return value [CodonTable *] + * + */ +# line 106 "codon.dy" +CodonTable * read_CodonTable(FILE * ifp) +{ + char buffer[MAXLINE]; + CodonTable * out; + codon c; + char * runner; + char * run2; + + out = CodonTable_alloc(); + memset(out->codon_str,'x',125); + + while( fgets(buffer,MAXLINE,ifp) != NULL) { + if( buffer[0] == '#' || buffer[0] == '!') + continue; + runner = strtok(buffer,spacestr); + run2 = strtok(NULL,spacestr); + + if( runner == NULL || run2 == NULL ){ + warn("Unable to read a line in codon table"); + } + + c = codon_from_seq(runner); + + out->codon_str[c] = *run2; + } + + return out; +} + + +/* Function: alloc_aminoacid_from_seq(ct,seq) + * + * Descrip: Not very useful function: allocates a single amino + * acid (ie, buffer length one) so it can be freed later. + * + * + * Arg: ct [READ ] codon table [CodonTable *] + * Arg: seq [READ ] pointer to DNA Sequence chars [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 144 "codon.dy" +char * alloc_aminoacid_from_seq(CodonTable * ct,char * seq) +{ + char buf[2]; + + buf[1] = '\0'; + + buf[0] = aminoacid_from_codon(ct,codon_from_seq(seq)); + + return stringalloc(buf); +} + +/* Function: aminoacid_from_seq(ct,seq) + * + * Descrip: Returns the amino acid for this position in the DNA sequence + * Takes the pointer +1 and +2 points. + * + * No error checks implemented. Probably a mistake ;) + * + * + * Arg: ct [READ ] codon table [CodonTable *] + * Arg: seq [READ ] pointer to DNA chars [char *] + * + * Return [OWNER] an amino acid char (A-Z) [aa] + * + */ +# line 165 "codon.dy" +aa aminoacid_from_seq(CodonTable * ct,char * seq) +{ + return aminoacid_from_codon(ct,codon_from_seq(seq)); +} + +/* Function: aminoacid_from_codon(ct,c) + * + * Descrip: returns amino acid for this codon number (NB codon numbers 0-125) + * + * + * Arg: ct [READ ] codon table [CodonTable *] + * Arg: c [READ ] codon number [codon] + * + * Return [READ ] aminoacid that is this codon (X for ambiguous, * for stop) [aa] + * + */ +# line 177 "codon.dy" +aa aminoacid_from_codon(CodonTable * ct,codon c) +{ + return ct->codon_str[c]; +} + +/* Function: aminoacid_no_from_codon(ct,c) + * + * Descrip: a sister function to aminoacid_from_codon: + * returns amino acid number (0-26) for this codon number (0-125) + * + * + * Arg: ct [READ ] codon table [CodonTable *] + * Arg: c [READ ] codon number [codon] + * + * Return [READ ] aminoacid number [0-26] for this codon [int] + * + */ +# line 190 "codon.dy" +int aminoacid_no_from_codon(CodonTable * ct,codon c) +{ + return (ct->codon_str[c] - 'A'); +} + +/* Function: is_stop_codon(c,ct) + * + * Descrip: tells you whether this codon number is really a stop + * in this translation table + * + * + * Arg: c [READ ] codon number [codon] + * Arg: ct [READ ] codon table [CodonTable *] + * + * Return [UNKN ] TRUE if is stop, FALSE otherwise [boolean] + * + */ +# line 203 "codon.dy" +boolean is_stop_codon(codon c,CodonTable * ct) +{ + aa a; + + a = aminoacid_from_codon(ct,c); + + if( a == 'X' || a == '*') { + return TRUE; + } + + return FALSE; +} + +/* Function: is_non_ambiguous_codon_seq(seq) + * + * Descrip: Tells you if this codon is a real codon + * + * + * Arg: seq [READ ] pointer to DNA sequence [char *] + * + * Return [UNKN ] TRUE if real codon, FALSE if contains N's [boolean] + * + */ +# line 222 "codon.dy" +boolean is_non_ambiguous_codon_seq(char * seq) +{ + if( *seq == '\0' || *(seq+1) == '\0' || *(seq+2) == '\0') { + warn("Attempting to find a codon number is something less than 3 bases long!"); + return FALSE; + } + + if( base_from_char(*(seq++)) == BASE_N) + return FALSE; + if( base_from_char(*(seq++)) == BASE_N) + return FALSE; + if( base_from_char(*(seq)) == BASE_N) + return FALSE; + + return TRUE; +} + +/* Function: is_valid_aminoacid(ct,c) + * + * Descrip: Tells you if this letter (c) is recognised as a valid amino acid + * in this codon table + * + * + * Arg: ct [READ ] Codon Table [CodonTable *] + * Arg: c [UNKN ] aminoacid [char] + * + * Return [UNKN ] TRUE if valid, FALSE if not. [boolean] + * + */ +# line 247 "codon.dy" +boolean is_valid_aminoacid(CodonTable * ct,char c) +{ + if( strchr(ct->codon_str,c) != NULL ) + return TRUE; + else return FALSE; +} + +/* Function: is_valid_base_char(c) + * + * Descrip: Tells you if the letter is A,T,C,G,N (NB, N is ok). + * + * + * Arg: c [READ ] base [char] + * + * Return [UNKN ] TRUE if (ATGCN) FALSE otherwise [boolean] + * + */ +# line 260 "codon.dy" +boolean is_valid_base_char(char c) +{ + if( c == 'A' || c == 'T' || c == 'G' || c == 'C' || c == 'N') + return TRUE; + return FALSE; +} + +/* Function: codon_from_base4_codon(c) + * + * Descrip: maps a 0-63 codon to a 0-123 codon. Suprisingly useful. + * + * + * Arg: c [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [codon] + * + */ +# line 270 "codon.dy" +codon codon_from_base4_codon(int c) +{ + base one; + base two; + base three; + + one = c / 16; + c -= one*16; + + two = c/4; + c -= 4*two; + three = c; + + return 25*one+5*two+three; +} + +/* Function: base4_codon_from_codon(c) + * + * Descrip: maps a 0-125 codon to a 0-63 codon. + * + * If ambiguous then returns 64 having issued a warning. + * + * + * Arg: c [READ ] codon 0-125 [codon] + * + * Return [UNKN ] base 4 codon (0-63) [int] + * + */ +# line 294 "codon.dy" +int base4_codon_from_codon(codon c) +{ + base one; + base two; + base three; + + all_bases_from_codon(c,&one,&two,&three); + + if( one == BASE_N || two == BASE_N || three == BASE_N) { + warn("Attempting to convert an ambiguous codon to base 64... returning 64"); + return 64; + } + + return one*16 + two*4 + three; +} + +/* Function: has_random_bases(c) + * + * Descrip: Tests to see if this codon number has any N's in it + * + * + * Arg: c [READ ] codon number 0-124 [codon] + * + * Return [UNKN ] TRUE if has N's , FALSE otherwise [boolean] + * + */ +# line 316 "codon.dy" +boolean has_random_bases(codon c) +{ + base o; + base w; + base t; + + o = base_from_codon(c,1); + w = base_from_codon(c,2); + t = base_from_codon(c,3); + + if( o == BASE_N || w == BASE_N || t == BASE_N) + return TRUE; + + return FALSE; +} + +/* Function: permute_possible_random_bases(c,one,two,three) + * + * Descrip: Bizarely useful function for calculating ambiguity scores. + * + * This takes the codon c, and for each possible base, + * if it is N, replaces it with one, two or three. + * + * If the base is not N, it remains the same + * + * + * Arg: c [READ ] codon number [codon] + * Arg: one [READ ] base to replace first position if N [base] + * Arg: two [READ ] base to replace second position if N [base] + * Arg: three [READ ] base to replace third position if N [base] + * + * Return [UNKN ] codon number [codon] + * + */ +# line 346 "codon.dy" +codon permute_possible_random_bases(codon c,base one,base two,base three) +{ + base o; + base w; + base t; + + o = base_from_codon(c,1); + w = base_from_codon(c,2); + t = base_from_codon(c,3); + + if( o == BASE_N ) + o = one; + if( w == BASE_N ) + w = two; + if( t == BASE_N ) + t = three; + + return one*25+two*5+three; +} + + +/* Function: all_bases_from_codon(c,one,two,three) + * + * Descrip: Really an internal function, by useful enough to + * encourage outside use. + * + * Takes codon c and breaks it into 3 base-numbers + * + * + * Arg: c [UNKN ] Undocumented argument [codon] + * Arg: one [UNKN ] Undocumented argument [base *] + * Arg: two [UNKN ] Undocumented argument [base *] + * Arg: three [UNKN ] Undocumented argument [base *] + * + */ +# line 373 "codon.dy" +void all_bases_from_codon(codon c,base * one,base * two,base * three) +{ + base o; + base t; + base r; + + o = c/25; + c -= o*25; + + t = c/5; + c -= t*5; + + r = c; + + if( one != NULL ) + *one = o; + if( two != NULL ) + *two = t; + if( three != NULL ) + *three = r; + +} + + +/* Function: base_from_codon(c,pos) + * + * Descrip: Probably not the best function to use for this, but + * useful. Takes a codon and with pos being 1,2,3 gives + * you the firt,second of third base + * + * + * Arg: c [UNKN ] Undocumented argument [codon] + * Arg: pos [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [base] + * + */ +# line 402 "codon.dy" +base base_from_codon(codon c,int pos) +{ + base one; + base two; + base three; + + one = c/25; + c -= one*25; + + two = c/5; + c -= two*5; + + three = c; + + switch(pos) { + case 1 : return one; + case 2: return two; + case 3: return three; + default : + warn("This is not good news: got a position asked which is not 1,2,3 [%d](BTW - first base is 1)",pos); + return BASE_N; + } + +} + +/* Function: codon_from_seq(seq) + * + * Descrip: takes an ASCII coded pointer to a 3 base pair + * sequence (it could be the part of a sequence: it only + * assummes that the seq points with 3 chars at pos 0,1,2 + * in C coordinates from seq. No NULL is required). It + * ives back the codon as made from standard mapping, ie, + * 25*base_1+5*base_2 + base3 being a number from 0-124 inc. + * + * + * Arg: seq [UNKN ] pointer to sequence of at least 3 chrs long. [char *] + * + * Return [UNKN ] Undocumented return value [codon] + * + */ +# line 437 "codon.dy" +codon codon_from_seq(char * seq) +{ + base one; + base two; + base three; + + one = base_from_char(*seq); + two = base_from_char(*(seq+1)); + three = base_from_char(*(seq+2)); + + return one*25+two*5+three; +} + +/* Function: base4_codon_from_seq(seq) + * + * Descrip: Sometimes it is more useful to work in base64, ie, + * non N. this functions does the same thing as + * /codon_from_seq but produces a seq being + * 16*base1 + 4 *base2 + base3 + * + * + * Arg: seq [UNKN ] pointer to sequence of at least 3 chrs long [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 458 "codon.dy" +int base4_codon_from_seq(char * seq) +{ + base one; + base two; + base three; + + one = base_from_char(*seq); + two = base_from_char(*(seq+1)); + three = base_from_char(*(seq+2)); + + if( one == BASE_N || two == BASE_N || three == BASE_N) + return 64; + + else return one*16+two*4+three; +} + +/* Function: char_from_base(b) + * + * Descrip: maps a base number (-04 inc) to A,T,G,C,N + * + * + * Arg: b [UNKN ] Undocumented argument [base] + * + * Return [UNKN ] Undocumented return value [char] + * + */ +# line 477 "codon.dy" +char char_from_base(base b) +{ + switch(b) { + case BASE_A : return 'A'; + case BASE_G : return 'G'; + case BASE_C : return 'C'; + case BASE_T : return 'T'; + case BASE_N : return 'N'; + default : return '?'; + } + +} + +/* Function: base_from_char(c) + * + * Descrip: maps a char (atcgn) to number, + * case insensitive, returns BASE_N + * if not atcgn + * + * + * Arg: c [UNKN ] Undocumented argument [char] + * + * Return [UNKN ] Undocumented return value [base] + * + */ +# line 495 "codon.dy" +base base_from_char(char c) +{ + c = toupper(c); + + switch(c) { + case 'A' : return BASE_A; + case 'T' : return BASE_T; + case 'G' : return BASE_G; + case 'C' : return BASE_C; + case 'N' : return BASE_N; + default : return BASE_N; + } +} + +/* Function: char_complement_base(c) + * + * Descrip: the char equivalent of /complement_base. + * this gives the complement in char of a base + * in char. Does not check for non ATGCN + * + * + * Arg: c [UNKN ] Undocumented argument [char] + * + * Return [UNKN ] Undocumented return value [char] + * + */ +# line 514 "codon.dy" +char char_complement_base(char c) +{ + return char_from_base(complement_base(base_from_char(c))); +} + +/* Function: complement_base(b) + * + * Descrip: gives back the complement as a number + * ofthe base (given as a number) + * + * + * Arg: b [UNKN ] Undocumented argument [base] + * + * Return [UNKN ] Undocumented return value [base] + * + */ +# line 523 "codon.dy" +base complement_base(base b) +{ + switch(b) { + case BASE_A : return BASE_T; + case BASE_G : return BASE_C; + case BASE_C : return BASE_G; + case BASE_T : return BASE_A; + case BASE_N : return BASE_N; + default : return BASE_N; + } + +} + + + + +# line 566 "codon.c" +/* Function: hard_link_CodonTable(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [CodonTable *] + * + * Return [UNKN ] Undocumented return value [CodonTable *] + * + */ +CodonTable * hard_link_CodonTable(CodonTable * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a CodonTable object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: CodonTable_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [CodonTable *] + * + */ +CodonTable * CodonTable_alloc(void) +{ + CodonTable * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(CodonTable *) ckalloc (sizeof(CodonTable))) == NULL) { + warn("CodonTable_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + /* codon_str[125] is an array: no default possible */ + out->name = NULL; + + + return out; +} + + +/* Function: free_CodonTable(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [CodonTable *] + * + * Return [UNKN ] Undocumented return value [CodonTable *] + * + */ +CodonTable * free_CodonTable(CodonTable * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a CodonTable obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->name != NULL) + ckfree(obj->name); + + + ckfree(obj); + return NULL; +} + + +/* Function: replace_name_CodonTable(obj,name) + * + * Descrip: Replace member variable name + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [CodonTable *] + * Arg: name [OWNER] New value of the variable [char *] + * + * Return [SOFT ] member variable name [boolean] + * + */ +boolean replace_name_CodonTable(CodonTable * obj,char * name) +{ + if( obj == NULL) { + warn("In replacement function name for object CodonTable, got a NULL object"); + return FALSE; + } + obj->name = name; + return TRUE; +} + + +/* Function: access_name_CodonTable(obj) + * + * Descrip: Access member variable name + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [CodonTable *] + * + * Return [SOFT ] member variable name [char *] + * + */ +char * access_name_CodonTable(CodonTable * obj) +{ + if( obj == NULL) { + warn("In accessor function name for object CodonTable, got a NULL object"); + return NULL; + } + return obj->name; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/codon.h b/Bio/Ext/Align/libs/codon.h new file mode 100644 index 0000000..0a28105 --- /dev/null +++ b/Bio/Ext/Align/libs/codon.h @@ -0,0 +1,462 @@ +#ifndef DYNAMITEcodonHEADERFILE +#define DYNAMITEcodonHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" + + +#define BASE_A 0 +#define BASE_G 1 +#define BASE_C 2 +#define BASE_T 3 +#define BASE_N 4 + +typedef short int base; +typedef short int codon; +typedef char aa; + +#define aminoacid_number(c) (c-'A') + +/* Object CodonTable + * + * Descrip: The codon table provides a mapping from the 64 codons to the 20 amino + * acids. The rest of the modules provides assorted codon<->base<->amino + * acid mappings. + * + * Probably the trickiest thing is that there are two different types of + * representations of codons. One in base 5 (N being the 5th base), + * providing 0-124 inclusive codon numbers. These numbers are the ones + * going to be principly used in most calculations. + * + * However, it is often very useful to use 0-63 numbers, for example + * in the precise definition of the codon table. + * + * + */ +struct bp_sw_CodonTable { + int dynamite_hard_link; + aa codon_str[125]; + char * name; + } ; +/* CodonTable defined */ +#ifndef DYNAMITE_DEFINED_CodonTable +typedef struct bp_sw_CodonTable bp_sw_CodonTable; +#define CodonTable bp_sw_CodonTable +#define DYNAMITE_DEFINED_CodonTable +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: read_CodonTable_file(file) + * + * Descrip: Opens filename, reads it as if a Ewan style + * codon table and closes. + * + * + * Arg: file [READ ] filename to open [char *] + * + * Return [OWNER] A codon-table, NULL if error [CodonTable *] + * + */ +CodonTable * bp_sw_read_CodonTable_file(char * file); +#define read_CodonTable_file bp_sw_read_CodonTable_file + + +/* Function: read_CodonTable(ifp) + * + * Descrip: reads a codon table from a filestream in Ewan + * format. + * + * As Ewan format is really bad and has no start/stop + * this will effectively read to the end of the file. + * Ooops. + * + * + * Arg: ifp [READ ] file input [FILE *] + * + * Return [UNKN ] Undocumented return value [CodonTable *] + * + */ +CodonTable * bp_sw_read_CodonTable(FILE * ifp); +#define read_CodonTable bp_sw_read_CodonTable + + +/* Function: aminoacid_from_seq(ct,seq) + * + * Descrip: Returns the amino acid for this position in the DNA sequence + * Takes the pointer +1 and +2 points. + * + * No error checks implemented. Probably a mistake ;) + * + * + * Arg: ct [READ ] codon table [CodonTable *] + * Arg: seq [READ ] pointer to DNA chars [char *] + * + * Return [OWNER] an amino acid char (A-Z) [aa] + * + */ +aa bp_sw_aminoacid_from_seq(CodonTable * ct,char * seq); +#define aminoacid_from_seq bp_sw_aminoacid_from_seq + + +/* Function: aminoacid_from_codon(ct,c) + * + * Descrip: returns amino acid for this codon number (NB codon numbers 0-125) + * + * + * Arg: ct [READ ] codon table [CodonTable *] + * Arg: c [READ ] codon number [codon] + * + * Return [READ ] aminoacid that is this codon (X for ambiguous, * for stop) [aa] + * + */ +aa bp_sw_aminoacid_from_codon(CodonTable * ct,codon c); +#define aminoacid_from_codon bp_sw_aminoacid_from_codon + + +/* Function: aminoacid_no_from_codon(ct,c) + * + * Descrip: a sister function to aminoacid_from_codon: + * returns amino acid number (0-26) for this codon number (0-125) + * + * + * Arg: ct [READ ] codon table [CodonTable *] + * Arg: c [READ ] codon number [codon] + * + * Return [READ ] aminoacid number [0-26] for this codon [int] + * + */ +int bp_sw_aminoacid_no_from_codon(CodonTable * ct,codon c); +#define aminoacid_no_from_codon bp_sw_aminoacid_no_from_codon + + +/* Function: is_stop_codon(c,ct) + * + * Descrip: tells you whether this codon number is really a stop + * in this translation table + * + * + * Arg: c [READ ] codon number [codon] + * Arg: ct [READ ] codon table [CodonTable *] + * + * Return [UNKN ] TRUE if is stop, FALSE otherwise [boolean] + * + */ +boolean bp_sw_is_stop_codon(codon c,CodonTable * ct); +#define is_stop_codon bp_sw_is_stop_codon + + +/* Function: is_non_ambiguous_codon_seq(seq) + * + * Descrip: Tells you if this codon is a real codon + * + * + * Arg: seq [READ ] pointer to DNA sequence [char *] + * + * Return [UNKN ] TRUE if real codon, FALSE if contains N's [boolean] + * + */ +boolean bp_sw_is_non_ambiguous_codon_seq(char * seq); +#define is_non_ambiguous_codon_seq bp_sw_is_non_ambiguous_codon_seq + + +/* Function: is_valid_aminoacid(ct,c) + * + * Descrip: Tells you if this letter (c) is recognised as a valid amino acid + * in this codon table + * + * + * Arg: ct [READ ] Codon Table [CodonTable *] + * Arg: c [UNKN ] aminoacid [char] + * + * Return [UNKN ] TRUE if valid, FALSE if not. [boolean] + * + */ +boolean bp_sw_is_valid_aminoacid(CodonTable * ct,char c); +#define is_valid_aminoacid bp_sw_is_valid_aminoacid + + +/* Function: is_valid_base_char(c) + * + * Descrip: Tells you if the letter is A,T,C,G,N (NB, N is ok). + * + * + * Arg: c [READ ] base [char] + * + * Return [UNKN ] TRUE if (ATGCN) FALSE otherwise [boolean] + * + */ +boolean bp_sw_is_valid_base_char(char c); +#define is_valid_base_char bp_sw_is_valid_base_char + + +/* Function: codon_from_base4_codon(c) + * + * Descrip: maps a 0-63 codon to a 0-123 codon. Suprisingly useful. + * + * + * Arg: c [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [codon] + * + */ +codon bp_sw_codon_from_base4_codon(int c); +#define codon_from_base4_codon bp_sw_codon_from_base4_codon + + +/* Function: base4_codon_from_codon(c) + * + * Descrip: maps a 0-125 codon to a 0-63 codon. + * + * If ambiguous then returns 64 having issued a warning. + * + * + * Arg: c [READ ] codon 0-125 [codon] + * + * Return [UNKN ] base 4 codon (0-63) [int] + * + */ +int bp_sw_base4_codon_from_codon(codon c); +#define base4_codon_from_codon bp_sw_base4_codon_from_codon + + +/* Function: has_random_bases(c) + * + * Descrip: Tests to see if this codon number has any N's in it + * + * + * Arg: c [READ ] codon number 0-124 [codon] + * + * Return [UNKN ] TRUE if has N's , FALSE otherwise [boolean] + * + */ +boolean bp_sw_has_random_bases(codon c); +#define has_random_bases bp_sw_has_random_bases + + +/* Function: permute_possible_random_bases(c,one,two,three) + * + * Descrip: Bizarely useful function for calculating ambiguity scores. + * + * This takes the codon c, and for each possible base, + * if it is N, replaces it with one, two or three. + * + * If the base is not N, it remains the same + * + * + * Arg: c [READ ] codon number [codon] + * Arg: one [READ ] base to replace first position if N [base] + * Arg: two [READ ] base to replace second position if N [base] + * Arg: three [READ ] base to replace third position if N [base] + * + * Return [UNKN ] codon number [codon] + * + */ +codon bp_sw_permute_possible_random_bases(codon c,base one,base two,base three); +#define permute_possible_random_bases bp_sw_permute_possible_random_bases + + +/* Function: all_bases_from_codon(c,one,two,three) + * + * Descrip: Really an internal function, by useful enough to + * encourage outside use. + * + * Takes codon c and breaks it into 3 base-numbers + * + * + * Arg: c [UNKN ] Undocumented argument [codon] + * Arg: one [UNKN ] Undocumented argument [base *] + * Arg: two [UNKN ] Undocumented argument [base *] + * Arg: three [UNKN ] Undocumented argument [base *] + * + */ +void bp_sw_all_bases_from_codon(codon c,base * one,base * two,base * three); +#define all_bases_from_codon bp_sw_all_bases_from_codon + + +/* Function: base_from_codon(c,pos) + * + * Descrip: Probably not the best function to use for this, but + * useful. Takes a codon and with pos being 1,2,3 gives + * you the firt,second of third base + * + * + * Arg: c [UNKN ] Undocumented argument [codon] + * Arg: pos [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [base] + * + */ +base bp_sw_base_from_codon(codon c,int pos); +#define base_from_codon bp_sw_base_from_codon + + +/* Function: codon_from_seq(seq) + * + * Descrip: takes an ASCII coded pointer to a 3 base pair + * sequence (it could be the part of a sequence: it only + * assummes that the seq points with 3 chars at pos 0,1,2 + * in C coordinates from seq. No NULL is required). It + * ives back the codon as made from standard mapping, ie, + * 25*base_1+5*base_2 + base3 being a number from 0-124 inc. + * + * + * Arg: seq [UNKN ] pointer to sequence of at least 3 chrs long. [char *] + * + * Return [UNKN ] Undocumented return value [codon] + * + */ +codon bp_sw_codon_from_seq(char * seq); +#define codon_from_seq bp_sw_codon_from_seq + + +/* Function: base4_codon_from_seq(seq) + * + * Descrip: Sometimes it is more useful to work in base64, ie, + * non N. this functions does the same thing as + * /codon_from_seq but produces a seq being + * 16*base1 + 4 *base2 + base3 + * + * + * Arg: seq [UNKN ] pointer to sequence of at least 3 chrs long [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_base4_codon_from_seq(char * seq); +#define base4_codon_from_seq bp_sw_base4_codon_from_seq + + +/* Function: char_from_base(b) + * + * Descrip: maps a base number (-04 inc) to A,T,G,C,N + * + * + * Arg: b [UNKN ] Undocumented argument [base] + * + * Return [UNKN ] Undocumented return value [char] + * + */ +char bp_sw_char_from_base(base b); +#define char_from_base bp_sw_char_from_base + + +/* Function: base_from_char(c) + * + * Descrip: maps a char (atcgn) to number, + * case insensitive, returns BASE_N + * if not atcgn + * + * + * Arg: c [UNKN ] Undocumented argument [char] + * + * Return [UNKN ] Undocumented return value [base] + * + */ +base bp_sw_base_from_char(char c); +#define base_from_char bp_sw_base_from_char + + +/* Function: char_complement_base(c) + * + * Descrip: the char equivalent of /complement_base. + * this gives the complement in char of a base + * in char. Does not check for non ATGCN + * + * + * Arg: c [UNKN ] Undocumented argument [char] + * + * Return [UNKN ] Undocumented return value [char] + * + */ +char bp_sw_char_complement_base(char c); +#define char_complement_base bp_sw_char_complement_base + + +/* Function: complement_base(b) + * + * Descrip: gives back the complement as a number + * ofthe base (given as a number) + * + * + * Arg: b [UNKN ] Undocumented argument [base] + * + * Return [UNKN ] Undocumented return value [base] + * + */ +base bp_sw_complement_base(base b); +#define complement_base bp_sw_complement_base + + +/* Function: hard_link_CodonTable(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [CodonTable *] + * + * Return [UNKN ] Undocumented return value [CodonTable *] + * + */ +CodonTable * bp_sw_hard_link_CodonTable(CodonTable * obj); +#define hard_link_CodonTable bp_sw_hard_link_CodonTable + + +/* Function: CodonTable_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [CodonTable *] + * + */ +CodonTable * bp_sw_CodonTable_alloc(void); +#define CodonTable_alloc bp_sw_CodonTable_alloc + + +/* Function: free_CodonTable(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [CodonTable *] + * + * Return [UNKN ] Undocumented return value [CodonTable *] + * + */ +CodonTable * bp_sw_free_CodonTable(CodonTable * obj); +#define free_CodonTable bp_sw_free_CodonTable + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +boolean bp_sw_replace_name_CodonTable(CodonTable * obj,char * name); +#define replace_name_CodonTable bp_sw_replace_name_CodonTable +char * bp_sw_access_name_CodonTable(CodonTable * obj); +#define access_name_CodonTable bp_sw_access_name_CodonTable +char * bp_sw_alloc_aminoacid_from_seq(CodonTable * ct,char * seq); +#define alloc_aminoacid_from_seq bp_sw_alloc_aminoacid_from_seq + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/commandline.c b/Bio/Ext/Align/libs/commandline.c new file mode 100644 index 0000000..284fa2f --- /dev/null +++ b/Bio/Ext/Align/libs/commandline.c @@ -0,0 +1,226 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "commandline.h" + + +/* Function: strip_out_remaining_options_with_warning(argc,argv) + * + * Descrip: This removes all remaining options, issuing warnings + * through warn + * + * + * Arg: argc [UNKN ] Undocumented argument [int *] + * Arg: argv [UNKN ] Undocumented argument [char **] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 33 "commandline.dy" +boolean strip_out_remaining_options_with_warning(int * argc,char ** argv) +{ + register int i; + boolean ret = FALSE; + + + for(i=0;i<*argc;i++) { + if( argv[i][0] != '-' ) + continue; + + /*** ignore bare '-' - could be arguments ***/ + + if( argv[i][1] == '\0') + continue; + + warn("You have an unrecognised argument, %s, removing",argv[i]); + + memmove(argv+i,argv+i+1,sizeof(char *)*(*argc - i -1)); + *argc -= 1; + ret = TRUE; + } + + return ret; +} + +/* Function: strip_out_boolean_argument(argc,argv,tag) + * + * Descrip: This removes argument in tag from the commandline if there and + * returns TRUE + * + * otherwise returns FALSE + * + * + * Arg: argc [UNKN ] argc from main declaration (call as &argc) [int *] + * Arg: argv [UNKN ] argv from main declaration [char **] + * Arg: tag [READ ] -[string] argument to find [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 68 "commandline.dy" +boolean strip_out_boolean_argument(int * argc,char ** argv,char * tag) +{ + register int i; + + for(i=0;i<*argc;i++) { + if( argv[i][0] != '-' ) + continue; + + /** ignore '-' by themselves **/ + + if( argv[i][1] == '\0') + continue; + + /** try to strcmp with tag **/ + + if( strcmp(tag,argv[i]+1) == 0 ) { + memmove(argv+i,argv+i+1,sizeof(char *)*(*argc - i -1)); + + *argc -= 1; + + /* return */ + + return TRUE; + } + } + + return FALSE; +} + +/* Function: strip_out_assigned_argument(argc,argv,tag) + * + * Descrip: This removes argument in tag from the commandline if there and + * returns the argument to it (in -tag arg - ie with a space). + * + * otherwise returns NULL + * + * + * Arg: argc [UNKN ] argc from main declaration (call as &argc) [int *] + * Arg: argv [UNKN ] argv from main declaration [char **] + * Arg: tag [READ ] -[string] argument to find [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 107 "commandline.dy" +char * strip_out_assigned_argument(int * argc,char ** argv,char * tag) +{ + register int i; + register char * ret; + + + for(i=0;i<*argc;i++) { + if( argv[i][0] != '-' ) + continue; + + /** ignore '-' by themselves **/ + + if( argv[i][1] == '\0') + continue; + + /** try to strcmp with tag **/ + + if( strcmp(tag,argv[i]+1) == 0 ) { + /* pick up next argument: if it has a '-' treat that as the argument. */ + + if( i+1 >= *argc ) { + warn("In processing command line [%s], tag [%s] expects an argument",argv[0],tag); + return NULL; /* give 'em nothing */ + } + + + /* assign return value */ + + ret = argv[i+1]; + + /* ok, now remove both tag and argument from the line */ + + memmove(argv+i,argv+i+2,sizeof(char *)*(*argc - i -2)); + + *argc -= 2; + + /* return */ + + return ret; + } + } + + return NULL; +} + + +/* Function: strip_out_integer_argument(argc,argv,tag,value) + * + * Descrip: This removes argument in tag from the commandline if there, and + * looks at the argument as whether it is an int or not. + * + * No tag - returns FALSE and leaves value alone + * Tag but no integer value - issues warning, returns FALSE + * tag but integer value - sets value, returns true + * + * + * Arg: argc [UNKN ] argc from main declaration (call as &argc) [int *] + * Arg: argv [UNKN ] argv from main declaration [char **] + * Arg: tag [READ ] -[string] argument to find [char *] + * Arg: value [WRITE] int pointer to write value to [int *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 166 "commandline.dy" +boolean strip_out_integer_argument(int * argc,char ** argv,char * tag,int * value) +{ + char * arg; + + if( (arg = strip_out_assigned_argument(argc,argv,tag)) == NULL ) + return FALSE; + + if( is_integer_string(arg,value) == FALSE ) { + warn("Argument [%s] to [%s] is not an integer. Not changing the value [%d]",arg,tag,value); + return FALSE; + } + + return TRUE; +} + +/* Function: strip_out_float_argument(argc,argv,tag,value) + * + * Descrip: This removes argument in tag from the commandline if there, and + * looks at the argument as whether it is a double or not. + * + * No tag - returns FALSE and leaves value alone + * Tag but no integer value - issues warning, returns FALSE + * tag but integer value - sets value, returns true + * + * + * Arg: argc [UNKN ] argc from main declaration (call as &argc) [int *] + * Arg: argv [UNKN ] argv from main declaration [char **] + * Arg: tag [READ ] -[string] argument to find [char *] + * Arg: value [WRITE] double pointer to write value to [double *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 194 "commandline.dy" +boolean strip_out_float_argument(int * argc,char ** argv,char * tag,double * value) +{ + char * arg; + + if( (arg = strip_out_assigned_argument(argc,argv,tag)) == NULL ) + return FALSE; + + if( is_double_string(arg,value) == FALSE ) { + warn("Argument [%s] to [%s] is not a double. Not changing the value [%f]",arg,tag,value); + return FALSE; + } + + return TRUE; +} + + + +# line 211 "commandline.c" + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/commandline.h b/Bio/Ext/Align/libs/commandline.h new file mode 100644 index 0000000..ae09c0d --- /dev/null +++ b/Bio/Ext/Align/libs/commandline.h @@ -0,0 +1,133 @@ +#ifndef DYNAMITEcommandlineHEADERFILE +#define DYNAMITEcommandlineHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" + + + + + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: strip_out_remaining_options_with_warning(argc,argv) + * + * Descrip: This removes all remaining options, issuing warnings + * through warn + * + * + * Arg: argc [UNKN ] Undocumented argument [int *] + * Arg: argv [UNKN ] Undocumented argument [char **] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_strip_out_remaining_options_with_warning(int * argc,char ** argv); +#define strip_out_remaining_options_with_warning bp_sw_strip_out_remaining_options_with_warning + + +/* Function: strip_out_boolean_argument(argc,argv,tag) + * + * Descrip: This removes argument in tag from the commandline if there and + * returns TRUE + * + * otherwise returns FALSE + * + * + * Arg: argc [UNKN ] argc from main declaration (call as &argc) [int *] + * Arg: argv [UNKN ] argv from main declaration [char **] + * Arg: tag [READ ] -[string] argument to find [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_strip_out_boolean_argument(int * argc,char ** argv,char * tag); +#define strip_out_boolean_argument bp_sw_strip_out_boolean_argument + + +/* Function: strip_out_assigned_argument(argc,argv,tag) + * + * Descrip: This removes argument in tag from the commandline if there and + * returns the argument to it (in -tag arg - ie with a space). + * + * otherwise returns NULL + * + * + * Arg: argc [UNKN ] argc from main declaration (call as &argc) [int *] + * Arg: argv [UNKN ] argv from main declaration [char **] + * Arg: tag [READ ] -[string] argument to find [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_strip_out_assigned_argument(int * argc,char ** argv,char * tag); +#define strip_out_assigned_argument bp_sw_strip_out_assigned_argument + + +/* Function: strip_out_integer_argument(argc,argv,tag,value) + * + * Descrip: This removes argument in tag from the commandline if there, and + * looks at the argument as whether it is an int or not. + * + * No tag - returns FALSE and leaves value alone + * Tag but no integer value - issues warning, returns FALSE + * tag but integer value - sets value, returns true + * + * + * Arg: argc [UNKN ] argc from main declaration (call as &argc) [int *] + * Arg: argv [UNKN ] argv from main declaration [char **] + * Arg: tag [READ ] -[string] argument to find [char *] + * Arg: value [WRITE] int pointer to write value to [int *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_strip_out_integer_argument(int * argc,char ** argv,char * tag,int * value); +#define strip_out_integer_argument bp_sw_strip_out_integer_argument + + +/* Function: strip_out_float_argument(argc,argv,tag,value) + * + * Descrip: This removes argument in tag from the commandline if there, and + * looks at the argument as whether it is a double or not. + * + * No tag - returns FALSE and leaves value alone + * Tag but no integer value - issues warning, returns FALSE + * tag but integer value - sets value, returns true + * + * + * Arg: argc [UNKN ] argc from main declaration (call as &argc) [int *] + * Arg: argv [UNKN ] argv from main declaration [char **] + * Arg: tag [READ ] -[string] argument to find [char *] + * Arg: value [WRITE] double pointer to write value to [double *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_strip_out_float_argument(int * argc,char ** argv,char * tag,double * value); +#define strip_out_float_argument bp_sw_strip_out_float_argument + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/complexconsensi.c b/Bio/Ext/Align/libs/complexconsensi.c new file mode 100644 index 0000000..0784672 --- /dev/null +++ b/Bio/Ext/Align/libs/complexconsensi.c @@ -0,0 +1,677 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "complexconsensi.h" + +/* Function: show_ComplexConsensi(cc,*ofp) + * + * Descrip: shows complexconsensi in vaguely human form + * + * + * Arg: cc [UNKN ] Undocumented argument [ComplexConsensi *] + * Arg: *ofp [UNKN ] Undocumented argument [FILE] + * + */ +# line 31 "complexconsensi.dy" +void show_ComplexConsensi(ComplexConsensi * cc,FILE *ofp) +{ + register int i; + + for(i=0;ilen;i++) + show_ComplexConsensusWord(cc->ccw[i],ofp); + +} + +/* Function: show_ComplexConsensusWord(ccw,ofp) + * + * Descrip: shows an individual ccword + * + * + * Arg: ccw [UNKN ] Undocumented argument [ComplexConsensusWord *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 45 "complexconsensi.dy" +void show_ComplexConsensusWord(ComplexConsensusWord * ccw,FILE * ofp) +{ + fprintf(ofp,"%s %4.4f %d\n",ccw->pattern,ccw->p,ccw->score); +} + + +/* Function: word_from_ComplexConsensi(word,cc) + * + * Descrip: Way of getting probabilities out of a consensus. + * If it is in the Consensus, then gets prob, otherwise 0. + * + * + * Arg: word [UNKN ] Undocumented argument [char *] + * Arg: cc [UNKN ] Undocumented argument [ComplexConsensi *] + * + * Return [UNKN ] Undocumented return value [Probability] + * + */ +# line 56 "complexconsensi.dy" +Probability word_from_ComplexConsensi(char * word,ComplexConsensi * cc) +{ + ComplexConsensusWord * ccw; + + ccw = best_ComplexConsensusWord(word,cc); + + if( ccw == NULL ) + return 0.0; + + return ccw->p; +} + +/* Function: score_from_ComplexConsensi(word,cc) + * + * Descrip: Way of getting scores out of a consensus. + * If it is in the Consensus, then gets score, otherwise NEGI. + * + * + * Arg: word [UNKN ] Undocumented argument [char *] + * Arg: cc [UNKN ] Undocumented argument [ComplexConsensi *] + * + * Return [UNKN ] Undocumented return value [Score] + * + */ +# line 73 "complexconsensi.dy" +Score score_from_ComplexConsensi(char * word,ComplexConsensi * cc) +{ + ComplexConsensusWord * ccw; + + ccw = best_ComplexConsensusWord(word,cc); + + if( ccw == NULL ) + return NEGI; + + return ccw->score; +} + +/* Function: best_ComplexConsensusWord(word,cc) + * + * Descrip: Finds the best (highest) match to this word + * + * + * Arg: word [UNKN ] Undocumented argument [char *] + * Arg: cc [UNKN ] Undocumented argument [ComplexConsensi *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensusWord *] + * + */ +# line 89 "complexconsensi.dy" +ComplexConsensusWord * best_ComplexConsensusWord(char * word,ComplexConsensi * cc) +{ + register int i; + + for(i=0;ilen;i++) { + if( word_matches_ComplexConsensusWord(word,cc->ccw[i]) == TRUE) + return cc->ccw[i]; + } + + return NULL; +} + + +/* Function: word_matches_ComplexConsensusWord(word,ccw) + * + * Descrip: Core of the matching system. Checks that word matches + * ComplexConsensusWord. This says that '-' matches anything. + * Issues a warning if hits a '\0' in word + * + * + * Arg: word [UNKN ] Undocumented argument [char *] + * Arg: ccw [UNKN ] Undocumented argument [ComplexConsensusWord *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 108 "complexconsensi.dy" +boolean word_matches_ComplexConsensusWord(char * word,ComplexConsensusWord * ccw) +{ + return strcmp_with_dashes(word,ccw->pattern); +} + +/* Function: strcmp_with_dashes(word,pattern) + * + * Descrip: The matching 'function' used by + * /word_matches_ComplexConsensusWord + * + * + * Arg: word [UNKN ] Undocumented argument [char *] + * Arg: pattern [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 118 "complexconsensi.dy" +boolean strcmp_with_dashes(char * word,char * pattern) +{ + char * runner; + char * base = word; + + for(runner = pattern;*runner && *word;word++,runner++) { + if( *runner == '-') { + continue; + } + + if( *runner != *word ) { + break; + } + + } + + if( *word == '\0' && *runner != '\0') { + warn("Tried to match a word [%s] which is shorter than the pattern [%s]",base,pattern); + return FALSE; + } + + if( *runner == '\0') { + /* end of pattern */ + return TRUE; + } + + return FALSE; +} + + + + + /************************/ + /* I/O */ + /************************/ + + +/* Function: read_ComplexConsensi_file(filename) + * + * Descrip: Reads a file containing the ComplexConsensi. + * Not every useful, as most times these consensi + * are in one file, with other things + * + * + * Arg: filename [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +# line 161 "complexconsensi.dy" +ComplexConsensi * read_ComplexConsensi_file(char * filename) +{ + FILE * ifp; + ComplexConsensi * out; + + ifp = openfile(filename,"r"); + if( ifp == NULL ) { + warn("Could not open file %s for ComplexConsensi",filename); + return NULL; + } + + out = read_ComplexConsensi(ifp); + + fclose(ifp); + + return out; +} + + +/* Function: read_ComplexConsensi(ifp) + * + * Descrip: Reads on ComplexConsensi from the FILE ifp. + * + * + * Arg: ifp [UNKN ] input filestream [FILE *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +# line 185 "complexconsensi.dy" +ComplexConsensi * read_ComplexConsensi(FILE * ifp) +{ + ComplexConsensi * out; + ComplexConsensusWord * temp; + char buffer[MAXLINE]; + + + out = ComplexConsensi_alloc_std(); + if( out == NULL ) + return NULL; + + + while( fgets(buffer,MAXLINE,ifp) != NULL ) { + if( buffer[0] == '#' ) + continue; + temp = read_ComplexConsensusWord_line(buffer); + if( temp != NULL ) + add_ComplexConsensi(out,temp); + } + + return out; +} + + +/* Function: read_ComplexConsensusWord_line(line) + * + * Descrip: Reads a single ccword from a line + * + * + * Arg: line [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensusWord *] + * + */ +# line 214 "complexconsensi.dy" +ComplexConsensusWord * read_ComplexConsensusWord_line(char * line) +{ + ComplexConsensusWord * out; + char * pattern; + char * score; + + + pattern = strtok(line,spacestr); + score = strtok(NULL,spacestr); + + if( pattern == NULL || score == NULL ) { + warn("Could not read a ComplexConsenusWord... ooops"); + return NULL; + } + + + out = ComplexConsensusWord_alloc(); + + if( out == NULL) + return NULL; + + out->pattern = stringalloc(pattern); + out->score = (double) atof(score); + + return out; +} + + +# line 270 "complexconsensi.c" +/* Function: hard_link_ComplexConsensusWord(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [ComplexConsensusWord *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensusWord *] + * + */ +ComplexConsensusWord * hard_link_ComplexConsensusWord(ComplexConsensusWord * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a ComplexConsensusWord object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: ComplexConsensusWord_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ComplexConsensusWord *] + * + */ +ComplexConsensusWord * ComplexConsensusWord_alloc(void) +{ + ComplexConsensusWord * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(ComplexConsensusWord *) ckalloc (sizeof(ComplexConsensusWord))) == NULL) { + warn("ComplexConsensusWord_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->pattern = NULL; + out->score = 0; + out->p = 0; + + + return out; +} + + +/* Function: free_ComplexConsensusWord(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ComplexConsensusWord *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensusWord *] + * + */ +ComplexConsensusWord * free_ComplexConsensusWord(ComplexConsensusWord * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a ComplexConsensusWord obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->pattern != NULL) + ckfree(obj->pattern); + + + ckfree(obj); + return NULL; +} + + +/* Function: swap_ComplexConsensi(list,i,j) + * + * Descrip: swap function: an internal for qsort_ComplexConsensi + * swaps two positions in the array + * + * + * Arg: list [UNKN ] List of structures to swap in [ComplexConsensusWord **] + * Arg: i [UNKN ] swap position [int] + * Arg: j [UNKN ] swap position [int] + * + */ +/* swap function for qsort function */ +void swap_ComplexConsensi(ComplexConsensusWord ** list,int i,int j) +{ + ComplexConsensusWord * temp; + temp=list[i]; + list[i]=list[j]; + list[j]=temp; +} + + +/* Function: qsort_ComplexConsensi(list,left,right,comp) + * + * Descrip: qsort - lifted from K&R + * sorts the array using quicksort + * Probably much better to call sort_ComplexConsensi which sorts from start to end + * + * + * Arg: list [UNKN ] List of structures to swap in [ComplexConsensusWord **] + * Arg: left [UNKN ] left position [int] + * Arg: right [UNKN ] right position [int] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void qsort_ComplexConsensi(ComplexConsensusWord ** list,int left,int right,int (*comp)(ComplexConsensusWord * ,ComplexConsensusWord * )) +{ + int i,last; + if( left >= right ) + return; + + + swap_ComplexConsensi(list,left,(left+right)/2); + last = left; + for ( i=left+1; i <= right;i++) { + if( (*comp)(list[i],list[left]) < 0) + swap_ComplexConsensi (list,++last,i); + } + swap_ComplexConsensi (list,left,last); + qsort_ComplexConsensi(list,left,last-1,comp); + qsort_ComplexConsensi(list,last+1,right,comp); +} + + +/* Function: sort_ComplexConsensi(obj,comp) + * + * Descrip: sorts from start to end using comp + * sorts the array using quicksort by calling qsort_ComplexConsensi + * + * + * Arg: obj [UNKN ] Object containing list [ComplexConsensi *] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void sort_ComplexConsensi(ComplexConsensi * obj,int (*comp)(ComplexConsensusWord *, ComplexConsensusWord *)) +{ + qsort_ComplexConsensi(obj->ccw,0,obj->len-1,comp); + return; +} + + +/* Function: expand_ComplexConsensi(obj,len) + * + * Descrip: Really an internal function for add_ComplexConsensi + * + * + * Arg: obj [UNKN ] Object which contains the list [ComplexConsensi *] + * Arg: len [UNKN ] Length to add one [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean expand_ComplexConsensi(ComplexConsensi * obj,int len) +{ + + + if( obj->maxlen > obj->len ) { + warn("expand_ComplexConsensi called with no need"); + return TRUE; + } + + + if( (obj->ccw = (ComplexConsensusWord ** ) ckrealloc (obj->ccw,sizeof(ComplexConsensusWord *)*len)) == NULL) { + warn("ckrealloc failed for expand_ComplexConsensi, returning FALSE"); + return FALSE; + } + obj->maxlen = len; + return TRUE; +} + + +/* Function: add_ComplexConsensi(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [ComplexConsensi *] + * Arg: add [OWNER] Object to add to the list [ComplexConsensusWord *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +/* will expand function if necessary */ +boolean add_ComplexConsensi(ComplexConsensi * obj,ComplexConsensusWord * add) +{ + if( obj->len >= obj->maxlen) { + if( expand_ComplexConsensi(obj,obj->len + ComplexConsensiLISTLENGTH) == FALSE) + return FALSE; + } + + + obj->ccw[obj->len++]=add; + return TRUE; +} + + +/* Function: flush_ComplexConsensi(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [ComplexConsensi *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int flush_ComplexConsensi(ComplexConsensi * obj) +{ + int i; + + + for(i=0;ilen;i++) { + if( obj->ccw[i] != NULL) { + free_ComplexConsensusWord(obj->ccw[i]); + obj->ccw[i] = NULL; + } + } /* end of for i over list length */ + + + obj->len = 0; + return i; +} + + +/* Function: ComplexConsensi_alloc_std(void) + * + * Descrip: Equivalent to ComplexConsensi_alloc_len(ComplexConsensiLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +ComplexConsensi * ComplexConsensi_alloc_std(void) +{ + return ComplexConsensi_alloc_len(ComplexConsensiLISTLENGTH); +} + + +/* Function: ComplexConsensi_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +ComplexConsensi * ComplexConsensi_alloc_len(int len) +{ + ComplexConsensi * out; /* out is exported at the end of function */ + + + /* Call alloc function: return NULL if NULL */ + /* Warning message alread in alloc function */ + if((out = ComplexConsensi_alloc()) == NULL) + return NULL; + + + /* Calling ckcalloc for list elements */ + if((out->ccw = (ComplexConsensusWord ** ) ckcalloc (len,sizeof(ComplexConsensusWord *))) == NULL) { + warn("Warning, ckcalloc failed in ComplexConsensi_alloc_len"); + return NULL; + } + out->len = 0; + out->maxlen = len; + + + return out; +} + + +/* Function: hard_link_ComplexConsensi(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [ComplexConsensi *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +ComplexConsensi * hard_link_ComplexConsensi(ComplexConsensi * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a ComplexConsensi object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: ComplexConsensi_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +ComplexConsensi * ComplexConsensi_alloc(void) +{ + ComplexConsensi * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(ComplexConsensi *) ckalloc (sizeof(ComplexConsensi))) == NULL) { + warn("ComplexConsensi_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->ccw = NULL; + out->len = out->maxlen = 0; + out->name = NULL; + + + return out; +} + + +/* Function: free_ComplexConsensi(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ComplexConsensi *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +ComplexConsensi * free_ComplexConsensi(ComplexConsensi * obj) +{ + int i; + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a ComplexConsensi obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->ccw != NULL) { + for(i=0;ilen;i++) { + if( obj->ccw[i] != NULL) + free_ComplexConsensusWord(obj->ccw[i]); + } + ckfree(obj->ccw); + } + if( obj->name != NULL) + ckfree(obj->name); + + + ckfree(obj); + return NULL; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/complexconsensi.h b/Bio/Ext/Align/libs/complexconsensi.h new file mode 100644 index 0000000..97230a6 --- /dev/null +++ b/Bio/Ext/Align/libs/complexconsensi.h @@ -0,0 +1,327 @@ +#ifndef DYNAMITEcomplexconsensiHEADERFILE +#define DYNAMITEcomplexconsensiHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" +#include "probability.h" + +#define ComplexConsensiLISTLENGTH 64 + +struct bp_sw_ComplexConsensusWord { + int dynamite_hard_link; + char * pattern; + Score score; + Probability p; + } ; +/* ComplexConsensusWord defined */ +#ifndef DYNAMITE_DEFINED_ComplexConsensusWord +typedef struct bp_sw_ComplexConsensusWord bp_sw_ComplexConsensusWord; +#define ComplexConsensusWord bp_sw_ComplexConsensusWord +#define DYNAMITE_DEFINED_ComplexConsensusWord +#endif + + +struct bp_sw_ComplexConsensi { + int dynamite_hard_link; + ComplexConsensusWord ** ccw; + int len;/* len for above ccw */ + int maxlen; /* maxlen for above ccw */ + char * name; + } ; +/* ComplexConsensi defined */ +#ifndef DYNAMITE_DEFINED_ComplexConsensi +typedef struct bp_sw_ComplexConsensi bp_sw_ComplexConsensi; +#define ComplexConsensi bp_sw_ComplexConsensi +#define DYNAMITE_DEFINED_ComplexConsensi +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: show_ComplexConsensi(cc,*ofp) + * + * Descrip: shows complexconsensi in vaguely human form + * + * + * Arg: cc [UNKN ] Undocumented argument [ComplexConsensi *] + * Arg: *ofp [UNKN ] Undocumented argument [FILE] + * + */ +void bp_sw_show_ComplexConsensi(ComplexConsensi * cc,FILE *ofp); +#define show_ComplexConsensi bp_sw_show_ComplexConsensi + + +/* Function: word_from_ComplexConsensi(word,cc) + * + * Descrip: Way of getting probabilities out of a consensus. + * If it is in the Consensus, then gets prob, otherwise 0. + * + * + * Arg: word [UNKN ] Undocumented argument [char *] + * Arg: cc [UNKN ] Undocumented argument [ComplexConsensi *] + * + * Return [UNKN ] Undocumented return value [Probability] + * + */ +Probability bp_sw_word_from_ComplexConsensi(char * word,ComplexConsensi * cc); +#define word_from_ComplexConsensi bp_sw_word_from_ComplexConsensi + + +/* Function: score_from_ComplexConsensi(word,cc) + * + * Descrip: Way of getting scores out of a consensus. + * If it is in the Consensus, then gets score, otherwise NEGI. + * + * + * Arg: word [UNKN ] Undocumented argument [char *] + * Arg: cc [UNKN ] Undocumented argument [ComplexConsensi *] + * + * Return [UNKN ] Undocumented return value [Score] + * + */ +Score bp_sw_score_from_ComplexConsensi(char * word,ComplexConsensi * cc); +#define score_from_ComplexConsensi bp_sw_score_from_ComplexConsensi + + +/* Function: best_ComplexConsensusWord(word,cc) + * + * Descrip: Finds the best (highest) match to this word + * + * + * Arg: word [UNKN ] Undocumented argument [char *] + * Arg: cc [UNKN ] Undocumented argument [ComplexConsensi *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensusWord *] + * + */ +ComplexConsensusWord * bp_sw_best_ComplexConsensusWord(char * word,ComplexConsensi * cc); +#define best_ComplexConsensusWord bp_sw_best_ComplexConsensusWord + + +/* Function: word_matches_ComplexConsensusWord(word,ccw) + * + * Descrip: Core of the matching system. Checks that word matches + * ComplexConsensusWord. This says that '-' matches anything. + * Issues a warning if hits a '\0' in word + * + * + * Arg: word [UNKN ] Undocumented argument [char *] + * Arg: ccw [UNKN ] Undocumented argument [ComplexConsensusWord *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_word_matches_ComplexConsensusWord(char * word,ComplexConsensusWord * ccw); +#define word_matches_ComplexConsensusWord bp_sw_word_matches_ComplexConsensusWord + + +/* Function: read_ComplexConsensi_file(filename) + * + * Descrip: Reads a file containing the ComplexConsensi. + * Not every useful, as most times these consensi + * are in one file, with other things + * + * + * Arg: filename [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +ComplexConsensi * bp_sw_read_ComplexConsensi_file(char * filename); +#define read_ComplexConsensi_file bp_sw_read_ComplexConsensi_file + + +/* Function: read_ComplexConsensi(ifp) + * + * Descrip: Reads on ComplexConsensi from the FILE ifp. + * + * + * Arg: ifp [UNKN ] input filestream [FILE *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +ComplexConsensi * bp_sw_read_ComplexConsensi(FILE * ifp); +#define read_ComplexConsensi bp_sw_read_ComplexConsensi + + +/* Function: hard_link_ComplexConsensusWord(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [ComplexConsensusWord *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensusWord *] + * + */ +ComplexConsensusWord * bp_sw_hard_link_ComplexConsensusWord(ComplexConsensusWord * obj); +#define hard_link_ComplexConsensusWord bp_sw_hard_link_ComplexConsensusWord + + +/* Function: ComplexConsensusWord_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ComplexConsensusWord *] + * + */ +ComplexConsensusWord * bp_sw_ComplexConsensusWord_alloc(void); +#define ComplexConsensusWord_alloc bp_sw_ComplexConsensusWord_alloc + + +/* Function: free_ComplexConsensusWord(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ComplexConsensusWord *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensusWord *] + * + */ +ComplexConsensusWord * bp_sw_free_ComplexConsensusWord(ComplexConsensusWord * obj); +#define free_ComplexConsensusWord bp_sw_free_ComplexConsensusWord + + +/* Function: add_ComplexConsensi(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [ComplexConsensi *] + * Arg: add [OWNER] Object to add to the list [ComplexConsensusWord *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_ComplexConsensi(ComplexConsensi * obj,ComplexConsensusWord * add); +#define add_ComplexConsensi bp_sw_add_ComplexConsensi + + +/* Function: flush_ComplexConsensi(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [ComplexConsensi *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_flush_ComplexConsensi(ComplexConsensi * obj); +#define flush_ComplexConsensi bp_sw_flush_ComplexConsensi + + +/* Function: ComplexConsensi_alloc_std(void) + * + * Descrip: Equivalent to ComplexConsensi_alloc_len(ComplexConsensiLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +ComplexConsensi * bp_sw_ComplexConsensi_alloc_std(void); +#define ComplexConsensi_alloc_std bp_sw_ComplexConsensi_alloc_std + + +/* Function: ComplexConsensi_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +ComplexConsensi * bp_sw_ComplexConsensi_alloc_len(int len); +#define ComplexConsensi_alloc_len bp_sw_ComplexConsensi_alloc_len + + +/* Function: hard_link_ComplexConsensi(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [ComplexConsensi *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +ComplexConsensi * bp_sw_hard_link_ComplexConsensi(ComplexConsensi * obj); +#define hard_link_ComplexConsensi bp_sw_hard_link_ComplexConsensi + + +/* Function: ComplexConsensi_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +ComplexConsensi * bp_sw_ComplexConsensi_alloc(void); +#define ComplexConsensi_alloc bp_sw_ComplexConsensi_alloc + + +/* Function: free_ComplexConsensi(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ComplexConsensi *] + * + * Return [UNKN ] Undocumented return value [ComplexConsensi *] + * + */ +ComplexConsensi * bp_sw_free_ComplexConsensi(ComplexConsensi * obj); +#define free_ComplexConsensi bp_sw_free_ComplexConsensi + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +void bp_sw_show_ComplexConsensusWord(ComplexConsensusWord * ccw,FILE * ofp); +#define show_ComplexConsensusWord bp_sw_show_ComplexConsensusWord +boolean bp_sw_strcmp_with_dashes(char * word,char * pattern); +#define strcmp_with_dashes bp_sw_strcmp_with_dashes +ComplexConsensusWord * bp_sw_read_ComplexConsensusWord_line(char * line); +#define read_ComplexConsensusWord_line bp_sw_read_ComplexConsensusWord_line +void bp_sw_swap_ComplexConsensi(ComplexConsensusWord ** list,int i,int j) ; +#define swap_ComplexConsensi bp_sw_swap_ComplexConsensi +void bp_sw_qsort_ComplexConsensi(ComplexConsensusWord ** list,int left,int right,int (*comp)(ComplexConsensusWord * ,ComplexConsensusWord * )); +#define qsort_ComplexConsensi bp_sw_qsort_ComplexConsensi +void bp_sw_sort_ComplexConsensi(ComplexConsensi * obj,int (*comp)(ComplexConsensusWord *, ComplexConsensusWord *)); +#define sort_ComplexConsensi bp_sw_sort_ComplexConsensi +boolean bp_sw_expand_ComplexConsensi(ComplexConsensi * obj,int len); +#define expand_ComplexConsensi bp_sw_expand_ComplexConsensi + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/complexevalset.c b/Bio/Ext/Align/libs/complexevalset.c new file mode 100644 index 0000000..2b2fbf7 --- /dev/null +++ b/Bio/Ext/Align/libs/complexevalset.c @@ -0,0 +1,437 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "complexevalset.h" + + +/* Function: default_genomic_ComplexSequenceEvalSet(void) + * + * Descrip: Makes a reasonably sensible genomic sequence + * eval set. Has base and codon numbers (what + * every good genomic sequence should do) and then + * /stupid_5SS and /stupid_3SS. Finally the repeat/EST + * regions modelled with the /flat_zero + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +# line 58 "complexevalset.dy" +ComplexSequenceEvalSet * default_genomic_ComplexSequenceEvalSet(void) +{ + ComplexSequenceEvalSet * out; + + + out = ComplexSequenceEvalSet_alloc_len(11); + + add_ComplexSequenceEvalSet(out,base_number_ComplexSequenceEval()); + add_ComplexSequenceEvalSet(out,codon_number_ComplexSequenceEval()); + add_ComplexSequenceEvalSet(out,stupid_5SS()); + add_ComplexSequenceEvalSet(out,stupid_3SS()); + add_ComplexSequenceEvalSet(out,flat_zero()); + add_ComplexSequenceEvalSet(out,flat_zero()); + + + out->type = SEQUENCE_GENOMIC; + + prepare_ComplexSequenceEvalSet(out); + + return out; +} + + +/* Function: flat_zero(void) + * + * Descrip: Makes a ComplexSequenceEval that puts 0 everywhere + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +# line 85 "complexevalset.dy" +ComplexSequenceEval * flat_zero(void) +{ + ComplexSequenceEval * out; + + out= ComplexSequenceEval_alloc(); + + out->left_window = 0; + out->right_window = 0; + out->outside_score = NEGI; + out->eval_func = flat_zero_eval; + + return out; +} + +/* Function: flat_zero_eval(type,*data,seq) + * + * Descrip: Used by /flat_zero as function actually called + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * Arg: *data [UNKN ] Undocumented argument [void] + * Arg: seq [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 104 "complexevalset.dy" +int flat_zero_eval(int type,void *data,char * seq) +{ + return 0; +} + + +/* Function: stupid_5SS(void) + * + * Descrip: Reasonably stupid 5'SS, of 0 at GT's + * and NEGI elsewhere. Pretends to have a longer + * footprint than it needs to satisify the lookbacks + * of more proper genomic models + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +# line 117 "complexevalset.dy" +ComplexSequenceEval * stupid_5SS(void) +{ + ComplexSequenceEval * out; + + out= ComplexSequenceEval_alloc(); + + out->left_window = 3; + out->right_window = 7; + out->left_lookback = 8; + out->outside_score = NEGI; + out->eval_func = stupid_5SS_eval; + + return out; +} + +/* Function: stupid_5SS_eval(type,*data,seq) + * + * Descrip: Function which actually does the evaluation for + * 5'SS + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * Arg: *data [UNKN ] Undocumented argument [void] + * Arg: seq [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 138 "complexevalset.dy" +int stupid_5SS_eval(int type,void *data,char * seq) +{ + if( *(seq) == 'G' && *(seq+1) == 'T' ) + return 0; + else return NEGI; +} + + +/* Function: stupid_3SS(void) + * + * Descrip: Reasonably stupid 3'SS, of 0 at AG's + * and NEGI elsewhere. Pretends to have a longer + * footprint than it needs to satisify the lookbacks + * of more proper genomic models + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +# line 153 "complexevalset.dy" +ComplexSequenceEval * stupid_3SS(void) +{ + ComplexSequenceEval * out; + + out= ComplexSequenceEval_alloc(); + + out->left_window = 3; + out->right_window = 3; + out->left_lookback = 5; + out->outside_score = NEGI; + out->eval_func = stupid_3SS_eval; + + return out; +} + + +/* Function: stupid_3SS_eval(type,*data,seq) + * + * Descrip: Function which actually does the evaluation for + * 3'SS + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * Arg: *data [UNKN ] Undocumented argument [void] + * Arg: seq [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 175 "complexevalset.dy" +int stupid_3SS_eval(int type,void *data,char * seq) +{ + if( *(seq-1) == 'A' && *(seq) == 'G' ) + return 0; + else return NEGI; +} + + + + /********************************/ + /* cDNA and base stuff */ + /********************************/ + +/* Function: default_DNA_ComplexSequenceEvalSet(void) + * + * Descrip: Makes a very sensible DNA sequence + * eval set. You shouldn't need your own + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +# line 193 "complexevalset.dy" +ComplexSequenceEvalSet * default_DNA_ComplexSequenceEvalSet(void) +{ + ComplexSequenceEvalSet * out; + + + out = ComplexSequenceEvalSet_alloc_len(1); + + add_ComplexSequenceEvalSet(out,base_number_ComplexSequenceEval()); + out->type = SEQUENCE_DNA; + + prepare_ComplexSequenceEvalSet(out); + + return out; +} + + +/* Function: default_cDNA_ComplexSequenceEvalSet(void) + * + * Descrip: Makes a very sensible cDNA sequence + * eval set. You shouldn't need your own + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +# line 214 "complexevalset.dy" +ComplexSequenceEvalSet * default_cDNA_ComplexSequenceEvalSet(void) +{ + ComplexSequenceEvalSet * out; + + + out = ComplexSequenceEvalSet_alloc_len(2); + + add_ComplexSequenceEvalSet(out,base_number_ComplexSequenceEval()); + add_ComplexSequenceEvalSet(out,codon_number_ComplexSequenceEval()); + out->type = SEQUENCE_CDNA; + + prepare_ComplexSequenceEvalSet(out); + + return out; +} + + + + +/* Function: codon_number_ComplexSequenceEval(void) + * + * Descrip: ComplexSequenceEval that puts a codon + * number in there (0-125 inc, 125 = impossible codon). + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +# line 238 "complexevalset.dy" +ComplexSequenceEval * codon_number_ComplexSequenceEval(void) +{ + ComplexSequenceEval * out; + + + out = ComplexSequenceEval_alloc(); + + if (out == NULL ) { + return NULL; + } + + out->left_window = 2; + out->right_window = 0; + out->outside_score = 125; + out->eval_func = codon_number_func; + + + return out; +} + + +/* Function: codon_number_func(type,data,seq) + * + * Descrip: Function which actually does the codon evaluation + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * Arg: data [UNKN ] Undocumented argument [void *] + * Arg: seq [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 264 "complexevalset.dy" +int codon_number_func(int type,void * data,char * seq) +{ + return codon_from_seq(seq-2); +} + + + + +/* Function: base_number_ComplexSequenceEval(void) + * + * Descrip: ComplexSequenceEval that puts a base + * number (0-5 inc) + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +# line 277 "complexevalset.dy" +ComplexSequenceEval * base_number_ComplexSequenceEval(void) +{ + ComplexSequenceEval * out; + + + out = ComplexSequenceEval_alloc(); + + if (out == NULL ) { + return NULL; + } + + out->left_window = out->right_window = 0; + out->eval_func = base_number_func; + + return out; +} + + +/* Function: base_number_func(type,data,seq) + * + * Descrip: Function which actually does the evaluation bases + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * Arg: data [UNKN ] Undocumented argument [void *] + * Arg: seq [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 300 "complexevalset.dy" +int base_number_func(int type,void * data,char * seq) +{ + return base_from_char(*seq); +} + + + + /***************************/ + /* amino acid stuff */ + /***************************/ + + +/* Function: default_aminoacid_ComplexSequenceEvalSet(void) + * + * Descrip: Makes a very sensible protein sequence + * eval set. You shouldn't need your own + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +# line 317 "complexevalset.dy" +ComplexSequenceEvalSet * default_aminoacid_ComplexSequenceEvalSet(void) +{ + ComplexSequenceEvalSet * out; + + + out = ComplexSequenceEvalSet_alloc_len(1); + + add_ComplexSequenceEvalSet(out,aminoacid_number_ComplexSequenceEval()); + + out->type = SEQUENCE_PROTEIN; + + prepare_ComplexSequenceEvalSet(out); + + return out; +} + + + +/* Function: aminoacid_number_ComplexSequenceEval(void) + * + * Descrip: ComplexSequenceEval that puts a amino acid + * number in there (0-26) + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +# line 340 "complexevalset.dy" +ComplexSequenceEval * aminoacid_number_ComplexSequenceEval(void) +{ + ComplexSequenceEval * out; + + + out = ComplexSequenceEval_alloc(); + + if (out == NULL ) { + return NULL; + } + + out->left_window = out->right_window = 0; + out->eval_func = aminoacid_number_func; + + return out; +} + + +/* Function: aminoacid_number_func(type,data,seq) + * + * Descrip: Function which actually does the evaluation for aminoacids + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * Arg: data [UNKN ] Undocumented argument [void *] + * Arg: seq [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 363 "complexevalset.dy" +int aminoacid_number_func(int type,void * data,char * seq) +{ + return (toupper(*seq)-'A'); +} + +# line 400 "complexevalset.c" + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/complexevalset.h b/Bio/Ext/Align/libs/complexevalset.h new file mode 100644 index 0000000..584fdd3 --- /dev/null +++ b/Bio/Ext/Align/libs/complexevalset.h @@ -0,0 +1,220 @@ +#ifndef DYNAMITEcomplexevalsetHEADERFILE +#define DYNAMITEcomplexevalsetHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "complexsequence.h" + + + + +/*** ok, some types to works with ***/ + +#define AMINOACID CSEQ_PROTEIN_AMINOACID +#define CSEQ_PROTEIN_AMINOACID(cseq,index) (cseq->data[index]) + + +/*** for genomic ***/ + +#define CSEQ_G_LEN 6 + +#define CSEQ_GENOMIC_BASE(cseq,index) (cseq->data[(index)*CSEQ_G_LEN]) +#define CSEQ_GENOMIC_CODON(cseq,index) (cseq->data[(index)*CSEQ_G_LEN +1]) +#define CSEQ_GENOMIC_5SS(cseq,index) (cseq->data[(index)*CSEQ_G_LEN +2]) +#define CSEQ_GENOMIC_3SS(cseq,index) (cseq->data[(index)*CSEQ_G_LEN +3]) +#define CSEQ_GENOMIC_REPEAT(cseq,index) (cseq->data[(index)*CSEQ_G_LEN +4]) +#define CSEQ_GENOMIC_CDSPOT(cseq,index) (cseq->data[(index)*CSEQ_G_LEN +5]) + + +/*** for cDNA ***/ + +#define CSEQ_C_LEN 2 + +#define CSEQ_CDNA_BASE(cseq,index) (cseq->data[index*CSEQ_C_LEN]) +#define CSEQ_CDNA_CODON(cseq,index) (cseq->data[index*CSEQ_C_LEN +1]) + +#define CSEQ_D_LEN 1 + +#define CSEQ_DNA_BASE(cseq,index) (cseq->data[index]) + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: default_genomic_ComplexSequenceEvalSet(void) + * + * Descrip: Makes a reasonably sensible genomic sequence + * eval set. Has base and codon numbers (what + * every good genomic sequence should do) and then + * /stupid_5SS and /stupid_3SS. Finally the repeat/EST + * regions modelled with the /flat_zero + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * bp_sw_default_genomic_ComplexSequenceEvalSet(void); +#define default_genomic_ComplexSequenceEvalSet bp_sw_default_genomic_ComplexSequenceEvalSet + + +/* Function: flat_zero(void) + * + * Descrip: Makes a ComplexSequenceEval that puts 0 everywhere + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +ComplexSequenceEval * bp_sw_flat_zero(void); +#define flat_zero bp_sw_flat_zero + + +/* Function: stupid_5SS(void) + * + * Descrip: Reasonably stupid 5'SS, of 0 at GT's + * and NEGI elsewhere. Pretends to have a longer + * footprint than it needs to satisify the lookbacks + * of more proper genomic models + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +ComplexSequenceEval * bp_sw_stupid_5SS(void); +#define stupid_5SS bp_sw_stupid_5SS + + +/* Function: stupid_3SS(void) + * + * Descrip: Reasonably stupid 3'SS, of 0 at AG's + * and NEGI elsewhere. Pretends to have a longer + * footprint than it needs to satisify the lookbacks + * of more proper genomic models + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +ComplexSequenceEval * bp_sw_stupid_3SS(void); +#define stupid_3SS bp_sw_stupid_3SS + + +/* Function: default_DNA_ComplexSequenceEvalSet(void) + * + * Descrip: Makes a very sensible DNA sequence + * eval set. You shouldn't need your own + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * bp_sw_default_DNA_ComplexSequenceEvalSet(void); +#define default_DNA_ComplexSequenceEvalSet bp_sw_default_DNA_ComplexSequenceEvalSet + + +/* Function: default_cDNA_ComplexSequenceEvalSet(void) + * + * Descrip: Makes a very sensible cDNA sequence + * eval set. You shouldn't need your own + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * bp_sw_default_cDNA_ComplexSequenceEvalSet(void); +#define default_cDNA_ComplexSequenceEvalSet bp_sw_default_cDNA_ComplexSequenceEvalSet + + +/* Function: codon_number_ComplexSequenceEval(void) + * + * Descrip: ComplexSequenceEval that puts a codon + * number in there (0-125 inc, 125 = impossible codon). + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +ComplexSequenceEval * bp_sw_codon_number_ComplexSequenceEval(void); +#define codon_number_ComplexSequenceEval bp_sw_codon_number_ComplexSequenceEval + + +/* Function: base_number_ComplexSequenceEval(void) + * + * Descrip: ComplexSequenceEval that puts a base + * number (0-5 inc) + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +ComplexSequenceEval * bp_sw_base_number_ComplexSequenceEval(void); +#define base_number_ComplexSequenceEval bp_sw_base_number_ComplexSequenceEval + + +/* Function: default_aminoacid_ComplexSequenceEvalSet(void) + * + * Descrip: Makes a very sensible protein sequence + * eval set. You shouldn't need your own + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * bp_sw_default_aminoacid_ComplexSequenceEvalSet(void); +#define default_aminoacid_ComplexSequenceEvalSet bp_sw_default_aminoacid_ComplexSequenceEvalSet + + +/* Function: aminoacid_number_ComplexSequenceEval(void) + * + * Descrip: ComplexSequenceEval that puts a amino acid + * number in there (0-26) + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +ComplexSequenceEval * bp_sw_aminoacid_number_ComplexSequenceEval(void); +#define aminoacid_number_ComplexSequenceEval bp_sw_aminoacid_number_ComplexSequenceEval + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +int bp_sw_flat_zero_eval(int type,void *data,char * seq); +#define flat_zero_eval bp_sw_flat_zero_eval +int bp_sw_stupid_5SS_eval(int type,void *data,char * seq); +#define stupid_5SS_eval bp_sw_stupid_5SS_eval +int bp_sw_stupid_3SS_eval(int type,void *data,char * seq); +#define stupid_3SS_eval bp_sw_stupid_3SS_eval +int bp_sw_codon_number_func(int type,void * data,char * seq); +#define codon_number_func bp_sw_codon_number_func +int bp_sw_base_number_func(int type,void * data,char * seq); +#define base_number_func bp_sw_base_number_func +int bp_sw_aminoacid_number_func(int type,void * data,char * seq); +#define aminoacid_number_func bp_sw_aminoacid_number_func + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/complexsequence.c b/Bio/Ext/Align/libs/complexsequence.c new file mode 100644 index 0000000..aa8a56b --- /dev/null +++ b/Bio/Ext/Align/libs/complexsequence.c @@ -0,0 +1,1004 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "complexsequence.h" + + + +/* Function: new_ComplexSequence(seq,cses) + * + * Descrip: The basic way to make a ComplexSequence. Requires that + * you have already built a ComplexSequenceEvalSet (such as + * /default_aminoacid_ComplexSequenceEvalSet). + * + * + * + * Arg: seq [UNKN ] Sequence that the ComplexSequence is based on [Sequence *] + * Arg: cses [UNKN ] EvalSet that defines the functions used on the sequence [ComplexSequenceEvalSet *] + * + * Return [UNKN ] Undocumented return value [ComplexSequence *] + * + */ +# line 101 "complexsequence.dy" +ComplexSequence * new_ComplexSequence(Sequence * seq,ComplexSequenceEvalSet * cses) +{ + ComplexSequence * out; + register int i; + register int j; + register int * poi; + + + if( can_evaluate_this_Sequence(cses,seq) == FALSE ) { + warn("Could not evaluate these sequences Sequence type [%d][%s] Evaluation type [%d][%s]",seq->type,Sequence_type_to_string(seq->type),cses->type,Sequence_type_to_string(cses->type)); + return NULL; + } + + if( cses->has_been_prepared == FALSE) { + warn("Trappable error: you have not prepared this ComplexSequenceEvalSet before using. Please do so in the future"); + prepare_ComplexSequenceEvalSet(cses); + } + + + out = ComplexSequence_alloc(); + if( out == NULL ) + return NULL; + + out->datastore = (int *) ckcalloc((seq->len+cses->left_lookback)*cses->len,sizeof(int)); + + if( out->datastore == NULL ) { + warn("Could not allocate data pointer of length %d for ComplexSequence",seq->len*cses->len); + free_ComplexSequence(out); + return NULL; + } + + out->data = out->datastore + (cses->left_lookback * cses->len); + + for(i=0;ileft_lookback;i++) { + for(j=0;jlen;j++) + out->datastore[(i*cses->len)+j] = cses->cse[j]->outside_score; + } + + out->depth = cses->len; + + for(i=0,poi = out->data;ilen;i++,poi = next_ComplexSequence_data(out,poi)) { + for(j=0;jlen;j++) { + /* fprintf(stderr,"Calling with i at %d vs %d\n",i,cses->cse[j]->left_window); */ + if( i < cses->cse[j]->left_window || (i + cses->cse[j]->right_window) >= seq->len) + poi[j] = cses->cse[j]->outside_score; + else poi[j] = (*cses->cse[j]->eval_func)(cses->cse[j]->data_type,cses->cse[j]->data,seq->seq+i); + } + } + + out->seq = hard_link_Sequence(seq); + + out->length = seq->len; + + return out; + +} + +/* Function: show_ComplexSequence(cs,ofp) + * + * Descrip: shows complex sequence in a vaguely + * human form + * + * + * Arg: cs [UNKN ] Undocumented argument [ComplexSequence *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 163 "complexsequence.dy" +void show_ComplexSequence(ComplexSequence * cs,FILE * ofp) +{ + register int i; + + fprintf(ofp,"ComplexSequence %s\n",cs->seq->name); + for(i=0;ilength;i++) { + show_one_position_ComplexSequence(cs,i,ofp); + } + +} + +/* Function: show_one_position_ComplexSequence(cs,pos,ofp) + * + * Descrip: shows one position of a complex sequence + * + * + * Arg: cs [UNKN ] Undocumented argument [ComplexSequence *] + * Arg: pos [UNKN ] Undocumented argument [int] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 179 "complexsequence.dy" +void show_one_position_ComplexSequence(ComplexSequence * cs,int pos,FILE * ofp) +{ + fprintf(ofp,"%4d %c [",pos,cs->seq->seq[pos]); + show_Score_array(&(ComplexSequence_data(cs,pos,0)),cs->depth,ofp); + fprintf(ofp,"]\n"); +} + + + /********************************/ + /* Making complex sequences */ + /********************************/ + +/* Function: prepare_ComplexSequenceEvalSet(cses) + * + * Descrip: Calculates all the necessary offset for an EvalSet. + * This is necessary before using it in a /new_ComplexSequence + * place + * + * + * Arg: cses [UNKN ] Undocumented argument [ComplexSequenceEvalSet *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 197 "complexsequence.dy" +boolean prepare_ComplexSequenceEvalSet(ComplexSequenceEvalSet * cses) +{ + register int i; + int left_window = 0; + int right_window = 0; + int left_lookback = 0; + + for(i=0;ilen;i++) { + if( cses->cse[i]->right_window > right_window ) + right_window = cses->cse[i]->right_window; + if( cses->cse[i]->left_window > left_window ) + left_window = cses->cse[i]->left_window; + if( cses->cse[i]->left_lookback > left_lookback ) + left_lookback = cses->cse[i]->left_lookback; + } + + cses->right_window = right_window; + cses->left_window = left_window; + cses->left_lookback = left_lookback; + cses->has_been_prepared = TRUE; + + return TRUE; +} + + +/* Function: can_evaluate_this_Sequence(cses,s) + * + * Descrip: Checks that this ComplexSequenceEvalSet can be used with + * this Sequence. This is probably going to go defunct. + * + * + * + * Arg: cses [UNKN ] Undocumented argument [ComplexSequenceEvalSet *] + * Arg: s [UNKN ] Undocumented argument [Sequence *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 228 "complexsequence.dy" +boolean can_evaluate_this_Sequence(ComplexSequenceEvalSet * cses,Sequence * s) +{ + return can_evaluate_this_type(cses,s->type); +} + + +/* Function: can_evaluate_this_type(cses,type) + * + * Descrip: Pretty much an internal for /can_evaluate_this_Sequence + * + * + * Arg: cses [UNKN ] Undocumented argument [ComplexSequenceEvalSet *] + * Arg: type [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 239 "complexsequence.dy" +boolean can_evaluate_this_type(ComplexSequenceEvalSet * cses,int type) +{ + switch (type) { + case SEQUENCE_UNKNOWN : return FALSE; + case SEQUENCE_DNA : + if( cses->type == SEQUENCE_DNA || cses->type == SEQUENCE_CDNA || cses->type == SEQUENCE_EST || cses->type == SEQUENCE_GENOMIC) + return TRUE; + else return FALSE; + default : + if( cses->type == type) + return TRUE; + else return FALSE; + } +} + + + + +# line 200 "complexsequence.c" +/* Function: hard_link_ComplexSequenceEval(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [ComplexSequenceEval *] + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +ComplexSequenceEval * hard_link_ComplexSequenceEval(ComplexSequenceEval * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a ComplexSequenceEval object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: ComplexSequenceEval_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +ComplexSequenceEval * ComplexSequenceEval_alloc(void) +{ + ComplexSequenceEval * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(ComplexSequenceEval *) ckalloc (sizeof(ComplexSequenceEval))) == NULL) { + warn("ComplexSequenceEval_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->type = 0; + out->sequence_type = 0; + out->left_window = 0; + out->right_window = 0; + out->left_lookback = 0; + out->outside_score = 0; + out->data_type = 0; + out->eval_func = NULL; + + + return out; +} + + +/* Function: free_ComplexSequenceEval(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ComplexSequenceEval *] + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +ComplexSequenceEval * free_ComplexSequenceEval(ComplexSequenceEval * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a ComplexSequenceEval obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + /* obj->data is linked in */ + /* obj->eval_func is a function pointer */ + + + ckfree(obj); + return NULL; +} + + +/* Function: swap_ComplexSequenceEvalSet(list,i,j) + * + * Descrip: swap function: an internal for qsort_ComplexSequenceEvalSet + * swaps two positions in the array + * + * + * Arg: list [UNKN ] List of structures to swap in [ComplexSequenceEval **] + * Arg: i [UNKN ] swap position [int] + * Arg: j [UNKN ] swap position [int] + * + */ +/* swap function for qsort function */ +void swap_ComplexSequenceEvalSet(ComplexSequenceEval ** list,int i,int j) +{ + ComplexSequenceEval * temp; + temp=list[i]; + list[i]=list[j]; + list[j]=temp; +} + + +/* Function: qsort_ComplexSequenceEvalSet(list,left,right,comp) + * + * Descrip: qsort - lifted from K&R + * sorts the array using quicksort + * Probably much better to call sort_ComplexSequenceEvalSet which sorts from start to end + * + * + * Arg: list [UNKN ] List of structures to swap in [ComplexSequenceEval **] + * Arg: left [UNKN ] left position [int] + * Arg: right [UNKN ] right position [int] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void qsort_ComplexSequenceEvalSet(ComplexSequenceEval ** list,int left,int right,int (*comp)(ComplexSequenceEval * ,ComplexSequenceEval * )) +{ + int i,last; + if( left >= right ) + return; + + + swap_ComplexSequenceEvalSet(list,left,(left+right)/2); + last = left; + for ( i=left+1; i <= right;i++) { + if( (*comp)(list[i],list[left]) < 0) + swap_ComplexSequenceEvalSet (list,++last,i); + } + swap_ComplexSequenceEvalSet (list,left,last); + qsort_ComplexSequenceEvalSet(list,left,last-1,comp); + qsort_ComplexSequenceEvalSet(list,last+1,right,comp); +} + + +/* Function: sort_ComplexSequenceEvalSet(obj,comp) + * + * Descrip: sorts from start to end using comp + * sorts the array using quicksort by calling qsort_ComplexSequenceEvalSet + * + * + * Arg: obj [UNKN ] Object containing list [ComplexSequenceEvalSet *] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void sort_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,int (*comp)(ComplexSequenceEval *, ComplexSequenceEval *)) +{ + qsort_ComplexSequenceEvalSet(obj->cse,0,obj->len-1,comp); + return; +} + + +/* Function: expand_ComplexSequenceEvalSet(obj,len) + * + * Descrip: Really an internal function for add_ComplexSequenceEvalSet + * + * + * Arg: obj [UNKN ] Object which contains the list [ComplexSequenceEvalSet *] + * Arg: len [UNKN ] Length to add one [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean expand_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,int len) +{ + + + if( obj->maxlen > obj->len ) { + warn("expand_ComplexSequenceEvalSet called with no need"); + return TRUE; + } + + + if( (obj->cse = (ComplexSequenceEval ** ) ckrealloc (obj->cse,sizeof(ComplexSequenceEval *)*len)) == NULL) { + warn("ckrealloc failed for expand_ComplexSequenceEvalSet, returning FALSE"); + return FALSE; + } + obj->maxlen = len; + return TRUE; +} + + +/* Function: add_ComplexSequenceEvalSet(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [ComplexSequenceEvalSet *] + * Arg: add [OWNER] Object to add to the list [ComplexSequenceEval *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +/* will expand function if necessary */ +boolean add_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,ComplexSequenceEval * add) +{ + if( obj->len >= obj->maxlen) { + if( expand_ComplexSequenceEvalSet(obj,obj->len + ComplexSequenceEvalSetLISTLENGTH) == FALSE) + return FALSE; + } + + + obj->cse[obj->len++]=add; + return TRUE; +} + + +/* Function: flush_ComplexSequenceEvalSet(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [ComplexSequenceEvalSet *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int flush_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj) +{ + int i; + + + for(i=0;ilen;i++) { + if( obj->cse[i] != NULL) { + free_ComplexSequenceEval(obj->cse[i]); + obj->cse[i] = NULL; + } + } /* end of for i over list length */ + + + obj->len = 0; + return i; +} + + +/* Function: ComplexSequenceEvalSet_alloc_std(void) + * + * Descrip: Equivalent to ComplexSequenceEvalSet_alloc_len(ComplexSequenceEvalSetLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * ComplexSequenceEvalSet_alloc_std(void) +{ + return ComplexSequenceEvalSet_alloc_len(ComplexSequenceEvalSetLISTLENGTH); +} + + +/* Function: ComplexSequenceEvalSet_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * ComplexSequenceEvalSet_alloc_len(int len) +{ + ComplexSequenceEvalSet * out; /* out is exported at the end of function */ + + + /* Call alloc function: return NULL if NULL */ + /* Warning message alread in alloc function */ + if((out = ComplexSequenceEvalSet_alloc()) == NULL) + return NULL; + + + /* Calling ckcalloc for list elements */ + if((out->cse = (ComplexSequenceEval ** ) ckcalloc (len,sizeof(ComplexSequenceEval *))) == NULL) { + warn("Warning, ckcalloc failed in ComplexSequenceEvalSet_alloc_len"); + return NULL; + } + out->len = 0; + out->maxlen = len; + + + return out; +} + + +/* Function: hard_link_ComplexSequenceEvalSet(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [ComplexSequenceEvalSet *] + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * hard_link_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a ComplexSequenceEvalSet object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: ComplexSequenceEvalSet_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * ComplexSequenceEvalSet_alloc(void) +{ + ComplexSequenceEvalSet * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(ComplexSequenceEvalSet *) ckalloc (sizeof(ComplexSequenceEvalSet))) == NULL) { + warn("ComplexSequenceEvalSet_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->type = 0; + out->has_been_prepared = FALSE; + out->left_window = 0; + out->right_window = 0; + out->left_lookback = 0; + out->cse = NULL; + out->len = out->maxlen = 0; + + + return out; +} + + +/* Function: free_ComplexSequenceEvalSet(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ComplexSequenceEvalSet *] + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * free_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj) +{ + int i; + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a ComplexSequenceEvalSet obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->cse != NULL) { + for(i=0;ilen;i++) { + if( obj->cse[i] != NULL) + free_ComplexSequenceEval(obj->cse[i]); + } + ckfree(obj->cse); + } + + + ckfree(obj); + return NULL; +} + + +/* Function: hard_link_ComplexSequence(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [ComplexSequence *] + * + * Return [UNKN ] Undocumented return value [ComplexSequence *] + * + */ +ComplexSequence * hard_link_ComplexSequence(ComplexSequence * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a ComplexSequence object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: ComplexSequence_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequence *] + * + */ +ComplexSequence * ComplexSequence_alloc(void) +{ + ComplexSequence * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(ComplexSequence *) ckalloc (sizeof(ComplexSequence))) == NULL) { + warn("ComplexSequence_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->type = 0; + out->seq = NULL; + out->datastore = NULL; + out->depth = 0; + out->length = 0; + + + return out; +} + + +/* Function: free_ComplexSequence(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ComplexSequence *] + * + * Return [UNKN ] Undocumented return value [ComplexSequence *] + * + */ +ComplexSequence * free_ComplexSequence(ComplexSequence * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a ComplexSequence obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->seq != NULL) + free_Sequence(obj->seq); + /* obj->data is linked in */ + if( obj->datastore != NULL) + ckfree(obj->datastore); + + + ckfree(obj); + return NULL; +} + + +/* Function: replace_type_ComplexSequence(obj,type) + * + * Descrip: Replace member variable type + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequence *] + * Arg: type [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable type [boolean] + * + */ +boolean replace_type_ComplexSequence(ComplexSequence * obj,int type) +{ + if( obj == NULL) { + warn("In replacement function type for object ComplexSequence, got a NULL object"); + return FALSE; + } + obj->type = type; + return TRUE; +} + + +/* Function: access_type_ComplexSequence(obj) + * + * Descrip: Access member variable type + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequence *] + * + * Return [SOFT ] member variable type [int] + * + */ +int access_type_ComplexSequence(ComplexSequence * obj) +{ + if( obj == NULL) { + warn("In accessor function type for object ComplexSequence, got a NULL object"); + return 0; + } + return obj->type; +} + + +/* Function: replace_seq_ComplexSequence(obj,seq) + * + * Descrip: Replace member variable seq + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequence *] + * Arg: seq [OWNER] New value of the variable [Sequence *] + * + * Return [SOFT ] member variable seq [boolean] + * + */ +boolean replace_seq_ComplexSequence(ComplexSequence * obj,Sequence * seq) +{ + if( obj == NULL) { + warn("In replacement function seq for object ComplexSequence, got a NULL object"); + return FALSE; + } + obj->seq = seq; + return TRUE; +} + + +/* Function: access_seq_ComplexSequence(obj) + * + * Descrip: Access member variable seq + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequence *] + * + * Return [SOFT ] member variable seq [Sequence *] + * + */ +Sequence * access_seq_ComplexSequence(ComplexSequence * obj) +{ + if( obj == NULL) { + warn("In accessor function seq for object ComplexSequence, got a NULL object"); + return NULL; + } + return obj->seq; +} + + +/* Function: replace_type_ComplexSequenceEvalSet(obj,type) + * + * Descrip: Replace member variable type + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequenceEvalSet *] + * Arg: type [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable type [boolean] + * + */ +boolean replace_type_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,int type) +{ + if( obj == NULL) { + warn("In replacement function type for object ComplexSequenceEvalSet, got a NULL object"); + return FALSE; + } + obj->type = type; + return TRUE; +} + + +/* Function: access_type_ComplexSequenceEvalSet(obj) + * + * Descrip: Access member variable type + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequenceEvalSet *] + * + * Return [SOFT ] member variable type [int] + * + */ +int access_type_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj) +{ + if( obj == NULL) { + warn("In accessor function type for object ComplexSequenceEvalSet, got a NULL object"); + return 0; + } + return obj->type; +} + + +/* Function: replace_has_been_prepared_ComplexSequenceEvalSet(obj,has_been_prepared) + * + * Descrip: Replace member variable has_been_prepared + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequenceEvalSet *] + * Arg: has_been_prepared [OWNER] New value of the variable [boolean] + * + * Return [SOFT ] member variable has_been_prepared [boolean] + * + */ +boolean replace_has_been_prepared_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,boolean has_been_prepared) +{ + if( obj == NULL) { + warn("In replacement function has_been_prepared for object ComplexSequenceEvalSet, got a NULL object"); + return FALSE; + } + obj->has_been_prepared = has_been_prepared; + return TRUE; +} + + +/* Function: access_has_been_prepared_ComplexSequenceEvalSet(obj) + * + * Descrip: Access member variable has_been_prepared + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequenceEvalSet *] + * + * Return [SOFT ] member variable has_been_prepared [boolean] + * + */ +boolean access_has_been_prepared_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj) +{ + if( obj == NULL) { + warn("In accessor function has_been_prepared for object ComplexSequenceEvalSet, got a NULL object"); + return FALSE; + } + return obj->has_been_prepared; +} + + +/* Function: replace_left_window_ComplexSequenceEvalSet(obj,left_window) + * + * Descrip: Replace member variable left_window + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequenceEvalSet *] + * Arg: left_window [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable left_window [boolean] + * + */ +boolean replace_left_window_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,int left_window) +{ + if( obj == NULL) { + warn("In replacement function left_window for object ComplexSequenceEvalSet, got a NULL object"); + return FALSE; + } + obj->left_window = left_window; + return TRUE; +} + + +/* Function: access_left_window_ComplexSequenceEvalSet(obj) + * + * Descrip: Access member variable left_window + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequenceEvalSet *] + * + * Return [SOFT ] member variable left_window [int] + * + */ +int access_left_window_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj) +{ + if( obj == NULL) { + warn("In accessor function left_window for object ComplexSequenceEvalSet, got a NULL object"); + return 0; + } + return obj->left_window; +} + + +/* Function: replace_right_window_ComplexSequenceEvalSet(obj,right_window) + * + * Descrip: Replace member variable right_window + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequenceEvalSet *] + * Arg: right_window [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable right_window [boolean] + * + */ +boolean replace_right_window_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,int right_window) +{ + if( obj == NULL) { + warn("In replacement function right_window for object ComplexSequenceEvalSet, got a NULL object"); + return FALSE; + } + obj->right_window = right_window; + return TRUE; +} + + +/* Function: access_right_window_ComplexSequenceEvalSet(obj) + * + * Descrip: Access member variable right_window + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequenceEvalSet *] + * + * Return [SOFT ] member variable right_window [int] + * + */ +int access_right_window_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj) +{ + if( obj == NULL) { + warn("In accessor function right_window for object ComplexSequenceEvalSet, got a NULL object"); + return 0; + } + return obj->right_window; +} + + +/* Function: replace_left_lookback_ComplexSequenceEvalSet(obj,left_lookback) + * + * Descrip: Replace member variable left_lookback + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequenceEvalSet *] + * Arg: left_lookback [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable left_lookback [boolean] + * + */ +boolean replace_left_lookback_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,int left_lookback) +{ + if( obj == NULL) { + warn("In replacement function left_lookback for object ComplexSequenceEvalSet, got a NULL object"); + return FALSE; + } + obj->left_lookback = left_lookback; + return TRUE; +} + + +/* Function: access_left_lookback_ComplexSequenceEvalSet(obj) + * + * Descrip: Access member variable left_lookback + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ComplexSequenceEvalSet *] + * + * Return [SOFT ] member variable left_lookback [int] + * + */ +int access_left_lookback_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj) +{ + if( obj == NULL) { + warn("In accessor function left_lookback for object ComplexSequenceEvalSet, got a NULL object"); + return 0; + } + return obj->left_lookback; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/complexsequence.h b/Bio/Ext/Align/libs/complexsequence.h new file mode 100644 index 0000000..1b8cad7 --- /dev/null +++ b/Bio/Ext/Align/libs/complexsequence.h @@ -0,0 +1,426 @@ +#ifndef DYNAMITEcomplexsequenceHEADERFILE +#define DYNAMITEcomplexsequenceHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "sequence.h" +#include "probability.h" /* should move this to wisestring */ + + +#define ComplexSequenceEvalSetLISTLENGTH 16 + +#define next_ComplexSequence_data(cs_struct,pointer) (pointer + cs_struct->depth) +#define ComplexSequence_data(cs,position,number) (cs->data[cs->depth*position + number]) + + + +/* Object ComplexSequenceEval + * + * Descrip: This object is best left alone (!) + * + * It represents a single way of mapping + * a sequence to some sort of number, eg + * amino acids to 0-25, bases to 0-4 or + * splice sites to log(Prob(splice)) + * + * This is handled by a reasonably scary + * pointer-to-function method + * + * You'll use collections of them in + * complexsequenceevalset's + * + * + */ +struct bp_sw_ComplexSequenceEval { + int dynamite_hard_link; + int type; + int sequence_type; + int left_window; + int right_window; + int left_lookback; + int outside_score; + void * data; + int data_type; /* optional, to be used by eval_func to check things if it wants to */ + int (*eval_func)(int,void * ,char *); + } ; +/* ComplexSequenceEval defined */ +#ifndef DYNAMITE_DEFINED_ComplexSequenceEval +typedef struct bp_sw_ComplexSequenceEval bp_sw_ComplexSequenceEval; +#define ComplexSequenceEval bp_sw_ComplexSequenceEval +#define DYNAMITE_DEFINED_ComplexSequenceEval +#endif + + +/* Object ComplexSequenceEvalSet + * + * Descrip: This object holds a collection of + * ComplexSequenceEval's. Its role is to + * define the sequence specific parts of a + * dynamic programming algorithm as computable + * functions. + * + * Ideally you should use pre-made ComplexSequenceEvalSets + * as it will save you alot of grief + * + * + */ +struct bp_sw_ComplexSequenceEvalSet { + int dynamite_hard_link; + int type; + boolean has_been_prepared; + int left_window; /* overall sequence eval */ + int right_window; /* overall sequence eval */ + int left_lookback; /* overall sequence eval */ + ComplexSequenceEval ** cse; + int len;/* len for above cse */ + int maxlen; /* maxlen for above cse */ + } ; +/* ComplexSequenceEvalSet defined */ +#ifndef DYNAMITE_DEFINED_ComplexSequenceEvalSet +typedef struct bp_sw_ComplexSequenceEvalSet bp_sw_ComplexSequenceEvalSet; +#define ComplexSequenceEvalSet bp_sw_ComplexSequenceEvalSet +#define DYNAMITE_DEFINED_ComplexSequenceEvalSet +#endif + + +/* Object ComplexSequence + * + * Descrip: A ComplexSequence is an abstraction of a + * Sequence which can be handily made using + * ComplexSequenceEval functions and is efficiently + * laid out in memory. + * + * + */ +struct bp_sw_ComplexSequence { + int dynamite_hard_link; + int type; + Sequence * seq; + int * data; + int * datastore; + int depth; + int length; + } ; +/* ComplexSequence defined */ +#ifndef DYNAMITE_DEFINED_ComplexSequence +typedef struct bp_sw_ComplexSequence bp_sw_ComplexSequence; +#define ComplexSequence bp_sw_ComplexSequence +#define DYNAMITE_DEFINED_ComplexSequence +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: new_ComplexSequence(seq,cses) + * + * Descrip: The basic way to make a ComplexSequence. Requires that + * you have already built a ComplexSequenceEvalSet (such as + * /default_aminoacid_ComplexSequenceEvalSet). + * + * + * + * Arg: seq [UNKN ] Sequence that the ComplexSequence is based on [Sequence *] + * Arg: cses [UNKN ] EvalSet that defines the functions used on the sequence [ComplexSequenceEvalSet *] + * + * Return [UNKN ] Undocumented return value [ComplexSequence *] + * + */ +ComplexSequence * bp_sw_new_ComplexSequence(Sequence * seq,ComplexSequenceEvalSet * cses); +#define new_ComplexSequence bp_sw_new_ComplexSequence + + +/* Function: show_ComplexSequence(cs,ofp) + * + * Descrip: shows complex sequence in a vaguely + * human form + * + * + * Arg: cs [UNKN ] Undocumented argument [ComplexSequence *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_show_ComplexSequence(ComplexSequence * cs,FILE * ofp); +#define show_ComplexSequence bp_sw_show_ComplexSequence + + +/* Function: prepare_ComplexSequenceEvalSet(cses) + * + * Descrip: Calculates all the necessary offset for an EvalSet. + * This is necessary before using it in a /new_ComplexSequence + * place + * + * + * Arg: cses [UNKN ] Undocumented argument [ComplexSequenceEvalSet *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_prepare_ComplexSequenceEvalSet(ComplexSequenceEvalSet * cses); +#define prepare_ComplexSequenceEvalSet bp_sw_prepare_ComplexSequenceEvalSet + + +/* Function: can_evaluate_this_Sequence(cses,s) + * + * Descrip: Checks that this ComplexSequenceEvalSet can be used with + * this Sequence. This is probably going to go defunct. + * + * + * + * Arg: cses [UNKN ] Undocumented argument [ComplexSequenceEvalSet *] + * Arg: s [UNKN ] Undocumented argument [Sequence *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_can_evaluate_this_Sequence(ComplexSequenceEvalSet * cses,Sequence * s); +#define can_evaluate_this_Sequence bp_sw_can_evaluate_this_Sequence + + +/* Function: hard_link_ComplexSequenceEval(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [ComplexSequenceEval *] + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +ComplexSequenceEval * bp_sw_hard_link_ComplexSequenceEval(ComplexSequenceEval * obj); +#define hard_link_ComplexSequenceEval bp_sw_hard_link_ComplexSequenceEval + + +/* Function: ComplexSequenceEval_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +ComplexSequenceEval * bp_sw_ComplexSequenceEval_alloc(void); +#define ComplexSequenceEval_alloc bp_sw_ComplexSequenceEval_alloc + + +/* Function: free_ComplexSequenceEval(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ComplexSequenceEval *] + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEval *] + * + */ +ComplexSequenceEval * bp_sw_free_ComplexSequenceEval(ComplexSequenceEval * obj); +#define free_ComplexSequenceEval bp_sw_free_ComplexSequenceEval + + +/* Function: add_ComplexSequenceEvalSet(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [ComplexSequenceEvalSet *] + * Arg: add [OWNER] Object to add to the list [ComplexSequenceEval *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,ComplexSequenceEval * add); +#define add_ComplexSequenceEvalSet bp_sw_add_ComplexSequenceEvalSet + + +/* Function: flush_ComplexSequenceEvalSet(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [ComplexSequenceEvalSet *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_flush_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj); +#define flush_ComplexSequenceEvalSet bp_sw_flush_ComplexSequenceEvalSet + + +/* Function: ComplexSequenceEvalSet_alloc_std(void) + * + * Descrip: Equivalent to ComplexSequenceEvalSet_alloc_len(ComplexSequenceEvalSetLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * bp_sw_ComplexSequenceEvalSet_alloc_std(void); +#define ComplexSequenceEvalSet_alloc_std bp_sw_ComplexSequenceEvalSet_alloc_std + + +/* Function: ComplexSequenceEvalSet_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * bp_sw_ComplexSequenceEvalSet_alloc_len(int len); +#define ComplexSequenceEvalSet_alloc_len bp_sw_ComplexSequenceEvalSet_alloc_len + + +/* Function: hard_link_ComplexSequenceEvalSet(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [ComplexSequenceEvalSet *] + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * bp_sw_hard_link_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj); +#define hard_link_ComplexSequenceEvalSet bp_sw_hard_link_ComplexSequenceEvalSet + + +/* Function: ComplexSequenceEvalSet_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * bp_sw_ComplexSequenceEvalSet_alloc(void); +#define ComplexSequenceEvalSet_alloc bp_sw_ComplexSequenceEvalSet_alloc + + +/* Function: free_ComplexSequenceEvalSet(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ComplexSequenceEvalSet *] + * + * Return [UNKN ] Undocumented return value [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * bp_sw_free_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj); +#define free_ComplexSequenceEvalSet bp_sw_free_ComplexSequenceEvalSet + + +/* Function: hard_link_ComplexSequence(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [ComplexSequence *] + * + * Return [UNKN ] Undocumented return value [ComplexSequence *] + * + */ +ComplexSequence * bp_sw_hard_link_ComplexSequence(ComplexSequence * obj); +#define hard_link_ComplexSequence bp_sw_hard_link_ComplexSequence + + +/* Function: ComplexSequence_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ComplexSequence *] + * + */ +ComplexSequence * bp_sw_ComplexSequence_alloc(void); +#define ComplexSequence_alloc bp_sw_ComplexSequence_alloc + + +/* Function: free_ComplexSequence(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ComplexSequence *] + * + * Return [UNKN ] Undocumented return value [ComplexSequence *] + * + */ +ComplexSequence * bp_sw_free_ComplexSequence(ComplexSequence * obj); +#define free_ComplexSequence bp_sw_free_ComplexSequence + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +int bp_sw_access_type_ComplexSequence(ComplexSequence * obj); +#define access_type_ComplexSequence bp_sw_access_type_ComplexSequence +boolean bp_sw_replace_type_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,int type); +#define replace_type_ComplexSequenceEvalSet bp_sw_replace_type_ComplexSequenceEvalSet +int bp_sw_access_type_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj); +#define access_type_ComplexSequenceEvalSet bp_sw_access_type_ComplexSequenceEvalSet +boolean bp_sw_replace_has_been_prepared_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,boolean has_been_prepared); +#define replace_has_been_prepared_ComplexSequenceEvalSet bp_sw_replace_has_been_prepared_ComplexSequenceEvalSet +boolean bp_sw_replace_type_ComplexSequence(ComplexSequence * obj,int type); +#define replace_type_ComplexSequence bp_sw_replace_type_ComplexSequence +boolean bp_sw_access_has_been_prepared_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj); +#define access_has_been_prepared_ComplexSequenceEvalSet bp_sw_access_has_been_prepared_ComplexSequenceEvalSet +Sequence * bp_sw_access_seq_ComplexSequence(ComplexSequence * obj); +#define access_seq_ComplexSequence bp_sw_access_seq_ComplexSequence +boolean bp_sw_replace_left_window_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,int left_window); +#define replace_left_window_ComplexSequenceEvalSet bp_sw_replace_left_window_ComplexSequenceEvalSet +boolean bp_sw_replace_left_lookback_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,int left_lookback); +#define replace_left_lookback_ComplexSequenceEvalSet bp_sw_replace_left_lookback_ComplexSequenceEvalSet +int bp_sw_access_left_window_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj); +#define access_left_window_ComplexSequenceEvalSet bp_sw_access_left_window_ComplexSequenceEvalSet +int bp_sw_access_left_lookback_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj); +#define access_left_lookback_ComplexSequenceEvalSet bp_sw_access_left_lookback_ComplexSequenceEvalSet +boolean bp_sw_replace_right_window_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,int right_window); +#define replace_right_window_ComplexSequenceEvalSet bp_sw_replace_right_window_ComplexSequenceEvalSet +boolean bp_sw_replace_seq_ComplexSequence(ComplexSequence * obj,Sequence * seq); +#define replace_seq_ComplexSequence bp_sw_replace_seq_ComplexSequence +int bp_sw_access_right_window_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj); +#define access_right_window_ComplexSequenceEvalSet bp_sw_access_right_window_ComplexSequenceEvalSet +void bp_sw_show_one_position_ComplexSequence(ComplexSequence * cs,int pos,FILE * ofp); +#define show_one_position_ComplexSequence bp_sw_show_one_position_ComplexSequence +boolean bp_sw_can_evaluate_this_type(ComplexSequenceEvalSet * cses,int type); +#define can_evaluate_this_type bp_sw_can_evaluate_this_type +void bp_sw_swap_ComplexSequenceEvalSet(ComplexSequenceEval ** list,int i,int j) ; +#define swap_ComplexSequenceEvalSet bp_sw_swap_ComplexSequenceEvalSet +void bp_sw_qsort_ComplexSequenceEvalSet(ComplexSequenceEval ** list,int left,int right,int (*comp)(ComplexSequenceEval * ,ComplexSequenceEval * )); +#define qsort_ComplexSequenceEvalSet bp_sw_qsort_ComplexSequenceEvalSet +void bp_sw_sort_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,int (*comp)(ComplexSequenceEval *, ComplexSequenceEval *)); +#define sort_ComplexSequenceEvalSet bp_sw_sort_ComplexSequenceEvalSet +boolean bp_sw_expand_ComplexSequenceEvalSet(ComplexSequenceEvalSet * obj,int len); +#define expand_ComplexSequenceEvalSet bp_sw_expand_ComplexSequenceEvalSet + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/compmat.c b/Bio/Ext/Align/libs/compmat.c new file mode 100644 index 0000000..e15ffe0 --- /dev/null +++ b/Bio/Ext/Align/libs/compmat.c @@ -0,0 +1,708 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "compmat.h" + + +/* Function: CompMat_from_CompProb(cp) + * + * Descrip: Maps a CompProb to a CompMat going through + * Probability2Score + * + * + * Arg: cp [UNKN ] Undocumented argument [CompProb *] + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +# line 49 "compmat.dy" +CompMat * CompMat_from_CompProb(CompProb * cp) +{ + int i,j; + CompMat * cm; + + cm = CompMat_alloc(); + + for(i=0;i<26;i++) { + for(j=0;j<26;j++) { + cm->comp[i][j] = Probability2Score(cp->comp[i][j]); + } + } + + + return cm; +} + +/* Function: CompProb_from_halfbit(cm) + * + * Descrip: Maps a halfbit matrix to a prob matrix by rebasing + * etc. + * + * *Really* not sensible! + * + * + * Arg: cm [UNKN ] Undocumented argument [CompMat *] + * + * Return [UNKN ] Undocumented return value [CompProb *] + * + */ +# line 72 "compmat.dy" +CompProb * CompProb_from_halfbit(CompMat * cm) +{ + CompProb * out; + int i,j; + + out = CompProb_alloc(); + for(i=0;i<26;i++) + for(j=0;j<26;j++) + out->comp[i][j] = halfbit2Probability(cm->comp[i][j]); + + return out; +} + +/* Function: CompMat_from_halfbit(cm) + * + * Descrip: flips a halfbit based matrix (eg, blosum62) into a score + * based matrix just by rebasing the log etc. + * + * Not a sensible function ... + * + * + * + * Arg: cm [UNKN ] Undocumented argument [CompMat *] + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +# line 92 "compmat.dy" +CompMat * CompMat_from_halfbit(CompMat * cm) +{ + CompMat * out; + int i,j; + + out = CompMat_alloc(); + for(i=0;i<26;i++) + for(j=0;j<26;j++) + out->comp[i][j] = Probability2Score(halfbit2Probability(cm->comp[i][j])); + + return out; +} + + +/* Function: factor_CompMat(cm,factor) + * + * Descrip: multiples all the scores by the amount + * + * + * Arg: cm [UNKN ] compmat object [CompMat *] + * Arg: factor [UNKN ] amount to multiple by [int] + * + */ +# line 112 "compmat.dy" +void factor_CompMat(CompMat * cm,int factor) +{ + int i,j; + + for(i=0;i<26;i++) + for(j=0;j<26;j++) + cm->comp[i][j] *= factor; + +} + + +/* Function: fail_safe_CompMat_access(cm,aa1,aa2) + * + * Descrip: gives the fail form of the macro CompMat_AAMATCH which + * checks that aa1 and a2 are sensible and that cm is not NULL. + * + * + * Arg: cm [UNKN ] compmat object [CompMat *] + * Arg: aa1 [UNKN ] first amino acid [int] + * Arg: aa2 [UNKN ] second amino acid [int] + * + * Return [UNKN ] Undocumented return value [Score] + * + */ +# line 131 "compmat.dy" +Score fail_safe_CompMat_access(CompMat * cm,int aa1,int aa2) +{ + if( cm == NULL) { + warn("Attempting to access NULL CompMat."); + return 0; + } + + if( aa1 < 0 || aa1 >= 26 || aa2 < 0 || aa2 > 26) { + warn("Attempting to access CompMat with aminoacid numbers %d:%d (they must be bound between 0:26, returning 0 here",aa1,aa2); + return 0; + } + + else return cm->comp[aa1][aa2]; +} + +/* Function: write_Blast_CompMat(cm,ofp) + * + * Descrip: writes a protien CompMat with a standard + * alphabet. + * + * + * Arg: cm [UNKN ] CompMat object [CompMat *] + * Arg: ofp [UNKN ] file to output [FILE *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 153 "compmat.dy" +boolean write_Blast_CompMat(CompMat * cm,FILE * ofp) +{ + return write_Blast_CompMat_alphabet(cm,"ARNDCQEGHILKMFPSTWYVBZX",ofp); +} + +/* Function: bad_CompMat_alphabet(al) + * + * Descrip: checks that this string is ok for BLAST alphabet mappings. + * + * + * Arg: al [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 162 "compmat.dy" +boolean bad_CompMat_alphabet(char * al) +{ + char * runner; + for(runner=al;*runner;runner++) + if( !isalpha(*runner) && toupper(*runner) != *runner ) { + warn("Attempting to use [%s] as a CompMat alphabet: needs all upper case, no spaced letters",al); + return TRUE; + } + + return FALSE; +} + +/* Function: write_Blast_CompMat_alphabet(cm,alphabet,ofp) + * + * Descrip: actualy writes out the Blast CFormat. The alphabet is + * what order you want the amino acids. If you want the + * standard format use /write_Blast_CompMat + * + * + * Arg: cm [UNKN ] comp mat object [CompMat *] + * Arg: alphabet [UNKN ] string for alphabet to be used [char *] + * Arg: ofp [UNKN ] fileoutput [FILE *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 183 "compmat.dy" +boolean write_Blast_CompMat_alphabet(CompMat * cm,char * alphabet,FILE * ofp) +{ + char * runner; + char * run2; + int minnumbers[26]; + int len; + int i; + int min; + + if( bad_CompMat_alphabet(alphabet) == TRUE ) + return FALSE; /* warning already issued */ + + fprintf(ofp,"# File made by *Wise CompMat library module\n"); + fprintf(ofp,"# Comparison matrix in BLAST format\n"); + fprintf(ofp,"# Usually matrices are given in half-bit units\n"); + fprintf(ofp,"# First line is alphabet, the * column is the lowest score\n"); + fprintf(ofp,"# File Created [%s]\n",now_string()); + fprintf(ofp,"# Matrix name [%s]\n",cm->name == NULL ? "No Name" : cm->name); + + + /*** print out alphabet wit correct spacing ***/ + fprintf(ofp," %c",alphabet[0]); + for(runner=alphabet+1;*runner;runner++) + fprintf(ofp," %c",*runner); + fprintf(ofp," *\n"); + + /*** print out each row: remember the minimum number for printing later **/ + + for(runner=alphabet,len=0;*runner;runner++) { + min = cm->comp[*runner-'A'][0]; + fprintf(ofp,"%- d",cm->comp[*runner-'A'][0]); + for(run2=alphabet+1;*run2;run2++) { + fprintf(ofp," %- d",cm->comp[*runner-'A'][*run2-'A']); + if( cm->comp[*runner-'A'][*run2-'A'] < min ) + min = cm->comp[*runner-'A'][*run2-'A']; + } + + minnumbers[len++] = min; + fprintf(ofp," % d\n",min); + } + + /*** final row... * ***/ + + fprintf(ofp,"% d",minnumbers[0]); + for(i=1;iname = stringalloc(filename); + } + + fclose(ifp); + + return out; +} + +/* Function: read_Blast_CompMat(ifp) + * + * Descrip: reads a BLAST format matrix and + * allocates a new ComMat structure. + * + * + * Arg: ifp [UNKN ] Undocumented argument [FILE *] + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +# line 269 "compmat.dy" +CompMat * read_Blast_CompMat(FILE * ifp) +{ + char buffer[MAXLINE]; + int alphabet[MAXLINE]; + char * runner; + int len; + int linenum; + int row; + CompMat * out; + + + + /*** + Skip over # lines... + + read first line: is alphabet ie + A R T G .... * + ***/ + + while( fgets(buffer,MAXLINE,ifp) != NULL) + if( buffer[0] != '#') + break; + + /** loop over line, getting letters: warn if longer than one, or not a letter **/ + + for(len=0,runner=strtok(buffer,spacestr);runner != NULL;runner=strtok(NULL,spacestr)) { + if( *runner == '*' ) + break; /* end column */ + + if( !isalpha(*runner) || strlen(runner) > 1 ) { + warn("In read Blast comp mat, probably an error: trying to interpret [%s] as an amino acid",runner); + return NULL; + } + + alphabet[len++] = toupper(*runner) -'A'; + } + + + out = blank_CompMat(); + linenum = 0; + + /** get len lines, each line, get len numbers and put them away **/ + + while( fgets(buffer,MAXLINE,ifp) != NULL ) { + + if( linenum >= len ) + break; + + for(runner=strtok(buffer,spacestr),row = 0;runner != NULL && row < len;runner=strtok(NULL,spacestr),row++) { + if( is_integer_string(runner,&out->comp[alphabet[linenum]][alphabet[row]]) == FALSE ) { + warn("In read Blast comp mat, probably an error: trying to interpret [%s] as a number ... continuing",runner); + } + } + linenum++; + } + + return out; + +} +/* Function: read_Blast_CompProb(ifp) + * + * Descrip: reads a BLAST format matrix and + * allocates a new CompProb structure. + * + * + * Arg: ifp [READ ] file input [FILE *] + * + * Return [UNKN ] newly allocated CompProb [CompProb *] + * + */ +# line 335 "compmat.dy" +CompProb * read_Blast_CompProb(FILE * ifp) +{ + char buffer[MAXLINE]; + int alphabet[MAXLINE]; + char * runner; + int len; + int linenum; + int row; + CompProb * out; + + + + /*** + Skip over # lines... + + read first line: is alphabet ie + A R T G .... * + ***/ + + while( fgets(buffer,MAXLINE,ifp) != NULL) + if( buffer[0] != '#') + break; + + /** loop over line, getting letters: warn if longer than one, or not a letter **/ + + for(len=0,runner=strtok(buffer,spacestr);runner != NULL;runner=strtok(NULL,spacestr)) { + if( *runner == '*' ) + break; /* end column */ + + if( !isalpha(*runner) || strlen(runner) > 1 ) { + warn("In read Blast comp mat, probably an error: trying to interpret [%s] as an amino acid",runner); + return NULL; + } + + alphabet[len++] = toupper(*runner) -'A'; + } + + + out = blank_CompProb(); + linenum = 0; + + /** get len lines, each line, get len numbers and put them away **/ + + while( fgets(buffer,MAXLINE,ifp) != NULL ) { + if( strstartcmp(buffer,"//") == 0 ) + break; + if( linenum >= len ) + break; + + for(runner=strtok(buffer,spacestr),row = 0;runner != NULL && row < len;runner=strtok(NULL,spacestr),row++) { + if( is_double_string(runner,&out->comp[alphabet[linenum]][alphabet[row]]) == FALSE ) { + warn("In read Blast comp prob, probably an error: trying to interpret [%s] as a number ... continuing",runner); + } + } + linenum++; + } + + return out; +} + +/* Function: blank_CompMat(void) + * + * Descrip: makes a 0,0 matrix + * + * + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +# line 398 "compmat.dy" +CompMat * blank_CompMat(void) +{ + register int i; + register int j; + CompMat * out; + + + out = CompMat_alloc(); + if( out == NULL) + return NULL; + + for(i=0;i<26;i++) + for(j=0;j<26;j++) + out->comp[i][j] = 0; + + return out; +} + +/* Function: blank_CompProb(void) + * + * Descrip: makes a 1.0 prob matrix + * + * + * + * Return [UNKN ] Undocumented return value [CompProb *] + * + */ +# line 419 "compmat.dy" +CompProb * blank_CompProb(void) +{ + register int i; + register int j; + CompProb * out; + + + out = CompProb_alloc(); + if( out == NULL) + return NULL; + + for(i=0;i<26;i++) + for(j=0;j<26;j++) + out->comp[i][j] = 1.0; + + return out; +} + + + + + + +# line 465 "compmat.c" +/* Function: hard_link_CompProb(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [CompProb *] + * + * Return [UNKN ] Undocumented return value [CompProb *] + * + */ +CompProb * hard_link_CompProb(CompProb * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a CompProb object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: CompProb_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [CompProb *] + * + */ +CompProb * CompProb_alloc(void) +{ + CompProb * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(CompProb *) ckalloc (sizeof(CompProb))) == NULL) { + warn("CompProb_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + /* comp[26][26] is an array: no default possible */ + out->name = NULL; + + + return out; +} + + +/* Function: free_CompProb(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [CompProb *] + * + * Return [UNKN ] Undocumented return value [CompProb *] + * + */ +CompProb * free_CompProb(CompProb * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a CompProb obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->name != NULL) + ckfree(obj->name); + + + ckfree(obj); + return NULL; +} + + +/* Function: hard_link_CompMat(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [CompMat *] + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +CompMat * hard_link_CompMat(CompMat * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a CompMat object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: CompMat_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +CompMat * CompMat_alloc(void) +{ + CompMat * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(CompMat *) ckalloc (sizeof(CompMat))) == NULL) { + warn("CompMat_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + /* comp[26][26] is an array: no default possible */ + out->name = NULL; + + + return out; +} + + +/* Function: free_CompMat(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [CompMat *] + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +CompMat * free_CompMat(CompMat * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a CompMat obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->name != NULL) + ckfree(obj->name); + + + ckfree(obj); + return NULL; +} + + +/* Function: replace_name_CompMat(obj,name) + * + * Descrip: Replace member variable name + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [CompMat *] + * Arg: name [OWNER] New value of the variable [char *] + * + * Return [SOFT ] member variable name [boolean] + * + */ +boolean replace_name_CompMat(CompMat * obj,char * name) +{ + if( obj == NULL) { + warn("In replacement function name for object CompMat, got a NULL object"); + return FALSE; + } + obj->name = name; + return TRUE; +} + + +/* Function: access_name_CompMat(obj) + * + * Descrip: Access member variable name + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [CompMat *] + * + * Return [SOFT ] member variable name [char *] + * + */ +char * access_name_CompMat(CompMat * obj) +{ + if( obj == NULL) { + warn("In accessor function name for object CompMat, got a NULL object"); + return NULL; + } + return obj->name; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/compmat.h b/Bio/Ext/Align/libs/compmat.h new file mode 100644 index 0000000..32e750e --- /dev/null +++ b/Bio/Ext/Align/libs/compmat.h @@ -0,0 +1,353 @@ +#ifndef DYNAMITEcompmatHEADERFILE +#define DYNAMITEcompmatHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" +#include "probability.h" + +#define CompMat_AAMATCH(comp_mat,aa1,aa2) (comp_mat->comp[aa1][aa2]) +/* Object CompProb + * + * Descrip: The probabilistic form of CompMat + * + * + */ +struct bp_sw_CompProb { + int dynamite_hard_link; + Probability comp[26][26]; + char * name; + } ; +/* CompProb defined */ +#ifndef DYNAMITE_DEFINED_CompProb +typedef struct bp_sw_CompProb bp_sw_CompProb; +#define CompProb bp_sw_CompProb +#define DYNAMITE_DEFINED_CompProb +#endif + + +/* Object CompMat + * + * Descrip: This object stores BLOSUM and PAM + * comparison matrices. It stores them as + * scores: NB - this means probabilistically + * we are talking about some arbitary base of + * log which is really annoying. + * + * + */ +struct bp_sw_CompMat { + int dynamite_hard_link; + Score comp[26][26]; + char * name; /* if any, could be NULL */ + } ; +/* CompMat defined */ +#ifndef DYNAMITE_DEFINED_CompMat +typedef struct bp_sw_CompMat bp_sw_CompMat; +#define CompMat bp_sw_CompMat +#define DYNAMITE_DEFINED_CompMat +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: CompMat_from_CompProb(cp) + * + * Descrip: Maps a CompProb to a CompMat going through + * Probability2Score + * + * + * Arg: cp [UNKN ] Undocumented argument [CompProb *] + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +CompMat * bp_sw_CompMat_from_CompProb(CompProb * cp); +#define CompMat_from_CompProb bp_sw_CompMat_from_CompProb + + +/* Function: CompProb_from_halfbit(cm) + * + * Descrip: Maps a halfbit matrix to a prob matrix by rebasing + * etc. + * + * *Really* not sensible! + * + * + * Arg: cm [UNKN ] Undocumented argument [CompMat *] + * + * Return [UNKN ] Undocumented return value [CompProb *] + * + */ +CompProb * bp_sw_CompProb_from_halfbit(CompMat * cm); +#define CompProb_from_halfbit bp_sw_CompProb_from_halfbit + + +/* Function: CompMat_from_halfbit(cm) + * + * Descrip: flips a halfbit based matrix (eg, blosum62) into a score + * based matrix just by rebasing the log etc. + * + * Not a sensible function ... + * + * + * + * Arg: cm [UNKN ] Undocumented argument [CompMat *] + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +CompMat * bp_sw_CompMat_from_halfbit(CompMat * cm); +#define CompMat_from_halfbit bp_sw_CompMat_from_halfbit + + +/* Function: factor_CompMat(cm,factor) + * + * Descrip: multiples all the scores by the amount + * + * + * Arg: cm [UNKN ] compmat object [CompMat *] + * Arg: factor [UNKN ] amount to multiple by [int] + * + */ +void bp_sw_factor_CompMat(CompMat * cm,int factor); +#define factor_CompMat bp_sw_factor_CompMat + + +/* Function: fail_safe_CompMat_access(cm,aa1,aa2) + * + * Descrip: gives the fail form of the macro CompMat_AAMATCH which + * checks that aa1 and a2 are sensible and that cm is not NULL. + * + * + * Arg: cm [UNKN ] compmat object [CompMat *] + * Arg: aa1 [UNKN ] first amino acid [int] + * Arg: aa2 [UNKN ] second amino acid [int] + * + * Return [UNKN ] Undocumented return value [Score] + * + */ +Score bp_sw_fail_safe_CompMat_access(CompMat * cm,int aa1,int aa2); +#define fail_safe_CompMat_access bp_sw_fail_safe_CompMat_access + + +/* Function: write_Blast_CompMat(cm,ofp) + * + * Descrip: writes a protien CompMat with a standard + * alphabet. + * + * + * Arg: cm [UNKN ] CompMat object [CompMat *] + * Arg: ofp [UNKN ] file to output [FILE *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_write_Blast_CompMat(CompMat * cm,FILE * ofp); +#define write_Blast_CompMat bp_sw_write_Blast_CompMat + + +/* Function: write_Blast_CompMat_alphabet(cm,alphabet,ofp) + * + * Descrip: actualy writes out the Blast CFormat. The alphabet is + * what order you want the amino acids. If you want the + * standard format use /write_Blast_CompMat + * + * + * Arg: cm [UNKN ] comp mat object [CompMat *] + * Arg: alphabet [UNKN ] string for alphabet to be used [char *] + * Arg: ofp [UNKN ] fileoutput [FILE *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_write_Blast_CompMat_alphabet(CompMat * cm,char * alphabet,FILE * ofp); +#define write_Blast_CompMat_alphabet bp_sw_write_Blast_CompMat_alphabet + + +/* Function: read_Blast_file_CompMat(filename) + * + * Descrip: Opens file, reads matrix, closes file. + * calls /read_Blast_CompMat for the actual format + * reading. Uses /openfile to open the file, + * so will open from config files. + * + * + * Arg: filename [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +CompMat * bp_sw_read_Blast_file_CompMat(char * filename); +#define read_Blast_file_CompMat bp_sw_read_Blast_file_CompMat + + +/* Function: read_Blast_CompMat(ifp) + * + * Descrip: reads a BLAST format matrix and + * allocates a new ComMat structure. + * + * + * Arg: ifp [UNKN ] Undocumented argument [FILE *] + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +CompMat * bp_sw_read_Blast_CompMat(FILE * ifp); +#define read_Blast_CompMat bp_sw_read_Blast_CompMat + + +/* Function: read_Blast_CompProb(ifp) + * + * Descrip: reads a BLAST format matrix and + * allocates a new CompProb structure. + * + * + * Arg: ifp [READ ] file input [FILE *] + * + * Return [UNKN ] newly allocated CompProb [CompProb *] + * + */ +CompProb * bp_sw_read_Blast_CompProb(FILE * ifp); +#define read_Blast_CompProb bp_sw_read_Blast_CompProb + + +/* Function: blank_CompMat(void) + * + * Descrip: makes a 0,0 matrix + * + * + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +CompMat * bp_sw_blank_CompMat(void); +#define blank_CompMat bp_sw_blank_CompMat + + +/* Function: blank_CompProb(void) + * + * Descrip: makes a 1.0 prob matrix + * + * + * + * Return [UNKN ] Undocumented return value [CompProb *] + * + */ +CompProb * bp_sw_blank_CompProb(void); +#define blank_CompProb bp_sw_blank_CompProb + + +/* Function: hard_link_CompProb(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [CompProb *] + * + * Return [UNKN ] Undocumented return value [CompProb *] + * + */ +CompProb * bp_sw_hard_link_CompProb(CompProb * obj); +#define hard_link_CompProb bp_sw_hard_link_CompProb + + +/* Function: CompProb_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [CompProb *] + * + */ +CompProb * bp_sw_CompProb_alloc(void); +#define CompProb_alloc bp_sw_CompProb_alloc + + +/* Function: free_CompProb(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [CompProb *] + * + * Return [UNKN ] Undocumented return value [CompProb *] + * + */ +CompProb * bp_sw_free_CompProb(CompProb * obj); +#define free_CompProb bp_sw_free_CompProb + + +/* Function: hard_link_CompMat(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [CompMat *] + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +CompMat * bp_sw_hard_link_CompMat(CompMat * obj); +#define hard_link_CompMat bp_sw_hard_link_CompMat + + +/* Function: CompMat_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +CompMat * bp_sw_CompMat_alloc(void); +#define CompMat_alloc bp_sw_CompMat_alloc + + +/* Function: free_CompMat(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [CompMat *] + * + * Return [UNKN ] Undocumented return value [CompMat *] + * + */ +CompMat * bp_sw_free_CompMat(CompMat * obj); +#define free_CompMat bp_sw_free_CompMat + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +boolean bp_sw_replace_name_CompMat(CompMat * obj,char * name); +#define replace_name_CompMat bp_sw_replace_name_CompMat +char * bp_sw_access_name_CompMat(CompMat * obj); +#define access_name_CompMat bp_sw_access_name_CompMat +boolean bp_sw_bad_CompMat_alphabet(char * al); +#define bad_CompMat_alphabet bp_sw_bad_CompMat_alphabet + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/database.h b/Bio/Ext/Align/libs/database.h new file mode 100644 index 0000000..28b9c00 --- /dev/null +++ b/Bio/Ext/Align/libs/database.h @@ -0,0 +1,30 @@ + +#ifndef DATABASE_HEADER_FILE +#define DATABASE_HEADER_FILE + +/* + * Enum for database reload success/failure + */ + + +enum return_status { + DB_RETURN_UNKNOWN = 143, + DB_RETURN_OK, + DB_RETURN_ERROR, + DB_RETURN_END }; + +typedef int DB_Return_Type; + +/* + * Enum for search success/failure + */ + +enum search_return { + SEARCH_UNKNOWN = 152, + SEARCH_ERROR, + SEARCH_OK }; + +typedef int Search_Return_Type; + + +#endif diff --git a/Bio/Ext/Align/libs/dna.c b/Bio/Ext/Align/libs/dna.c new file mode 100644 index 0000000..b4d0957 --- /dev/null +++ b/Bio/Ext/Align/libs/dna.c @@ -0,0 +1,292 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "dna.h" + + + +/* Function: truncate_DNA(dna,start,stop) + * + * Descrip: Truncates a DNA sequence. Basically uses + * the /trunc_Sequence function (of course!) + * + * It does not alter dna, rather it returns a new + * sequence with that truncation + * + * + * Arg: dna [READ ] DNA that is truncated [DNA *] + * Arg: start [UNKN ] Undocumented argument [int] + * Arg: stop [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +# line 30 "dna.dy" +DNA * truncate_DNA(DNA * dna,int start,int stop) +{ + return DNA_from_Sequence(trunc_Sequence(dna->baseseq,start,stop)); +} + +/* Function: read_fasta_file_DNA (filename) + * + * Descrip: Reads a fasta file assumming that it is DNA. + * Will complain if it is not, and return NULL. + * + * + * Arg: filename [UNKN ] filename to be opened and read [char *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +# line 41 "dna.dy" +DNA * read_fasta_file_DNA (char * filename) +{ + Sequence * seq; + + seq = read_fasta_file_Sequence(filename); + if( seq == NULL ) { + return NULL; + } + + return DNA_from_Sequence(seq); +} + + +/* Function: read_fasta_DNA (ifp) + * + * Descrip: Reads a fasta file assumming that it is DNA. + * Will complain if it is not, and return NULL. + * + * + * Arg: ifp [UNKN ] file point to be read from [FILE *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +# line 60 "dna.dy" +DNA * read_fasta_DNA (FILE * ifp) +{ + Sequence * seq; + + seq = read_fasta_Sequence(ifp); + if( seq == NULL ) { + return NULL; + } + + return DNA_from_Sequence(seq); +} + +/* Function: read_efetch_DNA(estr) + * + * Descrip: Reads a efetch specified query + * Uses, of course /read_efetch_Sequence + * + * + * Arg: estr [READ ] efetch string which is read [char *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +# line 78 "dna.dy" +DNA * read_efetch_DNA(char * estr) +{ + return DNA_from_Sequence(read_efetch_Sequence(estr)); +} + +/* Function: read_SRS_DNA(srsquery) + * + * Descrip: Reads a SRS sequence using srs4 syntax. + * Uses, of course, /read_SRS_Sequence + * + * + * + * Arg: srsquery [READ ] string query representing SRS name [char *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +# line 90 "dna.dy" +DNA * read_SRS_DNA(char * srsquery) +{ + return DNA_from_Sequence(read_SRS_Sequence(srsquery)); +} + + +/* Function: DNA_name (dna) + * + * Descrip: Returns the name of the DNA + * + * + * Arg: dna [UNKN ] Undocumented argument [DNA *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 100 "dna.dy" +char * DNA_name (DNA * dna) +{ + return dna->baseseq->name; +} + +/* Function: DNA_length (dna) + * + * Descrip: Returns the length of the DNA + * + * + * Arg: dna [UNKN ] Undocumented argument [DNA *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 109 "dna.dy" +int DNA_length (DNA * dna) +{ + return dna->baseseq->len; +} + +/* Function: DNA_seqchar(dna,pos) + * + * Descrip: Returns sequence character at this position. + * + * + * Arg: dna [UNKN ] DNA [DNA *] + * Arg: pos [UNKN ] position in DNA to get char [int] + * + * Return [UNKN ] Undocumented return value [char] + * + */ +# line 120 "dna.dy" +char DNA_seqchar(DNA * dna,int pos) +{ + return dna->baseseq->seq[pos]; +} + + +/* Function: DNA_from_Sequence(seq) + * + * Descrip: makes a new DNA from a Sequence. It + * owns the Sequence memory, ie will attempt a /free_Sequence + * on the structure when /free_DNA is called + * + * If you want to give this DNA this Sequence and + * forget about it, then just hand it this sequence and set + * seq to NULL (no need to free it). If you intend to use + * the sequence object elsewhere outside of the DNA datastructure + * then use DNA_from_Sequence(/hard_link_Sequence(seq)) + * + * + * + * Arg: seq [UNKN ] Sequence to make DNA from [Sequence *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +# line 140 "dna.dy" +DNA * DNA_from_Sequence(Sequence * seq) +{ + DNA * out; + + + if( is_dna_Sequence(seq) == FALSE ) { + warn("Trying to make a DNA sequence from a non DNA base sequence [%s].",seq->name); + return NULL; + } + + out = DNA_alloc(); + + out->baseseq = seq; + + return out; +} + + + + +# line 186 "dna.c" +/* Function: hard_link_DNA(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DNA *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +DNA * hard_link_DNA(DNA * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a DNA object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: DNA_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +DNA * DNA_alloc(void) +{ + DNA * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(DNA *) ckalloc (sizeof(DNA))) == NULL) { + warn("DNA_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->baseseq = NULL; + + + return out; +} + + +/* Function: free_DNA(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [DNA *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +DNA * free_DNA(DNA * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a DNA obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->baseseq != NULL) + free_Sequence(obj->baseseq); + + + ckfree(obj); + return NULL; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/dna.h b/Bio/Ext/Align/libs/dna.h new file mode 100644 index 0000000..955f74e --- /dev/null +++ b/Bio/Ext/Align/libs/dna.h @@ -0,0 +1,234 @@ +#ifndef DYNAMITEdnaHEADERFILE +#define DYNAMITEdnaHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "sequence.h" + + + +struct bp_sw_DNA { + int dynamite_hard_link; + Sequence * baseseq; + } ; +/* DNA defined */ +#ifndef DYNAMITE_DEFINED_DNA +typedef struct bp_sw_DNA bp_sw_DNA; +#define DNA bp_sw_DNA +#define DYNAMITE_DEFINED_DNA +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: truncate_DNA(dna,start,stop) + * + * Descrip: Truncates a DNA sequence. Basically uses + * the /trunc_Sequence function (of course!) + * + * It does not alter dna, rather it returns a new + * sequence with that truncation + * + * + * Arg: dna [READ ] DNA that is truncated [DNA *] + * Arg: start [UNKN ] Undocumented argument [int] + * Arg: stop [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +DNA * bp_sw_truncate_DNA(DNA * dna,int start,int stop); +#define truncate_DNA bp_sw_truncate_DNA + + +/* Function: read_fasta_file_DNA (filename) + * + * Descrip: Reads a fasta file assumming that it is DNA. + * Will complain if it is not, and return NULL. + * + * + * Arg: filename [UNKN ] filename to be opened and read [char *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +DNA * bp_sw_read_fasta_file_DNA (char * filename); +#define read_fasta_file_DNA bp_sw_read_fasta_file_DNA + + +/* Function: read_fasta_DNA (ifp) + * + * Descrip: Reads a fasta file assumming that it is DNA. + * Will complain if it is not, and return NULL. + * + * + * Arg: ifp [UNKN ] file point to be read from [FILE *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +DNA * bp_sw_read_fasta_DNA (FILE * ifp); +#define read_fasta_DNA bp_sw_read_fasta_DNA + + +/* Function: read_efetch_DNA(estr) + * + * Descrip: Reads a efetch specified query + * Uses, of course /read_efetch_Sequence + * + * + * Arg: estr [READ ] efetch string which is read [char *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +DNA * bp_sw_read_efetch_DNA(char * estr); +#define read_efetch_DNA bp_sw_read_efetch_DNA + + +/* Function: read_SRS_DNA(srsquery) + * + * Descrip: Reads a SRS sequence using srs4 syntax. + * Uses, of course, /read_SRS_Sequence + * + * + * + * Arg: srsquery [READ ] string query representing SRS name [char *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +DNA * bp_sw_read_SRS_DNA(char * srsquery); +#define read_SRS_DNA bp_sw_read_SRS_DNA + + +/* Function: DNA_name (dna) + * + * Descrip: Returns the name of the DNA + * + * + * Arg: dna [UNKN ] Undocumented argument [DNA *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_DNA_name (DNA * dna); +#define DNA_name bp_sw_DNA_name + + +/* Function: DNA_length (dna) + * + * Descrip: Returns the length of the DNA + * + * + * Arg: dna [UNKN ] Undocumented argument [DNA *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_DNA_length (DNA * dna); +#define DNA_length bp_sw_DNA_length + + +/* Function: DNA_seqchar(dna,pos) + * + * Descrip: Returns sequence character at this position. + * + * + * Arg: dna [UNKN ] DNA [DNA *] + * Arg: pos [UNKN ] position in DNA to get char [int] + * + * Return [UNKN ] Undocumented return value [char] + * + */ +char bp_sw_DNA_seqchar(DNA * dna,int pos); +#define DNA_seqchar bp_sw_DNA_seqchar + + +/* Function: DNA_from_Sequence(seq) + * + * Descrip: makes a new DNA from a Sequence. It + * owns the Sequence memory, ie will attempt a /free_Sequence + * on the structure when /free_DNA is called + * + * If you want to give this DNA this Sequence and + * forget about it, then just hand it this sequence and set + * seq to NULL (no need to free it). If you intend to use + * the sequence object elsewhere outside of the DNA datastructure + * then use DNA_from_Sequence(/hard_link_Sequence(seq)) + * + * + * + * Arg: seq [UNKN ] Sequence to make DNA from [Sequence *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +DNA * bp_sw_DNA_from_Sequence(Sequence * seq); +#define DNA_from_Sequence bp_sw_DNA_from_Sequence + + +/* Function: hard_link_DNA(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DNA *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +DNA * bp_sw_hard_link_DNA(DNA * obj); +#define hard_link_DNA bp_sw_hard_link_DNA + + +/* Function: DNA_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +DNA * bp_sw_DNA_alloc(void); +#define DNA_alloc bp_sw_DNA_alloc + + +/* Function: free_DNA(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [DNA *] + * + * Return [UNKN ] Undocumented return value [DNA *] + * + */ +DNA * bp_sw_free_DNA(DNA * obj); +#define free_DNA bp_sw_free_DNA + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/dnamatrix.c b/Bio/Ext/Align/libs/dnamatrix.c new file mode 100644 index 0000000..08f07d8 --- /dev/null +++ b/Bio/Ext/Align/libs/dnamatrix.c @@ -0,0 +1,416 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "dnamatrix.h" + +/* Function: DnaProbMatrix_from_match(match,type) + * + * Descrip: Makes a probability matrix from simple match/mismatch + * probabilities. + * + * + * + * Arg: match [UNKN ] Undocumented argument [Probability] + * Arg: type [UNKN ] Undocumented argument [NMaskType] + * + * Return [UNKN ] Undocumented return value [DnaProbMatrix *] + * + */ +# line 29 "dnamatrix.dy" +DnaProbMatrix * DnaProbMatrix_from_match(Probability match,NMaskType type) +{ + int i,j; + DnaProbMatrix * out; + Probability factor; + + switch (type ) { + case NMaskType_BASE : + factor = ((1.0 - match)/4.0); + break; + case NMaskType_VARIABLE : + case NMaskType_EXCLUDED : + case NMaskType_BANNED : + factor = ((1.0 - match)/3.0); + break; + default : + warn("No valid mask type. Ugh!"); + return NULL; + } + + + + out = DnaProbMatrix_alloc(); + + for(i=0;i<4;i++) { + for(j=0;j<4;j++) { + if( i == j ) { + out->prob[i][j] = match; + } else { + out->prob[i][j] = factor; + } + } + } + + for(i=0;i<5;i++) { + switch (type ) { + case NMaskType_BASE : + if( i == BASE_N ) { + out->prob[i][i] = match; + } else { + out->prob[BASE_N][i] = out->prob[i][BASE_N] = factor; + } + break; + case NMaskType_VARIABLE : + if( i == BASE_N ) { + out->prob[i][i] = 0.25; + } else { + out->prob[BASE_N][i] = out->prob[i][BASE_N] = 0.25; + } + break; + + case NMaskType_EXCLUDED : + if( i == BASE_N ) { + out->prob[i][i] = 1.0; + } else { + out->prob[BASE_N][i] = out->prob[i][BASE_N] = 0.0; + } + break; + case NMaskType_BANNED : + out->prob[BASE_N][i] = out->prob[i][BASE_N] = 0.0; + break; + default : + warn("No valid mask type. Ugh! Shouldn't be here. A BAD BAD bug!!!"); + } + + } + + return out; + +} + +/* Function: flat_null_DnaProbMatrix(dpm) + * + * Descrip: makes a odds of dpm via a 0.25 factor + * into each base. + * + * + * Arg: dpm [UNKN ] Undocumented argument [DnaProbMatrix *] + * + */ +# line 104 "dnamatrix.dy" +void flat_null_DnaProbMatrix(DnaProbMatrix * dpm) +{ + int i,j; + + for(i=0;i<4;i++) { + for(j=0;j<4;j++) { + dpm->prob[i][j] = dpm->prob[i][j]/0.25; + } + } + + return; +} + + +/* Function: DnaMatrix_from_DnaProbMatrix(dpm) + * + * Descrip: Maps probabilities to scores + * + * + * Arg: dpm [UNKN ] Undocumented argument [DnaProbMatrix *] + * + * Return [UNKN ] Undocumented return value [DnaMatrix *] + * + */ +# line 121 "dnamatrix.dy" +DnaMatrix * DnaMatrix_from_DnaProbMatrix(DnaProbMatrix * dpm) +{ + int i,j; + DnaMatrix * out; + + out = DnaMatrix_alloc(); + for(i=0;i<5;i++) + for(j=0;j<5;j++) + out->score[i][j] = Probability2Score(dpm->prob[i][j]); + + return out; +} + +/* Function: show_DnaMatrix(dcm,ofp) + * + * Descrip: Simple view of DnaMatrix + * + * + * Arg: dcm [UNKN ] Undocumented argument [DnaMatrix *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 137 "dnamatrix.dy" +void show_DnaMatrix(DnaMatrix * dcm,FILE * ofp) +{ + int i,j; + + for(i=0;i<5;i++) { + for(j=0;j<5;j++) { + fprintf(ofp,"%c %c - %d\n",char_from_base(i),char_from_base(j),dcm->score[i][j]); + } + } +} + +/* Function: show_DnaProbMatrix(dpm,ofp) + * + * Descrip: Simple view of DnaProbMatrix + * + * + * Arg: dpm [UNKN ] Undocumented argument [DnaProbMatrix *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 151 "dnamatrix.dy" +void show_DnaProbMatrix(DnaProbMatrix * dpm,FILE * ofp) +{ + int i,j; + + for(i=0;i<5;i++) { + for(j=0;j<5;j++) { + fprintf(ofp,"%c %c - %g\n",char_from_base(i),char_from_base(j),dpm->prob[i][j]); + } + } +} + + +/* Function: fail_safe_DnaMatrix_access(dm,one,two) + * + * Descrip: Run-time checked that one and two are ok to pass + * into dm as bases + * + * + * + * Arg: dm [UNKN ] DnaMatrix to get score from [DnaMatrix *] + * Arg: one [UNKN ] base of one sequence [base] + * Arg: two [UNKN ] base of the other sequence [base] + * + * Return [UNKN ] Undocumented return value [Score] + * + */ +# line 172 "dnamatrix.dy" +Score fail_safe_DnaMatrix_access(DnaMatrix * dm,base one,base two) +{ + if( dm == NULL) { + warn("Passing in a NULL dna matrix into fail_safe_DnaMatrix_access, can't get a score therefore"); + return 0; + } + + if( one < 0 || one > 4 || two < 0 || two > 4 ) { + warn("In fail safe DnaMatrix access, trying to access a position [%d][%d] where this is meant to be 0-4",one,two); + return 0; + } + + return dm->score[one][two]; +} + +/* Function: identity_DnaMatrix(id_score,mismatch) + * + * Descrip: makes an idenity matrix wth id_score on the leading + * diagonal and mismatch elsewhere. + * + * + * + * Arg: id_score [UNKN ] score of idenities [Score] + * Arg: mismatch [UNKN ] score of mistmatches [Score] + * + * Return [UNKN ] Undocumented return value [DnaMatrix *] + * + */ +# line 195 "dnamatrix.dy" +DnaMatrix * identity_DnaMatrix(Score id_score,Score mismatch) +{ + DnaMatrix * out; + int i; + int j; + + out = DnaMatrix_alloc(); + + for(i=0;i<4;i++) + for(j=i;j<4;j++) { + if( i == j ) + out->score[i][j] = id_score; + else + out->score[i][j] = out->score[j][i] = mismatch; + } + + for(i=0;i<4;i++) { + out->score[i][4] = out->score[4][i] = 0; + } + out->score[4][4] = 0; + + return out; +} + +# line 235 "dnamatrix.c" +/* Function: hard_link_DnaProbMatrix(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DnaProbMatrix *] + * + * Return [UNKN ] Undocumented return value [DnaProbMatrix *] + * + */ +DnaProbMatrix * hard_link_DnaProbMatrix(DnaProbMatrix * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a DnaProbMatrix object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: DnaProbMatrix_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DnaProbMatrix *] + * + */ +DnaProbMatrix * DnaProbMatrix_alloc(void) +{ + DnaProbMatrix * out;/* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(DnaProbMatrix *) ckalloc (sizeof(DnaProbMatrix))) == NULL) { + warn("DnaProbMatrix_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + /* prob[5][5] is an array: no default possible */ + + + return out; +} + + +/* Function: free_DnaProbMatrix(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [DnaProbMatrix *] + * + * Return [UNKN ] Undocumented return value [DnaProbMatrix *] + * + */ +DnaProbMatrix * free_DnaProbMatrix(DnaProbMatrix * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a DnaProbMatrix obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + + + ckfree(obj); + return NULL; +} + + +/* Function: hard_link_DnaMatrix(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DnaMatrix *] + * + * Return [UNKN ] Undocumented return value [DnaMatrix *] + * + */ +DnaMatrix * hard_link_DnaMatrix(DnaMatrix * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a DnaMatrix object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: DnaMatrix_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DnaMatrix *] + * + */ +DnaMatrix * DnaMatrix_alloc(void) +{ + DnaMatrix * out;/* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(DnaMatrix *) ckalloc (sizeof(DnaMatrix))) == NULL) { + warn("DnaMatrix_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + /* score[5][5] is an array: no default possible */ + + + return out; +} + + +/* Function: free_DnaMatrix(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [DnaMatrix *] + * + * Return [UNKN ] Undocumented return value [DnaMatrix *] + * + */ +DnaMatrix * free_DnaMatrix(DnaMatrix * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a DnaMatrix obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + + + ckfree(obj); + return NULL; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/dnamatrix.h b/Bio/Ext/Align/libs/dnamatrix.h new file mode 100644 index 0000000..62d8f41 --- /dev/null +++ b/Bio/Ext/Align/libs/dnamatrix.h @@ -0,0 +1,252 @@ +#ifndef DYNAMITEdnamatrixHEADERFILE +#define DYNAMITEdnamatrixHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "dyna.h" + +typedef enum NMaskType { + NMaskType_BASE, + NMaskType_VARIABLE, + NMaskType_EXCLUDED, + NMaskType_BANNED +} NMaskType; + +struct bp_sw_DnaProbMatrix { + int dynamite_hard_link; + Probability prob[5][5]; + } ; +/* DnaProbMatrix defined */ +#ifndef DYNAMITE_DEFINED_DnaProbMatrix +typedef struct bp_sw_DnaProbMatrix bp_sw_DnaProbMatrix; +#define DnaProbMatrix bp_sw_DnaProbMatrix +#define DYNAMITE_DEFINED_DnaProbMatrix +#endif + + +struct bp_sw_DnaMatrix { + int dynamite_hard_link; + Score score[5][5]; + } ; +/* DnaMatrix defined */ +#ifndef DYNAMITE_DEFINED_DnaMatrix +typedef struct bp_sw_DnaMatrix bp_sw_DnaMatrix; +#define DnaMatrix bp_sw_DnaMatrix +#define DYNAMITE_DEFINED_DnaMatrix +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: DnaProbMatrix_from_match(match,type) + * + * Descrip: Makes a probability matrix from simple match/mismatch + * probabilities. + * + * + * + * Arg: match [UNKN ] Undocumented argument [Probability] + * Arg: type [UNKN ] Undocumented argument [NMaskType] + * + * Return [UNKN ] Undocumented return value [DnaProbMatrix *] + * + */ +DnaProbMatrix * bp_sw_DnaProbMatrix_from_match(Probability match,NMaskType type); +#define DnaProbMatrix_from_match bp_sw_DnaProbMatrix_from_match + + +/* Function: flat_null_DnaProbMatrix(dpm) + * + * Descrip: makes a odds of dpm via a 0.25 factor + * into each base. + * + * + * Arg: dpm [UNKN ] Undocumented argument [DnaProbMatrix *] + * + */ +void bp_sw_flat_null_DnaProbMatrix(DnaProbMatrix * dpm); +#define flat_null_DnaProbMatrix bp_sw_flat_null_DnaProbMatrix + + +/* Function: DnaMatrix_from_DnaProbMatrix(dpm) + * + * Descrip: Maps probabilities to scores + * + * + * Arg: dpm [UNKN ] Undocumented argument [DnaProbMatrix *] + * + * Return [UNKN ] Undocumented return value [DnaMatrix *] + * + */ +DnaMatrix * bp_sw_DnaMatrix_from_DnaProbMatrix(DnaProbMatrix * dpm); +#define DnaMatrix_from_DnaProbMatrix bp_sw_DnaMatrix_from_DnaProbMatrix + + +/* Function: show_DnaMatrix(dcm,ofp) + * + * Descrip: Simple view of DnaMatrix + * + * + * Arg: dcm [UNKN ] Undocumented argument [DnaMatrix *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_show_DnaMatrix(DnaMatrix * dcm,FILE * ofp); +#define show_DnaMatrix bp_sw_show_DnaMatrix + + +/* Function: show_DnaProbMatrix(dpm,ofp) + * + * Descrip: Simple view of DnaProbMatrix + * + * + * Arg: dpm [UNKN ] Undocumented argument [DnaProbMatrix *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_show_DnaProbMatrix(DnaProbMatrix * dpm,FILE * ofp); +#define show_DnaProbMatrix bp_sw_show_DnaProbMatrix + + +/* Function: fail_safe_DnaMatrix_access(dm,one,two) + * + * Descrip: Run-time checked that one and two are ok to pass + * into dm as bases + * + * + * + * Arg: dm [UNKN ] DnaMatrix to get score from [DnaMatrix *] + * Arg: one [UNKN ] base of one sequence [base] + * Arg: two [UNKN ] base of the other sequence [base] + * + * Return [UNKN ] Undocumented return value [Score] + * + */ +Score bp_sw_fail_safe_DnaMatrix_access(DnaMatrix * dm,base one,base two); +#define fail_safe_DnaMatrix_access bp_sw_fail_safe_DnaMatrix_access + + +/* Function: identity_DnaMatrix(id_score,mismatch) + * + * Descrip: makes an idenity matrix wth id_score on the leading + * diagonal and mismatch elsewhere. + * + * + * + * Arg: id_score [UNKN ] score of idenities [Score] + * Arg: mismatch [UNKN ] score of mistmatches [Score] + * + * Return [UNKN ] Undocumented return value [DnaMatrix *] + * + */ +DnaMatrix * bp_sw_identity_DnaMatrix(Score id_score,Score mismatch); +#define identity_DnaMatrix bp_sw_identity_DnaMatrix + + +/* Function: hard_link_DnaProbMatrix(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DnaProbMatrix *] + * + * Return [UNKN ] Undocumented return value [DnaProbMatrix *] + * + */ +DnaProbMatrix * bp_sw_hard_link_DnaProbMatrix(DnaProbMatrix * obj); +#define hard_link_DnaProbMatrix bp_sw_hard_link_DnaProbMatrix + + +/* Function: DnaProbMatrix_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DnaProbMatrix *] + * + */ +DnaProbMatrix * bp_sw_DnaProbMatrix_alloc(void); +#define DnaProbMatrix_alloc bp_sw_DnaProbMatrix_alloc + + +/* Function: free_DnaProbMatrix(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [DnaProbMatrix *] + * + * Return [UNKN ] Undocumented return value [DnaProbMatrix *] + * + */ +DnaProbMatrix * bp_sw_free_DnaProbMatrix(DnaProbMatrix * obj); +#define free_DnaProbMatrix bp_sw_free_DnaProbMatrix + + +/* Function: hard_link_DnaMatrix(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DnaMatrix *] + * + * Return [UNKN ] Undocumented return value [DnaMatrix *] + * + */ +DnaMatrix * bp_sw_hard_link_DnaMatrix(DnaMatrix * obj); +#define hard_link_DnaMatrix bp_sw_hard_link_DnaMatrix + + +/* Function: DnaMatrix_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DnaMatrix *] + * + */ +DnaMatrix * bp_sw_DnaMatrix_alloc(void); +#define DnaMatrix_alloc bp_sw_DnaMatrix_alloc + + +/* Function: free_DnaMatrix(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [DnaMatrix *] + * + * Return [UNKN ] Undocumented return value [DnaMatrix *] + * + */ +DnaMatrix * bp_sw_free_DnaMatrix(DnaMatrix * obj); +#define free_DnaMatrix bp_sw_free_DnaMatrix + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/dpenvelope.c b/Bio/Ext/Align/libs/dpenvelope.c new file mode 100644 index 0000000..330d7cf --- /dev/null +++ b/Bio/Ext/Align/libs/dpenvelope.c @@ -0,0 +1,517 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "dpenvelope.h" + +/* Function: show_DPEnvelope(dpe,ofp) + * + * Descrip: shows structure. useful for debugging + * + * + * Arg: dpe [UNKN ] Undocumented argument [DPEnvelope *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 31 "dpenvelope.dy" +void show_DPEnvelope(DPEnvelope * dpe,FILE * ofp) +{ + int i; + + for(i=0;ilen;i++) { + fprintf(ofp,"Unit [%d] %d-%d %d-%d\n",i,dpe->dpu[i]->starti,dpe->dpu[i]->startj,dpe->dpu[i]->starti+dpe->dpu[i]->height,dpe->dpu[i]->startj+dpe->dpu[i]->length); + } + +} + +/* Function: is_in_DPEnvelope(dpe,i,j) + * + * Descrip: Tests whether this i,j position is allowed in the + * DPEnvelope + * + * + * Arg: dpe [UNKN ] Undocumented argument [DPEnvelope *] + * Arg: i [UNKN ] Undocumented argument [int] + * Arg: j [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 45 "dpenvelope.dy" +boolean is_in_DPEnvelope(DPEnvelope * dpe,int i,int j) +{ + int k; + + for(k=0;klen;k++) { + auto DPUnit * u; + u = dpe->dpu[k]; + /* sorted by startj position */ + if( j < u->startj ) + return FALSE; + + + switch (u->type) { + + case DPENV_RECT : + if( i >= u->starti && j >= u->startj && i <= (u->starti+u->height) && j <= (u->startj+u->length) ) + return TRUE; + else + break; + case DPENV_DIAG : + warn("Can't do diagonals yet."); + return FALSE; + default : + warn("Bad DPUnit type put in. Yuk. Bad error... %d",u->type); + return FALSE; + } + } + + /* bad error to get here! */ + return FALSE; +} + +/* Function: prepare_DPEnvelope(dpe) + * + * Descrip: Should run this before using the DPEnvelope + * + * + * Arg: dpe [UNKN ] Undocumented argument [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 80 "dpenvelope.dy" +boolean prepare_DPEnvelope(DPEnvelope * dpe) +{ + int i; + + for(i=0;ilen;i++) + if( dpe->dpu[i]->type != DPENV_RECT ) { + warn("Bad envelope type %d",dpe->dpu[i]->type); + return FALSE; + } + + sort_DPEnvelope_by_startj(dpe); + return TRUE; +} + +/* Function: sort_DPEnvelope_by_startj(dpe) + * + * Descrip: Sorts by startj + * + * + * Arg: dpe [UNKN ] Undocumented argument [DPEnvelope *] + * + */ +# line 97 "dpenvelope.dy" +void sort_DPEnvelope_by_startj(DPEnvelope * dpe) +{ + sort_DPEnvelope(dpe,compare_DPUnit_startj); +} + +/* Function: compare_DPUnit_startj(one,two) + * + * Descrip: internal for sort by startj + * + * + * Arg: one [UNKN ] Undocumented argument [DPUnit *] + * Arg: two [UNKN ] Undocumented argument [DPUnit *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 106 "dpenvelope.dy" +int compare_DPUnit_startj(DPUnit * one,DPUnit * two) +{ + return one->startj - two->startj; +} + + + + + + + +# line 123 "dpenvelope.c" +/* Function: hard_link_DPUnit(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DPUnit *] + * + * Return [UNKN ] Undocumented return value [DPUnit *] + * + */ +DPUnit * hard_link_DPUnit(DPUnit * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a DPUnit object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: DPUnit_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DPUnit *] + * + */ +DPUnit * DPUnit_alloc(void) +{ + DPUnit * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(DPUnit *) ckalloc (sizeof(DPUnit))) == NULL) { + warn("DPUnit_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->type = DPENV_RECT; + out->starti = 0; + out->startj = 0; + out->height = 0; + out->length = 0; + + + return out; +} + + +/* Function: free_DPUnit(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [DPUnit *] + * + * Return [UNKN ] Undocumented return value [DPUnit *] + * + */ +DPUnit * free_DPUnit(DPUnit * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a DPUnit obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + + + ckfree(obj); + return NULL; +} + + +/* Function: swap_DPEnvelope(list,i,j) + * + * Descrip: swap function: an internal for qsort_DPEnvelope + * swaps two positions in the array + * + * + * Arg: list [UNKN ] List of structures to swap in [DPUnit **] + * Arg: i [UNKN ] swap position [int] + * Arg: j [UNKN ] swap position [int] + * + */ +/* swap function for qsort function */ +void swap_DPEnvelope(DPUnit ** list,int i,int j) +{ + DPUnit * temp; + temp=list[i]; + list[i]=list[j]; + list[j]=temp; +} + + +/* Function: qsort_DPEnvelope(list,left,right,comp) + * + * Descrip: qsort - lifted from K&R + * sorts the array using quicksort + * Probably much better to call sort_DPEnvelope which sorts from start to end + * + * + * Arg: list [UNKN ] List of structures to swap in [DPUnit **] + * Arg: left [UNKN ] left position [int] + * Arg: right [UNKN ] right position [int] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void qsort_DPEnvelope(DPUnit ** list,int left,int right,int (*comp)(DPUnit * ,DPUnit * )) +{ + int i,last; + if( left >= right ) + return; + + + swap_DPEnvelope(list,left,(left+right)/2); + last = left; + for ( i=left+1; i <= right;i++) { + if( (*comp)(list[i],list[left]) < 0) + swap_DPEnvelope (list,++last,i); + } + swap_DPEnvelope (list,left,last); + qsort_DPEnvelope(list,left,last-1,comp); + qsort_DPEnvelope(list,last+1,right,comp); +} + + +/* Function: sort_DPEnvelope(obj,comp) + * + * Descrip: sorts from start to end using comp + * sorts the array using quicksort by calling qsort_DPEnvelope + * + * + * Arg: obj [UNKN ] Object containing list [DPEnvelope *] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void sort_DPEnvelope(DPEnvelope * obj,int (*comp)(DPUnit *, DPUnit *)) +{ + qsort_DPEnvelope(obj->dpu,0,obj->len-1,comp); + return; +} + + +/* Function: expand_DPEnvelope(obj,len) + * + * Descrip: Really an internal function for add_DPEnvelope + * + * + * Arg: obj [UNKN ] Object which contains the list [DPEnvelope *] + * Arg: len [UNKN ] Length to add one [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean expand_DPEnvelope(DPEnvelope * obj,int len) +{ + + + if( obj->maxlen > obj->len ) { + warn("expand_DPEnvelope called with no need"); + return TRUE; + } + + + if( (obj->dpu = (DPUnit ** ) ckrealloc (obj->dpu,sizeof(DPUnit *)*len)) == NULL) { + warn("ckrealloc failed for expand_DPEnvelope, returning FALSE"); + return FALSE; + } + obj->maxlen = len; + return TRUE; +} + + +/* Function: add_DPEnvelope(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [DPEnvelope *] + * Arg: add [OWNER] Object to add to the list [DPUnit *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +/* will expand function if necessary */ +boolean add_DPEnvelope(DPEnvelope * obj,DPUnit * add) +{ + if( obj->len >= obj->maxlen) { + if( expand_DPEnvelope(obj,obj->len + DPEnvelopeLISTLENGTH) == FALSE) + return FALSE; + } + + + obj->dpu[obj->len++]=add; + return TRUE; +} + + +/* Function: flush_DPEnvelope(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int flush_DPEnvelope(DPEnvelope * obj) +{ + int i; + + + for(i=0;ilen;i++) { + if( obj->dpu[i] != NULL) { + free_DPUnit(obj->dpu[i]); + obj->dpu[i] = NULL; + } + } /* end of for i over list length */ + + + obj->len = 0; + return i; +} + + +/* Function: DPEnvelope_alloc_std(void) + * + * Descrip: Equivalent to DPEnvelope_alloc_len(DPEnvelopeLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [DPEnvelope *] + * + */ +DPEnvelope * DPEnvelope_alloc_std(void) +{ + return DPEnvelope_alloc_len(DPEnvelopeLISTLENGTH); +} + + +/* Function: DPEnvelope_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [DPEnvelope *] + * + */ +DPEnvelope * DPEnvelope_alloc_len(int len) +{ + DPEnvelope * out; /* out is exported at the end of function */ + + + /* Call alloc function: return NULL if NULL */ + /* Warning message alread in alloc function */ + if((out = DPEnvelope_alloc()) == NULL) + return NULL; + + + /* Calling ckcalloc for list elements */ + if((out->dpu = (DPUnit ** ) ckcalloc (len,sizeof(DPUnit *))) == NULL) { + warn("Warning, ckcalloc failed in DPEnvelope_alloc_len"); + return NULL; + } + out->len = 0; + out->maxlen = len; + + + return out; +} + + +/* Function: hard_link_DPEnvelope(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [DPEnvelope *] + * + */ +DPEnvelope * hard_link_DPEnvelope(DPEnvelope * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a DPEnvelope object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: DPEnvelope_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DPEnvelope *] + * + */ +DPEnvelope * DPEnvelope_alloc(void) +{ + DPEnvelope * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(DPEnvelope *) ckalloc (sizeof(DPEnvelope))) == NULL) { + warn("DPEnvelope_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->dpu = NULL; + out->len = out->maxlen = 0; + + + return out; +} + + +/* Function: free_DPEnvelope(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [DPEnvelope *] + * + */ +DPEnvelope * free_DPEnvelope(DPEnvelope * obj) +{ + int i; + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a DPEnvelope obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->dpu != NULL) { + for(i=0;ilen;i++) { + if( obj->dpu[i] != NULL) + free_DPUnit(obj->dpu[i]); + } + ckfree(obj->dpu); + } + + + ckfree(obj); + return NULL; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/dpenvelope.h b/Bio/Ext/Align/libs/dpenvelope.h new file mode 100644 index 0000000..4755945 --- /dev/null +++ b/Bio/Ext/Align/libs/dpenvelope.h @@ -0,0 +1,276 @@ +#ifndef DYNAMITEdpenvelopeHEADERFILE +#define DYNAMITEdpenvelopeHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" + +typedef enum dpenvelope_type { + DPENV_RECT = 0, + DPENV_DIAG +} dpenv_type; + +#define DPEnvelopeLISTLENGTH 32 +struct bp_sw_DPUnit { + int dynamite_hard_link; + int type; + int starti; + int startj; + int height; /* for diagonal units */ + int length; /* for diagonal units */ + } ; +/* DPUnit defined */ +#ifndef DYNAMITE_DEFINED_DPUnit +typedef struct bp_sw_DPUnit bp_sw_DPUnit; +#define DPUnit bp_sw_DPUnit +#define DYNAMITE_DEFINED_DPUnit +#endif + + +struct bp_sw_DPEnvelope { + int dynamite_hard_link; + DPUnit ** dpu; + int len;/* len for above dpu */ + int maxlen; /* maxlen for above dpu */ + } ; +/* DPEnvelope defined */ +#ifndef DYNAMITE_DEFINED_DPEnvelope +typedef struct bp_sw_DPEnvelope bp_sw_DPEnvelope; +#define DPEnvelope bp_sw_DPEnvelope +#define DYNAMITE_DEFINED_DPEnvelope +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: show_DPEnvelope(dpe,ofp) + * + * Descrip: shows structure. useful for debugging + * + * + * Arg: dpe [UNKN ] Undocumented argument [DPEnvelope *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_show_DPEnvelope(DPEnvelope * dpe,FILE * ofp); +#define show_DPEnvelope bp_sw_show_DPEnvelope + + +/* Function: is_in_DPEnvelope(dpe,i,j) + * + * Descrip: Tests whether this i,j position is allowed in the + * DPEnvelope + * + * + * Arg: dpe [UNKN ] Undocumented argument [DPEnvelope *] + * Arg: i [UNKN ] Undocumented argument [int] + * Arg: j [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_is_in_DPEnvelope(DPEnvelope * dpe,int i,int j); +#define is_in_DPEnvelope bp_sw_is_in_DPEnvelope + + +/* Function: prepare_DPEnvelope(dpe) + * + * Descrip: Should run this before using the DPEnvelope + * + * + * Arg: dpe [UNKN ] Undocumented argument [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_prepare_DPEnvelope(DPEnvelope * dpe); +#define prepare_DPEnvelope bp_sw_prepare_DPEnvelope + + +/* Function: sort_DPEnvelope_by_startj(dpe) + * + * Descrip: Sorts by startj + * + * + * Arg: dpe [UNKN ] Undocumented argument [DPEnvelope *] + * + */ +void bp_sw_sort_DPEnvelope_by_startj(DPEnvelope * dpe); +#define sort_DPEnvelope_by_startj bp_sw_sort_DPEnvelope_by_startj + + +/* Function: hard_link_DPUnit(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DPUnit *] + * + * Return [UNKN ] Undocumented return value [DPUnit *] + * + */ +DPUnit * bp_sw_hard_link_DPUnit(DPUnit * obj); +#define hard_link_DPUnit bp_sw_hard_link_DPUnit + + +/* Function: DPUnit_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DPUnit *] + * + */ +DPUnit * bp_sw_DPUnit_alloc(void); +#define DPUnit_alloc bp_sw_DPUnit_alloc + + +/* Function: free_DPUnit(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [DPUnit *] + * + * Return [UNKN ] Undocumented return value [DPUnit *] + * + */ +DPUnit * bp_sw_free_DPUnit(DPUnit * obj); +#define free_DPUnit bp_sw_free_DPUnit + + +/* Function: add_DPEnvelope(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [DPEnvelope *] + * Arg: add [OWNER] Object to add to the list [DPUnit *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_DPEnvelope(DPEnvelope * obj,DPUnit * add); +#define add_DPEnvelope bp_sw_add_DPEnvelope + + +/* Function: flush_DPEnvelope(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_flush_DPEnvelope(DPEnvelope * obj); +#define flush_DPEnvelope bp_sw_flush_DPEnvelope + + +/* Function: DPEnvelope_alloc_std(void) + * + * Descrip: Equivalent to DPEnvelope_alloc_len(DPEnvelopeLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [DPEnvelope *] + * + */ +DPEnvelope * bp_sw_DPEnvelope_alloc_std(void); +#define DPEnvelope_alloc_std bp_sw_DPEnvelope_alloc_std + + +/* Function: DPEnvelope_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [DPEnvelope *] + * + */ +DPEnvelope * bp_sw_DPEnvelope_alloc_len(int len); +#define DPEnvelope_alloc_len bp_sw_DPEnvelope_alloc_len + + +/* Function: hard_link_DPEnvelope(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [DPEnvelope *] + * + */ +DPEnvelope * bp_sw_hard_link_DPEnvelope(DPEnvelope * obj); +#define hard_link_DPEnvelope bp_sw_hard_link_DPEnvelope + + +/* Function: DPEnvelope_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DPEnvelope *] + * + */ +DPEnvelope * bp_sw_DPEnvelope_alloc(void); +#define DPEnvelope_alloc bp_sw_DPEnvelope_alloc + + +/* Function: free_DPEnvelope(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [DPEnvelope *] + * + */ +DPEnvelope * bp_sw_free_DPEnvelope(DPEnvelope * obj); +#define free_DPEnvelope bp_sw_free_DPEnvelope + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +int bp_sw_compare_DPUnit_startj(DPUnit * one,DPUnit * two); +#define compare_DPUnit_startj bp_sw_compare_DPUnit_startj +void bp_sw_swap_DPEnvelope(DPUnit ** list,int i,int j) ; +#define swap_DPEnvelope bp_sw_swap_DPEnvelope +void bp_sw_qsort_DPEnvelope(DPUnit ** list,int left,int right,int (*comp)(DPUnit * ,DPUnit * )); +#define qsort_DPEnvelope bp_sw_qsort_DPEnvelope +void bp_sw_sort_DPEnvelope(DPEnvelope * obj,int (*comp)(DPUnit *, DPUnit *)); +#define sort_DPEnvelope bp_sw_sort_DPEnvelope +boolean bp_sw_expand_DPEnvelope(DPEnvelope * obj,int len); +#define expand_DPEnvelope bp_sw_expand_DPEnvelope + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/dyna.h b/Bio/Ext/Align/libs/dyna.h new file mode 100644 index 0000000..ca8d73f --- /dev/null +++ b/Bio/Ext/Align/libs/dyna.h @@ -0,0 +1,42 @@ +/* Last edited: Mar 16 17:36 1997 (birney) */ + + +#ifndef DYNAMITEHELPERHEADERFILE +#define DYNAMITEHELPERHEADERFILE + + +/*** this file includes all the correct files + for libdyn linking ***/ + + +#include "packaln.h" +#include "basematrix.h" +#include "dpenvelope.h" + +#include "sequence.h" +#include "proteindb.h" +#include "database.h" +#include "hscore.h" +#include "histogram.h" +#include "aln.h" +#include "linesubs.h" +#include "complexsequence.h" +#include "complexevalset.h" +#include "alnconvert.h" +#include "alnrange.h" +#include "compmat.h" +#include "dnamatrix.h" +#include "protein.h" +#include "dna.h" + +#include "btcanvas.h" +#include "asciibtcanvas.h" + +#include "dynlibcross.h" +#endif + + + + + + diff --git a/Bio/Ext/Align/libs/dynlibcross.c b/Bio/Ext/Align/libs/dynlibcross.c new file mode 100644 index 0000000..3680207 --- /dev/null +++ b/Bio/Ext/Align/libs/dynlibcross.c @@ -0,0 +1,81 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "dynlibcross.h" + + +/* Function: std_bits_Hscore(cut_off_level,report_stagger) + * + * Descrip: This gives you a standard Hscore + * module with a cutoff in bits (assumming + * the score is being made from a standard + * Probability2Score type function). + * + * + * Arg: cut_off_level [UNKN ] Undocumented argument [double] + * Arg: report_stagger [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [Hscore *] + * + */ +# line 21 "dynlibcross.dy" +Hscore * std_bits_Hscore(double cut_off_level,int report_stagger) +{ + Hscore * out; + + out = Hscore_alloc_std(); + out->his = new_Histogram(-1000,1000,100); + out->score_level = cut_off_level; + out->should_store = std_should_store_Hscore; + out->score_to_his = std_score_to_his; + out->report_level = report_stagger; + + return out; +} + + +/* Function: std_should_store_Hscore(score,cutoff) + * + * Descrip: This function is for the Hscore std constructor, + * + * + * Arg: score [UNKN ] Undocumented argument [int] + * Arg: cutoff [UNKN ] Undocumented argument [double] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 40 "dynlibcross.dy" +boolean std_should_store_Hscore(int score,double cutoff) +{ + if( Score2Bits(score) > cutoff ) { + return TRUE; + } + return FALSE; +} + +/* Function: std_score_to_his(score) + * + * Descrip: This function is for the Hscore std constructor, + * + * + * Arg: score [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [float] + * + */ +# line 52 "dynlibcross.dy" +float std_score_to_his(int score) +{ + return Score2Bits(score); +} + + + + + +# line 70 "dynlibcross.c" + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/dynlibcross.h b/Bio/Ext/Align/libs/dynlibcross.h new file mode 100644 index 0000000..dddf922 --- /dev/null +++ b/Bio/Ext/Align/libs/dynlibcross.h @@ -0,0 +1,54 @@ +#ifndef DYNAMITEdynlibcrossHEADERFILE +#define DYNAMITEdynlibcrossHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "dyna.h" + + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: std_bits_Hscore(cut_off_level,report_stagger) + * + * Descrip: This gives you a standard Hscore + * module with a cutoff in bits (assumming + * the score is being made from a standard + * Probability2Score type function). + * + * + * Arg: cut_off_level [UNKN ] Undocumented argument [double] + * Arg: report_stagger [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [Hscore *] + * + */ +Hscore * bp_sw_std_bits_Hscore(double cut_off_level,int report_stagger); +#define std_bits_Hscore bp_sw_std_bits_Hscore + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +boolean bp_sw_std_should_store_Hscore(int score,double cutoff); +#define std_should_store_Hscore bp_sw_std_should_store_Hscore +float bp_sw_std_score_to_his(int score); +#define std_score_to_his bp_sw_std_score_to_his + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/histogram.c b/Bio/Ext/Align/libs/histogram.c new file mode 100644 index 0000000..774affc --- /dev/null +++ b/Bio/Ext/Align/libs/histogram.c @@ -0,0 +1,1565 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "histogram.h" + + +/* Function: Evalue_from_Histogram(his,score) + * + * Descrip: No Description + * + * Arg: his [UNKN ] Histogram object [Histogram *] + * Arg: score [UNKN ] score you want the evalue for [double] + * + * Return [UNKN ] Undocumented return value [double] + * + */ +# line 85 "histogram.dy" +double Evalue_from_Histogram(Histogram * his,double score) +{ + return ExtremeValueE(score,his->param[EVD_MU],his->param[EVD_LAMBDA],his->total); +} + +/* Function: new_Histogram(min,max,lumpsize) + * + * Descrip: No Description + * + * Arg: min [UNKN ] minimum score (integer) [int] + * Arg: max [UNKN ] maximum score (integer) [int] + * Arg: lumpsize [UNKN ] when reallocating histogram, the reallocation amount [int] + * + * Return [UNKN ] Undocumented return value [Histogram *] + * + */ +# line 113 "histogram.dy" +Histogram * new_Histogram(int min, int max, int lumpsize) +{ + Histogram *h; + int newsize; + int i; + + newsize = max - min + 1; + + h = Histogram_alloc(); /* ewan changed */ + if( h == NULL ) { + return NULL; + } + + h->min = min; + h->max = max; + h->total = 0; + h->lowscore = INT_MAX; + h->highscore = INT_MIN; + h->lumpsize = lumpsize; + h->histogram = (int *) ckcalloc (newsize,sizeof(int)); /* ewan changed */ + for (i = 0; i < newsize; i++) h->histogram[i] = 0; + + h->expect = NULL; + h->fit_type = HISTFIT_NONE; + + h->param[EVD_WONKA] = 1.0; /* just in case, make sure this initializes */ + + return h; +} + + +/* Function: UnfitHistogram(h) + * + * Descrip: No Description + * + * Arg: h [UNKN ] Undocumented argument [Histogram *] + * + */ +# line 156 "histogram.dy" +void UnfitHistogram(Histogram * h) +{ + if (h->expect != NULL) + ckfree(h->expect); + h->expect = NULL; + h->fit_type = HISTFIT_NONE; +} + + + +/* Function: AddToHistogram(h,sc) + * + * Descrip: No Description + * + * Arg: h [UNKN ] Undocumented argument [Histogram *] + * Arg: sc [UNKN ] Undocumented argument [float] + * + */ +# line 182 "histogram.dy" +void AddToHistogram(Histogram * h, float sc) +{ + int score; + int moveby; + int prevsize; + int newsize; + int i; + + /* Adding to a histogram conflicts with existing fit: + * prohibit this. + */ + if (h->fit_type != HISTFIT_NONE) + fatal("AddToHistogram(): Can't add to a fitted histogram\n"); + + + /* histogram bins are defined as: score >= bin value, < bin+1 + * -1.9 -> -2 -0.4 -> -1 1.9 -> 1 + * -2.1 -> -3 0.4 -> 0 2.1 -> 2 + */ + score = (int) floor(sc); + + /* Check to see if we must reallocate the histogram. + */ + if (score < h->min) + { + prevsize = h->max - h->min + 1; + moveby = (h->min - score) + h->lumpsize; + newsize = prevsize + moveby; + h->min -= moveby; + + h->histogram = (int *) ckrealloc(h->histogram, sizeof(int) * newsize); + if( h->histogram == NULL ) { + fatal("Unable to extend histogram... have to crash... sorry!"); + } + memmove(h->histogram+moveby, h->histogram, sizeof(int) * prevsize); + for (i = 0; i < moveby; i++) + h->histogram[i] = 0; + } + else if (score > h->max) + { + prevsize = h->max - h->min + 1; + h->max = h->lumpsize + score; + newsize = h->max - h->min + 1; + + h->histogram = (int *) ckrealloc(h->histogram, sizeof(int) * newsize); + if( h->histogram == NULL ) { + fatal("Cannot realloc histogram... going to die... sorry!"); + } + for (i = prevsize; i < newsize; i++) + h->histogram[i] = 0; + } + + /* Bump the correct bin. + * The bin number is score - h->min + */ + h->histogram[score - h->min]++; + h->total++; + if (score < h->lowscore) h->lowscore = score; + if (score > h->highscore) h->highscore = score; + +#if DEBUG + fprintf(stderr, "AddToHistogram(): added %.1f; rounded to %d; in bin %d (%d-%d)\n", + sc, score, score-h->min, h->min, h->max); +#endif + return; +} + + +/* Function: PrintASCIIHistogram(h,fp) + * + * Descrip: No Description + * + * Arg: h [UNKN ] histogram to print [Histogram *] + * Arg: fp [UNKN ] open file to print to (stdout works) [FILE *] + * + */ +# line 268 "histogram.dy" +void PrintASCIIHistogram(Histogram * h,FILE * fp) +{ + int units; + int maxbar; + int num; + int i, idx; + char buffer[81]; /* output line buffer */ + int pos; /* position in output line buffer */ + int lowbound, lowcount; /* cutoffs on the low side */ + int highbound, highcount; /* cutoffs on the high side */ + int emptybins = 3; + + /* Find out how we'll scale the histogram. + * We have 59 characters to play with on a + * standard 80-column terminal display: + * leading "%5d %6d %6d|" occupies 20 chars. + * Save the peak position, we'll use it later. + */ + maxbar = 0; + for (i = h->lowscore - h->min; i <= h->highscore - h->min; i++) + if (h->histogram[i] > maxbar) + { + maxbar = h->histogram[i]; /* max height */ + lowbound = i + h->min; /* peak position */ + } + + /* Truncate histogram display on both sides, ad hoc fashion. + * Start from the peak; then move out until we see empty bins, + * and stop. + */ + highbound = lowbound; /* start at peak position */ + for (num = 0; lowbound > h->lowscore; lowbound--) + { + i = lowbound - h->min; + if (h->histogram[i] > 0) { num = 0; continue; } /* reset */ + if (++num == emptybins) { lowbound += emptybins; break; } /* stop */ + } + for (num = 0; highbound < h->highscore; highbound++) + { + i = highbound - h->min; + if (h->histogram[i] > 0) { num = 0; continue; } /* reset */ + if (++num == emptybins) { highbound -= emptybins; break; } /* stop */ + } + /* collect counts outside of bounds */ + for (lowcount = 0, i = h->lowscore - h->min; i <= lowbound - h->min; i++) + lowcount += h->histogram[i]; + for (highcount = 0, i = h->highscore - h->min; i >= highbound - h->min; i--) + highcount += h->histogram[i]; + + /* maxbar might need raised now; then set our units */ + if (lowcount > maxbar) maxbar = lowcount; + if (highcount > maxbar) maxbar = highcount; + units = ((maxbar-1)/ 59) + 1; + + + /* Print the histogram + */ + fprintf(fp, "%5s %6s %6s (one = represents %d sequences)\n", + "score", "obs", "exp", units); + fprintf(fp, "%5s %6s %6s\n", "-----", "---", "---"); + buffer[80] = '\0'; + buffer[79] = '\n'; + for (i = h->lowscore; i <= h->highscore; i++) + { + memset(buffer, ' ', 79 * sizeof(char)); + idx = i - h->min; + + /* Deal with special cases at edges + */ + if (i < lowbound) continue; + else if (i > highbound) continue; + else if (i == lowbound && i != h->lowscore) + { + sprintf(buffer, "<%4d %6d %6s|", i+1, lowcount, "-"); + if (lowcount > 0) { + num = 1+(lowcount-1) / units; + if (num > 60) fatal("oops - more than 60 somethings in printing... "); + for (pos = 20; num > 0; num--) buffer[pos++] = '='; + } + fputs(buffer, fp); + continue; + } + else if (i == highbound && i != h->highscore) + { + sprintf(buffer, ">%4d %6d %6s|", i, highcount, "-"); + if (highcount > 0) { + num = 1+(highcount-1) / units; + for (pos = 20; num > 0; num--) buffer[pos++] = '='; + } + fputs(buffer, fp); + continue; + } + + /* Deal with most cases + */ + if (h->fit_type != HISTFIT_NONE) + sprintf(buffer, "%5d %6d %6d|", + i, h->histogram[idx], (int) h->expect[idx]); + else + sprintf(buffer, "%5d %6d %6s|", i, h->histogram[idx], "-"); + buffer[20] = ' '; /* sprintf writes a null char */ + + /* Mark the histogram bar for observed hits + */ + if (h->histogram[idx] > 0) { + num = 1 + (h->histogram[idx]-1) / units; + for (pos = 20; num > 0; num--) buffer[pos++] = '='; + } + + /* Mark the theoretically expected value + */ + if (h->fit_type != HISTFIT_NONE && (int) h->expect[idx] > 0) + { + /* "corrected" line */ +#ifdef SRE_REMOVED + if (h->fit_type == HISTFIT_EVD) + { + pos = 20 + (int)(h->param[EVD_WONKA] * h->expect[idx] - 1) / units; + if (pos >= 78) pos = 78; /* be careful of buffer bounds */ + buffer[pos] = 'o'; + } +#endif + /* true (uncorrected) line */ + pos = 20 + (int)(h->expect[idx]-1) / units; + if (pos >= 78) pos = 78; /* be careful of buffer bounds */ + buffer[pos] = '*'; + } + + /* Print the line + */ + fputs(buffer, fp); + } + + /* Print details about the statistics + */ + switch (h->fit_type) { + case HISTFIT_NONE: + fprintf(fp, "\n\n%% No statistical fit available\n"); + break; + + case HISTFIT_EVD: + fprintf(fp, "\n\n%% Statistical details of theoretical EVD fit:\n"); + fprintf(fp, " mu = %10.4f\n", h->param[EVD_MU]); + fprintf(fp, " lambda = %10.4f\n", h->param[EVD_LAMBDA]); +#ifdef SRE_REMOVED + fprintf(fp, " fraction fit = %10.4f\n", h->param[EVD_WONKA]); +#endif + fprintf(fp, "chi-sq statistic = %10.4f\n", h->chisq); + fprintf(fp, " P(chi-square) = %10.4g\n", h->chip); + break; + + case HISTFIT_GAUSSIAN: + fprintf(fp, "\n\n%% Statistical details of theoretical Gaussian fit:\n"); + fprintf(fp, " mean = %10.4f\n", h->param[GAUSS_MEAN]); + fprintf(fp, " sd = %10.4f\n", h->param[GAUSS_SD]); + fprintf(fp, "chi-sq statistic = %10.4f\n", h->chisq); + fprintf(fp, " P(chi-square) = %10.4g\n", h->chip); + break; + } + return; +} + + + +/* Function: EVDBasicFit(h) + * + * Descrip: No Description + * + * Arg: h [UNKN ] histogram to fit [Histogram *] + * + */ +# line 456 "histogram.dy" +void EVDBasicFit(Histogram * h) +{ + float *d; /* distribution P(S < x) */ + float *x; /* x-axis of P(Smin */ + float slope, intercept; /* m,b fit from Linefit() */ + float corr; /* correlation coeff of line fit, not used */ + float lambda, mu; /* slope, intercept converted to EVD params */ + + /* Allocations for x, y axes + * distribution d runs from min..max with indices 0..max-min + * i.e. score - min = index into d, x, histogram, and expect + */ + hsize = h->highscore - h->lowscore + 1; + d = (float *) ckalloc(sizeof(float) * hsize); + x = (float *) ckalloc(sizeof(float) * hsize); + for (idx = 0; idx < hsize; idx++) + d[idx] = x[idx] = 0.; + + /* Calculate P(S < x) distribution from histogram. + * note off-by-one of sc, because histogram bin contains scores between + * x and x+1. + */ + sum = 0; + for (sc = h->lowscore; sc <= h->highscore; sc++) + { + sum += h->histogram[sc - h->min]; + d[sc - h->lowscore] = (float) sum / (float) h->total; + x[sc - h->lowscore] = (float) (sc + 1); + } + + /* Do a linear regression fit to the log[-log(P(Sx))] = -lambda * x + lambda * mu + * so lambda = -m and mu = b/lambda + */ + /* convert y axis to log[-log(P(Slowscore; sc < h->highscore; sc++) + d[sc - h->lowscore] = log(-1. * log(d[sc - h->lowscore])); + + /* do the linear regression */ + Linefit(x, d, hsize-1, &intercept, &slope, &corr); + /* calc mu, lambda */ + lambda = -1. * slope; + mu = intercept / lambda; + + /* Set the EVD parameters in the histogram; + * pass 2 for additional lost degrees of freedom because we fit mu, lambda. + */ + ExtremeValueSetHistogram(h, mu, lambda, h->lowscore, h->highscore, 1.0, 2); + + free(x); + free(d); + return; +} + + +/* Function: ExtremeValueFitHistogram(h,censor,high_hint) + * + * Descrip: No Description + * + * Arg: h [UNKN ] histogram to fit [Histogram *] + * Arg: censor [UNKN ] TRUE to censor data left of the peak [int] + * Arg: high_hint [UNKN ] score cutoff; above this are real hits that arent fit [float] + * + * Return [UNKN ] if fit is judged to be valid else 0 if fit is invalid (too few seqs.) [int] + * + */ +# line 540 "histogram.dy" +int ExtremeValueFitHistogram(Histogram * h, int censor, float high_hint) +{ + float *x; /* array of EVD samples to fit */ + int *y; /* histogram counts */ + int n; /* number of observed samples */ + int z; /* number of censored samples */ + int hsize; /* size of histogram */ + float lambda, mu; /* new estimates of lambda, mu */ + int sc; /* loop index for score */ + int lowbound; /* lower bound of fitted region*/ + int highbound; /* upper bound of fitted region*/ + int new_highbound; + int iteration; + + /* Determine lower bound on fitted region; + * if we're censoring the data, choose the peak of the histogram. + * if we're not, then we take the whole histogram. + */ + lowbound = h->lowscore; + if (censor) + { + int max = -1; + for (sc = h->lowscore; sc <= h->highscore; sc++) + if (h->histogram[sc - h->min] > max) + { + max = h->histogram[sc - h->min]; + lowbound = sc; + } + } + + /* Determine initial upper bound on fitted region. + */ + highbound = MIN(high_hint, h->highscore); + + /* Now, iteratively converge on our lambda, mu: + */ + for (iteration = 0; iteration < 100; iteration++) + { + /* Construct x, y vectors. + */ + x = NULL; + y = NULL; + hsize = highbound - lowbound + 1; + if (hsize < 5) { + warn("On iteration %d, got %d bins, which is not fitable",iteration,hsize); + goto FITFAILED; /* require at least 5 bins or we don't fit */ + } + + + x = ckalloc(sizeof(float) * hsize); + y = ckalloc(sizeof(int) * hsize); + if( x == NULL || y == NULL ) { + warn("Out of temporary memory for evd fitting... exiting with error, though I'd worry about this"); + return 0; + } + + n = 0; + for (sc = lowbound; sc <= highbound; sc++) + { + x[sc-lowbound] = (float) sc + 0.5; /* crude, but tests OK */ + y[sc-lowbound] = h->histogram[sc - h->min]; + n += h->histogram[sc - h->min]; + } + + if (n < 100) { + warn("On iteration %d, got only %d points, which is not fitable",iteration,n); + goto FITFAILED; /* require fitting to at least 100 points */ + } + + + /* If we're censoring, estimate z, the number of censored guys + * left of the bound. Our initial estimate is crudely that we're + * missing e^-1 of the total distribution (which would be exact + * if we censored exactly at mu; but we censored at the observed peak). + * Subsequent estimates are more exact based on our current estimate of mu. + */ + if (censor) + { + if (iteration == 0) + z = MIN(h->total-n, (int) (0.58198 * (float) n)); + else + { + double psx; + psx = EVDDistribution((float) lowbound, mu, lambda); + z = MIN(h->total-n, (int) ((double) n * psx / (1. - psx))); + } + } + + /* Do an ML fit + */ + if (censor) { + if (! EVDCensoredFit(x, y, hsize, z, (float) lowbound, &mu, &lambda)) { + warn("On iteration %d, unable to make maxlikehood evd fit with censor",iteration); + goto FITFAILED; + } + } else { + if (! EVDMaxLikelyFit(x, y, hsize, &mu, &lambda)) { + warn("On iteration %d, unable to make maxlikehood evd fit without censor",iteration); + goto FITFAILED; + } + } + + + /* Find the Eval = 1 point as a new highbound; + * the total number of samples estimated to "belong" to the EVD is n+z + */ + new_highbound = (int) + (mu - (log (-1. * log((double) (n+z-1) / (double)(n+z))) / lambda)); + + free(x); + free(y); + if (new_highbound >= highbound) break; + highbound = new_highbound; + } + + /* Set the histogram parameters; + * - the wonka factor is n+z / h->total : e.g. that's the fraction of the + * hits that we expect to match the EVD, others are generally lower + * - we fit from lowbound to highbound; thus we lose 2 degrees of freedom + * for fitting mu, lambda, but we get 1 back because we're unnormalized + * in this interval, hence we pass 2-1 = 1 as ndegrees. + * + * Mon Jan 19 06:18:14 1998: wonka = 1.0, temporarily disabled. + */ + ExtremeValueSetHistogram(h, mu, lambda, lowbound, highbound, 1.0, 1); + return 1; + +FITFAILED: + UnfitHistogram(h); + if (x != NULL) free(x); + if (y != NULL) free(y); + return 0; +} + + +/* Function: ExtremeValueSetHistogram(h,mu,lambda,lowbound,highbound,wonka,ndegrees) + * + * Descrip: No Description + * + * Arg: h [UNKN ] the histogram to set [Histogram *] + * Arg: mu [UNKN ] mu location parameter [float] + * Arg: lambda [UNKN ] lambda scale parameter [float] + * Arg: lowbound [UNKN ] low bound of the histogram that was fit [float] + * Arg: highbound [UNKN ] high bound of histogram that was fit [float] + * Arg: wonka [UNKN ] fudge factor; fraction of hits estimated to be "EVD-like" [float] + * Arg: ndegrees [UNKN ] extra degrees of freedom to subtract in chi2 test: [int] + * + */ +# line 702 "histogram.dy" +void ExtremeValueSetHistogram(Histogram * h, float mu, float lambda, float lowbound, float highbound, float wonka, int ndegrees) +{ + int sc; + int hsize, idx; + int nbins; + float delta; + + UnfitHistogram(h); + h->fit_type = HISTFIT_EVD; + h->param[EVD_LAMBDA] = lambda; + h->param[EVD_MU] = mu; + h->param[EVD_WONKA] = wonka; + + hsize = h->max - h->min + 1; + h->expect = (float *) ckalloc(sizeof(float) * hsize); + if( h->expect == NULL ) { + fatal("Cannot make memory for expect thing... "); + } + for (idx = 0; idx < hsize; idx++) + h->expect[idx] = 0.; + + /* Calculate the expected values for the histogram. + */ + for (sc = h->min; sc <= h->max; sc++) + h->expect[sc - h->min] = + ExtremeValueE((float)(sc), h->param[EVD_MU], h->param[EVD_LAMBDA], + h->total) - + ExtremeValueE((float)(sc+1), h->param[EVD_MU], h->param[EVD_LAMBDA], + h->total); + + /* Calculate the goodness-of-fit (within whole region) + */ + h->chisq = 0.; + nbins = 0; + for (sc = lowbound; sc <= highbound; sc++) + if (h->expect[sc-h->min] >= 5. && h->histogram[sc-h->min] >= 5) + { + delta = (float) h->histogram[sc-h->min] - h->expect[sc-h->min]; + h->chisq += delta * delta / h->expect[sc-h->min]; + nbins++; + } + + /* Since we fit the whole histogram, there is at least + * one constraint on chi-square: the normalization to h->total. + */ + if (nbins > 1 + ndegrees) + h->chip = (float) IncompleteGamma((double)(nbins-1-ndegrees)/2., + (double) h->chisq/2.); + else + h->chip = 0.; +} + + + +/* Function: GaussianFitHistogram(h,high_hint) + * + * Descrip: No Description + * + * Arg: h [UNKN ] histogram to fit [Histogram *] + * Arg: high_hint [UNKN ] score cutoff; above this are `real' hits that aren't fit [float] + * + * Return [UNKN ] if fit is judged to be valid else 0 if fit is invalid (too few seqs.) [int] + * + */ +# line 777 "histogram.dy" +int GaussianFitHistogram(Histogram * h, float high_hint) +{ + float sum; + float sqsum; + float delta; + int sc; + int nbins; + int hsize, idx; + + /* Clear any previous fitting from the histogram. + */ + UnfitHistogram(h); + + /* Determine if we have enough hits to fit the histogram; + * arbitrarily require 1000. + */ + if (h->total < 1000) { h->fit_type = HISTFIT_NONE; return 0; } + + /* Simplest algorithm for mean and sd; + * no outlier detection yet (not even using high_hint) + * + * Magic 0.5 correction is because our histogram is for + * scores between x and x+1; we estimate the expectation + * (roughly) as x + 0.5. + */ + sum = sqsum = 0.; + for (sc = h->lowscore; sc <= h->highscore; sc++) + { + delta = (float) sc + 0.5; + sum += (float) h->histogram[sc-h->min] * delta; + sqsum += (float) h->histogram[sc-h->min] * delta * delta; + } + h->fit_type = HISTFIT_GAUSSIAN; + h->param[GAUSS_MEAN] = sum / (float) h->total; + h->param[GAUSS_SD] = sqrt((sqsum - (sum*sum/(float)h->total)) / + (float)(h->total-1)); + + /* Calculate the expected values for the histogram. + * Note that the magic 0.5 correction appears again. + * Calculating difference between distribution functions for Gaussian + * would be correct but hard. + */ + hsize = h->max - h->min + 1; + h->expect = (float *) ckalloc(sizeof(float) * hsize); + if( h->expect == NULL ) { + fatal("Unable to allocate expect space in histogram... sorry!"); + } + for (idx = 0; idx < hsize; idx++) + h->expect[idx] = 0.; + + for (sc = h->min; sc <= h->max; sc++) + { + delta = (float) sc + 0.5 - h->param[GAUSS_MEAN]; + h->expect[sc - h->min] = + (float) h->total * ((1. / (h->param[GAUSS_SD] * sqrt(2.*3.14159))) * + (exp(-1.* delta*delta / (2. * h->param[GAUSS_SD] * h->param[GAUSS_SD])))); + } + + /* Calculate the goodness-of-fit (within region that was fitted) + */ + h->chisq = 0.; + nbins = 0; + for (sc = h->lowscore; sc <= h->highscore; sc++) + if (h->expect[sc-h->min] >= 5. && h->histogram[sc-h->min] >= 5) + { + delta = (float) h->histogram[sc-h->min] - h->expect[sc-h->min]; + h->chisq += delta * delta / h->expect[sc-h->min]; + nbins++; + } + /* -1 d.f. for normalization; -2 d.f. for two free parameters */ + if (nbins > 3) + h->chip = (float) IncompleteGamma((double)(nbins-3)/2., + (double) h->chisq/2.); + else + h->chip = 0.; + + return 1; +} + + +/* Function: GaussianSetHistogram(h,mean,sd) + * + * Descrip: No Description + * + * Arg: h [UNKN ] Undocumented argument [Histogram *] + * Arg: mean [UNKN ] Undocumented argument [float] + * Arg: sd [UNKN ] Undocumented argument [float] + * + */ +# line 871 "histogram.dy" +void GaussianSetHistogram(Histogram * h, float mean, float sd) +{ + int sc; + int hsize, idx; + int nbins; + float delta; + + UnfitHistogram(h); + h->fit_type = HISTFIT_GAUSSIAN; + h->param[GAUSS_MEAN] = mean; + h->param[GAUSS_SD] = sd; + + /* Calculate the expected values for the histogram. + */ + hsize = h->max - h->min + 1; + h->expect = (float *) ckalloc(sizeof(float) * hsize); + if( h->expect == NULL ) { + fatal("Unable to allocate expect size in expected histogram..."); + } + + for (idx = 0; idx < hsize; idx++) + h->expect[idx] = 0.; + + /* Note: ideally we'd use the Gaussian distribution function + * to find the histogram occupancy in the window sc..sc+1. + * However, the distribution function is hard to calculate. + * Instead, estimate the histogram by taking the density at sc+0.5. + */ + for (sc = h->min; sc <= h->max; sc++) + { + delta = ((float)sc + 0.5) - h->param[GAUSS_MEAN]; + h->expect[sc - h->min] = + (float) h->total * ((1. / (h->param[GAUSS_SD] * sqrt(2.*3.14159))) * + (exp(-1.*delta*delta / (2. * h->param[GAUSS_SD] * h->param[GAUSS_SD])))); + } + + /* Calculate the goodness-of-fit (within whole region) + */ + h->chisq = 0.; + nbins = 0; + for (sc = h->lowscore; sc <= h->highscore; sc++) + if (h->expect[sc-h->min] >= 5. && h->histogram[sc-h->min] >= 5) + { + delta = (float) h->histogram[sc-h->min] - h->expect[sc-h->min]; + h->chisq += delta * delta / h->expect[sc-h->min]; + nbins++; + } + /* -1 d.f. for normalization */ + if (nbins > 1) + h->chip = (float) IncompleteGamma((double)(nbins-1)/2., + (double) h->chisq/2.); + else + h->chip = 0.; +} + + + +/* Function: EVDDensity(x,mu,lambda) + * + * Descrip: No Description + * + * Arg: x [UNKN ] Undocumented argument [float] + * Arg: mu [UNKN ] Undocumented argument [float] + * Arg: lambda [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] Undocumented return value [double] + * + */ +# line 942 "histogram.dy" +double EVDDensity(float x, float mu, float lambda) +{ + return (lambda * exp(-1. * lambda * (x - mu) + - exp(-1. * lambda * (x - mu)))); +} + +/* Function: EVDDistribution(x,mu,lambda) + * + * Descrip: No Description + * + * Arg: x [UNKN ] Undocumented argument [float] + * Arg: mu [UNKN ] Undocumented argument [float] + * Arg: lambda [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] Undocumented return value [double] + * + */ +# line 962 "histogram.dy" +double EVDDistribution(float x, float mu, float lambda) +{ + return (exp(-1. * exp(-1. * lambda * (x - mu)))); +} + +/* Function: ExtremeValueP(x,mu,lambda) + * + * Descrip: No Description + * + * Arg: x [UNKN ] score [float] + * Arg: mu [UNKN ] characteristic value of extreme value distribution [float] + * Arg: lambda [UNKN ] decay constant of extreme value distribution [float] + * + * Return [UNKN ] P(S>x) [double] + * + */ +# line 988 "histogram.dy" +double ExtremeValueP(float x, float mu, float lambda) +{ + double y; + /* a roundoff issue arises; use 1 - e^-x --> x for small x */ + y = exp(-1. * lambda * (x - mu)); + if (y < 1e-7) return y; + else return (1.0 - exp(-1. * y)); +} + + +/* Function: ExtremeValueP2(x,mu,lambda,N) + * + * Descrip: No Description + * + * Arg: x [UNKN ] score [float] + * Arg: mu [UNKN ] characteristic value of extreme value distribution [float] + * Arg: lambda [UNKN ] decay constant of extreme value distribution [float] + * Arg: N [UNKN ] number of trials (number of sequences) [int] + * + * Return [UNKN ] P(S>x) for database of size N [double] + * + */ +# line 1018 "histogram.dy" +double ExtremeValueP2(float x, float mu, float lambda, int N) +{ + double y; + y = N * ExtremeValueP(x,mu,lambda); + if (y < 1e-7) return y; + else return (1.0 - exp(-1. * y)); +} + +/* Function: ExtremeValueE(x,mu,lambda,N) + * + * Descrip: No Description + * + * Arg: x [UNKN ] score [float] + * Arg: mu [UNKN ] characteristic value of extreme value distribution [float] + * Arg: lambda [UNKN ] decay constant of extreme value distribution [float] + * Arg: N [UNKN ] number of trials (number of sequences) [int] + * + * Return [UNKN ] E(S>x) for database of size N [double] + * + */ +# line 1046 "histogram.dy" +double ExtremeValueE(float x, float mu, float lambda, int N) +{ + return (double)N * ExtremeValueP(x,mu,lambda); +} + + +/* Function: EVDrandom(mu,lambda) + * + * Descrip: No Description + * + * Arg: mu [UNKN ] Undocumented argument [float] + * Arg: lambda [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] Undocumented return value [float] + * + */ +# line 1068 "histogram.dy" +float EVDrandom(float mu, float lambda) +{ + float p = 0.0; + + /* Very unlikely, but possible, + * that sre_random() would give us exactly 0 or 1 + */ + while (p == 0. || p == 1.) p = sre_random(); + return mu - log(-1. * log(p)) / lambda; +} + + +/* Function: Lawless416(ret_f,ret_df,y,*x,x,*y,n,lambda,*ret_f,*ret_df) + * + * Descrip: No Description + * + * Arg: ret_f [WRITE] RETURN: 4.1.6 evaluated at lambda [NullString] + * Arg: ret_df [WRITE] RETURN: first derivative of 4.1.6 evaluated at lambda [NullString] + * Arg: y [UNKN ] NULL (or y-axis of a histogram) [NullString] + * Arg: *x [UNKN ] Undocumented argument [float] + * Arg: x [UNKN ] array of sample values (or x-axis of a histogram) [NullString] + * Arg: *y [UNKN ] Undocumented argument [int] + * Arg: n [UNKN ] number of samples (or number of histogram bins) [int] + * Arg: lambda [UNKN ] a lambda to test [float] + * Arg: *ret_f [UNKN ] Undocumented argument [float] + * Arg: *ret_df [UNKN ] Undocumented argument [float] + * + */ +# line 1107 "histogram.dy" +void Lawless416(float *x, int *y, int n, float lambda, float *ret_f, float *ret_df) +{ + + double esum; /* \sum e^(-lambda xi) */ + double xesum; /* \sum xi e^(-lambda xi) */ + double xxesum; /* \sum xi^2 e^(-lambda xi) */ + double xsum; /* \sum xi */ + double mult; /* histogram count multiplier */ + double total; /* total samples */ + int i; + + + esum = xesum = xsum = xxesum = total = 0.; + for (i = 0; i < n; i++) + { + mult = (y == NULL) ? 1. : (double) y[i]; + xsum += mult * x[i]; + xesum += mult * x[i] * exp(-1. * lambda * x[i]); + xxesum += mult * x[i] * x[i] * exp(-1. * lambda * x[i]); + esum += mult * exp(-1. * lambda * x[i]); + total += mult; + } + *ret_f = 1./lambda - xsum / total + xesum / esum; + *ret_df = ((xesum / esum) * (xesum / esum)) + - (xxesum / esum) + - (1. / (lambda * lambda)); + + return; +} + + +/* Function: Lawless422(*x,ret_df,y,ret_f,x,*y,n,z,c,lambda,*ret_f,*ret_df) + * + * Descrip: No Description + * + * Arg: *x [UNKN ] Undocumented argument [float] + * Arg: ret_df [WRITE] RETURN: first derivative of 4.2.2 evaluated at lambda [NullString] + * Arg: y [UNKN ] NULL (or y axis of a histogram) [NullString] + * Arg: ret_f [WRITE] RETURN: 4.2.2 evaluated at lambda [NullString] + * Arg: x [UNKN ] array of sample values (or x axis of a histogram) [NullString] + * Arg: *y [UNKN ] Undocumented argument [int] + * Arg: n [UNKN ] number of observed samples (or number of histogram bins) [int] + * Arg: z [UNKN ] number of censored samples [int] + * Arg: c [UNKN ] censoring value; all observed x_i >= c [float] + * Arg: lambda [UNKN ] a lambda to test [float] + * Arg: *ret_f [UNKN ] Undocumented argument [float] + * Arg: *ret_df [UNKN ] Undocumented argument [float] + * + */ +# line 1170 "histogram.dy" +void Lawless422(float *x, int *y, int n, int z, float c,float lambda, float *ret_f, float *ret_df) +{ + double esum; /* \sum e^(-lambda xi) + z term */ + double xesum; /* \sum xi e^(-lambda xi) + z term */ + double xxesum; /* \sum xi^2 e^(-lambda xi) + z term */ + double xsum; /* \sum xi (no z term) */ + double mult; /* histogram count multiplier */ + double total; /* total samples */ + int i; + + esum = xesum = xsum = xxesum = total = 0.; + for (i = 0; i < n; i++) + { + mult = (y == NULL) ? 1. : (double) y[i]; + xsum += mult * x[i]; + esum += mult * exp(-1. * lambda * x[i]); + xesum += mult * x[i] * exp(-1. * lambda * x[i]); + xxesum += mult * x[i] * x[i] * exp(-1. * lambda * x[i]); + total += mult; + } + + /* Add z terms for censored data + */ + esum += (double) z * exp(-1. * lambda * c); + xesum += (double) z * c * exp(-1. * lambda * c); + xxesum += (double) z * c * c * exp(-1. * lambda * c); + + *ret_f = 1./lambda - xsum / total + xesum / esum; + *ret_df = ((xesum / esum) * (xesum / esum)) + - (xxesum / esum) + - (1. / (lambda * lambda)); + + return; +} + + + +/* Function: EVDMaxLikelyFit(ret_lambda,x,*x,c,ret_mu,*c,n,*ret_mu,*ret_lambda) + * + * Descrip: No Description + * + * Arg: ret_lambda [WRITE] RETURN: ML estimate of lambda [NullString] + * Arg: x [UNKN ] list of EVD distributed samples or x axis of histogram [NullString] + * Arg: *x [UNKN ] Undocumented argument [float] + * Arg: c [UNKN ] NULL, or y-axis of histogram [NullString] + * Arg: ret_mu [WRITE] RETURN: ML estimate of mu [NullString] + * Arg: *c [UNKN ] Undocumented argument [int] + * Arg: n [UNKN ] number of samples, or number of histogram bins [int] + * Arg: *ret_mu [UNKN ] Undocumented argument [float] + * Arg: *ret_lambda [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] on success; 0 on any failure [int] + * + */ +# line 1238 "histogram.dy" +int EVDMaxLikelyFit(float *x, int *c, int n, float *ret_mu, float *ret_lambda) +{ + float lambda, mu; + float fx; /* f(x) */ + float dfx; /* f'(x) */ + double esum; /* \sum e^(-lambda xi) */ + double mult; + double total; + float tol = 1e-5; + int i; + + /* 1. Find an initial guess at lambda: linear regression here? + */ + lambda = 0.2; + + /* 2. Use Newton/Raphson to solve Lawless 4.1.6 and find ML lambda + */ + for (i = 0; i < 100; i++) + { + Lawless416(x, c, n, lambda, &fx, &dfx); + if (fabs(fx) < tol) break; /* success */ + lambda = lambda - fx / dfx; /* Newton/Raphson is simple */ + if (lambda <= 0.) lambda = 0.001; /* but be a little careful */ + } + + /* 2.5: If we did 100 iterations but didn't converge, Newton/Raphson failed. + * Resort to a bisection search. Worse convergence speed + * but guaranteed to converge (unlike Newton/Raphson). + * We assume (!?) that fx is a monotonically decreasing function of x; + * i.e. fx > 0 if we are left of the root, fx < 0 if we + * are right of the root. + */ + if (i == 100) + { + float left, right, mid; + info("EVD maxlik fit - Newton/Raphson failed; switchover to bisection"); + + /* First we need to bracket the root */ + lambda = right = left = 0.2; + Lawless416(x, c, n, lambda, &fx, &dfx); + if (fx < 0.) + { /* fix right; search left. */ + do { + left -= 0.1; + if (left < 0.) { + info("failed to bracket root"); + return 0; + } + Lawless416(x, c, n, left, &fx, &dfx); + } while (fx < 0.); + } + else + { /* fix left; search right. */ + do { + right += 0.1; + Lawless416(x, c, n, right, &fx, &dfx); + if (right > 100.) { + info("failed to bracket root"); + return 0; + } + } while (fx > 0.); + } + /* now we bisection search in left/right interval */ + for (i = 0; i < 100; i++) + { + mid = (left + right) / 2.; + Lawless416(x, c, n, mid, &fx, &dfx); + if (fabs(fx) < tol) break; /* success */ + if (fx > 0.) left = mid; + else right = mid; + } + if (i == 100) { + warn("even the bisection search failed"); + return 0; + } + lambda = mid; + } + + /* 3. Substitute into Lawless 4.1.5 to find mu + */ + esum = 0.; + for (i = 0; i < n; i++) + { + mult = (c == NULL) ? 1. : (double) c[i]; + esum += mult * exp(-1 * lambda * x[i]); + total += mult; + } + mu = -1. * log(esum / total) / lambda; + + *ret_lambda = lambda; + *ret_mu = mu; + return 1; +} + + +/* Function: EVDCensoredFit(ret_mu,x,ret_lambda,y,*x,*y,n,z,c,*ret_mu,*ret_lambda) + * + * Descrip: No Description + * + * Arg: ret_mu [WRITE] RETURN: ML estimate of mu [NullString] + * Arg: x [UNKN ] list of EVD distributed samples or x axis of histogram [NullString] + * Arg: ret_lambda [WRITE] RETURN: ML estimate of lambda [NullString] + * Arg: y [UNKN ] NULL, or y axis of histogram [NullString] + * Arg: *x [UNKN ] Undocumented argument [float] + * Arg: *y [UNKN ] Undocumented argument [int] + * Arg: n [UNKN ] number of observed samples,or number of histogram bins [int] + * Arg: z [UNKN ] number of censored samples [int] + * Arg: c [UNKN ] censoring value (all x_i >= c) [float] + * Arg: *ret_mu [UNKN ] Undocumented argument [float] + * Arg: *ret_lambda [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 1366 "histogram.dy" +int EVDCensoredFit(float *x, int *y, int n, int z, float c,float *ret_mu, float *ret_lambda) +{ + float lambda, mu; + float fx; /* f(x) */ + float dfx; /* f'(x) */ + double esum; /* \sum e^(-lambda xi) */ + double mult; + double total; + float tol = 1e-5; + int i; + + /* 1. Find an initial guess at lambda: linear regression here? + */ + lambda = 0.2; + + /* 2. Use Newton/Raphson to solve Lawless 4.2.2 and find ML lambda + */ + for (i = 0; i < 100; i++) + { + Lawless422(x, y, n, z, c, lambda, &fx, &dfx); + if (fabs(fx) < tol) break; /* success */ + lambda = lambda - fx / dfx; /* Newton/Raphson is simple */ + if (lambda <= 0.) lambda = 0.001; /* but be a little careful */ + } + + /* 2.5: If we did 100 iterations but didn't converge, Newton/Raphson failed. + * Resort to a bisection search. Worse convergence speed + * but guaranteed to converge (unlike Newton/Raphson). + * We assume (!?) that fx is a monotonically decreasing function of x; + * i.e. fx > 0 if we are left of the root, fx < 0 if we + * are right of the root. + */ + if (i == 100) + { + float left, right, mid; + /* First we need to bracket the root */ + info("EVDCensor fit: Newton/Raphson failed; switched to bisection"); + lambda = right = left = 0.2; + Lawless422(x, y, n, z, c, lambda, &fx, &dfx); + if (fx < 0.) + { /* fix right; search left. */ + do { + left -= 0.03; + if (left < 0.) { + info("failed to bracket root"); + return 0; + } + Lawless422(x, y, n, z, c, left, &fx, &dfx); + } while (fx < 0.); + } + else + { /* fix left; search right. */ + do { + right += 0.1; + Lawless422(x, y, n, z, c, left, &fx, &dfx); + if (right > 100.) { + info("failed to bracket root"); + return 0; + } + } while (fx > 0.); + } + /* now we bisection search in left/right interval */ + for (i = 0; i < 100; i++) + { + mid = (left + right) / 2.; + Lawless422(x, y, n, z, c, left, &fx, &dfx); + if (fabs(fx) < tol) break; /* success */ + if (fx > 0.) left = mid; + else right = mid; + } + if (i == 100) { + info("even the bisection search failed"); + return 0; + } + lambda = mid; + } + + /* 3. Substitute into Lawless 4.2.3 to find mu + */ + esum = total = 0.; + for (i = 0; i < n; i++) + { + mult = (y == NULL) ? 1. : (double) y[i]; + esum += mult * exp(-1. * lambda * x[i]); + total += mult; + } + esum += (double) z * exp(-1. * lambda * c); /* term from censored data */ + mu = -1. * log(esum / total) / lambda; + + *ret_lambda = lambda; + *ret_mu = mu; + return 1; +} + +/* Function: Linefit(ret_r,x,*x,ret_b,y,ret_a,*y,N,*ret_a,*ret_b,*ret_r) + * + * Descrip: No Description + * + * Arg: ret_r [WRITE] RETURN: correlation coefficient [NullString] + * Arg: x [UNKN ] x values of data [NullString] + * Arg: *x [UNKN ] Undocumented argument [float] + * Arg: ret_b [WRITE] RETURN: slope [NullString] + * Arg: y [UNKN ] y values of data [NullString] + * Arg: ret_a [WRITE] RETURN: intercept [NullString] + * Arg: *y [UNKN ] Undocumented argument [float] + * Arg: N [UNKN ] number of data points [int] + * Arg: *ret_a [UNKN ] Undocumented argument [float] + * Arg: *ret_b [UNKN ] Undocumented argument [float] + * Arg: *ret_r [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] on success, 0 on failure. [int] + * + */ +# line 1484 "histogram.dy" +int Linefit(float *x, float *y, int N, float *ret_a, float *ret_b, float *ret_r) +{ + float xavg, yavg; + float sxx, syy, sxy; + int i; + + /* Calculate averages, xavg and yavg + */ + xavg = yavg = 0.0; + for (i = 0; i < N; i++) + { + xavg += x[i]; + yavg += y[i]; + } + xavg /= (float) N; + yavg /= (float) N; + + sxx = syy = sxy = 0.0; + for (i = 0; i < N; i++) + { + sxx += (x[i] - xavg) * (x[i] - xavg); + syy += (y[i] - yavg) * (y[i] - xavg); + sxy += (x[i] - xavg) * (y[i] - yavg); + } + *ret_b = sxy / sxx; + *ret_a = yavg - xavg*(*ret_b); + *ret_r = sxy / (sqrt(sxx) * sqrt(syy)); + return 1; +} + + +#define RANGE 268435456 /* 2^28 */ +#define DIV 16384 /* sqrt(RANGE) */ +#define MULT 72530821 /* my/Cathy's birthdays, x21, x even (Knuth)*/ + + +static int sre_reseed = 0; /* TRUE to reinit sre_random() */ +static int sre_randseed = 666; /* default seed for sre_random() */ + +/* Function: sre_random(void) + * + * Descrip: No Description + * + * + * Return [UNKN ] Undocumented return value [float] + * + */ +# line 1553 "histogram.dy" +float sre_random(void) +{ + static long rnd; + static int firsttime = 1; + long high1, low1; + long high2, low2; + + if (sre_reseed || firsttime) + { + sre_reseed = firsttime = 0; + if (sre_randseed <= 0) sre_randseed = 666; /* seeds of zero break me */ + high1 = sre_randseed / DIV; low1 = sre_randseed % DIV; + high2 = MULT / DIV; low2 = MULT % DIV; + rnd = (((high2*low1 + high1*low2) % DIV)*DIV + low1*low2) % RANGE; + } + high1 = rnd / DIV; low1 = rnd % DIV; + high2 = MULT / DIV; low2 = MULT % DIV; + rnd = (((high2*low1 + high1*low2) % DIV)*DIV + low1*low2) % RANGE; + + return ((float) rnd / (float) RANGE); +} +#undef RANGE +#undef DIV +#undef MULT + +/* Function: IncompleteGamma(a,x) + * + * Descrip: No Description + * + * Arg: a [UNKN ] Undocumented argument [double] + * Arg: x [UNKN ] Undocumented argument [double] + * + * Return [UNKN ] Undocumented return value [double] + * + */ +# line 1609 "histogram.dy" +double IncompleteGamma(double a, double x) +{ + int iter; /* iteration counter */ + + if (a <= 0.) fatal("IncompleteGamma(): a must be > 0"); + if (x < 0.) fatal("IncompleteGamma(): x must be >= 0"); + + /* For x > a + 1 the following gives rapid convergence; + * calculate 1 - P(a,x) = \frac{\Gamma(a,x)}{\Gamma(a)}: + * use a continued fraction development for \Gamma(a,x). + */ + if (x > a+1) + { + double oldp; /* previous value of p */ + double nu0, nu1; /* numerators for continued fraction calc */ + double de0, de1; /* denominators for continued fraction calc */ + + nu0 = 0.; /* A_0 = 0 */ + de0 = 1.; /* B_0 = 1 */ + nu1 = 1.; /* A_1 = 1 */ + de1 = x; /* B_1 = x */ + + oldp = nu1; + for (iter = 1; iter < 100; iter++) + { + /* Continued fraction development: + * set A_j = b_j A_j-1 + a_j A_j-2 + * B_j = b_j B_j-1 + a_j B_j-2 + * We start with A_2, B_2. + */ + /* j = even: a_j = iter-a, b_j = 1 */ + /* A,B_j-2 are in nu0, de0; A,B_j-1 are in nu1,de1 */ + nu0 = nu1 + ((double)iter - a) * nu0; + de0 = de1 + ((double)iter - a) * de0; + + /* j = odd: a_j = iter, b_j = x */ + /* A,B_j-2 are in nu1, de1; A,B_j-1 in nu0,de0 */ + nu1 = x * nu0 + (double) iter * nu1; + de1 = x * de0 + (double) iter * de1; + + /* rescale */ + if (de1) + { + nu0 /= de1; + de0 /= de1; + nu1 /= de1; + de1 = 1.; + } + /* check for convergence */ + if (fabs((nu1-oldp)/nu1) < 1.e-7) + return nu1 * exp(a * log(x) - x - Gammln(a)); + + oldp = nu1; + } + fatal("IncompleteGamma(): failed to converge using continued fraction approx"); + } + else /* x <= a+1 */ + { + double p; /* current sum */ + double val; /* current value used in sum */ + + /* For x <= a+1 we use a convergent series instead: + * P(a,x) = \frac{\gamma(a,x)}{\Gamma(a)}, + * where + * \gamma(a,x) = e^{-x}x^a \sum_{n=0}{\infty} \frac{\Gamma{a}}{\Gamma{a+1+n}} x^n + * which looks appalling but the sum is in fact rearrangeable to + * a simple series without the \Gamma functions: + * = \frac{1}{a} + \frac{x}{a(a+1)} + \frac{x^2}{a(a+1)(a+2)} ... + * and it's obvious that this should converge nicely for x <= a+1. + */ + + p = val = 1. / a; + for (iter = 1; iter < 10000; iter++) + { + val *= x / (a+(double)iter); + p += val; + + if (fabs(val/p) < 1.e-7) + return 1. - p * exp(a * log(x) - x - Gammln(a)); + } + fatal("IncompleteGamma(): failed to converge using series approx"); + } + /*NOTREACHED*/ + return 0.; +} + + +/* Function: Gammln(x) + * + * Descrip: No Description + * + * Arg: x [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] Undocumented return value [float] + * + */ +# line 1715 "histogram.dy" +float Gammln(float x) +{ + int i; + double xx, tx; + double tmp, value; + static double cof[11] = { + 4.694580336184385e+04, + -1.560605207784446e+05, + 2.065049568014106e+05, + -1.388934775095388e+05, + 5.031796415085709e+04, + -9.601592329182778e+03, + 8.785855930895250e+02, + -3.155153906098611e+01, + 2.908143421162229e-01, + -2.319827630494973e-04, + 1.251639670050933e-10 + }; + + /* Protect against x=0. We see this in Dirichlet code, + * for terms alpha = 0. This is a severe hack but it is effective + * and safe. (due to GJM) + */ + if (x <= 0.0) return 999999.; + + xx = x - 1.0; + tx = tmp = xx + 11.0; + value = 1.0; + for (i = 10; i >= 0; i--) /* sum least significant terms first */ + { + value += cof[i] / tmp; + tmp -= 1.0; + } + value = log(value); + tx += 0.5; + value += 0.918938533 + (xx+0.5)*log(tx) - tx; + return (float) value; +} + + +# line 1416 "histogram.c" +/* Function: hard_link_Histogram(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [Histogram *] + * + * Return [UNKN ] Undocumented return value [Histogram *] + * + */ +Histogram * hard_link_Histogram(Histogram * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a Histogram object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: Histogram_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [Histogram *] + * + */ +Histogram * Histogram_alloc(void) +{ + Histogram * out;/* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(Histogram *) ckalloc (sizeof(Histogram))) == NULL) { + warn("Histogram_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->histogram = NULL; + out->min = 0; + out->max = 0; + out->highscore = 0; + out->lowscore = 0; + out->lumpsize = 0; + out->total = 0; + out->expect = NULL; + out->fit_type = 0; + /* param[3] is an array: no default possible */ + out->chisq = 0; + out->chip = 0; + + + return out; +} + + +/* Function: free_Histogram(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [Histogram *] + * + * Return [UNKN ] Undocumented return value [Histogram *] + * + */ +Histogram * free_Histogram(Histogram * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a Histogram obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->histogram != NULL) + ckfree(obj->histogram); + if( obj->expect != NULL) + ckfree(obj->expect); + + + ckfree(obj); + return NULL; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/histogram.h b/Bio/Ext/Align/libs/histogram.h new file mode 100644 index 0000000..91b58c9 --- /dev/null +++ b/Bio/Ext/Align/libs/histogram.h @@ -0,0 +1,506 @@ +#ifndef DYNAMITEhistogramHEADERFILE +#define DYNAMITEhistogramHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" + +#define HISTFIT_NONE 0 /* no fit done yet */ +#define HISTFIT_EVD 1 /* fit type = extreme value dist */ +#define HISTFIT_GAUSSIAN 2 /* fit type = Gaussian */ +#define EVD_MU 0 /* EVD fit parameter mu */ +#define EVD_LAMBDA 1 /* EVD fit parameter lambda */ +#define EVD_WONKA 2 /* EVD fit fudge factor */ +#define GAUSS_MEAN 0 /* Gaussian parameter mean */ +#define GAUSS_SD 1 /* Gaussian parameter std. dev. */ + +#ifndef MIN +#define MIN(a,b) ((a)<(b) ? (a) : (b)) +#endif + +/* Object Histogram + * + * Descrip: This Object came from Sean Eddy excellent histogram package. + * He donated it free of all restrictions to allow it to be used + * in the Wise2 package without complicated licensing terms. + * He is a *very* nice man. + * + * It was made into a dynamite object so that + * a) External ports to scripting languages would be trivial + * b) cooperation with future versions of histogram.c would be possible. + * + * Here is the rest of the documentation from sean. + * + * Keep a score histogram. + * + * The main implementation issue here is that the range of + * scores is unknown, and will go negative. histogram is + * a 0..max-min array that represents the range min..max. + * A given score is indexed in histogram array as score-min. + * The AddToHistogram function deals with dynamically + * resizing the histogram array when necessary. + * + * + */ +struct bp_sw_Histogram { + int dynamite_hard_link; + int* histogram; /* counts of hits */ + int min; /* elem 0 of histogram == min */ + int max; /* last elem of histogram == max */ + int highscore; /* highest active elem has this score */ + int lowscore; /* lowest active elem has this score */ + int lumpsize; /* when resizing, overalloc by this */ + int total; /* total # of hits counted */ + float* expect; /* expected counts of hits */ + int fit_type; /* flag indicating distribution type */ + float param[3]; /* parameters used for fits */ + float chisq; /* chi-squared val for goodness of fit */ + float chip; /* P value for chisquared */ + } ; +/* Histogram defined */ +#ifndef DYNAMITE_DEFINED_Histogram +typedef struct bp_sw_Histogram bp_sw_Histogram; +#define Histogram bp_sw_Histogram +#define DYNAMITE_DEFINED_Histogram +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: Evalue_from_Histogram(his,score) + * + * Descrip: No Description + * + * Arg: his [UNKN ] Histogram object [Histogram *] + * Arg: score [UNKN ] score you want the evalue for [double] + * + * Return [UNKN ] Undocumented return value [double] + * + */ +double bp_sw_Evalue_from_Histogram(Histogram * his,double score); +#define Evalue_from_Histogram bp_sw_Evalue_from_Histogram + + +/* Function: new_Histogram(min,max,lumpsize) + * + * Descrip: No Description + * + * Arg: min [UNKN ] minimum score (integer) [int] + * Arg: max [UNKN ] maximum score (integer) [int] + * Arg: lumpsize [UNKN ] when reallocating histogram, the reallocation amount [int] + * + * Return [UNKN ] Undocumented return value [Histogram *] + * + */ +Histogram * bp_sw_new_Histogram(int min, int max, int lumpsize); +#define new_Histogram bp_sw_new_Histogram + + +/* Function: UnfitHistogram(h) + * + * Descrip: No Description + * + * Arg: h [UNKN ] Undocumented argument [Histogram *] + * + */ +void bp_sw_UnfitHistogram(Histogram * h); +#define UnfitHistogram bp_sw_UnfitHistogram + + +/* Function: AddToHistogram(h,sc) + * + * Descrip: No Description + * + * Arg: h [UNKN ] Undocumented argument [Histogram *] + * Arg: sc [UNKN ] Undocumented argument [float] + * + */ +void bp_sw_AddToHistogram(Histogram * h, float sc); +#define AddToHistogram bp_sw_AddToHistogram + + +/* Function: PrintASCIIHistogram(h,fp) + * + * Descrip: No Description + * + * Arg: h [UNKN ] histogram to print [Histogram *] + * Arg: fp [UNKN ] open file to print to (stdout works) [FILE *] + * + */ +void bp_sw_PrintASCIIHistogram(Histogram * h,FILE * fp); +#define PrintASCIIHistogram bp_sw_PrintASCIIHistogram + + +/* Function: EVDBasicFit(h) + * + * Descrip: No Description + * + * Arg: h [UNKN ] histogram to fit [Histogram *] + * + */ +void bp_sw_EVDBasicFit(Histogram * h); +#define EVDBasicFit bp_sw_EVDBasicFit + + +/* Function: ExtremeValueFitHistogram(h,censor,high_hint) + * + * Descrip: No Description + * + * Arg: h [UNKN ] histogram to fit [Histogram *] + * Arg: censor [UNKN ] TRUE to censor data left of the peak [int] + * Arg: high_hint [UNKN ] score cutoff; above this are real hits that arent fit [float] + * + * Return [UNKN ] if fit is judged to be valid else 0 if fit is invalid (too few seqs.) [int] + * + */ +int bp_sw_ExtremeValueFitHistogram(Histogram * h, int censor, float high_hint) ; +#define ExtremeValueFitHistogram bp_sw_ExtremeValueFitHistogram + + +/* Function: ExtremeValueSetHistogram(h,mu,lambda,lowbound,highbound,wonka,ndegrees) + * + * Descrip: No Description + * + * Arg: h [UNKN ] the histogram to set [Histogram *] + * Arg: mu [UNKN ] mu location parameter [float] + * Arg: lambda [UNKN ] lambda scale parameter [float] + * Arg: lowbound [UNKN ] low bound of the histogram that was fit [float] + * Arg: highbound [UNKN ] high bound of histogram that was fit [float] + * Arg: wonka [UNKN ] fudge factor; fraction of hits estimated to be "EVD-like" [float] + * Arg: ndegrees [UNKN ] extra degrees of freedom to subtract in chi2 test: [int] + * + */ +void bp_sw_ExtremeValueSetHistogram(Histogram * h, float mu, float lambda, float lowbound, float highbound, float wonka, int ndegrees); +#define ExtremeValueSetHistogram bp_sw_ExtremeValueSetHistogram + + +/* Function: GaussianFitHistogram(h,high_hint) + * + * Descrip: No Description + * + * Arg: h [UNKN ] histogram to fit [Histogram *] + * Arg: high_hint [UNKN ] score cutoff; above this are `real' hits that aren't fit [float] + * + * Return [UNKN ] if fit is judged to be valid else 0 if fit is invalid (too few seqs.) [int] + * + */ +int bp_sw_GaussianFitHistogram(Histogram * h, float high_hint); +#define GaussianFitHistogram bp_sw_GaussianFitHistogram + + +/* Function: GaussianSetHistogram(h,mean,sd) + * + * Descrip: No Description + * + * Arg: h [UNKN ] Undocumented argument [Histogram *] + * Arg: mean [UNKN ] Undocumented argument [float] + * Arg: sd [UNKN ] Undocumented argument [float] + * + */ +void bp_sw_GaussianSetHistogram(Histogram * h, float mean, float sd); +#define GaussianSetHistogram bp_sw_GaussianSetHistogram + + +/* Function: EVDDensity(x,mu,lambda) + * + * Descrip: No Description + * + * Arg: x [UNKN ] Undocumented argument [float] + * Arg: mu [UNKN ] Undocumented argument [float] + * Arg: lambda [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] Undocumented return value [double] + * + */ +double bp_sw_EVDDensity(float x, float mu, float lambda); +#define EVDDensity bp_sw_EVDDensity + + +/* Function: EVDDistribution(x,mu,lambda) + * + * Descrip: No Description + * + * Arg: x [UNKN ] Undocumented argument [float] + * Arg: mu [UNKN ] Undocumented argument [float] + * Arg: lambda [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] Undocumented return value [double] + * + */ +double bp_sw_EVDDistribution(float x, float mu, float lambda); +#define EVDDistribution bp_sw_EVDDistribution + + +/* Function: ExtremeValueP(x,mu,lambda) + * + * Descrip: No Description + * + * Arg: x [UNKN ] score [float] + * Arg: mu [UNKN ] characteristic value of extreme value distribution [float] + * Arg: lambda [UNKN ] decay constant of extreme value distribution [float] + * + * Return [UNKN ] P(S>x) [double] + * + */ +double bp_sw_ExtremeValueP(float x, float mu, float lambda); +#define ExtremeValueP bp_sw_ExtremeValueP + + +/* Function: ExtremeValueP2(x,mu,lambda,N) + * + * Descrip: No Description + * + * Arg: x [UNKN ] score [float] + * Arg: mu [UNKN ] characteristic value of extreme value distribution [float] + * Arg: lambda [UNKN ] decay constant of extreme value distribution [float] + * Arg: N [UNKN ] number of trials (number of sequences) [int] + * + * Return [UNKN ] P(S>x) for database of size N [double] + * + */ +double bp_sw_ExtremeValueP2(float x, float mu, float lambda, int N); +#define ExtremeValueP2 bp_sw_ExtremeValueP2 + + +/* Function: ExtremeValueE(x,mu,lambda,N) + * + * Descrip: No Description + * + * Arg: x [UNKN ] score [float] + * Arg: mu [UNKN ] characteristic value of extreme value distribution [float] + * Arg: lambda [UNKN ] decay constant of extreme value distribution [float] + * Arg: N [UNKN ] number of trials (number of sequences) [int] + * + * Return [UNKN ] E(S>x) for database of size N [double] + * + */ +double bp_sw_ExtremeValueE(float x, float mu, float lambda, int N); +#define ExtremeValueE bp_sw_ExtremeValueE + + +/* Function: EVDrandom(mu,lambda) + * + * Descrip: No Description + * + * Arg: mu [UNKN ] Undocumented argument [float] + * Arg: lambda [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] Undocumented return value [float] + * + */ +float bp_sw_EVDrandom(float mu, float lambda); +#define EVDrandom bp_sw_EVDrandom + + +/* Function: Lawless416(ret_f,ret_df,y,*x,x,*y,n,lambda,*ret_f,*ret_df) + * + * Descrip: No Description + * + * Arg: ret_f [WRITE] RETURN: 4.1.6 evaluated at lambda [NullString] + * Arg: ret_df [WRITE] RETURN: first derivative of 4.1.6 evaluated at lambda [NullString] + * Arg: y [UNKN ] NULL (or y-axis of a histogram) [NullString] + * Arg: *x [UNKN ] Undocumented argument [float] + * Arg: x [UNKN ] array of sample values (or x-axis of a histogram) [NullString] + * Arg: *y [UNKN ] Undocumented argument [int] + * Arg: n [UNKN ] number of samples (or number of histogram bins) [int] + * Arg: lambda [UNKN ] a lambda to test [float] + * Arg: *ret_f [UNKN ] Undocumented argument [float] + * Arg: *ret_df [UNKN ] Undocumented argument [float] + * + */ +void bp_sw_Lawless416(float *x, int *y, int n, float lambda, float *ret_f, float *ret_df); +#define Lawless416 bp_sw_Lawless416 + + +/* Function: Lawless422(*x,ret_df,y,ret_f,x,*y,n,z,c,lambda,*ret_f,*ret_df) + * + * Descrip: No Description + * + * Arg: *x [UNKN ] Undocumented argument [float] + * Arg: ret_df [WRITE] RETURN: first derivative of 4.2.2 evaluated at lambda [NullString] + * Arg: y [UNKN ] NULL (or y axis of a histogram) [NullString] + * Arg: ret_f [WRITE] RETURN: 4.2.2 evaluated at lambda [NullString] + * Arg: x [UNKN ] array of sample values (or x axis of a histogram) [NullString] + * Arg: *y [UNKN ] Undocumented argument [int] + * Arg: n [UNKN ] number of observed samples (or number of histogram bins) [int] + * Arg: z [UNKN ] number of censored samples [int] + * Arg: c [UNKN ] censoring value; all observed x_i >= c [float] + * Arg: lambda [UNKN ] a lambda to test [float] + * Arg: *ret_f [UNKN ] Undocumented argument [float] + * Arg: *ret_df [UNKN ] Undocumented argument [float] + * + */ +void bp_sw_Lawless422(float *x, int *y, int n, int z, float c,float lambda, float *ret_f, float *ret_df); +#define Lawless422 bp_sw_Lawless422 + + +/* Function: EVDMaxLikelyFit(ret_lambda,x,*x,c,ret_mu,*c,n,*ret_mu,*ret_lambda) + * + * Descrip: No Description + * + * Arg: ret_lambda [WRITE] RETURN: ML estimate of lambda [NullString] + * Arg: x [UNKN ] list of EVD distributed samples or x axis of histogram [NullString] + * Arg: *x [UNKN ] Undocumented argument [float] + * Arg: c [UNKN ] NULL, or y-axis of histogram [NullString] + * Arg: ret_mu [WRITE] RETURN: ML estimate of mu [NullString] + * Arg: *c [UNKN ] Undocumented argument [int] + * Arg: n [UNKN ] number of samples, or number of histogram bins [int] + * Arg: *ret_mu [UNKN ] Undocumented argument [float] + * Arg: *ret_lambda [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] on success; 0 on any failure [int] + * + */ +int bp_sw_EVDMaxLikelyFit(float *x, int *c, int n, float *ret_mu, float *ret_lambda); +#define EVDMaxLikelyFit bp_sw_EVDMaxLikelyFit + + +/* Function: EVDCensoredFit(ret_mu,x,ret_lambda,y,*x,*y,n,z,c,*ret_mu,*ret_lambda) + * + * Descrip: No Description + * + * Arg: ret_mu [WRITE] RETURN: ML estimate of mu [NullString] + * Arg: x [UNKN ] list of EVD distributed samples or x axis of histogram [NullString] + * Arg: ret_lambda [WRITE] RETURN: ML estimate of lambda [NullString] + * Arg: y [UNKN ] NULL, or y axis of histogram [NullString] + * Arg: *x [UNKN ] Undocumented argument [float] + * Arg: *y [UNKN ] Undocumented argument [int] + * Arg: n [UNKN ] number of observed samples,or number of histogram bins [int] + * Arg: z [UNKN ] number of censored samples [int] + * Arg: c [UNKN ] censoring value (all x_i >= c) [float] + * Arg: *ret_mu [UNKN ] Undocumented argument [float] + * Arg: *ret_lambda [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_EVDCensoredFit(float *x, int *y, int n, int z, float c,float *ret_mu, float *ret_lambda); +#define EVDCensoredFit bp_sw_EVDCensoredFit + + +/* Function: Linefit(ret_r,x,*x,ret_b,y,ret_a,*y,N,*ret_a,*ret_b,*ret_r) + * + * Descrip: No Description + * + * Arg: ret_r [WRITE] RETURN: correlation coefficient [NullString] + * Arg: x [UNKN ] x values of data [NullString] + * Arg: *x [UNKN ] Undocumented argument [float] + * Arg: ret_b [WRITE] RETURN: slope [NullString] + * Arg: y [UNKN ] y values of data [NullString] + * Arg: ret_a [WRITE] RETURN: intercept [NullString] + * Arg: *y [UNKN ] Undocumented argument [float] + * Arg: N [UNKN ] number of data points [int] + * Arg: *ret_a [UNKN ] Undocumented argument [float] + * Arg: *ret_b [UNKN ] Undocumented argument [float] + * Arg: *ret_r [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] on success, 0 on failure. [int] + * + */ +int bp_sw_Linefit(float *x, float *y, int N, float *ret_a, float *ret_b, float *ret_r) ; +#define Linefit bp_sw_Linefit + + +/* Function: sre_random(void) + * + * Descrip: No Description + * + * + * Return [UNKN ] Undocumented return value [float] + * + */ +float bp_sw_sre_random(void); +#define sre_random bp_sw_sre_random + + +/* Function: IncompleteGamma(a,x) + * + * Descrip: No Description + * + * Arg: a [UNKN ] Undocumented argument [double] + * Arg: x [UNKN ] Undocumented argument [double] + * + * Return [UNKN ] Undocumented return value [double] + * + */ +double bp_sw_IncompleteGamma(double a, double x); +#define IncompleteGamma bp_sw_IncompleteGamma + + +/* Function: Gammln(x) + * + * Descrip: No Description + * + * Arg: x [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] Undocumented return value [float] + * + */ +float bp_sw_Gammln(float x); +#define Gammln bp_sw_Gammln + + +/* Function: hard_link_Histogram(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [Histogram *] + * + * Return [UNKN ] Undocumented return value [Histogram *] + * + */ +Histogram * bp_sw_hard_link_Histogram(Histogram * obj); +#define hard_link_Histogram bp_sw_hard_link_Histogram + + +/* Function: Histogram_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [Histogram *] + * + */ +Histogram * bp_sw_Histogram_alloc(void); +#define Histogram_alloc bp_sw_Histogram_alloc + + +/* Function: free_Histogram(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [Histogram *] + * + * Return [UNKN ] Undocumented return value [Histogram *] + * + */ +Histogram * bp_sw_free_Histogram(Histogram * obj); +#define free_Histogram bp_sw_free_Histogram + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/hscore.c b/Bio/Ext/Align/libs/hscore.c new file mode 100644 index 0000000..84587ca --- /dev/null +++ b/Bio/Ext/Align/libs/hscore.c @@ -0,0 +1,1441 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "hscore.h" + + +/* Function: should_store_Hscore(hs,score) + * + * Descrip: Tells whether this score should be stored + * or not. Also updates Histogram if needed + * + * + * Arg: hs [UNKN ] Undocumented argument [Hscore *] + * Arg: score [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 102 "hscore.dy" +boolean should_store_Hscore(Hscore * hs,int score) +{ + hs->total++; + + if( hs->report_level != -1 && (hs->total % hs->report_level == 0)) { + if( hs->len > 0) { + info("Done %d comparisons: last stored comparison was %s to %s",hs->total,hs->ds[hs->len-1]->query->name,hs->ds[hs->len-1]->target->name); + } else { + info("Done %d comparisons: No stored comparisons",hs->total); + } + } + + if( hs->his != NULL && hs->score_to_his != NULL ) { + AddToHistogram(hs->his,(*hs->score_to_his)(score)); + } + if( hs->should_store == NULL ) { + return TRUE; + } + return (*hs->should_store)(score,hs->score_level); +} + + +/* Function: length_datascore_Hscore(obj) + * + * Descrip: Returns the number of datascores in the hscore + * structure + * + * + * Arg: obj [READ ] Hscore object [Hscore *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 131 "hscore.dy" +int length_datascore_Hscore(Hscore * obj) +{ + return obj->len; +} + + +/* Function: get_datascore_Hscore(hs,i) + * + * Descrip: Returns the specific datascore held at this + * position. + * + * This requires a considerable amount of memory + * duplication, so please dont process all your + * results by looping through this. + * + * + * Arg: hs [READ ] Hscore object [Hscore *] + * Arg: i [UNKN ] position to be read [int] + * + * Return [OWNER] New datascore object [DataScore *] + * + */ +# line 150 "hscore.dy" +DataScore * get_datascore_Hscore(Hscore * hs,int i) +{ + DataScore * out; + + out = new_DataScore(); + copy_DataEntry(hs->ds[i]->query,out->query); + copy_DataEntry(hs->ds[i]->target,out->target); + out->score = hs->ds[i]->score; + out->evalue = hs->ds[i]->evalue; + return out; +} + +/* Function: copy_DataEntry(from,to) + * + * Descrip: Copies the info from one DataEntry to another + * + * + * Arg: from [UNKN ] Undocumented argument [DataEntry *] + * Arg: to [UNKN ] Undocumented argument [DataEntry *] + * + */ +# line 166 "hscore.dy" +void copy_DataEntry(DataEntry * from,DataEntry * to) +{ + int i; + + to->name = stringalloc(from->name); + for(i=0;idata[i] = from->data[i]; + to->is_reversed = from->is_reversed; + to->filename = from->filename; /* linked! */ +} + +/* Function: get_score_Hscore(hs,i) + * + * Descrip: No Description + * + * Arg: hs [READ ] Hscore object [Hscore *] + * Arg: i [UNKN ] position to be read [int] + * + * Return [UNKN ] score [int] + * + */ +# line 187 "hscore.dy" +int get_score_Hscore(Hscore * hs,int i) +{ + return hs->ds[i]->score; +} + + +/* Function: get_evalue_Hscore(hs,i) + * + * Descrip: Returns the evalue of the specific datascore held at this position. + * + * + * + * Arg: hs [READ ] Hscore object [Hscore *] + * Arg: i [UNKN ] position to be read [int] + * + * Return [UNKN ] evalue [double] + * + */ +# line 202 "hscore.dy" +double get_evalue_Hscore(Hscore * hs,int i) +{ + return hs->ds[i]->evalue; +} + +/* Function: fit_Hscore_to_EVD(hs,guess_of_outliers) + * + * Descrip: If a histogram is present, tries to fit the histogram and + * then gives evalues to all the scores in the Hscore model + * + * + * Arg: hs [UNKN ] Undocumented argument [Hscore *] + * Arg: guess_of_outliers [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 211 "hscore.dy" +boolean fit_Hscore_to_EVD(Hscore * hs,float guess_of_outliers) +{ + int i; + + + if( hs->his == NULL ) { + warn("Your Hscore has no histogram structure, and so no EVD can be fitted"); + return FALSE; + } + + if( ExtremeValueFitHistogram(hs->his,TRUE,guess_of_outliers) == 0 ) { + warn("Extreme Value distribution is unable to be fitted. Sorry!"); + return FALSE; + } + + + for(i=0;ilen;i++) { + hs->ds[i]->evalue = ExtremeValueE((*hs->score_to_his)(hs->ds[i]->score),hs->his->param[EVD_MU],hs->his->param[EVD_LAMBDA],hs->his->total); + } + + return TRUE; +} + + +/* Function: minimum_score_Hscore(hs) + * + * Descrip: gets the minimum score from Hscore + * + * + * Arg: hs [UNKN ] Undocumented argument [Hscore *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 238 "hscore.dy" +int minimum_score_Hscore(Hscore * hs) +{ + int i; + int min; + + if( hs->len == 0) { + warn("Can't get a minimum score with no entries"); + return 0; + } + + for(i=1,min=hs->ds[0]->score;ilen;i++) { + if( min > hs->ds[i]->score ) { + min = hs->ds[i]->score; + } + } + + return min; +} + +/* Function: maximum_score_Hscore(hs) + * + * Descrip: gets the maximum score from Hscore + * + * + * Arg: hs [UNKN ] Undocumented argument [Hscore *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 260 "hscore.dy" +int maximum_score_Hscore(Hscore * hs) +{ + int i; + int max; + + if( hs->len == 0) { + warn("Can't get a minimum score with no entries"); + return 0; + } + + for(i=1,max=hs->ds[0]->score;ilen;i++) { + if( max < hs->ds[i]->score ) { + max = hs->ds[i]->score; + } + } + + return max; +} + + +/* Function: basic_show_Hscore(hs,ofp) + * + * Descrip: The most baby-talk showing of Hscore + * + * + * Arg: hs [UNKN ] Undocumented argument [Hscore *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 285 "hscore.dy" +void basic_show_Hscore(Hscore * hs,FILE * ofp) +{ + int i; + + for(i=0;ilen;i++) { + fprintf(ofp,"%3d Query: %12s Target: %12s Score %d\n",i, + hs->ds[i]->query->name == NULL ? "NoName" : hs->ds[i]->query->name, + hs->ds[i]->target->name == NULL ? "NoName" : hs->ds[i]->target->name, + hs->ds[i]->score); + } +} + +/* Function: sort_Hscore_by_score(hs) + * + * Descrip: As it says, sorts the high score by its score + * + * + * Arg: hs [UNKN ] Hscore to be sorted [Hscore *] + * + */ +# line 302 "hscore.dy" +void sort_Hscore_by_score(Hscore * hs) +{ + sort_Hscore(hs,compare_DataScore_by_score); +} + + +/* Function: compare_DataScore_by_score(one,two) + * + * Descrip: Used to compare two datascores for + * /sort_Hscore_by_score + * + * + * Arg: one [UNKN ] Undocumented argument [DataScore *] + * Arg: two [UNKN ] Undocumented argument [DataScore *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 314 "hscore.dy" +int compare_DataScore_by_score(DataScore * one,DataScore * two) +{ + if( one->score == two->score ) { + if( one->query != NULL && one->query->name != NULL && two->query != NULL && two->query->name != NULL ) + return strcmp(one->query->name,two->query->name); + else return 1; + } + + return two->score - one->score; +} + + +/* Function: new_DataScore(void) + * + * Descrip: The best way to make a new DataScore. + * Allocates the query and target DataEntry structures + * as well as the DataScore structure. + * + * + * + * Return [UNKN ] Undocumented return value [DataScore *] + * + */ +# line 333 "hscore.dy" +DataScore * new_DataScore(void) +{ + DataScore * ds; + + ds = DataScore_alloc(); + ds->query = DataEntry_alloc(); + ds->target = DataEntry_alloc(); + + return ds; +} + +/* Function: new_DataScore_from_storage(hs) + * + * Descrip: Gets a new DataScore from Storage + * + * + * Arg: hs [UNKN ] Undocumented argument [Hscore *] + * + * Return [UNKN ] Undocumented return value [DataScore *] + * + */ +# line 348 "hscore.dy" +DataScore * new_DataScore_from_storage(Hscore * hs) +{ + DataScoreStorage * new; + DataScoreStorage * curr; + + if( hs->st_len == 0 ) { + new = new_DataScoreStorage(); + if( new == NULL ) { + warn("could not make inital data score storage!"); + return NULL; + } + add_st_Hscore(hs,new); + curr = new; + } else { + curr = hs->store[hs->st_len-1]; + if( curr->curr_pos == DATASCORESTORAGE_LENGTH ) { + new = new_DataScoreStorage(); + if( new == NULL ) { + warn("could not make data score storage block %d!",hs->st_len-1); + return NULL; + } + add_st_Hscore(hs,new); + curr = new; + } + } + + return &curr->score_array[curr->curr_pos++]; +} + + + +/* Function: free_DataScore(obj) + * + * Descrip: Correctly handles destruction of a datascore + * + * + * Arg: obj [UNKN ] Undocumented argument [DataScore *] + * + * Return [UNKN ] Undocumented return value [DataScore *] + * + */ +# line 383 "hscore.dy" +DataScore * free_DataScore(DataScore * obj) +{ + if( obj->is_stored == 1 ) { + return NULL; /* don't free! */ + } + if( obj->dynamite_hard_link > 1 ) { + obj->dynamite_hard_link--; + return NULL; + } + + if( obj->query != NULL ) + free_DataEntry(obj->query); + + if( obj->target != NULL ) + free_DataEntry(obj->target); + + return NULL; +} + +/* Function: free_DataScoreStorage(obj) + * + * Descrip: Correctly handles destruction of DataScoreStorage, by + * freeing members in data storage + * + * + * Arg: obj [UNKN ] Undocumented argument [DataScoreStorage *] + * + * Return [UNKN ] Undocumented return value [DataScoreStorage *] + * + */ +# line 407 "hscore.dy" +DataScoreStorage * free_DataScoreStorage(DataScoreStorage * obj) +{ + int i; + + for(i=0;icurr_pos;i++) { + if( obj->query_array[i].name != NULL ) { + ckfree(obj->query_array[i].name); + } + if( obj->target_array[i].name != NULL ) { + ckfree(obj->target_array[i].name); + } + } + + ckfree(obj); + + return NULL; +} + + + +/* Function: new_DataScoreStorage(void) + * + * Descrip: Makes a new DataScoreStorage with all the pointers connected correctly + * + * + * + * Return [UNKN ] Undocumented return value [DataScoreStorage *] + * + */ +# line 430 "hscore.dy" +DataScoreStorage * new_DataScoreStorage(void) +{ + DataScoreStorage * out; + int i; + + out = DataScoreStorage_alloc(); + if( out == NULL ) { + warn("Unable to make a new DataScoreStorage block with blocksize %d",DATASCORESTORAGE_LENGTH); + return NULL; + } + + for(i=0;iscore_array[i].query = &out->query_array[i]; + out->score_array[i].target = &out->target_array[i]; + out->score_array[i].is_stored = 1; + } + + return out; +} + +# line 427 "hscore.c" +/* Function: hard_link_DataEntry(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DataEntry *] + * + * Return [UNKN ] Undocumented return value [DataEntry *] + * + */ +DataEntry * hard_link_DataEntry(DataEntry * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a DataEntry object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: DataEntry_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DataEntry *] + * + */ +DataEntry * DataEntry_alloc(void) +{ + DataEntry * out;/* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(DataEntry *) ckalloc (sizeof(DataEntry))) == NULL) { + warn("DataEntry_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->name = NULL; + /* data[DATAENTRYSTDPOINTS] is an array: no default possible */ + out->is_reversed = FALSE; + + + return out; +} + + +/* Function: free_DataEntry(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [DataEntry *] + * + * Return [UNKN ] Undocumented return value [DataEntry *] + * + */ +DataEntry * free_DataEntry(DataEntry * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a DataEntry obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->name != NULL) + ckfree(obj->name); + /* obj->filename is linked in */ + + + ckfree(obj); + return NULL; +} + + +/* Function: hard_link_DataScore(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DataScore *] + * + * Return [UNKN ] Undocumented return value [DataScore *] + * + */ +DataScore * hard_link_DataScore(DataScore * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a DataScore object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: DataScore_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DataScore *] + * + */ +DataScore * DataScore_alloc(void) +{ + DataScore * out;/* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(DataScore *) ckalloc (sizeof(DataScore))) == NULL) { + warn("DataScore_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->query = NULL; + out->target = NULL; + out->score = 0; + out->evalue = 0; + out->is_stored = 0; + + + return out; +} + + +/* Function: hard_link_DataScoreStorage(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DataScoreStorage *] + * + * Return [UNKN ] Undocumented return value [DataScoreStorage *] + * + */ +DataScoreStorage * hard_link_DataScoreStorage(DataScoreStorage * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a DataScoreStorage object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: DataScoreStorage_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DataScoreStorage *] + * + */ +DataScoreStorage * DataScoreStorage_alloc(void) +{ + DataScoreStorage * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(DataScoreStorage *) ckalloc (sizeof(DataScoreStorage))) == NULL) { + warn("DataScoreStorage_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + /* score_array[DATASCORESTORAGE_LENGTH] is an array: no default possible */ + /* query_array[DATASCORESTORAGE_LENGTH] is an array: no default possible */ + /* target_array[DATASCORESTORAGE_LENGTH] is an array: no default possible */ + out->curr_pos = 0; + + + return out; +} + + +/* Function: swap_Hscore(list,i,j) + * + * Descrip: swap function: an internal for qsort_Hscore + * swaps two positions in the array + * + * + * Arg: list [UNKN ] List of structures to swap in [DataScore **] + * Arg: i [UNKN ] swap position [int] + * Arg: j [UNKN ] swap position [int] + * + */ +/* swap function for qsort function */ +void swap_Hscore(DataScore ** list,int i,int j) +{ + DataScore * temp; + temp=list[i]; + list[i]=list[j]; + list[j]=temp; +} + + +/* Function: qsort_Hscore(list,left,right,comp) + * + * Descrip: qsort - lifted from K&R + * sorts the array using quicksort + * Probably much better to call sort_Hscore which sorts from start to end + * + * + * Arg: list [UNKN ] List of structures to swap in [DataScore **] + * Arg: left [UNKN ] left position [int] + * Arg: right [UNKN ] right position [int] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void qsort_Hscore(DataScore ** list,int left,int right,int (*comp)(DataScore * ,DataScore * )) +{ + int i,last; + if( left >= right ) + return; + + + swap_Hscore(list,left,(left+right)/2); + last = left; + for ( i=left+1; i <= right;i++) { + if( (*comp)(list[i],list[left]) < 0) + swap_Hscore (list,++last,i); + } + swap_Hscore (list,left,last); + qsort_Hscore(list,left,last-1,comp); + qsort_Hscore(list,last+1,right,comp); +} + + +/* Function: sort_Hscore(obj,comp) + * + * Descrip: sorts from start to end using comp + * sorts the array using quicksort by calling qsort_Hscore + * + * + * Arg: obj [UNKN ] Object containing list [Hscore *] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void sort_Hscore(Hscore * obj,int (*comp)(DataScore *, DataScore *)) +{ + qsort_Hscore(obj->ds,0,obj->len-1,comp); + return; +} + + +/* Function: expand_Hscore(obj,len) + * + * Descrip: Really an internal function for add_Hscore + * + * + * Arg: obj [UNKN ] Object which contains the list [Hscore *] + * Arg: len [UNKN ] Length to add one [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean expand_Hscore(Hscore * obj,int len) +{ + + + if( obj->maxlen > obj->len ) { + warn("expand_Hscore called with no need"); + return TRUE; + } + + + if( (obj->ds = (DataScore ** ) ckrealloc (obj->ds,sizeof(DataScore *)*len)) == NULL) { + warn("ckrealloc failed for expand_Hscore, returning FALSE"); + return FALSE; + } + obj->maxlen = len; + return TRUE; +} + + +/* Function: add_Hscore(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [Hscore *] + * Arg: add [OWNER] Object to add to the list [DataScore *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +/* will expand function if necessary */ +boolean add_Hscore(Hscore * obj,DataScore * add) +{ + if( obj->len >= obj->maxlen) { + if( expand_Hscore(obj,obj->len + HscoreLISTLENGTH) == FALSE) + return FALSE; + } + + + obj->ds[obj->len++]=add; + return TRUE; +} + + +/* Function: flush_Hscore(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [Hscore *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int flush_Hscore(Hscore * obj) +{ + int i; + + + for(i=0;ilen;i++) { + if( obj->ds[i] != NULL) { + free_DataScore(obj->ds[i]); + obj->ds[i] = NULL; + } + } /* end of for i over list length */ + + + obj->len = 0; + return i; +} + + +/* Function: swap_st_Hscore(list,i,j) + * + * Descrip: swap function: an internal for qsort_st_Hscore + * swaps two positions in the array + * + * + * Arg: list [UNKN ] List of structures to swap in [DataScoreStorage **] + * Arg: i [UNKN ] swap position [int] + * Arg: j [UNKN ] swap position [int] + * + */ +/* swap function for qsort function */ +void swap_st_Hscore(DataScoreStorage ** list,int i,int j) +{ + DataScoreStorage * temp; + temp=list[i]; + list[i]=list[j]; + list[j]=temp; +} + + +/* Function: qsort_st_Hscore(list,left,right,comp) + * + * Descrip: qsort - lifted from K&R + * sorts the array using quicksort + * Probably much better to call sort_st_Hscore which sorts from start to end + * + * + * Arg: list [UNKN ] List of structures to swap in [DataScoreStorage **] + * Arg: left [UNKN ] left position [int] + * Arg: right [UNKN ] right position [int] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void qsort_st_Hscore(DataScoreStorage ** list,int left,int right,int (*comp)(DataScoreStorage * ,DataScoreStorage * )) +{ + int i,last; + if( left >= right ) + return; + + + swap_st_Hscore(list,left,(left+right)/2); + last = left; + for ( i=left+1; i <= right;i++) { + if( (*comp)(list[i],list[left]) < 0) + swap_st_Hscore (list,++last,i); + } + swap_st_Hscore (list,left,last); + qsort_st_Hscore(list,left,last-1,comp); + qsort_st_Hscore(list,last+1,right,comp); +} + + +/* Function: sort_st_Hscore(obj,comp) + * + * Descrip: sorts from start to end using comp + * sorts the array using quicksort by calling qsort_st_Hscore + * + * + * Arg: obj [UNKN ] Object containing list [Hscore *] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void sort_st_Hscore(Hscore * obj,int (*comp)(DataScoreStorage *, DataScoreStorage *)) +{ + qsort_st_Hscore(obj->store,0,obj->st_len-1,comp); + return; +} + + +/* Function: expand_st_Hscore(obj,len) + * + * Descrip: Really an internal function for add_st_Hscore + * + * + * Arg: obj [UNKN ] Object which contains the list [Hscore *] + * Arg: len [UNKN ] Length to add one [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean expand_st_Hscore(Hscore * obj,int len) +{ + + + if( obj->st_maxlen > obj->st_len ) { + warn("expand_Hscorest_ called with no need"); + return TRUE; + } + + + if( (obj->store = (DataScoreStorage ** ) ckrealloc (obj->store,sizeof(DataScoreStorage *)*len)) == NULL) { + warn("ckrealloc failed for expand_Hscore, returning FALSE"); + return FALSE; + } + obj->st_maxlen = len; + return TRUE; +} + + +/* Function: add_st_Hscore(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [Hscore *] + * Arg: add [OWNER] Object to add to the list [DataScoreStorage *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +/* will expand function if necessary */ +boolean add_st_Hscore(Hscore * obj,DataScoreStorage * add) +{ + if( obj->st_len >= obj->st_maxlen) { + if( expand_st_Hscore(obj,obj->st_len + HscoreLISTLENGTH) == FALSE) + return FALSE; + } + + + obj->store[obj->st_len++]=add; + return TRUE; +} + + +/* Function: flush_st_Hscore(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [Hscore *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int flush_st_Hscore(Hscore * obj) +{ + int i; + + + for(i=0;ist_len;i++) { + if( obj->store[i] != NULL) { + free_DataScoreStorage(obj->store[i]); + obj->store[i] = NULL; + } + } /* end of for i over list length */ + + + obj->st_len = 0; + return i; +} + + +/* Function: Hscore_alloc_std(void) + * + * Descrip: Equivalent to Hscore_alloc_len(HscoreLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [Hscore *] + * + */ +Hscore * Hscore_alloc_std(void) +{ + return Hscore_alloc_len(HscoreLISTLENGTH); +} + + +/* Function: Hscore_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [Hscore *] + * + */ +Hscore * Hscore_alloc_len(int len) +{ + Hscore * out; /* out is exported at the end of function */ + + + /* Call alloc function: return NULL if NULL */ + /* Warning message alread in alloc function */ + if((out = Hscore_alloc()) == NULL) + return NULL; + + + /* Calling ckcalloc for list elements */ + if((out->ds = (DataScore ** ) ckcalloc (len,sizeof(DataScore *))) == NULL) { + warn("Warning, ckcalloc failed in Hscore_alloc_len"); + return NULL; + } + out->len = 0; + out->maxlen = len; + + + if((out->store = (DataScoreStorage ** ) ckcalloc (len,sizeof(DataScoreStorage *))) == NULL) { + warn("Warning, ckcalloc failed in Hscore_alloc_len"); + return NULL; + } + out->st_len = 0; + out->st_maxlen = len; + + + return out; +} + + +/* Function: hard_link_Hscore(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [Hscore *] + * + * Return [UNKN ] Undocumented return value [Hscore *] + * + */ +Hscore * hard_link_Hscore(Hscore * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a Hscore object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: Hscore_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [Hscore *] + * + */ +Hscore * Hscore_alloc(void) +{ + Hscore * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(Hscore *) ckalloc (sizeof(Hscore))) == NULL) { + warn("Hscore_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->ds = NULL; + out->len = out->maxlen = 0; + out->store = NULL; + out->st_len = out->st_maxlen = 0; + out->his = NULL; + out->score_level = 0; + out->should_store = NULL; + out->score_to_his = NULL; + out->report_level = 0; + out->total = 0; + + + return out; +} + + +/* Function: free_Hscore(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [Hscore *] + * + * Return [UNKN ] Undocumented return value [Hscore *] + * + */ +Hscore * free_Hscore(Hscore * obj) +{ + int i; + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a Hscore obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->ds != NULL) { + for(i=0;ilen;i++) { + if( obj->ds[i] != NULL) + free_DataScore(obj->ds[i]); + } + ckfree(obj->ds); + } + if( obj->store != NULL) { + for(i=0;ist_len;i++) { + if( obj->store[i] != NULL) + free_DataScoreStorage(obj->store[i]); + } + ckfree(obj->store); + } + if( obj->his != NULL) + free_Histogram(obj->his); + /* obj->should_store is a function pointer */ + /* obj->score_to_his is a function pointer */ + + + ckfree(obj); + return NULL; +} + + +/* Function: replace_query_DataScore(obj,query) + * + * Descrip: Replace member variable query + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataScore *] + * Arg: query [OWNER] New value of the variable [DataEntry *] + * + * Return [SOFT ] member variable query [boolean] + * + */ +boolean replace_query_DataScore(DataScore * obj,DataEntry * query) +{ + if( obj == NULL) { + warn("In replacement function query for object DataScore, got a NULL object"); + return FALSE; + } + obj->query = query; + return TRUE; +} + + +/* Function: access_query_DataScore(obj) + * + * Descrip: Access member variable query + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataScore *] + * + * Return [SOFT ] member variable query [DataEntry *] + * + */ +DataEntry * access_query_DataScore(DataScore * obj) +{ + if( obj == NULL) { + warn("In accessor function query for object DataScore, got a NULL object"); + return NULL; + } + return obj->query; +} + + +/* Function: replace_target_DataScore(obj,target) + * + * Descrip: Replace member variable target + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataScore *] + * Arg: target [OWNER] New value of the variable [DataEntry *] + * + * Return [SOFT ] member variable target [boolean] + * + */ +boolean replace_target_DataScore(DataScore * obj,DataEntry * target) +{ + if( obj == NULL) { + warn("In replacement function target for object DataScore, got a NULL object"); + return FALSE; + } + obj->target = target; + return TRUE; +} + + +/* Function: access_target_DataScore(obj) + * + * Descrip: Access member variable target + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataScore *] + * + * Return [SOFT ] member variable target [DataEntry *] + * + */ +DataEntry * access_target_DataScore(DataScore * obj) +{ + if( obj == NULL) { + warn("In accessor function target for object DataScore, got a NULL object"); + return NULL; + } + return obj->target; +} + + +/* Function: replace_score_DataScore(obj,score) + * + * Descrip: Replace member variable score + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataScore *] + * Arg: score [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable score [boolean] + * + */ +boolean replace_score_DataScore(DataScore * obj,int score) +{ + if( obj == NULL) { + warn("In replacement function score for object DataScore, got a NULL object"); + return FALSE; + } + obj->score = score; + return TRUE; +} + + +/* Function: access_score_DataScore(obj) + * + * Descrip: Access member variable score + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataScore *] + * + * Return [SOFT ] member variable score [int] + * + */ +int access_score_DataScore(DataScore * obj) +{ + if( obj == NULL) { + warn("In accessor function score for object DataScore, got a NULL object"); + return 0; + } + return obj->score; +} + + +/* Function: replace_evalue_DataScore(obj,evalue) + * + * Descrip: Replace member variable evalue + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataScore *] + * Arg: evalue [OWNER] New value of the variable [double] + * + * Return [SOFT ] member variable evalue [boolean] + * + */ +boolean replace_evalue_DataScore(DataScore * obj,double evalue) +{ + if( obj == NULL) { + warn("In replacement function evalue for object DataScore, got a NULL object"); + return FALSE; + } + obj->evalue = evalue; + return TRUE; +} + + +/* Function: access_evalue_DataScore(obj) + * + * Descrip: Access member variable evalue + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataScore *] + * + * Return [SOFT ] member variable evalue [double] + * + */ +double access_evalue_DataScore(DataScore * obj) +{ + if( obj == NULL) { + warn("In accessor function evalue for object DataScore, got a NULL object"); + return 0; + } + return obj->evalue; +} + + +/* Function: replace_name_DataEntry(obj,name) + * + * Descrip: Replace member variable name + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataEntry *] + * Arg: name [OWNER] New value of the variable [char *] + * + * Return [SOFT ] member variable name [boolean] + * + */ +boolean replace_name_DataEntry(DataEntry * obj,char * name) +{ + if( obj == NULL) { + warn("In replacement function name for object DataEntry, got a NULL object"); + return FALSE; + } + obj->name = name; + return TRUE; +} + + +/* Function: access_name_DataEntry(obj) + * + * Descrip: Access member variable name + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataEntry *] + * + * Return [SOFT ] member variable name [char *] + * + */ +char * access_name_DataEntry(DataEntry * obj) +{ + if( obj == NULL) { + warn("In accessor function name for object DataEntry, got a NULL object"); + return NULL; + } + return obj->name; +} + + +/* Function: replace_is_reversed_DataEntry(obj,is_reversed) + * + * Descrip: Replace member variable is_reversed + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataEntry *] + * Arg: is_reversed [OWNER] New value of the variable [boolean] + * + * Return [SOFT ] member variable is_reversed [boolean] + * + */ +boolean replace_is_reversed_DataEntry(DataEntry * obj,boolean is_reversed) +{ + if( obj == NULL) { + warn("In replacement function is_reversed for object DataEntry, got a NULL object"); + return FALSE; + } + obj->is_reversed = is_reversed; + return TRUE; +} + + +/* Function: access_is_reversed_DataEntry(obj) + * + * Descrip: Access member variable is_reversed + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataEntry *] + * + * Return [SOFT ] member variable is_reversed [boolean] + * + */ +boolean access_is_reversed_DataEntry(DataEntry * obj) +{ + if( obj == NULL) { + warn("In accessor function is_reversed for object DataEntry, got a NULL object"); + return FALSE; + } + return obj->is_reversed; +} + + +/* Function: replace_filename_DataEntry(obj,filename) + * + * Descrip: Replace member variable filename + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataEntry *] + * Arg: filename [OWNER] New value of the variable [char *] + * + * Return [SOFT ] member variable filename [boolean] + * + */ +boolean replace_filename_DataEntry(DataEntry * obj,char * filename) +{ + if( obj == NULL) { + warn("In replacement function filename for object DataEntry, got a NULL object"); + return FALSE; + } + obj->filename = filename; + return TRUE; +} + + +/* Function: access_filename_DataEntry(obj) + * + * Descrip: Access member variable filename + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [DataEntry *] + * + * Return [SOFT ] member variable filename [char *] + * + */ +char * access_filename_DataEntry(DataEntry * obj) +{ + if( obj == NULL) { + warn("In accessor function filename for object DataEntry, got a NULL object"); + return NULL; + } + return obj->filename; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/hscore.h b/Bio/Ext/Align/libs/hscore.h new file mode 100644 index 0000000..217c7a1 --- /dev/null +++ b/Bio/Ext/Align/libs/hscore.h @@ -0,0 +1,621 @@ +#ifndef DYNAMITEhscoreHEADERFILE +#define DYNAMITEhscoreHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" +#include "histogram.h" + +#define HscoreLISTLENGTH 256 +#define DATAENTRYSTDPOINTS 8 + +#define DATASCORESTORAGE_LENGTH 1024 + +/* Object DataEntry + * + * Descrip: A lightweight structure to represent the information + * a db search algorithm will want to store and *nothing* + * more about a single entry + * + * + */ +struct bp_sw_DataEntry { + int dynamite_hard_link; + char * name; /* name of the entry */ + int data[DATAENTRYSTDPOINTS]; /* space for algorithms to use */ + boolean is_reversed; /* for sequences. handy */ + char * filename; /* useful for indexers etc. */ + } ; +/* DataEntry defined */ +#ifndef DYNAMITE_DEFINED_DataEntry +typedef struct bp_sw_DataEntry bp_sw_DataEntry; +#define DataEntry bp_sw_DataEntry +#define DYNAMITE_DEFINED_DataEntry +#endif + + +/* Object DataScore + * + * Descrip: The basic one entry vs one entry structure + * + * + */ +struct bp_sw_DataScore { + int dynamite_hard_link; + DataEntry * query; + DataEntry * target; + int score; + double evalue; + int is_stored; + } ; +/* DataScore defined */ +#ifndef DYNAMITE_DEFINED_DataScore +typedef struct bp_sw_DataScore bp_sw_DataScore; +#define DataScore bp_sw_DataScore +#define DYNAMITE_DEFINED_DataScore +#endif + + +/* Object DataScoreStorage + * + * Descrip: Scary internal structure to simplify storage methods + * + * + */ +struct bp_sw_DataScoreStorage { + int dynamite_hard_link; + DataScore score_array[DATASCORESTORAGE_LENGTH]; + DataEntry query_array[DATASCORESTORAGE_LENGTH]; + DataEntry target_array[DATASCORESTORAGE_LENGTH]; + int curr_pos; + } ; +/* DataScoreStorage defined */ +#ifndef DYNAMITE_DEFINED_DataScoreStorage +typedef struct bp_sw_DataScoreStorage bp_sw_DataScoreStorage; +#define DataScoreStorage bp_sw_DataScoreStorage +#define DYNAMITE_DEFINED_DataScoreStorage +#endif + + +/* Object Hscore + * + * Descrip: Holds the information about a db search. + * Meant to be very lightweight + * + * The histogram is carried for on-the-fly histogram storage outside + * of the database. The idea is that the function should_store will + * tell whether the datascore structure should be stored (if it is + * NULL, it is always stored). The score_to_his function maps the + * score in datascore to the float in Histogram, allowing the scoring + * system of the search method to be on a different basis to the + * scoring system of the histogram. For most times, this is going to + * be Score2Bits + * + * To prevent too much dependency, the 'standard' way of making a + * histogram that has a bits cut off level is done using functions + * in the dynlibcross module (cross code), as it needs both Hscore and + * Probability + * + * + */ +struct bp_sw_Hscore { + int dynamite_hard_link; + DataScore ** ds; + int len;/* len for above ds */ + int maxlen; /* maxlen for above ds */ + DataScoreStorage ** store; + int st_len; /* len for above store */ + int st_maxlen; /* maxlen for above store */ + Histogram * his; + double score_level; /* passed into should_store function */ + boolean (*should_store)(int given_score,double internal_score_level); + float (*score_to_his)(int given_score); + int report_level; /* number of sequences to report on */ + long total; /* total number of scores (duplicated info in histogram) */ + } ; +/* Hscore defined */ +#ifndef DYNAMITE_DEFINED_Hscore +typedef struct bp_sw_Hscore bp_sw_Hscore; +#define Hscore bp_sw_Hscore +#define DYNAMITE_DEFINED_Hscore +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: should_store_Hscore(hs,score) + * + * Descrip: Tells whether this score should be stored + * or not. Also updates Histogram if needed + * + * + * Arg: hs [UNKN ] Undocumented argument [Hscore *] + * Arg: score [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_should_store_Hscore(Hscore * hs,int score); +#define should_store_Hscore bp_sw_should_store_Hscore + + +/* Function: length_datascore_Hscore(obj) + * + * Descrip: Returns the number of datascores in the hscore + * structure + * + * + * Arg: obj [READ ] Hscore object [Hscore *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_length_datascore_Hscore(Hscore * obj); +#define length_datascore_Hscore bp_sw_length_datascore_Hscore + + +/* Function: get_datascore_Hscore(hs,i) + * + * Descrip: Returns the specific datascore held at this + * position. + * + * This requires a considerable amount of memory + * duplication, so please dont process all your + * results by looping through this. + * + * + * Arg: hs [READ ] Hscore object [Hscore *] + * Arg: i [UNKN ] position to be read [int] + * + * Return [OWNER] New datascore object [DataScore *] + * + */ +DataScore * bp_sw_get_datascore_Hscore(Hscore * hs,int i); +#define get_datascore_Hscore bp_sw_get_datascore_Hscore + + +/* Function: get_score_Hscore(hs,i) + * + * Descrip: No Description + * + * Arg: hs [READ ] Hscore object [Hscore *] + * Arg: i [UNKN ] position to be read [int] + * + * Return [UNKN ] score [int] + * + */ +int bp_sw_get_score_Hscore(Hscore * hs,int i); +#define get_score_Hscore bp_sw_get_score_Hscore + + +/* Function: get_evalue_Hscore(hs,i) + * + * Descrip: Returns the evalue of the specific datascore held at this position. + * + * + * + * Arg: hs [READ ] Hscore object [Hscore *] + * Arg: i [UNKN ] position to be read [int] + * + * Return [UNKN ] evalue [double] + * + */ +double bp_sw_get_evalue_Hscore(Hscore * hs,int i); +#define get_evalue_Hscore bp_sw_get_evalue_Hscore + + +/* Function: fit_Hscore_to_EVD(hs,guess_of_outliers) + * + * Descrip: If a histogram is present, tries to fit the histogram and + * then gives evalues to all the scores in the Hscore model + * + * + * Arg: hs [UNKN ] Undocumented argument [Hscore *] + * Arg: guess_of_outliers [UNKN ] Undocumented argument [float] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_fit_Hscore_to_EVD(Hscore * hs,float guess_of_outliers); +#define fit_Hscore_to_EVD bp_sw_fit_Hscore_to_EVD + + +/* Function: minimum_score_Hscore(hs) + * + * Descrip: gets the minimum score from Hscore + * + * + * Arg: hs [UNKN ] Undocumented argument [Hscore *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_minimum_score_Hscore(Hscore * hs); +#define minimum_score_Hscore bp_sw_minimum_score_Hscore + + +/* Function: maximum_score_Hscore(hs) + * + * Descrip: gets the maximum score from Hscore + * + * + * Arg: hs [UNKN ] Undocumented argument [Hscore *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_maximum_score_Hscore(Hscore * hs); +#define maximum_score_Hscore bp_sw_maximum_score_Hscore + + +/* Function: basic_show_Hscore(hs,ofp) + * + * Descrip: The most baby-talk showing of Hscore + * + * + * Arg: hs [UNKN ] Undocumented argument [Hscore *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_basic_show_Hscore(Hscore * hs,FILE * ofp); +#define basic_show_Hscore bp_sw_basic_show_Hscore + + +/* Function: sort_Hscore_by_score(hs) + * + * Descrip: As it says, sorts the high score by its score + * + * + * Arg: hs [UNKN ] Hscore to be sorted [Hscore *] + * + */ +void bp_sw_sort_Hscore_by_score(Hscore * hs); +#define sort_Hscore_by_score bp_sw_sort_Hscore_by_score + + +/* Function: free_DataScore(obj) + * + * Descrip: Correctly handles destruction of a datascore + * + * + * Arg: obj [UNKN ] Undocumented argument [DataScore *] + * + * Return [UNKN ] Undocumented return value [DataScore *] + * + */ +DataScore * bp_sw_free_DataScore(DataScore * obj); +#define free_DataScore bp_sw_free_DataScore + + +/* Function: free_DataScoreStorage(obj) + * + * Descrip: Correctly handles destruction of DataScoreStorage, by + * freeing members in data storage + * + * + * Arg: obj [UNKN ] Undocumented argument [DataScoreStorage *] + * + * Return [UNKN ] Undocumented return value [DataScoreStorage *] + * + */ +DataScoreStorage * bp_sw_free_DataScoreStorage(DataScoreStorage * obj); +#define free_DataScoreStorage bp_sw_free_DataScoreStorage + + +/* Function: new_DataScoreStorage(void) + * + * Descrip: Makes a new DataScoreStorage with all the pointers connected correctly + * + * + * + * Return [UNKN ] Undocumented return value [DataScoreStorage *] + * + */ +DataScoreStorage * bp_sw_new_DataScoreStorage(void); +#define new_DataScoreStorage bp_sw_new_DataScoreStorage + + +/* Function: hard_link_DataEntry(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DataEntry *] + * + * Return [UNKN ] Undocumented return value [DataEntry *] + * + */ +DataEntry * bp_sw_hard_link_DataEntry(DataEntry * obj); +#define hard_link_DataEntry bp_sw_hard_link_DataEntry + + +/* Function: DataEntry_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DataEntry *] + * + */ +DataEntry * bp_sw_DataEntry_alloc(void); +#define DataEntry_alloc bp_sw_DataEntry_alloc + + +/* Function: free_DataEntry(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [DataEntry *] + * + * Return [UNKN ] Undocumented return value [DataEntry *] + * + */ +DataEntry * bp_sw_free_DataEntry(DataEntry * obj); +#define free_DataEntry bp_sw_free_DataEntry + + +/* Function: hard_link_DataScore(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DataScore *] + * + * Return [UNKN ] Undocumented return value [DataScore *] + * + */ +DataScore * bp_sw_hard_link_DataScore(DataScore * obj); +#define hard_link_DataScore bp_sw_hard_link_DataScore + + +/* Function: DataScore_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DataScore *] + * + */ +DataScore * bp_sw_DataScore_alloc(void); +#define DataScore_alloc bp_sw_DataScore_alloc + + +/* Function: hard_link_DataScoreStorage(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [DataScoreStorage *] + * + * Return [UNKN ] Undocumented return value [DataScoreStorage *] + * + */ +DataScoreStorage * bp_sw_hard_link_DataScoreStorage(DataScoreStorage * obj); +#define hard_link_DataScoreStorage bp_sw_hard_link_DataScoreStorage + + +/* Function: DataScoreStorage_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [DataScoreStorage *] + * + */ +DataScoreStorage * bp_sw_DataScoreStorage_alloc(void); +#define DataScoreStorage_alloc bp_sw_DataScoreStorage_alloc + + +/* Function: add_Hscore(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [Hscore *] + * Arg: add [OWNER] Object to add to the list [DataScore *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_Hscore(Hscore * obj,DataScore * add); +#define add_Hscore bp_sw_add_Hscore + + +/* Function: flush_Hscore(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [Hscore *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_flush_Hscore(Hscore * obj); +#define flush_Hscore bp_sw_flush_Hscore + + +/* Function: add_st_Hscore(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [Hscore *] + * Arg: add [OWNER] Object to add to the list [DataScoreStorage *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_st_Hscore(Hscore * obj,DataScoreStorage * add); +#define add_st_Hscore bp_sw_add_st_Hscore + + +/* Function: flush_st_Hscore(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [Hscore *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_flush_st_Hscore(Hscore * obj); +#define flush_st_Hscore bp_sw_flush_st_Hscore + + +/* Function: Hscore_alloc_std(void) + * + * Descrip: Equivalent to Hscore_alloc_len(HscoreLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [Hscore *] + * + */ +Hscore * bp_sw_Hscore_alloc_std(void); +#define Hscore_alloc_std bp_sw_Hscore_alloc_std + + +/* Function: Hscore_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [Hscore *] + * + */ +Hscore * bp_sw_Hscore_alloc_len(int len); +#define Hscore_alloc_len bp_sw_Hscore_alloc_len + + +/* Function: hard_link_Hscore(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [Hscore *] + * + * Return [UNKN ] Undocumented return value [Hscore *] + * + */ +Hscore * bp_sw_hard_link_Hscore(Hscore * obj); +#define hard_link_Hscore bp_sw_hard_link_Hscore + + +/* Function: Hscore_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [Hscore *] + * + */ +Hscore * bp_sw_Hscore_alloc(void); +#define Hscore_alloc bp_sw_Hscore_alloc + + +/* Function: free_Hscore(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [Hscore *] + * + * Return [UNKN ] Undocumented return value [Hscore *] + * + */ +Hscore * bp_sw_free_Hscore(Hscore * obj); +#define free_Hscore bp_sw_free_Hscore + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +boolean bp_sw_replace_target_DataScore(DataScore * obj,DataEntry * target); +#define replace_target_DataScore bp_sw_replace_target_DataScore +DataEntry * bp_sw_access_target_DataScore(DataScore * obj); +#define access_target_DataScore bp_sw_access_target_DataScore +boolean bp_sw_replace_score_DataScore(DataScore * obj,int score); +#define replace_score_DataScore bp_sw_replace_score_DataScore +boolean bp_sw_access_is_reversed_DataEntry(DataEntry * obj); +#define access_is_reversed_DataEntry bp_sw_access_is_reversed_DataEntry +int bp_sw_access_score_DataScore(DataScore * obj); +#define access_score_DataScore bp_sw_access_score_DataScore +char * bp_sw_access_filename_DataEntry(DataEntry * obj); +#define access_filename_DataEntry bp_sw_access_filename_DataEntry +boolean bp_sw_replace_evalue_DataScore(DataScore * obj,double evalue); +#define replace_evalue_DataScore bp_sw_replace_evalue_DataScore +DataEntry * bp_sw_access_query_DataScore(DataScore * obj); +#define access_query_DataScore bp_sw_access_query_DataScore +double bp_sw_access_evalue_DataScore(DataScore * obj); +#define access_evalue_DataScore bp_sw_access_evalue_DataScore +boolean bp_sw_replace_query_DataScore(DataScore * obj,DataEntry * query); +#define replace_query_DataScore bp_sw_replace_query_DataScore +boolean bp_sw_replace_is_reversed_DataEntry(DataEntry * obj,boolean is_reversed); +#define replace_is_reversed_DataEntry bp_sw_replace_is_reversed_DataEntry +boolean bp_sw_replace_name_DataEntry(DataEntry * obj,char * name); +#define replace_name_DataEntry bp_sw_replace_name_DataEntry +boolean bp_sw_replace_filename_DataEntry(DataEntry * obj,char * filename); +#define replace_filename_DataEntry bp_sw_replace_filename_DataEntry +char * bp_sw_access_name_DataEntry(DataEntry * obj); +#define access_name_DataEntry bp_sw_access_name_DataEntry +void bp_sw_copy_DataEntry(DataEntry * from,DataEntry * to); +#define copy_DataEntry bp_sw_copy_DataEntry +int bp_sw_compare_DataScore_by_score(DataScore * one,DataScore * two); +#define compare_DataScore_by_score bp_sw_compare_DataScore_by_score +DataScore * bp_sw_new_DataScore(void); +#define new_DataScore bp_sw_new_DataScore +DataScore * bp_sw_new_DataScore_from_storage(Hscore * hs); +#define new_DataScore_from_storage bp_sw_new_DataScore_from_storage +void bp_sw_swap_Hscore(DataScore ** list,int i,int j) ; +#define swap_Hscore bp_sw_swap_Hscore +void bp_sw_qsort_Hscore(DataScore ** list,int left,int right,int (*comp)(DataScore * ,DataScore * )); +#define qsort_Hscore bp_sw_qsort_Hscore +void bp_sw_sort_Hscore(Hscore * obj,int (*comp)(DataScore *, DataScore *)); +#define sort_Hscore bp_sw_sort_Hscore +boolean bp_sw_expand_Hscore(Hscore * obj,int len); +#define expand_Hscore bp_sw_expand_Hscore +void bp_sw_swap_st_Hscore(DataScoreStorage ** list,int i,int j) ; +#define swap_st_Hscore bp_sw_swap_st_Hscore +void bp_sw_qsort_st_Hscore(DataScoreStorage ** list,int left,int right,int (*comp)(DataScoreStorage * ,DataScoreStorage * )); +#define qsort_st_Hscore bp_sw_qsort_st_Hscore +void bp_sw_sort_st_Hscore(Hscore * obj,int (*comp)(DataScoreStorage *, DataScoreStorage *)); +#define sort_st_Hscore bp_sw_sort_st_Hscore +boolean bp_sw_expand_st_Hscore(Hscore * obj,int len); +#define expand_st_Hscore bp_sw_expand_st_Hscore + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/linesubs.c b/Bio/Ext/Align/libs/linesubs.c new file mode 100644 index 0000000..0787e7f --- /dev/null +++ b/Bio/Ext/Align/libs/linesubs.c @@ -0,0 +1,230 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "linesubs.h" + +/* this module is a little hacky... */ +/* It has buffers for loading in lines */ +/* and will edit them with the keys given */ + + + +#define MAXEDITLINE 512 +#define MAXREPLACEMENT 256 + +static char input[MAXEDITLINE]; +static char output[MAXEDITLINE]; + +static KeyandReplace kandr[MAXREPLACEMENT]; +static int size = 0; + +static int nest=0; + + +# line 33 "linesubs.dy" +void scan_and_replace(KeyandReplace * kr) +{ + char * runner; + char * run2; + char * o; + + if( (runner=strstr(input,kr->key)) == NULL) + return; /* nothing to do */ + + if( nest > 100 ) { + warn("scan and replaced one line more than 100 times; dropping out!"); + return; + } + + /*** copy upto runner in input ***/ + + for(run2=input,o=output; run2 < runner && *run2 != '\0';) + *(o++)=(*(run2++)); + + /*** copy replace into output ***/ + + for(run2=kr->replace; *run2 != '\0';) + *(o++)=(*(run2++)); + + /*** find end of key ***/ + + runner += strlen(kr->key); + + /*** copy rest of string into output ****/ + + + for(run2=runner; *run2 != '\0';) + *(o++)=(*(run2++)); + + /*** add terminal 0 ****/ + + *o = '\0'; + + /*** move back to input ***/ + + strcpy(input,output); + + /*** call again in case there are more to do ***/ + + nest++; + scan_and_replace(kr); + + + return; +} + +# line 84 "linesubs.dy" +char * scan_and_replace_line(char * line) +{ + register int i; + + + /*** load in line ***/ + + strcpy(input,line); + + + for(i=0;i MAXREPLACEMENT ) { + log_full_error(WARNING,0,"Scan and replace overflow for %s key\n",key); + return FALSE; + } + + kandr[size].key = stringalloc(key); + kandr[size].replace = stringalloc(replace); + + size++; + + return TRUE; +} + +# line 120 "linesubs.dy" +boolean pop_scan_and_replace_pair(void) +{ + if( size == 0 ) { + warn("Attempting to pop an empty scan and replace stack"); + return FALSE; + } + ckfree(kandr[size-1].key); + ckfree(kandr[size-1].replace); + + size--; + + return TRUE; +} + +# line 134 "linesubs.dy" +void flush_scan_and_replace(void) +{ + register int i; + + + for(i=0;i < size;i++) { + ckfree(kandr[i].key); + ckfree(kandr[i].replace); + } + size = 0; + + return; +} + +# line 148 "linesubs.dy" +void read_plain_scan_and_replace(char * filename) +{ + FILE * ifp; + + ifp = openfile(filename,"r"); + + if( ifp == NULL ) + { + log_full_error(WARNING,0,"Cannot open filename %s \n",filename); + return; + } + + read_scan_and_replace_file(ifp,"endofscanfile"); + + fclose(ifp); + + return; +} + +# line 167 "linesubs.dy" +void read_scan_and_replace_file(FILE * ifp,char * endstring) +{ + char buffer[MAXLINE]; + char ** base,**brk; + char * key; + char * runner; + + + while( fgets(buffer,MAXLINE,ifp) != NULL) + { + + /* fprintf(stderr,"Read line %s\n",buffer); */ + + if( endstring != NULL && endstring[0] != '\0' && strstartcmp(buffer,endstring) == 0) + break; + if( buffer[0] == '#' || buffer[0] == '!') + continue; + base = brk = breakstring_protect(buffer,spacestr,"@"); + if( base == NULL || *brk == NULL ) + { + log_full_error(WARNING,0,"Picked up problem in read scan and replace file"); + continue; + } + + key = *brk; + + brk++; + + if( *brk == NULL ) + { + log_full_error(WARNING,0,"Picked up problem in read scan and replace file key %s has no replace",key); + continue; + } + + if( **brk == '@' ) + (*brk)++; + + runner = (*brk) + strlen((*brk)); + runner--; + if( *runner == '@') + *runner = '\0'; + + + + push_scan_and_replace_pair(key,*brk); + + ckfree(base); + + } + + + return; +} + + + + + + + + +# line 225 "linesubs.c" + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/linesubs.h b/Bio/Ext/Align/libs/linesubs.h new file mode 100644 index 0000000..a17efac --- /dev/null +++ b/Bio/Ext/Align/libs/linesubs.h @@ -0,0 +1,50 @@ +#ifndef DYNAMITElinesubsHEADERFILE +#define DYNAMITElinesubsHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" + + + typedef struct { + char * key; + char * replace; + } KeyandReplace; + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ +void bp_sw_scan_and_replace(KeyandReplace * kr); +#define scan_and_replace bp_sw_scan_and_replace +char * bp_sw_scan_and_replace_line(char * line); +#define scan_and_replace_line bp_sw_scan_and_replace_line +boolean bp_sw_push_scan_and_replace_pair(char * key,char * replace); +#define push_scan_and_replace_pair bp_sw_push_scan_and_replace_pair +boolean bp_sw_pop_scan_and_replace_pair(void); +#define pop_scan_and_replace_pair bp_sw_pop_scan_and_replace_pair +void bp_sw_flush_scan_and_replace(void); +#define flush_scan_and_replace bp_sw_flush_scan_and_replace +void bp_sw_read_plain_scan_and_replace(char * filename); +#define read_plain_scan_and_replace bp_sw_read_plain_scan_and_replace +void bp_sw_read_scan_and_replace_file(FILE * ifp,char * endstring); +#define read_scan_and_replace_file bp_sw_read_scan_and_replace_file + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/makefile b/Bio/Ext/Align/libs/makefile new file mode 100644 index 0000000..2a1918f --- /dev/null +++ b/Bio/Ext/Align/libs/makefile @@ -0,0 +1,51 @@ + + + +OBJS = aln.o\ + alnconvert.o\ + alnrange.o\ + asciibtcanvas.o\ + basematrix.o\ + btcanvas.o\ + commandline.o\ + complexconsensi.o\ + complexevalset.o\ + complexsequence.o\ + compmat.o\ + codon.o\ + dna.o\ + dnamatrix.o\ + dpenvelope.o\ + dynlibcross.o\ + histogram.o\ + hscore.o\ + linesubs.o\ + packaln.o\ + probability.o\ + protein.o\ + proteindb.o\ + proteinsw.o\ + seqaligndisplay.o\ + sequence.o\ + sequencedb.o\ + sw_wrap.o\ + wiseerror.o\ + wisefile.o\ + wisememman.o\ + wiseoverlay.o\ + wiserandom.o\ + wisestring.o\ + wisetime.o + +libsw.a : $(OBJS) + ar ru libsw.a $(OBJS) + +wisefile.o : wisefile.c + $(CC) $(CFLAGS) -DNOERROR wisefile.c + +# +# For NetBSD or Sun (solaris) installs, add -fPIC to the CFLAGS lines +# + +CFLAGS = -c -O +CC = cc diff --git a/Bio/Ext/Align/libs/packaln.c b/Bio/Ext/Align/libs/packaln.c new file mode 100644 index 0000000..73727bf --- /dev/null +++ b/Bio/Ext/Align/libs/packaln.c @@ -0,0 +1,793 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "packaln.h" + +/* Function: show_simple_PackAlnUnit(pau,ofp) + * + * Descrip: shows packalnunit very simply ;) + * + * + * Arg: pau [UNKN ] Undocumented argument [PackAlnUnit *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 58 "packaln.dy" +void show_simple_PackAlnUnit(PackAlnUnit * pau,FILE * ofp) +{ + fprintf(ofp,"Position i:[%d] j:[%d] State:[%d] Score: %d\n",pau->i,pau->j,pau->state,pau->score); +} + +/* Function: show_text_PackAlnUnit(state_to_char,pau,ofp) + * + * Descrip: shows packalnunit with the text mapping + * + * + * Arg: state_to_char [UNKN ] Undocumented argument [NullString] + * Arg: pau [UNKN ] Undocumented argument [PackAlnUnit *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 67 "packaln.dy" +void show_text_PackAlnUnit(PackAlnUnit * pau,char * (*state_to_char)(int),FILE * ofp) +{ + fprintf(ofp,"Position i:[%4d] j:[%4d] State:[%2d] Score:[%3d] [%s]\n",pau->i,pau->j,pau->state,pau->score,(*state_to_char)(pau->state)); +} + +/* Function: show_bits_and_cumlative_PackAln(pal,ofp) + * + * Descrip: Shows packaln as: + * + * i,j,state,score,bits,cumlative-score,cumlative-bits + * + * cumlative score and cumlative bits are useful sometimes + * + * + * Arg: pal [UNKN ] Undocumented argument [PackAln *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 79 "packaln.dy" +void show_bits_and_cumlative_PackAln(PackAln * pal,FILE * ofp) +{ + int i; + int cs = 0; + double cb = 0.0; + + + fprintf(ofp,"Score %d\n",pal->score); + for(i=0;ilen;i++) { + auto PackAlnUnit * pau; + pau = pal->pau[i]; + + cs += pal->pau[i]->score; + cb += Score2Bits(pal->pau[i]->score); + fprintf(ofp,"i [%4d] j [%4d] state [%2d] score [%4d] bits [%2.2f] Score-CF [%6d] Bits-CF[%4.2f]\n",pau->i,pau->j,pau->state,pau->score,Score2Bits(pau->score),cs,cb); + } + +} + + +/* Function: show_simple_PackAln(pal,ofp) + * + * Descrip: shows packaln with a pretty verbose debugging + * format + * + * + * Arg: pal [UNKN ] Undocumented argument [PackAln *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 103 "packaln.dy" +void show_simple_PackAln(PackAln * pal,FILE * ofp) +{ + register int i; + + fprintf(ofp,"Score %d\n",pal->score); + for(i=0;ilen;i++) + show_simple_PackAlnUnit(pal->pau[i],ofp); +} + +/* Function: show_text_PackAln(state_to_char,pal,ofp) + * + * Descrip: shows packaln with a pretty verbose debugging + * format, but with a conversion function from state number to + * a string + * + * + * Arg: state_to_char [UNKN ] Undocumented argument [NullString] + * Arg: pal [UNKN ] Undocumented argument [PackAln *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 117 "packaln.dy" +void show_text_PackAln(PackAln * pal,char * (*state_to_char)(int),FILE * ofp) +{ + register int i; + + fprintf(ofp,"Score %d\n",pal->score); + for(i=0;ilen;i++) + show_text_PackAlnUnit(pal->pau[i],state_to_char,ofp); +} + +/* Function: invert_PackAln(pal) + * + * Descrip: inverts the packaln so that the last unit is the first + * etc. Because most alignments are read backwards this + * is useful + * + * + * Arg: pal [UNKN ] PackAln to be inverted [PackAln *] + * + */ +# line 133 "packaln.dy" +void invert_PackAln(PackAln * pal) +{ + PackAlnUnit ** temp; + register int i; + + /*** there are better ways to do this! ***/ + + temp = (PackAlnUnit **) ckcalloc(pal->len,sizeof(PackAlnUnit *)); + + for(i=0;ilen;i++) + temp[i] = pal->pau[pal->len-1-i]; + for(i=0;ilen;i++) + pal->pau[i] = temp[i]; + + ckfree(temp); +} + + + +# line 130 "packaln.c" +/* Function: hard_link_PackAlnUnit(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [PackAlnUnit *] + * + * Return [UNKN ] Undocumented return value [PackAlnUnit *] + * + */ +PackAlnUnit * hard_link_PackAlnUnit(PackAlnUnit * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a PackAlnUnit object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: PackAlnUnit_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [PackAlnUnit *] + * + */ +PackAlnUnit * PackAlnUnit_alloc(void) +{ + PackAlnUnit * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(PackAlnUnit *) ckalloc (sizeof(PackAlnUnit))) == NULL) { + warn("PackAlnUnit_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->i = 0; + out->j = 0; + out->state = 0; + out->score = 0; + + + return out; +} + + +/* Function: free_PackAlnUnit(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [PackAlnUnit *] + * + * Return [UNKN ] Undocumented return value [PackAlnUnit *] + * + */ +PackAlnUnit * free_PackAlnUnit(PackAlnUnit * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a PackAlnUnit obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + + + ckfree(obj); + return NULL; +} + + +/* Function: swap_PackAln(list,i,j) + * + * Descrip: swap function: an internal for qsort_PackAln + * swaps two positions in the array + * + * + * Arg: list [UNKN ] List of structures to swap in [PackAlnUnit **] + * Arg: i [UNKN ] swap position [int] + * Arg: j [UNKN ] swap position [int] + * + */ +/* swap function for qsort function */ +void swap_PackAln(PackAlnUnit ** list,int i,int j) +{ + PackAlnUnit * temp; + temp=list[i]; + list[i]=list[j]; + list[j]=temp; +} + + +/* Function: qsort_PackAln(list,left,right,comp) + * + * Descrip: qsort - lifted from K&R + * sorts the array using quicksort + * Probably much better to call sort_PackAln which sorts from start to end + * + * + * Arg: list [UNKN ] List of structures to swap in [PackAlnUnit **] + * Arg: left [UNKN ] left position [int] + * Arg: right [UNKN ] right position [int] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void qsort_PackAln(PackAlnUnit ** list,int left,int right,int (*comp)(PackAlnUnit * ,PackAlnUnit * )) +{ + int i,last; + if( left >= right ) + return; + + + swap_PackAln(list,left,(left+right)/2); + last = left; + for ( i=left+1; i <= right;i++) { + if( (*comp)(list[i],list[left]) < 0) + swap_PackAln (list,++last,i); + } + swap_PackAln (list,left,last); + qsort_PackAln(list,left,last-1,comp); + qsort_PackAln(list,last+1,right,comp); +} + + +/* Function: sort_PackAln(obj,comp) + * + * Descrip: sorts from start to end using comp + * sorts the array using quicksort by calling qsort_PackAln + * + * + * Arg: obj [UNKN ] Object containing list [PackAln *] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void sort_PackAln(PackAln * obj,int (*comp)(PackAlnUnit *, PackAlnUnit *)) +{ + qsort_PackAln(obj->pau,0,obj->len-1,comp); + return; +} + + +/* Function: expand_PackAln(obj,len) + * + * Descrip: Really an internal function for add_PackAln + * + * + * Arg: obj [UNKN ] Object which contains the list [PackAln *] + * Arg: len [UNKN ] Length to add one [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean expand_PackAln(PackAln * obj,int len) +{ + + + if( obj->maxlen > obj->len ) { + warn("expand_PackAln called with no need"); + return TRUE; + } + + + if( (obj->pau = (PackAlnUnit ** ) ckrealloc (obj->pau,sizeof(PackAlnUnit *)*len)) == NULL) { + warn("ckrealloc failed for expand_PackAln, returning FALSE"); + return FALSE; + } + obj->maxlen = len; + return TRUE; +} + + +/* Function: add_PackAln(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [PackAln *] + * Arg: add [OWNER] Object to add to the list [PackAlnUnit *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +/* will expand function if necessary */ +boolean add_PackAln(PackAln * obj,PackAlnUnit * add) +{ + if( obj->len >= obj->maxlen) { + if( expand_PackAln(obj,obj->len + PackAlnLISTLENGTH) == FALSE) + return FALSE; + } + + + obj->pau[obj->len++]=add; + return TRUE; +} + + +/* Function: flush_PackAln(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [PackAln *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int flush_PackAln(PackAln * obj) +{ + int i; + + + for(i=0;ilen;i++) { + if( obj->pau[i] != NULL) { + free_PackAlnUnit(obj->pau[i]); + obj->pau[i] = NULL; + } + } /* end of for i over list length */ + + + obj->len = 0; + return i; +} + + +/* Function: PackAln_alloc_std(void) + * + * Descrip: Equivalent to PackAln_alloc_len(PackAlnLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * PackAln_alloc_std(void) +{ + return PackAln_alloc_len(PackAlnLISTLENGTH); +} + + +/* Function: PackAln_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * PackAln_alloc_len(int len) +{ + PackAln * out; /* out is exported at the end of function */ + + + /* Call alloc function: return NULL if NULL */ + /* Warning message alread in alloc function */ + if((out = PackAln_alloc()) == NULL) + return NULL; + + + /* Calling ckcalloc for list elements */ + if((out->pau = (PackAlnUnit ** ) ckcalloc (len,sizeof(PackAlnUnit *))) == NULL) { + warn("Warning, ckcalloc failed in PackAln_alloc_len"); + return NULL; + } + out->len = 0; + out->maxlen = len; + + + return out; +} + + +/* Function: hard_link_PackAln(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [PackAln *] + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * hard_link_PackAln(PackAln * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a PackAln object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: PackAln_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * PackAln_alloc(void) +{ + PackAln * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(PackAln *) ckalloc (sizeof(PackAln))) == NULL) { + warn("PackAln_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->pau = NULL; + out->len = out->maxlen = 0; + out->score = 0; + + + return out; +} + + +/* Function: free_PackAln(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [PackAln *] + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * free_PackAln(PackAln * obj) +{ + int i; + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a PackAln obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->pau != NULL) { + for(i=0;ilen;i++) { + if( obj->pau[i] != NULL) + free_PackAlnUnit(obj->pau[i]); + } + ckfree(obj->pau); + } + + + ckfree(obj); + return NULL; +} + + +/* Function: access_pau_PackAln(obj,i) + * + * Descrip: Access members stored in the pau list + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the list [PackAln *] + * Arg: i [UNKN ] Position in the list [int] + * + * Return [SOFT ] Element of the list [PackAlnUnit *] + * + */ +PackAlnUnit * access_pau_PackAln(PackAln * obj,int i) +{ + if( obj == NULL) { + warn("In accessor function pau for object PackAln, got a NULL object"); + return NULL; + } + if( obj->len <= i ) { + warn("In accessor function pau for object PackAln, index %%d is greater than list length %%d",i,obj->len); + return NULL; + } + return obj->pau[i]; +} + + +/* Function: length_pau_PackAln(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the list [PackAln *] + * + * Return [UNKN ] length of the list [int] + * + */ +int length_pau_PackAln(PackAln * obj) +{ + if( obj == NULL) { + warn("In length function pau for object PackAln, got a NULL object"); + return -1; + } + return obj->len; +} + + +/* Function: replace_score_PackAln(obj,score) + * + * Descrip: Replace member variable score + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [PackAln *] + * Arg: score [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable score [boolean] + * + */ +boolean replace_score_PackAln(PackAln * obj,int score) +{ + if( obj == NULL) { + warn("In replacement function score for object PackAln, got a NULL object"); + return FALSE; + } + obj->score = score; + return TRUE; +} + + +/* Function: access_score_PackAln(obj) + * + * Descrip: Access member variable score + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [PackAln *] + * + * Return [SOFT ] member variable score [int] + * + */ +int access_score_PackAln(PackAln * obj) +{ + if( obj == NULL) { + warn("In accessor function score for object PackAln, got a NULL object"); + return 0; + } + return obj->score; +} + + +/* Function: replace_i_PackAlnUnit(obj,i) + * + * Descrip: Replace member variable i + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [PackAlnUnit *] + * Arg: i [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable i [boolean] + * + */ +boolean replace_i_PackAlnUnit(PackAlnUnit * obj,int i) +{ + if( obj == NULL) { + warn("In replacement function i for object PackAlnUnit, got a NULL object"); + return FALSE; + } + obj->i = i; + return TRUE; +} + + +/* Function: access_i_PackAlnUnit(obj) + * + * Descrip: Access member variable i + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [PackAlnUnit *] + * + * Return [SOFT ] member variable i [int] + * + */ +int access_i_PackAlnUnit(PackAlnUnit * obj) +{ + if( obj == NULL) { + warn("In accessor function i for object PackAlnUnit, got a NULL object"); + return 0; + } + return obj->i; +} + + +/* Function: replace_j_PackAlnUnit(obj,j) + * + * Descrip: Replace member variable j + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [PackAlnUnit *] + * Arg: j [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable j [boolean] + * + */ +boolean replace_j_PackAlnUnit(PackAlnUnit * obj,int j) +{ + if( obj == NULL) { + warn("In replacement function j for object PackAlnUnit, got a NULL object"); + return FALSE; + } + obj->j = j; + return TRUE; +} + + +/* Function: access_j_PackAlnUnit(obj) + * + * Descrip: Access member variable j + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [PackAlnUnit *] + * + * Return [SOFT ] member variable j [int] + * + */ +int access_j_PackAlnUnit(PackAlnUnit * obj) +{ + if( obj == NULL) { + warn("In accessor function j for object PackAlnUnit, got a NULL object"); + return 0; + } + return obj->j; +} + + +/* Function: replace_state_PackAlnUnit(obj,state) + * + * Descrip: Replace member variable state + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [PackAlnUnit *] + * Arg: state [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable state [boolean] + * + */ +boolean replace_state_PackAlnUnit(PackAlnUnit * obj,int state) +{ + if( obj == NULL) { + warn("In replacement function state for object PackAlnUnit, got a NULL object"); + return FALSE; + } + obj->state = state; + return TRUE; +} + + +/* Function: access_state_PackAlnUnit(obj) + * + * Descrip: Access member variable state + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [PackAlnUnit *] + * + * Return [SOFT ] member variable state [int] + * + */ +int access_state_PackAlnUnit(PackAlnUnit * obj) +{ + if( obj == NULL) { + warn("In accessor function state for object PackAlnUnit, got a NULL object"); + return 0; + } + return obj->state; +} + + +/* Function: replace_score_PackAlnUnit(obj,score) + * + * Descrip: Replace member variable score + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [PackAlnUnit *] + * Arg: score [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable score [boolean] + * + */ +boolean replace_score_PackAlnUnit(PackAlnUnit * obj,int score) +{ + if( obj == NULL) { + warn("In replacement function score for object PackAlnUnit, got a NULL object"); + return FALSE; + } + obj->score = score; + return TRUE; +} + + +/* Function: access_score_PackAlnUnit(obj) + * + * Descrip: Access member variable score + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [PackAlnUnit *] + * + * Return [SOFT ] member variable score [int] + * + */ +int access_score_PackAlnUnit(PackAlnUnit * obj) +{ + if( obj == NULL) { + warn("In accessor function score for object PackAlnUnit, got a NULL object"); + return 0; + } + return obj->score; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/packaln.h b/Bio/Ext/Align/libs/packaln.h new file mode 100644 index 0000000..e5403be --- /dev/null +++ b/Bio/Ext/Align/libs/packaln.h @@ -0,0 +1,328 @@ +#ifndef DYNAMITEpackalnHEADERFILE +#define DYNAMITEpackalnHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif + +#include "wisebase.h" +#include "probability.h" + + +#define PackAlnLISTLENGTH 64 + +/* Object PackAlnUnit + * + * Descrip: Internal object for /PackAln: + * A single position of an alignment + * as the (i,j,state) triple + * + * + */ +struct bp_sw_PackAlnUnit { + int dynamite_hard_link; + int i; /* position in query */ + int j; /* position in target */ + int state; /* state in FSM */ + int score; /* score of the transition that reached this state */ + } ; +/* PackAlnUnit defined */ +#ifndef DYNAMITE_DEFINED_PackAlnUnit +typedef struct bp_sw_PackAlnUnit bp_sw_PackAlnUnit; +#define PackAlnUnit bp_sw_PackAlnUnit +#define DYNAMITE_DEFINED_PackAlnUnit +#endif + + +/* Object PackAln + * + * Descrip: This is the lowest-level of representation + * of a DP alignment, being the list of + * (i,j,state) triples taken through the + * DP matrix. The score for the transition to + * this point is held as well. + * + * This object is very low level and often a + * much better choice for representation is + * in /AlnBlock objects + * + * + */ +struct bp_sw_PackAln { + int dynamite_hard_link; + PackAlnUnit ** pau; /* list of PackAlnUnits from start to end */ + int len;/* len for above pau */ + int maxlen; /* maxlen for above pau */ + int score; /* score over the entire alignment */ + } ; +/* PackAln defined */ +#ifndef DYNAMITE_DEFINED_PackAln +typedef struct bp_sw_PackAln bp_sw_PackAln; +#define PackAln bp_sw_PackAln +#define DYNAMITE_DEFINED_PackAln +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: show_bits_and_cumlative_PackAln(pal,ofp) + * + * Descrip: Shows packaln as: + * + * i,j,state,score,bits,cumlative-score,cumlative-bits + * + * cumlative score and cumlative bits are useful sometimes + * + * + * Arg: pal [UNKN ] Undocumented argument [PackAln *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_show_bits_and_cumlative_PackAln(PackAln * pal,FILE * ofp); +#define show_bits_and_cumlative_PackAln bp_sw_show_bits_and_cumlative_PackAln + + +/* Function: show_simple_PackAln(pal,ofp) + * + * Descrip: shows packaln with a pretty verbose debugging + * format + * + * + * Arg: pal [UNKN ] Undocumented argument [PackAln *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_show_simple_PackAln(PackAln * pal,FILE * ofp); +#define show_simple_PackAln bp_sw_show_simple_PackAln + + +/* Function: show_text_PackAln(state_to_char,pal,ofp) + * + * Descrip: shows packaln with a pretty verbose debugging + * format, but with a conversion function from state number to + * a string + * + * + * Arg: state_to_char [UNKN ] Undocumented argument [NullString] + * Arg: pal [UNKN ] Undocumented argument [PackAln *] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_show_text_PackAln(PackAln * pal,char * (*state_to_char)(int),FILE * ofp); +#define show_text_PackAln bp_sw_show_text_PackAln + + +/* Function: invert_PackAln(pal) + * + * Descrip: inverts the packaln so that the last unit is the first + * etc. Because most alignments are read backwards this + * is useful + * + * + * Arg: pal [UNKN ] PackAln to be inverted [PackAln *] + * + */ +void bp_sw_invert_PackAln(PackAln * pal) ; +#define invert_PackAln bp_sw_invert_PackAln + + +/* Function: hard_link_PackAlnUnit(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [PackAlnUnit *] + * + * Return [UNKN ] Undocumented return value [PackAlnUnit *] + * + */ +PackAlnUnit * bp_sw_hard_link_PackAlnUnit(PackAlnUnit * obj); +#define hard_link_PackAlnUnit bp_sw_hard_link_PackAlnUnit + + +/* Function: PackAlnUnit_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [PackAlnUnit *] + * + */ +PackAlnUnit * bp_sw_PackAlnUnit_alloc(void); +#define PackAlnUnit_alloc bp_sw_PackAlnUnit_alloc + + +/* Function: free_PackAlnUnit(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [PackAlnUnit *] + * + * Return [UNKN ] Undocumented return value [PackAlnUnit *] + * + */ +PackAlnUnit * bp_sw_free_PackAlnUnit(PackAlnUnit * obj); +#define free_PackAlnUnit bp_sw_free_PackAlnUnit + + +/* Function: add_PackAln(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [PackAln *] + * Arg: add [OWNER] Object to add to the list [PackAlnUnit *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_PackAln(PackAln * obj,PackAlnUnit * add); +#define add_PackAln bp_sw_add_PackAln + + +/* Function: flush_PackAln(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [PackAln *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_flush_PackAln(PackAln * obj); +#define flush_PackAln bp_sw_flush_PackAln + + +/* Function: PackAln_alloc_std(void) + * + * Descrip: Equivalent to PackAln_alloc_len(PackAlnLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * bp_sw_PackAln_alloc_std(void); +#define PackAln_alloc_std bp_sw_PackAln_alloc_std + + +/* Function: PackAln_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * bp_sw_PackAln_alloc_len(int len); +#define PackAln_alloc_len bp_sw_PackAln_alloc_len + + +/* Function: hard_link_PackAln(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [PackAln *] + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * bp_sw_hard_link_PackAln(PackAln * obj); +#define hard_link_PackAln bp_sw_hard_link_PackAln + + +/* Function: PackAln_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * bp_sw_PackAln_alloc(void); +#define PackAln_alloc bp_sw_PackAln_alloc + + +/* Function: free_PackAln(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [PackAln *] + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * bp_sw_free_PackAln(PackAln * obj); +#define free_PackAln bp_sw_free_PackAln + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +PackAlnUnit * bp_sw_access_pau_PackAln(PackAln * obj,int i); +#define access_pau_PackAln bp_sw_access_pau_PackAln +int bp_sw_access_score_PackAln(PackAln * obj); +#define access_score_PackAln bp_sw_access_score_PackAln +void bp_sw_show_simple_PackAlnUnit(PackAlnUnit * pau,FILE * ofp); +#define show_simple_PackAlnUnit bp_sw_show_simple_PackAlnUnit +boolean bp_sw_replace_i_PackAlnUnit(PackAlnUnit * obj,int i); +#define replace_i_PackAlnUnit bp_sw_replace_i_PackAlnUnit +int bp_sw_access_i_PackAlnUnit(PackAlnUnit * obj); +#define access_i_PackAlnUnit bp_sw_access_i_PackAlnUnit +boolean bp_sw_replace_score_PackAlnUnit(PackAlnUnit * obj,int score); +#define replace_score_PackAlnUnit bp_sw_replace_score_PackAlnUnit +boolean bp_sw_replace_j_PackAlnUnit(PackAlnUnit * obj,int j); +#define replace_j_PackAlnUnit bp_sw_replace_j_PackAlnUnit +boolean bp_sw_replace_score_PackAln(PackAln * obj,int score); +#define replace_score_PackAln bp_sw_replace_score_PackAln +int bp_sw_access_j_PackAlnUnit(PackAlnUnit * obj); +#define access_j_PackAlnUnit bp_sw_access_j_PackAlnUnit +int bp_sw_length_pau_PackAln(PackAln * obj); +#define length_pau_PackAln bp_sw_length_pau_PackAln +boolean bp_sw_replace_state_PackAlnUnit(PackAlnUnit * obj,int state); +#define replace_state_PackAlnUnit bp_sw_replace_state_PackAlnUnit +int bp_sw_access_score_PackAlnUnit(PackAlnUnit * obj); +#define access_score_PackAlnUnit bp_sw_access_score_PackAlnUnit +int bp_sw_access_state_PackAlnUnit(PackAlnUnit * obj); +#define access_state_PackAlnUnit bp_sw_access_state_PackAlnUnit +void bp_sw_show_text_PackAlnUnit(PackAlnUnit * pau,char * (*state_to_char)(int),FILE * ofp); +#define show_text_PackAlnUnit bp_sw_show_text_PackAlnUnit +void bp_sw_swap_PackAln(PackAlnUnit ** list,int i,int j) ; +#define swap_PackAln bp_sw_swap_PackAln +void bp_sw_qsort_PackAln(PackAlnUnit ** list,int left,int right,int (*comp)(PackAlnUnit * ,PackAlnUnit * )); +#define qsort_PackAln bp_sw_qsort_PackAln +void bp_sw_sort_PackAln(PackAln * obj,int (*comp)(PackAlnUnit *, PackAlnUnit *)); +#define sort_PackAln bp_sw_sort_PackAln +boolean bp_sw_expand_PackAln(PackAln * obj,int len); +#define expand_PackAln bp_sw_expand_PackAln + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/probability.c b/Bio/Ext/Align/libs/probability.c new file mode 100644 index 0000000..3499f9d --- /dev/null +++ b/Bio/Ext/Align/libs/probability.c @@ -0,0 +1,584 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "probability.h" + + +/* Function: Probability_from_average_state_occupancy(length) + * + * Descrip: for single state (exponetial decays) takes an average length + * and converts that to a probability that will produce that + * length (on average) for the state. NB... this *assumes* that + * you want a single state exp decay. + * + * + * Arg: length [UNKN ] average length of state [double] + * + * Return [UNKN ] Undocumented return value [Probability] + * + */ +# line 44 "probability.dy" +Probability Probability_from_average_state_occupancy(double length) +{ + return 1 - (1.0 / length); +} + +/* Function: state_occupancy_from_Probability(p) + * + * Descrip: If you have a single state then this will tak + * the probability for the state->state transition and + * give you back the average length in the state + * + * + * Arg: p [UNKN ] probability of staying in the state [double] + * + * Return [UNKN ] Undocumented return value [double] + * + */ +# line 56 "probability.dy" +double state_occupancy_from_Probability(double p) +{ + return 1 / (1-p); +} + +/* Function: show_Score_array(s,len,ofp) + * + * Descrip: shows a score array as score, score ,score ...' + * + * + * Arg: s [UNKN ] Score array [Score *] + * Arg: len [UNKN ] length of array [int] + * Arg: ofp [UNKN ] output filestream [FILE *] + * + */ +# line 68 "probability.dy" +void show_Score_array(Score * s,int len,FILE * ofp) +{ + register int i; + + fprintf(ofp,"\"%d",s[0]); + for(i=1;i= len ) { + return FALSE; + } + if( is_double_string(runner,&p[no]) == FALSE ) { + return FALSE; + } + } + return TRUE; +} + + +/* Function: show_Probability_array(p,len,ofp) + * + * Descrip: shows a proability array in %f notation. + * + * + * + * Arg: p [UNKN ] probability array [Probability *] + * Arg: len [UNKN ] length of proability array [int] + * Arg: ofp [UNKN ] output filestream [FILE *] + * + */ +# line 131 "probability.dy" +void show_Probability_array(Probability * p,int len,FILE * ofp) +{ + register int i; + + fprintf(ofp,"\"%f",p[0]); + for(i=1;istate transition and + * give you back the average length in the state + * + * + * Arg: p [UNKN ] probability of staying in the state [double] + * + * Return [UNKN ] Undocumented return value [double] + * + */ +double bp_sw_state_occupancy_from_Probability(double p); +#define state_occupancy_from_Probability bp_sw_state_occupancy_from_Probability + + +/* Function: show_Score_array(s,len,ofp) + * + * Descrip: shows a score array as score, score ,score ...' + * + * + * Arg: s [UNKN ] Score array [Score *] + * Arg: len [UNKN ] length of array [int] + * Arg: ofp [UNKN ] output filestream [FILE *] + * + */ +void bp_sw_show_Score_array(Score * s,int len,FILE * ofp); +#define show_Score_array bp_sw_show_Score_array + + +/* Function: show_Probability_array_exp(p,len,ofp) + * + * Descrip: shows a proability array in scientific notation. + * + * + * + * Arg: p [UNKN ] probability array [Probability *] + * Arg: len [UNKN ] length of proability array [int] + * Arg: ofp [UNKN ] output filestream [FILE *] + * + */ +void bp_sw_show_Probability_array_exp(Probability * p,int len,FILE * ofp); +#define show_Probability_array_exp bp_sw_show_Probability_array_exp + + +/* Function: read_Probability_array(p,len,start_of_array) + * + * Descrip: reads in a probability array of comma separated numbers. + * It calls /is_double_string to test whether the numbers are + * probabilities. It tries ito read in len numbers: if it runs out of + * commad separated guys it returns FALSE + * + * + * Arg: p [UNKN ] Undocumented argument [Probability *] + * Arg: len [UNKN ] Undocumented argument [int] + * Arg: start_of_array [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_read_Probability_array(Probability * p,int len,char * start_of_array); +#define read_Probability_array bp_sw_read_Probability_array + + +/* Function: show_Probability_array(p,len,ofp) + * + * Descrip: shows a proability array in %f notation. + * + * + * + * Arg: p [UNKN ] probability array [Probability *] + * Arg: len [UNKN ] length of proability array [int] + * Arg: ofp [UNKN ] output filestream [FILE *] + * + */ +void bp_sw_show_Probability_array(Probability * p,int len,FILE * ofp); +#define show_Probability_array bp_sw_show_Probability_array + + +/* Function: sum_Probability_array(p,len) + * + * Descrip: adds up the probability array given + * + * + * Arg: p [UNKN ] probability array [Probability *] + * Arg: len [UNKN ] length of array [int] + * + * Return [UNKN ] Undocumented return value [Probability] + * + */ +Probability bp_sw_sum_Probability_array(Probability * p,int len); +#define sum_Probability_array bp_sw_sum_Probability_array + + +/* Function: set_Probability_array(set,p,len) + * + * Descrip: Sets the probability array to p + * + * + * Arg: set [UNKN ] probability array to set [Probability *] + * Arg: p [UNKN ] probability to set it to [Probability] + * Arg: len [UNKN ] length of probability array [int] + * + * Return [UNKN ] Undocumented return value [Probability *] + * + */ +Probability * bp_sw_set_Probability_array(Probability * set,Probability p,int len); +#define set_Probability_array bp_sw_set_Probability_array + + +/* Function: Probability2Score_move(from,to,len) + * + * Descrip: moves the probability array from to the (same length) + * score array to going through Probability2Score function + * + * + * Arg: from [UNKN ] probability array to get the numbers [Probability *] + * Arg: to [UNKN ] Score array to put the numbers [Score *] + * Arg: len [UNKN ] length of arrays [int] + * + * Return [UNKN ] Undocumented return value [Score *] + * + */ +Score * bp_sw_Probability2Score_move(Probability * from,Score * to,int len); +#define Probability2Score_move bp_sw_Probability2Score_move + + +/* Function: Probability_move(from,to,len) + * + * Descrip: moves from to to + * + * + * Arg: from [UNKN ] probability array with the numbers [const Probability *] + * Arg: to [UNKN ] probability array to be written into [Probability *] + * Arg: len [UNKN ] length [int] + * + * Return [UNKN ] Undocumented return value [Probability *] + * + */ +Probability * bp_sw_Probability_move(const Probability * from,Probability * to,int len); +#define Probability_move bp_sw_Probability_move + + +/* Function: Score_move(from,to,len) + * + * Descrip: moves from to to + * + * + * Arg: from [UNKN ] Score array with the numbers [const Score *] + * Arg: to [UNKN ] Score array to be written into [Score *] + * Arg: len [UNKN ] length [int] + * + * Return [UNKN ] Undocumented return value [Score *] + * + */ +Score * bp_sw_Score_move(const Score * from,Score * to,int len); +#define Score_move bp_sw_Score_move + + +/* Function: renormalise_Probability_array(array,len) + * + * Descrip: Reasonably stupid function. Sums up probability array + * and then simply uses a linear renormalisation to get to the + * array adding to 1.0 + * + * returns the difference between the original sum and 1,0 + * + * + * Arg: array [UNKN ] array to renormalise [Probability *] + * Arg: len [UNKN ] length of array [int] + * + * Return [UNKN ] Undocumented return value [double] + * + */ +double bp_sw_renormalise_Probability_array(Probability * array,int len); +#define renormalise_Probability_array bp_sw_renormalise_Probability_array + + +/* Function: Probability_array_divide(to,top,bottem,len) + * + * Descrip: divides one prob array by another pairwise + * + * + * Arg: to [UNKN ] probability array to be written into [Probability *] + * Arg: top [UNKN ] probability array to be divided [const Probability *] + * Arg: bottem [UNKN ] probability array which divides [const Probability *] + * Arg: len [UNKN ] length [int] + * + * Return [UNKN ] Undocumented return value [Probability *] + * + */ +Probability * bp_sw_Probability_array_divide(Probability * to,const Probability * top,const Probability * bottem,int len); +#define Probability_array_divide bp_sw_Probability_array_divide + + +/* Function: Probability_array_multiply(to,top,bottem,len) + * + * Descrip: multiplies one prob array by another pairwise + * + * + * Arg: to [UNKN ] probability array to be written into [Probability *] + * Arg: top [UNKN ] probability array to be mulitpled [const Probability *] + * Arg: bottem [UNKN ] probability array to be mulitpled [const Probability *] + * Arg: len [UNKN ] length [int] + * + * Return [UNKN ] Undocumented return value [Probability *] + * + */ +Probability * bp_sw_Probability_array_multiply(Probability * to,const Probability * top,const Probability * bottem,int len); +#define Probability_array_multiply bp_sw_Probability_array_multiply + + +/* Function: Probability_array_add(to,top,bottem,len) + * + * Descrip: sums one prob array with another pairwise + * + * + * Arg: to [UNKN ] probability array to be written into [Probability *] + * Arg: top [UNKN ] probability array to be summed [const Probability *] + * Arg: bottem [UNKN ] probability array to be summed [const Probability *] + * Arg: len [UNKN ] length [int] + * + * Return [UNKN ] Undocumented return value [Probability *] + * + */ +Probability * bp_sw_Probability_array_add(Probability * to,const Probability * top,const Probability * bottem,int len); +#define Probability_array_add bp_sw_Probability_array_add + + +/* Function: Probability_array_subtract(to,top,bottem,len) + * + * Descrip: subtracts one prob array by another pairwise + * + * + * Arg: to [UNKN ] probability array to be written into [Probability *] + * Arg: top [UNKN ] probability array to be subtracted [const Probability *] + * Arg: bottem [UNKN ] probability array that subtracts [const Probability *] + * Arg: len [UNKN ] length [int] + * + * Return [UNKN ] Undocumented return value [Probability *] + * + */ +Probability * bp_sw_Probability_array_subtract(Probability * to,const Probability * top,const Probability * bottem,int len); +#define Probability_array_subtract bp_sw_Probability_array_subtract + + +/* Function: Score_array_add(to,top,bottem,len) + * + * Descrip: sums one score array with another pairwise + * + * + * Arg: to [UNKN ] score array to be written into [Score *] + * Arg: top [UNKN ] score array to be summed [Score *] + * Arg: bottem [UNKN ] score array to be summed [Score *] + * Arg: len [UNKN ] length [int] + * + * Return [UNKN ] Undocumented return value [Score *] + * + */ +Score * bp_sw_Score_array_add(Score * to,Score * top,Score * bottem,int len); +#define Score_array_add bp_sw_Score_array_add + + +/* Function: Score_array_subtract(to,top,bottem,len) + * + * Descrip: subtracts one score array by another pairwise + * + * + * Arg: to [UNKN ] score array to be written into [Score *] + * Arg: top [UNKN ] score array to be subtracted [const Score *] + * Arg: bottem [UNKN ] score array that subtracts [const Score *] + * Arg: len [UNKN ] length [int] + * + * Return [UNKN ] Undocumented return value [Score *] + * + */ +Score * bp_sw_Score_array_subtract(Score * to,const Score * top,const Score * bottem,int len); +#define Score_array_subtract bp_sw_Score_array_subtract + + +/* Function: Score_Probability_sum(one,two) + * + * Descrip: Badly implemented sum in probability + * space + * + * + * Arg: one [UNKN ] Undocumented argument [Score] + * Arg: two [UNKN ] Undocumented argument [Score] + * + * Return [UNKN ] Undocumented return value [Score] + * + */ +Score bp_sw_Score_Probability_sum(Score one,Score two); +#define Score_Probability_sum bp_sw_Score_Probability_sum + + +/* Function: Probability2Score(p) + * + * Descrip: maps probabilities to scores. Deals + * sensibly with 0's. + * + * + * Arg: p [UNKN ] Undocumented argument [Probability] + * + * Return [UNKN ] Undocumented return value [Score] + * + */ +Score bp_sw_Probability2Score(Probability p); +#define Probability2Score bp_sw_Probability2Score + + +/* Function: halfbit2Probability(half_bit) + * + * Descrip: maps halfbits (log2(prob*2) to + * probabilities + * + * + * Arg: half_bit [UNKN ] Undocumented argument [double] + * + * Return [UNKN ] Undocumented return value [Probability] + * + */ +Probability bp_sw_halfbit2Probability(double half_bit); +#define halfbit2Probability bp_sw_halfbit2Probability + + +/* Function: Bits2Probability(bits) + * + * Descrip: maps halfbits (log2(prob*2) to + * probabilities + * + * + * Arg: bits [UNKN ] Undocumented argument [double] + * + * Return [UNKN ] Undocumented return value [Probability] + * + */ +Probability bp_sw_Bits2Probability(double bits); +#define Bits2Probability bp_sw_Bits2Probability + + +/* Function: Probability2halfbit(p) + * + * Descrip: maps probabilities to halfbits. + * Deals with 0's sensibly + * + * + * Arg: p [UNKN ] Undocumented argument [Probability] + * + * Return [UNKN ] Undocumented return value [double] + * + */ +double bp_sw_Probability2halfbit(Probability p); +#define Probability2halfbit bp_sw_Probability2halfbit + + +/* Function: Score2Probability(s) + * + * Descrip: maps scores to probabilities + * + * + * Arg: s [UNKN ] Undocumented argument [Score] + * + * Return [UNKN ] Undocumented return value [Probability] + * + */ +Probability bp_sw_Score2Probability(Score s); +#define Score2Probability bp_sw_Score2Probability + + +/* Function: Score2Bits(s) + * + * Descrip: maps scores to bits + * + * + * Arg: s [UNKN ] Undocumented argument [Score] + * + * Return [UNKN ] Undocumented return value [Bits] + * + */ +Bits bp_sw_Score2Bits(Score s); +#define Score2Bits bp_sw_Score2Bits + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/protein.c b/Bio/Ext/Align/libs/protein.c new file mode 100644 index 0000000..36f587e --- /dev/null +++ b/Bio/Ext/Align/libs/protein.c @@ -0,0 +1,336 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "protein.h" + + + +/* Function: truncate_Protein(pro,start,stop) + * + * Descrip: Truncates a protein sequence. Basically uses + * the /trunc_Sequence function (of course!) + * + * It does not alter pro, rather it returns a new + * sequence with that truncation + * + * + * Arg: pro [READ ] Protein that is truncated [Protein *] + * Arg: start [UNKN ] Undocumented argument [int] + * Arg: stop [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +# line 39 "protein.dy" +Protein * truncate_Protein(Protein * pro,int start,int stop) +{ + return Protein_from_Sequence(trunc_Sequence(pro->baseseq,start,stop)); +} + +/* Function: read_fasta_file_Protein (filename) + * + * Descrip: Reads a fasta file assumming that it is protein. + * Will complain if it is not, and return NULL. + * + * + * Arg: filename [UNKN ] filename to be opened and read [char *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +# line 50 "protein.dy" +Protein * read_fasta_file_Protein (char * filename) +{ + Sequence * seq; + + seq = read_fasta_file_Sequence(filename); + if( seq == NULL ) { + return NULL; + } + + return Protein_from_Sequence(seq); +} + + +/* Function: read_fasta_Protein (ifp) + * + * Descrip: Reads a fasta file assumming that it is protein. + * Will complain if it is not, and return NULL. + * + * + * Arg: ifp [UNKN ] file point to be read from [FILE *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +# line 69 "protein.dy" +Protein * read_fasta_Protein (FILE * ifp) +{ + Sequence * seq; + + seq = read_fasta_Sequence(ifp); + if( seq == NULL ) { + return NULL; + } + + return Protein_from_Sequence(seq); +} + +/* Function: read_efetch_Protein(estr) + * + * Descrip: Reads a efetch specified query + * Uses, of course /read_efetch_Sequence + * + * + * Arg: estr [READ ] efetch string which is read [char *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +# line 87 "protein.dy" +Protein * read_efetch_Protein(char * estr) +{ + return Protein_from_Sequence(read_efetch_Sequence(estr)); +} + +/* Function: read_SRS_Protein(srsquery) + * + * Descrip: Reads a SRS sequence using srs4 syntax. + * Uses, of course, /read_SRS_Sequence + * + * + * + * Arg: srsquery [READ ] string query representing SRS name [char *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +# line 99 "protein.dy" +Protein * read_SRS_Protein(char * srsquery) +{ + return Protein_from_Sequence(read_SRS_Sequence(srsquery)); +} + + +/* Function: Protein_name (pr) + * + * Descrip: Returns the name of the protein + * + * + * Arg: pr [UNKN ] Undocumented argument [Protein *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 109 "protein.dy" +char * Protein_name (Protein * pr) +{ + return pr->baseseq->name; +} + +/* Function: Protein_length (pr) + * + * Descrip: Returns the length of the protein + * + * + * Arg: pr [UNKN ] Undocumented argument [Protein *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 118 "protein.dy" +int Protein_length (Protein * pr) +{ + return pr->baseseq->len; +} + +/* Function: Protein_seqchar(pr,pos) + * + * Descrip: Returns sequence character at this position. + * + * + * Arg: pr [UNKN ] Protein [Protein *] + * Arg: pos [UNKN ] position in protein to get char [int] + * + * Return [UNKN ] Undocumented return value [char] + * + */ +# line 129 "protein.dy" +char Protein_seqchar(Protein * pr,int pos) +{ + return pr->baseseq->seq[pos]; +} + + +/* Function: Protein_from_Sequence(seq) + * + * Descrip: makes a new protein from a Sequence. It + * owns the Sequence memory, ie will attempt a /free_Sequence + * on the structure when /free_Protein is called + * + * If you want to give this protein this Sequence and + * forget about it, then just hand it this sequence and set + * seq to NULL (no need to free it). If you intend to use + * the sequecne object elsewhere outside of the Protein datastructure + * then use Protein_from_Sequence(/hard_link_Sequence(seq)) + * + * + * + * Arg: seq [OWNER] Sequence to make protein from [Sequence *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +# line 149 "protein.dy" +Protein * Protein_from_Sequence(Sequence * seq) +{ + Protein * out; + + + if( is_protein_Sequence(seq) == FALSE ) { + warn("Trying to make a protein sequence from a non protein base sequence [%s].",seq->name); + return NULL; + } + + out = Protein_alloc(); + + out->baseseq = seq; + + return out; +} + + + + +# line 186 "protein.c" +/* Function: hard_link_Protein(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [Protein *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +Protein * hard_link_Protein(Protein * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a Protein object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: Protein_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +Protein * Protein_alloc(void) +{ + Protein * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(Protein *) ckalloc (sizeof(Protein))) == NULL) { + warn("Protein_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->baseseq = NULL; + + + return out; +} + + +/* Function: free_Protein(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [Protein *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +Protein * free_Protein(Protein * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a Protein obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->baseseq != NULL) + free_Sequence(obj->baseseq); + + + ckfree(obj); + return NULL; +} + + +/* Function: replace_baseseq_Protein(obj,baseseq) + * + * Descrip: Replace member variable baseseq + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Protein *] + * Arg: baseseq [OWNER] New value of the variable [Sequence *] + * + * Return [SOFT ] member variable baseseq [boolean] + * + */ +boolean replace_baseseq_Protein(Protein * obj,Sequence * baseseq) +{ + if( obj == NULL) { + warn("In replacement function baseseq for object Protein, got a NULL object"); + return FALSE; + } + obj->baseseq = baseseq; + return TRUE; +} + + +/* Function: access_baseseq_Protein(obj) + * + * Descrip: Access member variable baseseq + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Protein *] + * + * Return [SOFT ] member variable baseseq [Sequence *] + * + */ +Sequence * access_baseseq_Protein(Protein * obj) +{ + if( obj == NULL) { + warn("In accessor function baseseq for object Protein, got a NULL object"); + return NULL; + } + return obj->baseseq; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/protein.h b/Bio/Ext/Align/libs/protein.h new file mode 100644 index 0000000..2959094 --- /dev/null +++ b/Bio/Ext/Align/libs/protein.h @@ -0,0 +1,238 @@ +#ifndef DYNAMITEproteinHEADERFILE +#define DYNAMITEproteinHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "sequence.h" + + + +struct bp_sw_Protein { + int dynamite_hard_link; + Sequence * baseseq; + } ; +/* Protein defined */ +#ifndef DYNAMITE_DEFINED_Protein +typedef struct bp_sw_Protein bp_sw_Protein; +#define Protein bp_sw_Protein +#define DYNAMITE_DEFINED_Protein +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: truncate_Protein(pro,start,stop) + * + * Descrip: Truncates a protein sequence. Basically uses + * the /trunc_Sequence function (of course!) + * + * It does not alter pro, rather it returns a new + * sequence with that truncation + * + * + * Arg: pro [READ ] Protein that is truncated [Protein *] + * Arg: start [UNKN ] Undocumented argument [int] + * Arg: stop [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +Protein * bp_sw_truncate_Protein(Protein * pro,int start,int stop); +#define truncate_Protein bp_sw_truncate_Protein + + +/* Function: read_fasta_file_Protein (filename) + * + * Descrip: Reads a fasta file assumming that it is protein. + * Will complain if it is not, and return NULL. + * + * + * Arg: filename [UNKN ] filename to be opened and read [char *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +Protein * bp_sw_read_fasta_file_Protein (char * filename); +#define read_fasta_file_Protein bp_sw_read_fasta_file_Protein + + +/* Function: read_fasta_Protein (ifp) + * + * Descrip: Reads a fasta file assumming that it is protein. + * Will complain if it is not, and return NULL. + * + * + * Arg: ifp [UNKN ] file point to be read from [FILE *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +Protein * bp_sw_read_fasta_Protein (FILE * ifp); +#define read_fasta_Protein bp_sw_read_fasta_Protein + + +/* Function: read_efetch_Protein(estr) + * + * Descrip: Reads a efetch specified query + * Uses, of course /read_efetch_Sequence + * + * + * Arg: estr [READ ] efetch string which is read [char *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +Protein * bp_sw_read_efetch_Protein(char * estr); +#define read_efetch_Protein bp_sw_read_efetch_Protein + + +/* Function: read_SRS_Protein(srsquery) + * + * Descrip: Reads a SRS sequence using srs4 syntax. + * Uses, of course, /read_SRS_Sequence + * + * + * + * Arg: srsquery [READ ] string query representing SRS name [char *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +Protein * bp_sw_read_SRS_Protein(char * srsquery); +#define read_SRS_Protein bp_sw_read_SRS_Protein + + +/* Function: Protein_name (pr) + * + * Descrip: Returns the name of the protein + * + * + * Arg: pr [UNKN ] Undocumented argument [Protein *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_Protein_name (Protein * pr); +#define Protein_name bp_sw_Protein_name + + +/* Function: Protein_length (pr) + * + * Descrip: Returns the length of the protein + * + * + * Arg: pr [UNKN ] Undocumented argument [Protein *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_Protein_length (Protein * pr); +#define Protein_length bp_sw_Protein_length + + +/* Function: Protein_seqchar(pr,pos) + * + * Descrip: Returns sequence character at this position. + * + * + * Arg: pr [UNKN ] Protein [Protein *] + * Arg: pos [UNKN ] position in protein to get char [int] + * + * Return [UNKN ] Undocumented return value [char] + * + */ +char bp_sw_Protein_seqchar(Protein * pr,int pos); +#define Protein_seqchar bp_sw_Protein_seqchar + + +/* Function: Protein_from_Sequence(seq) + * + * Descrip: makes a new protein from a Sequence. It + * owns the Sequence memory, ie will attempt a /free_Sequence + * on the structure when /free_Protein is called + * + * If you want to give this protein this Sequence and + * forget about it, then just hand it this sequence and set + * seq to NULL (no need to free it). If you intend to use + * the sequecne object elsewhere outside of the Protein datastructure + * then use Protein_from_Sequence(/hard_link_Sequence(seq)) + * + * + * + * Arg: seq [OWNER] Sequence to make protein from [Sequence *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +Protein * bp_sw_Protein_from_Sequence(Sequence * seq); +#define Protein_from_Sequence bp_sw_Protein_from_Sequence + + +/* Function: hard_link_Protein(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [Protein *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +Protein * bp_sw_hard_link_Protein(Protein * obj); +#define hard_link_Protein bp_sw_hard_link_Protein + + +/* Function: Protein_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +Protein * bp_sw_Protein_alloc(void); +#define Protein_alloc bp_sw_Protein_alloc + + +/* Function: free_Protein(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [Protein *] + * + * Return [UNKN ] Undocumented return value [Protein *] + * + */ +Protein * bp_sw_free_Protein(Protein * obj); +#define free_Protein bp_sw_free_Protein + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +boolean bp_sw_replace_baseseq_Protein(Protein * obj,Sequence * baseseq); +#define replace_baseseq_Protein bp_sw_replace_baseseq_Protein +Sequence * bp_sw_access_baseseq_Protein(Protein * obj); +#define access_baseseq_Protein bp_sw_access_baseseq_Protein + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/proteindb.c b/Bio/Ext/Align/libs/proteindb.c new file mode 100644 index 0000000..c849060 --- /dev/null +++ b/Bio/Ext/Align/libs/proteindb.c @@ -0,0 +1,524 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "proteindb.h" + + +/* Function: show_Hscore_ProteinDB(hs,ofp) + * + * Descrip: shows the Hscore by the ProteinDB information + * + * + * + * Arg: hs [UNKN ] High Score structure [Hscore *] + * Arg: ofp [UNKN ] output file [FILE *] + * + */ +# line 41 "proteindb.dy" +void show_Hscore_ProteinDB(Hscore * hs,FILE * ofp) +{ + int i; + + for(i=0;ilen;i++) + fprintf(ofp,"Query [%20s] Target [%20s] %d\n",hs->ds[i]->query->name,hs->ds[i]->target->name,hs->ds[i]->score); +} + + +/* Function: dataentry_add_ProteinDB(de,cs,prodb) + * + * Descrip: adds information to dataentry from ProteinDB + * + * will eventually add file offset and format information + * + * + * Arg: de [UNKN ] Undocumented argument [DataEntry *] + * Arg: cs [UNKN ] Undocumented argument [ComplexSequence *] + * Arg: prodb [UNKN ] Undocumented argument [ProteinDB *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 55 "proteindb.dy" +boolean dataentry_add_ProteinDB(DataEntry * de,ComplexSequence * cs,ProteinDB * prodb) +{ + de->name = stringalloc(cs->seq->name); + return TRUE; +} + + +/* Function: init_ProteinDB(prodb,return_status) + * + * Descrip: top level function which opens the protein database + * + * + * Arg: prodb [UNKN ] protein database [ProteinDB *] + * Arg: return_status [WRITE] the status of the open from database.h [int *] + * + * Return [UNKN ] Undocumented return value [ComplexSequence *] + * + */ +# line 68 "proteindb.dy" +ComplexSequence * init_ProteinDB(ProteinDB * prodb,int * return_status) +{ + ComplexSequence * cs; + Sequence * seq; + + if( prodb->is_single_seq == TRUE) { + *return_status = DB_RETURN_OK; + return prodb->single; + } + + seq = init_SequenceDB(prodb->sdb,return_status); + + if( seq == NULL || *return_status == DB_RETURN_ERROR || *return_status == DB_RETURN_END ) { + return NULL; /** error already reported **/ + } + + cs = new_ComplexSequence(seq,prodb->cses); + + free_Sequence(seq); + + return cs; +} + +/* Function: reload_ProteinDB(last,prodb,return_status) + * + * Descrip: function which reloads the database + * + * + * Arg: last [UNKN ] previous complex sequence, will be freed [ComplexSequence *] + * Arg: prodb [UNKN ] Undocumented argument [ProteinDB *] + * Arg: return_status [WRITE] return_status of the load [int *] + * + * Return [UNKN ] Undocumented return value [ComplexSequence *] + * + */ +# line 97 "proteindb.dy" +ComplexSequence * reload_ProteinDB(ComplexSequence * last,ProteinDB * prodb,int * return_status) +{ + ComplexSequence * cs; + Sequence * seq; + + + + if( prodb->is_single_seq == TRUE ) { + *return_status = DB_RETURN_END; + return NULL; + } + + /** free Complex Sequence **/ + if( last != NULL ) + free_ComplexSequence(last); + + seq = reload_SequenceDB(NULL,prodb->sdb,return_status); + + if( seq == NULL || *return_status == DB_RETURN_ERROR || *return_status == DB_RETURN_END ) { + return NULL; /** error already reported **/ + } + + cs = new_ComplexSequence(seq,prodb->cses); + + free_Sequence(seq); + + return cs; +} + + + +/* Function: close_ProteinDB(cs,prodb) + * + * Descrip: top level function which closes the protein database + * + * + * Arg: cs [UNKN ] last complex sequence [ComplexSequence *] + * Arg: prodb [UNKN ] protein database [ProteinDB *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 134 "proteindb.dy" +boolean close_ProteinDB(ComplexSequence * cs,ProteinDB * prodb) +{ + if( prodb->is_single_seq == TRUE ) { + return TRUE; + } + + if( cs == NULL) + free_ComplexSequence(cs); + + return close_SequenceDB(NULL,prodb->sdb); +} + +/* Function: new_ProteinDB_from_single_seq(seq) + * + * Descrip: To make a new protein database + * from a single Sequence with default amino acid mapping + * + * + * Arg: seq [UNKN ] sequence which as placed into ProteinDB structure. [Sequence *] + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +# line 152 "proteindb.dy" +ProteinDB * new_ProteinDB_from_single_seq(Sequence * seq) +{ + ComplexSequenceEvalSet * cses; + ComplexSequence * cs; + + cses = default_aminoacid_ComplexSequenceEvalSet(); + + cs = new_ComplexSequence(seq,cses); + + free_ComplexSequenceEvalSet(cses); + + return new_ProteinDB_from_single_cseq(cs); +} + + +/* Function: new_ProteinDB_from_single_cseq(cs) + * + * Descrip: To make a new protein database + * from a single ComplexSequence + * + * + * Arg: cs [UNKN ] complex sequence which is held. [ComplexSequence *] + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +# line 173 "proteindb.dy" +ProteinDB * new_ProteinDB_from_single_cseq(ComplexSequence * cs) +{ + ProteinDB * out; + + + out = ProteinDB_alloc(); + out->is_single_seq = TRUE; + out->single = cs; + + return out; +} + +/* Function: single_fasta_ProteinDB(filename) + * + * Descrip: pre-packed single fasta protein database + * + * + * + * Arg: filename [UNKN ] name of fasta file [char *] + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +# line 191 "proteindb.dy" +ProteinDB * single_fasta_ProteinDB(char * filename) +{ + return new_ProteinDB(single_fasta_SequenceDB(filename),default_aminoacid_ComplexSequenceEvalSet()); +} + + +/* Function: new_ProteinDB(seqdb,cses) + * + * Descrip: To make a new protein database + * + * + * Arg: seqdb [UNKN ] sequence database [SequenceDB *] + * Arg: cses [UNKN ] protein evaluation set [ComplexSequenceEvalSet *] + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +# line 203 "proteindb.dy" +ProteinDB * new_ProteinDB(SequenceDB * seqdb,ComplexSequenceEvalSet * cses) +{ + ProteinDB * out; + + /** should check sequence database **/ + + if( cses->type != SEQUENCE_PROTEIN ) { + warn("You can't make a protein database with a non SEQUENCE_PROTEIN cses type [%d]",cses->type); + return NULL; + } + + + out = ProteinDB_alloc(); + + out->sdb = seqdb; + out->cses = cses; + + return out; +} + + +# line 235 "proteindb.c" +/* Function: hard_link_ProteinDB(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [ProteinDB *] + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +ProteinDB * hard_link_ProteinDB(ProteinDB * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a ProteinDB object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: ProteinDB_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +ProteinDB * ProteinDB_alloc(void) +{ + ProteinDB * out;/* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(ProteinDB *) ckalloc (sizeof(ProteinDB))) == NULL) { + warn("ProteinDB_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->is_single_seq = FALSE; + out->single = NULL; + out->sdb = NULL; + out->cses = NULL; + + + return out; +} + + +/* Function: free_ProteinDB(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ProteinDB *] + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +ProteinDB * free_ProteinDB(ProteinDB * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a ProteinDB obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->single != NULL) + free_ComplexSequence(obj->single); + if( obj->sdb != NULL) + free_SequenceDB(obj->sdb); + if( obj->cses != NULL) + free_ComplexSequenceEvalSet(obj->cses); + + + ckfree(obj); + return NULL; +} + + +/* Function: replace_is_single_seq_ProteinDB(obj,is_single_seq) + * + * Descrip: Replace member variable is_single_seq + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ProteinDB *] + * Arg: is_single_seq [OWNER] New value of the variable [boolean] + * + * Return [SOFT ] member variable is_single_seq [boolean] + * + */ +boolean replace_is_single_seq_ProteinDB(ProteinDB * obj,boolean is_single_seq) +{ + if( obj == NULL) { + warn("In replacement function is_single_seq for object ProteinDB, got a NULL object"); + return FALSE; + } + obj->is_single_seq = is_single_seq; + return TRUE; +} + + +/* Function: access_is_single_seq_ProteinDB(obj) + * + * Descrip: Access member variable is_single_seq + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ProteinDB *] + * + * Return [SOFT ] member variable is_single_seq [boolean] + * + */ +boolean access_is_single_seq_ProteinDB(ProteinDB * obj) +{ + if( obj == NULL) { + warn("In accessor function is_single_seq for object ProteinDB, got a NULL object"); + return FALSE; + } + return obj->is_single_seq; +} + + +/* Function: replace_single_ProteinDB(obj,single) + * + * Descrip: Replace member variable single + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ProteinDB *] + * Arg: single [OWNER] New value of the variable [ComplexSequence *] + * + * Return [SOFT ] member variable single [boolean] + * + */ +boolean replace_single_ProteinDB(ProteinDB * obj,ComplexSequence * single) +{ + if( obj == NULL) { + warn("In replacement function single for object ProteinDB, got a NULL object"); + return FALSE; + } + obj->single = single; + return TRUE; +} + + +/* Function: access_single_ProteinDB(obj) + * + * Descrip: Access member variable single + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ProteinDB *] + * + * Return [SOFT ] member variable single [ComplexSequence *] + * + */ +ComplexSequence * access_single_ProteinDB(ProteinDB * obj) +{ + if( obj == NULL) { + warn("In accessor function single for object ProteinDB, got a NULL object"); + return NULL; + } + return obj->single; +} + + +/* Function: replace_sdb_ProteinDB(obj,sdb) + * + * Descrip: Replace member variable sdb + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ProteinDB *] + * Arg: sdb [OWNER] New value of the variable [SequenceDB *] + * + * Return [SOFT ] member variable sdb [boolean] + * + */ +boolean replace_sdb_ProteinDB(ProteinDB * obj,SequenceDB * sdb) +{ + if( obj == NULL) { + warn("In replacement function sdb for object ProteinDB, got a NULL object"); + return FALSE; + } + obj->sdb = sdb; + return TRUE; +} + + +/* Function: access_sdb_ProteinDB(obj) + * + * Descrip: Access member variable sdb + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ProteinDB *] + * + * Return [SOFT ] member variable sdb [SequenceDB *] + * + */ +SequenceDB * access_sdb_ProteinDB(ProteinDB * obj) +{ + if( obj == NULL) { + warn("In accessor function sdb for object ProteinDB, got a NULL object"); + return NULL; + } + return obj->sdb; +} + + +/* Function: replace_cses_ProteinDB(obj,cses) + * + * Descrip: Replace member variable cses + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ProteinDB *] + * Arg: cses [OWNER] New value of the variable [ComplexSequenceEvalSet *] + * + * Return [SOFT ] member variable cses [boolean] + * + */ +boolean replace_cses_ProteinDB(ProteinDB * obj,ComplexSequenceEvalSet * cses) +{ + if( obj == NULL) { + warn("In replacement function cses for object ProteinDB, got a NULL object"); + return FALSE; + } + obj->cses = cses; + return TRUE; +} + + +/* Function: access_cses_ProteinDB(obj) + * + * Descrip: Access member variable cses + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [ProteinDB *] + * + * Return [SOFT ] member variable cses [ComplexSequenceEvalSet *] + * + */ +ComplexSequenceEvalSet * access_cses_ProteinDB(ProteinDB * obj) +{ + if( obj == NULL) { + warn("In accessor function cses for object ProteinDB, got a NULL object"); + return NULL; + } + return obj->cses; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/proteindb.h b/Bio/Ext/Align/libs/proteindb.h new file mode 100644 index 0000000..595ed32 --- /dev/null +++ b/Bio/Ext/Align/libs/proteindb.h @@ -0,0 +1,247 @@ +#ifndef DYNAMITEproteindbHEADERFILE +#define DYNAMITEproteindbHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "sequencedb.h" +#include "hscore.h" +#include "complexsequence.h" +#include "complexevalset.h" + + + +struct bp_sw_ProteinDB { + int dynamite_hard_link; + boolean is_single_seq; + ComplexSequence * single; + SequenceDB * sdb; + ComplexSequenceEvalSet * cses; + } ; +/* ProteinDB defined */ +#ifndef DYNAMITE_DEFINED_ProteinDB +typedef struct bp_sw_ProteinDB bp_sw_ProteinDB; +#define ProteinDB bp_sw_ProteinDB +#define DYNAMITE_DEFINED_ProteinDB +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: show_Hscore_ProteinDB(hs,ofp) + * + * Descrip: shows the Hscore by the ProteinDB information + * + * + * + * Arg: hs [UNKN ] High Score structure [Hscore *] + * Arg: ofp [UNKN ] output file [FILE *] + * + */ +void bp_sw_show_Hscore_ProteinDB(Hscore * hs,FILE * ofp); +#define show_Hscore_ProteinDB bp_sw_show_Hscore_ProteinDB + + +/* Function: dataentry_add_ProteinDB(de,cs,prodb) + * + * Descrip: adds information to dataentry from ProteinDB + * + * will eventually add file offset and format information + * + * + * Arg: de [UNKN ] Undocumented argument [DataEntry *] + * Arg: cs [UNKN ] Undocumented argument [ComplexSequence *] + * Arg: prodb [UNKN ] Undocumented argument [ProteinDB *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_dataentry_add_ProteinDB(DataEntry * de,ComplexSequence * cs,ProteinDB * prodb); +#define dataentry_add_ProteinDB bp_sw_dataentry_add_ProteinDB + + +/* Function: init_ProteinDB(prodb,return_status) + * + * Descrip: top level function which opens the protein database + * + * + * Arg: prodb [UNKN ] protein database [ProteinDB *] + * Arg: return_status [WRITE] the status of the open from database.h [int *] + * + * Return [UNKN ] Undocumented return value [ComplexSequence *] + * + */ +ComplexSequence * bp_sw_init_ProteinDB(ProteinDB * prodb,int * return_status); +#define init_ProteinDB bp_sw_init_ProteinDB + + +/* Function: reload_ProteinDB(last,prodb,return_status) + * + * Descrip: function which reloads the database + * + * + * Arg: last [UNKN ] previous complex sequence, will be freed [ComplexSequence *] + * Arg: prodb [UNKN ] Undocumented argument [ProteinDB *] + * Arg: return_status [WRITE] return_status of the load [int *] + * + * Return [UNKN ] Undocumented return value [ComplexSequence *] + * + */ +ComplexSequence * bp_sw_reload_ProteinDB(ComplexSequence * last,ProteinDB * prodb,int * return_status); +#define reload_ProteinDB bp_sw_reload_ProteinDB + + +/* Function: close_ProteinDB(cs,prodb) + * + * Descrip: top level function which closes the protein database + * + * + * Arg: cs [UNKN ] last complex sequence [ComplexSequence *] + * Arg: prodb [UNKN ] protein database [ProteinDB *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_close_ProteinDB(ComplexSequence * cs,ProteinDB * prodb) ; +#define close_ProteinDB bp_sw_close_ProteinDB + + +/* Function: new_ProteinDB_from_single_seq(seq) + * + * Descrip: To make a new protein database + * from a single Sequence with default amino acid mapping + * + * + * Arg: seq [UNKN ] sequence which as placed into ProteinDB structure. [Sequence *] + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +ProteinDB * bp_sw_new_ProteinDB_from_single_seq(Sequence * seq); +#define new_ProteinDB_from_single_seq bp_sw_new_ProteinDB_from_single_seq + + +/* Function: new_ProteinDB_from_single_cseq(cs) + * + * Descrip: To make a new protein database + * from a single ComplexSequence + * + * + * Arg: cs [UNKN ] complex sequence which is held. [ComplexSequence *] + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +ProteinDB * bp_sw_new_ProteinDB_from_single_cseq(ComplexSequence * cs); +#define new_ProteinDB_from_single_cseq bp_sw_new_ProteinDB_from_single_cseq + + +/* Function: single_fasta_ProteinDB(filename) + * + * Descrip: pre-packed single fasta protein database + * + * + * + * Arg: filename [UNKN ] name of fasta file [char *] + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +ProteinDB * bp_sw_single_fasta_ProteinDB(char * filename); +#define single_fasta_ProteinDB bp_sw_single_fasta_ProteinDB + + +/* Function: new_ProteinDB(seqdb,cses) + * + * Descrip: To make a new protein database + * + * + * Arg: seqdb [UNKN ] sequence database [SequenceDB *] + * Arg: cses [UNKN ] protein evaluation set [ComplexSequenceEvalSet *] + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +ProteinDB * bp_sw_new_ProteinDB(SequenceDB * seqdb,ComplexSequenceEvalSet * cses); +#define new_ProteinDB bp_sw_new_ProteinDB + + +/* Function: hard_link_ProteinDB(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [ProteinDB *] + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +ProteinDB * bp_sw_hard_link_ProteinDB(ProteinDB * obj); +#define hard_link_ProteinDB bp_sw_hard_link_ProteinDB + + +/* Function: ProteinDB_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +ProteinDB * bp_sw_ProteinDB_alloc(void); +#define ProteinDB_alloc bp_sw_ProteinDB_alloc + + +/* Function: free_ProteinDB(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ProteinDB *] + * + * Return [UNKN ] Undocumented return value [ProteinDB *] + * + */ +ProteinDB * bp_sw_free_ProteinDB(ProteinDB * obj); +#define free_ProteinDB bp_sw_free_ProteinDB + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +boolean bp_sw_replace_single_ProteinDB(ProteinDB * obj,ComplexSequence * single); +#define replace_single_ProteinDB bp_sw_replace_single_ProteinDB +boolean bp_sw_replace_sdb_ProteinDB(ProteinDB * obj,SequenceDB * sdb); +#define replace_sdb_ProteinDB bp_sw_replace_sdb_ProteinDB +boolean bp_sw_access_is_single_seq_ProteinDB(ProteinDB * obj); +#define access_is_single_seq_ProteinDB bp_sw_access_is_single_seq_ProteinDB +SequenceDB * bp_sw_access_sdb_ProteinDB(ProteinDB * obj); +#define access_sdb_ProteinDB bp_sw_access_sdb_ProteinDB +ComplexSequence * bp_sw_access_single_ProteinDB(ProteinDB * obj); +#define access_single_ProteinDB bp_sw_access_single_ProteinDB +boolean bp_sw_replace_cses_ProteinDB(ProteinDB * obj,ComplexSequenceEvalSet * cses); +#define replace_cses_ProteinDB bp_sw_replace_cses_ProteinDB +boolean bp_sw_replace_is_single_seq_ProteinDB(ProteinDB * obj,boolean is_single_seq); +#define replace_is_single_seq_ProteinDB bp_sw_replace_is_single_seq_ProteinDB +ComplexSequenceEvalSet * bp_sw_access_cses_ProteinDB(ProteinDB * obj); +#define access_cses_ProteinDB bp_sw_access_cses_ProteinDB + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/proteinsw.c b/Bio/Ext/Align/libs/proteinsw.c new file mode 100644 index 0000000..e21af8d --- /dev/null +++ b/Bio/Ext/Align/libs/proteinsw.c @@ -0,0 +1,2882 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "proteinsw.h" + +# line 5 "proteinsw.c" + + + /***************** C functions ****************/ + /* Written using dynamite */ + /* Wed Sep 9 13:58:08 1998 */ + /* email birney@sanger.ac.uk */ + /* http://www.sanger.ac.uk/Users/birney/dynamite */ + /*************************************************/ + + + /* Please report any problems or bugs to */ + /* Ewan Birney, birney@sanger.ac.uk */ + + +/* basic set of macros to map states to numbers */ +#define MATCH 0 +#define INSERT 1 +#define DELETE 2 + + +#define START 0 +#define END 1 + + +#define ProteinSW_EXPL_MATRIX(this_matrix,i,j,STATE) this_matrix->basematrix->matrix[((j+1)*3)+STATE][i+1] +#define ProteinSW_EXPL_SPECIAL(matrix,i,j,STATE) matrix->basematrix->specmatrix[STATE][j+1] +#define ProteinSW_READ_OFF_ERROR -3 + + + + + +/* Function: search_ProteinSW(out,querydb,targetdb,comp,gap,ext) + * + * Descrip: This function makes a database search of ProteinSW + * + * + * Arg: out [UNKN ] Undocumented argument [Hscore *] + * Arg: querydb [UNKN ] Undocumented argument [ProteinDB*] + * Arg: targetdb [UNKN ] Undocumented argument [ProteinDB*] + * Arg: comp [UNKN ] Undocumented argument [CompMat*] + * Arg: gap [UNKN ] Undocumented argument [int] + * Arg: ext [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [Search_Return_Type] + * + */ +Search_Return_Type search_ProteinSW(Hscore * out,ProteinDB* querydb,ProteinDB* targetdb ,CompMat* comp,int gap,int ext) +{ + ComplexSequence* query; + ComplexSequence* target; + int db_status; + int score; + int query_pos = 0; + int target_pos = 0; + DataScore * ds; + + + push_errormsg_stack("Before any actual search in db searching"); + query = init_ProteinDB(querydb,&db_status); + if( db_status == DB_RETURN_ERROR ) { + warn("In searching ProteinSW, got a database reload error on the query [query] database"); + return SEARCH_ERROR; + } + for(;;) { + + + target_pos = 0; + + + target = init_ProteinDB(targetdb,&db_status); + if( db_status == DB_RETURN_ERROR ) { + warn("In searching ProteinSW, got a database init error on the target [target] database"); + return SEARCH_ERROR; + } + for(;;) { + + + /* No maximum length - allocated on-the-fly */ + score = score_only_ProteinSW(query, target , comp, gap, ext); + if( should_store_Hscore(out,score) == TRUE ) { + ds = new_DataScore_from_storage(out); + if( ds == NULL ) { + warn("ProteinSW search had a memory error in allocating a new_DataScore (?a leak somewhere - DataScore is a very small datastructure"); + return SEARCH_ERROR; + } + /* Now: add query/target information to the entry */ + dataentry_add_ProteinDB(ds->query,query,querydb); + dataentry_add_ProteinDB(ds->target,target,targetdb); + ds->score = score; + add_Hscore(out,ds); + } /* end of if storing datascore */ + pop_errormsg_stack(); + push_errormsg_stack("DB searching: just finished [Query Pos: %d] [Target Pos: %d]",query_pos,target_pos); + + + target = reload_ProteinDB(target,targetdb,&db_status); + if( db_status == DB_RETURN_ERROR ) { + warn("In searching ProteinSW, Reload error on database target, position %d,%d",query_pos,target_pos); + return SEARCH_ERROR; + } + if( db_status == DB_RETURN_END ) + break;/* Out of target loop */ + target_pos++; + } /* end of For all target entries */ + close_ProteinDB(target,targetdb); + query = reload_ProteinDB(query,querydb,&db_status); + if( db_status == DB_RETURN_ERROR) { + warn("In searching ProteinSW, Reload error on database query, position %d,%d",query_pos,target_pos); + return SEARCH_ERROR; + } + if( db_status == DB_RETURN_END) + break; /* Out of query loop */ + query_pos++; + } /* end of For all query entries */ + close_ProteinDB(query,querydb); + pop_errormsg_stack(); + return SEARCH_OK; +} + + +#define ProteinSW_VSMALL_MATRIX(mat,i,j,STATE) mat->basematrix->matrix[(j+2)%2][((i+1)*3)+STATE] +#define ProteinSW_VSMALL_SPECIAL(mat,i,j,STATE) mat->basematrix->specmatrix[(j+2)%2][STATE] + + +/* Function: score_only_ProteinSW(query,target,comp,gap,ext) + * + * Descrip: This function just calculates the score for the matrix + * I am pretty sure we can do this better, but hey, for the moment... + * It calls /allocate_ProteinSW_only + * + * + * Arg: query [UNKN ] query data structure [ComplexSequence*] + * Arg: target [UNKN ] target data structure [ComplexSequence*] + * Arg: comp [UNKN ] Resource [CompMat*] + * Arg: gap [UNKN ] Resource [int] + * Arg: ext [UNKN ] Resource [int] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int score_only_ProteinSW(ComplexSequence* query,ComplexSequence* target ,CompMat* comp,int gap,int ext) +{ + int bestscore = NEGI; + int i; + int j; + int k; + ProteinSW * mat; + + + mat = allocate_ProteinSW_only(query, target , comp, gap, ext); + if( mat == NULL ) { + warn("Memory allocation error in the db search - unable to communicate to calling function. this spells DIASTER!"); + return NEGI; + } + if((mat->basematrix = BaseMatrix_alloc_matrix_and_specials(2,(mat->leni + 1) * 3,2,2)) == NULL) { + warn("Score only matrix for ProteinSW cannot be allocated, (asking for 1 by %d cells)",mat->leni*3); + mat = free_ProteinSW(mat); + return 0; + } + mat->basematrix->type = BASEMATRIX_TYPE_VERYSMALL; + + + /* Now, initiate matrix */ + for(j=0;j<3;j++) { + for(i=(-1);ileni;i++) { + for(k=0;k<3;k++) + ProteinSW_VSMALL_MATRIX(mat,i,j,k) = NEGI; + } + ProteinSW_VSMALL_SPECIAL(mat,i,j,START) = 0; + ProteinSW_VSMALL_SPECIAL(mat,i,j,END) = NEGI; + } + + + /* Ok, lets do-o-o-o-o it */ + + + for(j=0;jlenj;j++) { + auto int score; + auto int temp; + for(i=0;ileni;i++) { + + + /* For state MATCH */ + /* setting first movement to score */ + score = ProteinSW_VSMALL_MATRIX(mat,i-1,j-1,MATCH) + 0; + /* From state INSERT to state MATCH */ + temp = ProteinSW_VSMALL_MATRIX(mat,i-1,j-1,INSERT) + 0; + if( temp > score ) { + score = temp; + } + /* From state DELETE to state MATCH */ + temp = ProteinSW_VSMALL_MATRIX(mat,i-1,j-1,DELETE) + 0; + if( temp > score ) { + score = temp; + } + /* From state START to state MATCH */ + temp = ProteinSW_VSMALL_SPECIAL(mat,i-1,j-1,START) + 0; + if( temp > score ) { + score = temp; + } + + + /* Ok - finished max calculation for MATCH */ + /* Add any movement independant score and put away */ + score += CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j)); + ProteinSW_VSMALL_MATRIX(mat,i,j,MATCH) = score; + + + /* state MATCH is a source for special END */ + temp = score + (0) + (0) ; + if( temp > ProteinSW_VSMALL_SPECIAL(mat,i,j,END) ) { + ProteinSW_VSMALL_SPECIAL(mat,i,j,END) = temp; + } + + + + + /* Finished calculating state MATCH */ + + + /* For state INSERT */ + /* setting first movement to score */ + score = ProteinSW_VSMALL_MATRIX(mat,i-0,j-1,MATCH) + mat->gap; + /* From state INSERT to state INSERT */ + temp = ProteinSW_VSMALL_MATRIX(mat,i-0,j-1,INSERT) + mat->ext; + if( temp > score ) { + score = temp; + } + + + /* Ok - finished max calculation for INSERT */ + /* Add any movement independant score and put away */ + ProteinSW_VSMALL_MATRIX(mat,i,j,INSERT) = score; + + + /* Finished calculating state INSERT */ + + + /* For state DELETE */ + /* setting first movement to score */ + score = ProteinSW_VSMALL_MATRIX(mat,i-1,j-0,MATCH) + mat->gap; + /* From state DELETE to state DELETE */ + temp = ProteinSW_VSMALL_MATRIX(mat,i-1,j-0,DELETE) + mat->ext; + if( temp > score ) { + score = temp; + } + + + /* Ok - finished max calculation for DELETE */ + /* Add any movement independant score and put away */ + ProteinSW_VSMALL_MATRIX(mat,i,j,DELETE) = score; + + + /* Finished calculating state DELETE */ + } /* end of for all query positions */ + + + + + /* Special state START has no special to special movements */ + + + /* Special state END has no special to special movements */ + if( bestscore < ProteinSW_VSMALL_SPECIAL(mat,0,j,END) ) + bestscore = ProteinSW_VSMALL_SPECIAL(mat,0,j,END); + } /* end of for all target positions */ + + + mat = free_ProteinSW(mat); + return bestscore; +} + + +/* Function: PackAln_bestmemory_ProteinSW(query,target,comp,gap,ext,dpenv) + * + * Descrip: This function chooses the best memory set-up for the alignment + * using calls to basematrix, and then implements either a large + * or small memory model. + * + * It is the best function to use if you just want an alignment + * + * If you want a label alignment, you will need + * /convert_PackAln_to_AlnBlock_ProteinSW + * + * + * Arg: query [UNKN ] query data structure [ComplexSequence*] + * Arg: target [UNKN ] target data structure [ComplexSequence*] + * Arg: comp [UNKN ] Resource [CompMat*] + * Arg: gap [UNKN ] Resource [int] + * Arg: ext [UNKN ] Resource [int] + * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * PackAln_bestmemory_ProteinSW(ComplexSequence* query,ComplexSequence* target ,CompMat* comp,int gap,int ext,DPEnvelope * dpenv) +{ + int total; + ProteinSW * mat; + PackAln * out; + + + total = query->seq->len * target->seq->len; + + + if( dpenv != NULL || (total * 3 * sizeof(int)) > 1000*get_max_BaseMatrix_kbytes() ) { + /* use small implementation */ + if( (mat=allocate_Small_ProteinSW(query, target , comp, gap, ext)) == NULL ) { + warn("Unable to allocate small ProteinSW version"); + return NULL; + } + out = PackAln_calculate_Small_ProteinSW(mat,dpenv); + } + else { + /* use Large implementation */ + if( (mat=allocate_Expl_ProteinSW(query, target , comp, gap, ext)) == NULL ) { + warn("Unable to allocate large ProteinSW version"); + return NULL; + } + calculate_ProteinSW(mat); + out = PackAln_read_Expl_ProteinSW(mat); + } + + + mat = free_ProteinSW(mat); + return out; +} + + +/* Function: allocate_ProteinSW_only(query,target,comp,gap,ext) + * + * Descrip: This function only allocates the ProteinSW structure + * checks types where possible and determines leni and lenj + * The basematrix area is delt with elsewhere + * + * + * Arg: query [UNKN ] query data structure [ComplexSequence*] + * Arg: target [UNKN ] target data structure [ComplexSequence*] + * Arg: comp [UNKN ] Resource [CompMat*] + * Arg: gap [UNKN ] Resource [int] + * Arg: ext [UNKN ] Resource [int] + * + * Return [UNKN ] Undocumented return value [ProteinSW *] + * + */ +ProteinSW * allocate_ProteinSW_only(ComplexSequence* query,ComplexSequence* target ,CompMat* comp,int gap,int ext) +{ + ProteinSW * out; + + + if((out= ProteinSW_alloc()) == NULL) { + warn("Allocation of basic ProteinSW structure failed..."); + return NULL; + } + + + out->query = query; + out->target = target; + out->comp = comp; + out->gap = gap; + out->ext = ext; + out->leni = query->seq->len; + out->lenj = target->seq->len; + return out; +} + + +/* Function: allocate_Expl_ProteinSW(query,target,comp,gap,ext) + * + * Descrip: This function allocates the ProteinSW structure + * and the basematrix area for explicit memory implementations + * It calls /allocate_ProteinSW_only + * + * + * Arg: query [UNKN ] query data structure [ComplexSequence*] + * Arg: target [UNKN ] target data structure [ComplexSequence*] + * Arg: comp [UNKN ] Resource [CompMat*] + * Arg: gap [UNKN ] Resource [int] + * Arg: ext [UNKN ] Resource [int] + * + * Return [UNKN ] Undocumented return value [ProteinSW *] + * + */ +ProteinSW * allocate_Expl_ProteinSW(ComplexSequence* query,ComplexSequence* target ,CompMat* comp,int gap,int ext) +{ + ProteinSW * out; + + + out = allocate_ProteinSW_only(query, target , comp, gap, ext); + if( out == NULL ) + return NULL; + if( (out->basematrix = BaseMatrix_alloc_matrix_and_specials((out->lenj+1)*3,(out->leni+1),2,out->lenj+1)) == NULL) { + warn("Explicit matrix ProteinSW cannot be allocated, (asking for %d by %d main cells)",out->leni,out->lenj); + free_ProteinSW(out); + return NULL; + } + out->basematrix->type = BASEMATRIX_TYPE_EXPLICIT; + init_ProteinSW(out); + return out; +} + + +/* Function: init_ProteinSW(mat) + * + * Descrip: This function initates ProteinSW matrix when in explicit mode + * Called in /allocate_Expl_ProteinSW + * + * + * Arg: mat [UNKN ] ProteinSW which contains explicit basematrix memory [ProteinSW *] + * + */ +void init_ProteinSW(ProteinSW * mat) +{ + register int i; + register int j; + if( mat->basematrix->type != BASEMATRIX_TYPE_EXPLICIT) { + warn("Cannot iniate matrix, is not an explicit memory type and you have assummed that"); + return; + } + + + for(i= (-1);iquery->seq->len;i++) { + for(j= (-1);j<2;j++) { + ProteinSW_EXPL_MATRIX(mat,i,j,MATCH) = NEGI; + ProteinSW_EXPL_MATRIX(mat,i,j,INSERT) = NEGI; + ProteinSW_EXPL_MATRIX(mat,i,j,DELETE) = NEGI; + } + } + for(j= (-1);jtarget->seq->len;j++) { + for(i= (-1);i<2;i++) { + ProteinSW_EXPL_MATRIX(mat,i,j,MATCH) = NEGI; + ProteinSW_EXPL_MATRIX(mat,i,j,INSERT) = NEGI; + ProteinSW_EXPL_MATRIX(mat,i,j,DELETE) = NEGI; + } + ProteinSW_EXPL_SPECIAL(mat,i,j,START) = 0; + ProteinSW_EXPL_SPECIAL(mat,i,j,END) = NEGI; + } + return; +} + + +/* Function: recalculate_PackAln_ProteinSW(pal,mat) + * + * Descrip: This function recalculates the PackAln structure produced by ProteinSW + * For example, in linear space methods this is used to score them + * + * + * Arg: pal [UNKN ] Undocumented argument [PackAln *] + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * + */ +void recalculate_PackAln_ProteinSW(PackAln * pal,ProteinSW * mat) +{ + int i,j,k,offi,offj; + PackAlnUnit * prev; + PackAlnUnit * pau; + + + for(k=1,prev=pal->pau[0];k < pal->len;k++,prev=pau) { + pau = pal->pau[k]; + i = pau->i; + j = pau->j; + offi = pau->i - prev->i; + offj = pau->j - prev->j; + switch(pau->state) { + case MATCH : + if( offi == 1 && offj == 1 && prev->state == MATCH ) { + pau->score = 0 + (CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + continue; + } + if( offi == 1 && offj == 1 && prev->state == INSERT ) { + pau->score = 0 + (CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + continue; + } + if( offi == 1 && offj == 1 && prev->state == DELETE ) { + pau->score = 0 + (CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + continue; + } + if( offj == 1 && prev->state == (START+3) ) { + pau->score = 0 + (CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + continue; + } + warn("In recaluclating PackAln with state MATCH, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state); + break; + case INSERT : + if( offi == 0 && offj == 1 && prev->state == MATCH ) { + pau->score = mat->gap + (0); + continue; + } + if( offi == 0 && offj == 1 && prev->state == INSERT ) { + pau->score = mat->ext + (0); + continue; + } + warn("In recaluclating PackAln with state INSERT, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state); + break; + case DELETE : + if( offi == 1 && offj == 0 && prev->state == MATCH ) { + pau->score = mat->gap + (0); + continue; + } + if( offi == 1 && offj == 0 && prev->state == DELETE ) { + pau->score = mat->ext + (0); + continue; + } + warn("In recaluclating PackAln with state DELETE, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state); + break; + case (START+3) : + warn("In recaluclating PackAln with state START, got a bad source state. Error!"); + break; + case (END+3) : + if( offj == 0 && prev->state == MATCH ) { + /* i here comes from the previous state ;) - not the real one */ + i = prev->i; + pau->score = 0 + (0); + continue; + } + warn("In recaluclating PackAln with state END, got a bad source state. Error!"); + break; + default : + warn("In recaluclating PackAln got a bad recipient state. Error!"); + } + prev = pau; + } + return; +} +/* divide and conquor macros are next */ +#define ProteinSW_HIDDEN_MATRIX(thismatrix,i,j,state) (thismatrix->basematrix->matrix[(j-hiddenj+1)][(i+1)*3+state]) +#define ProteinSW_DC_SHADOW_MATRIX(thismatrix,i,j,state) (thismatrix->basematrix->matrix[((j+2)*8) % 16][(i+1)*3+state]) +#define ProteinSW_HIDDEN_SPECIAL(thismatrix,i,j,state) (thismatrix->basematrix->specmatrix[state][(j+1)]) +#define ProteinSW_DC_SHADOW_SPECIAL(thismatrix,i,j,state) (thismatrix->basematrix->specmatrix[state*8][(j+1)]) +#define ProteinSW_DC_SHADOW_MATRIX_SP(thismatrix,i,j,state,shadow) (thismatrix->basematrix->matrix[((((j+2)*8)+(shadow+1)) % 16)][(i+1)*3 + state]) +/* Function: allocate_Small_ProteinSW(query,target,comp,gap,ext) + * + * Descrip: This function allocates the ProteinSW structure + * and the basematrix area for a small memory implementations + * It calls /allocate_ProteinSW_only + * + * + * Arg: query [UNKN ] query data structure [ComplexSequence*] + * Arg: target [UNKN ] target data structure [ComplexSequence*] + * Arg: comp [UNKN ] Resource [CompMat*] + * Arg: gap [UNKN ] Resource [int] + * Arg: ext [UNKN ] Resource [int] + * + * Return [UNKN ] Undocumented return value [ProteinSW *] + * + */ +#define ProteinSW_DC_SHADOW_SPECIAL_SP(thismatrix,i,j,state,shadow) (thismatrix->basematrix->specmatrix[state*8 +shadow+1][(j+1)]) +ProteinSW * allocate_Small_ProteinSW(ComplexSequence* query,ComplexSequence* target ,CompMat* comp,int gap,int ext) +{ + ProteinSW * out; + + + out = allocate_ProteinSW_only(query, target , comp, gap, ext); + if( out == NULL ) + return NULL; + out->basematrix = BaseMatrix_alloc_matrix_and_specials(16,(out->leni + 1) * 3,16,out->lenj+1); + if(out == NULL) { + warn("Small shadow matrix ProteinSW cannot be allocated, (asking for 2 by %d main cells)",out->leni+2); + free_ProteinSW(out); + return NULL; + } + out->basematrix->type = BASEMATRIX_TYPE_SHADOW; + return out; +} + + +/* Function: PackAln_calculate_Small_ProteinSW(mat,dpenv) + * + * Descrip: This function calculates an alignment for ProteinSW structure in linear space + * If you want only the start/end points + * use /AlnRangeSet_calculate_Small_ProteinSW + * + * The function basically + * finds start/end points + * foreach start/end point + * calls /full_dc_ProteinSW + * + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * PackAln_calculate_Small_ProteinSW(ProteinSW * mat,DPEnvelope * dpenv) +{ + int endj; + int score; + PackAln * out; + PackAlnUnit * pau; + int starti; + int startj; + int startstate; + int stopi; + int stopj; + int stopstate; + int temp; + int donej; /* This is for reporting, will be passed as a & arg in */ + int totalj; /* This also is for reporting, but as is not changed, can be passed by value */ + + + if( mat->basematrix->type != BASEMATRIX_TYPE_SHADOW ) { + warn("Could not calculate packaln small for ProteinSW due to wrong type of matrix"); + return NULL; + } + + + out = PackAln_alloc_std(); + + + start_reporting("Find start end points: "); + dc_start_end_calculate_ProteinSW(mat,dpenv); + score = start_end_find_end_ProteinSW(mat,&endj); + out->score = score; + stopstate = END; + + /* No special to specials: one matrix alignment: simply remove and get */ + starti = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,0); + startj = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,1); + startstate = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,2); + stopi = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,3); + stopj = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,4); + stopstate = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,5); + temp = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,6); + log_full_error(REPORT,0,"[%d,%d][%d,%d] Score %d",starti,startj,stopi,stopj,score); + stop_reporting(); + start_reporting("Recovering alignment: "); + + + /* Figuring how much j we have to align for reporting purposes */ + donej = 0; + totalj = stopj - startj; + full_dc_ProteinSW(mat,starti,startj,startstate,stopi,stopj,stopstate,out,&donej,totalj,dpenv); + + + /* Although we have no specials, need to get start. Better to check than assume */ + + + max_matrix_to_special_ProteinSW(mat,starti,startj,startstate,temp,&stopi,&stopj,&stopstate,&temp,NULL); + if( stopi == ProteinSW_READ_OFF_ERROR || stopstate != START ) { + warn("Problem in reading off special state system, hit a non start state (or an internal error) in a single alignment mode"); + invert_PackAln(out); + recalculate_PackAln_ProteinSW(out,mat); + return out; + } + + + /* Ok. Put away start start... */ + pau = PackAlnUnit_alloc(); + pau->i = stopi; + pau->j = stopj; + pau->state = stopstate + 3; + add_PackAln(out,pau); + + + log_full_error(REPORT,0,"Alignment recovered"); + stop_reporting(); + invert_PackAln(out); + recalculate_PackAln_ProteinSW(out,mat); + return out; + + +} + + +/* Function: AlnRangeSet_calculate_Small_ProteinSW(mat) + * + * Descrip: This function calculates an alignment for ProteinSW structure in linear space + * If you want the full alignment, use /PackAln_calculate_Small_ProteinSW + * If you have already got the full alignment, but want the range set, use /AlnRangeSet_from_PackAln_ProteinSW + * If you have got the small matrix but not the alignment, use /AlnRangeSet_from_ProteinSW + * + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * AlnRangeSet_calculate_Small_ProteinSW(ProteinSW * mat) +{ + AlnRangeSet * out; + + + start_reporting("Find start end points: "); + dc_start_end_calculate_ProteinSW(mat,NULL); + log_full_error(REPORT,0,"Calculated"); + + + out = AlnRangeSet_from_ProteinSW(mat); + return out; +} + + +/* Function: AlnRangeSet_from_ProteinSW(mat) + * + * Descrip: This function reads off a start/end structure + * for ProteinSW structure in linear space + * If you want the full alignment use + * /PackAln_calculate_Small_ProteinSW + * If you have not calculated the matrix use + * /AlnRange_calculate_Small_ProteinSW + * + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * AlnRangeSet_from_ProteinSW(ProteinSW * mat) +{ + AlnRangeSet * out; + AlnRange * temp; + int jpos; + int state; + + + if( mat->basematrix->type != BASEMATRIX_TYPE_SHADOW) { + warn("Bad error! - non shadow matrix type in AlnRangeSet_from_ProteinSW"); + return NULL; + } + + + out = AlnRangeSet_alloc_std(); + /* Find the end position */ + out->score = start_end_find_end_ProteinSW(mat,&jpos); + state = END; + + + while( (temp = AlnRange_build_ProteinSW(mat,jpos,state,&jpos,&state)) != NULL) + add_AlnRangeSet(out,temp); + return out; +} + + +/* Function: AlnRange_build_ProteinSW(mat,stopj,stopspecstate,startj,startspecstate) + * + * Descrip: This function calculates a single start/end set in linear space + * Really a sub-routine for /AlnRangeSet_from_PackAln_ProteinSW + * + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: stopj [UNKN ] Undocumented argument [int] + * Arg: stopspecstate [UNKN ] Undocumented argument [int] + * Arg: startj [UNKN ] Undocumented argument [int *] + * Arg: startspecstate [UNKN ] Undocumented argument [int *] + * + * Return [UNKN ] Undocumented return value [AlnRange *] + * + */ +AlnRange * AlnRange_build_ProteinSW(ProteinSW * mat,int stopj,int stopspecstate,int * startj,int * startspecstate) +{ + AlnRange * out; + int jpos; + int state; + + + if( mat->basematrix->type != BASEMATRIX_TYPE_SHADOW) { + warn("Bad error! - non shadow matrix type in AlnRangeSet_from_ProteinSW"); + return NULL; + } + + + /* Assumme that we have specials (we should!). Read back along the specials till we have the finish point */ + if( read_special_strip_ProteinSW(mat,0,stopj,stopspecstate,&jpos,&state,NULL) == FALSE) { + warn("In AlnRanger_build_ProteinSW alignment ending at %d, unable to read back specials. Will (evenutally) return a partial range set... BEWARE!",stopj); + return NULL; + } + if( state == START || jpos <= 0) + return NULL; + + + out = AlnRange_alloc(); + + + out->starti = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,0); + out->startj = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,1); + out->startstate = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,2); + out->stopi = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,3); + out->stopj = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,4); + out->stopstate = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,5); + out->startscore = ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,6); + out->stopscore = ProteinSW_DC_SHADOW_SPECIAL(mat,0,jpos,state); + + + /* Now, we have to figure out where this state came from in the specials */ + max_matrix_to_special_ProteinSW(mat,out->starti,out->startj,out->startstate,out->startscore,&jpos,startj,startspecstate,&state,NULL); + if( jpos == ProteinSW_READ_OFF_ERROR) { + warn("In AlnRange_build_ProteinSW alignment ending at %d, with aln range between %d-%d in j, unable to find source special, returning this range, but this could get tricky!",stopj,out->startj,out->stopj); + return out; + } + + + /* Put in the correct score for startstate, from the special */ + out->startscore = ProteinSW_DC_SHADOW_SPECIAL(mat,0,*startj,*startspecstate); + /* The correct j coords have been put into startj, startspecstate... so just return out */ + return out; +} + + +/* Function: read_hidden_ProteinSW(mat,starti,startj,startstate,stopi,stopj,stopstate,out) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: starti [UNKN ] Undocumented argument [int] + * Arg: startj [UNKN ] Undocumented argument [int] + * Arg: startstate [UNKN ] Undocumented argument [int] + * Arg: stopi [UNKN ] Undocumented argument [int] + * Arg: stopj [UNKN ] Undocumented argument [int] + * Arg: stopstate [UNKN ] Undocumented argument [int] + * Arg: out [UNKN ] Undocumented argument [PackAln *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean read_hidden_ProteinSW(ProteinSW * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,PackAln * out) +{ + int i; + int j; + int state; + int cellscore; + int isspecial; + /* We don't need hiddenj here, 'cause matrix access handled by max funcs */ + PackAlnUnit * pau; + + + /* stop position is on the path */ + i = stopi; + j = stopj; + state= stopstate; + isspecial = FALSE; + + + while( i >= starti && j >= startj) { + /* Put away current i,j,state */ + pau = PackAlnUnit_alloc();/* Should deal with memory overflow */ + pau->i = i; + pau->j = j; + pau->state = state; + add_PackAln(out,pau); + + + max_hidden_ProteinSW(mat,startj,i,j,state,isspecial,&i,&j,&state,&isspecial,&cellscore); + + + if( i == ProteinSW_READ_OFF_ERROR) { + warn("In ProteinSW hidden read off, between %d:%d,%d:%d - at got bad read off. Problem!",starti,startj,stopi,stopj); + return FALSE; + } + + + if( i == starti && j == startj && state == startstate) { +/* Put away final state (start of this block) */ + pau = PackAlnUnit_alloc(); /* Should deal with memory overflow */ + pau->i = i; + pau->j = j; + pau->state = state; + add_PackAln(out,pau); + return TRUE; + } + if( i == starti && j == startj) { + warn("In ProteinSW hidden read off, between %d:%d,%d:%d - hit start cell, but not in start state. Can't be good!.",starti,startj,stopi,stopj); + return FALSE; + } + } + warn("In ProteinSW hidden read off, between %d:%d,%d:%d - gone past start cell (now in %d,%d,%d), can't be good news!.",starti,startj,stopi,stopj,i,j,state); + return FALSE; +} + + +/* Function: max_hidden_ProteinSW(mat,hiddenj,i,j,state,isspecial,reti,retj,retstate,retspecial,cellscore) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: hiddenj [UNKN ] Undocumented argument [int] + * Arg: i [UNKN ] Undocumented argument [int] + * Arg: j [UNKN ] Undocumented argument [int] + * Arg: state [UNKN ] Undocumented argument [int] + * Arg: isspecial [UNKN ] Undocumented argument [boolean] + * Arg: reti [UNKN ] Undocumented argument [int *] + * Arg: retj [UNKN ] Undocumented argument [int *] + * Arg: retstate [UNKN ] Undocumented argument [int *] + * Arg: retspecial [UNKN ] Undocumented argument [boolean *] + * Arg: cellscore [UNKN ] Undocumented argument [int *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int max_hidden_ProteinSW(ProteinSW * mat,int hiddenj,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore) +{ + register int temp; + register int cscore; + + + *reti = (*retj) = (*retstate) = ProteinSW_READ_OFF_ERROR; + + + if( i < 0 || j < 0 || i > mat->query->seq->len || j > mat->target->seq->len) { + warn("In ProteinSW matrix special read off - out of bounds on matrix [i,j is %d,%d state %d in standard matrix]",i,j,state); + return -1; + } + + + /* Then you have to select the correct switch statement to figure out the readoff */ + /* Somewhat odd - reverse the order of calculation and return as soon as it is correct */ + cscore = ProteinSW_HIDDEN_MATRIX(mat,i,j,state); + switch(state) { + case MATCH : + /* Not allowing special sources.. skipping START */ + temp = cscore - (0) - (CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + if( temp == ProteinSW_HIDDEN_MATRIX(mat,i - 1,j - 1,DELETE) ) { + *reti = i - 1; + *retj = j - 1; + *retstate = DELETE; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_HIDDEN_MATRIX(mat,i-1,j-1,DELETE); + } + return ProteinSW_HIDDEN_MATRIX(mat,i - 1,j - 1,DELETE); + } + temp = cscore - (0) - (CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + if( temp == ProteinSW_HIDDEN_MATRIX(mat,i - 1,j - 1,INSERT) ) { + *reti = i - 1; + *retj = j - 1; + *retstate = INSERT; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_HIDDEN_MATRIX(mat,i-1,j-1,INSERT); + } + return ProteinSW_HIDDEN_MATRIX(mat,i - 1,j - 1,INSERT); + } + temp = cscore - (0) - (CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + if( temp == ProteinSW_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH) ) { + *reti = i - 1; + *retj = j - 1; + *retstate = MATCH; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_HIDDEN_MATRIX(mat,i-1,j-1,MATCH); + } + return ProteinSW_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH); + } + warn("Major problem (!) - in ProteinSW read off, position %d,%d state %d no source found!",i,j,state); + return (-1); + case INSERT : + temp = cscore - (mat->ext) - (0); + if( temp == ProteinSW_HIDDEN_MATRIX(mat,i - 0,j - 1,INSERT) ) { + *reti = i - 0; + *retj = j - 1; + *retstate = INSERT; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_HIDDEN_MATRIX(mat,i-0,j-1,INSERT); + } + return ProteinSW_HIDDEN_MATRIX(mat,i - 0,j - 1,INSERT); + } + temp = cscore - (mat->gap) - (0); + if( temp == ProteinSW_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH) ) { + *reti = i - 0; + *retj = j - 1; + *retstate = MATCH; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_HIDDEN_MATRIX(mat,i-0,j-1,MATCH); + } + return ProteinSW_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH); + } + warn("Major problem (!) - in ProteinSW read off, position %d,%d state %d no source found!",i,j,state); + return (-1); + case DELETE : + temp = cscore - (mat->ext) - (0); + if( temp == ProteinSW_HIDDEN_MATRIX(mat,i - 1,j - 0,DELETE) ) { + *reti = i - 1; + *retj = j - 0; + *retstate = DELETE; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_HIDDEN_MATRIX(mat,i-1,j-0,DELETE); + } + return ProteinSW_HIDDEN_MATRIX(mat,i - 1,j - 0,DELETE); + } + temp = cscore - (mat->gap) - (0); + if( temp == ProteinSW_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH) ) { + *reti = i - 1; + *retj = j - 0; + *retstate = MATCH; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_HIDDEN_MATRIX(mat,i-1,j-0,MATCH); + } + return ProteinSW_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH); + } + warn("Major problem (!) - in ProteinSW read off, position %d,%d state %d no source found!",i,j,state); + return (-1); + default: + warn("Major problem (!) - in ProteinSW read off, position %d,%d state %d no source found!",i,j,state); + return (-1); + } /* end of Switch state */ +} + + +/* Function: read_special_strip_ProteinSW(mat,stopi,stopj,stopstate,startj,startstate,out) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: stopi [UNKN ] Undocumented argument [int] + * Arg: stopj [UNKN ] Undocumented argument [int] + * Arg: stopstate [UNKN ] Undocumented argument [int] + * Arg: startj [UNKN ] Undocumented argument [int *] + * Arg: startstate [UNKN ] Undocumented argument [int *] + * Arg: out [UNKN ] Undocumented argument [PackAln *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean read_special_strip_ProteinSW(ProteinSW * mat,int stopi,int stopj,int stopstate,int * startj,int * startstate,PackAln * out) +{ + int i; + int j; + int state; + int cellscore; + int isspecial; + PackAlnUnit * pau; + + + /* stop position is on the path */ + i = stopi; + j = stopj; + state= stopstate; + isspecial = TRUE; + + + /* Loop until state has the same j as its stop in shadow pointers */ + /* This will be the state is came out from, OR it has hit !start */ + /* We may not want to get the alignment, in which case out will be NULL */ + while( j > ProteinSW_DC_SHADOW_SPECIAL_SP(mat,i,j,state,4) && state != START) { + /* Put away current state, if we should */ + if(out != NULL) { + pau = PackAlnUnit_alloc(); /* Should deal with memory overflow */ + pau->i = i; + pau->j = j; + pau->state = state + 3; + add_PackAln(out,pau); + } + + + max_special_strip_ProteinSW(mat,i,j,state,isspecial,&i,&j,&state,&isspecial,&cellscore); + if( i == ProteinSW_READ_OFF_ERROR) { + warn("In special strip read ProteinSW, got a bad read off error. Sorry!"); + return FALSE; + } + } /* end of while more specials to eat up */ + + + /* check to see we have not gone too far! */ + if( state != START && j < ProteinSW_DC_SHADOW_SPECIAL_SP(mat,i,j,state,4)) { + warn("In special strip read ProteinSW, at special [%d] state [%d] overshot!",j,state); + return FALSE; + } + /* Put away last state */ + if(out != NULL) { + pau = PackAlnUnit_alloc();/* Should deal with memory overflow */ + pau->i = i; + pau->j = j; + pau->state = state + 3; + add_PackAln(out,pau); + } + + + /* Put away where we are in startj and startstate */ + *startj = j; + *startstate = state; + return TRUE; +} + + +/* Function: max_special_strip_ProteinSW(mat,i,j,state,isspecial,reti,retj,retstate,retspecial,cellscore) + * + * Descrip: A pretty intense internal function. Deals with read-off only in specials + * + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: i [UNKN ] Undocumented argument [int] + * Arg: j [UNKN ] Undocumented argument [int] + * Arg: state [UNKN ] Undocumented argument [int] + * Arg: isspecial [UNKN ] Undocumented argument [boolean] + * Arg: reti [UNKN ] Undocumented argument [int *] + * Arg: retj [UNKN ] Undocumented argument [int *] + * Arg: retstate [UNKN ] Undocumented argument [int *] + * Arg: retspecial [UNKN ] Undocumented argument [boolean *] + * Arg: cellscore [UNKN ] Undocumented argument [int *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int max_special_strip_ProteinSW(ProteinSW * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore) +{ + int temp; + int cscore; + + + *reti = (*retj) = (*retstate) = ProteinSW_READ_OFF_ERROR; + if( isspecial == FALSE ) { + warn("In special strip max function for ProteinSW, got a non special start point. Problem! (bad!)"); + return (-1); + } + + + if( j < 0 || j > mat->target->seq->len) { + warn("In ProteinSW matrix special read off - out of bounds on matrix [j is %d in special]",j); + return -1; + } + + + cscore = ProteinSW_DC_SHADOW_SPECIAL(mat,i,j,state); + switch(state) { + case START : + case END : + /* Source MATCH is not a special */ + default: + warn("Major problem (!) - in ProteinSW special strip read off, position %d,%d state %d no source found dropped into default on source switch!",i,j,state); + return (-1); + } /* end of switch on special states */ +} + + +/* Function: max_matrix_to_special_ProteinSW(mat,i,j,state,cscore,reti,retj,retstate,retspecial,cellscore) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: i [UNKN ] Undocumented argument [int] + * Arg: j [UNKN ] Undocumented argument [int] + * Arg: state [UNKN ] Undocumented argument [int] + * Arg: cscore [UNKN ] Undocumented argument [int] + * Arg: reti [UNKN ] Undocumented argument [int *] + * Arg: retj [UNKN ] Undocumented argument [int *] + * Arg: retstate [UNKN ] Undocumented argument [int *] + * Arg: retspecial [UNKN ] Undocumented argument [boolean *] + * Arg: cellscore [UNKN ] Undocumented argument [int *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int max_matrix_to_special_ProteinSW(ProteinSW * mat,int i,int j,int state,int cscore,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore) +{ + int temp; + *reti = (*retj) = (*retstate) = ProteinSW_READ_OFF_ERROR; + + + if( j < 0 || j > mat->lenj) { + warn("In ProteinSW matrix to special read off - out of bounds on matrix [j is %d in special]",j); + return -1; + } + + + switch(state) { + case MATCH : + temp = cscore - (0) - (CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + if( temp == ProteinSW_DC_SHADOW_SPECIAL(mat,i - 1,j - 1,START) ) { + *reti = i - 1; + *retj = j - 1; + *retstate = START; + *retspecial = TRUE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_DC_SHADOW_SPECIAL(mat,i-1,j-1,START); + } + return ProteinSW_DC_SHADOW_MATRIX(mat,i - 1,j - 1,START) ; + } + /* Source DELETE is not a special, should not get here! */ + /* Source INSERT is not a special, should not get here! */ + /* Source MATCH is not a special, should not get here! */ + warn("Major problem (!) - in ProteinSW matrix to special read off, position %d,%d state %d no source found!",i,j,state); + return (-1); + case INSERT : + /* Source INSERT is not a special, should not get here! */ + /* Source MATCH is not a special, should not get here! */ + warn("Major problem (!) - in ProteinSW matrix to special read off, position %d,%d state %d no source found!",i,j,state); + return (-1); + case DELETE : + /* Source DELETE is not a special, should not get here! */ + /* Source MATCH is not a special, should not get here! */ + warn("Major problem (!) - in ProteinSW matrix to special read off, position %d,%d state %d no source found!",i,j,state); + return (-1); + default: + warn("Major problem (!) - in ProteinSW read off, position %d,%d state %d no source found!",i,j,state); + return (-1); + } /* end of Switch state */ + + +} + + +/* Function: calculate_hidden_ProteinSW(mat,starti,startj,startstate,stopi,stopj,stopstate,dpenv) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: starti [UNKN ] Undocumented argument [int] + * Arg: startj [UNKN ] Undocumented argument [int] + * Arg: startstate [UNKN ] Undocumented argument [int] + * Arg: stopi [UNKN ] Undocumented argument [int] + * Arg: stopj [UNKN ] Undocumented argument [int] + * Arg: stopstate [UNKN ] Undocumented argument [int] + * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *] + * + */ +void calculate_hidden_ProteinSW(ProteinSW * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,DPEnvelope * dpenv) +{ + register int i; + register int j; + register int score; + register int temp; + register int hiddenj; + + + hiddenj = startj; + + + init_hidden_ProteinSW(mat,starti,startj,stopi,stopj); + + + ProteinSW_HIDDEN_MATRIX(mat,starti,startj,startstate) = 0; + + + for(j=startj;j<=stopj;j++) { + for(i=starti;i<=stopi;i++) { + /* Should *not* do very first cell as this is the one set to zero in one state! */ + if( i == starti && j == startj ) + continue; + if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE ) { + ProteinSW_HIDDEN_MATRIX(mat,i,j,MATCH) = NEGI; + ProteinSW_HIDDEN_MATRIX(mat,i,j,INSERT) = NEGI; + ProteinSW_HIDDEN_MATRIX(mat,i,j,DELETE) = NEGI; + continue; + } /* end of Is not in envelope */ + + + /* For state MATCH */ + /* setting first movement to score */ + score = ProteinSW_HIDDEN_MATRIX(mat,i-1,j-1,MATCH) + 0; + /* From state INSERT to state MATCH */ + temp = ProteinSW_HIDDEN_MATRIX(mat,i-1,j-1,INSERT) + 0; + if( temp > score ) { + score = temp; + } + /* From state DELETE to state MATCH */ + temp = ProteinSW_HIDDEN_MATRIX(mat,i-1,j-1,DELETE) + 0; + if( temp > score ) { + score = temp; + } + + + /* Ok - finished max calculation for MATCH */ + /* Add any movement independant score and put away */ + score += CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j)); + ProteinSW_HIDDEN_MATRIX(mat,i,j,MATCH) = score; + /* Finished calculating state MATCH */ + + + /* For state INSERT */ + /* setting first movement to score */ + score = ProteinSW_HIDDEN_MATRIX(mat,i-0,j-1,MATCH) + mat->gap; + /* From state INSERT to state INSERT */ + temp = ProteinSW_HIDDEN_MATRIX(mat,i-0,j-1,INSERT) + mat->ext; + if( temp > score ) { + score = temp; + } + + + /* Ok - finished max calculation for INSERT */ + /* Add any movement independant score and put away */ + ProteinSW_HIDDEN_MATRIX(mat,i,j,INSERT) = score; + /* Finished calculating state INSERT */ + + + /* For state DELETE */ + /* setting first movement to score */ + score = ProteinSW_HIDDEN_MATRIX(mat,i-1,j-0,MATCH) + mat->gap; + /* From state DELETE to state DELETE */ + temp = ProteinSW_HIDDEN_MATRIX(mat,i-1,j-0,DELETE) + mat->ext; + if( temp > score ) { + score = temp; + } + + + /* Ok - finished max calculation for DELETE */ + /* Add any movement independant score and put away */ + ProteinSW_HIDDEN_MATRIX(mat,i,j,DELETE) = score; + /* Finished calculating state DELETE */ + } + } + + + return; +} + + +/* Function: init_hidden_ProteinSW(mat,starti,startj,stopi,stopj) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: starti [UNKN ] Undocumented argument [int] + * Arg: startj [UNKN ] Undocumented argument [int] + * Arg: stopi [UNKN ] Undocumented argument [int] + * Arg: stopj [UNKN ] Undocumented argument [int] + * + */ +void init_hidden_ProteinSW(ProteinSW * mat,int starti,int startj,int stopi,int stopj) +{ + register int i; + register int j; + register int hiddenj; + + + hiddenj = startj; + for(j=(startj-1);j<=stopj;j++) { + for(i=(starti-1);i<=stopi;i++) { + ProteinSW_HIDDEN_MATRIX(mat,i,j,MATCH) = NEGI; + + ProteinSW_HIDDEN_MATRIX(mat,i,j,INSERT) = NEGI; + + ProteinSW_HIDDEN_MATRIX(mat,i,j,DELETE) = NEGI; + + } + } + + + return; +} + + +/* Function: full_dc_ProteinSW(mat,starti,startj,startstate,stopi,stopj,stopstate,out,donej,totalj,dpenv) + * + * Descrip: The main divide-and-conquor routine. Basically, call /PackAln_calculate_small_ProteinSW + * Not this function, which is pretty hard core. + * Function is given start/end points (in main matrix) for alignment + * It does some checks, decides whether start/end in j is small enough for explicit calc + * - if yes, calculates it, reads off into PackAln (out), adds the j distance to donej and returns TRUE + * - if no, uses /do_dc_single_pass_ProteinSW to get mid-point + * saves midpoint, and calls itself to do right portion then left portion + * right then left ensures PackAln is added the 'right' way, ie, back-to-front + * returns FALSE on any error, with a warning + * + * + * Arg: mat [UNKN ] Matrix with small memory implementation [ProteinSW *] + * Arg: starti [UNKN ] Start position in i [int] + * Arg: startj [UNKN ] Start position in j [int] + * Arg: startstate [UNKN ] Start position state number [int] + * Arg: stopi [UNKN ] Stop position in i [int] + * Arg: stopj [UNKN ] Stop position in j [int] + * Arg: stopstate [UNKN ] Stop position state number [int] + * Arg: out [UNKN ] PackAln structure to put alignment into [PackAln *] + * Arg: donej [UNKN ] pointer to a number with the amount of alignment done [int *] + * Arg: totalj [UNKN ] total amount of alignment to do (in j coordinates) [int] + * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean full_dc_ProteinSW(ProteinSW * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,PackAln * out,int * donej,int totalj,DPEnvelope * dpenv) +{ + int lstarti; + int lstartj; + int lstate; + + + if( mat->basematrix->type != BASEMATRIX_TYPE_SHADOW) { + warn("*Very* bad error! - non shadow matrix type in full_dc_ProteinSW"); + return FALSE; + } + + + if( starti == -1 || startj == -1 || startstate == -1 || stopi == -1 || stopstate == -1) { + warn("In full dc program, passed bad indices, indices passed were %d:%d[%d] to %d:%d[%d]\n",starti,startj,startstate,stopi,stopj,stopstate); + return FALSE; + } + + + if( stopj - startj < 5) { + log_full_error(REPORT,0,"[%d,%d][%d,%d] Explicit read off",starti,startj,stopi,stopj);/* Build hidden explicit matrix */ + calculate_hidden_ProteinSW(mat,starti,startj,startstate,stopi,stopj,stopstate,dpenv); + *donej += (stopj - startj); /* Now read it off into out */ + if( read_hidden_ProteinSW(mat,starti,startj,startstate,stopi,stopj,stopstate,out) == FALSE) { + warn("In full dc, at %d:%d,%d:%d got a bad hidden explicit read off... ",starti,startj,stopi,stopj); + return FALSE; + } + return TRUE; + } + + +/* In actual divide and conquor */ + if( do_dc_single_pass_ProteinSW(mat,starti,startj,startstate,stopi,stopj,stopstate,dpenv,(int)(*donej*100)/totalj) == FALSE) { + warn("In divide and conquor for ProteinSW, at bound %d:%d to %d:%d, unable to calculate midpoint. Problem!",starti,startj,stopi,stopj); + return FALSE; + } + + +/* Ok... now we have to call on each side of the matrix */ +/* We have to retrieve left hand side positions, as they will be vapped by the time we call LHS */ + lstarti= ProteinSW_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,0); + lstartj= ProteinSW_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,1); + lstate = ProteinSW_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,2); + + +/* Call on right hand side: this lets us do the correct read off */ + if( full_dc_ProteinSW(mat,ProteinSW_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,3),ProteinSW_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,4),ProteinSW_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,5),stopi,stopj,stopstate,out,donej,totalj,dpenv) == FALSE) { +/* Warning already issued, simply chained back up to top */ + return FALSE; + } +/* Call on left hand side */ + if( full_dc_ProteinSW(mat,starti,startj,startstate,lstarti,lstartj,lstate,out,donej,totalj,dpenv) == FALSE) { +/* Warning already issued, simply chained back up to top */ + return FALSE; + } + + + return TRUE; +} + + +/* Function: do_dc_single_pass_ProteinSW(mat,starti,startj,startstate,stopi,stopj,stopstate,dpenv,perc_done) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: starti [UNKN ] Undocumented argument [int] + * Arg: startj [UNKN ] Undocumented argument [int] + * Arg: startstate [UNKN ] Undocumented argument [int] + * Arg: stopi [UNKN ] Undocumented argument [int] + * Arg: stopj [UNKN ] Undocumented argument [int] + * Arg: stopstate [UNKN ] Undocumented argument [int] + * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *] + * Arg: perc_done [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean do_dc_single_pass_ProteinSW(ProteinSW * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,DPEnvelope * dpenv,int perc_done) +{ + int halfj; + halfj = startj + ((stopj - startj)/2); + + + init_dc_ProteinSW(mat); + + + ProteinSW_DC_SHADOW_MATRIX(mat,starti,startj,startstate) = 0; + run_up_dc_ProteinSW(mat,starti,stopi,startj,halfj-1,dpenv,perc_done); + push_dc_at_merge_ProteinSW(mat,starti,stopi,halfj,&halfj,dpenv); + follow_on_dc_ProteinSW(mat,starti,stopi,halfj,stopj,dpenv,perc_done); + return TRUE; +} + + +/* Function: push_dc_at_merge_ProteinSW(mat,starti,stopi,startj,stopj,dpenv) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: starti [UNKN ] Undocumented argument [int] + * Arg: stopi [UNKN ] Undocumented argument [int] + * Arg: startj [UNKN ] Undocumented argument [int] + * Arg: stopj [UNKN ] Undocumented argument [int *] + * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *] + * + */ +void push_dc_at_merge_ProteinSW(ProteinSW * mat,int starti,int stopi,int startj,int * stopj,DPEnvelope * dpenv) +{ + register int i; + register int j; + register int k; + register int count; + register int mergej;/* Sources below this j will be stamped by triples */ + register int score; + register int temp; + + + mergej = startj -1; + for(count=0,j=startj;count<1;count++,j++) { + for(i=starti;i<=stopi;i++) { + if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE ) { + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,MATCH) = NEGI; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,0) = (-100); + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,1) = (-100); + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,INSERT) = NEGI; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,0) = (-100); + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,1) = (-100); + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,DELETE) = NEGI; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,0) = (-100); + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,1) = (-100); + continue; + } /* end of Is not in envelope */ + + + /* For state MATCH, pushing when j - offj <= mergej */ + score = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH) + 0; + if( j - 1 <= mergej) { + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,0) = i-1; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,1) = j-1; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,2) = MATCH; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,3) = i; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,4) = j; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,5) = MATCH; + } + else { + for(k=0;k<7;k++) + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,k) = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH,k); + } + + + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-1,INSERT) + 0; + if( temp > score) { + score = temp; + + + if( j - 1 <= mergej) { + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,0) = i-1; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,1) = j-1; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,2) = INSERT; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,3) = i; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,4) = j; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,5) = MATCH; + } + else { + for(k=0;k<7;k++) + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,k) = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,INSERT,k); + } + } + + + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-1,DELETE) + 0; + if( temp > score) { + score = temp; + + + if( j - 1 <= mergej) { + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,0) = i-1; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,1) = j-1; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,2) = DELETE; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,3) = i; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,4) = j; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,5) = MATCH; + } + else { + for(k=0;k<7;k++) + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,k) = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,DELETE,k); + } + } + /* Add any movement independant score */ + score += CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j)); + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,MATCH) = score; + /* Finished with state MATCH */ + + + /* For state INSERT, pushing when j - offj <= mergej */ + score = ProteinSW_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH) + mat->gap; + if( j - 1 <= mergej) { + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,0) = i-0; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,1) = j-1; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,2) = MATCH; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,3) = i; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,4) = j; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,5) = INSERT; + } + else { + for(k=0;k<7;k++) + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,k) = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH,k); + } + + + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-0,j-1,INSERT) + mat->ext; + if( temp > score) { + score = temp; + + + if( j - 1 <= mergej) { + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,0) = i-0; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,1) = j-1; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,2) = INSERT; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,3) = i; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,4) = j; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,5) = INSERT; + } + else { + for(k=0;k<7;k++) + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,k) = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,INSERT,k); + } + } + /* Add any movement independant score */ + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,INSERT) = score; + /* Finished with state INSERT */ + + + /* For state DELETE, pushing when j - offj <= mergej */ + score = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH) + mat->gap; + if( j - 0 <= mergej) { + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,0) = i-1; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,1) = j-0; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,2) = MATCH; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,3) = i; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,4) = j; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,5) = DELETE; + } + else { + for(k=0;k<7;k++) + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,k) = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH,k); + } + + + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-0,DELETE) + mat->ext; + if( temp > score) { + score = temp; + + + if( j - 0 <= mergej) { + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,0) = i-1; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,1) = j-0; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,2) = DELETE; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,3) = i; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,4) = j; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,5) = DELETE; + } + else { + for(k=0;k<7;k++) + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,k) = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,DELETE,k); + } + } + /* Add any movement independant score */ + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,DELETE) = score; + /* Finished with state DELETE */ + } + } + /* Put back j into * stop j so that calling function gets it correct */ + if( stopj == NULL) + warn("Bad news... NULL stopj pointer in push dc function. This means that calling function does not know how many cells I have done!"); + else + *stopj = j; + + + return; +} + + +/* Function: follow_on_dc_ProteinSW(mat,starti,stopi,startj,stopj,dpenv,perc_done) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: starti [UNKN ] Undocumented argument [int] + * Arg: stopi [UNKN ] Undocumented argument [int] + * Arg: startj [UNKN ] Undocumented argument [int] + * Arg: stopj [UNKN ] Undocumented argument [int] + * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *] + * Arg: perc_done [UNKN ] Undocumented argument [int] + * + */ +void follow_on_dc_ProteinSW(ProteinSW * mat,int starti,int stopi,int startj,int stopj,DPEnvelope * dpenv,int perc_done) +{ + int i; + int j; + int k; + int score; + int temp; + int localshadow[7]; + long int total; + long int num; + + + total = (stopi - starti+1) * (stopj - startj+1); + num = 0; + + + for(j=startj;j<=stopj;j++) { + for(i=starti;i<=stopi;i++) { + num++; + if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE ) { + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,MATCH) = NEGI; + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,INSERT) = NEGI; + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,DELETE) = NEGI; + continue; + } /* end of Is not in envelope */ + if( num % 1000 == 0 ) + log_full_error(REPORT,0,"[%d%%%% done]After mid-j %5d Cells done %d%%%%",perc_done,startj,(num*100)/total); + + + /* For state MATCH */ + /* setting first movement to score */ + score = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH) + 0; + /* shift first shadow numbers */ + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH,k); + /* From state INSERT to state MATCH */ + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-1,INSERT) + 0; + if( temp > score ) { + score = temp; + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,INSERT,k); + } + /* From state DELETE to state MATCH */ + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-1,DELETE) + 0; + if( temp > score ) { + score = temp; + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,DELETE,k); + } + + + /* Ok - finished max calculation for MATCH */ + /* Add any movement independant score and put away */ + score += CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j)); + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,MATCH) = score; + for(k=0;k<7;k++) + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,k) = localshadow[k]; + /* Now figure out if any specials need this score */ + /* Finished calculating state MATCH */ + + + /* For state INSERT */ + /* setting first movement to score */ + score = ProteinSW_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH) + mat->gap; + /* shift first shadow numbers */ + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH,k); + /* From state INSERT to state INSERT */ + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-0,j-1,INSERT) + mat->ext; + if( temp > score ) { + score = temp; + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,INSERT,k); + } + + + /* Ok - finished max calculation for INSERT */ + /* Add any movement independant score and put away */ + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,INSERT) = score; + for(k=0;k<7;k++) + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,k) = localshadow[k]; + /* Now figure out if any specials need this score */ + /* Finished calculating state INSERT */ + + + /* For state DELETE */ + /* setting first movement to score */ + score = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH) + mat->gap; + /* shift first shadow numbers */ + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH,k); + /* From state DELETE to state DELETE */ + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-0,DELETE) + mat->ext; + if( temp > score ) { + score = temp; + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,DELETE,k); + } + + + /* Ok - finished max calculation for DELETE */ + /* Add any movement independant score and put away */ + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,DELETE) = score; + for(k=0;k<7;k++) + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,k) = localshadow[k]; + /* Now figure out if any specials need this score */ + /* Finished calculating state DELETE */ + } /* end of this is strip */ + } /* end of for each valid j column */ + + +/* Function: run_up_dc_ProteinSW(mat,starti,stopi,startj,stopj,dpenv,perc_done) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: starti [UNKN ] Undocumented argument [int] + * Arg: stopi [UNKN ] Undocumented argument [int] + * Arg: startj [UNKN ] Undocumented argument [int] + * Arg: stopj [UNKN ] Undocumented argument [int] + * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *] + * Arg: perc_done [UNKN ] Undocumented argument [int] + * + */ +} +void run_up_dc_ProteinSW(ProteinSW * mat,int starti,int stopi,int startj,int stopj,DPEnvelope * dpenv,int perc_done) +{ + register int i; + register int j; + register int score; + register int temp; + long int total; + long int num; + + + total = (stopi - starti+1) * (stopj - startj+1); + if( total <= 0 ) + total = 1; + num = 0; + + + for(j=startj;j<=stopj;j++) { + for(i=starti;i<=stopi;i++) { + if( j == startj && i == starti) + continue; + num++; + if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE ) { + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,MATCH) = NEGI; + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,INSERT) = NEGI; + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,DELETE) = NEGI; + continue; + } /* end of Is not in envelope */ + if( num % 1000 == 0 ) + log_full_error(REPORT,0,"[%d%%%% done]Before mid-j %5d Cells done %d%%%%",perc_done,stopj,(num*100)/total); + + + /* For state MATCH */ + /* setting first movement to score */ + score = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH) + 0; + /* From state INSERT to state MATCH */ + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-1,INSERT) + 0; + if( temp > score ) { + score = temp; + } + /* From state DELETE to state MATCH */ + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-1,DELETE) + 0; + if( temp > score ) { + score = temp; + } + + + /* Ok - finished max calculation for MATCH */ + /* Add any movement independant score and put away */ + score += CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j)); + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,MATCH) = score; + /* Finished calculating state MATCH */ + + + /* For state INSERT */ + /* setting first movement to score */ + score = ProteinSW_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH) + mat->gap; + /* From state INSERT to state INSERT */ + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-0,j-1,INSERT) + mat->ext; + if( temp > score ) { + score = temp; + } + + + /* Ok - finished max calculation for INSERT */ + /* Add any movement independant score and put away */ + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,INSERT) = score; + /* Finished calculating state INSERT */ + + + /* For state DELETE */ + /* setting first movement to score */ + score = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH) + mat->gap; + /* From state DELETE to state DELETE */ + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-0,DELETE) + mat->ext; + if( temp > score ) { + score = temp; + } + + + /* Ok - finished max calculation for DELETE */ + /* Add any movement independant score and put away */ + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,DELETE) = score; + /* Finished calculating state DELETE */ + } /* end of this is strip */ + } /* end of for each valid j column */ + + +/* Function: init_dc_ProteinSW(mat) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * + */ +} +void init_dc_ProteinSW(ProteinSW * mat) +{ + register int i; + register int j; + register int k; + + + for(j=0;j<3;j++) { + for(i=(-1);iquery->seq->len;i++) { + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,MATCH) = NEGI; + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,INSERT) = NEGI; + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,DELETE) = NEGI; + for(k=0;k<7;k++) { + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,k) = (-1); + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,k) = (-1); + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,k) = (-1); + } + } + } + + + return; +} + + +/* Function: dc_start_end_calculate_ProteinSW(mat,dpenv) + * + * Descrip: Calculates special strip, leaving start/end/score points in the shadow matrix + * One tricky thing is that we need to add score-independent calcs in the states + * As we have to evaluate them then. This is not ideally implemented therefore + * In fact it is *definitely* not ideal. Will have to do for now + * + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean dc_start_end_calculate_ProteinSW(ProteinSW * mat,DPEnvelope * dpenv) +{ + int i; + int j; + int k; + int score; + int temp; + int leni; + int lenj; + int localshadow[7]; + long int total; + long int num=0; + + + init_start_end_linear_ProteinSW(mat); + + + leni = mat->query->seq->len; + lenj = mat->target->seq->len; + total = leni * lenj; + + + for(j=0;jcomp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + /* shift first shadow numbers */ + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH,k); + /* From state INSERT to state MATCH */ + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-1,INSERT) + 0 +(CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + if( temp > score ) { + score = temp; + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,INSERT,k); + } + /* From state DELETE to state MATCH */ + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-1,DELETE) + 0 +(CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + if( temp > score ) { + score = temp; + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,DELETE,k); + } + /* From state START to state MATCH */ + temp = ProteinSW_DC_SHADOW_SPECIAL(mat,i-1,j-1,START) + 0 + (CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + if( temp > score ) { + score = temp; + /* This state [START] is a special for MATCH... push top shadow pointers here */ + localshadow[0]= i; + localshadow[1]= j; + localshadow[2]= MATCH; + localshadow[3]= (-1); + localshadow[4]= (-1); + localshadow[5]= (-1); + localshadow[6]= score; + } + + + /* Ok - finished max calculation for MATCH */ + /* Add any movement independant score and put away */ + /* Actually, already done inside scores */ + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,MATCH) = score; + for(k=0;k<7;k++) + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,k) = localshadow[k]; + /* Now figure out if any specials need this score */ + + + /* state MATCH is a source for special END */ + temp = score + (0) + (0) ; + if( temp > ProteinSW_DC_SHADOW_SPECIAL(mat,i,j,END) ) { + ProteinSW_DC_SHADOW_SPECIAL(mat,i,j,END) = temp; + /* Have to push only bottem half of system here */ + for(k=0;k<3;k++) + ProteinSW_DC_SHADOW_SPECIAL_SP(mat,i,j,END,k) = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,k); + ProteinSW_DC_SHADOW_SPECIAL_SP(mat,i,j,END,6) = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,6); + ProteinSW_DC_SHADOW_SPECIAL_SP(mat,i,j,END,3) = i; + ProteinSW_DC_SHADOW_SPECIAL_SP(mat,i,j,END,4) = j; + ProteinSW_DC_SHADOW_SPECIAL_SP(mat,i,j,END,5) = MATCH; + } + + + + + /* Finished calculating state MATCH */ + + + /* For state INSERT */ + /* setting first movement to score */ + score = ProteinSW_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH) + mat->gap + (0); + /* shift first shadow numbers */ + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH,k); + /* From state INSERT to state INSERT */ + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-0,j-1,INSERT) + mat->ext +(0); + if( temp > score ) { + score = temp; + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,INSERT,k); + } + + + /* Ok - finished max calculation for INSERT */ + /* Add any movement independant score and put away */ + /* Actually, already done inside scores */ + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,INSERT) = score; + for(k=0;k<7;k++) + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,k) = localshadow[k]; + /* Now figure out if any specials need this score */ + + + /* Finished calculating state INSERT */ + + + /* For state DELETE */ + /* setting first movement to score */ + score = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH) + mat->gap + (0); + /* shift first shadow numbers */ + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH,k); + /* From state DELETE to state DELETE */ + temp = ProteinSW_DC_SHADOW_MATRIX(mat,i-1,j-0,DELETE) + mat->ext +(0); + if( temp > score ) { + score = temp; + for(k=0;k<7;k++) + localshadow[k] = ProteinSW_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,DELETE,k); + } + + + /* Ok - finished max calculation for DELETE */ + /* Add any movement independant score and put away */ + /* Actually, already done inside scores */ + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,DELETE) = score; + for(k=0;k<7;k++) + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,k) = localshadow[k]; + /* Now figure out if any specials need this score */ + + + /* Finished calculating state DELETE */ + + + } /* end of for each i position in strip */ + } /* end of for each j strip */ + return TRUE; +} + + +/* Function: start_end_find_end_ProteinSW(mat,endj) + * + * Descrip: First function used to find end of the best path in the special state !end + * + * + * Arg: mat [UNKN ] Matrix in small mode [ProteinSW *] + * Arg: endj [WRITE] position of end in j (meaningless in i) [int *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int start_end_find_end_ProteinSW(ProteinSW * mat,int * endj) +{ + register int j; + register int max; + register int maxj; + + + max = ProteinSW_DC_SHADOW_SPECIAL(mat,0,mat->target->seq->len-1,END); + maxj = mat->target->seq->len-1; + for(j= mat->target->seq->len-2 ;j >= 0 ;j--) { + if( ProteinSW_DC_SHADOW_SPECIAL(mat,0,j,END) > max ) { + max = ProteinSW_DC_SHADOW_SPECIAL(mat,0,j,END); + maxj = j; + } + } + + + if( endj != NULL) + *endj = maxj; + + + return max; +} + + +/* Function: init_start_end_linear_ProteinSW(mat) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * + */ +void init_start_end_linear_ProteinSW(ProteinSW * mat) +{ + register int i; + register int j; + for(j=0;j<3;j++) { + for(i=(-1);iquery->seq->len;i++) { + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,MATCH) = NEGI; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,0) = (-1); + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,INSERT) = NEGI; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,0) = (-1); + ProteinSW_DC_SHADOW_MATRIX(mat,i,j,DELETE) = NEGI; + ProteinSW_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,0) = (-1); + } + } + + + for(j=(-1);jtarget->seq->len;j++) { + ProteinSW_DC_SHADOW_SPECIAL(mat,0,j,START) = 0; + ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,j,START,0) = j; + ProteinSW_DC_SHADOW_SPECIAL(mat,0,j,END) = NEGI; + ProteinSW_DC_SHADOW_SPECIAL_SP(mat,0,j,END,0) = (-1); + } + + + return; +} + + +/* Function: AlnRangeSet_from_PackAln_ProteinSW(pal) + * + * Descrip: Converts a PackAln (full alignment) to start/stop range + * The point being that you may have the PackAln and someone wants a range + * + * + * Arg: pal [UNKN ] Undocumented argument [PackAln *] + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * AlnRangeSet_from_PackAln_ProteinSW(PackAln * pal) +{ + int unit; + int cum_score = 0; + AlnRangeSet * out; + AlnRange * temp; + + + out = AlnRangeSet_alloc_std(); + for(unit = 0;unit < pal->len;unit++) { + cum_score += pal->pau[unit]->score; + if( pal->pau[unit]->state < 3) { + /* It is out of the specials */ + temp = AlnRange_alloc(); + temp->starti = pal->pau[unit]->i; + temp->startj = pal->pau[unit]->j; + temp->startstate = pal->pau[unit]->state; + temp->startscore = cum_score; + for(;unit < pal->len && pal->pau[unit]->state < 3;unit++) + cum_score += pal->pau[unit]->score; + temp->stopi = pal->pau[unit-1]->i; + temp->stopj = pal->pau[unit-1]->j; + temp->stopstate = pal->pau[unit-1]->state; + temp->stopscore = cum_score; + add_AlnRangeSet(out,temp); + } + } /* end of while there are more units */ + + + return out; +} + + +/* Function: convert_PackAln_to_AlnBlock_ProteinSW(pal) + * + * Descrip: Converts a path alignment to a label alignment + * The label alignment is probably much more useful than the path + * + * + * Arg: pal [UNKN ] Undocumented argument [PackAln *] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * convert_PackAln_to_AlnBlock_ProteinSW(PackAln * pal) +{ + AlnConvertSet * acs; + AlnBlock * alb; + + + acs = AlnConvertSet_ProteinSW(); + alb = AlnBlock_from_PackAln(acs,pal); + free_AlnConvertSet(acs); + return alb; +} + + + static char * query_label[] = { "SEQUENCE","INSERT","END" }; +/* Function: AlnConvertSet_ProteinSW(void) + * + * Descrip: No Description + * + * + * Return [UNKN ] Undocumented return value [AlnConvertSet *] + * + */ + static char * target_label[] = { "SEQUENCE","INSERT","END" }; +AlnConvertSet * AlnConvertSet_ProteinSW(void) +{ + AlnConvertUnit * acu; + AlnConvertSet * out; + + + out = AlnConvertSet_alloc_std(); + + + acu = AlnConvertUnit_alloc(); + add_AlnConvertSet(out,acu); + acu->state1 = MATCH; + acu->state2 = MATCH; + acu->offi = 1; + acu->offj = 1; + acu->label1 = query_label[0]; + acu->label2 = target_label[0]; + acu = AlnConvertUnit_alloc(); + add_AlnConvertSet(out,acu); + acu->state1 = INSERT; + acu->state2 = MATCH; + acu->offi = 1; + acu->offj = 1; + acu->label1 = query_label[0]; + acu->label2 = target_label[0]; + acu = AlnConvertUnit_alloc(); + add_AlnConvertSet(out,acu); + acu->state1 = DELETE; + acu->state2 = MATCH; + acu->offi = 1; + acu->offj = 1; + acu->label1 = query_label[0]; + acu->label2 = target_label[0]; + acu = AlnConvertUnit_alloc(); + add_AlnConvertSet(out,acu); + acu->state1 = START + 3; + acu->is_from_special = TRUE; + acu->state2 = MATCH; + acu->offi = (-1); + acu->offj = 1; + acu->label1 = query_label[0]; + acu->label2 = target_label[0]; + acu = AlnConvertUnit_alloc(); + add_AlnConvertSet(out,acu); + acu->state1 = MATCH; + acu->state2 = INSERT; + acu->offi = 0; + acu->offj = 1; + acu->label1 = query_label[1]; + acu->label2 = target_label[0]; + acu = AlnConvertUnit_alloc(); + add_AlnConvertSet(out,acu); + acu->state1 = INSERT; + acu->state2 = INSERT; + acu->offi = 0; + acu->offj = 1; + acu->label1 = query_label[1]; + acu->label2 = target_label[0]; + acu = AlnConvertUnit_alloc(); + add_AlnConvertSet(out,acu); + acu->state1 = MATCH; + acu->state2 = DELETE; + acu->offi = 1; + acu->offj = 0; + acu->label1 = query_label[0]; + acu->label2 = target_label[1]; + acu = AlnConvertUnit_alloc(); + add_AlnConvertSet(out,acu); + acu->state1 = DELETE; + acu->state2 = DELETE; + acu->offi = 1; + acu->offj = 0; + acu->label1 = query_label[0]; + acu->label2 = target_label[1]; + acu = AlnConvertUnit_alloc(); + add_AlnConvertSet(out,acu); + acu->state1 = MATCH; + acu->state2 = END + 3; + acu->offi = (-1); + acu->offj = 0; + acu->label1 = query_label[2]; + acu->label2 = target_label[2]; + return out; +} + + +/* Function: PackAln_read_Expl_ProteinSW(mat) + * + * Descrip: Reads off PackAln from explicit matrix structure + * + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * PackAln_read_Expl_ProteinSW(ProteinSW * mat) +{ + register PackAln * out; + int i; + int j; + int state; + int cellscore = (-1); + boolean isspecial; + PackAlnUnit * pau = NULL; + PackAlnUnit * prev = NULL; + + + if( mat->basematrix->type != BASEMATRIX_TYPE_EXPLICIT) { + warn("In ProteinSW_basic_read You have asked for an alignment from a non-explicit matrix: c'est impossible [current type is %d - %s]", mat->basematrix->type,basematrix_type_to_string(mat->basematrix->type)); + return NULL; + } + + + out = PackAln_alloc_std(); + if( out == NULL ) + return NULL; + + + out->score = find_end_ProteinSW(mat,&i,&j,&state,&isspecial); + + + /* Add final end transition (at the moment we have not got the score! */ + if( (pau= PackAlnUnit_alloc()) == NULL || add_PackAln(out,pau) == FALSE ) { + warn("Failed the first PackAlnUnit alloc, %d length of Alignment in ProteinSW_basic_read, returning a mess.(Sorry!)",out->len); + return out; + } + + + /* Put in positions for end trans. Remember that coordinates in C style */ + pau->i = i; + pau->j = j; + if( isspecial != TRUE) + pau->state = state; + else pau->state = state + 3; + prev=pau; + while( state != START || isspecial != TRUE) { + + + if( isspecial == TRUE ) + max_calc_special_ProteinSW(mat,i,j,state,isspecial,&i,&j,&state,&isspecial,&cellscore); + else + max_calc_ProteinSW(mat,i,j,state,isspecial,&i,&j,&state,&isspecial,&cellscore); + if(i == ProteinSW_READ_OFF_ERROR || j == ProteinSW_READ_OFF_ERROR || state == ProteinSW_READ_OFF_ERROR ) { + warn("Problem - hit bad read off system, exiting now"); + break; + } + if( (pau= PackAlnUnit_alloc()) == NULL || add_PackAln(out,pau) == FALSE ) { + warn("Failed a PackAlnUnit alloc, %d length of Alignment in ProteinSW_basic_read, returning partial alignment",out->len); + break; + } + + + /* Put in positions for block. Remember that coordinates in C style */ + pau->i = i; + pau->j = j; + if( isspecial != TRUE) + pau->state = state; + else pau->state = state + 3; + prev->score = cellscore; + prev = pau; + } /* end of while state != START */ + + + invert_PackAln(out); + return out; +} + + +/* Function: find_end_ProteinSW(mat,ri,rj,state,isspecial) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: ri [UNKN ] Undocumented argument [int *] + * Arg: rj [UNKN ] Undocumented argument [int *] + * Arg: state [UNKN ] Undocumented argument [int *] + * Arg: isspecial [UNKN ] Undocumented argument [boolean *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int find_end_ProteinSW(ProteinSW * mat,int * ri,int * rj,int * state,boolean * isspecial) +{ + register int j; + register int max; + register int maxj; + + + max = ProteinSW_EXPL_SPECIAL(mat,0,mat->target->seq->len-1,END); + maxj = mat->target->seq->len-1; + for(j= mat->target->seq->len-2 ;j >= 0 ;j--) { + if( ProteinSW_EXPL_SPECIAL(mat,0,j,END) > max ) { + max = ProteinSW_EXPL_SPECIAL(mat,0,j,END); + maxj = j; + } + } + + + if( ri != NULL) + *ri = 0; + if( rj != NULL) + *rj = maxj; + if( state != NULL) + *state = END; + if( isspecial != NULL) + *isspecial = TRUE; + + + return max; +} + + +/* Function: ProteinSW_debug_show_matrix(mat,starti,stopi,startj,stopj,ofp) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: starti [UNKN ] Undocumented argument [int] + * Arg: stopi [UNKN ] Undocumented argument [int] + * Arg: startj [UNKN ] Undocumented argument [int] + * Arg: stopj [UNKN ] Undocumented argument [int] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void ProteinSW_debug_show_matrix(ProteinSW * mat,int starti,int stopi,int startj,int stopj,FILE * ofp) +{ + register int i; + register int j; + + + for(i=starti;iquery->seq->len;i++) { + for(j=startj;jtarget->seq->len;j++) { + fprintf(ofp,"Cell [%d - %d]\n",i,j); + fprintf(ofp,"State MATCH %d\n",ProteinSW_EXPL_MATRIX(mat,i,j,MATCH)); + fprintf(ofp,"State INSERT %d\n",ProteinSW_EXPL_MATRIX(mat,i,j,INSERT)); + fprintf(ofp,"State DELETE %d\n",ProteinSW_EXPL_MATRIX(mat,i,j,DELETE)); + fprintf(ofp,"\n\n"); + } + } + + +} + + +/* Function: max_calc_ProteinSW(mat,i,j,state,isspecial,reti,retj,retstate,retspecial,cellscore) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: i [UNKN ] Undocumented argument [int] + * Arg: j [UNKN ] Undocumented argument [int] + * Arg: state [UNKN ] Undocumented argument [int] + * Arg: isspecial [UNKN ] Undocumented argument [boolean] + * Arg: reti [UNKN ] Undocumented argument [int *] + * Arg: retj [UNKN ] Undocumented argument [int *] + * Arg: retstate [UNKN ] Undocumented argument [int *] + * Arg: retspecial [UNKN ] Undocumented argument [boolean *] + * Arg: cellscore [UNKN ] Undocumented argument [int *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int max_calc_ProteinSW(ProteinSW * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore) +{ + register int temp; + register int cscore; + + + *reti = (*retj) = (*retstate) = ProteinSW_READ_OFF_ERROR; + + + if( i < 0 || j < 0 || i > mat->query->seq->len || j > mat->target->seq->len) { + warn("In ProteinSW matrix special read off - out of bounds on matrix [i,j is %d,%d state %d in standard matrix]",i,j,state); + return -1; + } + + + /* Then you have to select the correct switch statement to figure out the readoff */ + /* Somewhat odd - reverse the order of calculation and return as soon as it is correct */ + cscore = ProteinSW_EXPL_MATRIX(mat,i,j,state); + switch(state) { + case MATCH : + temp = cscore - (0) - (CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + if( temp == ProteinSW_EXPL_SPECIAL(mat,i - 1,j - 1,START) ) { + *reti = i - 1; + *retj = j - 1; + *retstate = START; + *retspecial = TRUE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_EXPL_SPECIAL(mat,i-1,j-1,START); + } + return ProteinSW_EXPL_MATRIX(mat,i - 1,j - 1,START); + } + temp = cscore - (0) - (CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + if( temp == ProteinSW_EXPL_MATRIX(mat,i - 1,j - 1,DELETE) ) { + *reti = i - 1; + *retj = j - 1; + *retstate = DELETE; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_EXPL_MATRIX(mat,i-1,j-1,DELETE); + } + return ProteinSW_EXPL_MATRIX(mat,i - 1,j - 1,DELETE); + } + temp = cscore - (0) - (CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + if( temp == ProteinSW_EXPL_MATRIX(mat,i - 1,j - 1,INSERT) ) { + *reti = i - 1; + *retj = j - 1; + *retstate = INSERT; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_EXPL_MATRIX(mat,i-1,j-1,INSERT); + } + return ProteinSW_EXPL_MATRIX(mat,i - 1,j - 1,INSERT); + } + temp = cscore - (0) - (CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j))); + if( temp == ProteinSW_EXPL_MATRIX(mat,i - 1,j - 1,MATCH) ) { + *reti = i - 1; + *retj = j - 1; + *retstate = MATCH; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_EXPL_MATRIX(mat,i-1,j-1,MATCH); + } + return ProteinSW_EXPL_MATRIX(mat,i - 1,j - 1,MATCH); + } + warn("Major problem (!) - in ProteinSW read off, position %d,%d state %d no source found!",i,j,state); + return (-1); + case INSERT : + temp = cscore - (mat->ext) - (0); + if( temp == ProteinSW_EXPL_MATRIX(mat,i - 0,j - 1,INSERT) ) { + *reti = i - 0; + *retj = j - 1; + *retstate = INSERT; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_EXPL_MATRIX(mat,i-0,j-1,INSERT); + } + return ProteinSW_EXPL_MATRIX(mat,i - 0,j - 1,INSERT); + } + temp = cscore - (mat->gap) - (0); + if( temp == ProteinSW_EXPL_MATRIX(mat,i - 0,j - 1,MATCH) ) { + *reti = i - 0; + *retj = j - 1; + *retstate = MATCH; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_EXPL_MATRIX(mat,i-0,j-1,MATCH); + } + return ProteinSW_EXPL_MATRIX(mat,i - 0,j - 1,MATCH); + } + warn("Major problem (!) - in ProteinSW read off, position %d,%d state %d no source found!",i,j,state); + return (-1); + case DELETE : + temp = cscore - (mat->ext) - (0); + if( temp == ProteinSW_EXPL_MATRIX(mat,i - 1,j - 0,DELETE) ) { + *reti = i - 1; + *retj = j - 0; + *retstate = DELETE; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_EXPL_MATRIX(mat,i-1,j-0,DELETE); + } + return ProteinSW_EXPL_MATRIX(mat,i - 1,j - 0,DELETE); + } + temp = cscore - (mat->gap) - (0); + if( temp == ProteinSW_EXPL_MATRIX(mat,i - 1,j - 0,MATCH) ) { + *reti = i - 1; + *retj = j - 0; + *retstate = MATCH; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_EXPL_MATRIX(mat,i-1,j-0,MATCH); + } + return ProteinSW_EXPL_MATRIX(mat,i - 1,j - 0,MATCH); + } + warn("Major problem (!) - in ProteinSW read off, position %d,%d state %d no source found!",i,j,state); + return (-1); + default: + warn("Major problem (!) - in ProteinSW read off, position %d,%d state %d no source found!",i,j,state); + return (-1); + } /* end of Switch state */ +} + + +/* Function: max_calc_special_ProteinSW(mat,i,j,state,isspecial,reti,retj,retstate,retspecial,cellscore) + * + * Descrip: No Description + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: i [UNKN ] Undocumented argument [int] + * Arg: j [UNKN ] Undocumented argument [int] + * Arg: state [UNKN ] Undocumented argument [int] + * Arg: isspecial [UNKN ] Undocumented argument [boolean] + * Arg: reti [UNKN ] Undocumented argument [int *] + * Arg: retj [UNKN ] Undocumented argument [int *] + * Arg: retstate [UNKN ] Undocumented argument [int *] + * Arg: retspecial [UNKN ] Undocumented argument [boolean *] + * Arg: cellscore [UNKN ] Undocumented argument [int *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int max_calc_special_ProteinSW(ProteinSW * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore) +{ + register int temp; + register int cscore; + + + *reti = (*retj) = (*retstate) = ProteinSW_READ_OFF_ERROR; + + + if( j < 0 || j > mat->target->seq->len) { + warn("In ProteinSW matrix special read off - out of bounds on matrix [j is %d in special]",j); + return -1; + } + + + cscore = ProteinSW_EXPL_SPECIAL(mat,i,j,state); + switch(state) { + case START : + case END : + /* source MATCH is from main matrix */ + for(i= mat->query->seq->len-1;i >= 0 ;i--) { + temp = cscore - (0) - (0); + if( temp == ProteinSW_EXPL_MATRIX(mat,i - 0,j - 0,MATCH) ) { + *reti = i - 0; + *retj = j - 0; + *retstate = MATCH; + *retspecial = FALSE; + if( cellscore != NULL) { + *cellscore = cscore - ProteinSW_EXPL_MATRIX(mat,i-0,j-0,MATCH); + } + return ProteinSW_EXPL_MATRIX(mat,i - 0,j - 0,MATCH) ; + } + } /* end of for i >= 0 */ + default: + warn("Major problem (!) - in ProteinSW read off, position %d,%d state %d no source found dropped into default on source switch!",i,j,state); + return (-1); + } /* end of switch on special states */ +} + + +/* Function: calculate_ProteinSW(mat) + * + * Descrip: This function calculates the ProteinSW matrix when in explicit mode + * To allocate the matrix use /allocate_Expl_ProteinSW + * + * + * Arg: mat [UNKN ] ProteinSW which contains explicit basematrix memory [ProteinSW *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean calculate_ProteinSW(ProteinSW * mat) +{ + int i; + int j; + int leni; + int lenj; + int tot; + int num; + + + if( mat->basematrix->type != BASEMATRIX_TYPE_EXPLICIT ) { + warn("in calculate_ProteinSW, passed a non Explicit matrix type, cannot calculate!"); + return FALSE; + } + + + leni = mat->leni; + lenj = mat->lenj; + tot = leni * lenj; + num = 0; + + + start_reporting("ProteinSW Matrix calculation: "); + for(j=0;j score ) { + score = temp; + } + /* From state DELETE to state MATCH */ + temp = ProteinSW_EXPL_MATRIX(mat,i-1,j-1,DELETE) + 0; + if( temp > score ) { + score = temp; + } + /* From state START to state MATCH */ + temp = ProteinSW_EXPL_SPECIAL(mat,i-1,j-1,START) + 0; + if( temp > score ) { + score = temp; + } + + + /* Ok - finished max calculation for MATCH */ + /* Add any movement independant score and put away */ + score += CompMat_AAMATCH(mat->comp,CSEQ_PROTEIN_AMINOACID(mat->query,i),CSEQ_PROTEIN_AMINOACID(mat->target,j)); + ProteinSW_EXPL_MATRIX(mat,i,j,MATCH) = score; + + + /* state MATCH is a source for special END */ + temp = score + (0) + (0) ; + if( temp > ProteinSW_EXPL_SPECIAL(mat,i,j,END) ) { + ProteinSW_EXPL_SPECIAL(mat,i,j,END) = temp; + } + + + + + /* Finished calculating state MATCH */ + + + /* For state INSERT */ + /* setting first movement to score */ + score = ProteinSW_EXPL_MATRIX(mat,i-0,j-1,MATCH) + mat->gap; + /* From state INSERT to state INSERT */ + temp = ProteinSW_EXPL_MATRIX(mat,i-0,j-1,INSERT) + mat->ext; + if( temp > score ) { + score = temp; + } + + + /* Ok - finished max calculation for INSERT */ + /* Add any movement independant score and put away */ + ProteinSW_EXPL_MATRIX(mat,i,j,INSERT) = score; + + + /* Finished calculating state INSERT */ + + + /* For state DELETE */ + /* setting first movement to score */ + score = ProteinSW_EXPL_MATRIX(mat,i-1,j-0,MATCH) + mat->gap; + /* From state DELETE to state DELETE */ + temp = ProteinSW_EXPL_MATRIX(mat,i-1,j-0,DELETE) + mat->ext; + if( temp > score ) { + score = temp; + } + + + /* Ok - finished max calculation for DELETE */ + /* Add any movement independant score and put away */ + ProteinSW_EXPL_MATRIX(mat,i,j,DELETE) = score; + + + /* Finished calculating state DELETE */ + } + + + /* Special state START has no special to special movements */ + + + /* Special state END has no special to special movements */ + } + stop_reporting(); + return TRUE; +} + + +/* Function: ProteinSW_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ProteinSW *] + * + */ +ProteinSW * ProteinSW_alloc(void) +{ + ProteinSW * out;/* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(ProteinSW *) ckalloc (sizeof(ProteinSW))) == NULL) { + warn("ProteinSW_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->basematrix = NULL; + out->leni = 0; + out->lenj = 0; + + + return out; +} + + +/* Function: free_ProteinSW(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ProteinSW *] + * + * Return [UNKN ] Undocumented return value [ProteinSW *] + * + */ +ProteinSW * free_ProteinSW(ProteinSW * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a ProteinSW obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->basematrix != NULL) + free_BaseMatrix(obj->basematrix); + /* obj->query is linked in */ + /* obj->target is linked in */ + /* obj->comp is linked in */ + /* obj->gap is linked in */ + /* obj->ext is linked in */ + + + ckfree(obj); + return NULL; +} + + + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/proteinsw.h b/Bio/Ext/Align/libs/proteinsw.h new file mode 100644 index 0000000..370bd36 --- /dev/null +++ b/Bio/Ext/Align/libs/proteinsw.h @@ -0,0 +1,343 @@ +#ifndef DYNAMITEproteinswHEADERFILE +#define DYNAMITEproteinswHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "dyna.h" + +struct bp_sw_ProteinSW { + int dynamite_hard_link; + BaseMatrix * basematrix; + int leni; + int lenj; + ComplexSequence* query; + ComplexSequence* target; + CompMat* comp; + int gap; + int ext; + } ; +/* ProteinSW defined */ +#ifndef DYNAMITE_DEFINED_ProteinSW +typedef struct bp_sw_ProteinSW bp_sw_ProteinSW; +#define ProteinSW bp_sw_ProteinSW +#define DYNAMITE_DEFINED_ProteinSW +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: search_ProteinSW(out,querydb,targetdb,comp,gap,ext) + * + * Descrip: This function makes a database search of ProteinSW + * + * + * Arg: out [UNKN ] Undocumented argument [Hscore *] + * Arg: querydb [UNKN ] Undocumented argument [ProteinDB*] + * Arg: targetdb [UNKN ] Undocumented argument [ProteinDB*] + * Arg: comp [UNKN ] Undocumented argument [CompMat*] + * Arg: gap [UNKN ] Undocumented argument [int] + * Arg: ext [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [Search_Return_Type] + * + */ +Search_Return_Type bp_sw_search_ProteinSW(Hscore * out,ProteinDB* querydb,ProteinDB* targetdb ,CompMat* comp,int gap,int ext); +#define search_ProteinSW bp_sw_search_ProteinSW + + +/* Function: PackAln_bestmemory_ProteinSW(query,target,comp,gap,ext,dpenv) + * + * Descrip: This function chooses the best memory set-up for the alignment + * using calls to basematrix, and then implements either a large + * or small memory model. + * + * It is the best function to use if you just want an alignment + * + * If you want a label alignment, you will need + * /convert_PackAln_to_AlnBlock_ProteinSW + * + * + * Arg: query [UNKN ] query data structure [ComplexSequence*] + * Arg: target [UNKN ] target data structure [ComplexSequence*] + * Arg: comp [UNKN ] Resource [CompMat*] + * Arg: gap [UNKN ] Resource [int] + * Arg: ext [UNKN ] Resource [int] + * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * bp_sw_PackAln_bestmemory_ProteinSW(ComplexSequence* query,ComplexSequence* target ,CompMat* comp,int gap,int ext,DPEnvelope * dpenv); +#define PackAln_bestmemory_ProteinSW bp_sw_PackAln_bestmemory_ProteinSW + + +/* Function: allocate_Expl_ProteinSW(query,target,comp,gap,ext) + * + * Descrip: This function allocates the ProteinSW structure + * and the basematrix area for explicit memory implementations + * It calls /allocate_ProteinSW_only + * + * + * Arg: query [UNKN ] query data structure [ComplexSequence*] + * Arg: target [UNKN ] target data structure [ComplexSequence*] + * Arg: comp [UNKN ] Resource [CompMat*] + * Arg: gap [UNKN ] Resource [int] + * Arg: ext [UNKN ] Resource [int] + * + * Return [UNKN ] Undocumented return value [ProteinSW *] + * + */ +ProteinSW * bp_sw_allocate_Expl_ProteinSW(ComplexSequence* query,ComplexSequence* target ,CompMat* comp,int gap,int ext); +#define allocate_Expl_ProteinSW bp_sw_allocate_Expl_ProteinSW + + +/* Function: recalculate_PackAln_ProteinSW(pal,mat) + * + * Descrip: This function recalculates the PackAln structure produced by ProteinSW + * For example, in linear space methods this is used to score them + * + * + * Arg: pal [UNKN ] Undocumented argument [PackAln *] + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * + */ +void bp_sw_recalculate_PackAln_ProteinSW(PackAln * pal,ProteinSW * mat); +#define recalculate_PackAln_ProteinSW bp_sw_recalculate_PackAln_ProteinSW + + +/* Function: allocate_Small_ProteinSW(query,target,comp,gap,ext) + * + * Descrip: This function allocates the ProteinSW structure + * and the basematrix area for a small memory implementations + * It calls /allocate_ProteinSW_only + * + * + * Arg: query [UNKN ] query data structure [ComplexSequence*] + * Arg: target [UNKN ] target data structure [ComplexSequence*] + * Arg: comp [UNKN ] Resource [CompMat*] + * Arg: gap [UNKN ] Resource [int] + * Arg: ext [UNKN ] Resource [int] + * + * Return [UNKN ] Undocumented return value [ProteinSW *] + * + */ +ProteinSW * bp_sw_allocate_Small_ProteinSW(ComplexSequence* query,ComplexSequence* target ,CompMat* comp,int gap,int ext); +#define allocate_Small_ProteinSW bp_sw_allocate_Small_ProteinSW + + +/* Function: PackAln_calculate_Small_ProteinSW(mat,dpenv) + * + * Descrip: This function calculates an alignment for ProteinSW structure in linear space + * If you want only the start/end points + * use /AlnRangeSet_calculate_Small_ProteinSW + * + * The function basically + * finds start/end points + * foreach start/end point + * calls /full_dc_ProteinSW + * + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *] + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * bp_sw_PackAln_calculate_Small_ProteinSW(ProteinSW * mat,DPEnvelope * dpenv); +#define PackAln_calculate_Small_ProteinSW bp_sw_PackAln_calculate_Small_ProteinSW + + +/* Function: AlnRangeSet_calculate_Small_ProteinSW(mat) + * + * Descrip: This function calculates an alignment for ProteinSW structure in linear space + * If you want the full alignment, use /PackAln_calculate_Small_ProteinSW + * If you have already got the full alignment, but want the range set, use /AlnRangeSet_from_PackAln_ProteinSW + * If you have got the small matrix but not the alignment, use /AlnRangeSet_from_ProteinSW + * + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * bp_sw_AlnRangeSet_calculate_Small_ProteinSW(ProteinSW * mat); +#define AlnRangeSet_calculate_Small_ProteinSW bp_sw_AlnRangeSet_calculate_Small_ProteinSW + + +/* Function: AlnRangeSet_from_ProteinSW(mat) + * + * Descrip: This function reads off a start/end structure + * for ProteinSW structure in linear space + * If you want the full alignment use + * /PackAln_calculate_Small_ProteinSW + * If you have not calculated the matrix use + * /AlnRange_calculate_Small_ProteinSW + * + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * bp_sw_AlnRangeSet_from_ProteinSW(ProteinSW * mat); +#define AlnRangeSet_from_ProteinSW bp_sw_AlnRangeSet_from_ProteinSW + + +/* Function: AlnRangeSet_from_PackAln_ProteinSW(pal) + * + * Descrip: Converts a PackAln (full alignment) to start/stop range + * The point being that you may have the PackAln and someone wants a range + * + * + * Arg: pal [UNKN ] Undocumented argument [PackAln *] + * + * Return [UNKN ] Undocumented return value [AlnRangeSet *] + * + */ +AlnRangeSet * bp_sw_AlnRangeSet_from_PackAln_ProteinSW(PackAln * pal); +#define AlnRangeSet_from_PackAln_ProteinSW bp_sw_AlnRangeSet_from_PackAln_ProteinSW + + +/* Function: convert_PackAln_to_AlnBlock_ProteinSW(pal) + * + * Descrip: Converts a path alignment to a label alignment + * The label alignment is probably much more useful than the path + * + * + * Arg: pal [UNKN ] Undocumented argument [PackAln *] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * bp_sw_convert_PackAln_to_AlnBlock_ProteinSW(PackAln * pal); +#define convert_PackAln_to_AlnBlock_ProteinSW bp_sw_convert_PackAln_to_AlnBlock_ProteinSW + + +/* Function: PackAln_read_Expl_ProteinSW(mat) + * + * Descrip: Reads off PackAln from explicit matrix structure + * + * + * Arg: mat [UNKN ] Undocumented argument [ProteinSW *] + * + * Return [UNKN ] Undocumented return value [PackAln *] + * + */ +PackAln * bp_sw_PackAln_read_Expl_ProteinSW(ProteinSW * mat); +#define PackAln_read_Expl_ProteinSW bp_sw_PackAln_read_Expl_ProteinSW + + +/* Function: calculate_ProteinSW(mat) + * + * Descrip: This function calculates the ProteinSW matrix when in explicit mode + * To allocate the matrix use /allocate_Expl_ProteinSW + * + * + * Arg: mat [UNKN ] ProteinSW which contains explicit basematrix memory [ProteinSW *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_calculate_ProteinSW(ProteinSW * mat); +#define calculate_ProteinSW bp_sw_calculate_ProteinSW + + +/* Function: ProteinSW_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [ProteinSW *] + * + */ +ProteinSW * bp_sw_ProteinSW_alloc(void); +#define ProteinSW_alloc bp_sw_ProteinSW_alloc + + +/* Function: free_ProteinSW(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [ProteinSW *] + * + * Return [UNKN ] Undocumented return value [ProteinSW *] + * + */ +ProteinSW * bp_sw_free_ProteinSW(ProteinSW * obj); +#define free_ProteinSW bp_sw_free_ProteinSW + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +int bp_sw_score_only_ProteinSW(ComplexSequence* query,ComplexSequence* target ,CompMat* comp,int gap,int ext); +#define score_only_ProteinSW bp_sw_score_only_ProteinSW +ProteinSW * bp_sw_allocate_ProteinSW_only(ComplexSequence* query,ComplexSequence* target ,CompMat* comp,int gap,int ext); +#define allocate_ProteinSW_only bp_sw_allocate_ProteinSW_only +void bp_sw_init_ProteinSW(ProteinSW * mat); +#define init_ProteinSW bp_sw_init_ProteinSW +AlnRange * bp_sw_AlnRange_build_ProteinSW(ProteinSW * mat,int stopj,int stopspecstate,int * startj,int * startspecstate); +#define AlnRange_build_ProteinSW bp_sw_AlnRange_build_ProteinSW +boolean bp_sw_read_hidden_ProteinSW(ProteinSW * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,PackAln * out); +#define read_hidden_ProteinSW bp_sw_read_hidden_ProteinSW +int bp_sw_max_hidden_ProteinSW(ProteinSW * mat,int hiddenj,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore); +#define max_hidden_ProteinSW bp_sw_max_hidden_ProteinSW +boolean bp_sw_read_special_strip_ProteinSW(ProteinSW * mat,int stopi,int stopj,int stopstate,int * startj,int * startstate,PackAln * out); +#define read_special_strip_ProteinSW bp_sw_read_special_strip_ProteinSW +int bp_sw_max_special_strip_ProteinSW(ProteinSW * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore); +#define max_special_strip_ProteinSW bp_sw_max_special_strip_ProteinSW +int bp_sw_max_matrix_to_special_ProteinSW(ProteinSW * mat,int i,int j,int state,int cscore,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore); +#define max_matrix_to_special_ProteinSW bp_sw_max_matrix_to_special_ProteinSW +void bp_sw_calculate_hidden_ProteinSW(ProteinSW * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,DPEnvelope * dpenv); +#define calculate_hidden_ProteinSW bp_sw_calculate_hidden_ProteinSW +void bp_sw_init_hidden_ProteinSW(ProteinSW * mat,int starti,int startj,int stopi,int stopj); +#define init_hidden_ProteinSW bp_sw_init_hidden_ProteinSW +boolean bp_sw_full_dc_ProteinSW(ProteinSW * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,PackAln * out,int * donej,int totalj,DPEnvelope * dpenv); +#define full_dc_ProteinSW bp_sw_full_dc_ProteinSW +boolean bp_sw_do_dc_single_pass_ProteinSW(ProteinSW * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,DPEnvelope * dpenv,int perc_done); +#define do_dc_single_pass_ProteinSW bp_sw_do_dc_single_pass_ProteinSW +void bp_sw_push_dc_at_merge_ProteinSW(ProteinSW * mat,int starti,int stopi,int startj,int * stopj,DPEnvelope * dpenv); +#define push_dc_at_merge_ProteinSW bp_sw_push_dc_at_merge_ProteinSW +void bp_sw_follow_on_dc_ProteinSW(ProteinSW * mat,int starti,int stopi,int startj,int stopj,DPEnvelope * dpenv,int perc_done); +#define follow_on_dc_ProteinSW bp_sw_follow_on_dc_ProteinSW +void bp_sw_run_up_dc_ProteinSW(ProteinSW * mat,int starti,int stopi,int startj,int stopj,DPEnvelope * dpenv,int perc_done); +#define run_up_dc_ProteinSW bp_sw_run_up_dc_ProteinSW +void bp_sw_init_dc_ProteinSW(ProteinSW * mat); +#define init_dc_ProteinSW bp_sw_init_dc_ProteinSW +boolean bp_sw_dc_start_end_calculate_ProteinSW(ProteinSW * mat,DPEnvelope * dpenv); +#define dc_start_end_calculate_ProteinSW bp_sw_dc_start_end_calculate_ProteinSW +int bp_sw_start_end_find_end_ProteinSW(ProteinSW * mat,int * endj); +#define start_end_find_end_ProteinSW bp_sw_start_end_find_end_ProteinSW +void bp_sw_init_start_end_linear_ProteinSW(ProteinSW * mat); +#define init_start_end_linear_ProteinSW bp_sw_init_start_end_linear_ProteinSW +AlnConvertSet * bp_sw_AlnConvertSet_ProteinSW(void); +#define AlnConvertSet_ProteinSW bp_sw_AlnConvertSet_ProteinSW +int bp_sw_find_end_ProteinSW(ProteinSW * mat,int * ri,int * rj,int * state,boolean * isspecial); +#define find_end_ProteinSW bp_sw_find_end_ProteinSW +void bp_sw_ProteinSW_debug_show_matrix(ProteinSW * mat,int starti,int stopi,int startj,int stopj,FILE * ofp); +#define ProteinSW_debug_show_matrix bp_sw_ProteinSW_debug_show_matrix +int bp_sw_max_calc_ProteinSW(ProteinSW * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore); +#define max_calc_ProteinSW bp_sw_max_calc_ProteinSW +int bp_sw_max_calc_special_ProteinSW(ProteinSW * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore); +#define max_calc_special_ProteinSW bp_sw_max_calc_special_ProteinSW + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/seqaligndisplay.c b/Bio/Ext/Align/libs/seqaligndisplay.c new file mode 100644 index 0000000..6950501 --- /dev/null +++ b/Bio/Ext/Align/libs/seqaligndisplay.c @@ -0,0 +1,277 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "seqaligndisplay.h" + +/* Function: write_pretty_Protein_align(alb,q,t,name,main,ofp) + * + * Descrip: This gives an interface into the + * alignment display using Protein + * objects + * + * + * Arg: alb [UNKN ] alignment structure [AlnBlock *] + * Arg: q [UNKN ] first sequence [Protein *] + * Arg: t [UNKN ] second sequence [Protein *] + * Arg: name [UNKN ] length of the name block [int] + * Arg: main [UNKN ] length of the main block [int] + * Arg: ofp [UNKN ] output file [FILE *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 30 "seqaligndisplay.dy" +boolean write_pretty_Protein_align(AlnBlock * alb,Protein * q,Protein * t,int name,int main,FILE * ofp) +{ + if( alb == NULL || q == NULL || t == NULL ) { + warn("NULL objects being passed into write_pretty_Protein_align"); + return FALSE; + } + return write_pretty_seq_align(alb,q->baseseq,t->baseseq,name,main,ofp); +} + + + +/* Function: write_pretty_seq_align(alb,q,t,name,main,ofp) + * + * Descrip: This gives an interface into the alignment + * display using sequences and files. A more + * generic function is write_pretty_str_align + * + * + * Arg: alb [UNKN ] alignment structure [AlnBlock *] + * Arg: q [UNKN ] first sequence [Sequence *] + * Arg: t [UNKN ] second sequence [Sequence *] + * Arg: name [UNKN ] length of the name block [int] + * Arg: main [UNKN ] length of the main block [int] + * Arg: ofp [UNKN ] output file [FILE *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 53 "seqaligndisplay.dy" +boolean write_pretty_seq_align(AlnBlock * alb,Sequence * q,Sequence * t,int name,int main,FILE * ofp) +{ + char qname[64]; + char tname[64]; + btCanvas * btc; + char * temp; + + if( alb == NULL || q == NULL || t == NULL ) { + warn("NULL objects being passed into write_pretty_seq_align"); + return FALSE; + } + + if( name > 64 ) { + warn("Sorry - hard coded limited, can't have names longer than 64"); + return FALSE; + } + + + if( strlen(q->name) > name ) { + warn("Name %s is longer than allowed name block (%d). Truncating\n",q->name,name); + strncpy(qname,q->name,name); + qname[name] = '\0'; + } else { + strcpy(qname,q->name); + } + + if( strlen(t->name) > name ) { + warn("Name %s is longer than allowed name block (%d). Truncating\n",t->name,name); + strncpy(tname,t->name,name); + tname[name] = '\0'; + } else { + strcpy(tname,t->name); + } + + btc = new_Ascii_btCanvas(ofp,name+6,main,0,3); /*+6 in case we want to put in numbers */ + + write_pretty_str_align_btc(alb,qname,q->seq,tname,t->seq,btc); + + /** destroy btc canvas **/ + + free_btCanvas(btc); + + return TRUE; +} + + +/* Function: write_pretty_str_align(alb,qname,query,tname,target,name,main,ofp) + * + * Descrip: This gives an interface into the alignment + * display using strings and files. + * + * + * Arg: alb [UNKN ] alignment structure [AlnBlock *] + * Arg: qname [UNKN ] name of first sequence [char *] + * Arg: query [UNKN ] first sequence [char *] + * Arg: tname [UNKN ] name of second sequence [char *] + * Arg: target [UNKN ] second sequence [char *] + * Arg: name [UNKN ] length of the name block [int] + * Arg: main [UNKN ] length of the main block [int] + * Arg: ofp [UNKN ] output file [FILE *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 112 "seqaligndisplay.dy" +boolean write_pretty_str_align(AlnBlock * alb,char * qname,char * query,char * tname,char * target,int name,int main,FILE * ofp) +{ + boolean out; + btCanvas * btc; + + btc = new_Ascii_btCanvas(ofp,name+6,main,0,3); /*+6 in case we want to put in numbers */ + + out = write_pretty_str_align_btc(alb,qname,query,tname,target,btc); + + /** destroy btc canvas **/ + + free_btCanvas(btc); + + return out; +} + +/* Function: write_pretty_str_align_btc(alb,qname,query,tname,target,btc) + * + * Descrip: This function writes precisely + * what you expect for a a simple alignment. + * + * We can reuse this routine all over the place because + * we dont use any hard coded structure for the + * query or the target sequence letters. ... but crap + * type checking it has to be said! + * + * Also we use a generic btCanvas that could have + * any implementation underneath (eg, ASCII, postscript etc). + * + * + * Arg: alb [UNKN ] Undocumented argument [AlnBlock *] + * Arg: qname [UNKN ] Undocumented argument [char *] + * Arg: query [UNKN ] Undocumented argument [char *] + * Arg: tname [UNKN ] Undocumented argument [char *] + * Arg: target [UNKN ] Undocumented argument [char *] + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 140 "seqaligndisplay.dy" +boolean write_pretty_str_align_btc(AlnBlock * alb,char * qname,char * query,char * tname,char * target,btCanvas * btc) +{ + AlnColumn * alc; + AlnUnit * q; + AlnUnit * t; + char buffer[14]; + + btPasteArea * btp; + + for(alc=alb->start;alc != NULL;) { + + /** put names in **/ + + btp = get_reserved_left_btCanvas(btc); + paste_string_btPasteArea(btp,0,0,qname,BC_RIGHT,0); + paste_string_btPasteArea(btp,0,2,tname,BC_RIGHT,0); + + sprintf(buffer,"%d",alc->alu[0]->start+1+1); + + paste_string_btPasteArea(btp,12,0,buffer,BC_RIGHT,0); + + sprintf(buffer,"%d",alc->alu[1]->start+1+1); + + paste_string_btPasteArea(btp,12,2,buffer,BC_RIGHT,0); + + free_btPasteArea(btp); + /** now loop over this block **/ + + for(;alc != NULL && can_get_paste_area_btCanvas(btc,1) == TRUE;alc=alc->next) { + + q = alc->alu[0]; + t = alc->alu[1]; + + /* + * at the end, break + */ + if( strcmp(q->text_label,"END") == 0 ) { + alc = NULL; + break; + } + + /* + * Get the paste area, length 1, depth will be 3 + */ + + btp = get_paste_area_btCanvas(btc,1); + + /* + * Write in the query sequence + * + */ + + if( strcmp(q->text_label,"SEQUENCE") == 0 ) { + paste_char_btPasteArea(btp,0,0,toupper(query[q->start+1]),0); + } else if( strcmp(q->text_label,"UNMATCHED_SEQUENCE") == 0 ) { + paste_char_btPasteArea(btp,0,0,tolower(query[q->start+1]),0); + } else { + /** is insert- we could check **/ + if( strcmp(q->text_label,"INSERT") != 0 ) { + warn("Got an uninterpretable label, %s",q->text_label); + paste_char_btPasteArea(btp,0,0,'?',0); + } else { + paste_char_btPasteArea(btp,0,0,'-',0); + } + } + + /* + * Write in the target sequence + * + */ + + if( strcmp(t->text_label,"SEQUENCE") == 0 ) { + paste_char_btPasteArea(btp,0,2,toupper(target[t->start+1]),0); + } else if( strcmp(t->text_label,"UNMATCHED_SEQUENCE") == 0 ) { + paste_char_btPasteArea(btp,0,2,tolower(target[t->start+1]),0); + } else { + /** is insert- we could check **/ + if( strcmp(t->text_label,"INSERT") != 0 ) { + warn("Got an uninterpretable label, %s",t->text_label); + paste_char_btPasteArea(btp,0,2,'?',0); + } else { + paste_char_btPasteArea(btp,0,2,'-',0); + } + } + + /* + * Match line + */ + + + + if( strcmp(q->text_label,"SEQUENCE") == 0 && strcmp(t->text_label,"SEQUENCE") == 0 ) { + if( q->score[0] > 0 ) { + if( query[q->start+1] == target[t->start+1] ) { + paste_char_btPasteArea(btp,0,1,target[t->start+1],0); + } else { + paste_char_btPasteArea(btp,0,1,'+',0); + } + } + } else + paste_char_btPasteArea(btp,0,1,' ',0); + + free_btPasteArea(btp); + + } /* end of for this block */ + + advance_line_btCanvas(btc); + } /* end of for the alignment */ + + return TRUE; /* we never returned false. Ooops! */ +} + + + +# line 264 "seqaligndisplay.c" + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/seqaligndisplay.h b/Bio/Ext/Align/libs/seqaligndisplay.h new file mode 100644 index 0000000..bcd4ce4 --- /dev/null +++ b/Bio/Ext/Align/libs/seqaligndisplay.h @@ -0,0 +1,123 @@ +#ifndef DYNAMITEseqaligndisplayHEADERFILE +#define DYNAMITEseqaligndisplayHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "dyna.h" + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: write_pretty_Protein_align(alb,q,t,name,main,ofp) + * + * Descrip: This gives an interface into the + * alignment display using Protein + * objects + * + * + * Arg: alb [UNKN ] alignment structure [AlnBlock *] + * Arg: q [UNKN ] first sequence [Protein *] + * Arg: t [UNKN ] second sequence [Protein *] + * Arg: name [UNKN ] length of the name block [int] + * Arg: main [UNKN ] length of the main block [int] + * Arg: ofp [UNKN ] output file [FILE *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_write_pretty_Protein_align(AlnBlock * alb,Protein * q,Protein * t,int name,int main,FILE * ofp); +#define write_pretty_Protein_align bp_sw_write_pretty_Protein_align + + +/* Function: write_pretty_seq_align(alb,q,t,name,main,ofp) + * + * Descrip: This gives an interface into the alignment + * display using sequences and files. A more + * generic function is write_pretty_str_align + * + * + * Arg: alb [UNKN ] alignment structure [AlnBlock *] + * Arg: q [UNKN ] first sequence [Sequence *] + * Arg: t [UNKN ] second sequence [Sequence *] + * Arg: name [UNKN ] length of the name block [int] + * Arg: main [UNKN ] length of the main block [int] + * Arg: ofp [UNKN ] output file [FILE *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_write_pretty_seq_align(AlnBlock * alb,Sequence * q,Sequence * t,int name,int main,FILE * ofp); +#define write_pretty_seq_align bp_sw_write_pretty_seq_align + + +/* Function: write_pretty_str_align(alb,qname,query,tname,target,name,main,ofp) + * + * Descrip: This gives an interface into the alignment + * display using strings and files. + * + * + * Arg: alb [UNKN ] alignment structure [AlnBlock *] + * Arg: qname [UNKN ] name of first sequence [char *] + * Arg: query [UNKN ] first sequence [char *] + * Arg: tname [UNKN ] name of second sequence [char *] + * Arg: target [UNKN ] second sequence [char *] + * Arg: name [UNKN ] length of the name block [int] + * Arg: main [UNKN ] length of the main block [int] + * Arg: ofp [UNKN ] output file [FILE *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_write_pretty_str_align(AlnBlock * alb,char * qname,char * query,char * tname,char * target,int name,int main,FILE * ofp); +#define write_pretty_str_align bp_sw_write_pretty_str_align + + +/* Function: write_pretty_str_align_btc(alb,qname,query,tname,target,btc) + * + * Descrip: This function writes precisely + * what you expect for a a simple alignment. + * + * We can reuse this routine all over the place because + * we dont use any hard coded structure for the + * query or the target sequence letters. ... but crap + * type checking it has to be said! + * + * Also we use a generic btCanvas that could have + * any implementation underneath (eg, ASCII, postscript etc). + * + * + * Arg: alb [UNKN ] Undocumented argument [AlnBlock *] + * Arg: qname [UNKN ] Undocumented argument [char *] + * Arg: query [UNKN ] Undocumented argument [char *] + * Arg: tname [UNKN ] Undocumented argument [char *] + * Arg: target [UNKN ] Undocumented argument [char *] + * Arg: btc [UNKN ] Undocumented argument [btCanvas *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_write_pretty_str_align_btc(AlnBlock * alb,char * qname,char * query,char * tname,char * target,btCanvas * btc); +#define write_pretty_str_align_btc bp_sw_write_pretty_str_align_btc + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/sequence.c b/Bio/Ext/Align/libs/sequence.c new file mode 100644 index 0000000..d0d91df --- /dev/null +++ b/Bio/Ext/Align/libs/sequence.c @@ -0,0 +1,1491 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" +#include "sequence.h" + +/* Function: new_Sequence_from_strings(name,seq) + * + * Descrip: Makes a new sequence from strings given. + * Separate memory will be allocated for them + * and them copied into it. + * + * They can be NULL, in which case + * o a dummy name SequenceName will be assigned + * o No sequence placed and length of zero. + * + * Though this is dangerous later on. + * + * The sequence type is calculated automatically using + * /best_guess_type. If you want a DNA sequence but are + * unsure of the content of, for example, IUPAC codes, + * please use /force_to_dna_Sequence before using the + * sequence. Most of the rest of dynamite relies on a + * five letter A,T,G,C,N alphabet, but this function + * will allow any sequence type to be stored, so please + * check if you want to save yourself alot of grief. + * + * In perl and other interfaces, this is a much safer + * constructor than the raw "new" type + * + * + * Arg: name [READ ] name of sequence, memory is allocated for it. [char *] + * Arg: seq [READ ] char * of sequence, memory is allocated for it. [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 116 "sequence.dy" +Sequence * new_Sequence_from_strings(char * name,char * seq) +{ + Sequence * out; + + out = Sequence_alloc(); + + if( name == NULL) + name = "SequenceName"; + + out->name = stringalloc(name); + + if( seq == NULL ) { + out->seq = NULL; + out->len = 0; + return out; + } + + out->seq = stringalloc(seq); + out->len = strlen(out->seq); + out->offset = 1; + out->end = out->len; + + out->type = best_guess_type(out); + + return out; +} + + +/* Function: looks_like_accession(name) + * + * Descrip: Returns true if name looks like [A-Za-z]+[0-9]+ + * This should be an accession number + * + * + * Arg: name [READ ] name to be tested [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 150 "sequence.dy" +boolean looks_like_accession(char * name) +{ + char * run; + + for(run=name;*run && isalpha(*run);run++) + ; + if( *run == '\0') + return FALSE; + for(;*run && isalnum(*run) && !isalpha(*run);run++) + ; + if( *run == '\0') + return TRUE; + return FALSE; +} + + +/* Function: make_len_type_Sequence(seq) + * + * Descrip: makes seq->len and seq->end match the seq->seq + * length number. + * + * It also checks the type of the sequence with + * /best_guess_type + * + * + * Arg: seq [RW ] Sequence object [Sequence *] + * + */ +# line 176 "sequence.dy" +void make_len_type_Sequence(Sequence * seq) +{ + seq->len = strlen(seq->seq); + + seq->end = seq->len + seq->offset -1; + seq->type = best_guess_type(seq); + +} + +/* Function: best_guess_type(seq) + * + * Descrip: Guesses DNA or protein, by adding all + * the A,T,G,C up and if len < 300 && > 95% or + * len > 300 && > 75% then considers + * it to be DNA. NB - Ns not counted. + * + * + * Arg: seq [READ ] Sequence to be guessed [Sequence *] + * + * Return [OWNER] SEQUENCE_DNA or SEQUENCE_PROTEIN [int] + * + */ +# line 194 "sequence.dy" +int best_guess_type(Sequence * seq) +{ + register int i; + int ch[26]; + int no; + int unplaced = 0; + int total; + + for(i=0;i<26;i++) + ch[i] = 0; + + for(i=0;ilen;i++) { + if( (no=(toupper(seq->seq[i])-'A')) > 26 || no < 0 ) + unplaced++; + else ch[no]++; + } + + total = (ch['A' - 'A']+ch['T' - 'A'] + ch['G' - 'A'] + ch['C' - 'A'] ); + + if( seq->len < 300 ) { + if( (double)total/(double)seq->len > 0.95 ) + return SEQUENCE_DNA; + else return SEQUENCE_PROTEIN; + } else { + if( (double)total/(double)seq->len > 0.75 ) + return SEQUENCE_DNA; + else return SEQUENCE_PROTEIN; + } + +} + +/* Function: Sequence_type_to_string(type) + * + * Descrip: Converts sequence type (SEQUENCE_*) to a string + * + * + * Arg: type [UNKN ] type eg SEQUENCE_PROTEIN [int] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 230 "sequence.dy" +char * Sequence_type_to_string(int type) +{ + switch (type ) { + case SEQUENCE_UNKNOWN : return "Unknown type"; + case SEQUENCE_PROTEIN : return "Protein"; + case SEQUENCE_DNA : return "Dna"; + case SEQUENCE_CDNA : return "cDNA"; + case SEQUENCE_GENOMIC : return "Genomic"; + case SEQUENCE_EST : return "Est"; + case SEQUENCE_RNA : return "RNA"; + default : return "Undefined!"; + } +} + +/* Function: uppercase_Sequence(seq) + * + * Descrip: makes all the sequence uppercase + * + * + * Arg: seq [RW ] Sequence to be uppercas'd [Sequence *] + * + */ +# line 250 "sequence.dy" +void uppercase_Sequence(Sequence * seq) +{ + int i; + + for(i=0;ilen;i++) + seq->seq[i] = toupper(seq->seq[i]); +} + +/* Function: force_to_dna_Sequence(seq,fraction,number_of_conver) + * + * Descrip: This + * a) sees how many non ATGCN characters there are in Seq + * b) If the level is below fraction + * a) flips non ATGC chars to N + * b) writes number of conversions to number_of_conver + * c) returns TRUE + * c) else returns FALSE + * + * fraction of 0.0 means completely intolerant of errors + * fraction of 1.0 means completely tolerant of errors + * + * + * + * Arg: seq [RW ] sequence object read and converted [Sequence *] + * Arg: fraction [READ ] number 0..1 for tolerance of conversion [double] + * Arg: number_of_conver [WRITE] number of conversions actually made [int *] + * + * Return [READ ] TRUE for conversion to DNA, FALSE if not [boolean] + * + */ +# line 277 "sequence.dy" +boolean force_to_dna_Sequence(Sequence * seq,double fraction,int * number_of_conver) +{ + int count =0; + int i; + + if( seq == NULL ) { + warn("Attempting to force a sequence with no Sequence object!\n"); + return FALSE; + } + if( seq->len <= 0 ) { + warn("Trying to make a sequence with a length of %d. Bad news!",seq->len); + return FALSE; + } + + + for(i=0;ilen;i++) { + /* if it is lower case, uppercase it! */ + seq->seq[i] = toupper(seq->seq[i]); + + if( !is_valid_base_char(seq->seq[i]) ) { + count++; + } + } + + + if( ((double)count/(double)seq->len) < fraction ) { + seq->type = SEQUENCE_DNA; + if( count != 0 ) { + for(i=0;ilen;i++) { + if( !is_valid_base_char(seq->seq[i]) ) { + seq->seq[i] = 'N'; + } + } + } + if( number_of_conver != NULL ) { + *number_of_conver = count; + } + return TRUE; + } + else { + if( number_of_conver != NULL ) { + *number_of_conver = count; + } + return FALSE; + } +} + +/* Function: is_reversed_Sequence(seq) + * + * Descrip: Currently the sequence object stores + * reversed sequences as start > end. + * + * This tests that and returns true if it is + * + * + * Arg: seq [READ ] sequence to test [Sequence *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 333 "sequence.dy" +boolean is_reversed_Sequence(Sequence * seq) +{ + if( seq->offset > seq->end) + return TRUE; + return FALSE; +} + +/* Function: translate_Sequence(dna,ct) + * + * Descrip: This translates a DNA sequence to a protein. + * It assummes that it starts at first residue + * (use trunc_Sequence to chop a sequence up). + * + * + * Arg: dna [READ ] DNA sequence to be translated [Sequence *] + * Arg: ct [READ ] Codon table to do codon->aa mapping [CodonTable *] + * + * Return [OWNER] new protein sequence [Sequence *] + * + */ +# line 350 "sequence.dy" +Sequence * translate_Sequence(Sequence * dna,CodonTable * ct) +{ + Sequence * out; + int i; + int j; + int len; + char * seq; + char * name; + char buffer[512]; + + if( is_dna_Sequence(dna) == FALSE) { + warn("Trying to make a translation from a non DNA sequence... type is [%s]",Sequence_type_to_string(dna->type)); + return NULL; + } + + len = dna->len/3 + 1; + + seq = ckcalloc(len,sizeof(char)); + + sprintf(buffer,"%s.tr",dna->name == NULL ? "NoNameDNASeq" : dna->name); + + name = stringalloc(buffer); + + out = Sequence_from_dynamic_memory(name,seq); + + for(i=0,j=0;ilen-3;i+=3,j++) { + out->seq[j] = aminoacid_from_seq(ct,dna->seq+i); + } + out->seq[j] = '\0'; + + out->type = SEQUENCE_PROTEIN; + out->len = strlen(out->seq); + + return out; +} + +/* Function: reverse_complement_Sequence(seq) + * + * Descrip: This both complements and reverses a sequence, + * - a common wish! + * + * The start/end are correct with respect to the start/end + * of the sequence (ie start = end, end = start). + * + * + * Arg: seq [READ ] Sequence to that is used to reverse (makes a new Sequence) [Sequence *] + * + * Return [OWNER] new Sequence which is reversed [Sequence *] + * + */ +# line 397 "sequence.dy" +Sequence * reverse_complement_Sequence(Sequence * seq) +{ + Sequence * out; + int i; + int j; + + + if( is_dna_Sequence(seq) != TRUE ) { + warn("Cannot reverse complement non-DNA sequence... type is %s",Sequence_type_to_string(seq->type)); + return NULL; + } + + out = Sequence_from_static_memory(seq->name,seq->seq); + + for(j=0,i=seq->len-1;i >= 0;i--,j++) { + out->seq[j] = char_complement_base(seq->seq[i]); + /*fprintf(stderr,"In position %d placed %c from %c\n",j,out->seq[j],seq->seq[i]);*/ + } + + out->len = strlen(seq->seq); + + out->offset = seq->end; + out->end = seq->offset; + out->type = seq->type; + + + return out; +} +/* Function: magic_trunc_Sequence(seq,start,end) + * + * Descrip: Clever function for dna sequences. + * + * When start < end, truncates normally + * + * when start > end, truncates end,start and then + * reverse complements. + * + * ie. If you have a coordinate system where reverse + * sequences are labelled in reverse start/end way, + * then this routine produces the correct sequence. + * + * + * Arg: seq [READ ] sequence that is the source to be truncated [Sequence *] + * Arg: start [READ ] start point [int] + * Arg: end [READ ] end point [int] + * + * Return [OWNER] new Sequence which is truncated/reversed [Sequence *] + * + */ +# line 443 "sequence.dy" +Sequence * magic_trunc_Sequence(Sequence * seq,int start,int end) +{ + Sequence * temp; + Sequence * out; + + if( is_dna_Sequence(seq) == FALSE) { + warn("Cannot magic truncate on a non DNA sequence... type is %s",Sequence_type_to_string(seq->type)); + return NULL; + } + + if( start < 0 || end < 0 ) { + warn("Attempting a magic truncation on indices which are less than zero [%d:%d]. Clearly impossible",start,end); + return NULL; + } + + if( start < end ) { + return trunc_Sequence(seq,start,end); + } + else { + temp = trunc_Sequence(seq,end,start); + if( temp == NULL ) { + warn("Unable to truncate sequence"); + return NULL; + } + + + out = reverse_complement_Sequence(temp); + + free_Sequence(temp); + + return out; + } + +} + + +/* Function: trunc_Sequence(seq,start,end) + * + * Descrip: truncates a sequence. It produces a new memory structure + * which is filled from sequence start to end. + * + * Please notice + * + * Truncation is in C coordinates. That is + * the first residue is 0 and end is the number of the + * residue after the cut-point. In otherwords to + * 2 - 3 would be a single residue truncation. So - if + * you want to work in more usual, 'inclusive' molecular + * biology numbers, which start at 1, then you need to say + * + * trunc_Sequence(seq,start-1,end); + * + * (NB, should be (end - 1 + 1) = end for the last coordinate). + * + * Truncation occurs against the *absolute* coordinate + * system of the Sequence, not the offset/end pair inside. + * So, this is a very bad error + * + * ** wrong code, and also leaks memory ** + * + * tru = trunc_Sequence(trunc_Sequence(seq,50,80),55,75); + * + * This the most portable way of doing this + * + * temp = trunc_Sequence(seq,50,80); + * + * tru = trunc_Sequence(temp,55-temp->offset,75-temp->offset); + * + * free_Sequence(temp); + * + * + * + * Arg: seq [READ ] object holding the sequence to be truncated [Sequence *] + * Arg: start [READ ] start point of truncation [int] + * Arg: end [READ ] end point of truncation [int] + * + * Return [OWNER] newly allocated sequence structure [Sequence *] + * + */ +# line 519 "sequence.dy" +Sequence * trunc_Sequence(Sequence * seq,int start,int end) +{ + char * name; + char * seqb; + Sequence * out; + + if( start < 0 || end < 0 ) { + warn("Attempting a truncation on indices which are less than zero [%d:%d]. Clearly impossible",start,end); + return NULL; + } + + if( end <= start ) { + warn("Trying to truncate Sequence from %d - %d",start,end); + return NULL; + } + + if( end > seq->len ) { + warn("Trying to truncate Sequecne %s from %d - %d when length is %d", + seq->name,start,end,seq->len); + return NULL; + } + + name = stringalloc(seq->name); + + seqb = (char *) ckcalloc(end-start+1,sizeof(char)); + + memcpy(seqb,seq->seq+start,(end-start)); + seqb[end-start] = '\0'; + + out = Sequence_from_dynamic_memory(name,seqb); + + out->len = strlen(out->seq); + out->type = seq->type; + out->offset = seq->offset+start; + out->end = seq->offset + end-1; + + return out; +} + +/* Function: read_SRS_db_Sequence(datastring,srsstring) + * + * Descrip: A function for you to easily specify the sequence name + * and the database separately. Just concatonates the two + * strings with : betwqeen them. Therefore you should use + * "swisprot-id" for example as your datastring. + * + * calls /read_SRS_Sequence + * + * + * Arg: datastring [READ ] string representing the database (swissprot-id) [char *] + * Arg: srsstring [READ ] string for the name (eg, ROA1_HUMAN) [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 569 "sequence.dy" +Sequence * read_SRS_db_Sequence(char * datastring,char * srsstring) +{ + char buffer[256]; + + sprintf(buffer,"%s:%s",datastring,srsstring); + + return read_SRS_Sequence(buffer); +} + +/* Function: read_SRS_Sequence(srsstring) + * + * Descrip: reads SRS specified sequence. calls popoen + * with getz -f using srs4 syntax. Will only read + * the first sequence if there is more than one in the + * SRS spec, and does not warn you about additional + * sequences + * + * + * Arg: srsstring [READ ] srs spec'd string swissprot-id:ROA1_HUMAN [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 587 "sequence.dy" +Sequence * read_SRS_Sequence(char * srsstring) +{ + FILE * pipe; + char buffer[MAXLINE]; + Sequence * out; + + + sprintf(buffer,"getz -d '[%s]' ",srsstring); + + pipe = popen(buffer,"r"); + + if ( pipe == NULL ) { + warn("Could not open %s as an SRS database string - probably no getz",srsstring); + return NULL; + } + + out = read_fasta_Sequence(pipe); + + pclose(pipe); + + return out; +} + +/* Function: read_efetch_Sequence(efetchstring) + * + * Descrip: reads efetch specificed sequence. calls popen to + * efetch. A hack around accession numbers so that if the + * thing looks like WP:acc number, calls it with -a... + * otherwise assummes you have both database and name in the + * efetchstring + * + * + * Arg: efetchstring [READ ] efetch valid string [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 619 "sequence.dy" +Sequence * read_efetch_Sequence(char * efetchstring) +{ + FILE * pf; + Sequence * out; + char buffer[MAXLINE]; + + if( strstartcmp(efetchstring,"WP:") != 0 && looks_like_accession(efetchstring+3) == TRUE) { + sprintf(buffer,"efetch -f -a %s",efetchstring); + } + else { + sprintf(buffer,"efetch -f %s",efetchstring); + } + + pf = popen(buffer,"r"); + + if( pf == NULL ) { + warn("Could not open efetch pipe with [%s]",efetchstring); + return NULL; + } + + out = read_fasta_Sequence(pf); + + pclose(pf); + + return out; +} + +/* Function: read_fasta_file_Sequence(filename) + * + * Descrip: Just a call + * a) open filename + * b) read sequence with /read_fasta_Sequence + * c) close file. + * + * + * Arg: filename [READ ] filename to open [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 654 "sequence.dy" +Sequence * read_fasta_file_Sequence(char * filename) +{ + Sequence * out; + FILE * ifp; + + ifp = openfile(filename,"r"); + + if( ifp == NULL ) { + warn("Cannot open %s for read_fasta_file",filename); + return NULL; + } + + out = read_fasta_Sequence(ifp); + + fclose(ifp); + + return out; +} + +/* Function: read_Sequence_EMBL_seq(buffer,maxlen,ifp) + * + * Descrip: reads the sequence part of an EMBL file. + * + * This function can either take a file which + * starts + * + * + * + * Arg: buffer [RW ] buffer containing the first line. [char *] + * Arg: maxlen [READ ] length of buffer [int] + * Arg: ifp [READ ] input file to read from [FILE *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 684 "sequence.dy" +Sequence * read_Sequence_EMBL_seq(char * buffer,int maxlen,FILE * ifp) +{ + Sequence * out; + char seqbuffer[SEQUENCEBLOCK]; + int i = 0; + signed char c; + + if( !isalpha(*buffer) ) { + warn("I don't like this - got a buffer of [%s] in reading an EMBL sequence section",buffer); + } + + do { + if( strstartcmp(buffer,"SQ") == 0 ) { + break; + } + } while ( fgets(buffer,maxlen,ifp) != NULL); + + out = empty_Sequence_from_dynamic_memory(stringalloc("EMBLseq")); + + while( (c=fgetc(ifp)) != EOF ) { + if( c == '/' && (c=fgetc(ifp)) == '/') + break; /*** ugly perhaps. what about single / lines? ***/ + + if( isalpha(c) ) + seqbuffer[i++] = c; + if( i > SEQUENCEBLOCK-2) { + seqbuffer[i] = '\0'; + if( add_string_to_Sequence(out,seqbuffer) == FALSE ) + { + warn("Could not read full sequence of %s - returning\n",out->name); + return out; + } + i = 0; + } + } + + /* ok have to now put away final buffer read! */ + + seqbuffer[i] = '\0'; + + add_string_to_Sequence(out,seqbuffer); + + /** add back > if need be **/ + + if( feof(ifp) || c != '/' ) { + warn("In parsing an EMBL file got an poor ending of a sequence region"); + } else { + while( (c=fgetc(ifp)) != '\n' && c != EOF ) + ; + } + + make_len_type_Sequence(out); + + return out; +} + + + + + + +/* Function: read_fasta_Sequence(ifp) + * + * Descrip: reads the fasta file: format is + * + * >name + * sequence + * + * allocates a structure and puts in the + * sequence. Calls /make_len_type_Sequence to + * check type and length. + * + * It leaves the '>' on the next fasta sequence + * for multiple sequence reading + * + * + * Arg: ifp [READ ] input file to read from [FILE *] + * + * Return [OWNER] new Sequence structure [Sequence *] + * + */ +# line 761 "sequence.dy" +Sequence * read_fasta_Sequence(FILE * ifp) +{ + Sequence * out; + char seqbuffer[SEQUENCEBLOCK]; + int i = 0; + signed char c = EOF; + + if( feof(ifp) ) { + /* fail silently */ + return NULL; + } + + while( (c=fgetc(ifp)) != EOF && isspace(c)) + ; + + if( feof(ifp) ) + return NULL; + + if( c != '>' ) { + warn("First letter read is not '>' - assumming it is not a fasta stream"); + return NULL; + } + + + if( c == EOF || feof(ifp) ) + return NULL; + + /*** ok = got to > ****/ + /*** read in name ****/ + + + while( !isspace(c=fgetc(ifp)) && c != EOF) + seqbuffer[i++]=c; + + if( c == EOF) + return NULL; + + seqbuffer[i]='\0'; + + /*** name now in sequence buffer - make sequence ***/ + + out = empty_Sequence_from_dynamic_memory(stringalloc(seqbuffer)); + + if( out == NULL ) + return NULL; + + + /*** ok, suck in the rest of this line if necessary (ie something else on the 1st line) ***/ + + while( c != EOF && c != '\n' ) + c=fgetc(ifp); + + + /*** now read in sequence ***/ + + for(i=0; !feof(ifp) && (c=fgetc(ifp)) != '>' && c != EOF;) + { + if( isalpha(c) ) + seqbuffer[i++] = c; + if( i > SEQUENCEBLOCK-2) + { + seqbuffer[i] = '\0'; + if( add_string_to_Sequence(out,seqbuffer) == FALSE ) + { + warn("Could not read full sequence of %s - returning\n",out->name); + return out; + } + i = 0; + } + } + + + + + /* ok have to now put away final buffer read! */ + + seqbuffer[i] = '\0'; + + add_string_to_Sequence(out,seqbuffer); + + /** add back > if need be **/ + + if( c == '>' ) + ungetc(c,ifp); + + make_len_type_Sequence(out); + + return out; +} + +/* Function: show_Sequence_residue_list(seq,start,end,ofp) + * + * Descrip: shows a region of a sequence as + * 124 A + * 125 T + * + * etc from start to end. The numbers + * are in C coordinates (ie, 0 is the first + * letter). + * + * useful for debugging + * + * + * Arg: seq [READ ] Sequence to show [Sequence *] + * Arg: start [READ ] start of list [int] + * Arg: end [READ ] end of list [int] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 867 "sequence.dy" +void show_Sequence_residue_list(Sequence * seq,int start,int end,FILE * ofp) +{ + int i; + + for(i=start;iseq[i]); + } +} + + +/* Function: add_string_to_Sequence(seq,more) + * + * Descrip: Dodgy function. This is meant to add the more + * sequence to seq (into ->seq). Not sure how stable + * this is. In theory it reallocates memory on + * the basis of ->maxlen. + * + * + * Arg: seq [UNKN ] Sequence to add sequence to [Sequence *] + * Arg: more [UNKN ] pointer to sequence to add [char *] + * + * Return [UNKN ] TRUE if successful, FALSE if not [boolean] + * + */ +# line 888 "sequence.dy" +boolean add_string_to_Sequence(Sequence * seq,char * more) +{ + register int len; + register int blocklen; + void * temp; + + + len = strlen(more)+1; + + if( len < seq->maxlen - seq->len ) + { + /*** ok can add to this block! ****/ + strcat(seq->seq,more); + seq->len = strlen(seq->seq); + return TRUE; + } + + + /*** nope - need to realloc ****/ + + len -= (seq->maxlen - seq->len); /* amount that needs to be realloc'd */ + blocklen = 1 + (int)(len / SEQUENCEBLOCK); /* number of blocks */ + blocklen *= SEQUENCEBLOCK; /* make that into bytes */ + blocklen += seq->maxlen; /* final size of string */ + + temp = ckrealloc ( seq->seq,blocklen); + + + if( temp == NULL ) + { + warn("Sequence block error for sequence %s on blocklen %d\n",CKS(seq->name),blocklen); + return FALSE; + } + + seq->seq = (char *) temp; /* realloc moves the memory for us as well */ + seq->maxlen = blocklen; + + /*** copy in string ****/ + + strcat(seq->seq,more); + + seq->len = strlen(seq->seq); + + return TRUE; +} + +/* Function: empty_Sequence_from_dynamic_memory(name) + * + * Descrip: Only allocates sequence structure and name + * + * + * Arg: name [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 937 "sequence.dy" +Sequence * empty_Sequence_from_dynamic_memory(char * name) +{ + Sequence * out; + + out = Sequence_alloc(); + + if( out == NULL ) + return NULL; + + if( name == NULL ) + { + warn("Attempting to make an empty sequence with no name: assigning dummy name"); + name = stringalloc("DummyName"); + } + + out->name = name; + out->seq = (char *) ckcalloc (SEQUENCEBLOCK,sizeof(char)); + out->maxlen = SEQUENCEBLOCK; + out->len = 0; + + return out; +} + +/* Function: Sequence_alloc_len(len) + * + * Descrip: allocates sequence structure with enough + * length in char for len sequence. + * + * + * Arg: len [READ ] length of blank sequene space [int] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 966 "sequence.dy" +Sequence * Sequence_alloc_len(int len) +{ + Sequence * out; + + out = Sequence_alloc(); + if( out == NULL) + return NULL; + + out->seq = (char *) ckcalloc (len,sizeof(char)); + out->maxlen = out->len = len; + + return out; +} + +/* Function: Sequence_from_static_memory (name,seq) + * + * Descrip: Allocates the sequence structure and memory for + * name and seq, copies them in. + * + * + * Arg: name [UNKN ] Undocumented argument [char *] + * Arg: seq [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 985 "sequence.dy" +Sequence * Sequence_from_static_memory (char * name,char * seq) +{ + return Sequence_from_dynamic_memory(stringalloc(name),stringalloc(seq)); +} + +/* Function: Sequence_from_dynamic_memory(name,seq) + * + * Descrip: Allocates the sequence structure and simple attaches + * name and seq to the correct places + * + * + * Arg: name [UNKN ] name of sequence [char *] + * Arg: seq [UNKN ] a char * to correct sequence [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 998 "sequence.dy" +Sequence * Sequence_from_dynamic_memory(char * name,char * seq) +{ + Sequence * out; + + + if( seq == NULL) { + warn("Cannot make a sequence with no sequence!"); + return NULL; + } + + if( name == NULL ) { + warn("You are attempting to make a sequence with no name - assigning dummy name"); + name = stringalloc ("DummyName"); + } + + out = Sequence_alloc(); + + if( out == NULL) + return out; + + out->name = name; + out->seq = seq; + + out->maxlen = out->len = strlen(seq); + + return out; +} + +/* Function: write_fasta_Sequence(seq,ofp) + * + * Descrip: writes a fasta file of the form + * >name + * Sequence + * + * + * Arg: seq [READ ] sequence to be written [Sequence *] + * Arg: ofp [UNKN ] file to write to [FILE *] + * + */ +# line 1035 "sequence.dy" +void write_fasta_Sequence(Sequence * seq,FILE * ofp) +{ + fprintf(ofp,">%s\n",seq->name); + show_line(seq->seq,60,ofp); +} + + + + +# line 1037 "sequence.c" +/* Function: hard_link_Sequence(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [Sequence *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * hard_link_Sequence(Sequence * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a Sequence object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: Sequence_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * Sequence_alloc(void) +{ + Sequence * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(Sequence *) ckalloc (sizeof(Sequence))) == NULL) { + warn("Sequence_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->name = NULL; + out->seq = NULL; + out->len = 0; + out->maxlen = 0; + out->offset = 1; + out->end = (-1); + out->type = SEQUENCE_UNKNOWN; + + + return out; +} + + +/* Function: free_Sequence(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [Sequence *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * free_Sequence(Sequence * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a Sequence obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->name != NULL) + ckfree(obj->name); + if( obj->seq != NULL) + ckfree(obj->seq); + + + ckfree(obj); + return NULL; +} + + +/* Function: replace_name_Sequence(obj,name) + * + * Descrip: Replace member variable name + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * Arg: name [OWNER] New value of the variable [char *] + * + * Return [SOFT ] member variable name [boolean] + * + */ +boolean replace_name_Sequence(Sequence * obj,char * name) +{ + if( obj == NULL) { + warn("In replacement function name for object Sequence, got a NULL object"); + return FALSE; + } + obj->name = name; + return TRUE; +} + + +/* Function: access_name_Sequence(obj) + * + * Descrip: Access member variable name + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * + * Return [SOFT ] member variable name [char *] + * + */ +char * access_name_Sequence(Sequence * obj) +{ + if( obj == NULL) { + warn("In accessor function name for object Sequence, got a NULL object"); + return NULL; + } + return obj->name; +} + + +/* Function: replace_seq_Sequence(obj,seq) + * + * Descrip: Replace member variable seq + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * Arg: seq [OWNER] New value of the variable [char *] + * + * Return [SOFT ] member variable seq [boolean] + * + */ +boolean replace_seq_Sequence(Sequence * obj,char * seq) +{ + if( obj == NULL) { + warn("In replacement function seq for object Sequence, got a NULL object"); + return FALSE; + } + obj->seq = seq; + return TRUE; +} + + +/* Function: access_seq_Sequence(obj) + * + * Descrip: Access member variable seq + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * + * Return [SOFT ] member variable seq [char *] + * + */ +char * access_seq_Sequence(Sequence * obj) +{ + if( obj == NULL) { + warn("In accessor function seq for object Sequence, got a NULL object"); + return NULL; + } + return obj->seq; +} + + +/* Function: replace_len_Sequence(obj,len) + * + * Descrip: Replace member variable len + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * Arg: len [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable len [boolean] + * + */ +boolean replace_len_Sequence(Sequence * obj,int len) +{ + if( obj == NULL) { + warn("In replacement function len for object Sequence, got a NULL object"); + return FALSE; + } + obj->len = len; + return TRUE; +} + + +/* Function: access_len_Sequence(obj) + * + * Descrip: Access member variable len + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * + * Return [SOFT ] member variable len [int] + * + */ +int access_len_Sequence(Sequence * obj) +{ + if( obj == NULL) { + warn("In accessor function len for object Sequence, got a NULL object"); + return 0; + } + return obj->len; +} + + +/* Function: replace_maxlen_Sequence(obj,maxlen) + * + * Descrip: Replace member variable maxlen + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * Arg: maxlen [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable maxlen [boolean] + * + */ +boolean replace_maxlen_Sequence(Sequence * obj,int maxlen) +{ + if( obj == NULL) { + warn("In replacement function maxlen for object Sequence, got a NULL object"); + return FALSE; + } + obj->maxlen = maxlen; + return TRUE; +} + + +/* Function: access_maxlen_Sequence(obj) + * + * Descrip: Access member variable maxlen + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * + * Return [SOFT ] member variable maxlen [int] + * + */ +int access_maxlen_Sequence(Sequence * obj) +{ + if( obj == NULL) { + warn("In accessor function maxlen for object Sequence, got a NULL object"); + return 0; + } + return obj->maxlen; +} + + +/* Function: replace_offset_Sequence(obj,offset) + * + * Descrip: Replace member variable offset + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * Arg: offset [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable offset [boolean] + * + */ +boolean replace_offset_Sequence(Sequence * obj,int offset) +{ + if( obj == NULL) { + warn("In replacement function offset for object Sequence, got a NULL object"); + return FALSE; + } + obj->offset = offset; + return TRUE; +} + + +/* Function: access_offset_Sequence(obj) + * + * Descrip: Access member variable offset + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * + * Return [SOFT ] member variable offset [int] + * + */ +int access_offset_Sequence(Sequence * obj) +{ + if( obj == NULL) { + warn("In accessor function offset for object Sequence, got a NULL object"); + return 0; + } + return obj->offset; +} + + +/* Function: replace_end_Sequence(obj,end) + * + * Descrip: Replace member variable end + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * Arg: end [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable end [boolean] + * + */ +boolean replace_end_Sequence(Sequence * obj,int end) +{ + if( obj == NULL) { + warn("In replacement function end for object Sequence, got a NULL object"); + return FALSE; + } + obj->end = end; + return TRUE; +} + + +/* Function: access_end_Sequence(obj) + * + * Descrip: Access member variable end + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * + * Return [SOFT ] member variable end [int] + * + */ +int access_end_Sequence(Sequence * obj) +{ + if( obj == NULL) { + warn("In accessor function end for object Sequence, got a NULL object"); + return 0; + } + return obj->end; +} + + +/* Function: replace_type_Sequence(obj,type) + * + * Descrip: Replace member variable type + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * Arg: type [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable type [boolean] + * + */ +boolean replace_type_Sequence(Sequence * obj,int type) +{ + if( obj == NULL) { + warn("In replacement function type for object Sequence, got a NULL object"); + return FALSE; + } + obj->type = type; + return TRUE; +} + + +/* Function: access_type_Sequence(obj) + * + * Descrip: Access member variable type + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [Sequence *] + * + * Return [SOFT ] member variable type [int] + * + */ +int access_type_Sequence(Sequence * obj) +{ + if( obj == NULL) { + warn("In accessor function type for object Sequence, got a NULL object"); + return 0; + } + return obj->type; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/sequence.h b/Bio/Ext/Align/libs/sequence.h new file mode 100644 index 0000000..953a348 --- /dev/null +++ b/Bio/Ext/Align/libs/sequence.h @@ -0,0 +1,613 @@ +#ifndef DYNAMITEsequenceHEADERFILE +#define DYNAMITEsequenceHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif + +#include "wisebase.h" +#include "codon.h" + +#ifdef LINUX +#include "posix.h" +#endif + +#define SEQUENCEBLOCK 128 + +enum SequenceType { +SEQUENCE_UNKNOWN = 64, +SEQUENCE_PROTEIN, +SEQUENCE_DNA, +SEQUENCE_CDNA, +SEQUENCE_GENOMIC, +SEQUENCE_EST, +SEQUENCE_RNA }; + +#define is_dna_SequenceType(type) (type == SEQUENCE_DNA || type == SEQUENCE_CDNA || type == SEQUENCE_GENOMIC || type == SEQUENCE_EST ? TRUE : FALSE) +#define is_rna_SequenceType(type) (type == SEQUENCE_RNA ? TRUE : FALSE) +#define is_protein_SequenceType(type) (type == SEQUENCE_PROTEIN ? TRUE : FALSE ) + +#define is_dna_Sequence(seq) (is_dna_SequenceType(seq->type)) +#define is_rna_Sequence(seq) (is_rna_SequenceType(seq->type)) +#define is_protein_Sequence(seq) (is_protein_SequenceType(seq->type)) + +/* Object Sequence + * + * Descrip: This object is the basic sequence object, + * trying to hold little more than the + * name and sequence of the DNA/protein. + * + * The len/maxlen is the actual length + * of the sequence (strlen(obj->seq)) and + * amount of memory allocated in obj->seq + * mainly for parsing purposes. + * + * You are strongly encouraged to used the + * typed counterparts of Sequence, namely, + * Protien, cDNA and Genomic. By doing this + * you are much, much less likely to + * mess up algorithms which expect specific + * sequence types. + * + * + */ +struct bp_sw_Sequence { + int dynamite_hard_link; + char * name; /* name of the sequence */ + char * seq; /* actual sequence */ + int len; /* length of the sequence */ + int maxlen; /* internal counter, indicating how much space in seq there is */ + int offset; /* start (in bio-coords) of the sequence. Not called start due to weird legacy. */ + int end; /* end (in bio-coords == C coords) of the sequence */ + int type; /* guess of protein/dna type */ + } ; +/* Sequence defined */ +#ifndef DYNAMITE_DEFINED_Sequence +typedef struct bp_sw_Sequence bp_sw_Sequence; +#define Sequence bp_sw_Sequence +#define DYNAMITE_DEFINED_Sequence +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: new_Sequence_from_strings(name,seq) + * + * Descrip: Makes a new sequence from strings given. + * Separate memory will be allocated for them + * and them copied into it. + * + * They can be NULL, in which case + * o a dummy name SequenceName will be assigned + * o No sequence placed and length of zero. + * + * Though this is dangerous later on. + * + * The sequence type is calculated automatically using + * /best_guess_type. If you want a DNA sequence but are + * unsure of the content of, for example, IUPAC codes, + * please use /force_to_dna_Sequence before using the + * sequence. Most of the rest of dynamite relies on a + * five letter A,T,G,C,N alphabet, but this function + * will allow any sequence type to be stored, so please + * check if you want to save yourself alot of grief. + * + * In perl and other interfaces, this is a much safer + * constructor than the raw "new" type + * + * + * Arg: name [READ ] name of sequence, memory is allocated for it. [char *] + * Arg: seq [READ ] char * of sequence, memory is allocated for it. [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_new_Sequence_from_strings(char * name,char * seq); +#define new_Sequence_from_strings bp_sw_new_Sequence_from_strings + + +/* Function: looks_like_accession(name) + * + * Descrip: Returns true if name looks like [A-Za-z]+[0-9]+ + * This should be an accession number + * + * + * Arg: name [READ ] name to be tested [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_looks_like_accession(char * name); +#define looks_like_accession bp_sw_looks_like_accession + + +/* Function: make_len_type_Sequence(seq) + * + * Descrip: makes seq->len and seq->end match the seq->seq + * length number. + * + * It also checks the type of the sequence with + * /best_guess_type + * + * + * Arg: seq [RW ] Sequence object [Sequence *] + * + */ +void bp_sw_make_len_type_Sequence(Sequence * seq); +#define make_len_type_Sequence bp_sw_make_len_type_Sequence + + +/* Function: best_guess_type(seq) + * + * Descrip: Guesses DNA or protein, by adding all + * the A,T,G,C up and if len < 300 && > 95% or + * len > 300 && > 75% then considers + * it to be DNA. NB - Ns not counted. + * + * + * Arg: seq [READ ] Sequence to be guessed [Sequence *] + * + * Return [OWNER] SEQUENCE_DNA or SEQUENCE_PROTEIN [int] + * + */ +int bp_sw_best_guess_type(Sequence * seq); +#define best_guess_type bp_sw_best_guess_type + + +/* Function: Sequence_type_to_string(type) + * + * Descrip: Converts sequence type (SEQUENCE_*) to a string + * + * + * Arg: type [UNKN ] type eg SEQUENCE_PROTEIN [int] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_Sequence_type_to_string(int type); +#define Sequence_type_to_string bp_sw_Sequence_type_to_string + + +/* Function: uppercase_Sequence(seq) + * + * Descrip: makes all the sequence uppercase + * + * + * Arg: seq [RW ] Sequence to be uppercas'd [Sequence *] + * + */ +void bp_sw_uppercase_Sequence(Sequence * seq); +#define uppercase_Sequence bp_sw_uppercase_Sequence + + +/* Function: force_to_dna_Sequence(seq,fraction,number_of_conver) + * + * Descrip: This + * a) sees how many non ATGCN characters there are in Seq + * b) If the level is below fraction + * a) flips non ATGC chars to N + * b) writes number of conversions to number_of_conver + * c) returns TRUE + * c) else returns FALSE + * + * fraction of 0.0 means completely intolerant of errors + * fraction of 1.0 means completely tolerant of errors + * + * + * + * Arg: seq [RW ] sequence object read and converted [Sequence *] + * Arg: fraction [READ ] number 0..1 for tolerance of conversion [double] + * Arg: number_of_conver [WRITE] number of conversions actually made [int *] + * + * Return [READ ] TRUE for conversion to DNA, FALSE if not [boolean] + * + */ +boolean bp_sw_force_to_dna_Sequence(Sequence * seq,double fraction,int * number_of_conver); +#define force_to_dna_Sequence bp_sw_force_to_dna_Sequence + + +/* Function: is_reversed_Sequence(seq) + * + * Descrip: Currently the sequence object stores + * reversed sequences as start > end. + * + * This tests that and returns true if it is + * + * + * Arg: seq [READ ] sequence to test [Sequence *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_is_reversed_Sequence(Sequence * seq); +#define is_reversed_Sequence bp_sw_is_reversed_Sequence + + +/* Function: translate_Sequence(dna,ct) + * + * Descrip: This translates a DNA sequence to a protein. + * It assummes that it starts at first residue + * (use trunc_Sequence to chop a sequence up). + * + * + * Arg: dna [READ ] DNA sequence to be translated [Sequence *] + * Arg: ct [READ ] Codon table to do codon->aa mapping [CodonTable *] + * + * Return [OWNER] new protein sequence [Sequence *] + * + */ +Sequence * bp_sw_translate_Sequence(Sequence * dna,CodonTable * ct); +#define translate_Sequence bp_sw_translate_Sequence + + +/* Function: reverse_complement_Sequence(seq) + * + * Descrip: This both complements and reverses a sequence, + * - a common wish! + * + * The start/end are correct with respect to the start/end + * of the sequence (ie start = end, end = start). + * + * + * Arg: seq [READ ] Sequence to that is used to reverse (makes a new Sequence) [Sequence *] + * + * Return [OWNER] new Sequence which is reversed [Sequence *] + * + */ +Sequence * bp_sw_reverse_complement_Sequence(Sequence * seq); +#define reverse_complement_Sequence bp_sw_reverse_complement_Sequence + + +/* Function: magic_trunc_Sequence(seq,start,end) + * + * Descrip: Clever function for dna sequences. + * + * When start < end, truncates normally + * + * when start > end, truncates end,start and then + * reverse complements. + * + * ie. If you have a coordinate system where reverse + * sequences are labelled in reverse start/end way, + * then this routine produces the correct sequence. + * + * + * Arg: seq [READ ] sequence that is the source to be truncated [Sequence *] + * Arg: start [READ ] start point [int] + * Arg: end [READ ] end point [int] + * + * Return [OWNER] new Sequence which is truncated/reversed [Sequence *] + * + */ +Sequence * bp_sw_magic_trunc_Sequence(Sequence * seq,int start,int end); +#define magic_trunc_Sequence bp_sw_magic_trunc_Sequence + + +/* Function: trunc_Sequence(seq,start,end) + * + * Descrip: truncates a sequence. It produces a new memory structure + * which is filled from sequence start to end. + * + * Please notice + * + * Truncation is in C coordinates. That is + * the first residue is 0 and end is the number of the + * residue after the cut-point. In otherwords to + * 2 - 3 would be a single residue truncation. So - if + * you want to work in more usual, 'inclusive' molecular + * biology numbers, which start at 1, then you need to say + * + * trunc_Sequence(seq,start-1,end); + * + * (NB, should be (end - 1 + 1) = end for the last coordinate). + * + * Truncation occurs against the *absolute* coordinate + * system of the Sequence, not the offset/end pair inside. + * So, this is a very bad error + * + * ** wrong code, and also leaks memory ** + * + * tru = trunc_Sequence(trunc_Sequence(seq,50,80),55,75); + * + * This the most portable way of doing this + * + * temp = trunc_Sequence(seq,50,80); + * + * tru = trunc_Sequence(temp,55-temp->offset,75-temp->offset); + * + * free_Sequence(temp); + * + * + * + * Arg: seq [READ ] object holding the sequence to be truncated [Sequence *] + * Arg: start [READ ] start point of truncation [int] + * Arg: end [READ ] end point of truncation [int] + * + * Return [OWNER] newly allocated sequence structure [Sequence *] + * + */ +Sequence * bp_sw_trunc_Sequence(Sequence * seq,int start,int end); +#define trunc_Sequence bp_sw_trunc_Sequence + + +/* Function: read_SRS_db_Sequence(datastring,srsstring) + * + * Descrip: A function for you to easily specify the sequence name + * and the database separately. Just concatonates the two + * strings with : betwqeen them. Therefore you should use + * "swisprot-id" for example as your datastring. + * + * calls /read_SRS_Sequence + * + * + * Arg: datastring [READ ] string representing the database (swissprot-id) [char *] + * Arg: srsstring [READ ] string for the name (eg, ROA1_HUMAN) [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_read_SRS_db_Sequence(char * datastring,char * srsstring); +#define read_SRS_db_Sequence bp_sw_read_SRS_db_Sequence + + +/* Function: read_SRS_Sequence(srsstring) + * + * Descrip: reads SRS specified sequence. calls popoen + * with getz -f using srs4 syntax. Will only read + * the first sequence if there is more than one in the + * SRS spec, and does not warn you about additional + * sequences + * + * + * Arg: srsstring [READ ] srs spec'd string swissprot-id:ROA1_HUMAN [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_read_SRS_Sequence(char * srsstring); +#define read_SRS_Sequence bp_sw_read_SRS_Sequence + + +/* Function: read_efetch_Sequence(efetchstring) + * + * Descrip: reads efetch specificed sequence. calls popen to + * efetch. A hack around accession numbers so that if the + * thing looks like WP:acc number, calls it with -a... + * otherwise assummes you have both database and name in the + * efetchstring + * + * + * Arg: efetchstring [READ ] efetch valid string [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_read_efetch_Sequence(char * efetchstring); +#define read_efetch_Sequence bp_sw_read_efetch_Sequence + + +/* Function: read_fasta_file_Sequence(filename) + * + * Descrip: Just a call + * a) open filename + * b) read sequence with /read_fasta_Sequence + * c) close file. + * + * + * Arg: filename [READ ] filename to open [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_read_fasta_file_Sequence(char * filename); +#define read_fasta_file_Sequence bp_sw_read_fasta_file_Sequence + + +/* Function: read_Sequence_EMBL_seq(buffer,maxlen,ifp) + * + * Descrip: reads the sequence part of an EMBL file. + * + * This function can either take a file which + * starts + * + * + * + * Arg: buffer [RW ] buffer containing the first line. [char *] + * Arg: maxlen [READ ] length of buffer [int] + * Arg: ifp [READ ] input file to read from [FILE *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_read_Sequence_EMBL_seq(char * buffer,int maxlen,FILE * ifp); +#define read_Sequence_EMBL_seq bp_sw_read_Sequence_EMBL_seq + + +/* Function: read_fasta_Sequence(ifp) + * + * Descrip: reads the fasta file: format is + * + * >name + * sequence + * + * allocates a structure and puts in the + * sequence. Calls /make_len_type_Sequence to + * check type and length. + * + * It leaves the '>' on the next fasta sequence + * for multiple sequence reading + * + * + * Arg: ifp [READ ] input file to read from [FILE *] + * + * Return [OWNER] new Sequence structure [Sequence *] + * + */ +Sequence * bp_sw_read_fasta_Sequence(FILE * ifp); +#define read_fasta_Sequence bp_sw_read_fasta_Sequence + + +/* Function: show_Sequence_residue_list(seq,start,end,ofp) + * + * Descrip: shows a region of a sequence as + * 124 A + * 125 T + * + * etc from start to end. The numbers + * are in C coordinates (ie, 0 is the first + * letter). + * + * useful for debugging + * + * + * Arg: seq [READ ] Sequence to show [Sequence *] + * Arg: start [READ ] start of list [int] + * Arg: end [READ ] end of list [int] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_show_Sequence_residue_list(Sequence * seq,int start,int end,FILE * ofp); +#define show_Sequence_residue_list bp_sw_show_Sequence_residue_list + + +/* Function: empty_Sequence_from_dynamic_memory(name) + * + * Descrip: Only allocates sequence structure and name + * + * + * Arg: name [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_empty_Sequence_from_dynamic_memory(char * name); +#define empty_Sequence_from_dynamic_memory bp_sw_empty_Sequence_from_dynamic_memory + + +/* Function: Sequence_alloc_len(len) + * + * Descrip: allocates sequence structure with enough + * length in char for len sequence. + * + * + * Arg: len [READ ] length of blank sequene space [int] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_Sequence_alloc_len(int len); +#define Sequence_alloc_len bp_sw_Sequence_alloc_len + + +/* Function: write_fasta_Sequence(seq,ofp) + * + * Descrip: writes a fasta file of the form + * >name + * Sequence + * + * + * Arg: seq [READ ] sequence to be written [Sequence *] + * Arg: ofp [UNKN ] file to write to [FILE *] + * + */ +void bp_sw_write_fasta_Sequence(Sequence * seq,FILE * ofp); +#define write_fasta_Sequence bp_sw_write_fasta_Sequence + + +/* Function: hard_link_Sequence(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [Sequence *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_hard_link_Sequence(Sequence * obj); +#define hard_link_Sequence bp_sw_hard_link_Sequence + + +/* Function: Sequence_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_Sequence_alloc(void); +#define Sequence_alloc bp_sw_Sequence_alloc + + +/* Function: free_Sequence(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [Sequence *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_free_Sequence(Sequence * obj); +#define free_Sequence bp_sw_free_Sequence + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +boolean bp_sw_replace_seq_Sequence(Sequence * obj,char * seq); +#define replace_seq_Sequence bp_sw_replace_seq_Sequence +int bp_sw_access_len_Sequence(Sequence * obj); +#define access_len_Sequence bp_sw_access_len_Sequence +boolean bp_sw_replace_maxlen_Sequence(Sequence * obj,int maxlen); +#define replace_maxlen_Sequence bp_sw_replace_maxlen_Sequence +boolean bp_sw_replace_name_Sequence(Sequence * obj,char * name); +#define replace_name_Sequence bp_sw_replace_name_Sequence +int bp_sw_access_type_Sequence(Sequence * obj); +#define access_type_Sequence bp_sw_access_type_Sequence +int bp_sw_access_maxlen_Sequence(Sequence * obj); +#define access_maxlen_Sequence bp_sw_access_maxlen_Sequence +char * bp_sw_access_seq_Sequence(Sequence * obj); +#define access_seq_Sequence bp_sw_access_seq_Sequence +boolean bp_sw_replace_offset_Sequence(Sequence * obj,int offset); +#define replace_offset_Sequence bp_sw_replace_offset_Sequence +boolean bp_sw_replace_len_Sequence(Sequence * obj,int len); +#define replace_len_Sequence bp_sw_replace_len_Sequence +int bp_sw_access_offset_Sequence(Sequence * obj); +#define access_offset_Sequence bp_sw_access_offset_Sequence +boolean bp_sw_replace_type_Sequence(Sequence * obj,int type); +#define replace_type_Sequence bp_sw_replace_type_Sequence +boolean bp_sw_replace_end_Sequence(Sequence * obj,int end); +#define replace_end_Sequence bp_sw_replace_end_Sequence +char * bp_sw_access_name_Sequence(Sequence * obj); +#define access_name_Sequence bp_sw_access_name_Sequence +int bp_sw_access_end_Sequence(Sequence * obj); +#define access_end_Sequence bp_sw_access_end_Sequence +boolean bp_sw_add_string_to_Sequence(Sequence * seq,char * more); +#define add_string_to_Sequence bp_sw_add_string_to_Sequence +Sequence * bp_sw_Sequence_from_static_memory (char * name,char * seq); +#define Sequence_from_static_memory bp_sw_Sequence_from_static_memory +Sequence * bp_sw_Sequence_from_dynamic_memory(char * name,char * seq); +#define Sequence_from_dynamic_memory bp_sw_Sequence_from_dynamic_memory + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/sequencedb.c b/Bio/Ext/Align/libs/sequencedb.c new file mode 100644 index 0000000..1af4571 --- /dev/null +++ b/Bio/Ext/Align/libs/sequencedb.c @@ -0,0 +1,1402 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "sequencedb.h" + + + +/* Function: get_Sequence_from_SequenceDB(sdb,de) + * + * Descrip: Quite a mindless function which retrieves sequences + * via indexes + * + * Going to spend too much time in fopen if this is used + * too much + * + * + * Arg: sdb [UNKN ] Undocumented argument [SequenceDB *] + * Arg: de [UNKN ] Undocumented argument [DataEntry *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 65 "sequencedb.dy" +Sequence * get_Sequence_from_SequenceDB(SequenceDB * sdb,DataEntry * de) +{ + FILE * ifp; + Sequence * ret; + + /* actually, all our info is in dataentry */ + + ifp = openfile(de->filename,"r"); + if( ifp == NULL ) { + warn("Bad error - could not open database file %s for reading indexed sequence",de->filename); + return NULL; + } + + fseek(ifp,de->data[0],SEEK_SET); + + switch(de->data[1]) { + case SEQ_DB_FASTA : + ret = read_fasta_Sequence(ifp); + break; + default : + warn("Unknown SequenceDB type [%d]",de->data[1]); + ret = NULL; + } + + fclose(ifp); + + return ret; +} + + + +/* Function: add_SequenceDB_info_DataEntry(sdb,de) + * + * Descrip: A function which places data into dataentry so we can + * be guarenteed to retrieve it sometime. + * + * It uses 0 and 1 points in the Data array. + * + * + * Arg: sdb [UNKN ] Undocumented argument [SequenceDB *] + * Arg: de [UNKN ] Undocumented argument [DataEntry *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 102 "sequencedb.dy" +boolean add_SequenceDB_info_DataEntry(SequenceDB * sdb,DataEntry * de) +{ + if( sdb == NULL || de == NULL ) { + warn("Null objects being passed into add_SequenceDB_info_DataEntry. Can't be good!"); + return FALSE; + } + + de->filename = sdb->fs[sdb->current_source]->filename; /* if there... */ + de->data[0] = sdb->byte_position; /* of this sequence */ + de->data[1] = sdb->fs[sdb->current_source]->format; + + return TRUE; +} + + +/* Function: close_SequenceDB(last,sdb) + * + * Descrip: top level function that closes the SequenceDB + * after the last sequence is read. + * + * + * Arg: last [WRITE] Sequence object to be freed [Sequence *] + * Arg: sdb [READ ] database to be closed [SequenceDB *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 124 "sequencedb.dy" +boolean close_SequenceDB(Sequence * last,SequenceDB * sdb) +{ + if( last != NULL ) + free_Sequence(last); + + /*** nothing else to do? ***/ + + sdb->current_source = (-1); + return TRUE; +} + + +/* Function: init_SequenceDB(sdb,return_status) + * + * Descrip: top level function that starts a database read on + * SequenceDB + * + * + * + * Arg: sdb [READ ] sequence database [SequenceDB *] + * Arg: return_status [WRITE] returns the database status as found in database.h [int *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 144 "sequencedb.dy" +Sequence * init_SequenceDB(SequenceDB * sdb,int * return_status) +{ + sdb->current_source = 0; + load_next_fs_SequenceDB(sdb); + + + return reload_SequenceDB(NULL,sdb,return_status); +} + +/* Function: reload_SequenceDB(last,sdb,return_status) + * + * Descrip: top level function that reloads a sequence database + * + * + * + * Arg: last [WRITE] previous sequence to be used: will simply be freed at the moment [Sequence *] + * Arg: sdb [UNKN ] sequence database [SequenceDB *] + * Arg: return_status [WRITE] returns the database status as found in database.h [int *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 161 "sequencedb.dy" +Sequence * reload_SequenceDB(Sequence * last,SequenceDB * sdb,int * return_status) +{ + Sequence * out; + int count = 0; + + /* + * free last Sequence: if we did something clever with + * memory, this is where we should do it + */ + + if( last != NULL ) + free_Sequence(last); + + /** see if we can read a Sequence now **/ + + + if( (out = get_next_SequenceDB(sdb)) != NULL ) { + *return_status = DB_RETURN_OK; + return out; + } + + + if( SequenceDB_at_end(sdb) == TRUE ) { + if( close_last_fs_SequenceDB(sdb) == FALSE ) { + warn("On file source [%d] [%s] could not close",sdb->current_source,sdb->fs[sdb->current_source]->filename); + *return_status = DB_RETURN_ERROR; + return NULL; + } + *return_status = DB_RETURN_END; + return NULL; + } + + /** ok, see if we can swap FileSources then **/ + + for(;;) { + if( close_last_fs_SequenceDB(sdb) == FALSE ) { + warn("On file source [%d] [%s] could not close",sdb->current_source,sdb->fs[sdb->current_source]->filename); + *return_status = DB_RETURN_ERROR; + return NULL; + } + + if( load_next_fs_SequenceDB(sdb) == FALSE ) { + warn("On file source [%d] [%s] could not open the file",sdb->current_source+1,sdb->fs[sdb->current_source+1]->filename); + *return_status = DB_RETURN_ERROR; + return NULL; + } + + + if( (out = get_next_SequenceDB(sdb)) != NULL ) { + *return_status = DB_RETURN_OK; + return out; + } + count++; + warn("Ok, don't like this, just loaded the next Filesource, and got no sequence. Nope!"); + + if( SequenceDB_at_end(sdb) == TRUE ) { + *return_status = DB_RETURN_END; + return NULL; + } + + if( count > 10 ) { + /*** break out of infinite loop ***/ + + warn("Too many failed reloads of databases, going to fail"); + *return_status = DB_RETURN_ERROR; + return NULL; + } + + + } /** back for for(;;) **/ + +} + +/* Function: get_next_SequenceDB(sdb) + * + * Descrip: Main switch around formats + * + * + * Arg: sdb [UNKN ] Undocumented argument [SequenceDB *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +# line 238 "sequencedb.dy" +Sequence * get_next_SequenceDB(SequenceDB * sdb) +{ + + /* remember the byte position now */ + + sdb->byte_position = ftell(sdb->current_file); + + switch (sdb->fs[sdb->current_source]->format) { + case SEQ_DB_FASTA : + return read_fasta_Sequence(sdb->current_file); + default : + warn("Unknown SequenceDB type [%d]",sdb->fs[sdb->current_source]->format); + return NULL; + } +} + + +/* Function: SequenceDB_at_end(sdb) + * + * Descrip: Tells you if the SequenceDB is actually ended + * in terms of no more FileSources to eat through + * + * + * Arg: sdb [UNKN ] Undocumented argument [SequenceDB *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 260 "sequencedb.dy" +boolean SequenceDB_at_end(SequenceDB * sdb) +{ + if( sdb->current_source == -1 ) { + warn("Bad bug: asking when it has finished when you have not init'd seqdb %s",sdb->name); + return TRUE; + } + + if( sdb->current_source+1 < sdb->len ) { + return FALSE; + } + + return TRUE; +} + + +/* Function: load_next_fs_SequenceDB(sdb) + * + * Descrip: Opens or attaches next FileSource stream + * + * Does not close anything - use /close_last_fs_SequenceDB + * + * + * Arg: sdb [UNKN ] Undocumented argument [SequenceDB *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 281 "sequencedb.dy" +boolean load_next_fs_SequenceDB(SequenceDB * sdb) +{ + FileSource * fs; + + if( sdb->current_source == -1 ) { + warn("Bad bug: trying to close last source when you have not init'd seqdb %s",sdb->name); + return FALSE; + } + + if( sdb->current_source >= sdb->len ) { + warn("Bad bug. Someone is trying to load the next fs file when there are none (has not tested with SequenceDB_at_end...). So. I will fail, but database is actually at the end"); + return FALSE; + } + + + fs = sdb->fs[sdb->current_source]; + + if( fs->filename != NULL ) { + if( (sdb->current_file = openfile(fs->filename,"r")) == NULL ) { + warn("Could not open file [%s] for database [%s]",fs->filename,sdb->name); + return FALSE; + } + } else { + sdb->current_file = fs->input; + } + + return TRUE; +} + +/* Function: close_last_fs_SequenceDB(sdb) + * + * Descrip: closes the last FileSource: checks if it was a straight stream + * (in which case does not close) + * + * + * Arg: sdb [UNKN ] Undocumented argument [SequenceDB *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 315 "sequencedb.dy" +boolean close_last_fs_SequenceDB(SequenceDB * sdb) +{ + FileSource * fs; + + if( sdb->current_source == -1 ) { + warn("Bad bug: trying to close last source when you have not init'd seqdb %s",sdb->name); + return FALSE; + } + + fs = sdb->fs[sdb->current_source]; + + if( fs->filename != NULL ) { + fclose(sdb->current_file); + } else if( fs->input != NULL ) { + warn("Can't handle closes on streams yet. Not sure what to do!"); + } + + + + sdb->current_source++; + + return TRUE; +} + + + /*** I/O ****/ + +/* Function: SequenceDB_from_FILE_and_format(input,format) + * + * Descrip: makes a SequencDB from a straight file stream. + * + * This means SequenceDB will *not* close it when + * the SequenceDB is closed. + * + * + * Arg: input [READ ] filestream [FILE *] + * Arg: format [UNKN ] format as defined by /word_to_format [int] + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +# line 351 "sequencedb.dy" +SequenceDB * SequenceDB_from_FILE_and_format(FILE * input,int format) +{ + SequenceDB * out; + FileSource * fs; + + out = SequenceDB_alloc_len(1); + + fs = FileSource_from_FILE_and_format(input,format); + + add_SequenceDB(out,fs); + + return out; + +} + +/* Function: FileSource_from_FILE_and_format(input,format) + * + * Descrip: Makes a file source from a straigth stream + * + * + * Arg: input [UNKN ] Undocumented argument [FILE *] + * Arg: format [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [FileSource *] + * + */ +# line 370 "sequencedb.dy" +FileSource * FileSource_from_FILE_and_format(FILE * input,int format) +{ + FileSource * fs; + + fs = FileSource_alloc(); + + fs->input = input; + fs->format = format; + + return fs; +} + +/* Function: single_fasta_SequenceDB(filename) + * + * Descrip: pre-packed single fasta file db + * + * + * + * Arg: filename [UNKN ] name of fastadb [char *] + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +# line 388 "sequencedb.dy" +SequenceDB * single_fasta_SequenceDB(char * filename) +{ + SequenceDB * out; + FileSource * fs; + + if( touchfile(filename) == FALSE) { + warn("Cannot make SequenceDB from an unopenable fileanme [%s]",filename); + return NULL; + } + + fs = FileSource_alloc(); + fs->filename = stringalloc(filename); + fs->format = SEQ_DB_FASTA; + + out = SequenceDB_alloc_len(1); + + add_SequenceDB(out,fs); + + return out; +} + + + +/* Function: read_SequenceDB_line(line,ifp) + * + * Descrip: Reads a SequenceDB definition from + * + * seqdb + * + * ... + * endseqdb + * + * + * + * Arg: line [UNKN ] starting line (seqdb line) [char *] + * Arg: ifp [UNKN ] file input [FILE *] + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +# line 423 "sequencedb.dy" +SequenceDB * read_SequenceDB_line(char * line,FILE * ifp) +{ + SequenceDB * out = NULL; + FileSource * fs; + char buffer[MAXLINE]; + char * runner; + + + if( strstartcmp(line,"seqdb") != 0 ) { + warn("Attempting to read a sequence line without a seqdb start"); + return NULL; + } + + runner = strtok(line,spacestr); + runner = strtok(line,spacestr); + + if( runner == NULL ) { + out->name = stringalloc("UnNamedDatabase"); + } + else out->name = stringalloc(runner); + + + out = SequenceDB_alloc_std(); + + while( fgets(buffer,MAXLINE,ifp) != NULL ){ + if( strstartcmp(buffer,"#") == 0 ) + continue; + if( strstartcmp(buffer,"end") == 0 ) + break; + fs = FileSource_from_line(buffer); + if( fs != NULL ) + add_SequenceDB(out,fs); + } + + return out; +} + +/* Function: word_to_format(word) + * + * Descrip: converts char * to format for SequenceDB FileSources + * + * + * Arg: word [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 463 "sequencedb.dy" +int word_to_format(char * word) +{ + if( strcmp(word,"fasta") == 0 ) { + return SEQ_DB_FASTA; + } + + return SEQ_DB_UNKNOWN; +} + + +/* Function: FileSource_from_line(line) + * + * Descrip: Reads line + * filename format type + * + * where format is determined by /word_to_format + * and type is protein/dna + * + * + * Arg: line [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [FileSource *] + * + */ +# line 481 "sequencedb.dy" +FileSource * FileSource_from_line(char * line) +{ + FileSource * out; + char * runner; + char * run2; + char * run3; + + runner = strtok(line,spacestr); + run2 = strtok(line,spacestr); + run3 = strtok(line,spacestr); + + if( runner == NULL || run2 == NULL || run3 == NULL ) { + warn("You have not provided a database source line"); + return NULL; + } + + + + out = FileSource_alloc(); + + out->filename = stringalloc(runner); + + if( (out->format = word_to_format(run2)) == SEQ_DB_UNKNOWN) { + warn("For filename %s, the format [%s] is unknown to me",runner,run2); + } + + return out; +} + + + + +# line 537 "sequencedb.c" +/* Function: hard_link_FileSource(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [FileSource *] + * + * Return [UNKN ] Undocumented return value [FileSource *] + * + */ +FileSource * hard_link_FileSource(FileSource * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a FileSource object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: FileSource_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [FileSource *] + * + */ +FileSource * FileSource_alloc(void) +{ + FileSource * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(FileSource *) ckalloc (sizeof(FileSource))) == NULL) { + warn("FileSource_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->filename = NULL; + out->format = 0; + out->type = 0; + + + return out; +} + + +/* Function: free_FileSource(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [FileSource *] + * + * Return [UNKN ] Undocumented return value [FileSource *] + * + */ +FileSource * free_FileSource(FileSource * obj) +{ + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a FileSource obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->filename != NULL) + ckfree(obj->filename); + /* obj->input is linked in */ + + + ckfree(obj); + return NULL; +} + + +/* Function: swap_SequenceDB(list,i,j) + * + * Descrip: swap function: an internal for qsort_SequenceDB + * swaps two positions in the array + * + * + * Arg: list [UNKN ] List of structures to swap in [FileSource **] + * Arg: i [UNKN ] swap position [int] + * Arg: j [UNKN ] swap position [int] + * + */ +/* swap function for qsort function */ +void swap_SequenceDB(FileSource ** list,int i,int j) +{ + FileSource * temp; + temp=list[i]; + list[i]=list[j]; + list[j]=temp; +} + + +/* Function: qsort_SequenceDB(list,left,right,comp) + * + * Descrip: qsort - lifted from K&R + * sorts the array using quicksort + * Probably much better to call sort_SequenceDB which sorts from start to end + * + * + * Arg: list [UNKN ] List of structures to swap in [FileSource **] + * Arg: left [UNKN ] left position [int] + * Arg: right [UNKN ] right position [int] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void qsort_SequenceDB(FileSource ** list,int left,int right,int (*comp)(FileSource * ,FileSource * )) +{ + int i,last; + if( left >= right ) + return; + + + swap_SequenceDB(list,left,(left+right)/2); + last = left; + for ( i=left+1; i <= right;i++) { + if( (*comp)(list[i],list[left]) < 0) + swap_SequenceDB (list,++last,i); + } + swap_SequenceDB (list,left,last); + qsort_SequenceDB(list,left,last-1,comp); + qsort_SequenceDB(list,last+1,right,comp); +} + + +/* Function: sort_SequenceDB(obj,comp) + * + * Descrip: sorts from start to end using comp + * sorts the array using quicksort by calling qsort_SequenceDB + * + * + * Arg: obj [UNKN ] Object containing list [SequenceDB *] + * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp] + * + */ +void sort_SequenceDB(SequenceDB * obj,int (*comp)(FileSource *, FileSource *)) +{ + qsort_SequenceDB(obj->fs,0,obj->len-1,comp); + return; +} + + +/* Function: expand_SequenceDB(obj,len) + * + * Descrip: Really an internal function for add_SequenceDB + * + * + * Arg: obj [UNKN ] Object which contains the list [SequenceDB *] + * Arg: len [UNKN ] Length to add one [int] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean expand_SequenceDB(SequenceDB * obj,int len) +{ + + + if( obj->maxlen > obj->len ) { + warn("expand_SequenceDB called with no need"); + return TRUE; + } + + + if( (obj->fs = (FileSource ** ) ckrealloc (obj->fs,sizeof(FileSource *)*len)) == NULL) { + warn("ckrealloc failed for expand_SequenceDB, returning FALSE"); + return FALSE; + } + obj->maxlen = len; + return TRUE; +} + + +/* Function: add_SequenceDB(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [SequenceDB *] + * Arg: add [OWNER] Object to add to the list [FileSource *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +/* will expand function if necessary */ +boolean add_SequenceDB(SequenceDB * obj,FileSource * add) +{ + if( obj->len >= obj->maxlen) { + if( expand_SequenceDB(obj,obj->len + SequenceDBLISTLENGTH) == FALSE) + return FALSE; + } + + + obj->fs[obj->len++]=add; + return TRUE; +} + + +/* Function: flush_SequenceDB(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [SequenceDB *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int flush_SequenceDB(SequenceDB * obj) +{ + int i; + + + for(i=0;ilen;i++) { + if( obj->fs[i] != NULL) { + free_FileSource(obj->fs[i]); + obj->fs[i] = NULL; + } + } /* end of for i over list length */ + + + obj->len = 0; + return i; +} + + +/* Function: SequenceDB_alloc_std(void) + * + * Descrip: Equivalent to SequenceDB_alloc_len(SequenceDBLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +SequenceDB * SequenceDB_alloc_std(void) +{ + return SequenceDB_alloc_len(SequenceDBLISTLENGTH); +} + + +/* Function: SequenceDB_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +SequenceDB * SequenceDB_alloc_len(int len) +{ + SequenceDB * out; /* out is exported at the end of function */ + + + /* Call alloc function: return NULL if NULL */ + /* Warning message alread in alloc function */ + if((out = SequenceDB_alloc()) == NULL) + return NULL; + + + /* Calling ckcalloc for list elements */ + if((out->fs = (FileSource ** ) ckcalloc (len,sizeof(FileSource *))) == NULL) { + warn("Warning, ckcalloc failed in SequenceDB_alloc_len"); + return NULL; + } + out->len = 0; + out->maxlen = len; + + + return out; +} + + +/* Function: hard_link_SequenceDB(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [SequenceDB *] + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +SequenceDB * hard_link_SequenceDB(SequenceDB * obj) +{ + if( obj == NULL ) { + warn("Trying to hard link to a SequenceDB object: passed a NULL object"); + return NULL; + } + obj->dynamite_hard_link++; + return obj; +} + + +/* Function: SequenceDB_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +SequenceDB * SequenceDB_alloc(void) +{ + SequenceDB * out; /* out is exported at end of function */ + + + /* call ckalloc and see if NULL */ + if((out=(SequenceDB *) ckalloc (sizeof(SequenceDB))) == NULL) { + warn("SequenceDB_alloc failed "); + return NULL; /* calling function should respond! */ + } + out->dynamite_hard_link = 1; + out->name = NULL; + out->fs = NULL; + out->len = out->maxlen = 0; + out->current_source = -1; + out->sequence_no = 0; + out->byte_position = 0; + + + return out; +} + + +/* Function: free_SequenceDB(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [SequenceDB *] + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +SequenceDB * free_SequenceDB(SequenceDB * obj) +{ + int i; + + + if( obj == NULL) { + warn("Attempting to free a NULL pointer to a SequenceDB obj. Should be trappable"); + return NULL; + } + + + if( obj->dynamite_hard_link > 1) { + obj->dynamite_hard_link--; + return NULL; + } + if( obj->name != NULL) + ckfree(obj->name); + if( obj->fs != NULL) { + for(i=0;ilen;i++) { + if( obj->fs[i] != NULL) + free_FileSource(obj->fs[i]); + } + ckfree(obj->fs); + } + /* obj->current_file is linked in */ + + + ckfree(obj); + return NULL; +} + + +/* Function: replace_name_SequenceDB(obj,name) + * + * Descrip: Replace member variable name + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [SequenceDB *] + * Arg: name [OWNER] New value of the variable [char *] + * + * Return [SOFT ] member variable name [boolean] + * + */ +boolean replace_name_SequenceDB(SequenceDB * obj,char * name) +{ + if( obj == NULL) { + warn("In replacement function name for object SequenceDB, got a NULL object"); + return FALSE; + } + obj->name = name; + return TRUE; +} + + +/* Function: access_name_SequenceDB(obj) + * + * Descrip: Access member variable name + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [SequenceDB *] + * + * Return [SOFT ] member variable name [char *] + * + */ +char * access_name_SequenceDB(SequenceDB * obj) +{ + if( obj == NULL) { + warn("In accessor function name for object SequenceDB, got a NULL object"); + return NULL; + } + return obj->name; +} + + +/* Function: access_fs_SequenceDB(obj,i) + * + * Descrip: Access members stored in the fs list + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the list [SequenceDB *] + * Arg: i [UNKN ] Position in the list [int] + * + * Return [SOFT ] Element of the list [FileSource *] + * + */ +FileSource * access_fs_SequenceDB(SequenceDB * obj,int i) +{ + if( obj == NULL) { + warn("In accessor function fs for object SequenceDB, got a NULL object"); + return NULL; + } + if( obj->len <= i ) { + warn("In accessor function fs for object SequenceDB, index %%d is greater than list length %%d",i,obj->len); + return NULL; + } + return obj->fs[i]; +} + + +/* Function: length_fs_SequenceDB(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the list [SequenceDB *] + * + * Return [UNKN ] length of the list [int] + * + */ +int length_fs_SequenceDB(SequenceDB * obj) +{ + if( obj == NULL) { + warn("In length function fs for object SequenceDB, got a NULL object"); + return -1; + } + return obj->len; +} + + +/* Function: replace_current_source_SequenceDB(obj,current_source) + * + * Descrip: Replace member variable current_source + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [SequenceDB *] + * Arg: current_source [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable current_source [boolean] + * + */ +boolean replace_current_source_SequenceDB(SequenceDB * obj,int current_source) +{ + if( obj == NULL) { + warn("In replacement function current_source for object SequenceDB, got a NULL object"); + return FALSE; + } + obj->current_source = current_source; + return TRUE; +} + + +/* Function: access_current_source_SequenceDB(obj) + * + * Descrip: Access member variable current_source + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [SequenceDB *] + * + * Return [SOFT ] member variable current_source [int] + * + */ +int access_current_source_SequenceDB(SequenceDB * obj) +{ + if( obj == NULL) { + warn("In accessor function current_source for object SequenceDB, got a NULL object"); + return 0; + } + return obj->current_source; +} + + +/* Function: replace_current_file_SequenceDB(obj,current_file) + * + * Descrip: Replace member variable current_file + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [SequenceDB *] + * Arg: current_file [OWNER] New value of the variable [FILE *] + * + * Return [SOFT ] member variable current_file [boolean] + * + */ +boolean replace_current_file_SequenceDB(SequenceDB * obj,FILE * current_file) +{ + if( obj == NULL) { + warn("In replacement function current_file for object SequenceDB, got a NULL object"); + return FALSE; + } + obj->current_file = current_file; + return TRUE; +} + + +/* Function: access_current_file_SequenceDB(obj) + * + * Descrip: Access member variable current_file + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [SequenceDB *] + * + * Return [SOFT ] member variable current_file [FILE *] + * + */ +FILE * access_current_file_SequenceDB(SequenceDB * obj) +{ + if( obj == NULL) { + warn("In accessor function current_file for object SequenceDB, got a NULL object"); + return NULL; + } + return obj->current_file; +} + + +/* Function: replace_sequence_no_SequenceDB(obj,sequence_no) + * + * Descrip: Replace member variable sequence_no + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [SequenceDB *] + * Arg: sequence_no [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable sequence_no [boolean] + * + */ +boolean replace_sequence_no_SequenceDB(SequenceDB * obj,int sequence_no) +{ + if( obj == NULL) { + warn("In replacement function sequence_no for object SequenceDB, got a NULL object"); + return FALSE; + } + obj->sequence_no = sequence_no; + return TRUE; +} + + +/* Function: access_sequence_no_SequenceDB(obj) + * + * Descrip: Access member variable sequence_no + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [SequenceDB *] + * + * Return [SOFT ] member variable sequence_no [int] + * + */ +int access_sequence_no_SequenceDB(SequenceDB * obj) +{ + if( obj == NULL) { + warn("In accessor function sequence_no for object SequenceDB, got a NULL object"); + return 0; + } + return obj->sequence_no; +} + + +/* Function: replace_byte_position_SequenceDB(obj,byte_position) + * + * Descrip: Replace member variable byte_position + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [SequenceDB *] + * Arg: byte_position [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable byte_position [boolean] + * + */ +boolean replace_byte_position_SequenceDB(SequenceDB * obj,int byte_position) +{ + if( obj == NULL) { + warn("In replacement function byte_position for object SequenceDB, got a NULL object"); + return FALSE; + } + obj->byte_position = byte_position; + return TRUE; +} + + +/* Function: access_byte_position_SequenceDB(obj) + * + * Descrip: Access member variable byte_position + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [SequenceDB *] + * + * Return [SOFT ] member variable byte_position [int] + * + */ +int access_byte_position_SequenceDB(SequenceDB * obj) +{ + if( obj == NULL) { + warn("In accessor function byte_position for object SequenceDB, got a NULL object"); + return 0; + } + return obj->byte_position; +} + + +/* Function: replace_filename_FileSource(obj,filename) + * + * Descrip: Replace member variable filename + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [FileSource *] + * Arg: filename [OWNER] New value of the variable [char *] + * + * Return [SOFT ] member variable filename [boolean] + * + */ +boolean replace_filename_FileSource(FileSource * obj,char * filename) +{ + if( obj == NULL) { + warn("In replacement function filename for object FileSource, got a NULL object"); + return FALSE; + } + obj->filename = filename; + return TRUE; +} + + +/* Function: access_filename_FileSource(obj) + * + * Descrip: Access member variable filename + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [FileSource *] + * + * Return [SOFT ] member variable filename [char *] + * + */ +char * access_filename_FileSource(FileSource * obj) +{ + if( obj == NULL) { + warn("In accessor function filename for object FileSource, got a NULL object"); + return NULL; + } + return obj->filename; +} + + +/* Function: replace_input_FileSource(obj,input) + * + * Descrip: Replace member variable input + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [FileSource *] + * Arg: input [OWNER] New value of the variable [FILE *] + * + * Return [SOFT ] member variable input [boolean] + * + */ +boolean replace_input_FileSource(FileSource * obj,FILE * input) +{ + if( obj == NULL) { + warn("In replacement function input for object FileSource, got a NULL object"); + return FALSE; + } + obj->input = input; + return TRUE; +} + + +/* Function: access_input_FileSource(obj) + * + * Descrip: Access member variable input + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [FileSource *] + * + * Return [SOFT ] member variable input [FILE *] + * + */ +FILE * access_input_FileSource(FileSource * obj) +{ + if( obj == NULL) { + warn("In accessor function input for object FileSource, got a NULL object"); + return NULL; + } + return obj->input; +} + + +/* Function: replace_format_FileSource(obj,format) + * + * Descrip: Replace member variable format + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [FileSource *] + * Arg: format [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable format [boolean] + * + */ +boolean replace_format_FileSource(FileSource * obj,int format) +{ + if( obj == NULL) { + warn("In replacement function format for object FileSource, got a NULL object"); + return FALSE; + } + obj->format = format; + return TRUE; +} + + +/* Function: access_format_FileSource(obj) + * + * Descrip: Access member variable format + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [FileSource *] + * + * Return [SOFT ] member variable format [int] + * + */ +int access_format_FileSource(FileSource * obj) +{ + if( obj == NULL) { + warn("In accessor function format for object FileSource, got a NULL object"); + return 0; + } + return obj->format; +} + + +/* Function: replace_type_FileSource(obj,type) + * + * Descrip: Replace member variable type + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [FileSource *] + * Arg: type [OWNER] New value of the variable [int] + * + * Return [SOFT ] member variable type [boolean] + * + */ +boolean replace_type_FileSource(FileSource * obj,int type) +{ + if( obj == NULL) { + warn("In replacement function type for object FileSource, got a NULL object"); + return FALSE; + } + obj->type = type; + return TRUE; +} + + +/* Function: access_type_FileSource(obj) + * + * Descrip: Access member variable type + * For use principly by API functions + * + * + * Arg: obj [UNKN ] Object holding the variable [FileSource *] + * + * Return [SOFT ] member variable type [int] + * + */ +int access_type_FileSource(FileSource * obj) +{ + if( obj == NULL) { + warn("In accessor function type for object FileSource, got a NULL object"); + return 0; + } + return obj->type; +} + + + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/sequencedb.h b/Bio/Ext/Align/libs/sequencedb.h new file mode 100644 index 0000000..73a0df8 --- /dev/null +++ b/Bio/Ext/Align/libs/sequencedb.h @@ -0,0 +1,445 @@ +#ifndef DYNAMITEsequencedbHEADERFILE +#define DYNAMITEsequencedbHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "sequence.h" +#include "database.h" +#include "hscore.h" + + +#define SequenceDBLISTLENGTH 128 + +enum SequenceDBFormat { + SEQ_DB_UNKNOWN = 32, + SEQ_DB_FASTA }; + +struct bp_sw_FileSource { + int dynamite_hard_link; + char * filename; + FILE * input; /* could be stdin! */ + int format; + int type; + } ; +/* FileSource defined */ +#ifndef DYNAMITE_DEFINED_FileSource +typedef struct bp_sw_FileSource bp_sw_FileSource; +#define FileSource bp_sw_FileSource +#define DYNAMITE_DEFINED_FileSource +#endif + + +/* Object SequenceDB + * + * Descrip: This is the basic Sequence database + * wrapper - it handles all the formats + * and the on-the-fly indexing. + * + * Generally it wont be directly used by + * an algorithm, which will be using something + * specific to the sequence type produce complex + * sequence type objects + * + * + */ +struct bp_sw_SequenceDB { + int dynamite_hard_link; + char * name; + FileSource ** fs; + int len;/* len for above fs */ + int maxlen; /* maxlen for above fs */ + int current_source; + FILE * current_file; + int sequence_no; + int byte_position; + } ; +/* SequenceDB defined */ +#ifndef DYNAMITE_DEFINED_SequenceDB +typedef struct bp_sw_SequenceDB bp_sw_SequenceDB; +#define SequenceDB bp_sw_SequenceDB +#define DYNAMITE_DEFINED_SequenceDB +#endif + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: get_Sequence_from_SequenceDB(sdb,de) + * + * Descrip: Quite a mindless function which retrieves sequences + * via indexes + * + * Going to spend too much time in fopen if this is used + * too much + * + * + * Arg: sdb [UNKN ] Undocumented argument [SequenceDB *] + * Arg: de [UNKN ] Undocumented argument [DataEntry *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_get_Sequence_from_SequenceDB(SequenceDB * sdb,DataEntry * de); +#define get_Sequence_from_SequenceDB bp_sw_get_Sequence_from_SequenceDB + + +/* Function: add_SequenceDB_info_DataEntry(sdb,de) + * + * Descrip: A function which places data into dataentry so we can + * be guarenteed to retrieve it sometime. + * + * It uses 0 and 1 points in the Data array. + * + * + * Arg: sdb [UNKN ] Undocumented argument [SequenceDB *] + * Arg: de [UNKN ] Undocumented argument [DataEntry *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_SequenceDB_info_DataEntry(SequenceDB * sdb,DataEntry * de); +#define add_SequenceDB_info_DataEntry bp_sw_add_SequenceDB_info_DataEntry + + +/* Function: close_SequenceDB(last,sdb) + * + * Descrip: top level function that closes the SequenceDB + * after the last sequence is read. + * + * + * Arg: last [WRITE] Sequence object to be freed [Sequence *] + * Arg: sdb [READ ] database to be closed [SequenceDB *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_close_SequenceDB(Sequence * last,SequenceDB * sdb); +#define close_SequenceDB bp_sw_close_SequenceDB + + +/* Function: init_SequenceDB(sdb,return_status) + * + * Descrip: top level function that starts a database read on + * SequenceDB + * + * + * + * Arg: sdb [READ ] sequence database [SequenceDB *] + * Arg: return_status [WRITE] returns the database status as found in database.h [int *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_init_SequenceDB(SequenceDB * sdb,int * return_status); +#define init_SequenceDB bp_sw_init_SequenceDB + + +/* Function: reload_SequenceDB(last,sdb,return_status) + * + * Descrip: top level function that reloads a sequence database + * + * + * + * Arg: last [WRITE] previous sequence to be used: will simply be freed at the moment [Sequence *] + * Arg: sdb [UNKN ] sequence database [SequenceDB *] + * Arg: return_status [WRITE] returns the database status as found in database.h [int *] + * + * Return [UNKN ] Undocumented return value [Sequence *] + * + */ +Sequence * bp_sw_reload_SequenceDB(Sequence * last,SequenceDB * sdb,int * return_status); +#define reload_SequenceDB bp_sw_reload_SequenceDB + + +/* Function: SequenceDB_from_FILE_and_format(input,format) + * + * Descrip: makes a SequencDB from a straight file stream. + * + * This means SequenceDB will *not* close it when + * the SequenceDB is closed. + * + * + * Arg: input [READ ] filestream [FILE *] + * Arg: format [UNKN ] format as defined by /word_to_format [int] + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +SequenceDB * bp_sw_SequenceDB_from_FILE_and_format(FILE * input,int format); +#define SequenceDB_from_FILE_and_format bp_sw_SequenceDB_from_FILE_and_format + + +/* Function: single_fasta_SequenceDB(filename) + * + * Descrip: pre-packed single fasta file db + * + * + * + * Arg: filename [UNKN ] name of fastadb [char *] + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +SequenceDB * bp_sw_single_fasta_SequenceDB(char * filename); +#define single_fasta_SequenceDB bp_sw_single_fasta_SequenceDB + + +/* Function: read_SequenceDB_line(line,ifp) + * + * Descrip: Reads a SequenceDB definition from + * + * seqdb + * + * ... + * endseqdb + * + * + * + * Arg: line [UNKN ] starting line (seqdb line) [char *] + * Arg: ifp [UNKN ] file input [FILE *] + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +SequenceDB * bp_sw_read_SequenceDB_line(char * line,FILE * ifp); +#define read_SequenceDB_line bp_sw_read_SequenceDB_line + + +/* Function: word_to_format(word) + * + * Descrip: converts char * to format for SequenceDB FileSources + * + * + * Arg: word [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_word_to_format(char * word); +#define word_to_format bp_sw_word_to_format + + +/* Function: hard_link_FileSource(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [FileSource *] + * + * Return [UNKN ] Undocumented return value [FileSource *] + * + */ +FileSource * bp_sw_hard_link_FileSource(FileSource * obj); +#define hard_link_FileSource bp_sw_hard_link_FileSource + + +/* Function: FileSource_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [FileSource *] + * + */ +FileSource * bp_sw_FileSource_alloc(void); +#define FileSource_alloc bp_sw_FileSource_alloc + + +/* Function: free_FileSource(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [FileSource *] + * + * Return [UNKN ] Undocumented return value [FileSource *] + * + */ +FileSource * bp_sw_free_FileSource(FileSource * obj); +#define free_FileSource bp_sw_free_FileSource + + +/* Function: add_SequenceDB(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj [UNKN ] Object which contains the list [SequenceDB *] + * Arg: add [OWNER] Object to add to the list [FileSource *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_SequenceDB(SequenceDB * obj,FileSource * add); +#define add_SequenceDB bp_sw_add_SequenceDB + + +/* Function: flush_SequenceDB(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj [UNKN ] Object which contains the list [SequenceDB *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_flush_SequenceDB(SequenceDB * obj); +#define flush_SequenceDB bp_sw_flush_SequenceDB + + +/* Function: SequenceDB_alloc_std(void) + * + * Descrip: Equivalent to SequenceDB_alloc_len(SequenceDBLISTLENGTH) + * + * + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +SequenceDB * bp_sw_SequenceDB_alloc_std(void); +#define SequenceDB_alloc_std bp_sw_SequenceDB_alloc_std + + +/* Function: SequenceDB_alloc_len(len) + * + * Descrip: Allocates len length to all lists + * + * + * Arg: len [UNKN ] Length of lists to allocate [int] + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +SequenceDB * bp_sw_SequenceDB_alloc_len(int len); +#define SequenceDB_alloc_len bp_sw_SequenceDB_alloc_len + + +/* Function: hard_link_SequenceDB(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj [UNKN ] Object to be hard linked [SequenceDB *] + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +SequenceDB * bp_sw_hard_link_SequenceDB(SequenceDB * obj); +#define hard_link_SequenceDB bp_sw_hard_link_SequenceDB + + +/* Function: SequenceDB_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +SequenceDB * bp_sw_SequenceDB_alloc(void); +#define SequenceDB_alloc bp_sw_SequenceDB_alloc + + +/* Function: free_SequenceDB(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj [UNKN ] Object that is free'd [SequenceDB *] + * + * Return [UNKN ] Undocumented return value [SequenceDB *] + * + */ +SequenceDB * bp_sw_free_SequenceDB(SequenceDB * obj); +#define free_SequenceDB bp_sw_free_SequenceDB + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +FileSource * bp_sw_access_fs_SequenceDB(SequenceDB * obj,int i); +#define access_fs_SequenceDB bp_sw_access_fs_SequenceDB +int bp_sw_access_current_source_SequenceDB(SequenceDB * obj); +#define access_current_source_SequenceDB bp_sw_access_current_source_SequenceDB +boolean bp_sw_replace_current_source_SequenceDB(SequenceDB * obj,int current_source); +#define replace_current_source_SequenceDB bp_sw_replace_current_source_SequenceDB +boolean bp_sw_replace_current_file_SequenceDB(SequenceDB * obj,FILE * current_file); +#define replace_current_file_SequenceDB bp_sw_replace_current_file_SequenceDB +boolean bp_sw_replace_sequence_no_SequenceDB(SequenceDB * obj,int sequence_no); +#define replace_sequence_no_SequenceDB bp_sw_replace_sequence_no_SequenceDB +int bp_sw_access_sequence_no_SequenceDB(SequenceDB * obj); +#define access_sequence_no_SequenceDB bp_sw_access_sequence_no_SequenceDB +boolean bp_sw_replace_name_SequenceDB(SequenceDB * obj,char * name); +#define replace_name_SequenceDB bp_sw_replace_name_SequenceDB +int bp_sw_access_format_FileSource(FileSource * obj); +#define access_format_FileSource bp_sw_access_format_FileSource +boolean bp_sw_replace_byte_position_SequenceDB(SequenceDB * obj,int byte_position); +#define replace_byte_position_SequenceDB bp_sw_replace_byte_position_SequenceDB +int bp_sw_length_fs_SequenceDB(SequenceDB * obj); +#define length_fs_SequenceDB bp_sw_length_fs_SequenceDB +boolean bp_sw_replace_format_FileSource(FileSource * obj,int format); +#define replace_format_FileSource bp_sw_replace_format_FileSource +int bp_sw_access_byte_position_SequenceDB(SequenceDB * obj); +#define access_byte_position_SequenceDB bp_sw_access_byte_position_SequenceDB +FILE * bp_sw_access_current_file_SequenceDB(SequenceDB * obj); +#define access_current_file_SequenceDB bp_sw_access_current_file_SequenceDB +boolean bp_sw_replace_filename_FileSource(FileSource * obj,char * filename); +#define replace_filename_FileSource bp_sw_replace_filename_FileSource +char * bp_sw_access_name_SequenceDB(SequenceDB * obj); +#define access_name_SequenceDB bp_sw_access_name_SequenceDB +char * bp_sw_access_filename_FileSource(FileSource * obj); +#define access_filename_FileSource bp_sw_access_filename_FileSource +boolean bp_sw_replace_type_FileSource(FileSource * obj,int type); +#define replace_type_FileSource bp_sw_replace_type_FileSource +boolean bp_sw_replace_input_FileSource(FileSource * obj,FILE * input); +#define replace_input_FileSource bp_sw_replace_input_FileSource +int bp_sw_access_type_FileSource(FileSource * obj); +#define access_type_FileSource bp_sw_access_type_FileSource +FILE * bp_sw_access_input_FileSource(FileSource * obj); +#define access_input_FileSource bp_sw_access_input_FileSource +Sequence * bp_sw_get_next_SequenceDB(SequenceDB * sdb); +#define get_next_SequenceDB bp_sw_get_next_SequenceDB +boolean bp_sw_SequenceDB_at_end(SequenceDB * sdb); +#define SequenceDB_at_end bp_sw_SequenceDB_at_end +boolean bp_sw_load_next_fs_SequenceDB(SequenceDB * sdb); +#define load_next_fs_SequenceDB bp_sw_load_next_fs_SequenceDB +boolean bp_sw_close_last_fs_SequenceDB(SequenceDB * sdb); +#define close_last_fs_SequenceDB bp_sw_close_last_fs_SequenceDB +FileSource * bp_sw_FileSource_from_FILE_and_format(FILE * input,int format); +#define FileSource_from_FILE_and_format bp_sw_FileSource_from_FILE_and_format +FileSource * bp_sw_FileSource_from_line(char * line); +#define FileSource_from_line bp_sw_FileSource_from_line +void bp_sw_swap_SequenceDB(FileSource ** list,int i,int j) ; +#define swap_SequenceDB bp_sw_swap_SequenceDB +void bp_sw_qsort_SequenceDB(FileSource ** list,int left,int right,int (*comp)(FileSource * ,FileSource * )); +#define qsort_SequenceDB bp_sw_qsort_SequenceDB +void bp_sw_sort_SequenceDB(SequenceDB * obj,int (*comp)(FileSource *, FileSource *)); +#define sort_SequenceDB bp_sw_sort_SequenceDB +boolean bp_sw_expand_SequenceDB(SequenceDB * obj,int len); +#define expand_SequenceDB bp_sw_expand_SequenceDB + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/sw.h b/Bio/Ext/Align/libs/sw.h new file mode 100644 index 0000000..03b9cd7 --- /dev/null +++ b/Bio/Ext/Align/libs/sw.h @@ -0,0 +1,6963 @@ + +#include + +typedef char aa; +typedef int base; +typedef double Probability; +typedef double Bits; +typedef int Score; +typedef int codon; +typedef int boolean; + +#define WISE2_FATAL 1 +#define WISE2_WARNING 2 +#define WISE2_INFO 8 +#define WISE2_REPORT 16 + + +char * bp_sw_stringalloc(char *); +void bp_sw_error_off(int type); +void bp_sw_error_on(int type); + +typedef struct bp_sw_AlnBlock bp_sw_AlnBlock; + +typedef struct bp_sw_AlnColumn bp_sw_AlnColumn; + +typedef struct bp_sw_AlnUnit bp_sw_AlnUnit; + +typedef struct bp_sw_AlnSequence bp_sw_AlnSequence; + +typedef struct bp_sw_AlnRangeSet bp_sw_AlnRangeSet; + +typedef struct bp_sw_AlnRange bp_sw_AlnRange; + +typedef struct bp_sw_cDNA bp_sw_cDNA; + +typedef struct bp_sw_cDNADB bp_sw_cDNADB; + +typedef struct bp_sw_CodonTable bp_sw_CodonTable; + +typedef struct bp_sw_CodonMapper bp_sw_CodonMapper; + +typedef struct bp_sw_ComplexSequence bp_sw_ComplexSequence; + +typedef struct bp_sw_ComplexSequenceEvalSet bp_sw_ComplexSequenceEvalSet; + +typedef struct bp_sw_CompMat bp_sw_CompMat; + +typedef struct bp_sw_Gene bp_sw_Gene; + +typedef struct bp_sw_Genomic bp_sw_Genomic; + +typedef struct bp_sw_GenomicDB bp_sw_GenomicDB; + +typedef struct bp_sw_GenomicRegion bp_sw_GenomicRegion; + +typedef struct bp_sw_Histogram bp_sw_Histogram; + +typedef struct bp_sw_Hscore bp_sw_Hscore; + +typedef struct bp_sw_DataScore bp_sw_DataScore; + +typedef struct bp_sw_DataEntry bp_sw_DataEntry; + +typedef struct bp_sw_PackAln bp_sw_PackAln; + +typedef struct bp_sw_PackAlnUnit bp_sw_PackAlnUnit; + +typedef struct bp_sw_Protein bp_sw_Protein; + +typedef struct bp_sw_ProteinDB bp_sw_ProteinDB; + +typedef struct bp_sw_Sequence bp_sw_Sequence; + +typedef struct bp_sw_SequenceDB bp_sw_SequenceDB; + +typedef struct bp_sw_FileSource bp_sw_FileSource; + +typedef struct bp_sw_Exon bp_sw_Exon; + +typedef struct bp_sw_Transcript bp_sw_Transcript; + +typedef struct bp_sw_Translation bp_sw_Translation; + + + +/* Functions that create, manipulate or act on AlnBlock + * + * bp_sw_bit_ascii_AlnBlock + * bp_sw_dump_ascii_AlnBlock + * bp_sw_hard_link_AlnBlock + * bp_sw_AlnBlock_alloc_std + * bp_sw_replace_start_AlnBlock + * bp_sw_access_start_AlnBlock + * bp_sw_access_seq_AlnBlock + * bp_sw_length_seq_AlnBlock + * bp_sw_flush_AlnBlock + * bp_sw_add_AlnBlock + * bp_sw_replace_length_AlnBlock + * bp_sw_access_length_AlnBlock + * bp_sw_replace_score_AlnBlock + * bp_sw_access_score_AlnBlock + * bp_sw_free_AlnBlock [destructor] + * + */ + + + +/* Functions that create, manipulate or act on AlnColumn + * + * bp_sw_at_end_AlnColumn + * bp_sw_hard_link_AlnColumn + * bp_sw_AlnColumn_alloc_std + * bp_sw_access_alu_AlnColumn + * bp_sw_length_alu_AlnColumn + * bp_sw_flush_AlnColumn + * bp_sw_add_AlnColumn + * bp_sw_replace_next_AlnColumn + * bp_sw_access_next_AlnColumn + * bp_sw_free_AlnColumn [destructor] + * + */ + + + +/* Functions that create, manipulate or act on AlnUnit + * + * bp_sw_bio_start_AlnUnit + * bp_sw_bio_end_AlnUnit + * bp_sw_hard_link_AlnUnit + * bp_sw_AlnUnit_alloc + * bp_sw_replace_start_AlnUnit + * bp_sw_access_start_AlnUnit + * bp_sw_replace_end_AlnUnit + * bp_sw_access_end_AlnUnit + * bp_sw_replace_label_AlnUnit + * bp_sw_access_label_AlnUnit + * bp_sw_replace_text_label_AlnUnit + * bp_sw_access_text_label_AlnUnit + * bp_sw_replace_next_AlnUnit + * bp_sw_access_next_AlnUnit + * bp_sw_replace_in_column_AlnUnit + * bp_sw_access_in_column_AlnUnit + * bp_sw_replace_seq_AlnUnit + * bp_sw_access_seq_AlnUnit + * bp_sw_free_AlnUnit [destructor] + * + */ + + + +/* Functions that create, manipulate or act on AlnSequence + * + * bp_sw_hard_link_AlnSequence + * bp_sw_AlnSequence_alloc + * bp_sw_replace_start_AlnSequence + * bp_sw_access_start_AlnSequence + * bp_sw_replace_data_type_AlnSequence + * bp_sw_access_data_type_AlnSequence + * bp_sw_replace_data_AlnSequence + * bp_sw_access_data_AlnSequence + * bp_sw_replace_bio_start_AlnSequence + * bp_sw_access_bio_start_AlnSequence + * bp_sw_replace_bio_end_AlnSequence + * bp_sw_access_bio_end_AlnSequence + * bp_sw_free_AlnSequence [destructor] + * + */ + +/* API for object AlnBlock */ +/* Function: bp_sw_bit_ascii_AlnBlock(alb,ofp) + * + * Descrip: Should not be here... + * + * + * Arg: alb AlnBlock to dump [bp_sw_AlnBlock *] + * Arg: ofp File stream to dump to [FILE *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_bit_ascii_AlnBlock( bp_sw_AlnBlock * alb,FILE * ofp); + +/* Function: bp_sw_dump_ascii_AlnBlock(alb,ofp) + * + * Descrip: Dumps the alignment in rereadable ascii form. + * + * Not really for human consumption + * + * + * Arg: alb AlnBlock to dump [bp_sw_AlnBlock *] + * Arg: ofp File stream to dump to [FILE *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_dump_ascii_AlnBlock( bp_sw_AlnBlock * alb,FILE * ofp); + +/* Function: bp_sw_hard_link_AlnBlock(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_AlnBlock *] + * + * Returns Undocumented return value [bp_sw_AlnBlock *] + * + */ +bp_sw_AlnBlock * bp_sw_hard_link_AlnBlock( bp_sw_AlnBlock * obj); + +/* Function: bp_sw_AlnBlock_alloc_std(void) + * + * Descrip: Equivalent to AlnBlock_alloc_len(AlnBlockLISTLENGTH) + * + * + * + * Returns Undocumented return value [bp_sw_AlnBlock *] + * + */ +bp_sw_AlnBlock * bp_sw_AlnBlock_alloc_std(); + +/* Function: bp_sw_replace_start_AlnBlock(obj,start) + * + * Descrip: Replace member variable start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnBlock *] + * Arg: start New value of the variable [bp_sw_AlnColumn *] + * + * Returns member variable start [boolean] + * + */ +boolean bp_sw_replace_start_AlnBlock( bp_sw_AlnBlock * obj,bp_sw_AlnColumn * start); + +/* Function: bp_sw_access_start_AlnBlock(obj) + * + * Descrip: Access member variable start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnBlock *] + * + * Returns member variable start [bp_sw_AlnColumn *] + * + */ +bp_sw_AlnColumn * bp_sw_access_start_AlnBlock( bp_sw_AlnBlock * obj); + +/* Function: bp_sw_access_seq_AlnBlock(obj,i) + * + * Descrip: Access members stored in the seq list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_AlnBlock *] + * Arg: i Position in the list [int] + * + * Returns Element of the list [bp_sw_AlnSequence *] + * + */ +bp_sw_AlnSequence * bp_sw_access_seq_AlnBlock( bp_sw_AlnBlock * obj,int i); + +/* Function: bp_sw_length_seq_AlnBlock(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_AlnBlock *] + * + * Returns length of the list [int] + * + */ +int bp_sw_length_seq_AlnBlock( bp_sw_AlnBlock * obj); + +/* Function: bp_sw_flush_AlnBlock(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj Object which contains the list [bp_sw_AlnBlock *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_flush_AlnBlock( bp_sw_AlnBlock * obj); + +/* Function: bp_sw_add_AlnBlock(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj Object which contains the list [bp_sw_AlnBlock *] + * Arg: add Object to add to the list [bp_sw_AlnSequence *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_add_AlnBlock( bp_sw_AlnBlock * obj,bp_sw_AlnSequence * add); + +/* Function: bp_sw_replace_length_AlnBlock(obj,length) + * + * Descrip: Replace member variable length + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnBlock *] + * Arg: length New value of the variable [int] + * + * Returns member variable length [boolean] + * + */ +boolean bp_sw_replace_length_AlnBlock( bp_sw_AlnBlock * obj,int length); + +/* Function: bp_sw_access_length_AlnBlock(obj) + * + * Descrip: Access member variable length + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnBlock *] + * + * Returns member variable length [int] + * + */ +int bp_sw_access_length_AlnBlock( bp_sw_AlnBlock * obj); + +/* Function: bp_sw_replace_score_AlnBlock(obj,score) + * + * Descrip: Replace member variable score + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnBlock *] + * Arg: score New value of the variable [int] + * + * Returns member variable score [boolean] + * + */ +boolean bp_sw_replace_score_AlnBlock( bp_sw_AlnBlock * obj,int score); + +/* Function: bp_sw_access_score_AlnBlock(obj) + * + * Descrip: Access member variable score + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnBlock *] + * + * Returns member variable score [int] + * + */ +int bp_sw_access_score_AlnBlock( bp_sw_AlnBlock * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_AlnBlock(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_AlnBlock *] + * + * Returns Undocumented return value [bp_sw_AlnBlock *] + * + */ +bp_sw_AlnBlock * bp_sw_free_AlnBlock( bp_sw_AlnBlock * obj); + +/* API for object AlnColumn */ +/* Function: bp_sw_at_end_AlnColumn(alc) + * + * Descrip: This tells you whether the AlnColumn is at the + * end without passing NULL's around + * + * + * + * Arg: alc AlnColumn [bp_sw_AlnColumn *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_at_end_AlnColumn( bp_sw_AlnColumn * alc); + +/* Function: bp_sw_hard_link_AlnColumn(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_AlnColumn *] + * + * Returns Undocumented return value [bp_sw_AlnColumn *] + * + */ +bp_sw_AlnColumn * bp_sw_hard_link_AlnColumn( bp_sw_AlnColumn * obj); + +/* Function: bp_sw_AlnColumn_alloc_std(void) + * + * Descrip: Equivalent to AlnColumn_alloc_len(AlnColumnLISTLENGTH) + * + * + * + * Returns Undocumented return value [bp_sw_AlnColumn *] + * + */ +bp_sw_AlnColumn * bp_sw_AlnColumn_alloc_std(); + +/* Function: bp_sw_access_alu_AlnColumn(obj,i) + * + * Descrip: Access members stored in the alu list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_AlnColumn *] + * Arg: i Position in the list [int] + * + * Returns Element of the list [bp_sw_AlnUnit *] + * + */ +bp_sw_AlnUnit * bp_sw_access_alu_AlnColumn( bp_sw_AlnColumn * obj,int i); + +/* Function: bp_sw_length_alu_AlnColumn(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_AlnColumn *] + * + * Returns length of the list [int] + * + */ +int bp_sw_length_alu_AlnColumn( bp_sw_AlnColumn * obj); + +/* Function: bp_sw_flush_AlnColumn(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj Object which contains the list [bp_sw_AlnColumn *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_flush_AlnColumn( bp_sw_AlnColumn * obj); + +/* Function: bp_sw_add_AlnColumn(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj Object which contains the list [bp_sw_AlnColumn *] + * Arg: add Object to add to the list [bp_sw_AlnUnit *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_add_AlnColumn( bp_sw_AlnColumn * obj,bp_sw_AlnUnit * add); + +/* Function: bp_sw_replace_next_AlnColumn(obj,next) + * + * Descrip: Replace member variable next + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnColumn *] + * Arg: next New value of the variable [bp_sw_AlnColumn *] + * + * Returns member variable next [boolean] + * + */ +boolean bp_sw_replace_next_AlnColumn( bp_sw_AlnColumn * obj,bp_sw_AlnColumn * next); + +/* Function: bp_sw_access_next_AlnColumn(obj) + * + * Descrip: Access member variable next + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnColumn *] + * + * Returns member variable next [bp_sw_AlnColumn *] + * + */ +bp_sw_AlnColumn * bp_sw_access_next_AlnColumn( bp_sw_AlnColumn * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_AlnColumn(obj) + * + * Descrip: Specilased deconstructor needed because + * of linked list nature of the data structure + * + * + * Arg: obj Undocumented argument [bp_sw_AlnColumn *] + * + * Returns Undocumented return value [bp_sw_AlnColumn *] + * + */ +bp_sw_AlnColumn * bp_sw_free_AlnColumn( bp_sw_AlnColumn * obj); + +/* API for object AlnUnit */ +/* Function: bp_sw_bio_start_AlnUnit(alu) + * + * Descrip: Tells the bio-coordinate of the + * start point of this alnunit + * + * + * Arg: alu Undocumented argument [bp_sw_AlnUnit *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_bio_start_AlnUnit( bp_sw_AlnUnit * alu); + +/* Function: bp_sw_bio_end_AlnUnit(alu) + * + * Descrip: Tells the bio-coordinate of the + * end point of this alnunit + * + * + * Arg: alu Undocumented argument [bp_sw_AlnUnit *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_bio_end_AlnUnit( bp_sw_AlnUnit * alu); + +/* Function: bp_sw_hard_link_AlnUnit(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_AlnUnit *] + * + * Returns Undocumented return value [bp_sw_AlnUnit *] + * + */ +bp_sw_AlnUnit * bp_sw_hard_link_AlnUnit( bp_sw_AlnUnit * obj); + +/* Function: bp_sw_AlnUnit_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_AlnUnit *] + * + */ +bp_sw_AlnUnit * bp_sw_AlnUnit_alloc(); + +/* Function: bp_sw_replace_start_AlnUnit(obj,start) + * + * Descrip: Replace member variable start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * Arg: start New value of the variable [int] + * + * Returns member variable start [boolean] + * + */ +boolean bp_sw_replace_start_AlnUnit( bp_sw_AlnUnit * obj,int start); + +/* Function: bp_sw_access_start_AlnUnit(obj) + * + * Descrip: Access member variable start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * + * Returns member variable start [int] + * + */ +int bp_sw_access_start_AlnUnit( bp_sw_AlnUnit * obj); + +/* Function: bp_sw_replace_end_AlnUnit(obj,end) + * + * Descrip: Replace member variable end + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * Arg: end New value of the variable [int] + * + * Returns member variable end [boolean] + * + */ +boolean bp_sw_replace_end_AlnUnit( bp_sw_AlnUnit * obj,int end); + +/* Function: bp_sw_access_end_AlnUnit(obj) + * + * Descrip: Access member variable end + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * + * Returns member variable end [int] + * + */ +int bp_sw_access_end_AlnUnit( bp_sw_AlnUnit * obj); + +/* Function: bp_sw_replace_label_AlnUnit(obj,label) + * + * Descrip: Replace member variable label + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * Arg: label New value of the variable [int] + * + * Returns member variable label [boolean] + * + */ +boolean bp_sw_replace_label_AlnUnit( bp_sw_AlnUnit * obj,int label); + +/* Function: bp_sw_access_label_AlnUnit(obj) + * + * Descrip: Access member variable label + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * + * Returns member variable label [int] + * + */ +int bp_sw_access_label_AlnUnit( bp_sw_AlnUnit * obj); + +/* Function: bp_sw_replace_text_label_AlnUnit(obj,text_label) + * + * Descrip: Replace member variable text_label + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * Arg: text_label New value of the variable [char *] + * + * Returns member variable text_label [boolean] + * + */ +boolean bp_sw_replace_text_label_AlnUnit( bp_sw_AlnUnit * obj,char * text_label); + +/* Function: bp_sw_access_text_label_AlnUnit(obj) + * + * Descrip: Access member variable text_label + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * + * Returns member variable text_label [char *] + * + */ +char * bp_sw_access_text_label_AlnUnit( bp_sw_AlnUnit * obj); + +/* Function: bp_sw_replace_next_AlnUnit(obj,next) + * + * Descrip: Replace member variable next + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * Arg: next New value of the variable [bp_sw_AlnUnit *] + * + * Returns member variable next [boolean] + * + */ +boolean bp_sw_replace_next_AlnUnit( bp_sw_AlnUnit * obj,bp_sw_AlnUnit * next); + +/* Function: bp_sw_access_next_AlnUnit(obj) + * + * Descrip: Access member variable next + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * + * Returns member variable next [bp_sw_AlnUnit *] + * + */ +bp_sw_AlnUnit * bp_sw_access_next_AlnUnit( bp_sw_AlnUnit * obj); + +/* Function: bp_sw_replace_in_column_AlnUnit(obj,in_column) + * + * Descrip: Replace member variable in_column + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * Arg: in_column New value of the variable [boolean] + * + * Returns member variable in_column [boolean] + * + */ +boolean bp_sw_replace_in_column_AlnUnit( bp_sw_AlnUnit * obj,boolean in_column); + +/* Function: bp_sw_access_in_column_AlnUnit(obj) + * + * Descrip: Access member variable in_column + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * + * Returns member variable in_column [boolean] + * + */ +boolean bp_sw_access_in_column_AlnUnit( bp_sw_AlnUnit * obj); + +/* Function: bp_sw_replace_seq_AlnUnit(obj,seq) + * + * Descrip: Replace member variable seq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * Arg: seq New value of the variable [bp_sw_AlnSequence *] + * + * Returns member variable seq [boolean] + * + */ +boolean bp_sw_replace_seq_AlnUnit( bp_sw_AlnUnit * obj,bp_sw_AlnSequence * seq); + +/* Function: bp_sw_access_seq_AlnUnit(obj) + * + * Descrip: Access member variable seq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnUnit *] + * + * Returns member variable seq [bp_sw_AlnSequence *] + * + */ +bp_sw_AlnSequence * bp_sw_access_seq_AlnUnit( bp_sw_AlnUnit * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_AlnUnit(obj) + * + * Descrip: Specilased deconstructor needed because + * of linked list nature of the data structure + * + * + * Arg: obj Undocumented argument [bp_sw_AlnUnit *] + * + * Returns Undocumented return value [bp_sw_AlnUnit *] + * + */ +bp_sw_AlnUnit * bp_sw_free_AlnUnit( bp_sw_AlnUnit * obj); + +/* API for object AlnSequence */ +/* Function: bp_sw_hard_link_AlnSequence(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_AlnSequence *] + * + * Returns Undocumented return value [bp_sw_AlnSequence *] + * + */ +bp_sw_AlnSequence * bp_sw_hard_link_AlnSequence( bp_sw_AlnSequence * obj); + +/* Function: bp_sw_AlnSequence_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_AlnSequence *] + * + */ +bp_sw_AlnSequence * bp_sw_AlnSequence_alloc(); + +/* Function: bp_sw_replace_start_AlnSequence(obj,start) + * + * Descrip: Replace member variable start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnSequence *] + * Arg: start New value of the variable [bp_sw_AlnUnit *] + * + * Returns member variable start [boolean] + * + */ +boolean bp_sw_replace_start_AlnSequence( bp_sw_AlnSequence * obj,bp_sw_AlnUnit * start); + +/* Function: bp_sw_access_start_AlnSequence(obj) + * + * Descrip: Access member variable start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnSequence *] + * + * Returns member variable start [bp_sw_AlnUnit *] + * + */ +bp_sw_AlnUnit * bp_sw_access_start_AlnSequence( bp_sw_AlnSequence * obj); + +/* Function: bp_sw_replace_data_type_AlnSequence(obj,data_type) + * + * Descrip: Replace member variable data_type + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnSequence *] + * Arg: data_type New value of the variable [int] + * + * Returns member variable data_type [boolean] + * + */ +boolean bp_sw_replace_data_type_AlnSequence( bp_sw_AlnSequence * obj,int data_type); + +/* Function: bp_sw_access_data_type_AlnSequence(obj) + * + * Descrip: Access member variable data_type + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnSequence *] + * + * Returns member variable data_type [int] + * + */ +int bp_sw_access_data_type_AlnSequence( bp_sw_AlnSequence * obj); + +/* Function: bp_sw_replace_data_AlnSequence(obj,data) + * + * Descrip: Replace member variable data + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnSequence *] + * Arg: data New value of the variable [void *] + * + * Returns member variable data [boolean] + * + */ +boolean bp_sw_replace_data_AlnSequence( bp_sw_AlnSequence * obj,void * data); + +/* Function: bp_sw_access_data_AlnSequence(obj) + * + * Descrip: Access member variable data + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnSequence *] + * + * Returns member variable data [void *] + * + */ +void * bp_sw_access_data_AlnSequence( bp_sw_AlnSequence * obj); + +/* Function: bp_sw_replace_bio_start_AlnSequence(obj,bio_start) + * + * Descrip: Replace member variable bio_start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnSequence *] + * Arg: bio_start New value of the variable [int] + * + * Returns member variable bio_start [boolean] + * + */ +boolean bp_sw_replace_bio_start_AlnSequence( bp_sw_AlnSequence * obj,int bio_start); + +/* Function: bp_sw_access_bio_start_AlnSequence(obj) + * + * Descrip: Access member variable bio_start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnSequence *] + * + * Returns member variable bio_start [int] + * + */ +int bp_sw_access_bio_start_AlnSequence( bp_sw_AlnSequence * obj); + +/* Function: bp_sw_replace_bio_end_AlnSequence(obj,bio_end) + * + * Descrip: Replace member variable bio_end + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnSequence *] + * Arg: bio_end New value of the variable [int] + * + * Returns member variable bio_end [boolean] + * + */ +boolean bp_sw_replace_bio_end_AlnSequence( bp_sw_AlnSequence * obj,int bio_end); + +/* Function: bp_sw_access_bio_end_AlnSequence(obj) + * + * Descrip: Access member variable bio_end + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnSequence *] + * + * Returns member variable bio_end [int] + * + */ +int bp_sw_access_bio_end_AlnSequence( bp_sw_AlnSequence * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_AlnSequence(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_AlnSequence *] + * + * Returns Undocumented return value [bp_sw_AlnSequence *] + * + */ +bp_sw_AlnSequence * bp_sw_free_AlnSequence( bp_sw_AlnSequence * obj); + + + +/* Functions that create, manipulate or act on AlnRangeSet + * + * bp_sw_hard_link_AlnRangeSet + * bp_sw_AlnRangeSet_alloc_std + * bp_sw_replace_score_AlnRangeSet + * bp_sw_access_score_AlnRangeSet + * bp_sw_access_alr_AlnRangeSet + * bp_sw_length_alr_AlnRangeSet + * bp_sw_flush_AlnRangeSet + * bp_sw_add_AlnRangeSet + * bp_sw_free_AlnRangeSet [destructor] + * + */ + + + +/* Functions that create, manipulate or act on AlnRange + * + * bp_sw_hard_link_AlnRange + * bp_sw_AlnRange_alloc + * bp_sw_replace_starti_AlnRange + * bp_sw_access_starti_AlnRange + * bp_sw_replace_startj_AlnRange + * bp_sw_access_startj_AlnRange + * bp_sw_replace_startstate_AlnRange + * bp_sw_access_startstate_AlnRange + * bp_sw_replace_stopi_AlnRange + * bp_sw_access_stopi_AlnRange + * bp_sw_replace_stopj_AlnRange + * bp_sw_access_stopj_AlnRange + * bp_sw_replace_stopstate_AlnRange + * bp_sw_access_stopstate_AlnRange + * bp_sw_replace_startscore_AlnRange + * bp_sw_access_startscore_AlnRange + * bp_sw_replace_stopscore_AlnRange + * bp_sw_access_stopscore_AlnRange + * bp_sw_free_AlnRange [destructor] + * + */ + +/* API for object AlnRangeSet */ +/* Function: bp_sw_hard_link_AlnRangeSet(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_AlnRangeSet *] + * + * Returns Undocumented return value [bp_sw_AlnRangeSet *] + * + */ +bp_sw_AlnRangeSet * bp_sw_hard_link_AlnRangeSet( bp_sw_AlnRangeSet * obj); + +/* Function: bp_sw_AlnRangeSet_alloc_std(void) + * + * Descrip: Equivalent to AlnRangeSet_alloc_len(AlnRangeSetLISTLENGTH) + * + * + * + * Returns Undocumented return value [bp_sw_AlnRangeSet *] + * + */ +bp_sw_AlnRangeSet * bp_sw_AlnRangeSet_alloc_std(); + +/* Function: bp_sw_replace_score_AlnRangeSet(obj,score) + * + * Descrip: Replace member variable score + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRangeSet *] + * Arg: score New value of the variable [int] + * + * Returns member variable score [boolean] + * + */ +boolean bp_sw_replace_score_AlnRangeSet( bp_sw_AlnRangeSet * obj,int score); + +/* Function: bp_sw_access_score_AlnRangeSet(obj) + * + * Descrip: Access member variable score + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRangeSet *] + * + * Returns member variable score [int] + * + */ +int bp_sw_access_score_AlnRangeSet( bp_sw_AlnRangeSet * obj); + +/* Function: bp_sw_access_alr_AlnRangeSet(obj,i) + * + * Descrip: Access members stored in the alr list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_AlnRangeSet *] + * Arg: i Position in the list [int] + * + * Returns Element of the list [bp_sw_AlnRange *] + * + */ +bp_sw_AlnRange * bp_sw_access_alr_AlnRangeSet( bp_sw_AlnRangeSet * obj,int i); + +/* Function: bp_sw_length_alr_AlnRangeSet(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_AlnRangeSet *] + * + * Returns length of the list [int] + * + */ +int bp_sw_length_alr_AlnRangeSet( bp_sw_AlnRangeSet * obj); + +/* Function: bp_sw_flush_AlnRangeSet(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj Object which contains the list [bp_sw_AlnRangeSet *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_flush_AlnRangeSet( bp_sw_AlnRangeSet * obj); + +/* Function: bp_sw_add_AlnRangeSet(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj Object which contains the list [bp_sw_AlnRangeSet *] + * Arg: add Object to add to the list [bp_sw_AlnRange *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_add_AlnRangeSet( bp_sw_AlnRangeSet * obj,bp_sw_AlnRange * add); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_AlnRangeSet(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_AlnRangeSet *] + * + * Returns Undocumented return value [bp_sw_AlnRangeSet *] + * + */ +bp_sw_AlnRangeSet * bp_sw_free_AlnRangeSet( bp_sw_AlnRangeSet * obj); + +/* API for object AlnRange */ +/* Function: bp_sw_hard_link_AlnRange(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_AlnRange *] + * + * Returns Undocumented return value [bp_sw_AlnRange *] + * + */ +bp_sw_AlnRange * bp_sw_hard_link_AlnRange( bp_sw_AlnRange * obj); + +/* Function: bp_sw_AlnRange_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_AlnRange *] + * + */ +bp_sw_AlnRange * bp_sw_AlnRange_alloc(); + +/* Function: bp_sw_replace_starti_AlnRange(obj,starti) + * + * Descrip: Replace member variable starti + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * Arg: starti New value of the variable [int] + * + * Returns member variable starti [boolean] + * + */ +boolean bp_sw_replace_starti_AlnRange( bp_sw_AlnRange * obj,int starti); + +/* Function: bp_sw_access_starti_AlnRange(obj) + * + * Descrip: Access member variable starti + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * + * Returns member variable starti [int] + * + */ +int bp_sw_access_starti_AlnRange( bp_sw_AlnRange * obj); + +/* Function: bp_sw_replace_startj_AlnRange(obj,startj) + * + * Descrip: Replace member variable startj + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * Arg: startj New value of the variable [int] + * + * Returns member variable startj [boolean] + * + */ +boolean bp_sw_replace_startj_AlnRange( bp_sw_AlnRange * obj,int startj); + +/* Function: bp_sw_access_startj_AlnRange(obj) + * + * Descrip: Access member variable startj + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * + * Returns member variable startj [int] + * + */ +int bp_sw_access_startj_AlnRange( bp_sw_AlnRange * obj); + +/* Function: bp_sw_replace_startstate_AlnRange(obj,startstate) + * + * Descrip: Replace member variable startstate + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * Arg: startstate New value of the variable [int] + * + * Returns member variable startstate [boolean] + * + */ +boolean bp_sw_replace_startstate_AlnRange( bp_sw_AlnRange * obj,int startstate); + +/* Function: bp_sw_access_startstate_AlnRange(obj) + * + * Descrip: Access member variable startstate + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * + * Returns member variable startstate [int] + * + */ +int bp_sw_access_startstate_AlnRange( bp_sw_AlnRange * obj); + +/* Function: bp_sw_replace_stopi_AlnRange(obj,stopi) + * + * Descrip: Replace member variable stopi + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * Arg: stopi New value of the variable [int] + * + * Returns member variable stopi [boolean] + * + */ +boolean bp_sw_replace_stopi_AlnRange( bp_sw_AlnRange * obj,int stopi); + +/* Function: bp_sw_access_stopi_AlnRange(obj) + * + * Descrip: Access member variable stopi + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * + * Returns member variable stopi [int] + * + */ +int bp_sw_access_stopi_AlnRange( bp_sw_AlnRange * obj); + +/* Function: bp_sw_replace_stopj_AlnRange(obj,stopj) + * + * Descrip: Replace member variable stopj + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * Arg: stopj New value of the variable [int] + * + * Returns member variable stopj [boolean] + * + */ +boolean bp_sw_replace_stopj_AlnRange( bp_sw_AlnRange * obj,int stopj); + +/* Function: bp_sw_access_stopj_AlnRange(obj) + * + * Descrip: Access member variable stopj + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * + * Returns member variable stopj [int] + * + */ +int bp_sw_access_stopj_AlnRange( bp_sw_AlnRange * obj); + +/* Function: bp_sw_replace_stopstate_AlnRange(obj,stopstate) + * + * Descrip: Replace member variable stopstate + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * Arg: stopstate New value of the variable [int] + * + * Returns member variable stopstate [boolean] + * + */ +boolean bp_sw_replace_stopstate_AlnRange( bp_sw_AlnRange * obj,int stopstate); + +/* Function: bp_sw_access_stopstate_AlnRange(obj) + * + * Descrip: Access member variable stopstate + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * + * Returns member variable stopstate [int] + * + */ +int bp_sw_access_stopstate_AlnRange( bp_sw_AlnRange * obj); + +/* Function: bp_sw_replace_startscore_AlnRange(obj,startscore) + * + * Descrip: Replace member variable startscore + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * Arg: startscore New value of the variable [int] + * + * Returns member variable startscore [boolean] + * + */ +boolean bp_sw_replace_startscore_AlnRange( bp_sw_AlnRange * obj,int startscore); + +/* Function: bp_sw_access_startscore_AlnRange(obj) + * + * Descrip: Access member variable startscore + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * + * Returns member variable startscore [int] + * + */ +int bp_sw_access_startscore_AlnRange( bp_sw_AlnRange * obj); + +/* Function: bp_sw_replace_stopscore_AlnRange(obj,stopscore) + * + * Descrip: Replace member variable stopscore + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * Arg: stopscore New value of the variable [int] + * + * Returns member variable stopscore [boolean] + * + */ +boolean bp_sw_replace_stopscore_AlnRange( bp_sw_AlnRange * obj,int stopscore); + +/* Function: bp_sw_access_stopscore_AlnRange(obj) + * + * Descrip: Access member variable stopscore + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_AlnRange *] + * + * Returns member variable stopscore [int] + * + */ +int bp_sw_access_stopscore_AlnRange( bp_sw_AlnRange * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_AlnRange(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_AlnRange *] + * + * Returns Undocumented return value [bp_sw_AlnRange *] + * + */ +bp_sw_AlnRange * bp_sw_free_AlnRange( bp_sw_AlnRange * obj); + + + +/* Helper functions in the module + * + * bp_sw_change_max_BaseMatrix_kbytes + * bp_sw_get_max_BaseMatrix_kbytes + * + + + +/* These functions are not associated with an object */ +/* Function: bp_sw_change_max_BaseMatrix_kbytes(new_kilo_number) + * + * Descrip: This is to change, at run-time the maximum level of bytes basematrix *thinks* + * it can use. This number is *not* used for any actual calls to basematrix + * allocation: it is only used with /get_max_BaseMatrix_kbytes + * + * + * Arg: new_kilo_number max kilobytes allowed [int] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_change_max_BaseMatrix_kbytes( int new_kilo_number); + +/* Function: bp_sw_get_max_BaseMatrix_kbytes(void) + * + * Descrip: returns the max. number of kilobytes suggested as a limited + * to BaseMatrix. + * + * + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_get_max_BaseMatrix_kbytes(); + + + +/* Functions that create, manipulate or act on cDNA + * + * bp_sw_truncate_cDNA + * bp_sw_read_fasta_file_cDNA + * bp_sw_cDNA_name + * bp_sw_cDNA_length + * bp_sw_cDNA_seqchar + * bp_sw_cDNA_from_Sequence + * bp_sw_hard_link_cDNA + * bp_sw_cDNA_alloc + * bp_sw_replace_baseseq_cDNA + * bp_sw_access_baseseq_cDNA + * bp_sw_free_cDNA [destructor] + * + */ + +/* API for object cDNA */ +/* Function: bp_sw_truncate_cDNA(cdna,start,stop) + * + * Descrip: Truncates a cDNA sequence. Basically uses + * the /magic_trunc_Sequence function (of course!) + * + * It does not alter cdna, rather it returns a new + * sequence with that truncation + * + * + * Arg: cdna cDNA that is truncated [bp_sw_cDNA *] + * Arg: start Undocumented argument [int] + * Arg: stop Undocumented argument [int] + * + * Returns Undocumented return value [bp_sw_cDNA *] + * + */ +bp_sw_cDNA * bp_sw_truncate_cDNA( bp_sw_cDNA * cdna,int start,int stop); + +/* Function: bp_sw_read_fasta_file_cDNA(filename) + * + * Descrip: Reads a fasta file assumming that it is cDNA. + * Will complain if it is not, and return NULL. + * + * + * Arg: filename filename to be opened and read [char *] + * + * Returns Undocumented return value [bp_sw_cDNA *] + * + */ +bp_sw_cDNA * bp_sw_read_fasta_file_cDNA( char * filename); + +/* Function: bp_sw_cDNA_name(cdna) + * + * Descrip: Returns the name of the cDNA + * + * + * Arg: cdna Undocumented argument [bp_sw_cDNA *] + * + * Returns Undocumented return value [char *] + * + */ +char * bp_sw_cDNA_name( bp_sw_cDNA * cdna); + +/* Function: bp_sw_cDNA_length(cdna) + * + * Descrip: Returns the length of the cDNA + * + * + * Arg: cdna Undocumented argument [bp_sw_cDNA *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_cDNA_length( bp_sw_cDNA * cdna); + +/* Function: bp_sw_cDNA_seqchar(cdna,pos) + * + * Descrip: Returns sequence character at this position. + * + * + * Arg: cdna cDNA [bp_sw_cDNA *] + * Arg: pos position in cDNA to get char [int] + * + * Returns Undocumented return value [char] + * + */ +char bp_sw_cDNA_seqchar( bp_sw_cDNA * cdna,int pos); + +/* Function: bp_sw_cDNA_from_Sequence(seq) + * + * Descrip: makes a new cDNA from a Sequence. It + * owns the Sequence memory, ie will attempt a /free_Sequence + * on the structure when /free_cDNA is called + * + * If you want to give this cDNA this Sequence and + * forget about it, then just hand it this sequence and set + * seq to NULL (no need to free it). If you intend to use + * the sequence object elsewhere outside of the cDNA datastructure + * then use cDNA_from_Sequence(/hard_link_Sequence(seq)) + * + * + * + * Arg: seq Sequence to make cDNA from [bp_sw_Sequence *] + * + * Returns Undocumented return value [bp_sw_cDNA *] + * + */ +bp_sw_cDNA * bp_sw_cDNA_from_Sequence( bp_sw_Sequence * seq); + +/* Function: bp_sw_hard_link_cDNA(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_cDNA *] + * + * Returns Undocumented return value [bp_sw_cDNA *] + * + */ +bp_sw_cDNA * bp_sw_hard_link_cDNA( bp_sw_cDNA * obj); + +/* Function: bp_sw_cDNA_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_cDNA *] + * + */ +bp_sw_cDNA * bp_sw_cDNA_alloc(); + +/* Function: bp_sw_replace_baseseq_cDNA(obj,baseseq) + * + * Descrip: Replace member variable baseseq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNA *] + * Arg: baseseq New value of the variable [bp_sw_Sequence *] + * + * Returns member variable baseseq [boolean] + * + */ +boolean bp_sw_replace_baseseq_cDNA( bp_sw_cDNA * obj,bp_sw_Sequence * baseseq); + +/* Function: bp_sw_access_baseseq_cDNA(obj) + * + * Descrip: Access member variable baseseq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNA *] + * + * Returns member variable baseseq [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_access_baseseq_cDNA( bp_sw_cDNA * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_cDNA(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_cDNA *] + * + * Returns Undocumented return value [bp_sw_cDNA *] + * + */ +bp_sw_cDNA * bp_sw_free_cDNA( bp_sw_cDNA * obj); + + + +/* Functions that create, manipulate or act on cDNADB + * + * bp_sw_get_cDNA_from_cDNADB + * bp_sw_hard_link_cDNADB + * bp_sw_cDNADB_alloc + * bp_sw_replace_is_single_seq_cDNADB + * bp_sw_access_is_single_seq_cDNADB + * bp_sw_replace_done_forward_cDNADB + * bp_sw_access_done_forward_cDNADB + * bp_sw_replace_forw_cDNADB + * bp_sw_access_forw_cDNADB + * bp_sw_replace_rev_cDNADB + * bp_sw_access_rev_cDNADB + * bp_sw_replace_sdb_cDNADB + * bp_sw_access_sdb_cDNADB + * bp_sw_replace_current_cDNADB + * bp_sw_access_current_cDNADB + * bp_sw_replace_cses_cDNADB + * bp_sw_access_cses_cDNADB + * bp_sw_free_cDNADB [destructor] + * + */ + + + +/* Helper functions in the module + * + * bp_sw_new_cDNADB_from_single_seq + * bp_sw_new_cDNADB + * + +/* API for object cDNADB */ +/* Function: bp_sw_get_cDNA_from_cDNADB(cdnadb,de) + * + * Descrip: Gets cDNA sequence out from + * the cDNADB using the information stored in + * dataentry + * + * + * Arg: cdnadb cDNA database [bp_sw_cDNADB *] + * Arg: de DataEntry information [bp_sw_DataEntry *] + * + * Returns Undocumented return value [bp_sw_cDNA *] + * + */ +bp_sw_cDNA * bp_sw_get_cDNA_from_cDNADB( bp_sw_cDNADB * cdnadb,bp_sw_DataEntry * de); + +/* Function: bp_sw_hard_link_cDNADB(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_cDNADB *] + * + * Returns Undocumented return value [bp_sw_cDNADB *] + * + */ +bp_sw_cDNADB * bp_sw_hard_link_cDNADB( bp_sw_cDNADB * obj); + +/* Function: bp_sw_cDNADB_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_cDNADB *] + * + */ +bp_sw_cDNADB * bp_sw_cDNADB_alloc(); + +/* Function: bp_sw_replace_is_single_seq_cDNADB(obj,is_single_seq) + * + * Descrip: Replace member variable is_single_seq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * Arg: is_single_seq New value of the variable [boolean] + * + * Returns member variable is_single_seq [boolean] + * + */ +boolean bp_sw_replace_is_single_seq_cDNADB( bp_sw_cDNADB * obj,boolean is_single_seq); + +/* Function: bp_sw_access_is_single_seq_cDNADB(obj) + * + * Descrip: Access member variable is_single_seq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * + * Returns member variable is_single_seq [boolean] + * + */ +boolean bp_sw_access_is_single_seq_cDNADB( bp_sw_cDNADB * obj); + +/* Function: bp_sw_replace_done_forward_cDNADB(obj,done_forward) + * + * Descrip: Replace member variable done_forward + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * Arg: done_forward New value of the variable [boolean] + * + * Returns member variable done_forward [boolean] + * + */ +boolean bp_sw_replace_done_forward_cDNADB( bp_sw_cDNADB * obj,boolean done_forward); + +/* Function: bp_sw_access_done_forward_cDNADB(obj) + * + * Descrip: Access member variable done_forward + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * + * Returns member variable done_forward [boolean] + * + */ +boolean bp_sw_access_done_forward_cDNADB( bp_sw_cDNADB * obj); + +/* Function: bp_sw_replace_forw_cDNADB(obj,forw) + * + * Descrip: Replace member variable forw + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * Arg: forw New value of the variable [bp_sw_ComplexSequence *] + * + * Returns member variable forw [boolean] + * + */ +boolean bp_sw_replace_forw_cDNADB( bp_sw_cDNADB * obj,bp_sw_ComplexSequence * forw); + +/* Function: bp_sw_access_forw_cDNADB(obj) + * + * Descrip: Access member variable forw + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * + * Returns member variable forw [bp_sw_ComplexSequence *] + * + */ +bp_sw_ComplexSequence * bp_sw_access_forw_cDNADB( bp_sw_cDNADB * obj); + +/* Function: bp_sw_replace_rev_cDNADB(obj,rev) + * + * Descrip: Replace member variable rev + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * Arg: rev New value of the variable [bp_sw_ComplexSequence *] + * + * Returns member variable rev [boolean] + * + */ +boolean bp_sw_replace_rev_cDNADB( bp_sw_cDNADB * obj,bp_sw_ComplexSequence * rev); + +/* Function: bp_sw_access_rev_cDNADB(obj) + * + * Descrip: Access member variable rev + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * + * Returns member variable rev [bp_sw_ComplexSequence *] + * + */ +bp_sw_ComplexSequence * bp_sw_access_rev_cDNADB( bp_sw_cDNADB * obj); + +/* Function: bp_sw_replace_sdb_cDNADB(obj,sdb) + * + * Descrip: Replace member variable sdb + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * Arg: sdb New value of the variable [bp_sw_SequenceDB *] + * + * Returns member variable sdb [boolean] + * + */ +boolean bp_sw_replace_sdb_cDNADB( bp_sw_cDNADB * obj,bp_sw_SequenceDB * sdb); + +/* Function: bp_sw_access_sdb_cDNADB(obj) + * + * Descrip: Access member variable sdb + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * + * Returns member variable sdb [bp_sw_SequenceDB *] + * + */ +bp_sw_SequenceDB * bp_sw_access_sdb_cDNADB( bp_sw_cDNADB * obj); + +/* Function: bp_sw_replace_current_cDNADB(obj,current) + * + * Descrip: Replace member variable current + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * Arg: current New value of the variable [bp_sw_Sequence *] + * + * Returns member variable current [boolean] + * + */ +boolean bp_sw_replace_current_cDNADB( bp_sw_cDNADB * obj,bp_sw_Sequence * current); + +/* Function: bp_sw_access_current_cDNADB(obj) + * + * Descrip: Access member variable current + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * + * Returns member variable current [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_access_current_cDNADB( bp_sw_cDNADB * obj); + +/* Function: bp_sw_replace_cses_cDNADB(obj,cses) + * + * Descrip: Replace member variable cses + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * Arg: cses New value of the variable [bp_sw_ComplexSequenceEvalSet *] + * + * Returns member variable cses [boolean] + * + */ +boolean bp_sw_replace_cses_cDNADB( bp_sw_cDNADB * obj,bp_sw_ComplexSequenceEvalSet * cses); + +/* Function: bp_sw_access_cses_cDNADB(obj) + * + * Descrip: Access member variable cses + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_cDNADB *] + * + * Returns member variable cses [bp_sw_ComplexSequenceEvalSet *] + * + */ +bp_sw_ComplexSequenceEvalSet * bp_sw_access_cses_cDNADB( bp_sw_cDNADB * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_cDNADB(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_cDNADB *] + * + * Returns Undocumented return value [bp_sw_cDNADB *] + * + */ +bp_sw_cDNADB * bp_sw_free_cDNADB( bp_sw_cDNADB * obj); + + + +/* These functions are not associated with an object */ +/* Function: bp_sw_new_cDNADB_from_single_seq(seq) + * + * Descrip: To make a new cDNA database + * from a single cDNA Sequence with a eval system + * + * + * Arg: seq sequence which as placed into cDNADB structure. [bp_sw_cDNA *] + * + * Returns Undocumented return value [bp_sw_cDNADB *] + * + */ +bp_sw_cDNADB * bp_sw_new_cDNADB_from_single_seq( bp_sw_cDNA * seq); + +/* Function: bp_sw_new_cDNADB(seqdb) + * + * Descrip: To make a new cDNA database + * + * + * Arg: seqdb sequence database [bp_sw_SequenceDB *] + * + * Returns Undocumented return value [bp_sw_cDNADB *] + * + */ +bp_sw_cDNADB * bp_sw_new_cDNADB( bp_sw_SequenceDB * seqdb); + + + +/* Functions that create, manipulate or act on CodonTable + * + * bp_sw_read_CodonTable_file + * bp_sw_read_CodonTable + * bp_sw_aminoacid_from_seq + * bp_sw_aminoacid_from_codon + * bp_sw_is_stop_codon + * bp_sw_is_valid_aminoacid + * bp_sw_hard_link_CodonTable + * bp_sw_CodonTable_alloc + * bp_sw_replace_name_CodonTable + * bp_sw_access_name_CodonTable + * bp_sw_free_CodonTable [destructor] + * + */ + + + +/* Helper functions in the module + * + * bp_sw_is_non_ambiguous_codon_seq + * bp_sw_codon_from_base4_codon + * bp_sw_base4_codon_from_codon + * bp_sw_has_random_bases + * bp_sw_permute_possible_random_bases + * bp_sw_base_from_codon + * bp_sw_codon_from_seq + * bp_sw_base4_codon_from_seq + * bp_sw_char_from_base + * bp_sw_base_from_char + * bp_sw_char_complement_base + * bp_sw_complement_base + * + +/* API for object CodonTable */ +/* Function: bp_sw_read_CodonTable_file(file) + * + * Descrip: Opens filename, reads it as if a Ewan style + * codon table and closes. + * + * + * Arg: file filename to open [char *] + * + * Returns A codon-table, NULL if error [bp_sw_CodonTable *] + * + */ +bp_sw_CodonTable * bp_sw_read_CodonTable_file( char * file); + +/* Function: bp_sw_read_CodonTable(ifp) + * + * Descrip: reads a codon table from a filestream in Ewan + * format. + * + * As Ewan format is really bad and has no start/stop + * this will effectively read to the end of the file. + * Ooops. + * + * + * Arg: ifp file input [FILE *] + * + * Returns Undocumented return value [bp_sw_CodonTable *] + * + */ +bp_sw_CodonTable * bp_sw_read_CodonTable( FILE * ifp); + +/* Function: bp_sw_aminoacid_from_seq(ct,seq) + * + * Descrip: Returns the amino acid for this position in the DNA sequence + * Takes the pointer +1 and +2 points. + * + * No error checks implemented. Probably a mistake ;) + * + * + * Arg: ct codon table [bp_sw_CodonTable *] + * Arg: seq pointer to DNA chars [char *] + * + * Returns an amino acid char (A-Z) [aa] + * + */ +aa bp_sw_aminoacid_from_seq( bp_sw_CodonTable * ct,char * seq); + +/* Function: bp_sw_aminoacid_from_codon(ct,c) + * + * Descrip: returns amino acid for this codon number (NB codon numbers 0-125) + * + * + * Arg: ct codon table [bp_sw_CodonTable *] + * Arg: c codon number [codon] + * + * Returns aminoacid that is this codon (X for ambiguous, * for stop) [aa] + * + */ +aa bp_sw_aminoacid_from_codon( bp_sw_CodonTable * ct,codon c); + +/* Function: bp_sw_is_stop_codon(c,ct) + * + * Descrip: tells you whether this codon number is really a stop + * in this translation table + * + * + * Arg: c codon number [codon] + * Arg: ct codon table [bp_sw_CodonTable *] + * + * Returns TRUE if is stop, FALSE otherwise [boolean] + * + */ +boolean bp_sw_is_stop_codon( codon c,bp_sw_CodonTable * ct); + +/* Function: bp_sw_is_valid_aminoacid(ct,c) + * + * Descrip: Tells you if this letter (c) is recognised as a valid amino acid + * in this codon table + * + * + * Arg: ct Codon Table [bp_sw_CodonTable *] + * Arg: c aminoacid [char] + * + * Returns TRUE if valid, FALSE if not. [boolean] + * + */ +boolean bp_sw_is_valid_aminoacid( bp_sw_CodonTable * ct,char c); + +/* Function: bp_sw_hard_link_CodonTable(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_CodonTable *] + * + * Returns Undocumented return value [bp_sw_CodonTable *] + * + */ +bp_sw_CodonTable * bp_sw_hard_link_CodonTable( bp_sw_CodonTable * obj); + +/* Function: bp_sw_CodonTable_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_CodonTable *] + * + */ +bp_sw_CodonTable * bp_sw_CodonTable_alloc(); + +/* Function: bp_sw_replace_name_CodonTable(obj,name) + * + * Descrip: Replace member variable name + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_CodonTable *] + * Arg: name New value of the variable [char *] + * + * Returns member variable name [boolean] + * + */ +boolean bp_sw_replace_name_CodonTable( bp_sw_CodonTable * obj,char * name); + +/* Function: bp_sw_access_name_CodonTable(obj) + * + * Descrip: Access member variable name + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_CodonTable *] + * + * Returns member variable name [char *] + * + */ +char * bp_sw_access_name_CodonTable( bp_sw_CodonTable * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_CodonTable(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_CodonTable *] + * + * Returns Undocumented return value [bp_sw_CodonTable *] + * + */ +bp_sw_CodonTable * bp_sw_free_CodonTable( bp_sw_CodonTable * obj); + + + +/* These functions are not associated with an object */ +/* Function: bp_sw_is_non_ambiguous_codon_seq(seq) + * + * Descrip: Tells you if this codon is a real codon + * + * + * Arg: seq pointer to DNA sequence [char *] + * + * Returns TRUE if real codon, FALSE if contains N's [boolean] + * + */ +boolean bp_sw_is_non_ambiguous_codon_seq( char * seq); + +/* Function: bp_sw_codon_from_base4_codon(c) + * + * Descrip: maps a 0-63 codon to a 0-123 codon. Suprisingly useful. + * + * + * Arg: c Undocumented argument [int] + * + * Returns Undocumented return value [codon] + * + */ +codon bp_sw_codon_from_base4_codon( int c); + +/* Function: bp_sw_base4_codon_from_codon(c) + * + * Descrip: maps a 0-125 codon to a 0-63 codon. + * + * If ambiguous then returns 64 having issued a warning. + * + * + * Arg: c codon 0-125 [codon] + * + * Returns base 4 codon (0-63) [int] + * + */ +int bp_sw_base4_codon_from_codon( codon c); + +/* Function: bp_sw_has_random_bases(c) + * + * Descrip: Tests to see if this codon number has any N's in it + * + * + * Arg: c codon number 0-124 [codon] + * + * Returns TRUE if has N's , FALSE otherwise [boolean] + * + */ +boolean bp_sw_has_random_bases( codon c); + +/* Function: bp_sw_permute_possible_random_bases(c,one,two,three) + * + * Descrip: Bizarely useful function for calculating ambiguity scores. + * + * This takes the codon c, and for each possible base, + * if it is N, replaces it with one, two or three. + * + * If the base is not N, it remains the same + * + * + * Arg: c codon number [codon] + * Arg: one base to replace first position if N [base] + * Arg: two base to replace second position if N [base] + * Arg: three base to replace third position if N [base] + * + * Returns codon number [codon] + * + */ +codon bp_sw_permute_possible_random_bases( codon c,base one,base two,base three); + +/* Function: bp_sw_base_from_codon(c,pos) + * + * Descrip: Probably not the best function to use for this, but + * useful. Takes a codon and with pos being 1,2,3 gives + * you the firt,second of third base + * + * + * Arg: c Undocumented argument [codon] + * Arg: pos Undocumented argument [int] + * + * Returns Undocumented return value [base] + * + */ +base bp_sw_base_from_codon( codon c,int pos); + +/* Function: bp_sw_codon_from_seq(seq) + * + * Descrip: takes an ASCII coded pointer to a 3 base pair + * sequence (it could be the part of a sequence: it only + * assummes that the seq points with 3 chars at pos 0,1,2 + * in C coordinates from seq. No NULL is required). It + * ives back the codon as made from standard mapping, ie, + * 25*base_1+5*base_2 + base3 being a number from 0-124 inc. + * + * + * Arg: seq pointer to sequence of at least 3 chrs long. [char *] + * + * Returns Undocumented return value [codon] + * + */ +codon bp_sw_codon_from_seq( char * seq); + +/* Function: bp_sw_base4_codon_from_seq(seq) + * + * Descrip: Sometimes it is more useful to work in base64, ie, + * non N. this functions does the same thing as + * /codon_from_seq but produces a seq being + * 16*base1 + 4 *base2 + base3 + * + * + * Arg: seq pointer to sequence of at least 3 chrs long [char *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_base4_codon_from_seq( char * seq); + +/* Function: bp_sw_char_from_base(b) + * + * Descrip: maps a base number (-04 inc) to A,T,G,C,N + * + * + * Arg: b Undocumented argument [base] + * + * Returns Undocumented return value [char] + * + */ +char bp_sw_char_from_base( base b); + +/* Function: bp_sw_base_from_char(c) + * + * Descrip: maps a char (atcgn) to number, + * case insensitive, returns BASE_N + * if not atcgn + * + * + * Arg: c Undocumented argument [char] + * + * Returns Undocumented return value [base] + * + */ +base bp_sw_base_from_char( char c); + +/* Function: bp_sw_char_complement_base(c) + * + * Descrip: the char equivalent of /complement_base. + * this gives the complement in char of a base + * in char. Does not check for non ATGCN + * + * + * Arg: c Undocumented argument [char] + * + * Returns Undocumented return value [char] + * + */ +char bp_sw_char_complement_base( char c); + +/* Function: bp_sw_complement_base(b) + * + * Descrip: gives back the complement as a number + * ofthe base (given as a number) + * + * + * Arg: b Undocumented argument [base] + * + * Returns Undocumented return value [base] + * + */ +base bp_sw_complement_base( base b); + + + +/* Functions that create, manipulate or act on CodonMapper + * + * bp_sw_sprinkle_errors_over_CodonMapper + * bp_sw_hard_link_CodonMapper + * bp_sw_CodonMapper_alloc + * bp_sw_replace_ct_CodonMapper + * bp_sw_access_ct_CodonMapper + * bp_sw_free_CodonMapper [destructor] + * + */ + + + +/* Helper functions in the module + * + * bp_sw_flat_CodonMapper + * + +/* API for object CodonMapper */ +/* Function: bp_sw_sprinkle_errors_over_CodonMapper(cm,error) + * + * Descrip: Takes a codon mapper and assummes that the majority of errors + * are due to a single base change in the codon at probability error. + * Therefore, for each codon it adds error * prob(codon) * 0.25 to each + * other codon one base away, taking away therefore the result. + * + * + * + * Arg: cm CodonMapper to be sprinkled [bp_sw_CodonMapper *] + * Arg: error substitution error rate [double] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_sprinkle_errors_over_CodonMapper( bp_sw_CodonMapper * cm,double error); + +/* Function: bp_sw_hard_link_CodonMapper(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_CodonMapper *] + * + * Returns Undocumented return value [bp_sw_CodonMapper *] + * + */ +bp_sw_CodonMapper * bp_sw_hard_link_CodonMapper( bp_sw_CodonMapper * obj); + +/* Function: bp_sw_CodonMapper_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_CodonMapper *] + * + */ +bp_sw_CodonMapper * bp_sw_CodonMapper_alloc(); + +/* Function: bp_sw_replace_ct_CodonMapper(obj,ct) + * + * Descrip: Replace member variable ct + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_CodonMapper *] + * Arg: ct New value of the variable [bp_sw_CodonTable *] + * + * Returns member variable ct [boolean] + * + */ +boolean bp_sw_replace_ct_CodonMapper( bp_sw_CodonMapper * obj,bp_sw_CodonTable * ct); + +/* Function: bp_sw_access_ct_CodonMapper(obj) + * + * Descrip: Access member variable ct + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_CodonMapper *] + * + * Returns member variable ct [bp_sw_CodonTable *] + * + */ +bp_sw_CodonTable * bp_sw_access_ct_CodonMapper( bp_sw_CodonMapper * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_CodonMapper(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_CodonMapper *] + * + * Returns Undocumented return value [bp_sw_CodonMapper *] + * + */ +bp_sw_CodonMapper * bp_sw_free_CodonMapper( bp_sw_CodonMapper * obj); + + + +/* These functions are not associated with an object */ +/* Function: bp_sw_flat_CodonMapper(ct) + * + * Descrip: Makes a CodonMapper with no codon bias + * or error possiblities from codon table + * + * + * + * Arg: ct Codon Table giving codon->aa info [bp_sw_CodonTable *] + * + * Returns Undocumented return value [bp_sw_CodonMapper *] + * + */ +bp_sw_CodonMapper * bp_sw_flat_CodonMapper( bp_sw_CodonTable * ct); + + + +/* Functions that create, manipulate or act on ComplexSequence + * + * bp_sw_hard_link_ComplexSequence + * bp_sw_ComplexSequence_alloc + * bp_sw_replace_type_ComplexSequence + * bp_sw_access_type_ComplexSequence + * bp_sw_replace_seq_ComplexSequence + * bp_sw_access_seq_ComplexSequence + * bp_sw_free_ComplexSequence [destructor] + * + */ + + + +/* Functions that create, manipulate or act on ComplexSequenceEvalSet + * + * bp_sw_hard_link_ComplexSequenceEvalSet + * bp_sw_ComplexSequenceEvalSet_alloc_std + * bp_sw_replace_type_ComplexSequenceEvalSet + * bp_sw_access_type_ComplexSequenceEvalSet + * bp_sw_replace_has_been_prepared_ComplexSequenceEvalSet + * bp_sw_access_has_been_prepared_ComplexSequenceEvalSet + * bp_sw_replace_left_window_ComplexSequenceEvalSet + * bp_sw_access_left_window_ComplexSequenceEvalSet + * bp_sw_replace_right_window_ComplexSequenceEvalSet + * bp_sw_access_right_window_ComplexSequenceEvalSet + * bp_sw_replace_left_lookback_ComplexSequenceEvalSet + * bp_sw_access_left_lookback_ComplexSequenceEvalSet + * bp_sw_free_ComplexSequenceEvalSet [destructor] + * + */ + +/* API for object ComplexSequence */ +/* Function: bp_sw_hard_link_ComplexSequence(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_ComplexSequence *] + * + * Returns Undocumented return value [bp_sw_ComplexSequence *] + * + */ +bp_sw_ComplexSequence * bp_sw_hard_link_ComplexSequence( bp_sw_ComplexSequence * obj); + +/* Function: bp_sw_ComplexSequence_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_ComplexSequence *] + * + */ +bp_sw_ComplexSequence * bp_sw_ComplexSequence_alloc(); + +/* Function: bp_sw_replace_type_ComplexSequence(obj,type) + * + * Descrip: Replace member variable type + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequence *] + * Arg: type New value of the variable [int] + * + * Returns member variable type [boolean] + * + */ +boolean bp_sw_replace_type_ComplexSequence( bp_sw_ComplexSequence * obj,int type); + +/* Function: bp_sw_access_type_ComplexSequence(obj) + * + * Descrip: Access member variable type + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequence *] + * + * Returns member variable type [int] + * + */ +int bp_sw_access_type_ComplexSequence( bp_sw_ComplexSequence * obj); + +/* Function: bp_sw_replace_seq_ComplexSequence(obj,seq) + * + * Descrip: Replace member variable seq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequence *] + * Arg: seq New value of the variable [bp_sw_Sequence *] + * + * Returns member variable seq [boolean] + * + */ +boolean bp_sw_replace_seq_ComplexSequence( bp_sw_ComplexSequence * obj,bp_sw_Sequence * seq); + +/* Function: bp_sw_access_seq_ComplexSequence(obj) + * + * Descrip: Access member variable seq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequence *] + * + * Returns member variable seq [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_access_seq_ComplexSequence( bp_sw_ComplexSequence * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_ComplexSequence(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_ComplexSequence *] + * + * Returns Undocumented return value [bp_sw_ComplexSequence *] + * + */ +bp_sw_ComplexSequence * bp_sw_free_ComplexSequence( bp_sw_ComplexSequence * obj); + +/* API for object ComplexSequenceEvalSet */ +/* Function: bp_sw_hard_link_ComplexSequenceEvalSet(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_ComplexSequenceEvalSet *] + * + * Returns Undocumented return value [bp_sw_ComplexSequenceEvalSet *] + * + */ +bp_sw_ComplexSequenceEvalSet * bp_sw_hard_link_ComplexSequenceEvalSet( bp_sw_ComplexSequenceEvalSet * obj); + +/* Function: bp_sw_ComplexSequenceEvalSet_alloc_std(void) + * + * Descrip: Equivalent to ComplexSequenceEvalSet_alloc_len(ComplexSequenceEvalSetLISTLENGTH) + * + * + * + * Returns Undocumented return value [bp_sw_ComplexSequenceEvalSet *] + * + */ +bp_sw_ComplexSequenceEvalSet * bp_sw_ComplexSequenceEvalSet_alloc_std(); + +/* Function: bp_sw_replace_type_ComplexSequenceEvalSet(obj,type) + * + * Descrip: Replace member variable type + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequenceEvalSet *] + * Arg: type New value of the variable [int] + * + * Returns member variable type [boolean] + * + */ +boolean bp_sw_replace_type_ComplexSequenceEvalSet( bp_sw_ComplexSequenceEvalSet * obj,int type); + +/* Function: bp_sw_access_type_ComplexSequenceEvalSet(obj) + * + * Descrip: Access member variable type + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequenceEvalSet *] + * + * Returns member variable type [int] + * + */ +int bp_sw_access_type_ComplexSequenceEvalSet( bp_sw_ComplexSequenceEvalSet * obj); + +/* Function: bp_sw_replace_has_been_prepared_ComplexSequenceEvalSet(obj,has_been_prepared) + * + * Descrip: Replace member variable has_been_prepared + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequenceEvalSet *] + * Arg: has_been_prepared New value of the variable [boolean] + * + * Returns member variable has_been_prepared [boolean] + * + */ +boolean bp_sw_replace_has_been_prepared_ComplexSequenceEvalSet( bp_sw_ComplexSequenceEvalSet * obj,boolean has_been_prepared); + +/* Function: bp_sw_access_has_been_prepared_ComplexSequenceEvalSet(obj) + * + * Descrip: Access member variable has_been_prepared + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequenceEvalSet *] + * + * Returns member variable has_been_prepared [boolean] + * + */ +boolean bp_sw_access_has_been_prepared_ComplexSequenceEvalSet( bp_sw_ComplexSequenceEvalSet * obj); + +/* Function: bp_sw_replace_left_window_ComplexSequenceEvalSet(obj,left_window) + * + * Descrip: Replace member variable left_window + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequenceEvalSet *] + * Arg: left_window New value of the variable [int] + * + * Returns member variable left_window [boolean] + * + */ +boolean bp_sw_replace_left_window_ComplexSequenceEvalSet( bp_sw_ComplexSequenceEvalSet * obj,int left_window); + +/* Function: bp_sw_access_left_window_ComplexSequenceEvalSet(obj) + * + * Descrip: Access member variable left_window + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequenceEvalSet *] + * + * Returns member variable left_window [int] + * + */ +int bp_sw_access_left_window_ComplexSequenceEvalSet( bp_sw_ComplexSequenceEvalSet * obj); + +/* Function: bp_sw_replace_right_window_ComplexSequenceEvalSet(obj,right_window) + * + * Descrip: Replace member variable right_window + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequenceEvalSet *] + * Arg: right_window New value of the variable [int] + * + * Returns member variable right_window [boolean] + * + */ +boolean bp_sw_replace_right_window_ComplexSequenceEvalSet( bp_sw_ComplexSequenceEvalSet * obj,int right_window); + +/* Function: bp_sw_access_right_window_ComplexSequenceEvalSet(obj) + * + * Descrip: Access member variable right_window + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequenceEvalSet *] + * + * Returns member variable right_window [int] + * + */ +int bp_sw_access_right_window_ComplexSequenceEvalSet( bp_sw_ComplexSequenceEvalSet * obj); + +/* Function: bp_sw_replace_left_lookback_ComplexSequenceEvalSet(obj,left_lookback) + * + * Descrip: Replace member variable left_lookback + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequenceEvalSet *] + * Arg: left_lookback New value of the variable [int] + * + * Returns member variable left_lookback [boolean] + * + */ +boolean bp_sw_replace_left_lookback_ComplexSequenceEvalSet( bp_sw_ComplexSequenceEvalSet * obj,int left_lookback); + +/* Function: bp_sw_access_left_lookback_ComplexSequenceEvalSet(obj) + * + * Descrip: Access member variable left_lookback + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ComplexSequenceEvalSet *] + * + * Returns member variable left_lookback [int] + * + */ +int bp_sw_access_left_lookback_ComplexSequenceEvalSet( bp_sw_ComplexSequenceEvalSet * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_ComplexSequenceEvalSet(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_ComplexSequenceEvalSet *] + * + * Returns Undocumented return value [bp_sw_ComplexSequenceEvalSet *] + * + */ +bp_sw_ComplexSequenceEvalSet * bp_sw_free_ComplexSequenceEvalSet( bp_sw_ComplexSequenceEvalSet * obj); + + + +/* Functions that create, manipulate or act on CompMat + * + * bp_sw_fail_safe_CompMat_access + * bp_sw_write_Blast_CompMat + * bp_sw_read_Blast_file_CompMat + * bp_sw_read_Blast_CompMat + * bp_sw_hard_link_CompMat + * bp_sw_CompMat_alloc + * bp_sw_replace_name_CompMat + * bp_sw_access_name_CompMat + * bp_sw_free_CompMat [destructor] + * + */ + +/* API for object CompMat */ +/* Function: bp_sw_fail_safe_CompMat_access(cm,aa1,aa2) + * + * Descrip: gives the fail form of the macro CompMat_AAMATCH which + * checks that aa1 and a2 are sensible and that cm is not NULL. + * + * + * Arg: cm compmat object [bp_sw_CompMat *] + * Arg: aa1 first amino acid [int] + * Arg: aa2 second amino acid [int] + * + * Returns Undocumented return value [Score] + * + */ +Score bp_sw_fail_safe_CompMat_access( bp_sw_CompMat * cm,int aa1,int aa2); + +/* Function: bp_sw_write_Blast_CompMat(cm,ofp) + * + * Descrip: writes a protien CompMat with a standard + * alphabet. + * + * + * Arg: cm CompMat object [bp_sw_CompMat *] + * Arg: ofp file to output [FILE *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_write_Blast_CompMat( bp_sw_CompMat * cm,FILE * ofp); + +/* Function: bp_sw_read_Blast_file_CompMat(filename) + * + * Descrip: Opens file, reads matrix, closes file. + * calls /read_Blast_CompMat for the actual format + * reading. Uses /openfile to open the file, + * so will open from config files. + * + * + * Arg: filename Undocumented argument [char *] + * + * Returns Undocumented return value [bp_sw_CompMat *] + * + */ +bp_sw_CompMat * bp_sw_read_Blast_file_CompMat( char * filename); + +/* Function: bp_sw_read_Blast_CompMat(ifp) + * + * Descrip: reads a BLAST format matrix and + * allocates a new ComMat structure. + * + * + * Arg: ifp Undocumented argument [FILE *] + * + * Returns Undocumented return value [bp_sw_CompMat *] + * + */ +bp_sw_CompMat * bp_sw_read_Blast_CompMat( FILE * ifp); + +/* Function: bp_sw_hard_link_CompMat(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_CompMat *] + * + * Returns Undocumented return value [bp_sw_CompMat *] + * + */ +bp_sw_CompMat * bp_sw_hard_link_CompMat( bp_sw_CompMat * obj); + +/* Function: bp_sw_CompMat_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_CompMat *] + * + */ +bp_sw_CompMat * bp_sw_CompMat_alloc(); + +/* Function: bp_sw_replace_name_CompMat(obj,name) + * + * Descrip: Replace member variable name + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_CompMat *] + * Arg: name New value of the variable [char *] + * + * Returns member variable name [boolean] + * + */ +boolean bp_sw_replace_name_CompMat( bp_sw_CompMat * obj,char * name); + +/* Function: bp_sw_access_name_CompMat(obj) + * + * Descrip: Access member variable name + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_CompMat *] + * + * Returns member variable name [char *] + * + */ +char * bp_sw_access_name_CompMat( bp_sw_CompMat * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_CompMat(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_CompMat *] + * + * Returns Undocumented return value [bp_sw_CompMat *] + * + */ +bp_sw_CompMat * bp_sw_free_CompMat( bp_sw_CompMat * obj); + + + +/* Functions that create, manipulate or act on Gene + * + * bp_sw_get_Genomic_from_Gene + * bp_sw_show_pretty_Gene + * bp_sw_hard_link_Gene + * bp_sw_Gene_alloc_std + * bp_sw_replace_start_Gene + * bp_sw_access_start_Gene + * bp_sw_replace_end_Gene + * bp_sw_access_end_Gene + * bp_sw_replace_parent_Gene + * bp_sw_access_parent_Gene + * bp_sw_replace_genomic_Gene + * bp_sw_access_genomic_Gene + * bp_sw_access_transcript_Gene + * bp_sw_length_transcript_Gene + * bp_sw_flush_Gene + * bp_sw_add_Gene + * bp_sw_replace_name_Gene + * bp_sw_access_name_Gene + * bp_sw_replace_bits_Gene + * bp_sw_access_bits_Gene + * bp_sw_replace_seqname_Gene + * bp_sw_access_seqname_Gene + * bp_sw_free_Gene [destructor] + * + */ + +/* API for object Gene */ +/* Function: bp_sw_get_Genomic_from_Gene(gene) + * + * Descrip: Gives back a Genomic sequence type + * from a gene. + * + * + * Arg: gene gene to get Genomic from [bp_sw_Gene *] + * + * Returns Genomic DNA data structure [bp_sw_Genomic *] + * + */ +bp_sw_Genomic * bp_sw_get_Genomic_from_Gene( bp_sw_Gene * gene); + +/* Function: bp_sw_show_pretty_Gene(ge,ofp) + * + * Descrip: Shows a gene in the biologically accepted form + * + * + * Arg: ge Undocumented argument [bp_sw_Gene *] + * Arg: ofp Undocumented argument [FILE *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_show_pretty_Gene( bp_sw_Gene * ge,FILE * ofp); + +/* Function: bp_sw_hard_link_Gene(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_Gene *] + * + * Returns Undocumented return value [bp_sw_Gene *] + * + */ +bp_sw_Gene * bp_sw_hard_link_Gene( bp_sw_Gene * obj); + +/* Function: bp_sw_Gene_alloc_std(void) + * + * Descrip: Equivalent to Gene_alloc_len(GeneLISTLENGTH) + * + * + * + * Returns Undocumented return value [bp_sw_Gene *] + * + */ +bp_sw_Gene * bp_sw_Gene_alloc_std(); + +/* Function: bp_sw_replace_start_Gene(obj,start) + * + * Descrip: Replace member variable start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * Arg: start New value of the variable [int] + * + * Returns member variable start [boolean] + * + */ +boolean bp_sw_replace_start_Gene( bp_sw_Gene * obj,int start); + +/* Function: bp_sw_access_start_Gene(obj) + * + * Descrip: Access member variable start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * + * Returns member variable start [int] + * + */ +int bp_sw_access_start_Gene( bp_sw_Gene * obj); + +/* Function: bp_sw_replace_end_Gene(obj,end) + * + * Descrip: Replace member variable end + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * Arg: end New value of the variable [int] + * + * Returns member variable end [boolean] + * + */ +boolean bp_sw_replace_end_Gene( bp_sw_Gene * obj,int end); + +/* Function: bp_sw_access_end_Gene(obj) + * + * Descrip: Access member variable end + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * + * Returns member variable end [int] + * + */ +int bp_sw_access_end_Gene( bp_sw_Gene * obj); + +/* Function: bp_sw_replace_parent_Gene(obj,parent) + * + * Descrip: Replace member variable parent + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * Arg: parent New value of the variable [bp_sw_GenomicRegion *] + * + * Returns member variable parent [boolean] + * + */ +boolean bp_sw_replace_parent_Gene( bp_sw_Gene * obj,bp_sw_GenomicRegion * parent); + +/* Function: bp_sw_access_parent_Gene(obj) + * + * Descrip: Access member variable parent + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * + * Returns member variable parent [bp_sw_GenomicRegion *] + * + */ +bp_sw_GenomicRegion * bp_sw_access_parent_Gene( bp_sw_Gene * obj); + +/* Function: bp_sw_replace_genomic_Gene(obj,genomic) + * + * Descrip: Replace member variable genomic + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * Arg: genomic New value of the variable [bp_sw_Genomic *] + * + * Returns member variable genomic [boolean] + * + */ +boolean bp_sw_replace_genomic_Gene( bp_sw_Gene * obj,bp_sw_Genomic * genomic); + +/* Function: bp_sw_access_genomic_Gene(obj) + * + * Descrip: Access member variable genomic + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * + * Returns member variable genomic [bp_sw_Genomic *] + * + */ +bp_sw_Genomic * bp_sw_access_genomic_Gene( bp_sw_Gene * obj); + +/* Function: bp_sw_access_transcript_Gene(obj,i) + * + * Descrip: Access members stored in the transcript list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_Gene *] + * Arg: i Position in the list [int] + * + * Returns Element of the list [bp_sw_Transcript *] + * + */ +bp_sw_Transcript * bp_sw_access_transcript_Gene( bp_sw_Gene * obj,int i); + +/* Function: bp_sw_length_transcript_Gene(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_Gene *] + * + * Returns length of the list [int] + * + */ +int bp_sw_length_transcript_Gene( bp_sw_Gene * obj); + +/* Function: bp_sw_flush_Gene(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj Object which contains the list [bp_sw_Gene *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_flush_Gene( bp_sw_Gene * obj); + +/* Function: bp_sw_add_Gene(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj Object which contains the list [bp_sw_Gene *] + * Arg: add Object to add to the list [bp_sw_Transcript *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_add_Gene( bp_sw_Gene * obj,bp_sw_Transcript * add); + +/* Function: bp_sw_replace_name_Gene(obj,name) + * + * Descrip: Replace member variable name + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * Arg: name New value of the variable [char *] + * + * Returns member variable name [boolean] + * + */ +boolean bp_sw_replace_name_Gene( bp_sw_Gene * obj,char * name); + +/* Function: bp_sw_access_name_Gene(obj) + * + * Descrip: Access member variable name + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * + * Returns member variable name [char *] + * + */ +char * bp_sw_access_name_Gene( bp_sw_Gene * obj); + +/* Function: bp_sw_replace_bits_Gene(obj,bits) + * + * Descrip: Replace member variable bits + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * Arg: bits New value of the variable [double] + * + * Returns member variable bits [boolean] + * + */ +boolean bp_sw_replace_bits_Gene( bp_sw_Gene * obj,double bits); + +/* Function: bp_sw_access_bits_Gene(obj) + * + * Descrip: Access member variable bits + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * + * Returns member variable bits [double] + * + */ +double bp_sw_access_bits_Gene( bp_sw_Gene * obj); + +/* Function: bp_sw_replace_seqname_Gene(obj,seqname) + * + * Descrip: Replace member variable seqname + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * Arg: seqname New value of the variable [char *] + * + * Returns member variable seqname [boolean] + * + */ +boolean bp_sw_replace_seqname_Gene( bp_sw_Gene * obj,char * seqname); + +/* Function: bp_sw_access_seqname_Gene(obj) + * + * Descrip: Access member variable seqname + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Gene *] + * + * Returns member variable seqname [char *] + * + */ +char * bp_sw_access_seqname_Gene( bp_sw_Gene * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_Gene(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_Gene *] + * + * Returns Undocumented return value [bp_sw_Gene *] + * + */ +bp_sw_Gene * bp_sw_free_Gene( bp_sw_Gene * obj); + + + +/* Functions that create, manipulate or act on Genomic + * + * bp_sw_truncate_Genomic + * bp_sw_read_fasta_file_Genomic + * bp_sw_Genomic_name + * bp_sw_Genomic_length + * bp_sw_Genomic_seqchar + * bp_sw_Genomic_from_Sequence + * bp_sw_hard_link_Genomic + * bp_sw_Genomic_alloc + * bp_sw_replace_baseseq_Genomic + * bp_sw_access_baseseq_Genomic + * bp_sw_free_Genomic [destructor] + * + */ + +/* API for object Genomic */ +/* Function: bp_sw_truncate_Genomic(gen,start,stop) + * + * Descrip: Truncates a Genomic sequence. Basically uses + * the /magic_trunc_Sequence function (of course!) + * + * It does not alter gen, rather it returns a new + * sequence with that truncation + * + * + * Arg: gen Genomic that is truncated [bp_sw_Genomic *] + * Arg: start Undocumented argument [int] + * Arg: stop Undocumented argument [int] + * + * Returns Undocumented return value [bp_sw_Genomic *] + * + */ +bp_sw_Genomic * bp_sw_truncate_Genomic( bp_sw_Genomic * gen,int start,int stop); + +/* Function: bp_sw_read_fasta_file_Genomic(filename) + * + * Descrip: Reads a fasta file assumming that it is Genomic. + * Will complain if it is not, and return NULL. + * + * + * Arg: filename filename to be opened and read [char *] + * + * Returns Undocumented return value [bp_sw_Genomic *] + * + */ +bp_sw_Genomic * bp_sw_read_fasta_file_Genomic( char * filename); + +/* Function: bp_sw_Genomic_name(gen) + * + * Descrip: Returns the name of the Genomic + * + * + * Arg: gen Undocumented argument [bp_sw_Genomic *] + * + * Returns Undocumented return value [char *] + * + */ +char * bp_sw_Genomic_name( bp_sw_Genomic * gen); + +/* Function: bp_sw_Genomic_length(gen) + * + * Descrip: Returns the length of the Genomic + * + * + * Arg: gen Undocumented argument [bp_sw_Genomic *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_Genomic_length( bp_sw_Genomic * gen); + +/* Function: bp_sw_Genomic_seqchar(gen,pos) + * + * Descrip: Returns sequence character at this position. + * + * + * Arg: gen Genomic [bp_sw_Genomic *] + * Arg: pos position in Genomic to get char [int] + * + * Returns Undocumented return value [char] + * + */ +char bp_sw_Genomic_seqchar( bp_sw_Genomic * gen,int pos); + +/* Function: bp_sw_Genomic_from_Sequence(seq) + * + * Descrip: makes a new genomic from a Sequence. It + * owns the Sequence memory, ie will attempt a /free_Sequence + * on the structure when /free_Genomic is called + * + * If you want to give this genomic this Sequence and + * forget about it, then just hand it this sequence and set + * seq to NULL (no need to free it). If you intend to use + * the sequence object elsewhere outside of the Genomic datastructure + * then use Genomic_from_Sequence(/hard_link_Sequence(seq)) + * + * This is part of a strict typing system, and therefore + * is going to convert all non ATGCNs to Ns. You will lose + * information here. + * + * + * Arg: seq Sequence to make genomic from [bp_sw_Sequence *] + * + * Returns Undocumented return value [bp_sw_Genomic *] + * + */ +bp_sw_Genomic * bp_sw_Genomic_from_Sequence( bp_sw_Sequence * seq); + +/* Function: bp_sw_hard_link_Genomic(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_Genomic *] + * + * Returns Undocumented return value [bp_sw_Genomic *] + * + */ +bp_sw_Genomic * bp_sw_hard_link_Genomic( bp_sw_Genomic * obj); + +/* Function: bp_sw_Genomic_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_Genomic *] + * + */ +bp_sw_Genomic * bp_sw_Genomic_alloc(); + +/* Function: bp_sw_replace_baseseq_Genomic(obj,baseseq) + * + * Descrip: Replace member variable baseseq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Genomic *] + * Arg: baseseq New value of the variable [bp_sw_Sequence *] + * + * Returns member variable baseseq [boolean] + * + */ +boolean bp_sw_replace_baseseq_Genomic( bp_sw_Genomic * obj,bp_sw_Sequence * baseseq); + +/* Function: bp_sw_access_baseseq_Genomic(obj) + * + * Descrip: Access member variable baseseq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Genomic *] + * + * Returns member variable baseseq [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_access_baseseq_Genomic( bp_sw_Genomic * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_Genomic(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_Genomic *] + * + * Returns Undocumented return value [bp_sw_Genomic *] + * + */ +bp_sw_Genomic * bp_sw_free_Genomic( bp_sw_Genomic * obj); + + + +/* Functions that create, manipulate or act on GenomicDB + * + * bp_sw_get_Genomic_from_GenomicDB + * bp_sw_hard_link_GenomicDB + * bp_sw_GenomicDB_alloc + * bp_sw_replace_is_single_seq_GenomicDB + * bp_sw_access_is_single_seq_GenomicDB + * bp_sw_replace_done_forward_GenomicDB + * bp_sw_access_done_forward_GenomicDB + * bp_sw_replace_forw_GenomicDB + * bp_sw_access_forw_GenomicDB + * bp_sw_replace_rev_GenomicDB + * bp_sw_access_rev_GenomicDB + * bp_sw_replace_sdb_GenomicDB + * bp_sw_access_sdb_GenomicDB + * bp_sw_replace_current_GenomicDB + * bp_sw_access_current_GenomicDB + * bp_sw_replace_cses_GenomicDB + * bp_sw_access_cses_GenomicDB + * bp_sw_free_GenomicDB [destructor] + * + */ + + + +/* Helper functions in the module + * + * bp_sw_new_GenomicDB_from_single_seq + * bp_sw_new_GenomicDB + * + +/* API for object GenomicDB */ +/* Function: bp_sw_get_Genomic_from_GenomicDB(gendb,de) + * + * Descrip: Gets Genomic sequence out from + * the GenomicDB using the information stored in + * dataentry + * + * + * Arg: gendb Undocumented argument [bp_sw_GenomicDB *] + * Arg: de Undocumented argument [bp_sw_DataEntry *] + * + * Returns Undocumented return value [bp_sw_Genomic *] + * + */ +bp_sw_Genomic * bp_sw_get_Genomic_from_GenomicDB( bp_sw_GenomicDB * gendb,bp_sw_DataEntry * de); + +/* Function: bp_sw_hard_link_GenomicDB(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_GenomicDB *] + * + * Returns Undocumented return value [bp_sw_GenomicDB *] + * + */ +bp_sw_GenomicDB * bp_sw_hard_link_GenomicDB( bp_sw_GenomicDB * obj); + +/* Function: bp_sw_GenomicDB_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_GenomicDB *] + * + */ +bp_sw_GenomicDB * bp_sw_GenomicDB_alloc(); + +/* Function: bp_sw_replace_is_single_seq_GenomicDB(obj,is_single_seq) + * + * Descrip: Replace member variable is_single_seq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * Arg: is_single_seq New value of the variable [boolean] + * + * Returns member variable is_single_seq [boolean] + * + */ +boolean bp_sw_replace_is_single_seq_GenomicDB( bp_sw_GenomicDB * obj,boolean is_single_seq); + +/* Function: bp_sw_access_is_single_seq_GenomicDB(obj) + * + * Descrip: Access member variable is_single_seq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * + * Returns member variable is_single_seq [boolean] + * + */ +boolean bp_sw_access_is_single_seq_GenomicDB( bp_sw_GenomicDB * obj); + +/* Function: bp_sw_replace_done_forward_GenomicDB(obj,done_forward) + * + * Descrip: Replace member variable done_forward + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * Arg: done_forward New value of the variable [boolean] + * + * Returns member variable done_forward [boolean] + * + */ +boolean bp_sw_replace_done_forward_GenomicDB( bp_sw_GenomicDB * obj,boolean done_forward); + +/* Function: bp_sw_access_done_forward_GenomicDB(obj) + * + * Descrip: Access member variable done_forward + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * + * Returns member variable done_forward [boolean] + * + */ +boolean bp_sw_access_done_forward_GenomicDB( bp_sw_GenomicDB * obj); + +/* Function: bp_sw_replace_forw_GenomicDB(obj,forw) + * + * Descrip: Replace member variable forw + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * Arg: forw New value of the variable [bp_sw_ComplexSequence *] + * + * Returns member variable forw [boolean] + * + */ +boolean bp_sw_replace_forw_GenomicDB( bp_sw_GenomicDB * obj,bp_sw_ComplexSequence * forw); + +/* Function: bp_sw_access_forw_GenomicDB(obj) + * + * Descrip: Access member variable forw + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * + * Returns member variable forw [bp_sw_ComplexSequence *] + * + */ +bp_sw_ComplexSequence * bp_sw_access_forw_GenomicDB( bp_sw_GenomicDB * obj); + +/* Function: bp_sw_replace_rev_GenomicDB(obj,rev) + * + * Descrip: Replace member variable rev + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * Arg: rev New value of the variable [bp_sw_ComplexSequence *] + * + * Returns member variable rev [boolean] + * + */ +boolean bp_sw_replace_rev_GenomicDB( bp_sw_GenomicDB * obj,bp_sw_ComplexSequence * rev); + +/* Function: bp_sw_access_rev_GenomicDB(obj) + * + * Descrip: Access member variable rev + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * + * Returns member variable rev [bp_sw_ComplexSequence *] + * + */ +bp_sw_ComplexSequence * bp_sw_access_rev_GenomicDB( bp_sw_GenomicDB * obj); + +/* Function: bp_sw_replace_sdb_GenomicDB(obj,sdb) + * + * Descrip: Replace member variable sdb + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * Arg: sdb New value of the variable [bp_sw_SequenceDB *] + * + * Returns member variable sdb [boolean] + * + */ +boolean bp_sw_replace_sdb_GenomicDB( bp_sw_GenomicDB * obj,bp_sw_SequenceDB * sdb); + +/* Function: bp_sw_access_sdb_GenomicDB(obj) + * + * Descrip: Access member variable sdb + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * + * Returns member variable sdb [bp_sw_SequenceDB *] + * + */ +bp_sw_SequenceDB * bp_sw_access_sdb_GenomicDB( bp_sw_GenomicDB * obj); + +/* Function: bp_sw_replace_current_GenomicDB(obj,current) + * + * Descrip: Replace member variable current + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * Arg: current New value of the variable [bp_sw_Sequence *] + * + * Returns member variable current [boolean] + * + */ +boolean bp_sw_replace_current_GenomicDB( bp_sw_GenomicDB * obj,bp_sw_Sequence * current); + +/* Function: bp_sw_access_current_GenomicDB(obj) + * + * Descrip: Access member variable current + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * + * Returns member variable current [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_access_current_GenomicDB( bp_sw_GenomicDB * obj); + +/* Function: bp_sw_replace_cses_GenomicDB(obj,cses) + * + * Descrip: Replace member variable cses + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * Arg: cses New value of the variable [bp_sw_ComplexSequenceEvalSet *] + * + * Returns member variable cses [boolean] + * + */ +boolean bp_sw_replace_cses_GenomicDB( bp_sw_GenomicDB * obj,bp_sw_ComplexSequenceEvalSet * cses); + +/* Function: bp_sw_access_cses_GenomicDB(obj) + * + * Descrip: Access member variable cses + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicDB *] + * + * Returns member variable cses [bp_sw_ComplexSequenceEvalSet *] + * + */ +bp_sw_ComplexSequenceEvalSet * bp_sw_access_cses_GenomicDB( bp_sw_GenomicDB * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_GenomicDB(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_GenomicDB *] + * + * Returns Undocumented return value [bp_sw_GenomicDB *] + * + */ +bp_sw_GenomicDB * bp_sw_free_GenomicDB( bp_sw_GenomicDB * obj); + + + +/* These functions are not associated with an object */ +/* Function: bp_sw_new_GenomicDB_from_single_seq(seq,cses) + * + * Descrip: To make a new genomic database + * from a single Genomic Sequence with a eval system + * + * + * Arg: seq sequence which as placed into GenomicDB structure. [bp_sw_Genomic *] + * Arg: cses Undocumented argument [bp_sw_ComplexSequenceEvalSet *] + * + * Returns Undocumented return value [bp_sw_GenomicDB *] + * + */ +bp_sw_GenomicDB * bp_sw_new_GenomicDB_from_single_seq( bp_sw_Genomic * seq,bp_sw_ComplexSequenceEvalSet * cses); + +/* Function: bp_sw_new_GenomicDB(seqdb,cses) + * + * Descrip: To make a new genomic database + * + * + * Arg: seqdb sequence database [bp_sw_SequenceDB *] + * Arg: cses protein evaluation set [bp_sw_ComplexSequenceEvalSet *] + * + * Returns Undocumented return value [bp_sw_GenomicDB *] + * + */ +bp_sw_GenomicDB * bp_sw_new_GenomicDB( bp_sw_SequenceDB * seqdb,bp_sw_ComplexSequenceEvalSet * cses); + + + +/* Functions that create, manipulate or act on GenomicRegion + * + * bp_sw_new_GenomicRegion + * bp_sw_read_EMBL_GenomicRegion_file + * bp_sw_read_EMBL_GenomicRegion + * bp_sw_add_Gene_to_GenomicRegion + * bp_sw_show_ace_GenomicRegion + * bp_sw_show_pretty_GenomicRegion + * bp_sw_hard_link_GenomicRegion + * bp_sw_GenomicRegion_alloc_std + * bp_sw_access_gene_GenomicRegion + * bp_sw_length_gene_GenomicRegion + * bp_sw_flush_GenomicRegion + * bp_sw_add_GenomicRegion + * bp_sw_replace_genomic_GenomicRegion + * bp_sw_access_genomic_GenomicRegion + * bp_sw_free_GenomicRegion [destructor] + * + */ + +/* API for object GenomicRegion */ +/* Function: bp_sw_new_GenomicRegion(gen) + * + * Descrip: makes a genomicregion from a genomic sequence + * + * + * Arg: gen Undocumented argument [bp_sw_Genomic *] + * + * Returns Undocumented return value [bp_sw_GenomicRegion *] + * + */ +bp_sw_GenomicRegion * bp_sw_new_GenomicRegion( bp_sw_Genomic * gen); + +/* Function: bp_sw_read_EMBL_GenomicRegion_file(filename) + * + * Descrip: Reads in both EMBL sequence and features + * + * + * Arg: filename Undocumented argument [char *] + * + * Returns Undocumented return value [bp_sw_GenomicRegion *] + * + */ +bp_sw_GenomicRegion * bp_sw_read_EMBL_GenomicRegion_file( char * filename); + +/* Function: bp_sw_read_EMBL_GenomicRegion(ifp) + * + * Descrip: Reads in both EMBL sequence and features + * + * + * Arg: ifp Undocumented argument [FILE *] + * + * Returns Undocumented return value [bp_sw_GenomicRegion *] + * + */ +bp_sw_GenomicRegion * bp_sw_read_EMBL_GenomicRegion( FILE * ifp); + +/* Function: bp_sw_add_Gene_to_GenomicRegion(gr,gene) + * + * Descrip: adds a Gene to this GenomicRegion, making + * sure that it parent/son relationship is ok + * + * + * Arg: gr GenomicRegion to be added to [bp_sw_GenomicRegion *] + * Arg: gene Gene to be added [bp_sw_Gene *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_add_Gene_to_GenomicRegion( bp_sw_GenomicRegion * gr,bp_sw_Gene * gene); + +/* Function: bp_sw_show_ace_GenomicRegion(gr,seq_name,ofp) + * + * Descrip: shows ACeDB subsequence source. + * + * Assummes + * a only one transcript per gene + * b only cds exons are used + * + * + * Arg: gr Undocumented argument [bp_sw_GenomicRegion *] + * Arg: seq_name Undocumented argument [char *] + * Arg: ofp Undocumented argument [FILE *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_show_ace_GenomicRegion( bp_sw_GenomicRegion * gr,char * seq_name,FILE * ofp); + +/* Function: bp_sw_show_pretty_GenomicRegion(gr,ofp) + * + * Descrip: No Description + * + * Arg: gr Undocumented argument [bp_sw_GenomicRegion *] + * Arg: ofp Undocumented argument [FILE *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_show_pretty_GenomicRegion( bp_sw_GenomicRegion * gr,FILE * ofp); + +/* Function: bp_sw_hard_link_GenomicRegion(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_GenomicRegion *] + * + * Returns Undocumented return value [bp_sw_GenomicRegion *] + * + */ +bp_sw_GenomicRegion * bp_sw_hard_link_GenomicRegion( bp_sw_GenomicRegion * obj); + +/* Function: bp_sw_GenomicRegion_alloc_std(void) + * + * Descrip: Equivalent to GenomicRegion_alloc_len(GenomicRegionLISTLENGTH) + * + * + * + * Returns Undocumented return value [bp_sw_GenomicRegion *] + * + */ +bp_sw_GenomicRegion * bp_sw_GenomicRegion_alloc_std(); + +/* Function: bp_sw_access_gene_GenomicRegion(obj,i) + * + * Descrip: Access members stored in the gene list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_GenomicRegion *] + * Arg: i Position in the list [int] + * + * Returns Element of the list [bp_sw_Gene *] + * + */ +bp_sw_Gene * bp_sw_access_gene_GenomicRegion( bp_sw_GenomicRegion * obj,int i); + +/* Function: bp_sw_length_gene_GenomicRegion(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_GenomicRegion *] + * + * Returns length of the list [int] + * + */ +int bp_sw_length_gene_GenomicRegion( bp_sw_GenomicRegion * obj); + +/* Function: bp_sw_flush_GenomicRegion(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj Object which contains the list [bp_sw_GenomicRegion *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_flush_GenomicRegion( bp_sw_GenomicRegion * obj); + +/* Function: bp_sw_add_GenomicRegion(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj Object which contains the list [bp_sw_GenomicRegion *] + * Arg: add Object to add to the list [bp_sw_Gene *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_add_GenomicRegion( bp_sw_GenomicRegion * obj,bp_sw_Gene * add); + +/* Function: bp_sw_replace_genomic_GenomicRegion(obj,genomic) + * + * Descrip: Replace member variable genomic + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicRegion *] + * Arg: genomic New value of the variable [bp_sw_Genomic *] + * + * Returns member variable genomic [boolean] + * + */ +boolean bp_sw_replace_genomic_GenomicRegion( bp_sw_GenomicRegion * obj,bp_sw_Genomic * genomic); + +/* Function: bp_sw_access_genomic_GenomicRegion(obj) + * + * Descrip: Access member variable genomic + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_GenomicRegion *] + * + * Returns member variable genomic [bp_sw_Genomic *] + * + */ +bp_sw_Genomic * bp_sw_access_genomic_GenomicRegion( bp_sw_GenomicRegion * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_GenomicRegion(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_GenomicRegion *] + * + * Returns Undocumented return value [bp_sw_GenomicRegion *] + * + */ +bp_sw_GenomicRegion * bp_sw_free_GenomicRegion( bp_sw_GenomicRegion * obj); + + + +/* Functions that create, manipulate or act on Histogram + * + * bp_sw_UnfitHistogram + * bp_sw_AddToHistogram + * bp_sw_PrintASCIIHistogram + * bp_sw_EVDBasicFit + * bp_sw_ExtremeValueFitHistogram + * bp_sw_ExtremeValueSetHistogram + * bp_sw_GaussianFitHistogram + * bp_sw_GaussianSetHistogram + * bp_sw_hard_link_Histogram + * bp_sw_Histogram_alloc + * bp_sw_free_Histogram [destructor] + * + */ + + + +/* Helper functions in the module + * + * bp_sw_new_Histogram + * + +/* API for object Histogram */ +/* Function: bp_sw_UnfitHistogram(h) + * + * Descrip: No Description + * + * Arg: h Undocumented argument [bp_sw_Histogram *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_UnfitHistogram( bp_sw_Histogram * h); + +/* Function: bp_sw_AddToHistogram(h,sc) + * + * Descrip: No Description + * + * Arg: h Undocumented argument [bp_sw_Histogram *] + * Arg: sc Undocumented argument [float] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_AddToHistogram( bp_sw_Histogram * h,float sc); + +/* Function: bp_sw_PrintASCIIHistogram(h,fp) + * + * Descrip: No Description + * + * Arg: h histogram to print [bp_sw_Histogram *] + * Arg: fp open file to print to (stdout works) [FILE *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_PrintASCIIHistogram( bp_sw_Histogram * h,FILE * fp); + +/* Function: bp_sw_EVDBasicFit(h) + * + * Descrip: No Description + * + * Arg: h histogram to fit [bp_sw_Histogram *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_EVDBasicFit( bp_sw_Histogram * h); + +/* Function: bp_sw_ExtremeValueFitHistogram(h,censor,high_hint) + * + * Descrip: No Description + * + * Arg: h histogram to fit [bp_sw_Histogram *] + * Arg: censor TRUE to censor data left of the peak [int] + * Arg: high_hint score cutoff; above this are `real' hits that aren't fit [float] + * + * Returns if fit is judged to be valid else 0 if fit is invalid (too few seqs.) [int] + * + */ +int bp_sw_ExtremeValueFitHistogram( bp_sw_Histogram * h,int censor,float high_hint); + +/* Function: bp_sw_ExtremeValueSetHistogram(h,mu,lambda,lowbound,highbound,wonka,ndegrees) + * + * Descrip: No Description + * + * Arg: h the histogram to set [bp_sw_Histogram *] + * Arg: mu mu location parameter [float] + * Arg: lambda lambda scale parameter [float] + * Arg: lowbound low bound of the histogram that was fit [float] + * Arg: highbound high bound of histogram that was fit [float] + * Arg: wonka fudge factor; fraction of hits estimated to be "EVD-like" [float] + * Arg: ndegrees extra degrees of freedom to subtract in X^2 test: [int] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_ExtremeValueSetHistogram( bp_sw_Histogram * h,float mu,float lambda,float lowbound,float highbound,float wonka,int ndegrees); + +/* Function: bp_sw_GaussianFitHistogram(h,high_hint) + * + * Descrip: No Description + * + * Arg: h histogram to fit [bp_sw_Histogram *] + * Arg: high_hint score cutoff; above this are `real' hits that aren't fit [float] + * + * Returns if fit is judged to be valid else 0 if fit is invalid (too few seqs.) [int] + * + */ +int bp_sw_GaussianFitHistogram( bp_sw_Histogram * h,float high_hint); + +/* Function: bp_sw_GaussianSetHistogram(h,mean,sd) + * + * Descrip: No Description + * + * Arg: h Undocumented argument [bp_sw_Histogram *] + * Arg: mean Undocumented argument [float] + * Arg: sd Undocumented argument [float] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_GaussianSetHistogram( bp_sw_Histogram * h,float mean,float sd); + +/* Function: bp_sw_hard_link_Histogram(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_Histogram *] + * + * Returns Undocumented return value [bp_sw_Histogram *] + * + */ +bp_sw_Histogram * bp_sw_hard_link_Histogram( bp_sw_Histogram * obj); + +/* Function: bp_sw_Histogram_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_Histogram *] + * + */ +bp_sw_Histogram * bp_sw_Histogram_alloc(); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_Histogram(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_Histogram *] + * + * Returns Undocumented return value [bp_sw_Histogram *] + * + */ +bp_sw_Histogram * bp_sw_free_Histogram( bp_sw_Histogram * obj); + + + +/* These functions are not associated with an object */ +/* Function: bp_sw_new_Histogram(min,max,lumpsize) + * + * Descrip: No Description + * + * Arg: min minimum score (integer) [int] + * Arg: max maximum score (integer) [int] + * Arg: lumpsize when reallocating histogram, the reallocation amount [int] + * + * Returns Undocumented return value [bp_sw_Histogram *] + * + */ +bp_sw_Histogram * bp_sw_new_Histogram( int min,int max,int lumpsize); + + + +/* Functions that create, manipulate or act on Hscore + * + * bp_sw_minimum_score_Hscore + * bp_sw_maximum_score_Hscore + * bp_sw_sort_Hscore_by_score + * bp_sw_length_datascore_Hscore + * bp_sw_get_datascore_Hscore + * bp_sw_get_score_Hscore + * bp_sw_get_evalue_Hscore + * bp_sw_basic_show_Hscore + * bp_sw_hard_link_Hscore + * bp_sw_Hscore_alloc_std + * bp_sw_free_Hscore [destructor] + * + */ + + + +/* Functions that create, manipulate or act on DataScore + * + * bp_sw_hard_link_DataScore + * bp_sw_DataScore_alloc + * bp_sw_replace_query_DataScore + * bp_sw_access_query_DataScore + * bp_sw_replace_target_DataScore + * bp_sw_access_target_DataScore + * bp_sw_replace_score_DataScore + * bp_sw_access_score_DataScore + * bp_sw_replace_evalue_DataScore + * bp_sw_access_evalue_DataScore + * bp_sw_free_DataScore [destructor] + * + */ + + + +/* Functions that create, manipulate or act on DataEntry + * + * bp_sw_hard_link_DataEntry + * bp_sw_DataEntry_alloc + * bp_sw_replace_name_DataEntry + * bp_sw_access_name_DataEntry + * bp_sw_replace_is_reversed_DataEntry + * bp_sw_access_is_reversed_DataEntry + * bp_sw_replace_filename_DataEntry + * bp_sw_access_filename_DataEntry + * bp_sw_free_DataEntry [destructor] + * + */ + +/* API for object Hscore */ +/* Function: bp_sw_minimum_score_Hscore(hs) + * + * Descrip: gets the minimum score from Hscore + * + * + * Arg: hs Undocumented argument [bp_sw_Hscore *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_minimum_score_Hscore( bp_sw_Hscore * hs); + +/* Function: bp_sw_maximum_score_Hscore(hs) + * + * Descrip: gets the maximum score from Hscore + * + * + * Arg: hs Undocumented argument [bp_sw_Hscore *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_maximum_score_Hscore( bp_sw_Hscore * hs); + +/* Function: bp_sw_sort_Hscore_by_score(hs) + * + * Descrip: As it says, sorts the high score by its score + * + * + * Arg: hs Hscore to be sorted [bp_sw_Hscore *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_sort_Hscore_by_score( bp_sw_Hscore * hs); + +/* Function: bp_sw_length_datascore_Hscore(obj) + * + * Descrip: Returns the number of datascores in the hscore + * structure + * + * + * Arg: obj Hscore object [bp_sw_Hscore *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_length_datascore_Hscore( bp_sw_Hscore * obj); + +/* Function: bp_sw_get_datascore_Hscore(hs,i) + * + * Descrip: Returns the specific datascore held at this + * position. + * + * This requires a considerable amount of memory + * duplication, so please dont process all your + * results by looping through this. + * + * + * Arg: hs Hscore object [bp_sw_Hscore *] + * Arg: i position to be read [int] + * + * Returns New datascore object [bp_sw_DataScore *] + * + */ +bp_sw_DataScore * bp_sw_get_datascore_Hscore( bp_sw_Hscore * hs,int i); + +/* Function: bp_sw_get_score_Hscore(hs,i) + * + * Descrip: No Description + * + * Arg: hs Hscore object [bp_sw_Hscore *] + * Arg: i position to be read [int] + * + * Returns score [int] + * + */ +int bp_sw_get_score_Hscore( bp_sw_Hscore * hs,int i); + +/* Function: bp_sw_get_evalue_Hscore(hs,i) + * + * Descrip: Returns the evalue of the specific datascore held at this position. + * + * + * + * Arg: hs Hscore object [bp_sw_Hscore *] + * Arg: i position to be read [int] + * + * Returns evalue [double] + * + */ +double bp_sw_get_evalue_Hscore( bp_sw_Hscore * hs,int i); + +/* Function: bp_sw_basic_show_Hscore(hs,ofp) + * + * Descrip: The most baby-talk showing of Hscore + * + * + * Arg: hs Undocumented argument [bp_sw_Hscore *] + * Arg: ofp Undocumented argument [FILE *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_basic_show_Hscore( bp_sw_Hscore * hs,FILE * ofp); + +/* Function: bp_sw_hard_link_Hscore(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_Hscore *] + * + * Returns Undocumented return value [bp_sw_Hscore *] + * + */ +bp_sw_Hscore * bp_sw_hard_link_Hscore( bp_sw_Hscore * obj); + +/* Function: bp_sw_Hscore_alloc_std(void) + * + * Descrip: Equivalent to Hscore_alloc_len(HscoreLISTLENGTH) + * + * + * + * Returns Undocumented return value [bp_sw_Hscore *] + * + */ +bp_sw_Hscore * bp_sw_Hscore_alloc_std(); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_Hscore(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_Hscore *] + * + * Returns Undocumented return value [bp_sw_Hscore *] + * + */ +bp_sw_Hscore * bp_sw_free_Hscore( bp_sw_Hscore * obj); + +/* API for object DataScore */ +/* Function: bp_sw_hard_link_DataScore(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_DataScore *] + * + * Returns Undocumented return value [bp_sw_DataScore *] + * + */ +bp_sw_DataScore * bp_sw_hard_link_DataScore( bp_sw_DataScore * obj); + +/* Function: bp_sw_DataScore_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_DataScore *] + * + */ +bp_sw_DataScore * bp_sw_DataScore_alloc(); + +/* Function: bp_sw_replace_query_DataScore(obj,query) + * + * Descrip: Replace member variable query + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataScore *] + * Arg: query New value of the variable [bp_sw_DataEntry *] + * + * Returns member variable query [boolean] + * + */ +boolean bp_sw_replace_query_DataScore( bp_sw_DataScore * obj,bp_sw_DataEntry * query); + +/* Function: bp_sw_access_query_DataScore(obj) + * + * Descrip: Access member variable query + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataScore *] + * + * Returns member variable query [bp_sw_DataEntry *] + * + */ +bp_sw_DataEntry * bp_sw_access_query_DataScore( bp_sw_DataScore * obj); + +/* Function: bp_sw_replace_target_DataScore(obj,target) + * + * Descrip: Replace member variable target + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataScore *] + * Arg: target New value of the variable [bp_sw_DataEntry *] + * + * Returns member variable target [boolean] + * + */ +boolean bp_sw_replace_target_DataScore( bp_sw_DataScore * obj,bp_sw_DataEntry * target); + +/* Function: bp_sw_access_target_DataScore(obj) + * + * Descrip: Access member variable target + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataScore *] + * + * Returns member variable target [bp_sw_DataEntry *] + * + */ +bp_sw_DataEntry * bp_sw_access_target_DataScore( bp_sw_DataScore * obj); + +/* Function: bp_sw_replace_score_DataScore(obj,score) + * + * Descrip: Replace member variable score + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataScore *] + * Arg: score New value of the variable [int] + * + * Returns member variable score [boolean] + * + */ +boolean bp_sw_replace_score_DataScore( bp_sw_DataScore * obj,int score); + +/* Function: bp_sw_access_score_DataScore(obj) + * + * Descrip: Access member variable score + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataScore *] + * + * Returns member variable score [int] + * + */ +int bp_sw_access_score_DataScore( bp_sw_DataScore * obj); + +/* Function: bp_sw_replace_evalue_DataScore(obj,evalue) + * + * Descrip: Replace member variable evalue + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataScore *] + * Arg: evalue New value of the variable [double] + * + * Returns member variable evalue [boolean] + * + */ +boolean bp_sw_replace_evalue_DataScore( bp_sw_DataScore * obj,double evalue); + +/* Function: bp_sw_access_evalue_DataScore(obj) + * + * Descrip: Access member variable evalue + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataScore *] + * + * Returns member variable evalue [double] + * + */ +double bp_sw_access_evalue_DataScore( bp_sw_DataScore * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_DataScore(obj) + * + * Descrip: Correctly handles destruction of a datascore + * + * + * Arg: obj Undocumented argument [bp_sw_DataScore *] + * + * Returns Undocumented return value [bp_sw_DataScore *] + * + */ +bp_sw_DataScore * bp_sw_free_DataScore( bp_sw_DataScore * obj); + +/* API for object DataEntry */ +/* Function: bp_sw_hard_link_DataEntry(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_DataEntry *] + * + * Returns Undocumented return value [bp_sw_DataEntry *] + * + */ +bp_sw_DataEntry * bp_sw_hard_link_DataEntry( bp_sw_DataEntry * obj); + +/* Function: bp_sw_DataEntry_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_DataEntry *] + * + */ +bp_sw_DataEntry * bp_sw_DataEntry_alloc(); + +/* Function: bp_sw_replace_name_DataEntry(obj,name) + * + * Descrip: Replace member variable name + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataEntry *] + * Arg: name New value of the variable [char *] + * + * Returns member variable name [boolean] + * + */ +boolean bp_sw_replace_name_DataEntry( bp_sw_DataEntry * obj,char * name); + +/* Function: bp_sw_access_name_DataEntry(obj) + * + * Descrip: Access member variable name + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataEntry *] + * + * Returns member variable name [char *] + * + */ +char * bp_sw_access_name_DataEntry( bp_sw_DataEntry * obj); + +/* Function: bp_sw_replace_is_reversed_DataEntry(obj,is_reversed) + * + * Descrip: Replace member variable is_reversed + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataEntry *] + * Arg: is_reversed New value of the variable [boolean] + * + * Returns member variable is_reversed [boolean] + * + */ +boolean bp_sw_replace_is_reversed_DataEntry( bp_sw_DataEntry * obj,boolean is_reversed); + +/* Function: bp_sw_access_is_reversed_DataEntry(obj) + * + * Descrip: Access member variable is_reversed + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataEntry *] + * + * Returns member variable is_reversed [boolean] + * + */ +boolean bp_sw_access_is_reversed_DataEntry( bp_sw_DataEntry * obj); + +/* Function: bp_sw_replace_filename_DataEntry(obj,filename) + * + * Descrip: Replace member variable filename + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataEntry *] + * Arg: filename New value of the variable [char *] + * + * Returns member variable filename [boolean] + * + */ +boolean bp_sw_replace_filename_DataEntry( bp_sw_DataEntry * obj,char * filename); + +/* Function: bp_sw_access_filename_DataEntry(obj) + * + * Descrip: Access member variable filename + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_DataEntry *] + * + * Returns member variable filename [char *] + * + */ +char * bp_sw_access_filename_DataEntry( bp_sw_DataEntry * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_DataEntry(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_DataEntry *] + * + * Returns Undocumented return value [bp_sw_DataEntry *] + * + */ +bp_sw_DataEntry * bp_sw_free_DataEntry( bp_sw_DataEntry * obj); + + + +/* Functions that create, manipulate or act on PackAln + * + * bp_sw_show_simple_PackAln + * bp_sw_show_bits_and_cumlative_PackAln + * bp_sw_hard_link_PackAln + * bp_sw_PackAln_alloc_std + * bp_sw_access_pau_PackAln + * bp_sw_length_pau_PackAln + * bp_sw_flush_PackAln + * bp_sw_add_PackAln + * bp_sw_replace_score_PackAln + * bp_sw_access_score_PackAln + * bp_sw_free_PackAln [destructor] + * + */ + + + +/* Functions that create, manipulate or act on PackAlnUnit + * + * bp_sw_hard_link_PackAlnUnit + * bp_sw_PackAlnUnit_alloc + * bp_sw_replace_i_PackAlnUnit + * bp_sw_access_i_PackAlnUnit + * bp_sw_replace_j_PackAlnUnit + * bp_sw_access_j_PackAlnUnit + * bp_sw_replace_state_PackAlnUnit + * bp_sw_access_state_PackAlnUnit + * bp_sw_replace_score_PackAlnUnit + * bp_sw_access_score_PackAlnUnit + * bp_sw_free_PackAlnUnit [destructor] + * + */ + +/* API for object PackAln */ +/* Function: bp_sw_show_simple_PackAln(pal,ofp) + * + * Descrip: shows packaln with a pretty verbose debugging + * format + * + * + * Arg: pal Undocumented argument [bp_sw_PackAln *] + * Arg: ofp Undocumented argument [FILE *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_show_simple_PackAln( bp_sw_PackAln * pal,FILE * ofp); + +/* Function: bp_sw_show_bits_and_cumlative_PackAln(pal,ofp) + * + * Descrip: Shows packaln as: + * + * i,j,state,score,bits,cumlative-score,cumlative-bits + * + * cumlative score and cumlative bits are useful sometimes + * + * + * Arg: pal Undocumented argument [bp_sw_PackAln *] + * Arg: ofp Undocumented argument [FILE *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_show_bits_and_cumlative_PackAln( bp_sw_PackAln * pal,FILE * ofp); + +/* Function: bp_sw_hard_link_PackAln(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_PackAln *] + * + * Returns Undocumented return value [bp_sw_PackAln *] + * + */ +bp_sw_PackAln * bp_sw_hard_link_PackAln( bp_sw_PackAln * obj); + +/* Function: bp_sw_PackAln_alloc_std(void) + * + * Descrip: Equivalent to PackAln_alloc_len(PackAlnLISTLENGTH) + * + * + * + * Returns Undocumented return value [bp_sw_PackAln *] + * + */ +bp_sw_PackAln * bp_sw_PackAln_alloc_std(); + +/* Function: bp_sw_access_pau_PackAln(obj,i) + * + * Descrip: Access members stored in the pau list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_PackAln *] + * Arg: i Position in the list [int] + * + * Returns Element of the list [bp_sw_PackAlnUnit *] + * + */ +bp_sw_PackAlnUnit * bp_sw_access_pau_PackAln( bp_sw_PackAln * obj,int i); + +/* Function: bp_sw_length_pau_PackAln(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_PackAln *] + * + * Returns length of the list [int] + * + */ +int bp_sw_length_pau_PackAln( bp_sw_PackAln * obj); + +/* Function: bp_sw_flush_PackAln(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj Object which contains the list [bp_sw_PackAln *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_flush_PackAln( bp_sw_PackAln * obj); + +/* Function: bp_sw_add_PackAln(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj Object which contains the list [bp_sw_PackAln *] + * Arg: add Object to add to the list [bp_sw_PackAlnUnit *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_add_PackAln( bp_sw_PackAln * obj,bp_sw_PackAlnUnit * add); + +/* Function: bp_sw_replace_score_PackAln(obj,score) + * + * Descrip: Replace member variable score + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_PackAln *] + * Arg: score New value of the variable [int] + * + * Returns member variable score [boolean] + * + */ +boolean bp_sw_replace_score_PackAln( bp_sw_PackAln * obj,int score); + +/* Function: bp_sw_access_score_PackAln(obj) + * + * Descrip: Access member variable score + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_PackAln *] + * + * Returns member variable score [int] + * + */ +int bp_sw_access_score_PackAln( bp_sw_PackAln * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_PackAln(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_PackAln *] + * + * Returns Undocumented return value [bp_sw_PackAln *] + * + */ +bp_sw_PackAln * bp_sw_free_PackAln( bp_sw_PackAln * obj); + +/* API for object PackAlnUnit */ +/* Function: bp_sw_hard_link_PackAlnUnit(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_PackAlnUnit *] + * + * Returns Undocumented return value [bp_sw_PackAlnUnit *] + * + */ +bp_sw_PackAlnUnit * bp_sw_hard_link_PackAlnUnit( bp_sw_PackAlnUnit * obj); + +/* Function: bp_sw_PackAlnUnit_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_PackAlnUnit *] + * + */ +bp_sw_PackAlnUnit * bp_sw_PackAlnUnit_alloc(); + +/* Function: bp_sw_replace_i_PackAlnUnit(obj,i) + * + * Descrip: Replace member variable i + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_PackAlnUnit *] + * Arg: i New value of the variable [int] + * + * Returns member variable i [boolean] + * + */ +boolean bp_sw_replace_i_PackAlnUnit( bp_sw_PackAlnUnit * obj,int i); + +/* Function: bp_sw_access_i_PackAlnUnit(obj) + * + * Descrip: Access member variable i + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_PackAlnUnit *] + * + * Returns member variable i [int] + * + */ +int bp_sw_access_i_PackAlnUnit( bp_sw_PackAlnUnit * obj); + +/* Function: bp_sw_replace_j_PackAlnUnit(obj,j) + * + * Descrip: Replace member variable j + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_PackAlnUnit *] + * Arg: j New value of the variable [int] + * + * Returns member variable j [boolean] + * + */ +boolean bp_sw_replace_j_PackAlnUnit( bp_sw_PackAlnUnit * obj,int j); + +/* Function: bp_sw_access_j_PackAlnUnit(obj) + * + * Descrip: Access member variable j + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_PackAlnUnit *] + * + * Returns member variable j [int] + * + */ +int bp_sw_access_j_PackAlnUnit( bp_sw_PackAlnUnit * obj); + +/* Function: bp_sw_replace_state_PackAlnUnit(obj,state) + * + * Descrip: Replace member variable state + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_PackAlnUnit *] + * Arg: state New value of the variable [int] + * + * Returns member variable state [boolean] + * + */ +boolean bp_sw_replace_state_PackAlnUnit( bp_sw_PackAlnUnit * obj,int state); + +/* Function: bp_sw_access_state_PackAlnUnit(obj) + * + * Descrip: Access member variable state + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_PackAlnUnit *] + * + * Returns member variable state [int] + * + */ +int bp_sw_access_state_PackAlnUnit( bp_sw_PackAlnUnit * obj); + +/* Function: bp_sw_replace_score_PackAlnUnit(obj,score) + * + * Descrip: Replace member variable score + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_PackAlnUnit *] + * Arg: score New value of the variable [int] + * + * Returns member variable score [boolean] + * + */ +boolean bp_sw_replace_score_PackAlnUnit( bp_sw_PackAlnUnit * obj,int score); + +/* Function: bp_sw_access_score_PackAlnUnit(obj) + * + * Descrip: Access member variable score + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_PackAlnUnit *] + * + * Returns member variable score [int] + * + */ +int bp_sw_access_score_PackAlnUnit( bp_sw_PackAlnUnit * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_PackAlnUnit(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_PackAlnUnit *] + * + * Returns Undocumented return value [bp_sw_PackAlnUnit *] + * + */ +bp_sw_PackAlnUnit * bp_sw_free_PackAlnUnit( bp_sw_PackAlnUnit * obj); + + + +/* Helper functions in the module + * + * bp_sw_Probability_from_average_state_occupancy + * bp_sw_state_occupancy_from_Probability + * bp_sw_Probability2Score + * bp_sw_Score2Probability + * bp_sw_Score2Bits + * bp_sw_halfbit2Probability + * + + + +/* These functions are not associated with an object */ +/* Function: bp_sw_Probability_from_average_state_occupancy(length) + * + * Descrip: for single state (exponetial decays) takes an average length + * and converts that to a probability that will produce that + * length (on average) for the state. NB... this *assumes* that + * you want a single state exp decay. + * + * + * Arg: length average length of state [double] + * + * Returns Undocumented return value [Probability] + * + */ +Probability bp_sw_Probability_from_average_state_occupancy( double length); + +/* Function: bp_sw_state_occupancy_from_Probability(p) + * + * Descrip: If you have a single state then this will tak + * the probability for the state->state transition and + * give you back the average length in the state + * + * + * Arg: p probability of staying in the state [double] + * + * Returns Undocumented return value [double] + * + */ +double bp_sw_state_occupancy_from_Probability( double p); + +/* Function: bp_sw_Probability2Score(p) + * + * Descrip: maps probabilities to scores. Deals + * sensibly with 0's. + * + * + * Arg: p Undocumented argument [Probability] + * + * Returns Undocumented return value [Score] + * + */ +Score bp_sw_Probability2Score( Probability p); + +/* Function: bp_sw_Score2Probability(s) + * + * Descrip: maps scores to probabilities + * + * + * Arg: s Undocumented argument [Score] + * + * Returns Undocumented return value [Probability] + * + */ +Probability bp_sw_Score2Probability( Score s); + +/* Function: bp_sw_Score2Bits(s) + * + * Descrip: maps scores to bits + * + * + * Arg: s Undocumented argument [Score] + * + * Returns Undocumented return value [Bits] + * + */ +Bits bp_sw_Score2Bits( Score s); + +/* Function: bp_sw_halfbit2Probability(half_bit) + * + * Descrip: maps halfbits (log2(prob*2) to + * probabilities + * + * + * Arg: half_bit Undocumented argument [double] + * + * Returns Undocumented return value [Probability] + * + */ +Probability bp_sw_halfbit2Probability( double half_bit); + + + +/* Functions that create, manipulate or act on Protein + * + * bp_sw_Protein_from_Sequence + * bp_sw_hard_link_Protein + * bp_sw_Protein_alloc + * bp_sw_replace_baseseq_Protein + * bp_sw_access_baseseq_Protein + * bp_sw_free_Protein [destructor] + * + */ + +/* API for object Protein */ +/* Function: bp_sw_Protein_from_Sequence(seq) + * + * Descrip: makes a new protein from a Sequence. It + * owns the Sequence memory, ie will attempt a /free_Sequence + * on the structure when /free_Protein is called + * + * If you want to give this protein this Sequence and + * forget about it, then just hand it this sequence and set + * seq to NULL (no need to free it). If you intend to use + * the sequecne object elsewhere outside of the Protein datastructure + * then use Protein_from_Sequence(/hard_link_Sequence(seq)) + * + * + * + * Arg: seq Sequence to make protein from [bp_sw_Sequence *] + * + * Returns Undocumented return value [bp_sw_Protein *] + * + */ +bp_sw_Protein * bp_sw_Protein_from_Sequence( bp_sw_Sequence * seq); + +/* Function: bp_sw_hard_link_Protein(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_Protein *] + * + * Returns Undocumented return value [bp_sw_Protein *] + * + */ +bp_sw_Protein * bp_sw_hard_link_Protein( bp_sw_Protein * obj); + +/* Function: bp_sw_Protein_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_Protein *] + * + */ +bp_sw_Protein * bp_sw_Protein_alloc(); + +/* Function: bp_sw_replace_baseseq_Protein(obj,baseseq) + * + * Descrip: Replace member variable baseseq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Protein *] + * Arg: baseseq New value of the variable [bp_sw_Sequence *] + * + * Returns member variable baseseq [boolean] + * + */ +boolean bp_sw_replace_baseseq_Protein( bp_sw_Protein * obj,bp_sw_Sequence * baseseq); + +/* Function: bp_sw_access_baseseq_Protein(obj) + * + * Descrip: Access member variable baseseq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Protein *] + * + * Returns member variable baseseq [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_access_baseseq_Protein( bp_sw_Protein * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_Protein(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_Protein *] + * + * Returns Undocumented return value [bp_sw_Protein *] + * + */ +bp_sw_Protein * bp_sw_free_Protein( bp_sw_Protein * obj); + + + +/* Functions that create, manipulate or act on ProteinDB + * + * bp_sw_hard_link_ProteinDB + * bp_sw_ProteinDB_alloc + * bp_sw_replace_is_single_seq_ProteinDB + * bp_sw_access_is_single_seq_ProteinDB + * bp_sw_replace_single_ProteinDB + * bp_sw_access_single_ProteinDB + * bp_sw_replace_sdb_ProteinDB + * bp_sw_access_sdb_ProteinDB + * bp_sw_replace_cses_ProteinDB + * bp_sw_access_cses_ProteinDB + * bp_sw_free_ProteinDB [destructor] + * + */ + + + +/* Helper functions in the module + * + * bp_sw_new_ProteinDB_from_single_seq + * bp_sw_single_fasta_ProteinDB + * bp_sw_new_ProteinDB + * + +/* API for object ProteinDB */ +/* Function: bp_sw_hard_link_ProteinDB(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_ProteinDB *] + * + * Returns Undocumented return value [bp_sw_ProteinDB *] + * + */ +bp_sw_ProteinDB * bp_sw_hard_link_ProteinDB( bp_sw_ProteinDB * obj); + +/* Function: bp_sw_ProteinDB_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_ProteinDB *] + * + */ +bp_sw_ProteinDB * bp_sw_ProteinDB_alloc(); + +/* Function: bp_sw_replace_is_single_seq_ProteinDB(obj,is_single_seq) + * + * Descrip: Replace member variable is_single_seq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ProteinDB *] + * Arg: is_single_seq New value of the variable [boolean] + * + * Returns member variable is_single_seq [boolean] + * + */ +boolean bp_sw_replace_is_single_seq_ProteinDB( bp_sw_ProteinDB * obj,boolean is_single_seq); + +/* Function: bp_sw_access_is_single_seq_ProteinDB(obj) + * + * Descrip: Access member variable is_single_seq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ProteinDB *] + * + * Returns member variable is_single_seq [boolean] + * + */ +boolean bp_sw_access_is_single_seq_ProteinDB( bp_sw_ProteinDB * obj); + +/* Function: bp_sw_replace_single_ProteinDB(obj,single) + * + * Descrip: Replace member variable single + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ProteinDB *] + * Arg: single New value of the variable [bp_sw_ComplexSequence *] + * + * Returns member variable single [boolean] + * + */ +boolean bp_sw_replace_single_ProteinDB( bp_sw_ProteinDB * obj,bp_sw_ComplexSequence * single); + +/* Function: bp_sw_access_single_ProteinDB(obj) + * + * Descrip: Access member variable single + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ProteinDB *] + * + * Returns member variable single [bp_sw_ComplexSequence *] + * + */ +bp_sw_ComplexSequence * bp_sw_access_single_ProteinDB( bp_sw_ProteinDB * obj); + +/* Function: bp_sw_replace_sdb_ProteinDB(obj,sdb) + * + * Descrip: Replace member variable sdb + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ProteinDB *] + * Arg: sdb New value of the variable [bp_sw_SequenceDB *] + * + * Returns member variable sdb [boolean] + * + */ +boolean bp_sw_replace_sdb_ProteinDB( bp_sw_ProteinDB * obj,bp_sw_SequenceDB * sdb); + +/* Function: bp_sw_access_sdb_ProteinDB(obj) + * + * Descrip: Access member variable sdb + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ProteinDB *] + * + * Returns member variable sdb [bp_sw_SequenceDB *] + * + */ +bp_sw_SequenceDB * bp_sw_access_sdb_ProteinDB( bp_sw_ProteinDB * obj); + +/* Function: bp_sw_replace_cses_ProteinDB(obj,cses) + * + * Descrip: Replace member variable cses + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ProteinDB *] + * Arg: cses New value of the variable [bp_sw_ComplexSequenceEvalSet *] + * + * Returns member variable cses [boolean] + * + */ +boolean bp_sw_replace_cses_ProteinDB( bp_sw_ProteinDB * obj,bp_sw_ComplexSequenceEvalSet * cses); + +/* Function: bp_sw_access_cses_ProteinDB(obj) + * + * Descrip: Access member variable cses + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_ProteinDB *] + * + * Returns member variable cses [bp_sw_ComplexSequenceEvalSet *] + * + */ +bp_sw_ComplexSequenceEvalSet * bp_sw_access_cses_ProteinDB( bp_sw_ProteinDB * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_ProteinDB(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_ProteinDB *] + * + * Returns Undocumented return value [bp_sw_ProteinDB *] + * + */ +bp_sw_ProteinDB * bp_sw_free_ProteinDB( bp_sw_ProteinDB * obj); + + + +/* These functions are not associated with an object */ +/* Function: bp_sw_new_ProteinDB_from_single_seq(seq) + * + * Descrip: To make a new protein database + * from a single Sequence with default amino acid mapping + * + * + * Arg: seq sequence which as placed into ProteinDB structure. [bp_sw_Sequence *] + * + * Returns Undocumented return value [bp_sw_ProteinDB *] + * + */ +bp_sw_ProteinDB * bp_sw_new_ProteinDB_from_single_seq( bp_sw_Sequence * seq); + +/* Function: bp_sw_single_fasta_ProteinDB(filename) + * + * Descrip: pre-packed single fasta protein database + * + * + * + * Arg: filename name of fasta file [char *] + * + * Returns Undocumented return value [bp_sw_ProteinDB *] + * + */ +bp_sw_ProteinDB * bp_sw_single_fasta_ProteinDB( char * filename); + +/* Function: bp_sw_new_ProteinDB(seqdb,cses) + * + * Descrip: To make a new protein database + * + * + * Arg: seqdb sequence database [bp_sw_SequenceDB *] + * Arg: cses protein evaluation set [bp_sw_ComplexSequenceEvalSet *] + * + * Returns Undocumented return value [bp_sw_ProteinDB *] + * + */ +bp_sw_ProteinDB * bp_sw_new_ProteinDB( bp_sw_SequenceDB * seqdb,bp_sw_ComplexSequenceEvalSet * cses); + + + +/* Helper functions in the module + * + * bp_sw_write_pretty_str_align + * bp_sw_write_pretty_seq_align + * bp_sw_write_pretty_Protein_align + * + + + +/* These functions are not associated with an object */ +/* Function: bp_sw_write_pretty_str_align(alb,qname,query,tname,target,name,main,ofp) + * + * Descrip: This gives an interface into the alignment + * display using strings and files. + * + * + * Arg: alb alignment structure [bp_sw_AlnBlock *] + * Arg: qname name of first sequence [char *] + * Arg: query first sequence [char *] + * Arg: tname name of second sequence [char *] + * Arg: target second sequence [char *] + * Arg: name length of the name block [int] + * Arg: main length of the main block [int] + * Arg: ofp output file [FILE *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_write_pretty_str_align( bp_sw_AlnBlock * alb,char * qname,char * query,char * tname,char * target,int name,int main,FILE * ofp); + +/* Function: bp_sw_write_pretty_seq_align(alb,q,t,name,main,ofp) + * + * Descrip: This gives an interface into the alignment + * display using sequences and files. A more + * generic function is write_pretty_str_align + * + * + * Arg: alb alignment structure [bp_sw_AlnBlock *] + * Arg: q first sequence [bp_sw_Sequence *] + * Arg: t second sequence [bp_sw_Sequence *] + * Arg: name length of the name block [int] + * Arg: main length of the main block [int] + * Arg: ofp output file [FILE *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_write_pretty_seq_align( bp_sw_AlnBlock * alb,bp_sw_Sequence * q,bp_sw_Sequence * t,int name,int main,FILE * ofp); + +/* Function: bp_sw_write_pretty_Protein_align(alb,q,t,name,main,ofp) + * + * Descrip: This gives an interface into the + * alignment display using Protein + * objects + * + * + * Arg: alb alignment structure [bp_sw_AlnBlock *] + * Arg: q first sequence [bp_sw_Protein *] + * Arg: t second sequence [bp_sw_Protein *] + * Arg: name length of the name block [int] + * Arg: main length of the main block [int] + * Arg: ofp output file [FILE *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_write_pretty_Protein_align( bp_sw_AlnBlock * alb,bp_sw_Protein * q,bp_sw_Protein * t,int name,int main,FILE * ofp); + + + +/* Functions that create, manipulate or act on Sequence + * + * bp_sw_uppercase_Sequence + * bp_sw_force_to_dna_Sequence + * bp_sw_is_reversed_Sequence + * bp_sw_translate_Sequence + * bp_sw_reverse_complement_Sequence + * bp_sw_magic_trunc_Sequence + * bp_sw_trunc_Sequence + * bp_sw_read_fasta_file_Sequence + * bp_sw_read_Sequence_EMBL_seq + * bp_sw_read_fasta_Sequence + * bp_sw_show_Sequence_residue_list + * bp_sw_write_fasta_Sequence + * bp_sw_make_len_type_Sequence + * bp_sw_hard_link_Sequence + * bp_sw_Sequence_alloc + * bp_sw_replace_name_Sequence + * bp_sw_access_name_Sequence + * bp_sw_replace_seq_Sequence + * bp_sw_access_seq_Sequence + * bp_sw_replace_len_Sequence + * bp_sw_access_len_Sequence + * bp_sw_replace_maxlen_Sequence + * bp_sw_access_maxlen_Sequence + * bp_sw_replace_offset_Sequence + * bp_sw_access_offset_Sequence + * bp_sw_replace_end_Sequence + * bp_sw_access_end_Sequence + * bp_sw_replace_type_Sequence + * bp_sw_access_type_Sequence + * bp_sw_free_Sequence [destructor] + * + */ + + + +/* Helper functions in the module + * + * bp_sw_Sequence_type_to_string + * bp_sw_new_Sequence_from_strings + * + +/* API for object Sequence */ +/* Function: bp_sw_uppercase_Sequence(seq) + * + * Descrip: makes all the sequence uppercase + * + * + * Arg: seq Sequence to be uppercas'd [bp_sw_Sequence *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_uppercase_Sequence( bp_sw_Sequence * seq); + +/* Function: bp_sw_force_to_dna_Sequence(seq,fraction,number_of_conver) + * + * Descrip: This + * a) sees how many non ATGCN characters there are in Seq + * b) If the level is below fraction + * a) flips non ATGC chars to N + * b) writes number of conversions to number_of_conver + * c) returns TRUE + * c) else returns FALSE + * + * fraction of 0.0 means completely intolerant of errors + * fraction of 1.0 means completely tolerant of errors + * + * + * + * Arg: seq sequence object read and converted [bp_sw_Sequence *] + * Arg: fraction number 0..1 for tolerance of conversion [double] + * Arg: number_of_conver number of conversions actually made [int *] + * + * Returns TRUE for conversion to DNA, FALSE if not [boolean] + * + */ +boolean bp_sw_force_to_dna_Sequence( bp_sw_Sequence * seq,double fraction,int * number_of_conver); + +/* Function: bp_sw_is_reversed_Sequence(seq) + * + * Descrip: Currently the sequence object stores + * reversed sequences as start > end. + * + * This tests that and returns true if it is + * + * + * Arg: seq sequence to test [bp_sw_Sequence *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_is_reversed_Sequence( bp_sw_Sequence * seq); + +/* Function: bp_sw_translate_Sequence(dna,ct) + * + * Descrip: This translates a DNA sequence to a protein. + * It assummes that it starts at first residue + * (use trunc_Sequence to chop a sequence up). + * + * + * Arg: dna DNA sequence to be translated [bp_sw_Sequence *] + * Arg: ct Codon table to do codon->aa mapping [bp_sw_CodonTable *] + * + * Returns new protein sequence [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_translate_Sequence( bp_sw_Sequence * dna,bp_sw_CodonTable * ct); + +/* Function: bp_sw_reverse_complement_Sequence(seq) + * + * Descrip: This both complements and reverses a sequence, + * - a common wish! + * + * The start/end are correct with respect to the start/end + * of the sequence (ie start = end, end = start). + * + * + * Arg: seq Sequence to that is used to reverse (makes a new Sequence) [bp_sw_Sequence *] + * + * Returns new Sequence which is reversed [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_reverse_complement_Sequence( bp_sw_Sequence * seq); + +/* Function: bp_sw_magic_trunc_Sequence(seq,start,end) + * + * Descrip: Clever function for dna sequences. + * + * When start < end, truncates normally + * + * when start > end, truncates end,start and then + * reverse complements. + * + * ie. If you have a coordinate system where reverse + * sequences are labelled in reverse start/end way, + * then this routine produces the correct sequence. + * + * + * Arg: seq sequence that is the source to be truncated [bp_sw_Sequence *] + * Arg: start start point [int] + * Arg: end end point [int] + * + * Returns new Sequence which is truncated/reversed [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_magic_trunc_Sequence( bp_sw_Sequence * seq,int start,int end); + +/* Function: bp_sw_trunc_Sequence(seq,start,end) + * + * Descrip: truncates a sequence. It produces a new memory structure + * which is filled from sequence start to end. + * + * Please notice + * + * Truncation is in C coordinates. That is + * the first residue is 0 and end is the number of the + * residue after the cut-point. In otherwords to + * 2 - 3 would be a single residue truncation. So - if + * you want to work in more usual, 'inclusive' molecular + * biology numbers, which start at 1, then you need to say + * + * trunc_Sequence(seq,start-1,end); + * + * (NB, should be (end - 1 + 1) = end for the last coordinate). + * + * Truncation occurs against the *absolute* coordinate + * system of the Sequence, not the offset/end pair inside. + * So, this is a very bad error + * + * ** wrong code, and also leaks memory ** + * + * tru = trunc_Sequence(trunc_Sequence(seq,50,80),55,75); + * + * This the most portable way of doing this + * + * temp = trunc_Sequence(seq,50,80); + * + * tru = trunc_Sequence(temp,55-temp->offset,75-temp->offset); + * + * free_Sequence(temp); + * + * + * + * Arg: seq object holding the sequence to be truncated [bp_sw_Sequence *] + * Arg: start start point of truncation [int] + * Arg: end end point of truncation [int] + * + * Returns newly allocated sequence structure [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_trunc_Sequence( bp_sw_Sequence * seq,int start,int end); + +/* Function: bp_sw_read_fasta_file_Sequence(filename) + * + * Descrip: Just a call + * a) open filename + * b) read sequence with /read_fasta_Sequence + * c) close file. + * + * + * Arg: filename filename to open [char *] + * + * Returns Undocumented return value [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_read_fasta_file_Sequence( char * filename); + +/* Function: bp_sw_read_Sequence_EMBL_seq(buffer,maxlen,ifp) + * + * Descrip: reads the sequence part of an EMBL file. + * + * This function can either take a file which + * starts + * + * + * + * Arg: buffer buffer containing the first line. [char *] + * Arg: maxlen length of buffer [int] + * Arg: ifp input file to read from [FILE *] + * + * Returns Undocumented return value [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_read_Sequence_EMBL_seq( char * buffer,int maxlen,FILE * ifp); + +/* Function: bp_sw_read_fasta_Sequence(ifp) + * + * Descrip: reads the fasta file: format is + * + * >name + * sequence + * + * allocates a structure and puts in the + * sequence. Calls /make_len_type_Sequence to + * check type and length. + * + * It leaves the '>' on the next fasta sequence + * for multiple sequence reading + * + * + * Arg: ifp input file to read from [FILE *] + * + * Returns new Sequence structure [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_read_fasta_Sequence( FILE * ifp); + +/* Function: bp_sw_show_Sequence_residue_list(seq,start,end,ofp) + * + * Descrip: shows a region of a sequence as + * 124 A + * 125 T + * + * etc from start to end. The numbers + * are in C coordinates (ie, 0 is the first + * letter). + * + * useful for debugging + * + * + * Arg: seq Sequence to show [bp_sw_Sequence *] + * Arg: start start of list [int] + * Arg: end end of list [int] + * Arg: ofp Undocumented argument [FILE *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_show_Sequence_residue_list( bp_sw_Sequence * seq,int start,int end,FILE * ofp); + +/* Function: bp_sw_write_fasta_Sequence(seq,ofp) + * + * Descrip: writes a fasta file of the form + * >name + * Sequence + * + * + * Arg: seq sequence to be written [bp_sw_Sequence *] + * Arg: ofp file to write to [FILE *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_write_fasta_Sequence( bp_sw_Sequence * seq,FILE * ofp); + +/* Function: bp_sw_make_len_type_Sequence(seq) + * + * Descrip: makes seq->len and seq->end match the seq->seq + * length number. + * + * It also checks the type of the sequence with + * /best_guess_type + * + * + * Arg: seq Sequence object [bp_sw_Sequence *] + * + * Returns Undocumented return value [void] + * + */ +void bp_sw_make_len_type_Sequence( bp_sw_Sequence * seq); + +/* Function: bp_sw_hard_link_Sequence(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_Sequence *] + * + * Returns Undocumented return value [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_hard_link_Sequence( bp_sw_Sequence * obj); + +/* Function: bp_sw_Sequence_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_Sequence_alloc(); + +/* Function: bp_sw_replace_name_Sequence(obj,name) + * + * Descrip: Replace member variable name + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * Arg: name New value of the variable [char *] + * + * Returns member variable name [boolean] + * + */ +boolean bp_sw_replace_name_Sequence( bp_sw_Sequence * obj,char * name); + +/* Function: bp_sw_access_name_Sequence(obj) + * + * Descrip: Access member variable name + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * + * Returns member variable name [char *] + * + */ +char * bp_sw_access_name_Sequence( bp_sw_Sequence * obj); + +/* Function: bp_sw_replace_seq_Sequence(obj,seq) + * + * Descrip: Replace member variable seq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * Arg: seq New value of the variable [char *] + * + * Returns member variable seq [boolean] + * + */ +boolean bp_sw_replace_seq_Sequence( bp_sw_Sequence * obj,char * seq); + +/* Function: bp_sw_access_seq_Sequence(obj) + * + * Descrip: Access member variable seq + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * + * Returns member variable seq [char *] + * + */ +char * bp_sw_access_seq_Sequence( bp_sw_Sequence * obj); + +/* Function: bp_sw_replace_len_Sequence(obj,len) + * + * Descrip: Replace member variable len + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * Arg: len New value of the variable [int] + * + * Returns member variable len [boolean] + * + */ +boolean bp_sw_replace_len_Sequence( bp_sw_Sequence * obj,int len); + +/* Function: bp_sw_access_len_Sequence(obj) + * + * Descrip: Access member variable len + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * + * Returns member variable len [int] + * + */ +int bp_sw_access_len_Sequence( bp_sw_Sequence * obj); + +/* Function: bp_sw_replace_maxlen_Sequence(obj,maxlen) + * + * Descrip: Replace member variable maxlen + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * Arg: maxlen New value of the variable [int] + * + * Returns member variable maxlen [boolean] + * + */ +boolean bp_sw_replace_maxlen_Sequence( bp_sw_Sequence * obj,int maxlen); + +/* Function: bp_sw_access_maxlen_Sequence(obj) + * + * Descrip: Access member variable maxlen + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * + * Returns member variable maxlen [int] + * + */ +int bp_sw_access_maxlen_Sequence( bp_sw_Sequence * obj); + +/* Function: bp_sw_replace_offset_Sequence(obj,offset) + * + * Descrip: Replace member variable offset + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * Arg: offset New value of the variable [int] + * + * Returns member variable offset [boolean] + * + */ +boolean bp_sw_replace_offset_Sequence( bp_sw_Sequence * obj,int offset); + +/* Function: bp_sw_access_offset_Sequence(obj) + * + * Descrip: Access member variable offset + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * + * Returns member variable offset [int] + * + */ +int bp_sw_access_offset_Sequence( bp_sw_Sequence * obj); + +/* Function: bp_sw_replace_end_Sequence(obj,end) + * + * Descrip: Replace member variable end + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * Arg: end New value of the variable [int] + * + * Returns member variable end [boolean] + * + */ +boolean bp_sw_replace_end_Sequence( bp_sw_Sequence * obj,int end); + +/* Function: bp_sw_access_end_Sequence(obj) + * + * Descrip: Access member variable end + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * + * Returns member variable end [int] + * + */ +int bp_sw_access_end_Sequence( bp_sw_Sequence * obj); + +/* Function: bp_sw_replace_type_Sequence(obj,type) + * + * Descrip: Replace member variable type + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * Arg: type New value of the variable [int] + * + * Returns member variable type [boolean] + * + */ +boolean bp_sw_replace_type_Sequence( bp_sw_Sequence * obj,int type); + +/* Function: bp_sw_access_type_Sequence(obj) + * + * Descrip: Access member variable type + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Sequence *] + * + * Returns member variable type [int] + * + */ +int bp_sw_access_type_Sequence( bp_sw_Sequence * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_Sequence(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_Sequence *] + * + * Returns Undocumented return value [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_free_Sequence( bp_sw_Sequence * obj); + + + +/* These functions are not associated with an object */ +/* Function: bp_sw_Sequence_type_to_string(type) + * + * Descrip: Converts sequence type (SEQUENCE_*) to a string + * + * + * Arg: type type eg SEQUENCE_PROTEIN [int] + * + * Returns Undocumented return value [char *] + * + */ +char * bp_sw_Sequence_type_to_string( int type); + +/* Function: bp_sw_new_Sequence_from_strings(name,seq) + * + * Descrip: Makes a new sequence from strings given. + * Separate memory will be allocated for them + * and them copied into it. + * + * They can be NULL, in which case + * o a dummy name SequenceName will be assigned + * o No sequence placed and length of zero. + * + * Though this is dangerous later on. + * + * The sequence type is calculated automatically using + * /best_guess_type. If you want a DNA sequence but are + * unsure of the content of, for example, IUPAC codes, + * please use /force_to_dna_Sequence before using the + * sequence. Most of the rest of dynamite relies on a + * five letter A,T,G,C,N alphabet, but this function + * will allow any sequence type to be stored, so please + * check if you want to save yourself alot of grief. + * + * In perl and other interfaces, this is a much safer + * constructor than the raw "new" type + * + * + * Arg: name name of sequence, memory is allocated for it. [char *] + * Arg: seq char * of sequence, memory is allocated for it. [char *] + * + * Returns Undocumented return value [bp_sw_Sequence *] + * + */ +bp_sw_Sequence * bp_sw_new_Sequence_from_strings( char * name,char * seq); + + + +/* Functions that create, manipulate or act on SequenceDB + * + * bp_sw_single_fasta_SequenceDB + * bp_sw_hard_link_SequenceDB + * bp_sw_SequenceDB_alloc_std + * bp_sw_replace_name_SequenceDB + * bp_sw_access_name_SequenceDB + * bp_sw_access_fs_SequenceDB + * bp_sw_length_fs_SequenceDB + * bp_sw_flush_SequenceDB + * bp_sw_add_SequenceDB + * bp_sw_replace_current_source_SequenceDB + * bp_sw_access_current_source_SequenceDB + * bp_sw_replace_current_file_SequenceDB + * bp_sw_access_current_file_SequenceDB + * bp_sw_replace_sequence_no_SequenceDB + * bp_sw_access_sequence_no_SequenceDB + * bp_sw_replace_byte_position_SequenceDB + * bp_sw_access_byte_position_SequenceDB + * bp_sw_free_SequenceDB [destructor] + * + */ + + + +/* Functions that create, manipulate or act on FileSource + * + * bp_sw_hard_link_FileSource + * bp_sw_FileSource_alloc + * bp_sw_replace_filename_FileSource + * bp_sw_access_filename_FileSource + * bp_sw_replace_input_FileSource + * bp_sw_access_input_FileSource + * bp_sw_replace_format_FileSource + * bp_sw_access_format_FileSource + * bp_sw_replace_type_FileSource + * bp_sw_access_type_FileSource + * bp_sw_free_FileSource [destructor] + * + */ + +/* API for object SequenceDB */ +/* Function: bp_sw_single_fasta_SequenceDB(filename) + * + * Descrip: pre-packed single fasta file db + * + * + * + * Arg: filename name of fastadb [char *] + * + * Returns Undocumented return value [bp_sw_SequenceDB *] + * + */ +bp_sw_SequenceDB * bp_sw_single_fasta_SequenceDB( char * filename); + +/* Function: bp_sw_hard_link_SequenceDB(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_SequenceDB *] + * + * Returns Undocumented return value [bp_sw_SequenceDB *] + * + */ +bp_sw_SequenceDB * bp_sw_hard_link_SequenceDB( bp_sw_SequenceDB * obj); + +/* Function: bp_sw_SequenceDB_alloc_std(void) + * + * Descrip: Equivalent to SequenceDB_alloc_len(SequenceDBLISTLENGTH) + * + * + * + * Returns Undocumented return value [bp_sw_SequenceDB *] + * + */ +bp_sw_SequenceDB * bp_sw_SequenceDB_alloc_std(); + +/* Function: bp_sw_replace_name_SequenceDB(obj,name) + * + * Descrip: Replace member variable name + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_SequenceDB *] + * Arg: name New value of the variable [char *] + * + * Returns member variable name [boolean] + * + */ +boolean bp_sw_replace_name_SequenceDB( bp_sw_SequenceDB * obj,char * name); + +/* Function: bp_sw_access_name_SequenceDB(obj) + * + * Descrip: Access member variable name + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_SequenceDB *] + * + * Returns member variable name [char *] + * + */ +char * bp_sw_access_name_SequenceDB( bp_sw_SequenceDB * obj); + +/* Function: bp_sw_access_fs_SequenceDB(obj,i) + * + * Descrip: Access members stored in the fs list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_SequenceDB *] + * Arg: i Position in the list [int] + * + * Returns Element of the list [bp_sw_FileSource *] + * + */ +bp_sw_FileSource * bp_sw_access_fs_SequenceDB( bp_sw_SequenceDB * obj,int i); + +/* Function: bp_sw_length_fs_SequenceDB(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_SequenceDB *] + * + * Returns length of the list [int] + * + */ +int bp_sw_length_fs_SequenceDB( bp_sw_SequenceDB * obj); + +/* Function: bp_sw_flush_SequenceDB(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj Object which contains the list [bp_sw_SequenceDB *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_flush_SequenceDB( bp_sw_SequenceDB * obj); + +/* Function: bp_sw_add_SequenceDB(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj Object which contains the list [bp_sw_SequenceDB *] + * Arg: add Object to add to the list [bp_sw_FileSource *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_add_SequenceDB( bp_sw_SequenceDB * obj,bp_sw_FileSource * add); + +/* Function: bp_sw_replace_current_source_SequenceDB(obj,current_source) + * + * Descrip: Replace member variable current_source + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_SequenceDB *] + * Arg: current_source New value of the variable [int] + * + * Returns member variable current_source [boolean] + * + */ +boolean bp_sw_replace_current_source_SequenceDB( bp_sw_SequenceDB * obj,int current_source); + +/* Function: bp_sw_access_current_source_SequenceDB(obj) + * + * Descrip: Access member variable current_source + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_SequenceDB *] + * + * Returns member variable current_source [int] + * + */ +int bp_sw_access_current_source_SequenceDB( bp_sw_SequenceDB * obj); + +/* Function: bp_sw_replace_current_file_SequenceDB(obj,current_file) + * + * Descrip: Replace member variable current_file + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_SequenceDB *] + * Arg: current_file New value of the variable [FILE *] + * + * Returns member variable current_file [boolean] + * + */ +boolean bp_sw_replace_current_file_SequenceDB( bp_sw_SequenceDB * obj,FILE * current_file); + +/* Function: bp_sw_access_current_file_SequenceDB(obj) + * + * Descrip: Access member variable current_file + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_SequenceDB *] + * + * Returns member variable current_file [FILE *] + * + */ +FILE * bp_sw_access_current_file_SequenceDB( bp_sw_SequenceDB * obj); + +/* Function: bp_sw_replace_sequence_no_SequenceDB(obj,sequence_no) + * + * Descrip: Replace member variable sequence_no + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_SequenceDB *] + * Arg: sequence_no New value of the variable [int] + * + * Returns member variable sequence_no [boolean] + * + */ +boolean bp_sw_replace_sequence_no_SequenceDB( bp_sw_SequenceDB * obj,int sequence_no); + +/* Function: bp_sw_access_sequence_no_SequenceDB(obj) + * + * Descrip: Access member variable sequence_no + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_SequenceDB *] + * + * Returns member variable sequence_no [int] + * + */ +int bp_sw_access_sequence_no_SequenceDB( bp_sw_SequenceDB * obj); + +/* Function: bp_sw_replace_byte_position_SequenceDB(obj,byte_position) + * + * Descrip: Replace member variable byte_position + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_SequenceDB *] + * Arg: byte_position New value of the variable [int] + * + * Returns member variable byte_position [boolean] + * + */ +boolean bp_sw_replace_byte_position_SequenceDB( bp_sw_SequenceDB * obj,int byte_position); + +/* Function: bp_sw_access_byte_position_SequenceDB(obj) + * + * Descrip: Access member variable byte_position + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_SequenceDB *] + * + * Returns member variable byte_position [int] + * + */ +int bp_sw_access_byte_position_SequenceDB( bp_sw_SequenceDB * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_SequenceDB(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_SequenceDB *] + * + * Returns Undocumented return value [bp_sw_SequenceDB *] + * + */ +bp_sw_SequenceDB * bp_sw_free_SequenceDB( bp_sw_SequenceDB * obj); + +/* API for object FileSource */ +/* Function: bp_sw_hard_link_FileSource(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_FileSource *] + * + * Returns Undocumented return value [bp_sw_FileSource *] + * + */ +bp_sw_FileSource * bp_sw_hard_link_FileSource( bp_sw_FileSource * obj); + +/* Function: bp_sw_FileSource_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_FileSource *] + * + */ +bp_sw_FileSource * bp_sw_FileSource_alloc(); + +/* Function: bp_sw_replace_filename_FileSource(obj,filename) + * + * Descrip: Replace member variable filename + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_FileSource *] + * Arg: filename New value of the variable [char *] + * + * Returns member variable filename [boolean] + * + */ +boolean bp_sw_replace_filename_FileSource( bp_sw_FileSource * obj,char * filename); + +/* Function: bp_sw_access_filename_FileSource(obj) + * + * Descrip: Access member variable filename + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_FileSource *] + * + * Returns member variable filename [char *] + * + */ +char * bp_sw_access_filename_FileSource( bp_sw_FileSource * obj); + +/* Function: bp_sw_replace_input_FileSource(obj,input) + * + * Descrip: Replace member variable input + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_FileSource *] + * Arg: input New value of the variable [FILE *] + * + * Returns member variable input [boolean] + * + */ +boolean bp_sw_replace_input_FileSource( bp_sw_FileSource * obj,FILE * input); + +/* Function: bp_sw_access_input_FileSource(obj) + * + * Descrip: Access member variable input + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_FileSource *] + * + * Returns member variable input [FILE *] + * + */ +FILE * bp_sw_access_input_FileSource( bp_sw_FileSource * obj); + +/* Function: bp_sw_replace_format_FileSource(obj,format) + * + * Descrip: Replace member variable format + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_FileSource *] + * Arg: format New value of the variable [int] + * + * Returns member variable format [boolean] + * + */ +boolean bp_sw_replace_format_FileSource( bp_sw_FileSource * obj,int format); + +/* Function: bp_sw_access_format_FileSource(obj) + * + * Descrip: Access member variable format + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_FileSource *] + * + * Returns member variable format [int] + * + */ +int bp_sw_access_format_FileSource( bp_sw_FileSource * obj); + +/* Function: bp_sw_replace_type_FileSource(obj,type) + * + * Descrip: Replace member variable type + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_FileSource *] + * Arg: type New value of the variable [int] + * + * Returns member variable type [boolean] + * + */ +boolean bp_sw_replace_type_FileSource( bp_sw_FileSource * obj,int type); + +/* Function: bp_sw_access_type_FileSource(obj) + * + * Descrip: Access member variable type + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_FileSource *] + * + * Returns member variable type [int] + * + */ +int bp_sw_access_type_FileSource( bp_sw_FileSource * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_FileSource(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_FileSource *] + * + * Returns Undocumented return value [bp_sw_FileSource *] + * + */ +bp_sw_FileSource * bp_sw_free_FileSource( bp_sw_FileSource * obj); + + + +/* Helper functions in the module + * + * bp_sw_Align_strings_ProteinSmithWaterman + * bp_sw_Align_Sequences_ProteinSmithWaterman + * bp_sw_Align_Proteins_SmithWaterman + * + + + +/* These functions are not associated with an object */ +/* Function: bp_sw_Align_strings_ProteinSmithWaterman(one,two,comp,gap,ext) + * + * Descrip: This is the most *stupidly* abstracted view of two sequences + * getting aligned, being two strings. + * + * It would be much better if you used Sequence objects or Protein + * objects to carry the proteins. + * + * + * Arg: one string of the first sequence [char *] + * Arg: two string of the second sequence [char *] + * Arg: comp Comparison Matrix [bp_sw_CompMat *] + * Arg: gap gap penalty [int] + * Arg: ext extension penalty [int] + * + * Returns Undocumented return value [bp_sw_AlnBlock *] + * + */ +bp_sw_AlnBlock * bp_sw_Align_strings_ProteinSmithWaterman( char * one,char * two,bp_sw_CompMat * comp,int gap,int ext); + +/* Function: bp_sw_Align_Sequences_ProteinSmithWaterman(one,two,comp,gap,ext) + * + * Descrip: This function is a mid-level abstraction of + * comparing two sequences, which could be + * generic types (eg DNA!). This is tested + * for and warnings are given but the alignment + * is still calculated. To prevent this test + * warning either make sure the Sequence types + * are set to PROTEIN or, better still, use the + * high level abstraction Align_Proteins_SmithWaterman + * + * Otherwise this performs a standard smith waterman + * protein alignment... + * + * To display the alignment use write_pretty_seq_align + * + * + * Arg: one First sequence to compare [bp_sw_Sequence *] + * Arg: two Second sequecne to compare [bp_sw_Sequence *] + * Arg: comp Comparison matrix to use [bp_sw_CompMat *] + * Arg: gap gap penalty. Must be negative or 0 [int] + * Arg: ext ext penalty. Must be negative or 0 [int] + * + * Returns new AlnBlock structure representing the alignment [bp_sw_AlnBlock *] + * + */ +bp_sw_AlnBlock * bp_sw_Align_Sequences_ProteinSmithWaterman( bp_sw_Sequence * one,bp_sw_Sequence * two,bp_sw_CompMat * comp,int gap,int ext); + +/* Function: bp_sw_Align_Proteins_SmithWaterman(one,two,comp,gap,ext) + * + * Descrip: This is the most correct way of aligning two Proteins, + * using Protein objects, which can be assummed to be + * proteins with no objections + * + * To display the alignment use write_pretty_Protein_align + * + * + * + * Arg: one Protein to align [bp_sw_Protein *] + * Arg: two Protein to align [bp_sw_Protein *] + * Arg: comp Comparison Matrix [bp_sw_CompMat *] + * Arg: gap gap penalty [int] + * Arg: ext extension penalty [int] + * + * Returns Undocumented return value [bp_sw_AlnBlock *] + * + */ +bp_sw_AlnBlock * bp_sw_Align_Proteins_SmithWaterman( bp_sw_Protein * one,bp_sw_Protein * two,bp_sw_CompMat * comp,int gap,int ext); + + + +/* Functions that create, manipulate or act on Exon + * + * bp_sw_hard_link_Exon + * bp_sw_Exon_alloc + * bp_sw_replace_start_Exon + * bp_sw_access_start_Exon + * bp_sw_replace_end_Exon + * bp_sw_access_end_Exon + * bp_sw_replace_used_Exon + * bp_sw_access_used_Exon + * bp_sw_replace_score_Exon + * bp_sw_access_score_Exon + * bp_sw_free_Exon [destructor] + * + */ + + + +/* Functions that create, manipulate or act on Transcript + * + * bp_sw_get_cDNA_from_Transcript + * bp_sw_hard_link_Transcript + * bp_sw_Transcript_alloc_std + * bp_sw_access_exon_Transcript + * bp_sw_length_exon_Transcript + * bp_sw_flush_ex_Transcript + * bp_sw_add_ex_Transcript + * bp_sw_replace_parent_Transcript + * bp_sw_access_parent_Transcript + * bp_sw_access_translation_Transcript + * bp_sw_length_translation_Transcript + * bp_sw_flush_Transcript + * bp_sw_add_Transcript + * bp_sw_replace_cDNA_Transcript + * bp_sw_access_cDNA_Transcript + * bp_sw_free_Transcript [destructor] + * + */ + +/* API for object Exon */ +/* Function: bp_sw_hard_link_Exon(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_Exon *] + * + * Returns Undocumented return value [bp_sw_Exon *] + * + */ +bp_sw_Exon * bp_sw_hard_link_Exon( bp_sw_Exon * obj); + +/* Function: bp_sw_Exon_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_Exon *] + * + */ +bp_sw_Exon * bp_sw_Exon_alloc(); + +/* Function: bp_sw_replace_start_Exon(obj,start) + * + * Descrip: Replace member variable start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Exon *] + * Arg: start New value of the variable [int] + * + * Returns member variable start [boolean] + * + */ +boolean bp_sw_replace_start_Exon( bp_sw_Exon * obj,int start); + +/* Function: bp_sw_access_start_Exon(obj) + * + * Descrip: Access member variable start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Exon *] + * + * Returns member variable start [int] + * + */ +int bp_sw_access_start_Exon( bp_sw_Exon * obj); + +/* Function: bp_sw_replace_end_Exon(obj,end) + * + * Descrip: Replace member variable end + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Exon *] + * Arg: end New value of the variable [int] + * + * Returns member variable end [boolean] + * + */ +boolean bp_sw_replace_end_Exon( bp_sw_Exon * obj,int end); + +/* Function: bp_sw_access_end_Exon(obj) + * + * Descrip: Access member variable end + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Exon *] + * + * Returns member variable end [int] + * + */ +int bp_sw_access_end_Exon( bp_sw_Exon * obj); + +/* Function: bp_sw_replace_used_Exon(obj,used) + * + * Descrip: Replace member variable used + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Exon *] + * Arg: used New value of the variable [boolean] + * + * Returns member variable used [boolean] + * + */ +boolean bp_sw_replace_used_Exon( bp_sw_Exon * obj,boolean used); + +/* Function: bp_sw_access_used_Exon(obj) + * + * Descrip: Access member variable used + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Exon *] + * + * Returns member variable used [boolean] + * + */ +boolean bp_sw_access_used_Exon( bp_sw_Exon * obj); + +/* Function: bp_sw_replace_score_Exon(obj,score) + * + * Descrip: Replace member variable score + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Exon *] + * Arg: score New value of the variable [double] + * + * Returns member variable score [boolean] + * + */ +boolean bp_sw_replace_score_Exon( bp_sw_Exon * obj,double score); + +/* Function: bp_sw_access_score_Exon(obj) + * + * Descrip: Access member variable score + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Exon *] + * + * Returns member variable score [double] + * + */ +double bp_sw_access_score_Exon( bp_sw_Exon * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_Exon(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_Exon *] + * + * Returns Undocumented return value [bp_sw_Exon *] + * + */ +bp_sw_Exon * bp_sw_free_Exon( bp_sw_Exon * obj); + +/* API for object Transcript */ +/* Function: bp_sw_get_cDNA_from_Transcript(trs) + * + * Descrip: gets the cDNA associated with this transcript, + * if necessary, building it from the exon information + * provided. + * + * returns a soft-linked object. If you want to ensure + * that this cDNA object remains in memory use + * /hard_link_cDNA on the object. + * + * + * Arg: trs transcript to get cDNA from [bp_sw_Transcript *] + * + * Returns cDNA of the transcript [bp_sw_cDNA *] + * + */ +bp_sw_cDNA * bp_sw_get_cDNA_from_Transcript( bp_sw_Transcript * trs); + +/* Function: bp_sw_hard_link_Transcript(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_Transcript *] + * + * Returns Undocumented return value [bp_sw_Transcript *] + * + */ +bp_sw_Transcript * bp_sw_hard_link_Transcript( bp_sw_Transcript * obj); + +/* Function: bp_sw_Transcript_alloc_std(void) + * + * Descrip: Equivalent to Transcript_alloc_len(TranscriptLISTLENGTH) + * + * + * + * Returns Undocumented return value [bp_sw_Transcript *] + * + */ +bp_sw_Transcript * bp_sw_Transcript_alloc_std(); + +/* Function: bp_sw_access_exon_Transcript(obj,i) + * + * Descrip: Access members stored in the exon list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_Transcript *] + * Arg: i Position in the list [int] + * + * Returns Element of the list [bp_sw_Exon *] + * + */ +bp_sw_Exon * bp_sw_access_exon_Transcript( bp_sw_Transcript * obj,int i); + +/* Function: bp_sw_length_exon_Transcript(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_Transcript *] + * + * Returns length of the list [int] + * + */ +int bp_sw_length_exon_Transcript( bp_sw_Transcript * obj); + +/* Function: bp_sw_flush_ex_Transcript(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj Object which contains the list [bp_sw_Transcript *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_flush_ex_Transcript( bp_sw_Transcript * obj); + +/* Function: bp_sw_add_ex_Transcript(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj Object which contains the list [bp_sw_Transcript *] + * Arg: add Object to add to the list [bp_sw_Exon *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_add_ex_Transcript( bp_sw_Transcript * obj,bp_sw_Exon * add); + +/* Function: bp_sw_replace_parent_Transcript(obj,parent) + * + * Descrip: Replace member variable parent + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Transcript *] + * Arg: parent New value of the variable [bp_sw_Gene *] + * + * Returns member variable parent [boolean] + * + */ +boolean bp_sw_replace_parent_Transcript( bp_sw_Transcript * obj,bp_sw_Gene * parent); + +/* Function: bp_sw_access_parent_Transcript(obj) + * + * Descrip: Access member variable parent + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Transcript *] + * + * Returns member variable parent [bp_sw_Gene *] + * + */ +bp_sw_Gene * bp_sw_access_parent_Transcript( bp_sw_Transcript * obj); + +/* Function: bp_sw_access_translation_Transcript(obj,i) + * + * Descrip: Access members stored in the translation list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_Transcript *] + * Arg: i Position in the list [int] + * + * Returns Element of the list [bp_sw_Translation *] + * + */ +bp_sw_Translation * bp_sw_access_translation_Transcript( bp_sw_Transcript * obj,int i); + +/* Function: bp_sw_length_translation_Transcript(obj) + * + * Descrip: discover the length of the list + * For use principly by API functions + * + * + * Arg: obj Object holding the list [bp_sw_Transcript *] + * + * Returns length of the list [int] + * + */ +int bp_sw_length_translation_Transcript( bp_sw_Transcript * obj); + +/* Function: bp_sw_flush_Transcript(obj) + * + * Descrip: Frees the list elements, sets length to 0 + * If you want to save some elements, use hard_link_xxx + * to protect them from being actually destroyed in the free + * + * + * Arg: obj Object which contains the list [bp_sw_Transcript *] + * + * Returns Undocumented return value [int] + * + */ +int bp_sw_flush_Transcript( bp_sw_Transcript * obj); + +/* Function: bp_sw_add_Transcript(obj,add) + * + * Descrip: Adds another object to the list. It will expand the list if necessary + * + * + * Arg: obj Object which contains the list [bp_sw_Transcript *] + * Arg: add Object to add to the list [bp_sw_Translation *] + * + * Returns Undocumented return value [boolean] + * + */ +boolean bp_sw_add_Transcript( bp_sw_Transcript * obj,bp_sw_Translation * add); + +/* Function: bp_sw_replace_cDNA_Transcript(obj,cDNA) + * + * Descrip: Replace member variable cDNA + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Transcript *] + * Arg: cDNA New value of the variable [bp_sw_cDNA *] + * + * Returns member variable cDNA [boolean] + * + */ +boolean bp_sw_replace_cDNA_Transcript( bp_sw_Transcript * obj,bp_sw_cDNA * cDNA); + +/* Function: bp_sw_access_cDNA_Transcript(obj) + * + * Descrip: Access member variable cDNA + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Transcript *] + * + * Returns member variable cDNA [bp_sw_cDNA *] + * + */ +bp_sw_cDNA * bp_sw_access_cDNA_Transcript( bp_sw_Transcript * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_Transcript(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_Transcript *] + * + * Returns Undocumented return value [bp_sw_Transcript *] + * + */ +bp_sw_Transcript * bp_sw_free_Transcript( bp_sw_Transcript * obj); + + + +/* Functions that create, manipulate or act on Translation + * + * bp_sw_get_Protein_from_Translation + * bp_sw_hard_link_Translation + * bp_sw_Translation_alloc + * bp_sw_replace_start_Translation + * bp_sw_access_start_Translation + * bp_sw_replace_end_Translation + * bp_sw_access_end_Translation + * bp_sw_replace_parent_Translation + * bp_sw_access_parent_Translation + * bp_sw_replace_protein_Translation + * bp_sw_access_protein_Translation + * bp_sw_free_Translation [destructor] + * + */ + +/* API for object Translation */ +/* Function: bp_sw_get_Protein_from_Translation(ts,ct) + * + * Descrip: Gets the protein + * + * + * Arg: ts translation [bp_sw_Translation *] + * Arg: ct codon table to use [bp_sw_CodonTable *] + * + * Returns Protein sequence [bp_sw_Protein *] + * + */ +bp_sw_Protein * bp_sw_get_Protein_from_Translation( bp_sw_Translation * ts,bp_sw_CodonTable * ct); + +/* Function: bp_sw_hard_link_Translation(obj) + * + * Descrip: Bumps up the reference count of the object + * Meaning that multiple pointers can 'own' it + * + * + * Arg: obj Object to be hard linked [bp_sw_Translation *] + * + * Returns Undocumented return value [bp_sw_Translation *] + * + */ +bp_sw_Translation * bp_sw_hard_link_Translation( bp_sw_Translation * obj); + +/* Function: bp_sw_Translation_alloc(void) + * + * Descrip: Allocates structure: assigns defaults if given + * + * + * + * Returns Undocumented return value [bp_sw_Translation *] + * + */ +bp_sw_Translation * bp_sw_Translation_alloc(); + +/* Function: bp_sw_replace_start_Translation(obj,start) + * + * Descrip: Replace member variable start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Translation *] + * Arg: start New value of the variable [int] + * + * Returns member variable start [boolean] + * + */ +boolean bp_sw_replace_start_Translation( bp_sw_Translation * obj,int start); + +/* Function: bp_sw_access_start_Translation(obj) + * + * Descrip: Access member variable start + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Translation *] + * + * Returns member variable start [int] + * + */ +int bp_sw_access_start_Translation( bp_sw_Translation * obj); + +/* Function: bp_sw_replace_end_Translation(obj,end) + * + * Descrip: Replace member variable end + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Translation *] + * Arg: end New value of the variable [int] + * + * Returns member variable end [boolean] + * + */ +boolean bp_sw_replace_end_Translation( bp_sw_Translation * obj,int end); + +/* Function: bp_sw_access_end_Translation(obj) + * + * Descrip: Access member variable end + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Translation *] + * + * Returns member variable end [int] + * + */ +int bp_sw_access_end_Translation( bp_sw_Translation * obj); + +/* Function: bp_sw_replace_parent_Translation(obj,parent) + * + * Descrip: Replace member variable parent + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Translation *] + * Arg: parent New value of the variable [bp_sw_Transcript *] + * + * Returns member variable parent [boolean] + * + */ +boolean bp_sw_replace_parent_Translation( bp_sw_Translation * obj,bp_sw_Transcript * parent); + +/* Function: bp_sw_access_parent_Translation(obj) + * + * Descrip: Access member variable parent + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Translation *] + * + * Returns member variable parent [bp_sw_Transcript *] + * + */ +bp_sw_Transcript * bp_sw_access_parent_Translation( bp_sw_Translation * obj); + +/* Function: bp_sw_replace_protein_Translation(obj,protein) + * + * Descrip: Replace member variable protein + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Translation *] + * Arg: protein New value of the variable [bp_sw_Protein *] + * + * Returns member variable protein [boolean] + * + */ +boolean bp_sw_replace_protein_Translation( bp_sw_Translation * obj,bp_sw_Protein * protein); + +/* Function: bp_sw_access_protein_Translation(obj) + * + * Descrip: Access member variable protein + * For use principly by API functions + * + * + * Arg: obj Object holding the variable [bp_sw_Translation *] + * + * Returns member variable protein [bp_sw_Protein *] + * + */ +bp_sw_Protein * bp_sw_access_protein_Translation( bp_sw_Translation * obj); + +/* This is the destructor function, ie, call this to free object*/ +/* Function: bp_sw_free_Translation(obj) + * + * Descrip: Free Function: removes the memory held by obj + * Will chain up to owned members and clear all lists + * + * + * Arg: obj Object that is free'd [bp_sw_Translation *] + * + * Returns Undocumented return value [bp_sw_Translation *] + * + */ +bp_sw_Translation * bp_sw_free_Translation( bp_sw_Translation * obj); + diff --git a/Bio/Ext/Align/libs/sw_wrap.c b/Bio/Ext/Align/libs/sw_wrap.c new file mode 100644 index 0000000..13c21b4 --- /dev/null +++ b/Bio/Ext/Align/libs/sw_wrap.c @@ -0,0 +1,183 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "sw_wrap.h" + +/* Function: Align_strings_ProteinSmithWaterman(one,two,comp,gap,ext) + * + * Descrip: This is the most *stupidly* abstracted view of two sequences + * getting aligned, being two strings. + * + * It would be much better if you used Sequence objects or Protein + * objects to carry the proteins. + * + * + * Arg: one [UNKN ] string of the first sequence [char *] + * Arg: two [UNKN ] string of the second sequence [char *] + * Arg: comp [UNKN ] Comparison Matrix [CompMat *] + * Arg: gap [UNKN ] gap penalty [int] + * Arg: ext [UNKN ] extension penalty [int] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +# line 31 "sw_wrap.dy" +AlnBlock * Align_strings_ProteinSmithWaterman(char * one,char * two,CompMat * comp,int gap,int ext) +{ + Sequence * one_s; + Sequence * two_s; + AlnBlock * out; + + /* error check the strings? */ + + one_s = new_Sequence_from_strings(NULL,one); + if( one_s == NULL ) { + warn("Cannot make new sequence...\n"); + return NULL; + } + + two_s = new_Sequence_from_strings(NULL,two); + if( two_s == NULL ) { + warn("Cannot make new sequence...\n"); + return NULL; + } + + out = Align_Sequences_ProteinSmithWaterman(one_s,two_s,comp,gap,ext); + + free_Sequence(one_s); + free_Sequence(two_s); + + return out; +} + + +/* Function: Align_Sequences_ProteinSmithWaterman(one,two,comp,gap,ext) + * + * Descrip: This function is a mid-level abstraction of + * comparing two sequences, which could be + * generic types (eg DNA!). This is tested + * for and warnings are given but the alignment + * is still calculated. To prevent this test + * warning either make sure the Sequence types + * are set to PROTEIN or, better still, use the + * high level abstraction Align_Proteins_SmithWaterman + * + * Otherwise this performs a standard smith waterman + * protein alignment... + * + * To display the alignment use write_pretty_seq_align + * + * + * Arg: one [READ ] First sequence to compare [Sequence *] + * Arg: two [READ ] Second sequecne to compare [Sequence *] + * Arg: comp [READ ] Comparison matrix to use [CompMat *] + * Arg: gap [UNKN ] gap penalty. Must be negative or 0 [int] + * Arg: ext [UNKN ] ext penalty. Must be negative or 0 [int] + * + * Return [OWNER] new AlnBlock structure representing the alignment [AlnBlock *] + * + */ +# line 82 "sw_wrap.dy" +AlnBlock * Align_Sequences_ProteinSmithWaterman(Sequence * one,Sequence * two,CompMat * comp,int gap,int ext) +{ + AlnBlock * out = NULL; + ComplexSequenceEvalSet * evalfunc = NULL; + ComplexSequence * query_cs = NULL; + ComplexSequence * target_cs = NULL; + PackAln * pal = NULL; + + if( one == NULL || two == NULL || comp == NULL ) { + warn("Passed in NULL objects into Align_Sequences_ProteinSmithWaterman!"); + return NULL; + } + + if( one->type != SEQUENCE_PROTEIN ) { + warn("Sequence %s is not typed as protein... ignoring!\n",one->name); + } + + if( two->type != SEQUENCE_PROTEIN ) { + warn("Sequence %s is not typed as protein... ignoring!\n",two->name); + } + + + if( gap > 0 || ext > 0 ) { + warn("Gap penalties %d,%d only make sense if they are negative",gap,ext); + return NULL; + } + + evalfunc = default_aminoacid_ComplexSequenceEvalSet(); + + query_cs = new_ComplexSequence(one,evalfunc); + if( query_cs == NULL ) + goto cleanup; + target_cs = new_ComplexSequence(two,evalfunc); + if( target_cs == NULL ) + goto cleanup; + + pal = PackAln_bestmemory_ProteinSW(query_cs,target_cs,comp,gap,ext,NULL); + if( pal == NULL ) + goto cleanup; + + out = convert_PackAln_to_AlnBlock_ProteinSW(pal); + + goto cleanup; + + cleanup : + + if( query_cs != NULL ) + free_ComplexSequence(query_cs); + + if( target_cs != NULL ) + free_ComplexSequence(target_cs); + + if( pal != NULL ) + free_PackAln(pal); + + if( evalfunc != NULL ) + free_ComplexSequenceEvalSet(evalfunc); + + return out; + +} + + +/* Function: Align_Proteins_SmithWaterman(one,two,comp,gap,ext) + * + * Descrip: This is the most correct way of aligning two Proteins, + * using Protein objects, which can be assummed to be + * proteins with no objections + * + * To display the alignment use write_pretty_Protein_align + * + * + * + * Arg: one [UNKN ] Protein to align [Protein *] + * Arg: two [UNKN ] Protein to align [Protein *] + * Arg: comp [UNKN ] Comparison Matrix [CompMat *] + * Arg: gap [UNKN ] gap penalty [int] + * Arg: ext [UNKN ] extension penalty [int] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +# line 159 "sw_wrap.dy" +AlnBlock * Align_Proteins_SmithWaterman(Protein * one,Protein * two,CompMat * comp,int gap,int ext) +{ + if( one == NULL || two == NULL || comp == NULL ) { + warn("Passed in NULL objects into Align_Proteins_SmithWaterman!"); + return NULL; + } + + + return Align_Sequences_ProteinSmithWaterman(one->baseseq,two->baseseq,comp,gap,ext); +} + + + + + +# line 172 "sw_wrap.c" + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/sw_wrap.h b/Bio/Ext/Align/libs/sw_wrap.h new file mode 100644 index 0000000..b56b75d --- /dev/null +++ b/Bio/Ext/Align/libs/sw_wrap.h @@ -0,0 +1,106 @@ +#ifndef DYNAMITEsw_wrapHEADERFILE +#define DYNAMITEsw_wrapHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "proteinsw.h" + + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: Align_strings_ProteinSmithWaterman(one,two,comp,gap,ext) + * + * Descrip: This is the most *stupidly* abstracted view of two sequences + * getting aligned, being two strings. + * + * It would be much better if you used Sequence objects or Protein + * objects to carry the proteins. + * + * + * Arg: one [UNKN ] string of the first sequence [char *] + * Arg: two [UNKN ] string of the second sequence [char *] + * Arg: comp [UNKN ] Comparison Matrix [CompMat *] + * Arg: gap [UNKN ] gap penalty [int] + * Arg: ext [UNKN ] extension penalty [int] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * bp_sw_Align_strings_ProteinSmithWaterman(char * one,char * two,CompMat * comp,int gap,int ext); +#define Align_strings_ProteinSmithWaterman bp_sw_Align_strings_ProteinSmithWaterman + + +/* Function: Align_Sequences_ProteinSmithWaterman(one,two,comp,gap,ext) + * + * Descrip: This function is a mid-level abstraction of + * comparing two sequences, which could be + * generic types (eg DNA!). This is tested + * for and warnings are given but the alignment + * is still calculated. To prevent this test + * warning either make sure the Sequence types + * are set to PROTEIN or, better still, use the + * high level abstraction Align_Proteins_SmithWaterman + * + * Otherwise this performs a standard smith waterman + * protein alignment... + * + * To display the alignment use write_pretty_seq_align + * + * + * Arg: one [READ ] First sequence to compare [Sequence *] + * Arg: two [READ ] Second sequecne to compare [Sequence *] + * Arg: comp [READ ] Comparison matrix to use [CompMat *] + * Arg: gap [UNKN ] gap penalty. Must be negative or 0 [int] + * Arg: ext [UNKN ] ext penalty. Must be negative or 0 [int] + * + * Return [OWNER] new AlnBlock structure representing the alignment [AlnBlock *] + * + */ +AlnBlock * bp_sw_Align_Sequences_ProteinSmithWaterman(Sequence * one,Sequence * two,CompMat * comp,int gap,int ext); +#define Align_Sequences_ProteinSmithWaterman bp_sw_Align_Sequences_ProteinSmithWaterman + + +/* Function: Align_Proteins_SmithWaterman(one,two,comp,gap,ext) + * + * Descrip: This is the most correct way of aligning two Proteins, + * using Protein objects, which can be assummed to be + * proteins with no objections + * + * To display the alignment use write_pretty_Protein_align + * + * + * + * Arg: one [UNKN ] Protein to align [Protein *] + * Arg: two [UNKN ] Protein to align [Protein *] + * Arg: comp [UNKN ] Comparison Matrix [CompMat *] + * Arg: gap [UNKN ] gap penalty [int] + * Arg: ext [UNKN ] extension penalty [int] + * + * Return [UNKN ] Undocumented return value [AlnBlock *] + * + */ +AlnBlock * bp_sw_Align_Proteins_SmithWaterman(Protein * one,Protein * two,CompMat * comp,int gap,int ext); +#define Align_Proteins_SmithWaterman bp_sw_Align_Proteins_SmithWaterman + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/wisebase.h b/Bio/Ext/Align/libs/wisebase.h new file mode 100644 index 0000000..5592267 --- /dev/null +++ b/Bio/Ext/Align/libs/wisebase.h @@ -0,0 +1,52 @@ + +#ifndef TOPBASEHEADER +#define TOPBASEHEADER + + +#include +#include +#include +#include +#include +#include +#include +#include + + +#ifdef SUNS +#include +#ifndef UNIX +#define UNIX /* if users put -DSUN but not -DUNIX */ +#endif +#endif /* ifdef SUN */ + + +/**** OK some system wide defines now - used all over the place ****/ + +#define MAXLINE 512 /* generalised maximum input line */ +#define MAXBINARYDUMP 1024 /*** ok could be tricky here... ****/ + +#ifndef BOOLEANDEFINED + +typedef int boolean; +#define TRUE 1 +#define FALSE 0 + +#define BOOLEANDEFINED +#endif + + +/**** include the rest of the base files ****/ + +#include "wisestring.h" +#include "wisefile.h" +#include "wiseconfig.h" +#include "wisetime.h" +#include "wiserandom.h" +#include "wisememman.h" /* memory manager - ckalloc/ckfree etc */ +#include "wiseerror.h" +#include "wiseoverlay.h" +#include "commandline.h" + + +#endif /* TOP_BASE.H loaded */ diff --git a/Bio/Ext/Align/libs/wiseconfig.c b/Bio/Ext/Align/libs/wiseconfig.c new file mode 100755 index 0000000..6a7c3fa --- /dev/null +++ b/Bio/Ext/Align/libs/wiseconfig.c @@ -0,0 +1,272 @@ +/************************************************************************/ +/* WiseTools, Release 1.0. This software is copyright */ +/* Ewan Birney (c), 1995. */ +/* Anyone can distribute/compile and use this software */ +/* free of charge as long as this notice remains intact */ +/* */ +/* Any alterations should be cleared by Ewan Birney. */ +/* Email birney@molbiol.ox.ac.uk */ +/* URL http://www.molbiol.ox.ac.uk/www/users/birney/wise/topwise.html */ +/* */ +/* This software is provided as is, and the author does not accept any */ +/* liability for its use or performance :) */ +/************************************************************************/ + +#include "wisebase.h" + +#define MAXFIG 512 +#define MAXLINE 512 + +typedef struct { + char * keyword; + char * string; + char * filename; /* this is not alloc'd */ + } config; + +static config list[MAXFIG]; +static int maxnum=0; + +static char * filenamelist[64]; +static int noffiles=0; + +char * get_usermailname(void) +{ + char * out; + + out = config_single_from_key("usermailname"); + + if( out != NULL) return out; + + out = getenv("user"); + + if( out != NULL ) + return stringalloc(out); + + out = getenv("USER"); + + if( out != NULL) + return stringalloc(out); + + return NULL; +} + + + +boolean is_config_system(void) +{ + return (noffiles == 0 ? FALSE : TRUE); +} + +char ** filename_list(int * retval) +{ + *retval=noffiles; + return filenamelist; +} + + +boolean read_set_config(void) +{ + char * runner; + + + if( (runner=getenv("WISESYSTEMFILE")) != NULL) + read_config_file(runner); + else read_config_file("wise.cfg"); + + if( (runner=getenv("WISEPERSONALFILE")) != NULL) + read_config_file(runner); + + if( is_config_system() == FALSE) + { + log_full_error(WARNING,0,"Unable to find config files, " + "going to try a variety of other filenames. Default has changed " + "to wise.cfg for all systems"); + read_config_file("wise.cfg"); + read_config_file(".wisecfg"); + if( is_config_system() == FALSE) + log_full_error(WARNING,0,"Unable to find any config files " + "will bug out now"); + return TRUE; + } + return TRUE; +} + +int index_from_keyword(char * key) +{ + register int i; + + if(noffiles == 0) + { + log_full_error(PEDANTIC,0,"Tried to pull keyword in config " +"but no file has been read"); + return -1; + } + + for(i=0;i + +boolean read_set_config(void); + +char ** filename_list(int * retval); + +int config_is_key(char * key); + /* if keyword is present in list then return 1 else return 0 */ + +char * config_string_from_key(char * key); + /* if keyword is present then return string: if no keyword */ + /* will return NULL: however, string could be NULL: a NULL */ + /* return could mean either no keyword or NULL string */ + /* associated with keyword. Test with config_is_key */ + +char * config_single_from_key(char * key); + /* if keyword is present, returns the a string whith the first word */ + /* all packed up: string has been alloced... so free it if you like*/ + +int config_number_from_key(char * key,int * pass); + /* will put the value of the first word associated with key */ + /* into *pass using atoi: will return 0 if success, and */ + /* 1 if not */ + +int read_config_file(char * filename); + /* reads in a config file */ + +/* internal functions: don't call 'em !!! */ + +char * read_config_string(char * base,char * string,FILE * ifp); +int index_from_keyword(char * key); + +#endif /* of EWANCONFIG */ + diff --git a/Bio/Ext/Align/libs/wiseerror.c b/Bio/Ext/Align/libs/wiseerror.c new file mode 100644 index 0000000..f341c47 --- /dev/null +++ b/Bio/Ext/Align/libs/wiseerror.c @@ -0,0 +1,580 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "wiseerror.h" + +static Flag fatal_flag = 3; +static Flag warning_flag = 3; +static Flag info_flag = 3; +static Flag report_flag = 3; + +#define flag_of_type(c) (c == FATAL ? fatal_flag : c == WARNING ? warning_flag :c == INFO ? info_flag : report_flag ) + + +static int eventc=0; +static FILE * errlog=NULL; + +static void (*error_call)(char *,int)= NULL; + +static char * error_msg_stack[MAXMSGSTACKERROR]; + +static char * (*((error_msg_call)[MAXMSGSTACKERROR]))(void); +static int msg_stack_no=0; + +/* Function: push_errormsg_stack(msg,) + * + * Descrip: This adds a function onto the error message + * stack for stacking errors. this is for + * decent parsers etc for allowing 'error scope' + * to be propagated down. + * + * It is very very bad form to push an errormsg + * stack and not pop it at the end. + * + * + * Arg: msg [UNKN ] Undocumented argument [char *] + * Arg: [UNKN ] Undocumented argument [.] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 84 "wiseerror.dy" +boolean push_errormsg_stack(char * msg, ...) +{ + char buffer[1024]; + va_list ap; + + + + va_start(ap,msg); + vsprintf(buffer,msg,ap); + + if( msg_stack_no >= MAXMSGSTACKERROR ) { + warn("Too many messages held on stack, [%s] discarded\n",buffer); + /*** still should up the number ***/ + msg_stack_no++; + return FALSE; + } + error_msg_call[msg_stack_no] = NULL; + error_msg_stack[msg_stack_no++] = stringalloc(buffer); + return TRUE; +} + + + +/* Function: push_errormsg_stack_call(ecall) + * + * Descrip: This adds a function call for people who want + * to register error handling functions + * + * Probably best wrapped by a separate function + * + * + * Arg: ecall [UNKN ] Undocumented argument [NullString] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 113 "wiseerror.dy" +boolean push_errormsg_stack_call( char * (*ecall)(void)) +{ + + if( msg_stack_no >= MAXMSGSTACKERROR ) { + warn("Too many messages held on stack, Error message call discarded\n"); + /*** still should up the number ***/ + msg_stack_no++; + return FALSE; + } + error_msg_call[msg_stack_no] = ecall; + error_msg_stack[msg_stack_no++] = NULL; + return TRUE; +} + +/* Function: pop_errormsg_stack(void) + * + * Descrip: This removes a error message from the stack + * + * + * + */ +# line 130 "wiseerror.dy" +void pop_errormsg_stack(void) +{ + if( msg_stack_no < MAXMSGSTACKERROR && msg_stack_no > 0 && error_msg_stack[msg_stack_no-1] != NULL) + ckfree(error_msg_stack[msg_stack_no-1]); + if( msg_stack_no > 0) + msg_stack_no--; +} + +/* Function: show_message_stack(ofp) + * + * Descrip: This shows the error message set to + * everyone + * + * + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 143 "wiseerror.dy" +void show_message_stack(FILE * ofp) +{ + register int i; + register int j; + register int count; + + for(i=0;i 0 ) + show_message_stack(stderr); + fputs("\t",stderr); + if( type == FATAL ) + fputs(othermsg,stderr); + else show_text(othermsg,70,stderr); + } + + if( flag&ERRORTOLOG && errlog != NULL) { + fputs(type_to_error(type),errlog); + fputc('\n',stderr); + if( msg_stack_no > 0 ) + show_message_stack(errlog); + fputs("\n\t",errlog); + show_text(othermsg,70,errlog); + } + + if( flag&ERRORTOCALL && error_call != NULL) + { + (*(error_call))(othermsg,type); + } + + + + return; +} + + +# line 531 "wiseerror.c" + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/wiseerror.h b/Bio/Ext/Align/libs/wiseerror.h new file mode 100644 index 0000000..d187d09 --- /dev/null +++ b/Bio/Ext/Align/libs/wiseerror.h @@ -0,0 +1,323 @@ +#ifndef DYNAMITEwiseerrorHEADERFILE +#define DYNAMITEwiseerrorHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif + +#include "wisebase.h" + + + +typedef int Flag; + +#define MAXERROR 256 +#define MAXERRORCALL 32 +#define MAXMSGSTACKERROR 64 + +/* flags on errors */ +#define ERRORUSE 1 +#define ERRORTOSTDERR 2 +#define ERRORTOLOG 4 +#define ERRORTOCALL 8 +#define LONGERROR 16 /* not used */ + + +/* types of error */ +#define FATAL 1 +#define WARNING 2 +#define PEDANTIC 4 /* deprecated */ +#define INFO 8 +#define REPORT 16 + +#define erroroff(type) error_flag_off(type,ERRORUSE) +#define erroron(type) error_flag_on (type,ERRORUSE) +#define errorcallon(type) error_flag_on (type,ERRORTOCALL) +#define errorcalloff(type) error_flag_off(type,ERRORTOCALL) +#define errorstderron(type) error_flag_on (type,ERRORTOSTDERR) +#define errorstderroff(type) error_flag_off(type,ERRORTOSTDERR) +#define errorlogon(type) error_flag_on (type,ERRORTOLOG) +#define errorlogoff(type) error_flag_off(type,ERRORTOLOG) + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: push_errormsg_stack_call(ecall) + * + * Descrip: This adds a function call for people who want + * to register error handling functions + * + * Probably best wrapped by a separate function + * + * + * Arg: ecall [UNKN ] Undocumented argument [NullString] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_push_errormsg_stack_call( char * (*ecall)(void)); +#define push_errormsg_stack_call bp_sw_push_errormsg_stack_call + + +/* Function: pop_errormsg_stack(void) + * + * Descrip: This removes a error message from the stack + * + * + * + */ +void bp_sw_pop_errormsg_stack(void); +#define pop_errormsg_stack bp_sw_pop_errormsg_stack + + +/* Function: add_log_filename(filename) + * + * Descrip: Opens filename as the log file. + * + * + * Arg: filename [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_add_log_filename(char * filename); +#define add_log_filename bp_sw_add_log_filename + + +/* Function: error_off(type) + * + * Descrip: Really for the API. Wraps some + * of the error concepts.. + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * + */ +void bp_sw_error_off(int type); +#define error_off bp_sw_error_off + + +/* Function: error_on(type) + * + * Descrip: Really for the API. Wraps some + * of the error concepts.. + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * + */ +void bp_sw_error_on(int type); +#define error_on bp_sw_error_on + + +/* Function: error_flag_on(type,f) + * + * Descrip: Turns on the particular type of error flag + * (eg, STDERR etc). + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * Arg: f [UNKN ] Undocumented argument [Flag] + * + */ +void bp_sw_error_flag_on(int type,Flag f); +#define error_flag_on bp_sw_error_flag_on + + +/* Function: error_flag_off(type,f) + * + * Descrip: Turns off the particular type of error flag + * (eg, STDERR etc). + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * Arg: f [UNKN ] Undocumented argument [Flag] + * + */ +void bp_sw_error_flag_off(int type,Flag f); +#define error_flag_off bp_sw_error_flag_off + + +/* Function: catch_errors(catch) + * + * Descrip: This is a wrapper for the error handling + * system. It does the following things + * + * Sets function as the function to process errors + * + * Switches the INFO,ERROR and FATAL flags off on STDERR + * and on to ERROR CALL. + * + * + * + * Arg: catch [UNKN ] Undocumented argument [NullString] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_catch_errors(void (*catch)(char *,int)); +#define catch_errors bp_sw_catch_errors + + +/* Function: stop_catching_errors(void) + * + * Descrip: Switches off error catching, + * putting flags back on to STDERR + * + * + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_stop_catching_errors(void); +#define stop_catching_errors bp_sw_stop_catching_errors + + +/* Function: push_error_call() + * + * Descrip: Registers this function for dealing with errors + * + * Try to use catch_errors instead + * + * + * + * Arg: [UNKN ] Undocumented argument [NullString] + * + */ +void bp_sw_push_error_call(void (* func)(char *,int)); +#define push_error_call bp_sw_push_error_call + + +/* Function: pop_error_call(void) + * + * Descrip: Discards current function for dealing with errors + * + * + * + */ +void bp_sw_pop_error_call(void); +#define pop_error_call bp_sw_pop_error_call + + +/* Function: type_to_error(type) + * + * Descrip: Turns int error types to Names + * for display purposes. + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_type_to_error(int type); +#define type_to_error bp_sw_type_to_error + + +/* Function: info(msg,) + * + * Descrip: Produces a 'info' error message. + * + * + * Arg: msg [UNKN ] Undocumented argument [char *] + * Arg: [UNKN ] Undocumented argument [.] + * + */ +void bp_sw_info(char * msg, ...); +#define info bp_sw_info + + +/* Function: warn(msg,) + * + * Descrip: Produces a 'warn' error message. + * + * + * Arg: msg [UNKN ] Undocumented argument [char *] + * Arg: [UNKN ] Undocumented argument [.] + * + */ +void bp_sw_warn(char * msg, ...); +#define warn bp_sw_warn + + +/* Function: fatal(msg,) + * + * Descrip: Produces a 'fatal' error message. + * + * + * Arg: msg [UNKN ] Undocumented argument [char *] + * Arg: [UNKN ] Undocumented argument [.] + * + */ +void bp_sw_fatal(char * msg, ...); +#define fatal bp_sw_fatal + + +/* Function: log_full_error(type,location,msg,) + * + * Descrip: Deprecated + * + * produces any of the error types + * + * + * Arg: type [UNKN ] Undocumented argument [int] + * Arg: location [UNKN ] Undocumented argument [int] + * Arg: msg [UNKN ] Undocumented argument [char *] + * Arg: [UNKN ] Undocumented argument [.] + * + */ +void bp_sw_log_full_error(int type,int location,char * msg, ...); +#define log_full_error bp_sw_log_full_error + + +/* Function: start_reporting(msg,) + * + * Descrip: Starts a % reporting run. This is the header message + * + * + * Arg: msg [UNKN ] Undocumented argument [char *] + * Arg: [UNKN ] Undocumented argument [.] + * + */ +void bp_sw_start_reporting(char * msg,...); +#define start_reporting bp_sw_start_reporting + + +/* Function: stop_reporting(void) + * + * Descrip: Stops a % reporting run. + * + * + * + */ +void bp_sw_stop_reporting(void); +#define stop_reporting bp_sw_stop_reporting + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +boolean bp_sw_push_errormsg_stack(char * msg, ...); +#define push_errormsg_stack bp_sw_push_errormsg_stack +void bp_sw_show_message_stack(FILE * ofp); +#define show_message_stack bp_sw_show_message_stack +void bp_sw_add_log_file(FILE * ofp); +#define add_log_file bp_sw_add_log_file +void bp_sw_show_error(Flag flag,char * othermsg,int type); +#define show_error bp_sw_show_error + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/wisefile.c b/Bio/Ext/Align/libs/wisefile.c new file mode 100644 index 0000000..e657804 --- /dev/null +++ b/Bio/Ext/Align/libs/wisefile.c @@ -0,0 +1,364 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "wisefile.h" + + +#ifdef UNIX +static boolean isvms = FALSE; +#else +static boolean isvms= TRUE; +#endif + +static char * systemconfigdir=NULL; +static char * personaldir=NULL; +static char * homedir=NULL; +static boolean hasloaded=FALSE; + + +/* Function: set_config_dir(path,*path) + * + * Descrip: Programmatically set systemconfigdir to override + * any value set (or not) by env.var. WISECONFIGDIR. + * + * Added by arve. + * + * + * Arg: path [UNKN ] path that WISECONFIGDIR is set to [NullString] + * Arg: *path [UNKN ] Undocumented argument [char] + * + */ +# line 52 "wisefile.dy" +void set_config_dir(char *path) +{ + if (systemconfigdir != NULL ) { + ckfree(systemconfigdir); + } + systemconfigdir = stringalloc(path); +} + + +/* Function: myfclose(ofp) + * + * Descrip: reports the fclose type etc + * + * + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 64 "wisefile.dy" +int myfclose(FILE * ofp) +{ + fprintf(stderr,"Closing %d\n",ofp); +#undef fclose + fclose(ofp); + return 1; +} + + +/* Function: try_to_load(void) + * + * Descrip: Loads up 'standard' path places + * + * + * + */ +# line 77 "wisefile.dy" +void try_to_load(void) +{ + char * runner; + + + if( hasloaded == TRUE) + log_full_error(PEDANTIC,0,"Trying to reload configdirs"); + + + if( (runner=getenv("WISECONFIGDIR")) != NULL) { + systemconfigdir=stringalloc(runner); + } + + if( (runner=getenv("WISEPERSONALDIR")) != NULL) { + personaldir=stringalloc(runner); + } + + if( (runner=getenv("HOME")) != NULL) { + homedir=stringalloc(runner); + } + + hasloaded=TRUE; +} + +/* Function: remove_file(filename) + * + * Descrip: silly function to provide a boolean wrapper + * around remove. + * + * + * Arg: filename [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 105 "wisefile.dy" +boolean remove_file(char * filename) +{ + if( remove(filename) == 0) + return TRUE; + else return FALSE; +} + +/* Function: move_file(from,to) + * + * Descrip: silly function to provide a boolean wrapper + * around rename + * + * + * Arg: from [UNKN ] Undocumented argument [char *] + * Arg: to [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 116 "wisefile.dy" +boolean move_file(char * from,char * to) +{ + if( rename(from,to) == 0) + return TRUE; + else return FALSE; +} + +/* Function: append_file_to_path(buffer,len,file,path) + * + * Descrip: Appends file onto path in buffer + * + * + * Arg: buffer [UNKN ] Undocumented argument [char *] + * Arg: len [UNKN ] Undocumented argument [int] + * Arg: file [UNKN ] Undocumented argument [const char *] + * Arg: path [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 127 "wisefile.dy" +boolean append_file_to_path(char * buffer,int len,const char * file,char * path) +{ + char * runner; + + if( 1+strlen(file)+strlen(path) > len) { + warn("Unable to expand %s with %s due to lack of buffer space",path,file); + return FALSE; + } + + strcpy(buffer,path); + runner=buffer+strlen(buffer); + +#ifdef UNIX + if( *runner != '/') { + *(runner++)='/'; + *runner='\0'; + } +#endif + + strcat(buffer,file); + + return TRUE; +} + +/* Function: touchfile(filename) + * + * Descrip: sees if filename exists + * + * + * Arg: filename [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 154 "wisefile.dy" +boolean touchfile(char * filename) +{ + FILE * temp; + boolean retval; + + + if( filename == NULL ) { + warn("Tried to touch a NULL filename"); + return FALSE; + } + + if( (temp=openfile(filename,"r")) == NULL) { + retval=FALSE; + } + else { + fclose(temp); + retval=TRUE; + } + + + return retval; +} + +/* Function: openfile(filename,passedprot) + * + * Descrip: Every file open goes through this. + * + * It opens for reading in the following order + * . + * WISEPERSONALDIR + * WISECONFIGDIR + * + * For writing it opens in . + * + * Filenames with ~'s are expanded to HOME/filename + * + * + * Arg: filename [UNKN ] filename to open for read/writing [const char *] + * Arg: passedprot [UNKN ] string representing standard fopen attributes [const char *] + * + * Return [UNKN ] open'd filehandle, NULL on error [FILE *] + * + */ +# line 193 "wisefile.dy" +FILE * openfile(const char * filename,const char * passedprot) +{ + FILE * ifp; + char buffer[MAXPATHLEN]; + char prot[12]; /* protection string longer than 12 ! */ + boolean shouldreporterror=FALSE; + + strncpy(prot,passedprot,12); + + if( *prot == 'R' ) { + shouldreporterror=TRUE; + *prot = 'r'; + } + + if( *prot == 'W' ){ + shouldreporterror=TRUE; + *prot = 'w'; + } + + if( filename == NULL) { + if( shouldreporterror ) + info("Open for file failed due to NULL filename"); + return NULL; + } + + if( strcmp(filename,"-") == 0 ) { + if( *prot == 'r' ) + return stdin; + else return stdout; + } + + if( (ifp=fopen(filename,prot)) != NULL) { +#ifdef FILE_DEBUG + fprintf(stderr,"Succeeded in opening %s. Filehandle is %d\n",filename,ifp); +#endif + return ifp; + } + + if( shouldreporterror ) { + info("Direct open for [%s,%s] failed: Error message is %s",filename,prot, ERRORSTR); + } + + + if( hasloaded == FALSE) + try_to_load(); + + if( isvms != TRUE && homedir != NULL && filename[0]== '~' && filename[1] == '/') + if( append_file_to_path(buffer,MAXPATHLEN,filename+2,homedir) != FALSE ) + { + /*fprintf(stderr,"Trying to load %s\n",buffer);*/ + if( (ifp=fopen(buffer,prot)) != NULL) + return ifp; + else if( shouldreporterror ) + info("Expanded tilda open for[%s,%s], expanded to %s failed: Error message is %s",filename,prot,buffer, ERRORSTR); + } + + + + if( strchr(prot,'w') != NULL) + return NULL; + + + /* next line ABSOLUTELY relies on order of evaluation */ + if( personaldir != NULL && append_file_to_path(buffer,MAXPATHLEN,filename,personaldir) != FALSE && (ifp=fopen(buffer,prot)) != NULL) + return ifp; + + else if ( shouldreporterror ) + log_full_error(INFO,0,"Expanded personal direcotry open for[%s,%s], expanded to %s failed: Error message is %s",filename,prot,buffer,ERRORSTR); + + + /* next line ABSOLUTELY relies on order of evaluation */ + if( systemconfigdir != NULL && append_file_to_path(buffer,MAXPATHLEN,filename,systemconfigdir) != FALSE && (ifp=fopen(buffer,prot)) != NULL) + return ifp; + else if ( shouldreporterror ) + log_full_error(INFO,0,"Expanded system directory open for[%s,%s], expanded to %s failed: Error message is %s",filename,prot,buffer, ERRORSTR); + + +#ifdef CAREFUL + if( looks_like_vms(filename) && isvms == FALSE) + log_full_error(WARNING,0,"Filename %s looks like a VMS " + "file to me, and you've compiled as UNIX",filename); + if( looks_like_unix(filename) && isvms == TRUE) + log_full_error(WARNING,0,"Filename %s looks like a UNIX " + "file to me, and you've compiled as VMS",filename); +#endif + + return NULL; + +} + +/* Function: envopenfile(envname,filename,name,env) + * + * Descrip: This function basically mirrors the function in file.c + * in HMMer2. You call it as + * + * fp = Envfile(filename,envname); + * + * where envname looks like "BLASTDB" etc. + * + * + * + * Arg: envname [READ ] enviroment variable to read from [NullString] + * Arg: filename [UNKN ] Undocumented argument [char *] + * Arg: name [READ ] filename to open [NullString] + * Arg: env [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] a valid file pointer or NULL [FILE *] + * + */ +# line 296 "wisefile.dy" +FILE * envopenfile(char * filename,char * env) +{ + char * envp; + char path [512]; + + if( filename == NULL || env == NULL ) { + warn("Passed a NULL filename or enviroment name into Envfile. Should trap this elsewhere"); + return NULL; + } + + if( (envp = getenv(env)) == NULL ) { + /* fail gracefully - somebody might query a number of enviroment variables */ + return NULL; + } + + if( strlen(filename) + strlen(envp) < 490 ) { + warn("Really long filename/enviroment variables [%s] [%s] Can't cope!",filename,envp); + return NULL; + } + sprintf(path,"%s/%s",filename,envp); + + return fopen(path,"r"); +} + + +# line 341 "wisefile.c" + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/wisefile.h b/Bio/Ext/Align/libs/wisefile.h new file mode 100644 index 0000000..787683d --- /dev/null +++ b/Bio/Ext/Align/libs/wisefile.h @@ -0,0 +1,168 @@ +#ifndef DYNAMITEwisefileHEADERFILE +#define DYNAMITEwisefileHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" + +#define MAXPATHLEN 1024 + +#ifdef FILE_DEBUG +#define fclose myfclose +#endif + +#ifdef NOERROR +#define ERRORSTR "No error available" +#else +#define ERRORSTR strerror(errno) +#endif + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: set_config_dir(path,*path) + * + * Descrip: Programmatically set systemconfigdir to override + * any value set (or not) by env.var. WISECONFIGDIR. + * + * Added by arve. + * + * + * Arg: path [UNKN ] path that WISECONFIGDIR is set to [NullString] + * Arg: *path [UNKN ] Undocumented argument [char] + * + */ +void bp_sw_set_config_dir(char *path) ; +#define set_config_dir bp_sw_set_config_dir + + +/* Function: myfclose(ofp) + * + * Descrip: reports the fclose type etc + * + * + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_myfclose(FILE * ofp); +#define myfclose bp_sw_myfclose + + +/* Function: remove_file(filename) + * + * Descrip: silly function to provide a boolean wrapper + * around remove. + * + * + * Arg: filename [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_remove_file(char * filename); +#define remove_file bp_sw_remove_file + + +/* Function: move_file(from,to) + * + * Descrip: silly function to provide a boolean wrapper + * around rename + * + * + * Arg: from [UNKN ] Undocumented argument [char *] + * Arg: to [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_move_file(char * from,char * to); +#define move_file bp_sw_move_file + + +/* Function: touchfile(filename) + * + * Descrip: sees if filename exists + * + * + * Arg: filename [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_touchfile(char * filename); +#define touchfile bp_sw_touchfile + + +/* Function: openfile(filename,passedprot) + * + * Descrip: Every file open goes through this. + * + * It opens for reading in the following order + * . + * WISEPERSONALDIR + * WISECONFIGDIR + * + * For writing it opens in . + * + * Filenames with ~'s are expanded to HOME/filename + * + * + * Arg: filename [UNKN ] filename to open for read/writing [const char *] + * Arg: passedprot [UNKN ] string representing standard fopen attributes [const char *] + * + * Return [UNKN ] open'd filehandle, NULL on error [FILE *] + * + */ +FILE * bp_sw_openfile(const char * filename,const char * passedprot); +#define openfile bp_sw_openfile + + +/* Function: envopenfile(envname,filename,name,env) + * + * Descrip: This function basically mirrors the function in file.c + * in HMMer2. You call it as + * + * fp = Envfile(filename,envname); + * + * where envname looks like "BLASTDB" etc. + * + * + * + * Arg: envname [READ ] enviroment variable to read from [NullString] + * Arg: filename [UNKN ] Undocumented argument [char *] + * Arg: name [READ ] filename to open [NullString] + * Arg: env [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] a valid file pointer or NULL [FILE *] + * + */ +FILE * bp_sw_envopenfile(char * filename,char * env); +#define envopenfile bp_sw_envopenfile + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +void bp_sw_try_to_load(void); +#define try_to_load bp_sw_try_to_load +boolean bp_sw_append_file_to_path(char * buffer,int len,const char * file,char * path); +#define append_file_to_path bp_sw_append_file_to_path + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/wisememman.c b/Bio/Ext/Align/libs/wisememman.c new file mode 100644 index 0000000..4b044b3 --- /dev/null +++ b/Bio/Ext/Align/libs/wisememman.c @@ -0,0 +1,109 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "wisememman.h" + + + +/* Function: ckalloc(bytes) + * + * Descrip: Tries to alloc bytes of memory. Posts + * to warn if it fails + * + * + * Arg: bytes [UNKN ] Undocumented argument [size_t] + * + * Return [UNKN ] Undocumented return value [void *] + * + */ +# line 16 "wisememman.dy" +void * ckalloc(size_t bytes) +{ + register void *ret; + extern void *calloc (size_t nelem, size_t elsize); + + if( (ret = calloc(bytes, sizeof(char))) == NULL) { + warn("Out of memory, on asking for %d bytes\n",bytes); + return NULL; /*** for the moment, could fail here ***/ + } else + return ret; +} + +/* Function: ckcalloc(len,bytes) + * + * Descrip: calloc equivalent + * + * + * Arg: len [UNKN ] Undocumented argument [int] + * Arg: bytes [UNKN ] Undocumented argument [size_t] + * + * Return [UNKN ] Undocumented return value [void *] + * + */ +# line 31 "wisememman.dy" +void * ckcalloc(int len,size_t bytes) +{ + return ckalloc(len*bytes); +} + +/* Function: ckrealloc(*ptr,bytes) + * + * Descrip: realloc equivalent + * + * + * Arg: *ptr [UNKN ] Undocumented argument [void] + * Arg: bytes [UNKN ] Undocumented argument [size_t] + * + * Return [UNKN ] Undocumented return value [void *] + * + */ +# line 39 "wisememman.dy" +void * ckrealloc(void *ptr, size_t bytes) +{ + register void *ret; + extern void *realloc (void *ptr, size_t size); + + if (ptr == NULL) { + warn("Bad call to ckrealloc, NULL pointer\n"); + return NULL; + } + else if( (ret = realloc(ptr, bytes)) == NULL) { + warn("Out of memory, trying to realloc %d bytes\n",bytes); + return NULL; + } + else + return ret; +} + +/* Function: ckfree(*ptr) + * + * Descrip: free equivalent + * + * + * Arg: *ptr [UNKN ] Undocumented argument [void] + * + * Return [UNKN ] Undocumented return value [void *] + * + */ +# line 59 "wisememman.dy" +void * ckfree(void *ptr) +{ + + if (ptr == NULL) + warn("Bad call to ckfree - NULL pointer\n"); + else { + free(ptr); + ptr = NULL; + } + return ptr; +} + + + + + +# line 96 "wisememman.c" + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/wisememman.h b/Bio/Ext/Align/libs/wisememman.h new file mode 100644 index 0000000..ea64862 --- /dev/null +++ b/Bio/Ext/Align/libs/wisememman.h @@ -0,0 +1,89 @@ +#ifndef DYNAMITEwisememmanHEADERFILE +#define DYNAMITEwisememmanHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: ckalloc(bytes) + * + * Descrip: Tries to alloc bytes of memory. Posts + * to warn if it fails + * + * + * Arg: bytes [UNKN ] Undocumented argument [size_t] + * + * Return [UNKN ] Undocumented return value [void *] + * + */ +void * bp_sw_ckalloc(size_t bytes); +#define ckalloc bp_sw_ckalloc + + +/* Function: ckcalloc(len,bytes) + * + * Descrip: calloc equivalent + * + * + * Arg: len [UNKN ] Undocumented argument [int] + * Arg: bytes [UNKN ] Undocumented argument [size_t] + * + * Return [UNKN ] Undocumented return value [void *] + * + */ +void * bp_sw_ckcalloc(int len,size_t bytes); +#define ckcalloc bp_sw_ckcalloc + + +/* Function: ckrealloc(*ptr,bytes) + * + * Descrip: realloc equivalent + * + * + * Arg: *ptr [UNKN ] Undocumented argument [void] + * Arg: bytes [UNKN ] Undocumented argument [size_t] + * + * Return [UNKN ] Undocumented return value [void *] + * + */ +void * bp_sw_ckrealloc(void *ptr, size_t bytes); +#define ckrealloc bp_sw_ckrealloc + + +/* Function: ckfree(*ptr) + * + * Descrip: free equivalent + * + * + * Arg: *ptr [UNKN ] Undocumented argument [void] + * + * Return [UNKN ] Undocumented return value [void *] + * + */ +void * bp_sw_ckfree(void *ptr); +#define ckfree bp_sw_ckfree + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/wiseoverlay.c b/Bio/Ext/Align/libs/wiseoverlay.c new file mode 100644 index 0000000..38667e3 --- /dev/null +++ b/Bio/Ext/Align/libs/wiseoverlay.c @@ -0,0 +1,92 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "wiseoverlay.h" + +static boolean isinuse=FALSE; +static FILE * overlay = NULL; +static int delete_len=0; + + +/* Function: start_overlay(over) + * + * Descrip: actually starts on overlay system + * on the FILE*. Should really by stderr... + * nothing else makes sense. + * + * + * Arg: over [UNKN ] Undocumented argument [FILE *] + * + */ +# line 22 "wiseoverlay.dy" +void start_overlay(FILE * over) +{ + overlay=over; + isinuse=TRUE; +} + +/* Function: stop_overlay(void) + * + * Descrip: finishes an overlay system by putting in a + * newline and clearing the static variables + * + * + * + */ +# line 32 "wiseoverlay.dy" +void stop_overlay(void) +{ + fprintf(overlay,"\n"); + delete_len=0; + overlay=NULL; + isinuse=FALSE; +} + +/* Function: print_overlay(msg,) + * + * Descrip: Does the business. Deletes the previous + * message with \b and then prints the current + * one ontop. + * + * don't put in \n's otherwise this is going to + * look yukky ;) + * + * + * Arg: msg [UNKN ] Undocumented argument [char *] + * Arg: [UNKN ] Undocumented argument [.] + * + */ +# line 48 "wiseoverlay.dy" +void print_overlay(char * msg, ... ) +{ + char buffer[512]; + va_list ap; + register int i; + + if( isinuse == FALSE) + /* error message */ + return; + + + va_start(ap,msg); + + for(i=0;i + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: init_random(void) + * + * Descrip: initates the random generator to + * time byte... + * + * + * + */ +void bp_sw_init_random(void); +#define init_random bp_sw_init_random + + +/* Function: random_integer(l) + * + * Descrip: returns an integer between 0 and l + * though I don't think we will get 0 + * very often. Hmmm. + * + * + * Arg: l [UNKN ] Undocumented argument [int] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_random_integer(int l); +#define random_integer bp_sw_random_integer + + +/* Function: random_0_to_1(void) + * + * Descrip: returns a random number between + * 0 and 1 + * + * + * + * Return [UNKN ] Undocumented return value [double] + * + */ +double bp_sw_random_0_to_1(void); +#define random_0_to_1 bp_sw_random_0_to_1 + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/wisestring.c b/Bio/Ext/Align/libs/wisestring.c new file mode 100644 index 0000000..9ab8ef4 --- /dev/null +++ b/Bio/Ext/Align/libs/wisestring.c @@ -0,0 +1,1109 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "wisestring.h" + +/* Function: get_number_from_slashed_string(qstr,slashstr) + * + * Descrip: handy: pass a string like "xxx/yyy/zzz" + * and a query like yyy, will return 2 + * (ie, maps positions in slashed string with + * a number from start). Returns -1 if none + * + * + * Arg: qstr [UNKN ] Undocumented argument [char *] + * Arg: slashstr [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 41 "wisestring.dy" +int get_number_from_slashed_string(char * qstr,char * slashstr) +{ + char * runner; + char * stop; + int ret; + + /*** if the qstr is not in there, then we can get out! **/ + + if( (stop=strstr(slashstr,qstr)) == NULL ) { + return (-1); + } + + /** ok, run through slashstr until we hit stop, counting slashes **/ + + for(ret = 0,runner=slashstr;*runner && runner < stop ;runner++) + if( *runner == '/') + ret++; + + return ret; +} + + +/* Function: is_integer_string(string,val) + * + * Descrip: checks that strings are ints or doubles + * and then converts, storing value in val + * if val == NULL, will not store (!) + * + * Does use sensible library functions + * strtol... + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: val [UNKN ] Undocumented argument [int *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 71 "wisestring.dy" +boolean is_integer_string(char * string,int * val) +{ + int ret; + char * end; + + ret = strtol(string,&end,10); + + if( val != NULL) + *val = ret; + + if( isalpha(*end) ) + return FALSE; + + return TRUE; +} + +/* Function: is_double_string(string,val) + * + * Descrip: checks that strings are doubles + * and then converts, storing value in val + * if val == NULL, will not store (!) + * + * Does use sensible library functions + * strtod + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: val [UNKN ] Undocumented argument [double *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 95 "wisestring.dy" +boolean is_double_string(char * string,double * val) +{ + double ret; + char * end; + + ret = strtod(string,&end); + + if( val != NULL) + *val = ret; + + if( isalpha(*end) ) + return FALSE; + + return TRUE; +} + +/* Function: compress_space_around_punc(buffer,punc,space) + * + * Descrip: No Description + * + * Arg: buffer [UNKN ] Undocumented argument [char *] + * Arg: punc [UNKN ] Undocumented argument [char *] + * Arg: space [UNKN ] Undocumented argument [char *] + * + */ +# line 118 "wisestring.dy" +void compress_space_around_punc(char * buffer,char * punc,char * space) +{ + char * runner; + char * run2; + + runner = buffer; + for(;;) { + /*** find next position ***/ + for(;*runner && strchr(punc,*runner) == NULL;runner++ ) + ; + + if( *runner == '\0') + break; + + /*** this is a puncation position ***/ + /*** go back over any number of spaces ***/ + + for(run2 = runner - 1;run2 >= buffer && strchr(space,*run2) != NULL;run2--) + ; + + /*** run2 now at first non space position after runner ***/ + + if( run2 != buffer && run2+1 < runner ) { + /*** we have some spaces to remove ***/ + + strcpy(run2+1,runner); + runner = run2+1; /** runner now at first punc position **/ + } + + for(;*runner && strchr(punc,*runner) != NULL;runner++) + ; + if( *runner == '\0') + break; + + run2 = runner; /*** run2 at position after last punc ***/ + + for(;*runner && strchr(space,*runner) != NULL;runner++) + ; + if( run2 != runner ) { + strcpy(run2,runner); + } + + runner = run2; + } + +} + +/* Function: striptoprint(line) + * + * Descrip: useful strip functions to remove nasty chars + * does not allocate memory, simply uses + * given memory, but returns the line pointer + * so you can use it in nested function calls + * + * + * Arg: line [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 171 "wisestring.dy" +char * striptoprint(char * line) +{ + char * run; + char * base; + + if( line == NULL ) + return NULL; + + base = run = line; + + for(;*line;line++) + if( isprint(*line) ) + *(run++) = *line; + + *run = '\0'; + + return base; +} + +/* Function: stringalloc_next_quoted_string(buffer) + * + * Descrip: takes str's of type "xxxxx" + * and gives back xxxxxx . + * stringalloc'd piece so make sure you free it + * + * + * Arg: buffer [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 195 "wisestring.dy" +char * stringalloc_next_quoted_string(char * buffer) +{ + char c; + char * base; + char * ret; + + for(;*buffer && *buffer != '"';buffer++) + ; + if( ! *buffer ) + return NULL; + + for(base=buffer+1,buffer++;*buffer && *buffer != '"';buffer++) + ; + if( !*buffer ) + return NULL; + + c = *buffer; + *buffer = '\0'; + + ret = stringalloc (base); + *buffer = c; + + return ret; +} + + +/* Function: strwhitestartcmp(line,str,whitespace) + * + * Descrip: sees if line starts with str, ignoring whitespace + * + * returns 0 if they match, to look like strcmp + * + * + * Arg: line [UNKN ] Undocumented argument [char *] + * Arg: str [UNKN ] Undocumented argument [char *] + * Arg: whitespace [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 226 "wisestring.dy" +int strwhitestartcmp(char * line,char * str,char * whitespace) +{ + while( strchr(whitespace,*line) != NULL ) + line++; + + if( *line == '\0') + return -(int)(*str); + + for(;*line == *str && *line && *str;line++,str++) + ; + + if( *str == '\0') + return 0; + + else return (int)(*line - *str); +} + +/* Function: strwordcmp(buf,str,space) + * + * Descrip: sees if buf matches str\s in perl regex, ie + * a word match + * + * space defined \s + * + * returns 0 if they match to look like strcmp + * + * + * Arg: buf [UNKN ] Undocumented argument [char *] + * Arg: str [UNKN ] Undocumented argument [char *] + * Arg: space [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 251 "wisestring.dy" +int strwordcmp(char * buf,char * str,char * space) +{ + for(;*buf && *str && *buf == *str;buf++,str++) + ; + + /** end of buf... get out, buf not space, get out, not end of str **/ + + if( *str != '\0' || strchr(space,*buf) == NULL ) + return 1; + + return 0; +} + +/* Function: strstartcmp(buf,str) + * + * Descrip: sees if buf starts with str. + * + * returns 0 if so, to mimic strcmp + * + * + * Arg: buf [UNKN ] Undocumented argument [char *] + * Arg: str [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 269 "wisestring.dy" +int strstartcmp(char * buf,char * str) +{ + for(;*buf && *str;str++,buf++) + { + if( *buf > *str) + return 1; + else if( *buf < *str) + return -1; + else continue; + } + if( !(*str) ) + return 0; + + return 1; +} + +/* Function: print_numbered_line(num,ofp) + * + * Descrip: prints lines like _1_________ + * + * + * Arg: num [UNKN ] Undocumented argument [int] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 288 "wisestring.dy" +void print_numbered_line(int num,FILE * ofp) +{ + register int i; + fprintf(ofp,"_%d",num); + + if( num < 10000 ) + i=4; + if( num < 1000 ) + i=3; + if( num < 100 ) + i=2; + if( num < 10 ) + i=1; + for(;i<68;i++) + fputc('_',ofp); + fputc('\n',ofp); + return; +} + +/* Function: print_line(ofp) + * + * Descrip: prints _______________ (70 chars) + * + * + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 310 "wisestring.dy" +void print_line(FILE * ofp) +{ + register int i; + for(i=0;i<70;i++) + fputc('_',ofp); + fputc('\n',ofp); + return; +} + +/* Function: only_whitespace(str,space) + * + * Descrip: returns true if str is only made from space. + * + * Deprecated + * + * + * Arg: str [UNKN ] Undocumented argument [char *] + * Arg: space [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 325 "wisestring.dy" +boolean only_whitespace(char * str,char * space) +{ + for(;*str && strchr(space,*str) != NULL;str++) + ; + if( *str != '\0') + return FALSE; + return TRUE; +} + +/* Function: chop_newline(str) + * + * Descrip: removes trailing newline if present + * + * + * Arg: str [UNKN ] Undocumented argument [char *] + * + */ +# line 337 "wisestring.dy" +void chop_newline(char * str) +{ + str += strlen(str) -1; + if( *str == '\n' ) { + *str = '\0'; + } +} + + +/* Function: good_datastring_fromend(str) + * + * Descrip: Tries to find the last 'database name' + * type string from a string. + * + * Does not allocate memory + * + * + * Arg: str [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 352 "wisestring.dy" +char * good_datastring_fromend(char * str) +{ + register char * base=str; + + str+=strlen(str); + for(str--;str >= base;str--) + if( !isalnum(*str) && *str != '_' && *str != '.') + break; + return str == base ? base : ++str; +} + +/* Function: looks_like_vms(str) + * + * Descrip: not useful + * + * + * Arg: str [UNKN ] Undocumented argument [const char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 367 "wisestring.dy" +boolean looks_like_vms(const char * str) +{ + if ( strchr(str,':') != NULL) + return TRUE; + else return FALSE; +} + +/* Function: looks_like_unix(str) + * + * Descrip: not useful + * + * + * Arg: str [UNKN ] Undocumented argument [const char *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +# line 378 "wisestring.dy" +boolean looks_like_unix(const char * str) +{ + if( strchr(str,'/') != NULL) + return TRUE; + else return FALSE; +} + +/* Function: estrcasecmp(one,two) + * + * Descrip: returns strcmp on the captilalised + * one and two bufferers (doesn't touch them). + * + * + * Arg: one [UNKN ] Undocumented argument [char *] + * Arg: two [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 389 "wisestring.dy" +int estrcasecmp(char * one,char * two) +{ + char * tempone; + char * temptwo; + int out; + + tempone=stringalloc(one); + temptwo=stringalloc(two); + + capitalise(tempone); + capitalise(temptwo); + + out=strcmp(tempone,temptwo); + + free(tempone); + free(temptwo); + + return out; +} + +/* Function: strend(bu,se) + * + * Descrip: useless + * + * + * Arg: bu [UNKN ] Undocumented argument [char *] + * Arg: se [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 413 "wisestring.dy" +char * strend(char * bu,char * se) +{ + register char * runner; + + runner=strstr(bu,se); + if(runner == NULL) + return NULL; + + runner+=strlen(se); + + return runner; +} + + +/* Function: string_before_equality(string) + * + * Descrip: Useless + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 431 "wisestring.dy" +char * string_before_equality(char * string) +{ + char * base; + char * runner; + + runner=base=stringalloc(string); + + for(;*runner && *runner != '=';runner++) + ; + if(*runner == '\0') + { + free(base); + return NULL; + } + + for(runner--;isspace(*runner);runner--) + ; + runner++; + *runner='\0'; + + runner=stringalloc(base); + free(base); + + return runner; +} + +/* Function: number_from_quoted_equality(s) + * + * Descrip: supposedly gets a number from a + * string like xxx="12" + * + * + * Arg: s [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 461 "wisestring.dy" +int number_from_quoted_equality(char * s) +{ + char * st; + int ret; + char c; + + for(;*s && *s != '=';s++) + ; + + if( !*s ) + return 0; + + for(;*s && isspace(*s);s++) + ; + /*** start of the number now... ***/ + + st = s; + for(;*s && isalnum(*s);s++) + ; + c = *s; + *s = '\0'; + ret = atoi(st); + *s = c; + + return ret; +} + + +/* Function: number_from_equality(string) + * + * Descrip: supposedly gets a number from + * xxxx=12 + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +# line 493 "wisestring.dy" +int number_from_equality(char * string) +{ + char * st; + + for(;*string && *string != '=';string++) + ; + + if(*string == '\0') + return 0; + + for(;isspace(*string) && *string;string++) + ; + st=string; + + for(;!isspace(*string) && *string;string++) + + *string='\0'; + + return atoi(st); +} + +/* Function: sub_string(into,key,sub) + * + * Descrip: deprecated + * + * + * Arg: into [UNKN ] Undocumented argument [char *] + * Arg: key [UNKN ] Undocumented argument [char *] + * Arg: sub [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 518 "wisestring.dy" +char * sub_string(char * into,char * key,char * sub) +{ + char buffer[MAXLINE]; + char * runner; + char * stop; + + runner=buffer; + + while( (stop=strstr(into,key)) != NULL) + { + while( into != stop ) + *(runner++)=(*(into++)); + *runner='\0'; + strcat(buffer,sub); + runner=buffer+strlen(buffer); + into+=strlen(key); + } + while( *into ) + *(runner++)=(*(into++)); + *(runner)='\0'; + + return stringalloc(buffer); +} + +/* Function: string_from_quoted_equality(string) + * + * Descrip: gets the string from xxx="yyy". Returns + * yyy allocated, and messes around with string + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 546 "wisestring.dy" +char * string_from_quoted_equality(char * string) +{ + return string_from_charred_equality(string,'"'); +} + +/* Function: string_from_charred_equality(string,quote) + * + * Descrip: gets the string from xxx="yyy" ,where " comes + * from the quote argument Returns + * yyy allocated, and messes around with string + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: quote [UNKN ] Undocumented argument [char] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 556 "wisestring.dy" +char * string_from_charred_equality(char * string,char quote) +{ + char * base; + + for(;*string && *string != '=';string++) + ; + + if(*string == '\0') + return NULL; + + for(;*string && *string != quote;string++) + ; + + if(*string == '\0') + return NULL; + + string++; + base=string; + + for(;*string && *string != quote;string++) + ; + + *string='\0'; + + return stringalloc(base); +} + +/* Function: breakstring(string,parsestr) + * + * Descrip: A call to /breakstring_protect(string,parsestr,"\"") + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: parsestr [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char **] + * + */ +# line 586 "wisestring.dy" +char ** breakstring(char * string,char * parsestr) +{ + return breakstring_protect(string,parsestr,"\""); +} + +/* Function: breakstring_protect(string,parsestr,strpair) + * + * Descrip: will parse out words in string using parse + * as white space, like strtok, but strings + * enclosed in characters from strpair are not + * taken in parsed form. + * breakstring = + * breakstring_protect(string,parse,"\""); + * hence will not break in double quotes + * + * unlike strtok they return char ** + * which is a list of char * of words + * the last being NULL'd + * + * + * They returned an alloc'd char ** which you + * are expected to free. Standard idiom is + * base=brk=breakstring(buffer,spacestr) + * (NB - spacestr #defin'd above ) + * ... do stuff using brk + * eg *brk = first word + * *(++brk) = next word + * last word = NULL + * cleanup by ckfree(base) + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: parsestr [UNKN ] Undocumented argument [char *] + * Arg: strpair [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char **] + * + */ +# line 615 "wisestring.dy" +char ** breakstring_protect(char * string,char * parsestr,char * strpair) +{ + char ** outstr; + int index=1; + + outstr=(char **) ckcalloc (128,sizeof(char *)); + + + while( strchr(parsestr,*string) != NULL) + string++; + + outstr[0]=string; + + while(*string) + { + if( strchr(strpair,*string) != NULL ) + { + auto char c; + c = *string; + for(string++;strchr(strpair,*string) == NULL && *string;string++) + if( *string == '\\' ) + string++; + if( *string == '\0') + { + log_full_error(WARNING,0,"In breakstring_protect, reached endofline in protected string [%s]",outstr[index]); + outstr[++index]=NULL; + return outstr; + } + string++; /* shifts on one past " */ + } + else if( strchr(parsestr,*string) != NULL) + { + while( *string && strchr(parsestr,*string) != NULL) + *(string++)='\0'; + if( *string == '\0') + break; + string--; + *string='\0'; + outstr[index++]=string+1; + string++; + } + else string++; + } + + + outstr[index]=NULL; + + + + return outstr; +} + +/* Function: strip_quote_chars(string,quote) + * + * Descrip: removes chars in quote + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: quote [UNKN ] Undocumented argument [char *] + * + */ +# line 670 "wisestring.dy" +void strip_quote_chars(char * string,char * quote) +{ + char * base =string; + char * run; + + if( strchr(quote,*string) != NULL ) + { + for(string++;*string;string++) + *(string-1)= (*string); + *(string-1) = '\0'; + } + + + run = base+strlen(base)-1; + if( strchr(quote,*run) != NULL ) + *run= '\0'; + +} + +/* Function: padstring(buffer,string,maxlen) + * + * Descrip: copies string into buffer, and if under maxlen, + * adds spaces. Does *not* put in '\0' + * + * + * Arg: buffer [UNKN ] Undocumented argument [char *] + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: maxlen [UNKN ] Undocumented argument [int] + * + */ +# line 693 "wisestring.dy" +void padstring(char * buffer,char * string,int maxlen) +{ + + for(;*string && maxlen > 0;string++,buffer++,maxlen--) + *buffer=(*string); + if( maxlen > 0) + for(;maxlen > 0;maxlen--,buffer++) + *buffer=' '; + return; +} + +/* Function: capitalise(word) + * + * Descrip: toupper's each char in word + * + * + * Arg: word [UNKN ] Undocumented argument [char *] + * + */ +# line 707 "wisestring.dy" +void capitalise(char * word) +{ + for(;*word;word++) + *word=toupper(*word); +} + + + +/* Function: show_line(line,max,*ofp) + * + * Descrip: This shouws line putting a new line in every max + * chars, not minding word boundaries + * + * + * Arg: line [UNKN ] Undocumented argument [char *] + * Arg: max [UNKN ] Undocumented argument [int] + * Arg: *ofp [UNKN ] Undocumented argument [FILE] + * + */ +# line 719 "wisestring.dy" +void show_line(char * line,int max,FILE *ofp) +{ + int i; + + for(i=0;*(line+i);i++) + { + if( (i%max) == 0 && i != 0) + fputc('\n',ofp); + fputc(*(line+i),ofp); + } + fputc('\n',ofp); + + return; +} + +/* Function: show_text(line,max,*ofp) + * + * Descrip: This shouws line putting a new line in every max + * chars, *minding* word boundaries + * + * + * Arg: line [UNKN ] Undocumented argument [char *] + * Arg: max [UNKN ] Undocumented argument [int] + * Arg: *ofp [UNKN ] Undocumented argument [FILE] + * + */ +# line 738 "wisestring.dy" +void show_text(char * line,int max,FILE *ofp) +{ + char push; + char *pushpoi; + char * runner; + + for(runner=line;;) + { + for(;(int)(runner-line) < max && *runner;) + { + pushpoi=runner; + while( *(++runner) != ' ' && *runner) + ; /* NB dodgy pre ++ in above line */ + } + if(*runner == '\0') + { + if((int)(runner-line) < max) + fprintf(ofp,"%s\n",line); + else { + push=(*pushpoi); + *pushpoi='\0'; + fprintf(ofp,"%s\n",line); + *pushpoi=push; + line=pushpoi+1; + fprintf(ofp,"%s\n",line); + } + break; + } + else { + push=(*pushpoi); + *pushpoi='\0'; + fprintf(ofp,"%s\n",line); + *pushpoi=push; + line=pushpoi+1; + runner=line; + } + } + + return; +} + +/* Function: second_word_alloc(str,space) + * + * Descrip: returns the second word alloc'd for + * + * xxx yyyy + * + * returns yyyy. + * + * + * Arg: str [UNKN ] Undocumented argument [char *] + * Arg: space [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 786 "wisestring.dy" +char * second_word_alloc(char * str,char * space) +{ + char * out; + char c; + + for(;*str && strchr(space,*str) == NULL;str++) + ; + + if( *str == '\0') { + warn("Can only find one word in [%s] - certainly can't alloc the second",str); + return NULL; + } + + for(str++;*str && strchr(space,*str) != NULL;str++) + ; + + out=str; + + for(;*str && strchr(space,*str) == NULL;str++) + ; + + c = *str; + *str ='\0'; + out = stringalloc(out); + + *str= c; + + return out; +} + +/* Function: stringallocf(str,) + * + * Descrip: Don't use this + * + * sprintf's then allocs + * + * + * Arg: str [UNKN ] Undocumented argument [char *] + * Arg: [UNKN ] Undocumented argument [.] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 821 "wisestring.dy" +char * stringallocf(char * str,...) +{ + char buffer[1024]; + va_list ap; + + va_start(ap,str); + + vsprintf(buffer,str,ap); + + va_end(ap); + + return stringalloc(buffer); +} + + +/* Function: stringalloc(c) + * + * Descrip: returns the allocated copy of c. + * Usually called strdup in other packages + * + * + * Arg: c [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 840 "wisestring.dy" +char * stringalloc(char * c) +{ + register int i; + register char * temp; + + if(c == NULL) { + warn("Passed stringalloc a NULL pointer"); + return NULL; + } + + i = strlen(c); + + if((temp=(char *)ckalloc(sizeof(char)*(i+1))) == NULL) { + warn("stringalloc unable to allocate memory"); + return NULL; + } + + strcpy(temp,c); + + return temp; +} + +# line 1036 "wisestring.c" + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/wisestring.h b/Bio/Ext/Align/libs/wisestring.h new file mode 100644 index 0000000..f7334a3 --- /dev/null +++ b/Bio/Ext/Align/libs/wisestring.h @@ -0,0 +1,530 @@ +#ifndef DYNAMITEwisestringHEADERFILE +#define DYNAMITEwisestringHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" + + + +/**********************************************/ +/* useful macros to put into fprintf lines... */ +/* Makes sure you don't trash memory etc */ +/**********************************************/ +#define CHECKSTRING(str) (str == NULL ? "NullString" : str) +#define CKS CHECKSTRING + +/**********************************************/ +/* useful standard strings for parsing */ +/* spacestr is general whitespace */ +/* breakstr is general non alpha/num */ +/* used alot in breakstring */ +/**********************************************/ +#define spacestr " \t\n\0" +#define breakstr "!\"#$%^&*()-+={}[]@';:?/.,\\|~` \n\t" + +/**********************************************/ +/* Not the nicest of macros. Stay away from it*/ +/**********************************************/ +#define NEXTWORD strtok(NULL,spacestr) + + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: get_number_from_slashed_string(qstr,slashstr) + * + * Descrip: handy: pass a string like "xxx/yyy/zzz" + * and a query like yyy, will return 2 + * (ie, maps positions in slashed string with + * a number from start). Returns -1 if none + * + * + * Arg: qstr [UNKN ] Undocumented argument [char *] + * Arg: slashstr [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_get_number_from_slashed_string(char * qstr,char * slashstr); +#define get_number_from_slashed_string bp_sw_get_number_from_slashed_string + + +/* Function: is_integer_string(string,val) + * + * Descrip: checks that strings are ints or doubles + * and then converts, storing value in val + * if val == NULL, will not store (!) + * + * Does use sensible library functions + * strtol... + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: val [UNKN ] Undocumented argument [int *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_is_integer_string(char * string,int * val); +#define is_integer_string bp_sw_is_integer_string + + +/* Function: is_double_string(string,val) + * + * Descrip: checks that strings are doubles + * and then converts, storing value in val + * if val == NULL, will not store (!) + * + * Does use sensible library functions + * strtod + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: val [UNKN ] Undocumented argument [double *] + * + * Return [UNKN ] Undocumented return value [boolean] + * + */ +boolean bp_sw_is_double_string(char * string,double * val); +#define is_double_string bp_sw_is_double_string + + +/* Function: compress_space_around_punc(buffer,punc,space) + * + * Descrip: No Description + * + * Arg: buffer [UNKN ] Undocumented argument [char *] + * Arg: punc [UNKN ] Undocumented argument [char *] + * Arg: space [UNKN ] Undocumented argument [char *] + * + */ +void bp_sw_compress_space_around_punc(char * buffer,char * punc,char * space); +#define compress_space_around_punc bp_sw_compress_space_around_punc + + +/* Function: striptoprint(line) + * + * Descrip: useful strip functions to remove nasty chars + * does not allocate memory, simply uses + * given memory, but returns the line pointer + * so you can use it in nested function calls + * + * + * Arg: line [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_striptoprint(char * line); +#define striptoprint bp_sw_striptoprint + + +/* Function: stringalloc_next_quoted_string(buffer) + * + * Descrip: takes str's of type "xxxxx" + * and gives back xxxxxx . + * stringalloc'd piece so make sure you free it + * + * + * Arg: buffer [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_stringalloc_next_quoted_string(char * buffer); +#define stringalloc_next_quoted_string bp_sw_stringalloc_next_quoted_string + + +/* Function: strwhitestartcmp(line,str,whitespace) + * + * Descrip: sees if line starts with str, ignoring whitespace + * + * returns 0 if they match, to look like strcmp + * + * + * Arg: line [UNKN ] Undocumented argument [char *] + * Arg: str [UNKN ] Undocumented argument [char *] + * Arg: whitespace [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_strwhitestartcmp(char * line,char * str,char * whitespace); +#define strwhitestartcmp bp_sw_strwhitestartcmp + + +/* Function: strwordcmp(buf,str,space) + * + * Descrip: sees if buf matches str\s in perl regex, ie + * a word match + * + * space defined \s + * + * returns 0 if they match to look like strcmp + * + * + * Arg: buf [UNKN ] Undocumented argument [char *] + * Arg: str [UNKN ] Undocumented argument [char *] + * Arg: space [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_strwordcmp(char * buf,char * str,char * space); +#define strwordcmp bp_sw_strwordcmp + + +/* Function: strstartcmp(buf,str) + * + * Descrip: sees if buf starts with str. + * + * returns 0 if so, to mimic strcmp + * + * + * Arg: buf [UNKN ] Undocumented argument [char *] + * Arg: str [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_strstartcmp(char * buf,char * str); +#define strstartcmp bp_sw_strstartcmp + + +/* Function: print_numbered_line(num,ofp) + * + * Descrip: prints lines like _1_________ + * + * + * Arg: num [UNKN ] Undocumented argument [int] + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_print_numbered_line(int num,FILE * ofp); +#define print_numbered_line bp_sw_print_numbered_line + + +/* Function: print_line(ofp) + * + * Descrip: prints _______________ (70 chars) + * + * + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_print_line(FILE * ofp); +#define print_line bp_sw_print_line + + +/* Function: chop_newline(str) + * + * Descrip: removes trailing newline if present + * + * + * Arg: str [UNKN ] Undocumented argument [char *] + * + */ +void bp_sw_chop_newline(char * str); +#define chop_newline bp_sw_chop_newline + + +/* Function: good_datastring_fromend(str) + * + * Descrip: Tries to find the last 'database name' + * type string from a string. + * + * Does not allocate memory + * + * + * Arg: str [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_good_datastring_fromend(char * str); +#define good_datastring_fromend bp_sw_good_datastring_fromend + + +/* Function: estrcasecmp(one,two) + * + * Descrip: returns strcmp on the captilalised + * one and two bufferers (doesn't touch them). + * + * + * Arg: one [UNKN ] Undocumented argument [char *] + * Arg: two [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_estrcasecmp(char * one,char * two); +#define estrcasecmp bp_sw_estrcasecmp + + +/* Function: number_from_quoted_equality(s) + * + * Descrip: supposedly gets a number from a + * string like xxx="12" + * + * + * Arg: s [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_number_from_quoted_equality(char * s); +#define number_from_quoted_equality bp_sw_number_from_quoted_equality + + +/* Function: number_from_equality(string) + * + * Descrip: supposedly gets a number from + * xxxx=12 + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [int] + * + */ +int bp_sw_number_from_equality(char * string); +#define number_from_equality bp_sw_number_from_equality + + +/* Function: string_from_quoted_equality(string) + * + * Descrip: gets the string from xxx="yyy". Returns + * yyy allocated, and messes around with string + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_string_from_quoted_equality(char * string); +#define string_from_quoted_equality bp_sw_string_from_quoted_equality + + +/* Function: string_from_charred_equality(string,quote) + * + * Descrip: gets the string from xxx="yyy" ,where " comes + * from the quote argument Returns + * yyy allocated, and messes around with string + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: quote [UNKN ] Undocumented argument [char] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_string_from_charred_equality(char * string,char quote); +#define string_from_charred_equality bp_sw_string_from_charred_equality + + +/* Function: breakstring(string,parsestr) + * + * Descrip: A call to /breakstring_protect(string,parsestr,"\"") + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: parsestr [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char **] + * + */ +char ** bp_sw_breakstring(char * string,char * parsestr); +#define breakstring bp_sw_breakstring + + +/* Function: breakstring_protect(string,parsestr,strpair) + * + * Descrip: will parse out words in string using parse + * as white space, like strtok, but strings + * enclosed in characters from strpair are not + * taken in parsed form. + * breakstring = + * breakstring_protect(string,parse,"\""); + * hence will not break in double quotes + * + * unlike strtok they return char ** + * which is a list of char * of words + * the last being NULL'd + * + * + * They returned an alloc'd char ** which you + * are expected to free. Standard idiom is + * base=brk=breakstring(buffer,spacestr) + * (NB - spacestr #defin'd above ) + * ... do stuff using brk + * eg *brk = first word + * *(++brk) = next word + * last word = NULL + * cleanup by ckfree(base) + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: parsestr [UNKN ] Undocumented argument [char *] + * Arg: strpair [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char **] + * + */ +char ** bp_sw_breakstring_protect(char * string,char * parsestr,char * strpair); +#define breakstring_protect bp_sw_breakstring_protect + + +/* Function: strip_quote_chars(string,quote) + * + * Descrip: removes chars in quote + * + * + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: quote [UNKN ] Undocumented argument [char *] + * + */ +void bp_sw_strip_quote_chars(char * string,char * quote); +#define strip_quote_chars bp_sw_strip_quote_chars + + +/* Function: padstring(buffer,string,maxlen) + * + * Descrip: copies string into buffer, and if under maxlen, + * adds spaces. Does *not* put in '\0' + * + * + * Arg: buffer [UNKN ] Undocumented argument [char *] + * Arg: string [UNKN ] Undocumented argument [char *] + * Arg: maxlen [UNKN ] Undocumented argument [int] + * + */ +void bp_sw_padstring(char * buffer,char * string,int maxlen); +#define padstring bp_sw_padstring + + +/* Function: capitalise(word) + * + * Descrip: toupper's each char in word + * + * + * Arg: word [UNKN ] Undocumented argument [char *] + * + */ +void bp_sw_capitalise(char * word); +#define capitalise bp_sw_capitalise + + +/* Function: show_line(line,max,*ofp) + * + * Descrip: This shouws line putting a new line in every max + * chars, not minding word boundaries + * + * + * Arg: line [UNKN ] Undocumented argument [char *] + * Arg: max [UNKN ] Undocumented argument [int] + * Arg: *ofp [UNKN ] Undocumented argument [FILE] + * + */ +void bp_sw_show_line(char * line,int max,FILE *ofp); +#define show_line bp_sw_show_line + + +/* Function: show_text(line,max,*ofp) + * + * Descrip: This shouws line putting a new line in every max + * chars, *minding* word boundaries + * + * + * Arg: line [UNKN ] Undocumented argument [char *] + * Arg: max [UNKN ] Undocumented argument [int] + * Arg: *ofp [UNKN ] Undocumented argument [FILE] + * + */ +void bp_sw_show_text(char * line,int max,FILE *ofp); +#define show_text bp_sw_show_text + + +/* Function: second_word_alloc(str,space) + * + * Descrip: returns the second word alloc'd for + * + * xxx yyyy + * + * returns yyyy. + * + * + * Arg: str [UNKN ] Undocumented argument [char *] + * Arg: space [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_second_word_alloc(char * str,char * space); +#define second_word_alloc bp_sw_second_word_alloc + + +/* Function: stringallocf(str,) + * + * Descrip: Don't use this + * + * sprintf's then allocs + * + * + * Arg: str [UNKN ] Undocumented argument [char *] + * Arg: [UNKN ] Undocumented argument [.] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_stringallocf(char * str,...); +#define stringallocf bp_sw_stringallocf + + +/* Function: stringalloc(c) + * + * Descrip: returns the allocated copy of c. + * Usually called strdup in other packages + * + * + * Arg: c [UNKN ] Undocumented argument [char *] + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_stringalloc(char * c); +#define stringalloc bp_sw_stringalloc + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ +boolean bp_sw_only_whitespace(char * str,char * space); +#define only_whitespace bp_sw_only_whitespace +boolean bp_sw_looks_like_vms(const char * str); +#define looks_like_vms bp_sw_looks_like_vms +boolean bp_sw_looks_like_unix(const char * str); +#define looks_like_unix bp_sw_looks_like_unix +char * bp_sw_strend(char * bu,char * se); +#define strend bp_sw_strend +char * bp_sw_string_before_equality(char * string); +#define string_before_equality bp_sw_string_before_equality +char * bp_sw_sub_string(char * into,char * key,char * sub); +#define sub_string bp_sw_sub_string + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/libs/wisetime.c b/Bio/Ext/Align/libs/wisetime.c new file mode 100644 index 0000000..36b3568 --- /dev/null +++ b/Bio/Ext/Align/libs/wisetime.c @@ -0,0 +1,55 @@ +#ifdef _cplusplus +extern "C" { +#endif +#include "wisetime.h" + +/* Function: now_string(void) + * + * Descrip: returns a buffer + * of the current date and time + * + * + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +# line 14 "wisetime.dy" +char * now_string(void) +{ + char * temp; + char * runner; + time_t now; + + now=time(NULL); + temp=ctime(&now); + runner=temp+strlen(temp); + runner--; + *runner='\0'; /* got rid of annoying new line */ + return temp; +} + +/* Function: time_stamp(ofp) + * + * Descrip: puts now_string into file, with + * no newline + * + * + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +# line 32 "wisetime.dy" +void time_stamp(FILE * ofp) +{ + time_t now; + + now=time(NULL); + fputs(ctime(&now),ofp); + + return; +} + +# line 46 "wisetime.c" + +#ifdef _cplusplus +} +#endif diff --git a/Bio/Ext/Align/libs/wisetime.h b/Bio/Ext/Align/libs/wisetime.h new file mode 100644 index 0000000..2841465 --- /dev/null +++ b/Bio/Ext/Align/libs/wisetime.h @@ -0,0 +1,57 @@ +#ifndef DYNAMITEwisetimeHEADERFILE +#define DYNAMITEwisetimeHEADERFILE +#ifdef _cplusplus +extern "C" { +#endif +#include "wisebase.h" +#include + + + /***************************************************/ + /* Callable functions */ + /* These are the functions you are expected to use */ + /***************************************************/ + + + +/* Function: now_string(void) + * + * Descrip: returns a buffer + * of the current date and time + * + * + * + * Return [UNKN ] Undocumented return value [char *] + * + */ +char * bp_sw_now_string(void); +#define now_string bp_sw_now_string + + +/* Function: time_stamp(ofp) + * + * Descrip: puts now_string into file, with + * no newline + * + * + * Arg: ofp [UNKN ] Undocumented argument [FILE *] + * + */ +void bp_sw_time_stamp(FILE * ofp); +#define time_stamp bp_sw_time_stamp + + + /* Unplaced functions */ + /* There has been no indication of the use of these functions */ + + + /***************************************************/ + /* Internal functions */ + /* you are not expected to have to call these */ + /***************************************************/ + +#ifdef _cplusplus +} +#endif + +#endif diff --git a/Bio/Ext/Align/test.pl b/Bio/Ext/Align/test.pl new file mode 100755 index 0000000..4eb36fb --- /dev/null +++ b/Bio/Ext/Align/test.pl @@ -0,0 +1,37 @@ +#!/usr/local/bin/perl + +## Test framework for pSW XS stuff +## $Id$ + +## We start with some black magic to print on failure. +BEGIN { $| = 1; print "1..2\n"; } +END {print "not ok 1\n" unless $loaded;} + +use Bio::Ext::Align; + +$loaded = 1; +print "ok 1\n"; # 1st test passes. + +print "\n2..2\nTesting bp_sw with a protein alignment...\n\n"; + +&Bio::Ext::Align::change_max_BaseMatrix_kbytes(20000); +$cm = &Bio::Ext::Align::CompMat::read_Blast_file_CompMat("blosum62.bla"); +$seq1 = &Bio::Ext::Align::new_Sequence_from_strings("one","WLGQRNLVSSTGGNLLNVWLKDW"); +$seq2 = &Bio::Ext::Align::new_Sequence_from_strings("two","WMGNRNVVNLLNVWFRDW"); + +$alb = &Bio::Ext::Align::Align_Sequences_ProteinSmithWaterman($seq1,$seq2,$cm,-12,-2); + +&Bio::Ext::Align::write_pretty_str_align($alb,$seq1->name,$seq1->seq,$seq2->name,$seq2->seq,15,50,STDERR); + +print "ok 2\n"; # Assume 2nd test worked. + +## End of black magic. +## +## Insert additional test code below but remember to change +## the print "1..x\n" in the BEGIN block to reflect the +## total number of tests that will be run. + + + + + diff --git a/Bio/Ext/Align/typemap b/Bio/Ext/Align/typemap new file mode 100644 index 0000000..658c42a --- /dev/null +++ b/Bio/Ext/Align/typemap @@ -0,0 +1,351 @@ +TYPEMAP +void T_IV +boolean T_IV +aa T_IV +codon T_IV +base T_IV +Score T_IV +float T_DOUBLE +Probability T_DOUBLE +Bits T_DOUBLE + +TYPEMAP +bp_sw_AlnBlock * T_bp_sw_AlnBlock + +INPUT +T_bp_sw_AlnBlock + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_AlnBlock + sv_setref_pv($arg, "Bio::Ext::Align::AlnBlock", (void*) $var); + +TYPEMAP +bp_sw_AlnColumn * T_bp_sw_AlnColumn + +INPUT +T_bp_sw_AlnColumn + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_AlnColumn + sv_setref_pv($arg, "Bio::Ext::Align::AlnColumn", (void*) $var); + +TYPEMAP +bp_sw_AlnUnit * T_bp_sw_AlnUnit + +INPUT +T_bp_sw_AlnUnit + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_AlnUnit + sv_setref_pv($arg, "Bio::Ext::Align::AlnUnit", (void*) $var); + +TYPEMAP +bp_sw_AlnSequence * T_bp_sw_AlnSequence + +INPUT +T_bp_sw_AlnSequence + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_AlnSequence + sv_setref_pv($arg, "Bio::Ext::Align::AlnSequence", (void*) $var); + +TYPEMAP +bp_sw_AlnRangeSet * T_bp_sw_AlnRangeSet + +INPUT +T_bp_sw_AlnRangeSet + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_AlnRangeSet + sv_setref_pv($arg, "Bio::Ext::Align::AlnRangeSet", (void*) $var); + +TYPEMAP +bp_sw_AlnRange * T_bp_sw_AlnRange + +INPUT +T_bp_sw_AlnRange + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_AlnRange + sv_setref_pv($arg, "Bio::Ext::Align::AlnRange", (void*) $var); + +TYPEMAP +bp_sw_cDNA * T_bp_sw_cDNA + +INPUT +T_bp_sw_cDNA + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_cDNA + sv_setref_pv($arg, "Bio::Ext::Align::cDNA", (void*) $var); + +TYPEMAP +bp_sw_cDNADB * T_bp_sw_cDNADB + +INPUT +T_bp_sw_cDNADB + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_cDNADB + sv_setref_pv($arg, "Bio::Ext::Align::cDNADB", (void*) $var); + +TYPEMAP +bp_sw_CodonTable * T_bp_sw_CodonTable + +INPUT +T_bp_sw_CodonTable + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_CodonTable + sv_setref_pv($arg, "Bio::Ext::Align::CodonTable", (void*) $var); + +TYPEMAP +bp_sw_CodonMapper * T_bp_sw_CodonMapper + +INPUT +T_bp_sw_CodonMapper + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_CodonMapper + sv_setref_pv($arg, "Bio::Ext::Align::CodonMapper", (void*) $var); + +TYPEMAP +bp_sw_ComplexSequence * T_bp_sw_ComplexSequence + +INPUT +T_bp_sw_ComplexSequence + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_ComplexSequence + sv_setref_pv($arg, "Bio::Ext::Align::ComplexSequence", (void*) $var); + +TYPEMAP +bp_sw_ComplexSequenceEvalSet * T_bp_sw_ComplexSequenceEvalSet + +INPUT +T_bp_sw_ComplexSequenceEvalSet + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_ComplexSequenceEvalSet + sv_setref_pv($arg, "Bio::Ext::Align::ComplexSequenceEvalSet", (void*) $var); + +TYPEMAP +bp_sw_CompMat * T_bp_sw_CompMat + +INPUT +T_bp_sw_CompMat + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_CompMat + sv_setref_pv($arg, "Bio::Ext::Align::CompMat", (void*) $var); + +TYPEMAP +bp_sw_Gene * T_bp_sw_Gene + +INPUT +T_bp_sw_Gene + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_Gene + sv_setref_pv($arg, "Bio::Ext::Align::Gene", (void*) $var); + +TYPEMAP +bp_sw_Genomic * T_bp_sw_Genomic + +INPUT +T_bp_sw_Genomic + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_Genomic + sv_setref_pv($arg, "Bio::Ext::Align::Genomic", (void*) $var); + +TYPEMAP +bp_sw_GenomicDB * T_bp_sw_GenomicDB + +INPUT +T_bp_sw_GenomicDB + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_GenomicDB + sv_setref_pv($arg, "Bio::Ext::Align::GenomicDB", (void*) $var); + +TYPEMAP +bp_sw_GenomicRegion * T_bp_sw_GenomicRegion + +INPUT +T_bp_sw_GenomicRegion + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_GenomicRegion + sv_setref_pv($arg, "Bio::Ext::Align::GenomicRegion", (void*) $var); + +TYPEMAP +bp_sw_Histogram * T_bp_sw_Histogram + +INPUT +T_bp_sw_Histogram + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_Histogram + sv_setref_pv($arg, "Bio::Ext::Align::Histogram", (void*) $var); + +TYPEMAP +bp_sw_Hscore * T_bp_sw_Hscore + +INPUT +T_bp_sw_Hscore + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_Hscore + sv_setref_pv($arg, "Bio::Ext::Align::Hscore", (void*) $var); + +TYPEMAP +bp_sw_DataScore * T_bp_sw_DataScore + +INPUT +T_bp_sw_DataScore + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_DataScore + sv_setref_pv($arg, "Bio::Ext::Align::DataScore", (void*) $var); + +TYPEMAP +bp_sw_DataEntry * T_bp_sw_DataEntry + +INPUT +T_bp_sw_DataEntry + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_DataEntry + sv_setref_pv($arg, "Bio::Ext::Align::DataEntry", (void*) $var); + +TYPEMAP +bp_sw_PackAln * T_bp_sw_PackAln + +INPUT +T_bp_sw_PackAln + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_PackAln + sv_setref_pv($arg, "Bio::Ext::Align::PackAln", (void*) $var); + +TYPEMAP +bp_sw_PackAlnUnit * T_bp_sw_PackAlnUnit + +INPUT +T_bp_sw_PackAlnUnit + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_PackAlnUnit + sv_setref_pv($arg, "Bio::Ext::Align::PackAlnUnit", (void*) $var); + +TYPEMAP +bp_sw_Protein * T_bp_sw_Protein + +INPUT +T_bp_sw_Protein + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_Protein + sv_setref_pv($arg, "Bio::Ext::Align::Protein", (void*) $var); + +TYPEMAP +bp_sw_ProteinDB * T_bp_sw_ProteinDB + +INPUT +T_bp_sw_ProteinDB + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_ProteinDB + sv_setref_pv($arg, "Bio::Ext::Align::ProteinDB", (void*) $var); + +TYPEMAP +bp_sw_Sequence * T_bp_sw_Sequence + +INPUT +T_bp_sw_Sequence + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_Sequence + sv_setref_pv($arg, "Bio::Ext::Align::Sequence", (void*) $var); + +TYPEMAP +bp_sw_SequenceDB * T_bp_sw_SequenceDB + +INPUT +T_bp_sw_SequenceDB + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_SequenceDB + sv_setref_pv($arg, "Bio::Ext::Align::SequenceDB", (void*) $var); + +TYPEMAP +bp_sw_FileSource * T_bp_sw_FileSource + +INPUT +T_bp_sw_FileSource + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_FileSource + sv_setref_pv($arg, "Bio::Ext::Align::FileSource", (void*) $var); + +TYPEMAP +bp_sw_Exon * T_bp_sw_Exon + +INPUT +T_bp_sw_Exon + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_Exon + sv_setref_pv($arg, "Bio::Ext::Align::Exon", (void*) $var); + +TYPEMAP +bp_sw_Transcript * T_bp_sw_Transcript + +INPUT +T_bp_sw_Transcript + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_Transcript + sv_setref_pv($arg, "Bio::Ext::Align::Transcript", (void*) $var); + +TYPEMAP +bp_sw_Translation * T_bp_sw_Translation + +INPUT +T_bp_sw_Translation + $var = ($type) (SvROK($arg) == 0 ? ($type) NULL : ($type) SvIV((SV*)SvRV($arg))) + +OUTPUT +T_bp_sw_Translation + sv_setref_pv($arg, "Bio::Ext::Align::Translation", (void*) $var); diff --git a/README b/README new file mode 100644 index 0000000..7d8a3de --- /dev/null +++ b/README @@ -0,0 +1,24 @@ + + This is the directory for the Bioperl C compiled Extensions. +The main author for this is Ewan Birney + + To install... + + cd into Bio/Ext/Align + go perl Makefile.PL + make + make test (should print out alignment on STDERR) + make install (probably need root permissions). + + +Although these extensions can be called by themselves, they +really need the main bioperl distribution to drive them. The +modules which do this are + + Bio::Tools::pSW - makes smith waterman alignments + Bio::SearchDist - deals with EVD fitting of extreme value distributions + +For more information on how to use these modules, read their own documentation +(go perldoc Bio::Tools::pSW ...) + +