├── AUTHORS ├── NEWS ├── ChangeLog ├── tags.sh ├── manual.pdf ├── seqgen ├── model.c ├── aamodels.c ├── gamma.h ├── Makefile.am ├── eigen.h ├── twister.h ├── progress.h ├── tree.h ├── model.h ├── treefile.h ├── global.h ├── nucmodels.h ├── aamodels.h ├── evolve.h ├── progress.c ├── global.c └── twister.c ├── color-legend.pdf ├── autogen.sh ├── src ├── treeML.h ├── weight.h ├── postscript.h ├── formatMatrix.pl ├── Makefile.am ├── extreme_fit.h ├── code.h ├── treeSimulate.h ├── rnaz_utils.h ├── RNAcode.h ├── cmdline.ggo ├── misc.h ├── EBLOSUM62 ├── EBLOSUM90 ├── utils.h ├── weight.c ├── score.h ├── getopt.h ├── treeML.c └── treeSimulate.c ├── examples ├── Makefile.am ├── noncoding.maf ├── coding.maf ├── noncoding.aln └── coding.aln ├── .github └── workflows │ ├── pull_request.yaml │ ├── release.yaml │ ├── dist_check.yaml │ └── dist_archives.yaml ├── Makefile.am ├── levmar ├── Makefile.am ├── CMakeLists.txt ├── misc.c ├── Axb.c ├── lmlec.c ├── lm.c ├── lmbc.c ├── README.txt ├── misc.h └── lm.h ├── upload.sh ├── .gitignore ├── librna ├── aln_util.h ├── Makefile.am ├── energy_const.h ├── fold.h ├── alifold.h ├── PS_dot.h ├── fold_vars.h ├── fold_vars.c ├── params.h ├── utils.h ├── energy_par.h ├── pair_mat.h ├── aln_util.c └── alicircfold.inc ├── phyml ├── Makefile.am ├── cl.h ├── options.h ├── rates.h ├── interface.h ├── alrt.h ├── draw.h ├── simu.h ├── pars.h ├── bionj.h ├── eigen.h ├── m4.h ├── mc.h ├── free.h ├── spr.h ├── models.h ├── lk.h ├── mg.h ├── rates.c └── optimiz.h ├── configure.ac ├── index.html ├── docs └── manual.tex └── README /AUTHORS: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tags.sh: -------------------------------------------------------------------------------- 1 | etags src/*[ch] phyml/*.[ch] seqgen/*.[ch] levmar/*.[ch] 2 | -------------------------------------------------------------------------------- /manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ViennaRNA/RNAcode/HEAD/manual.pdf -------------------------------------------------------------------------------- /seqgen/model.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ViennaRNA/RNAcode/HEAD/seqgen/model.c -------------------------------------------------------------------------------- /color-legend.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ViennaRNA/RNAcode/HEAD/color-legend.pdf -------------------------------------------------------------------------------- /seqgen/aamodels.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ViennaRNA/RNAcode/HEAD/seqgen/aamodels.c -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | # Inits project from configure.ac 2 | aclocal 3 | autoheader 4 | automake -a 5 | autoconf 6 | -------------------------------------------------------------------------------- /src/treeML.h: -------------------------------------------------------------------------------- 1 | #define PHYML 2 | 3 | int treeML(const struct aln *alignment[], char** treeString, float* kappa); 4 | 5 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = coding.aln coding.maf genomic.maf genomic-preprocessed.maf noncoding.aln noncoding.maf 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/weight.h: -------------------------------------------------------------------------------- 1 | #ifndef _WEIGHT_H_ 2 | #define _WEIGHT_H_ 3 | 4 | int linsys(float **a, float *b, int N ); 5 | double *weights(float **D, int N); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /.github/workflows/pull_request.yaml: -------------------------------------------------------------------------------- 1 | name: Process Pull Request 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | run-distcheck: 7 | uses: ./.github/workflows/dist_check.yaml 8 | 9 | 10 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS=phyml levmar seqgen librna src examples 2 | 3 | docu_DATA = INSTALL README AUTHORS COPYING 4 | 5 | EXTRA_DIST = INSTALL README AUTHORS COPYING manual.pdf color-legend.pdf 6 | 7 | docudir = $(pkgdatadir) 8 | -------------------------------------------------------------------------------- /levmar/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = liblevmar.a 2 | 3 | liblevmar_a_SOURCES = Axb.c lmbc.c lm.c lmlec.c misc.c lm.h misc.h 4 | 5 | noinst_HEADERS = lm.h misc.h Axb_core.c lmbc_core.c lmlec_core.c misc_core.c lm_core.c 6 | -------------------------------------------------------------------------------- /upload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | make dist 4 | scp -P 2001 RNAcode-0.1.tar.gz washietl@localhost:~/programs/ 5 | rsh -p 2001 washietl@localhost /homes/washietl/programs/compileRNAcode.sh 6 | rsh -p 2001 washietl@localhost RNAcode -V 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .RData 2 | aclocal.m4 3 | autom4te.cache 4 | config.h 5 | config.h.in 6 | config.log 7 | config.status 8 | configure 9 | depcomp 10 | install-sh 11 | missing 12 | src/*ps 13 | src/scratch.c 14 | src/RNAcode 15 | stamp-h1 16 | RNAcode*.tar.gz 17 | -------------------------------------------------------------------------------- /librna/aln_util.h: -------------------------------------------------------------------------------- 1 | #ifndef ALN_UTIL_H 2 | #define ALN_UTIL_H 3 | 4 | extern int read_clustal(FILE *clust, char *AlignedSeqs[], char *names[]); 5 | extern /*@only@*/ /*@notnull@*/ char *consensus(const char *AS[]); 6 | extern /*@only@*/ /*@notnull@*/ char *consens_mis(const char *AS[]); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /librna/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libRNA.a 2 | 3 | libRNA_a_SOURCES = fold_vars.c read_epars.c \ 4 | energy_par.c utils.c fold.c params.c alifold.c PS_dot.c aln_util.c naview.c 5 | 6 | noinst_HEADERS =alifold.h energy_const.h fold.h\ 7 | intloops.h params.h utils.h energy_par.h fold_vars.h\ 8 | pair_mat.h PS_dot.h aln_util.h circfold.inc alicircfold.inc 9 | 10 | -------------------------------------------------------------------------------- /src/postscript.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSTSCRIPT_H_ 2 | #define _POSTSCRIPT_H_ 3 | 4 | #include "rnaz_utils.h" 5 | #include "code.h" 6 | 7 | int colorAln(const char *filename, const struct aln *alignment[],segmentStats region); 8 | 9 | void colorHSS(const char *filename, const struct aln *alignment[], backtrackData *bt, const char* label, int b, int i); 10 | 11 | void setParameters(); 12 | 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /phyml/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libPHYML.a 2 | 3 | libPHYML_a_SOURCES = alrt.c bionj.c cl.c draw.c eigen.c free.c interface.c lk.c m4.c main.c mc.c models.c optimiz.c options.c pars.c rates.c simu.c spr.c utilities.c 4 | 5 | noinst_HEADERS = alrt.h bionj.h cl.h draw.h eigen.h free.h interface.h lk.h m4.h mc.h models.h optimiz.h options.h pars.h rates.h simu.h spr.h utilities.h mg.h 6 | -------------------------------------------------------------------------------- /src/formatMatrix.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | my $name='BLOSUM62'; 4 | 5 | print "int BLOSUM62[24][24]={"; 6 | 7 | while (<>){ 8 | 9 | next if /^#/; 10 | next if /^\s+A\s+R/; 11 | 12 | my @entries=split; 13 | 14 | shift @entries; 15 | 16 | foreach my $i (0..$#entries){ 17 | $entries[$i]=" ".$entries[$i] if not $entries[$i]=~/-/; 18 | } 19 | 20 | 21 | print "{",join(',',@entries),"},\n"; 22 | 23 | 24 | } 25 | 26 | 27 | print "};\n"; 28 | -------------------------------------------------------------------------------- /librna/energy_const.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | energy constants, formerly defined in 4 | energy_par.h 5 | 6 | customized for use with RNAedit by 7 | S.Kopp, IMB-Jena, Germany, Mar 1996 8 | 9 | */ 10 | 11 | #ifndef _ENERGY_CONST_H 12 | #define _ENERGY_CONST_H 1 13 | 14 | #define GASCONST 1.98717 /* in [cal/K] */ 15 | #define K0 273.15 16 | #define INF 1000000 17 | #define FORBIDDEN 9999 18 | #define BONUS 10000 19 | #define NBPAIRS 7 20 | #define TURN 3 21 | #define MAXLOOP 30 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /phyml/cl.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PHYML : a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #include "utilities.h" 14 | 15 | #ifndef CL_H 16 | #define CL_H 17 | 18 | void Read_Command_Line(option *input, int argc, char **argv); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /levmar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # LEVMAR cmake file (http://www.cmake.org) 2 | 3 | #CMAKE_MINIMUM_REQUIRED(VERSION 1.4) 4 | 5 | PROJECT(LEVMAR) 6 | 7 | # ROOTDIR should be set to the directory of your compiler lapack libs 8 | IF (WIN32) 9 | SET(ROOTDIR C:/local/lib) 10 | ELSE (WIN32) 11 | SET(ROOTDIR /usr/local/lib) 12 | ENDIF (WIN32) 13 | 14 | ADD_EXECUTABLE(lmdemo lmdemo_sources) 15 | 16 | SOURCE_FILES(lmdemo_sources 17 | lm.c Axb.c lmdemo.c lm.h 18 | ) 19 | 20 | #INCLUDE_DIRECTORIES(${ROOTDIR}/../include) 21 | 22 | LINK_DIRECTORIES(${ROOTDIR}) 23 | 24 | TARGET_LINK_LIBRARIES(lmdemo clapack.lib blas.lib) 25 | -------------------------------------------------------------------------------- /phyml/options.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PhyML: a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences. 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward. 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #ifndef OPTIONS_H 14 | #define OPTIONS_H 15 | 16 | void Usage(); 17 | option *Get_Input(int argc, char **argv); 18 | void Init_Optimiz(optimiz *s_opt); 19 | void Get_Input_Interactive(option *input); 20 | void Set_Defaults(option* input); 21 | #endif 22 | -------------------------------------------------------------------------------- /librna/fold.h: -------------------------------------------------------------------------------- 1 | /* function from fold.c */ 2 | extern float fold(const char *sequence, char *structure); 3 | /* calculate mfe-structure of sequence */ 4 | extern float energy_of_struct(const char *string, const char *structure); 5 | /* calculate energy of string on structure */ 6 | extern void free_arrays(void); /* free arrays for mfe folding */ 7 | extern void initialize_fold(int length); /* allocate arrays for folding */ 8 | extern void update_fold_params(void); /* recalculate parameters */ 9 | extern char *backtrack_fold_from_pair(char *sequence, int i, int j); 10 | extern float energy_of_circ_struct(const char *string, const char *structure); 11 | -------------------------------------------------------------------------------- /librna/alifold.h: -------------------------------------------------------------------------------- 1 | extern float alifold(char **strings, char *structure); 2 | extern void free_alifold_arrays(void); 3 | extern void update_alifold_params(void); 4 | extern double cv_fact /* =1 */; 5 | extern double nc_fact /* =1 */; 6 | typedef struct { 7 | short i; /* i,j in [0, n-1] */ 8 | short j; 9 | float p; /* probability */ 10 | float ent; /* pseudo entropy for p(i,j) = S_i + S_j - p_ij*ln(p_ij) */ 11 | short bp[8]; /* frequencies of pair_types */ 12 | char comp; /* 1 iff pair is in mfe structure */ 13 | } pair_info; 14 | extern float alipf_fold(char **sequences, char *structure, pair_info **pi); 15 | extern float circalifold(const char **strings, char *structure); 16 | -------------------------------------------------------------------------------- /seqgen/gamma.h: -------------------------------------------------------------------------------- 1 | /* Header file for gamma.c */ 2 | 3 | /* 4 | Sequence Generator - seq-gen, version 1.3.2 5 | Andrew Rambaut & Nick Grassly 6 | Department of Zoology, University of Oxford 7 | 8 | The code in this file is taken from Ziheng Yang's PAML package. 9 | http://abacus.gene.ucl.ac.uk/ 10 | 11 | Any feedback is very welcome. 12 | http://evolve.zoo.ox.ac.uk/software/Seq-Gen/ 13 | email: andrew.rambaut@zoo.ox.ac.uk 14 | */ 15 | 16 | #ifndef _GAMMA_H_ 17 | #define _GAMMA_H_ 18 | 19 | double rndgamma (double s); 20 | int DiscreteGamma (double freqK[], double rK[], double alfa, double beta, int K, int median); 21 | 22 | #endif /* _GAMMA_H_ */ 23 | 24 | -------------------------------------------------------------------------------- /phyml/rates.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PhyML: a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences. 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward. 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #ifndef RATES_H 14 | #define RATES_H 15 | 16 | void RATES_Monte_Carlo_Mean_Rates(arbre *tree); 17 | void RATES_Monte_Carlo_Mean_Rates_Pre(node *a, node *d, edge *b, phydbl curr_rate, arbre *tree); 18 | void RATES_Print_Rates(arbre *tree); 19 | void RATES_Print_Rates_Pre(node *a, node *d, edge *b, arbre *tree); 20 | trate *RATES_Make_Rate_Struct(arbre *tree); 21 | void RATES_Init_Rate_Struct(trate *rates, arbre *tree); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /seqgen/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = \ 2 | libseqgen.a 3 | 4 | libseqgen_a_SOURCES = \ 5 | aamodels.c \ 6 | eigen.c \ 7 | evolve.c \ 8 | gamma.c \ 9 | global.c \ 10 | model.c \ 11 | nucmodels.c \ 12 | progress.c \ 13 | treefile.c \ 14 | twister.c 15 | 16 | noinst_HEADERS = \ 17 | aamodels.h \ 18 | eigen.h \ 19 | evolve.h \ 20 | gamma.h \ 21 | global.h \ 22 | model.h \ 23 | nucmodels.h \ 24 | progress.h \ 25 | treefile.h \ 26 | tree.h \ 27 | twister.h 28 | 29 | pkginclude_HEADERS = \ 30 | aamodels.h \ 31 | eigen.h \ 32 | evolve.h \ 33 | gamma.h \ 34 | global.h \ 35 | model.h \ 36 | nucmodels.h \ 37 | progress.h \ 38 | treefile.h \ 39 | tree.h \ 40 | twister.h 41 | -------------------------------------------------------------------------------- /phyml/interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PhyML: a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences. 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward. 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #ifndef INTERFACE_H 14 | #define INTERFACE_H 15 | 16 | void Launch_Interface(option *input); 17 | void Clear(); 18 | void Launch_Interface_Input(option *input); 19 | void Launch_Interface_Data_Type(option *input); 20 | void Launch_Interface_Model(option *input); 21 | void Launch_Interface_Topo_Search(option *input); 22 | void Launch_Interface_Branch_Support(option *input); 23 | void Launch_Interface_Multigene(option *input); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT(RNAcode, 0.3.1, rna@tbi.univie.ac.at, RNAcode) 2 | AM_INIT_AUTOMAKE 3 | 4 | AC_PROG_CC 5 | 6 | 7 | if test "$GCC" = yes; then 8 | AC_DEFINE(UNUSED, __attribute__ ((unused)), avoid warning about unused variables) 9 | else 10 | AC_DEFINE(UNUSED,, only for gcc) 11 | fi 12 | 13 | AC_SUBST(VERSION) 14 | ISODATE=`date +%Y-%m-%d` 15 | AC_SUBST(ISODATE) 16 | 17 | 18 | AC_HEADER_STDC 19 | AC_CHECK_HEADERS(malloc.h strings.h unistd.h) 20 | AC_C_CONST 21 | AC_TYPE_SIZE_T 22 | AC_INLINE 23 | 24 | AC_CHECK_FUNCS(strdup strstr strchr erand48) 25 | 26 | AC_PROG_CXX 27 | 28 | AC_PROG_RANLIB 29 | 30 | AC_PROG_INSTALL 31 | 32 | AC_CONFIG_HEADERS(config.h) 33 | 34 | AC_OUTPUT([Makefile phyml/Makefile levmar/Makefile seqgen/Makefile src/Makefile librna/Makefile examples/Makefile]) 35 | 36 | 37 | -------------------------------------------------------------------------------- /seqgen/eigen.h: -------------------------------------------------------------------------------- 1 | /* Header file for eigen.c */ 2 | 3 | /* 4 | Sequence Generator - seq-gen, version 1.3.2 5 | Andrew Rambaut & Nick Grassly 6 | Department of Zoology, University of Oxford 7 | 8 | The code in this file is taken from Ziheng Yang's PAML package. 9 | http://abacus.gene.ucl.ac.uk/ 10 | 11 | Any feedback is very welcome. 12 | http://evolve.zoo.ox.ac.uk/software/Seq-Gen/ 13 | email: andrew.rambaut@zoo.ox.ac.uk 14 | */ 15 | 16 | #ifndef _EIGEN_H_ 17 | #define _EIGEN_H_ 18 | 19 | int abyx (double a, double x[], int n); 20 | int xtoy (double x[], double y[], int n); 21 | int matinv( double x[], int n, int m, double space[]); 22 | int eigen(int job, double A[], int n, double rr[], double ri[], 23 | double vr[], double vi[], double w[]); 24 | 25 | #endif /* _EIGEN_H_ */ 26 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = \ 2 | -I${top_srcdir}/phyml \ 3 | -I${top_srcdir}/seqgen \ 4 | -I${top_srcdir}/levmar \ 5 | -I${top_srcdir}/librna 6 | 7 | bin_PROGRAMS = RNAcode 8 | 9 | RNAcode_SOURCES = \ 10 | RNAcode.c \ 11 | RNAcode.h \ 12 | rnaz_utils.h \ 13 | rnaz_utils.c \ 14 | utils.h \ 15 | utils.c \ 16 | cmdline.c \ 17 | cmdline.h \ 18 | treeSimulate.c \ 19 | treeSimulate.h \ 20 | treeML.h \ 21 | treeML.c \ 22 | code.c \ 23 | postscript.c \ 24 | code.h \ 25 | extreme_fit.c \ 26 | extreme_fit.h \ 27 | postscript.h \ 28 | score.c \ 29 | score.h \ 30 | misc.c \ 31 | misc.h 32 | 33 | LDADD = \ 34 | -L${top_builddir}/levmar -llevmar \ 35 | -L${top_builddir}/phyml -lPHYML \ 36 | -L${top_builddir}/seqgen -lseqgen \ 37 | -L${top_builddir}/librna -lRNA \ 38 | -lm 39 | -------------------------------------------------------------------------------- /src/extreme_fit.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2009, Stefan Washietl 2 | 3 | This file is part of RNAcode. 4 | 5 | RNAcode is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | RNAcode is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with RNAcode. If not, see . */ 17 | 18 | 19 | int EVDMaxLikelyFit(double *x, int *c, int n, double *ret_mu, double *ret_lambda); 20 | -------------------------------------------------------------------------------- /phyml/alrt.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PHYML : a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #ifndef ALRT_H 14 | #define ALRT_H 15 | 16 | void aLRT(arbre *tree); 17 | int Check_NNI_Five_Branches(arbre *tree); 18 | int Compute_Likelihood_Ratio_Test(edge *tested_edge, arbre *tree); 19 | int NNI_Neigh_BL(edge *b_fcus, arbre *tree); 20 | void Make_Target_Swap(arbre *tree, edge *b_fcus, int swaptodo); 21 | phydbl Statistics_To_Probabilities(phydbl in); 22 | phydbl Statistics_To_RELL(arbre *tree); 23 | phydbl Statistics_To_SH(arbre *tree); 24 | phydbl Update_Lk_At_Given_Edge_Excluding(edge *b_fcus, arbre *tree, node *exclude); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /phyml/draw.h: -------------------------------------------------------------------------------- 1 | #ifndef DRAW_H 2 | #define DRAW_H 3 | 4 | void DR_Dist_To_Root_Pre(node *a, node *d, edge *b, arbre *tree); 5 | void DR_Dist_To_Root(node *n_root, arbre *tree); 6 | void DR_Get_X_Coord_Pre(node *a, node *d, edge *b, tdraw *w, arbre *tree); 7 | void DR_Get_X_Coord(tdraw *w, arbre *tree); 8 | tdraw *DR_Make_Tdraw_Struct(arbre *tree); 9 | void DR_Init_Tdraw_Struct(tdraw *d); 10 | void DR_Get_Tree_Box_Width(tdraw *w, arbre *tree); 11 | void DR_Get_Y_Coord_Post(node *a, node *d, edge *b, int *next_y_slot, tdraw *w, arbre *tree); 12 | void DR_Get_Y_Coord(tdraw *w, arbre *tree); 13 | void DR_Get_Tree_Coord(arbre *tree); 14 | double DR_Get_Max_Dist_To_Root(arbre *tree); 15 | void DR_Print_Tree_Postscript(int tree_num, FILE *fp, arbre *tree); 16 | void DR_Print_Tree_Postscript_Pre(node *a, node *d, FILE *fp, tdraw *w, arbre *tree); 17 | void DR_Print_Postscript_EOF(FILE *fp); 18 | void DR_Print_Postscript_Header(int n_pages, FILE *fp); 19 | 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Version release 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*.*' 7 | 8 | jobs: 9 | run-distcheck: 10 | uses: ./.github/workflows/dist_check.yaml 11 | 12 | create-dist-archives: 13 | needs: run-distcheck 14 | uses: ./.github/workflows/dist_archives.yaml 15 | with: 16 | zip: true 17 | artifact-name: 'dist-archives' 18 | 19 | create-release: 20 | needs: [run-distcheck, create-dist-archives] 21 | runs-on: ubuntu-latest 22 | permissions: 23 | contents: write 24 | steps: 25 | - uses: actions/checkout@v4 26 | - name: Download source archives 27 | uses: actions/download-artifact@v4 28 | with: 29 | name: dist-archives 30 | - name: Make release 31 | uses: ncipollo/release-action@v1 32 | with: 33 | artifacts: "RNAcode-*.tar.gz,RNAcode-*.zip" 34 | name: "RNAcode ${{ needs.create-dist-archive.outputs.version_number }}" 35 | -------------------------------------------------------------------------------- /src/code.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2009, Stefan Washietl 2 | 3 | This file is part of RNAcode. 4 | 5 | RNAcode is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | RNAcode is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with RNAcode. If not, see . */ 17 | 18 | 19 | #ifndef _CODE_H_ 20 | #define _CODE_H_ 21 | 22 | int* encodeSeq(char* seq); 23 | 24 | int encodeAA(char aa); 25 | 26 | char decodeAA(int encodedAA); 27 | 28 | char* translateSeq(char* seq); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /.github/workflows/dist_check.yaml: -------------------------------------------------------------------------------- 1 | name: Run distcheck 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | config-flags: 7 | description: 'Configure flags to prepare the source directory' 8 | default: '' 9 | required: false 10 | type: string 11 | workflow_call: 12 | inputs: 13 | config-flags: 14 | description: 'Configure flags to prepare the source directory' 15 | default: '' 16 | required: false 17 | type: string 18 | 19 | jobs: 20 | check: 21 | runs-on: ubuntu-latest 22 | 23 | steps: 24 | - name: Checkout 25 | uses: actions/checkout@v4 26 | - name: Install prerequisites 27 | run: | 28 | sudo apt-get update 29 | sudo apt-get -y install \ 30 | build-essential \ 31 | autoconf \ 32 | automake \ 33 | gengetopt \ 34 | libtool 35 | - name: Autotools setup 36 | run: | 37 | autoreconf -i 38 | - name: Configure 39 | run: ./configure ${{ inputs.config-flags }} 40 | - name: distcheck 41 | run: make distcheck 42 | -------------------------------------------------------------------------------- /phyml/simu.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PHYML : a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #ifndef CURR_H 14 | #define CURR_H 15 | 16 | void Simu_Loop(arbre *tree); 17 | void Simu(arbre *tree,int n_step_max); 18 | void Select_Edges_To_Swap(arbre *tree,edge **sorted_b,int *n_neg); 19 | void Update_Bl(arbre *tree,phydbl fact); 20 | void Make_N_Swap(arbre *tree,edge **b,int beg,int end); 21 | int Make_Best_Swap(arbre *tree); 22 | int Mov_Backward_Topo_Bl(arbre *tree,phydbl lk_old,edge **tested_b,int n_tested); 23 | void Unswap_N_Branch(arbre *tree,edge **b,int beg,int end); 24 | void Swap_N_Branch(arbre *tree,edge **b,int beg,int end); 25 | void Check_NNI_Scores_Around(node *a, node *d, edge *b, phydbl *best_score); 26 | int Mov_Backward_Topo_Pars(arbre *tree, int pars_old, edge **tested_b, int n_tested); 27 | void Simu_Pars(arbre *tree, int n_step_max); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /phyml/pars.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PHYML : a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #ifndef PARS_H 14 | #define PARS_H 15 | 16 | void Make_Tree_4_Pars(arbre *tree, allseq *alldata, int n_site); 17 | int Pars(arbre *tree); 18 | void Post_Order_Pars(node *a, node *d, arbre *tree); 19 | void Pre_Order_Pars(node *a, node *d, arbre *tree); 20 | void Get_Partial_Pars(arbre *tree, edge *b_fcus, node *a, node *d); 21 | void Site_Pars(arbre *tree); 22 | void Init_Ui_Tips(arbre *tree); 23 | void Update_P_Pars(arbre *tree, edge *b_fcus, node *n); 24 | int Pars_At_Given_Edge(edge *b, arbre *tree); 25 | void Get_All_Partial_Pars(arbre *tree, edge *b_fcus, node *a, node *d); 26 | int Update_Pars_At_Given_Edge(edge *b_fcus, arbre *tree); 27 | void Init_P_Pars_Tips(arbre *tree); 28 | void Get_Step_Mat(arbre *tree); 29 | int Pars_Core(edge *b, arbre *tree); 30 | int One_Pars_Step(edge *b,arbre *tree); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/treeSimulate.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2009, Stefan Washietl 2 | 3 | This file is part of RNAcode. 4 | 5 | RNAcode is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | RNAcode is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with RNAcode. If not, see . */ 17 | 18 | #include "tree.h" 19 | #include "rnaz_utils.h" 20 | 21 | TNode* getLCA(TTree* tree, TNode* nodeA, TNode* nodeB); 22 | void tree2aln(TTree* tree, struct aln *alignment[]); 23 | TTree* string2tree(char* treeString); 24 | 25 | void simulateTree(TTree* tree, float freqs[], float kap, int L); 26 | 27 | float** getDistanceMatrix(TTree* tree, struct aln *alignment[]); 28 | 29 | void freeSeqgenTree(TTree* tree); 30 | -------------------------------------------------------------------------------- /examples/noncoding.maf: -------------------------------------------------------------------------------- 1 | a score=0 2 | s ec_K12.chr 146715 122 + 0 TC---GTTAA------CGAAGCAGG----CGAT----GCCTGCTTTGAGGAAATTCTCACGCAGTATTGCCCGATTTTTGTTTAGTGTCTACTCATCTGACGGCATTTGCGTCA----GCAGTTTGCGTACCGCGCCGAAGCG 3 | s ec_O157H7.chr 151087 122 + 0 TC---GTTAA------CGAAGCAGG----CGGT----GCCTGCTTTGAGGAAATTCTCACGCAGTATTGCCCGATTTTTGTTTAGTGTCTACTCATCTGACGGCATTTGCATCA----GCAGTTTGCGTACCGCGCCGAAGCG 4 | s ec_APEC_O1.chr 152722 122 + 0 TC---GTTAA------CGAAGCAGG----CGAT----GCCTGCTTTGAGGAAATTCTCACGCAGTATTGCCCGATTTTTGTTGAGTGTCTACTCATCTGACGGCATTTGCAGCA----GCAGTTTGCGTACCGTGCCGAAGCG 5 | s ente638.chr 771945 127 + 0 TCAAGGCCGA------GAGGGCAGGGTGAAGGG----ATATTTCCCAGGCAAATATCGGCGCAGTATTGCCCGATTTTTAGTCGGTGTCTACTC------CGCCAGCTCAACCACTTTATTGTCTATGAGGCGTGCCTGGCCG 6 | s shigFlex_2A.chr 144806 122 + 0 TC---GTTAA------CGAAGCAGG----CGGT----GCCTGCTTTGAGGAAATTCTCACGCAGTATTGCCCGATTTTTGATGAGTGTCTACTCATCTGATGGCATTTGCGTCA----GCAGTTTGCGTACCGCGCCGAAGCG 7 | s salmTyph.chr 208300 120 + 0 TC---GTTTATCTTGGCTAAGCAGG----CGCTTGTAGCCTGCTTT--GGAAATTCTCAGGCAGTATTGCCCGATTTTTAACCCCTGTCTACTGGGCTAATG----------TA----ACGCTTTGATTATCGATCAGACGCG 8 | s salmEnte_PARATYPI_ATC.chr 215652 120 + 0 TC---GTTTACCTTGGCTAAGCAGG----CGCTTGTGGCCTGCTTT--GGAAATTCTCAGGCAGTATTGCCCGATTTTTAACCCCTGTCTACTGGGCTAATG----------TA----ACGCTTTGATTATCGATCAGACGCG 9 | 10 | -------------------------------------------------------------------------------- /phyml/bionj.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PhyML: a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences. 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward. 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #ifndef NJ_H 14 | #define NJ_H 15 | 16 | #include "utilities.h" 17 | #include "optimiz.h" 18 | /*#include "tools.h"*/ 19 | 20 | void Bionj(matrix *mat); 21 | void Finish(matrix *mat); 22 | void Compute_Sx(matrix *mat); 23 | phydbl Sum_S(matrix *mat, int i); 24 | phydbl Dist(matrix *mat, int x, int y); 25 | phydbl Q_Agglo(matrix *mat, int x, int y); 26 | phydbl Variance(matrix *mat, int x, int y); 27 | phydbl Br_Length(matrix *mat, int x, int y); 28 | void Update_Dist(matrix *mat, int x, int y); 29 | phydbl Lamda(matrix *mat, int x, int y, phydbl vxy); 30 | void Best_Pair(matrix *mat, int *x, int *y, phydbl *score); 31 | phydbl Var_Red(matrix *mat, int x, int y, int i, phydbl lamda, phydbl vxy); 32 | void Update_Tree(matrix *mat, int x, int y, phydbl lx, phydbl ly, phydbl score); 33 | void Update_Mat(matrix *mat, int x, int y, 34 | phydbl lx, phydbl ly, phydbl vxy, phydbl lamda); 35 | phydbl Dist_Red(matrix *mat, int x, phydbl lx, int y, 36 | phydbl ly, int i, phydbl lamda); 37 | int Bionj_Br_Length_Post(node *a, node *d, matrix *mat); 38 | void Bionj_Br_Length(matrix *mat); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /phyml/eigen.h: -------------------------------------------------------------------------------- 1 | #ifndef EIGEN_H 2 | #define EIGEN_H 3 | 4 | int Eigen(int job, double *A, int n, double *rr, double *ri, 5 | double *vr, double *vi, double *w); 6 | 7 | /* wash. renamed balance to bbalance due to name clash with SISSI */ 8 | void bbalance(double *mat, int n, int *low, int *hi, double *scale); 9 | void unbalance(int n, double *vr, double *vi, int low, int hi, 10 | double *scale); 11 | int realeig(int job, double *mat, int n,int low, int hi, double *valr, 12 | double *vali, double *vr, double *vi); 13 | void elemhess(int job, double *mat, int n, int low, int hi, 14 | double *vr, double *vi, int *work); 15 | 16 | int ludcmp(double **a, int n, double *d); 17 | void det(double **a, int n, double *d); 18 | 19 | /* complex functions */ 20 | 21 | typedef struct { double re, im; } complex; 22 | #define csize(a) (fabs(a.re)+fabs(a.im)) 23 | 24 | complex compl (double re,double im); 25 | complex _conj (complex a); 26 | complex cplus (complex a, complex b); 27 | complex cminus (complex a, complex b); 28 | complex cby (complex a, complex b); 29 | complex cdiv (complex a,complex b); 30 | /* complex local_cexp (complex a); */ 31 | complex cfactor (complex x, double a); 32 | int cxtoy (complex *x, complex *y, int n); 33 | int cmatby (complex *a, complex *b, complex *c, int n,int m,int k); 34 | int cmatout (FILE * fout, complex *x, int n, int m); 35 | int cmatinv( complex *x, int n, int m, double *space); 36 | 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /examples/coding.maf: -------------------------------------------------------------------------------- 1 | a score=0 2 | s ec_K12.chr 3401506 198 + 0 TGCAGGCGTTACTTTTAGAACAGCAGGACGGCAAAACTCTCGCATCAGTACA--GACTCTGGACGAAAGTCGCCTGCCGGAGGGCGATGTCACGGTCGATGTTCACTGGTCGAGCCTGAACTATAAAGATGCGCTGG 3 | s ec_O157H7.chr 4138444 198 + 0 TGCAGGCGTTACTTTTAGAACAGCAGGACGGCAAAACTCTCGCATCAGTACA--GACTCTGGACGAAAGTCGCCTGCCGGAGGGCGATGTCACGGTCGATGTTCACTGGTCGAGCCTGAACTATAAAGATGCGCTGG 4 | s ec_APEC_O1.chr 3685781 198 + 0 TGCAGGCGTTACTTTTAGAACAGCAGGACGGCAAAACTCTCGCATCAGTACA--GACTCTGGACGAAAGTCGCCAGCCGGAAGGCGATGTCACGGTTGATGTTCACTGGTCGAGCCTGAACTACAAAGATGCGCTGG 5 | s ente638.chr 4000173 198 + 0 TGCAGGCATTGATCTTAGAACAACAAGACGGCAAAACCCTGGCTTCGGTTCA--ATCCATCGAGGCTACCCGCCTGCCCGAAGGCGACGTCACCGTTGACATTGACTGGTCCAGCCTGAATTACAAGGACGCGCTCG 6 | s shigFlex_2A.chr 3391056 198 + 0 TGCAGGCGTTACTTTTAGAACAGCAGGACGGCAAAACTCTCGCATCAGTACA--GACTCTGGACGAACGTCGCCTGCCGGAGGGCGATGTCACGGTCGATGTTCACTGGTCGAGCCTGAACTATAAAGATGCGCTGG 7 | s salmTyph.chr 3400613 198 + 0 TGCAGGCGTTGATCTTAGAACAGCAGGACGGTAAAACCCTCGCATCCGTGCA--ACATCTCGAAGAGAGTCAACTGCCGGCAGGTGATGTGACGGTGGATGTCCACTGGTCCAGCCTGAATTATAAAGATGCTCTGG 8 | s salmEnte_PARATYPI_ATC.chr 3353535 198 + 0 TGCAGGCGTTGATCTTAGAACAGCAGGACGGTAAAACCCTCGCATCCGTGCA--ACATCTCGAAGAGAGTCAACTGCCGGCAGGTGATGTGACGGTGGATGTCCACTGGTCCAGCCTGAATTATAAAGATGCTCTGG 9 | s yersPest_CO92.chr 569086 198 - 0 TGCGAGCACTGATACTTGAGCAAATTGAAGGGCGTACCACCGCAGAAGTACGTCAAATTTCGGCCTCA--CAACTGCCTGCGGGTAATGTCACCGTAGATGTCAATTGGTCCAGCCTGAATTATAAAGATGCGTTGG 10 | 11 | -------------------------------------------------------------------------------- /src/rnaz_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _RNAZ_UTILS_H_ 2 | #define _RNAZ_UTILS_H_ 3 | 4 | 5 | 6 | #define PRIVATE static 7 | #define MAX_NUM_NAMES 500 8 | #define MIN2(A, B) ((A) < (B) ? (A) : (B)) 9 | 10 | enum alnFormat {UNKNOWN=0, CLUSTAL=1, MAF=2}; 11 | 12 | struct aln { 13 | char *name; 14 | char *seq; 15 | char *fullSeq; /* Remembers full sequence when gaps are stripped in seq*/ 16 | int start; 17 | int length; 18 | int fullLength; 19 | char strand; 20 | }; 21 | 22 | 23 | int read_clustal(FILE *clust, struct aln *alignedSeqs[]); 24 | int read_maf(FILE *clust, struct aln *alignedSeqs[]); 25 | 26 | 27 | char *consensus(const struct aln *AS[]); 28 | 29 | double meanPairID(const struct aln *AS[]); 30 | 31 | void revAln(struct aln *AS[]); 32 | 33 | double combPerPair(struct aln *AS[],char* structure); 34 | 35 | int encodeBase(char base); 36 | 37 | void sliceAln(const struct aln *sourceAln[], struct aln *destAln[], 38 | int from, int to); 39 | 40 | void freeAln(struct aln *AS[]); 41 | 42 | 43 | struct aln* createAlnEntry(char* name, char* seq, int start, int length, int fullLength, char strand); 44 | void freeAlnEntry(struct aln* entry); 45 | void printAln(const struct aln* AS[]); 46 | 47 | int checkFormat(FILE *file); 48 | 49 | char** splitFields(char* string); 50 | void freeFields(char** fields); 51 | 52 | char** splitLines(char* string); 53 | 54 | void printAlnMAF(FILE *out, const struct aln* AS[],int printU); 55 | 56 | void pruneAln(char *species, struct aln* AS[]); 57 | 58 | char** splitString(char* string, char* separators); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /librna/PS_dot.h: -------------------------------------------------------------------------------- 1 | /* routines from PS_dot.c */ 2 | extern int PS_rna_plot(char *string, char *structure, char *file); 3 | /* write PostScript drawing of structure to file */ 4 | extern int PS_rna_plot_a(char *string, char *structure, char *file, char *pre, char *post); 5 | /* write PostScript drawing of structure to file with annotation */ 6 | extern int gmlRNA(char *string, char *structure, char *ssfile, char option); 7 | /* structure drawing in gml */ 8 | extern int ssv_rna_plot(char *string, char *structure, char *ssfile); 9 | /*write coord file for SStructView */ 10 | extern int svg_rna_plot(char *string, char *structure, char *ssfile); 11 | /*write RNAplot in SVG */ 12 | extern int xrna_plot(char *string, char *structure, char *ssfile); 13 | /*write .ss file for further editing in XRNA */ 14 | extern int PS_dot_plot(char *string, char *file); 15 | /* produce a PostScript dot plot of the pair probability matix */ 16 | extern int rna_plot_type; /* 0= simple coordinates, 1= naview */ 17 | 18 | typedef struct cpair { 19 | int i,j,mfe; 20 | float p, hue, sat; 21 | } cpair; 22 | extern int PS_color_dot_plot(char *string, cpair *pi, char *filename); 23 | 24 | typedef struct plist { 25 | int i; 26 | int j; 27 | float p; 28 | }plist; 29 | extern int PS_dot_plot_list(char *seq, char *filename, struct plist *pl, 30 | struct plist *mf, char *comment); 31 | extern int PS_dot_plot_turn(char *seq, struct plist *pl, char *filename, 32 | int winSize); 33 | extern int PS_color_aln(const char *structure, const char *filename, 34 | const char *seqs[], const char *names[]); 35 | -------------------------------------------------------------------------------- /phyml/m4.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PhyML: a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences. 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward. 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #ifndef M4_H 14 | #define M4_H 15 | 16 | int M4_main(int argc, char **argv); 17 | void M4_Make_Complete(int n_h, int n_o, m4 *m4mod); 18 | m4 *M4_Make_Light(int n_o); 19 | void M4_Free_M4_Model(m4 *m4mod); 20 | void M4_Init_Qmat(m4 *m4mod, allseq *data, model *mod); 21 | void M4_Update_Qmat(m4 *m4mod, model *mod); 22 | void M4_Init_Model(m4 *m4mod, allseq *data, model *mod); 23 | void M4_Init_P_Lk_Tips_Double(arbre *tree); 24 | void M4_Init_P_Lk_Tips_Int(arbre *tree); 25 | void M4_Post_Prob_H_Class_Edge_Site(edge *b, phydbl ****integral, phydbl *postprob, arbre *tree); 26 | phydbl ****M4_Integral_Term_On_One_Edge(edge *b, arbre *tree); 27 | phydbl ***M4_Compute_Proba_Hidden_States_On_Edges(arbre *tree); 28 | void M4_Free_Integral_Term_On_One_Edge(phydbl ****integral, arbre *tree); 29 | void M4_Compute_Posterior_Mean_Rates(phydbl ***post_probs, arbre *tree); 30 | void M4_Scale_Br_Len(arbre *tree); 31 | void M4_Detect_Site_Switches_Experiment(arbre *tree); 32 | m4 *M4_Copy_M4_Model(model *ori_mod, m4 *ori_m4mod); 33 | void M4_Posterior_Prediction_Experiment(arbre *tree); 34 | void M4_Set_M4mod_Default(m4 *m4mod); 35 | phydbl **M4_Site_Branch_Classification(phydbl ***post_probs, arbre *tree); 36 | void M4_Site_Branch_Classification_Experiment(arbre *tree); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/RNAcode.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2009, Stefan Washietl 2 | 3 | This file is part of RNAcode. 4 | 5 | RNAcode is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | RNAcode is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with RNAcode. If not, see . */ 17 | 18 | 19 | #ifndef _RNACODE_H_ 20 | #define _RNACODE_H_ 21 | 22 | void usage(void); 23 | void help(void); 24 | void version(void); 25 | void read_commandline(int argc, char *argv[]); 26 | 27 | typedef struct _parameters parameters; 28 | 29 | struct _parameters{ 30 | float omega; 31 | float Omega; 32 | float Delta; 33 | float stopPenalty_0; 34 | float stopPenalty_k; 35 | FILE *inputFile; 36 | FILE *outputFile; 37 | FILE *debugFile; 38 | int sampleN; 39 | char limit[10000]; 40 | float cutoff; 41 | int outputFormat; 42 | int stopEarly; 43 | int bestOnly; 44 | int bestRegion; 45 | int blosum; 46 | char debugFileName[1024]; 47 | char inputFileName[1024]; 48 | float printIfBelow; 49 | float printIfAbove; 50 | int postscript; 51 | float postscript_cutoff; 52 | char postscriptDir[1024]; 53 | 54 | }; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /phyml/mc.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PhyML: a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences. 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward. 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #ifndef MC_H 14 | #define MC_H 15 | 16 | void MC_Least_Square_Node_Times_Pre(node *a, node *d, phydbl *A, phydbl *b, int n, arbre *tree); 17 | int MC_main(int argc, char **argv); 18 | void MC_Bl_From_T_Post(node *a, node *d, edge *b, arbre *tree); 19 | void MC_Bl_From_T(arbre *tree); 20 | void MC_Optimize_Node_Times_Serie(node *a, node *d, edge *b, arbre *tree); 21 | void MC_Round_Optimize(arbre *tree); 22 | void MC_Print_Node_Times(node *a, node *d, arbre *tree); 23 | edge *MC_Find_Best_Root_Position(arbre *tree); 24 | void MC_Least_Square_Node_Times(edge *e_root, arbre *tree); 25 | void MC_Mult_Time_Stamps(arbre *tree); 26 | void MC_Div_Time_Stamps(arbre *tree); 27 | void MC_Optimize_Tree_Height(arbre *tree); 28 | void MC_Adjust_Node_Times(arbre *tree); 29 | void MC_Adjust_Node_Times_Pre(node *a, node *d, arbre *tree); 30 | void MC_Optimize_Root_Height(arbre *tree); 31 | void MC_Estimate_Branch_Rates(arbre *tree); 32 | edge *MC_Find_Best_Root_Position_Approx(arbre *tree); 33 | void MC_Estimate_Branch_Rate_Parameter(arbre *tree); 34 | phydbl MC_Classify_Branch_In_Rate_Class(arbre *tree); 35 | void MC_Compute_Rates_And_Times_Least_Square_Adjustments(arbre *tree); 36 | void MC_Compute_Rates_And_Times_Least_Square_Adjustments_Post(node *a, node *d, edge *b, arbre *tree); 37 | void MC_Classify_Branch_Rates(arbre *tree); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /phyml/free.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PHYML : a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #ifndef FREE_H 14 | #define FREE_H 15 | 16 | void Free_All_Nodes_Light(arbre *tree); 17 | void Free_All_Edges_Light(arbre *tree); 18 | void Free_Mat(matrix *mat); 19 | void Free_Partial_Lk(phydbl ****p_lk, int len, int n_catg); 20 | void Free_Tree(arbre *tree); 21 | void Free_Edge(edge *b); 22 | void Free_Node(node *n); 23 | void Free_Cseq(allseq *alldata); 24 | void Free_Seq(seq **d, int n_otu); 25 | void Free_All(seq **d, allseq *alldata, arbre *tree); 26 | void Free_SubTree(edge *b_fcus, node *a, node *d, arbre *tree); 27 | void Free_Tree_Ins_Tar(arbre *tree); 28 | void Free_Tree_Lk(arbre *tree); 29 | void Free_NNI(arbre *tree); 30 | void Free_Edge_P_Lk_Struct(edge *b, arbre *tree); 31 | void Free_Node_Lk(node *n); 32 | void Free_Edge_Lk(arbre *tree, edge *b); 33 | void Free_Model(model *mod); 34 | void Free(void *p); 35 | void Free_Input(option *input); 36 | void Free_Reachable(arbre *tree); 37 | void Free_St(superarbre *st); 38 | void Free_Eigen(eigen *eigen_struct); 39 | void Free_Triplet(ttriplet *t); 40 | void Free_Tree_Pars(arbre *tree); 41 | void Free_Edge_Pars(edge *b, arbre *tree); 42 | void Free_One_Spr(spr *this_spr); 43 | void Free_Spr_List(arbre *tree); 44 | void Free_Actual_CSeq(allseq *data); 45 | void Free_Prefix_Tree(pnode *n, int size); 46 | void Free_Pnode(pnode *n); 47 | void Free_Edge_Labels(edge *b); 48 | void Free_Rates(int n_otu, trate *r); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/cmdline.ggo: -------------------------------------------------------------------------------- 1 | # gengetopt template file 2 | # create cmdline.h and cmdline.c with the following command: 3 | # 4 | #gengetopt < cmdline.ggo -F cmdline --unamed-opts --no-handle-version --no-handle-help --no-handle-error 5 | 6 | option "outfile" o "Output filename" string no 7 | option "gtf" g "GTF output" flag off 8 | option "tabular" t "Tab delimited output" flag off 9 | option "best-only" b "Print only best hit per alignment" flag off 10 | option "best-region" r "Print all best non-overlapping hits per alignment" flag off 11 | option "pars" c "String with parameters" string no 12 | option "stop-early" s "Don't calculate p-values if below cutoff" flag off 13 | option "num-samples" n "Number of samples" int no 14 | option "cutoff" p "p-value cutoff" float no 15 | option "debug-file" z "Debug file" string no 16 | option "eps" e "Postscript output" flag off 17 | option "eps-cutoff" i "Postscript output p-value cutoff" float no 18 | option "eps-dir" d "Postscript directory" string no 19 | option "limit" l "limit to species" string no 20 | option "blosum" m "BLOSUM matrix version" int no 21 | 22 | -------------------------------------------------------------------------------- /librna/fold_vars.h: -------------------------------------------------------------------------------- 1 | /* to use floats instead of doubles in pf_fold() comment next line */ 2 | #define LARGE_PF 3 | #ifdef LARGE_PF 4 | #define FLT_OR_DBL double 5 | #else 6 | #define FLT_OR_DBL float 7 | #endif 8 | 9 | extern int noGU; /* GU not allowed at all */ 10 | extern int no_closingGU; /* GU allowed only inside stacks */ 11 | extern int tetra_loop; /* Fold with specially stable 4-loops */ 12 | extern int energy_set; /* 0 = BP; 1=any mit GC; 2=any mit AU-parameter */ 13 | extern int dangles; /* use dangling end energies (not in part_func!) */ 14 | /*@null@*/ 15 | extern char *nonstandards; /* contains allowed non standard bases */ 16 | extern double temperature; /* rescale parameters to this temperature */ 17 | extern int james_rule; /* interior loops of size 2 get energy 0.8Kcal and 18 | no mismatches, default 1 */ 19 | extern int logML; /* use logarithmic multiloop energy function */ 20 | extern int cut_point; /* first position of 2nd strand for co-folding */ 21 | 22 | typedef struct bond { /* base pair */ 23 | int i; 24 | int j; 25 | } bondT; 26 | extern bondT *base_pair; /* list of base pairs */ 27 | 28 | extern FLT_OR_DBL *pr; /* base pairing prob. matrix */ 29 | extern int *iindx; /* pr[i,j] -> pr[iindx[i]-j] */ 30 | extern double pf_scale; /* scaling factor to avoid float overflows*/ 31 | extern int fold_constrained; /* fold with constraints */ 32 | extern int do_backtrack; /* calculate pair prob matrix in part_func() */ 33 | extern int noLonelyPairs; /* avoid helices of length 1 */ 34 | extern char backtrack_type; /* usually 'F'; 'C' require (1,N) to be bonded; 35 | 'M' seq is part of a multi loop */ 36 | char * option_string(void); 37 | -------------------------------------------------------------------------------- /phyml/spr.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** spr.h: Header file for the SPR routines. 3 | ** 4 | ** Wim Hordijk Last modified: 28 August 2006 5 | */ 6 | 7 | #ifndef _SPR_H_ 8 | #define _SPR_H_ 9 | 10 | #include "utilities.h" 11 | 12 | #define ALL 1 13 | #define BEST 2 14 | #define ONE 3 15 | 16 | /* 17 | ** _move_: Structure for holding the relevant information for candidate SPR moves. 18 | */ 19 | 20 | typedef struct 21 | { 22 | node *v_prune, *u_prune, *v_n, *v_nx1, *u_n, **path; 23 | edge *e_prune, *e_regraft; 24 | phydbl l_connect, l_est[3], delta_lk, d_L, d_up_v, d_un_v; 25 | int dist, rgrft_rank, optim_rank, globl_rank; 26 | } _move_; 27 | 28 | 29 | 30 | void Init_SPR (arbre *tree); 31 | void Clean_SPR (arbre *tree); 32 | void Optim_SPR (arbre *tree, int max_size, int method); 33 | int Perform_SPR_Moves (arbre *tree, int max_size); 34 | int Perform_Best_SPR (arbre *tree, int max_size); 35 | int Perform_One_SPR (arbre *tree, int max_size); 36 | 37 | void Calc_Tree_Length (edge *e_prune, node *v_prune, arbre *tree); 38 | void Tree_Length (node *v_prune, node *u_prune, node *v_n, node *v_n_1, 39 | node *v_nx1, node *v_0, node *u_n, phydbl d_up_v_1, 40 | phydbl d_uu, phydbl d_L_1, int n, arbre *tree); 41 | int Est_Lk_Change (edge *e_prune, node *v_prune, arbre *tree); 42 | int Best_Lk_Change (edge *e_prune, node *v_prune, arbre *tree); 43 | void Make_Move (_move_ *move, int type, arbre *tree); 44 | int Find_Optim_Local (arbre *tree); 45 | int Find_Optim_Globl (arbre *tree); 46 | void Prune (edge *e, node *v, edge **e_connect, edge **e_avail, 47 | arbre *tree); 48 | void Regraft (edge *e, node *v, edge *avail, arbre *tree); 49 | void PostOrder_v (arbre *tree, node *v, edge *e); 50 | void PostOrder_w (arbre *tree, node *v, edge *v_e, node *w, edge *e); 51 | 52 | 53 | #endif /* _SPR_H_ */ 54 | 55 | 56 | /* 57 | ** EOF: spr.h 58 | */ 59 | -------------------------------------------------------------------------------- /librna/fold_vars.c: -------------------------------------------------------------------------------- 1 | /* Last changed Time-stamp: <2006-11-03 16:29:09 ulim> */ 2 | 3 | /* 4 | global variables to change behaviour of folding routines 5 | Vienna RNA package 6 | */ 7 | #include 8 | #include 9 | #include "fold_vars.h" 10 | 11 | int noGU = 0; /* GU not allowed at all */ 12 | int no_closingGU = 0; /* GU allowed only inside stacks */ 13 | int tetra_loop = 1; /* Fold with specially stable 4-loops */ 14 | int energy_set = 0; /* 0 = BP; 1=any with GC; 2=any with AU parameters */ 15 | int dangles = 1; /* use dangling end energies */ 16 | char *nonstandards = (char *)0; /* contains allowed non standard bases */ 17 | double temperature = 37.0; 18 | int james_rule = 1; /* interior loops of size 2 get energy 0.8Kcal and 19 | no mismatches (no longer used) */ 20 | 21 | struct bond *base_pair; 22 | 23 | FLT_OR_DBL *pr; /* base pairing prob. matrix */ 24 | int *iindx; /* pr[i,j] -> pr[iindx[i]-j] */ 25 | double pf_scale=- 1; /* scaling factor to avoid floating point overflows */ 26 | int fold_constrained = 0; /* fold with constraints */ 27 | int do_backtrack=1; /* calculate pair prob matrix in part_func() */ 28 | int noLonelyPairs = 0; /* avoid helices of length 1 */ 29 | char backtrack_type='F'; /* 'C' require (1,N) to be bonded; 30 | 'M' seq is part of s multi loop */ 31 | 32 | int *cut_points; 33 | int *strand; 34 | char * option_string(void) { 35 | static char options[100]; 36 | *options = '\0'; 37 | if (noGU) strcat(options, "-noGU "); 38 | if (no_closingGU) strcat(options, "-noCloseGU "); 39 | if (!tetra_loop) strcat(options, "-4 "); 40 | if (noLonelyPairs) strcat(options, "-noLP "); 41 | if (fold_constrained) strcat(options, "-C "); 42 | if (dangles!=1) sprintf(options+strlen(options), "-d%d ", dangles); 43 | if (temperature!=37.0) 44 | sprintf(options+strlen(options), "-T %f ", temperature); 45 | return options; 46 | } 47 | -------------------------------------------------------------------------------- /librna/params.h: -------------------------------------------------------------------------------- 1 | #include "energy_const.h" 2 | typedef struct { 3 | int id; 4 | int stack[NBPAIRS+1][NBPAIRS+1]; 5 | int hairpin[31]; 6 | int bulge[MAXLOOP+1]; 7 | int internal_loop[MAXLOOP+1]; 8 | int mismatchI[NBPAIRS+1][5][5]; 9 | int mismatchH[NBPAIRS+1][5][5]; 10 | int mismatchM[NBPAIRS+1][5][5]; 11 | int dangle5[NBPAIRS+1][5]; 12 | int dangle3[NBPAIRS+1][5]; 13 | int int11[NBPAIRS+1][NBPAIRS+1][5][5]; 14 | int int21[NBPAIRS+1][NBPAIRS+1][5][5][5]; 15 | int int22[NBPAIRS+1][NBPAIRS+1][5][5][5][5]; 16 | int F_ninio[5]; 17 | double lxc; 18 | int MLbase; 19 | int MLintern[NBPAIRS+1]; 20 | int MLclosing; 21 | int TerminalAU; 22 | int DuplexInit; 23 | int TETRA_ENERGY[200]; 24 | char Tetraloops[1401]; 25 | int Triloop_E[40]; 26 | char Triloops[241]; 27 | double temperature; 28 | } paramT; 29 | 30 | extern paramT *scale_parameters(void); 31 | extern paramT *copy_parameters(void); 32 | extern paramT *set_parameters(paramT *dest); 33 | 34 | typedef struct { 35 | int id; 36 | double expstack[NBPAIRS+1][NBPAIRS+1]; 37 | double exphairpin[31]; 38 | double expbulge[MAXLOOP+1]; 39 | double expinternal[MAXLOOP+1]; 40 | double expmismatchI[NBPAIRS+1][5][5]; 41 | double expmismatchH[NBPAIRS+1][5][5]; 42 | double expmismatchM[NBPAIRS+1][5][5]; 43 | double expdangle5[NBPAIRS+1][5]; 44 | double expdangle3[NBPAIRS+1][5]; 45 | double expint11[NBPAIRS+1][NBPAIRS+1][5][5]; 46 | double expint21[NBPAIRS+1][NBPAIRS+1][5][5][5]; 47 | double expint22[NBPAIRS+1][NBPAIRS+1][5][5][5][5]; 48 | double expninio[5][MAXLOOP+1]; 49 | double lxc; 50 | double expMLbase; 51 | double expMLintern[NBPAIRS+1]; 52 | double expMLclosing; 53 | double expTermAU; 54 | double expDuplexInit; 55 | double exptetra[40]; 56 | char Tetraloops[1401]; 57 | double expTriloop[40]; 58 | char Triloops[241]; 59 | double temperature; 60 | } pf_paramT; 61 | 62 | extern pf_paramT *scale_pf_parameters(void); 63 | extern pf_paramT *copy_pf_param(void); 64 | extern pf_paramT *set_pf_param(paramT *dest); 65 | 66 | -------------------------------------------------------------------------------- /src/misc.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2009, Stefan Washietl 2 | 3 | This file is part of RNAcode. 4 | 5 | RNAcode is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | RNAcode is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with RNAcode. If not, see . */ 17 | 18 | #ifndef _MISC_H_ 19 | #define _MISC_H_ 20 | 21 | #include "score.h" 22 | #include "code.h" 23 | #include "rnaz_utils.h" 24 | 25 | float**** allocateSk(int N, int L); 26 | void copySk(float**** from, float**** to, int N, int L); 27 | 28 | int compareScores(const void * a, const void * b); 29 | 30 | void reintroduceGaps(const struct aln* origAln[], struct aln* sampledAln[]); 31 | 32 | void sortAln(const struct aln* origAln[], struct aln* sampledAln[]); 33 | 34 | void freeResults(segmentStats results[]); 35 | 36 | //void getBlock(const char* seq_0, const char* seq_k, int i, char* block_0, char* block_k, int* z ); 37 | void getBlock(int i, const char* seq_0, const char* seq_k, const int* map_0, const int* map_k, char* block_0, char* block_k, int* z ); 38 | 39 | int pos2col(const char* seq, int pos); 40 | 41 | int getSeqLength(char *seq); 42 | 43 | int hDist(int a1, int a2, int a3, int b1, int b2, int b3); 44 | 45 | float avg(float* data, int N); 46 | 47 | float stddev(float* data, int N); 48 | 49 | float gaussian (const float sigma); 50 | 51 | void copyAln(struct aln *src[],struct aln *dest[]); 52 | 53 | void printAlnClustal(FILE *out, const struct aln* AS[]); 54 | 55 | void printResults(FILE* outfile, int outputFormat, const struct aln* AS[], segmentStats results[]); 56 | 57 | int extendRegion(const struct aln* alignment[], int pos, int direction); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /seqgen/twister.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sequence Generator - seq-gen, version 1.3.2 3 | Copyright (c)1996-2004, Andrew Rambaut & Nick Grassly 4 | Department of Zoology, University of Oxford 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | 3. The names of its contributors may not be used to endorse or promote 19 | products derived from this software without specific prior written 20 | permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | Any feedback is very welcome. 36 | http://evolve.zoo.ox.ac.uk/software/Seq-Gen/ 37 | email: andrew.rambaut@zoo.ox.ac.uk 38 | */ 39 | 40 | #ifndef _TWISTER_H_ 41 | #define _TWISTER_H_ 42 | 43 | void SetSeed (unsigned long seed); 44 | unsigned long CreateSeed(void); 45 | double rndu (void); 46 | 47 | #endif /* _TWISTER_H_ */ 48 | 49 | -------------------------------------------------------------------------------- /examples/noncoding.aln: -------------------------------------------------------------------------------- 1 | CLUSTAL W(1.81) multiple sequence alignment 2 | 3 | 4 | ec_K12.chr_fwd/146715-146836 TC---GTTAA------CGAAGCAGG----CGAT----GCCTGCTTTGAGGAAATTCTCAC 5 | ec_O157H7.chr_fwd/151087-151208 TC---GTTAA------CGAAGCAGG----CGGT----GCCTGCTTTGAGGAAATTCTCAC 6 | ec_APEC_O1.chr_fwd/152722-152843 TC---GTTAA------CGAAGCAGG----CGAT----GCCTGCTTTGAGGAAATTCTCAC 7 | ente638.chr_fwd/771945-772071 TCAAGGCCGA------GAGGGCAGGGTGAAGGG----ATATTTCCCAGGCAAATATCGGC 8 | shigFlex_2A.chr_fwd/144806-144927 TC---GTTAA------CGAAGCAGG----CGGT----GCCTGCTTTGAGGAAATTCTCAC 9 | salmTyph.chr_fwd/208300-208419 TC---GTTTATCTTGGCTAAGCAGG----CGCTTGTAGCCTGCTTT--GGAAATTCTCAG 10 | salmEnte_PARATYPI_ATC.chr_fwd/215652-215771 TC---GTTTACCTTGGCTAAGCAGG----CGCTTGTGGCCTGCTTT--GGAAATTCTCAG 11 | 12 | 13 | ec_K12.chr_fwd/146715-146836 GCAGTATTGCCCGATTTTTGTTTAGTGTCTACTCATCTGACGGCATTTGCGTCA----GC 14 | ec_O157H7.chr_fwd/151087-151208 GCAGTATTGCCCGATTTTTGTTTAGTGTCTACTCATCTGACGGCATTTGCATCA----GC 15 | ec_APEC_O1.chr_fwd/152722-152843 GCAGTATTGCCCGATTTTTGTTGAGTGTCTACTCATCTGACGGCATTTGCAGCA----GC 16 | ente638.chr_fwd/771945-772071 GCAGTATTGCCCGATTTTTAGTCGGTGTCTACTC------CGCCAGCTCAACCACTTTAT 17 | shigFlex_2A.chr_fwd/144806-144927 GCAGTATTGCCCGATTTTTGATGAGTGTCTACTCATCTGATGGCATTTGCGTCA----GC 18 | salmTyph.chr_fwd/208300-208419 GCAGTATTGCCCGATTTTTAACCCCTGTCTACTGGGCTAATG----------TA----AC 19 | salmEnte_PARATYPI_ATC.chr_fwd/215652-215771 GCAGTATTGCCCGATTTTTAACCCCTGTCTACTGGGCTAATG----------TA----AC 20 | 21 | 22 | ec_K12.chr_fwd/146715-146836 AGTTTGCGTACCGCGCCGAAGCG 23 | ec_O157H7.chr_fwd/151087-151208 AGTTTGCGTACCGCGCCGAAGCG 24 | ec_APEC_O1.chr_fwd/152722-152843 AGTTTGCGTACCGTGCCGAAGCG 25 | ente638.chr_fwd/771945-772071 TGTCTATGAGGCGTGCCTGGCCG 26 | shigFlex_2A.chr_fwd/144806-144927 AGTTTGCGTACCGCGCCGAAGCG 27 | salmTyph.chr_fwd/208300-208419 GCTTTGATTATCGATCAGACGCG 28 | salmEnte_PARATYPI_ATC.chr_fwd/215652-215771 GCTTTGATTATCGATCAGACGCG 29 | 30 | -------------------------------------------------------------------------------- /phyml/models.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PHYML : a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #ifndef MODELS_H 14 | #define MODELS_H 15 | 16 | void PMat(phydbl l, model *mod, double ***Pij); 17 | void PMat_K80(phydbl l,phydbl kappa, double ***Pij); 18 | void PMat_TN93(phydbl l, model *mod, double ***Pij); 19 | void PMat_Empirical(phydbl l, model *mod, double ***Pij); 20 | int GetDaa (phydbl *daa, phydbl *pi, char *file_name); 21 | int Matinv (double *x, int n, int m, double *space); 22 | 23 | /* add error checking, return value is set to int instead of void */ 24 | int Init_Model(allseq *data, model *mod); 25 | void Update_Qmat_GTR(double *rr, phydbl *rr_val, int *rr_num, double *pi, double *qmat); 26 | void Update_Qmat_HKY(double kappa, double *pi, double *qmat); 27 | void Update_Qmat_Generic(double *rr, double *pi, int ns, double *qmat); 28 | void Translate_Custom_Mod_String(model *mod); 29 | 30 | /* add error checking, return value is set to int instead of void */ 31 | int Set_Model_Parameters(model *mod); 32 | void PMat_Zero_Br_Len(model *mod, double ***Pij); 33 | phydbl GTR_Dist(phydbl *F, phydbl alpha, eigen *eigen_struct); 34 | phydbl General_Dist(phydbl *F, model *mod, eigen *eigen_struct); 35 | 36 | int Init_Qmat_WAG(double *daa, phydbl *pi); 37 | int Init_Qmat_Dayhoff(double *daa, phydbl *pi); 38 | int Init_Qmat_JTT(double *daa, phydbl *pi); 39 | int Init_Qmat_RtREV(double *daa, phydbl *pi); 40 | int Init_Qmat_CpREV(double *daa, phydbl *pi); 41 | int Init_Qmat_VT(double *daa, phydbl *pi); 42 | int Init_Qmat_Blosum62(double *daa, phydbl *pi); 43 | int Init_Qmat_MtMam(double *daa, phydbl *pi); 44 | int Init_Qmat_MtArt(double *daa, double *pi); // Added by Federico Abascal 45 | int Init_Qmat_HIVb(double *daa, double *pi); //added by Federic Abascal 46 | int Init_Qmat_HIVw(double *daa, double *pi); //added by Federico Abascal 47 | void Switch_From_Mod_To_M4mod(model *mod); 48 | void Switch_From_M4mod_To_Mod(model *mod); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/EBLOSUM62: -------------------------------------------------------------------------------- 1 | # Matrix made by matblas from blosum62.iij 2 | # * column uses minimum score 3 | # BLOSUM Clustered Scoring Matrix in 1/2 Bit Units 4 | # Blocks Database = /data/blocks_5.0/blocks.dat 5 | # Cluster Percentage: >= 62 6 | # Entropy = 0.6979, Expected = -0.5209 7 | A R N D C Q E G H I L K M F P S T W Y V B Z X * 8 | A 4 -1 -2 -2 0 -1 -1 0 -2 -1 -1 -1 -1 -2 -1 1 0 -3 -2 0 -2 -1 0 -4 9 | R -1 5 0 -2 -3 1 0 -2 0 -3 -2 2 -1 -3 -2 -1 -1 -3 -2 -3 -1 0 -1 -4 10 | N -2 0 6 1 -3 0 0 0 1 -3 -3 0 -2 -3 -2 1 0 -4 -2 -3 3 0 -1 -4 11 | D -2 -2 1 6 -3 0 2 -1 -1 -3 -4 -1 -3 -3 -1 0 -1 -4 -3 -3 4 1 -1 -4 12 | C 0 -3 -3 -3 9 -3 -4 -3 -3 -1 -1 -3 -1 -2 -3 -1 -1 -2 -2 -1 -3 -3 -2 -4 13 | Q -1 1 0 0 -3 5 2 -2 0 -3 -2 1 0 -3 -1 0 -1 -2 -1 -2 0 3 -1 -4 14 | E -1 0 0 2 -4 2 5 -2 0 -3 -3 1 -2 -3 -1 0 -1 -3 -2 -2 1 4 -1 -4 15 | G 0 -2 0 -1 -3 -2 -2 6 -2 -4 -4 -2 -3 -3 -2 0 -2 -2 -3 -3 -1 -2 -1 -4 16 | H -2 0 1 -1 -3 0 0 -2 8 -3 -3 -1 -2 -1 -2 -1 -2 -2 2 -3 0 0 -1 -4 17 | I -1 -3 -3 -3 -1 -3 -3 -4 -3 4 2 -3 1 0 -3 -2 -1 -3 -1 3 -3 -3 -1 -4 18 | L -1 -2 -3 -4 -1 -2 -3 -4 -3 2 4 -2 2 0 -3 -2 -1 -2 -1 1 -4 -3 -1 -4 19 | K -1 2 0 -1 -3 1 1 -2 -1 -3 -2 5 -1 -3 -1 0 -1 -3 -2 -2 0 1 -1 -4 20 | M -1 -1 -2 -3 -1 0 -2 -3 -2 1 2 -1 5 0 -2 -1 -1 -1 -1 1 -3 -1 -1 -4 21 | F -2 -3 -3 -3 -2 -3 -3 -3 -1 0 0 -3 0 6 -4 -2 -2 1 3 -1 -3 -3 -1 -4 22 | P -1 -2 -2 -1 -3 -1 -1 -2 -2 -3 -3 -1 -2 -4 7 -1 -1 -4 -3 -2 -2 -1 -2 -4 23 | S 1 -1 1 0 -1 0 0 0 -1 -2 -2 0 -1 -2 -1 4 1 -3 -2 -2 0 0 0 -4 24 | T 0 -1 0 -1 -1 -1 -1 -2 -2 -1 -1 -1 -1 -2 -1 1 5 -2 -2 0 -1 -1 0 -4 25 | W -3 -3 -4 -4 -2 -2 -3 -2 -2 -3 -2 -3 -1 1 -4 -3 -2 11 2 -3 -4 -3 -2 -4 26 | Y -2 -2 -2 -3 -2 -1 -2 -3 2 -1 -1 -2 -1 3 -3 -2 -2 2 7 -1 -3 -2 -1 -4 27 | V 0 -3 -3 -3 -1 -2 -2 -3 -3 3 1 -2 1 -1 -2 -2 0 -3 -1 4 -3 -2 -1 -4 28 | B -2 -1 3 4 -3 0 1 -1 0 -3 -4 0 -3 -3 -2 0 -1 -4 -3 -3 4 1 -1 -4 29 | Z -1 0 0 1 -3 3 4 -2 0 -3 -3 1 -1 -3 -1 0 -1 -3 -2 -2 1 4 -1 -4 30 | X 0 -1 -1 -1 -2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -2 0 0 -2 -1 -1 -1 -1 -1 -4 31 | * -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 1 32 | -------------------------------------------------------------------------------- /src/EBLOSUM90: -------------------------------------------------------------------------------- 1 | # Matrix made by matblas from blosum90.iij 2 | # * column uses minimum score 3 | # BLOSUM Clustered Scoring Matrix in 1/2 Bit Units 4 | # Blocks Database = /data/blocks_5.0/blocks.dat 5 | # Cluster Percentage: >= 90 6 | # Entropy = 1.1806, Expected = -0.8887 7 | A R N D C Q E G H I L K M F P S T W Y V B Z X * 8 | A 5 -2 -2 -3 -1 -1 -1 0 -2 -2 -2 -1 -2 -3 -1 1 0 -4 -3 -1 -2 -1 -1 -6 9 | R -2 6 -1 -3 -5 1 -1 -3 0 -4 -3 2 -2 -4 -3 -1 -2 -4 -3 -3 -2 0 -2 -6 10 | N -2 -1 7 1 -4 0 -1 -1 0 -4 -4 0 -3 -4 -3 0 0 -5 -3 -4 4 -1 -2 -6 11 | D -3 -3 1 7 -5 -1 1 -2 -2 -5 -5 -1 -4 -5 -3 -1 -2 -6 -4 -5 4 0 -2 -6 12 | C -1 -5 -4 -5 9 -4 -6 -4 -5 -2 -2 -4 -2 -3 -4 -2 -2 -4 -4 -2 -4 -5 -3 -6 13 | Q -1 1 0 -1 -4 7 2 -3 1 -4 -3 1 0 -4 -2 -1 -1 -3 -3 -3 -1 4 -1 -6 14 | E -1 -1 -1 1 -6 2 6 -3 -1 -4 -4 0 -3 -5 -2 -1 -1 -5 -4 -3 0 4 -2 -6 15 | G 0 -3 -1 -2 -4 -3 -3 6 -3 -5 -5 -2 -4 -5 -3 -1 -3 -4 -5 -5 -2 -3 -2 -6 16 | H -2 0 0 -2 -5 1 -1 -3 8 -4 -4 -1 -3 -2 -3 -2 -2 -3 1 -4 -1 0 -2 -6 17 | I -2 -4 -4 -5 -2 -4 -4 -5 -4 5 1 -4 1 -1 -4 -3 -1 -4 -2 3 -5 -4 -2 -6 18 | L -2 -3 -4 -5 -2 -3 -4 -5 -4 1 5 -3 2 0 -4 -3 -2 -3 -2 0 -5 -4 -2 -6 19 | K -1 2 0 -1 -4 1 0 -2 -1 -4 -3 6 -2 -4 -2 -1 -1 -5 -3 -3 -1 1 -1 -6 20 | M -2 -2 -3 -4 -2 0 -3 -4 -3 1 2 -2 7 -1 -3 -2 -1 -2 -2 0 -4 -2 -1 -6 21 | F -3 -4 -4 -5 -3 -4 -5 -5 -2 -1 0 -4 -1 7 -4 -3 -3 0 3 -2 -4 -4 -2 -6 22 | P -1 -3 -3 -3 -4 -2 -2 -3 -3 -4 -4 -2 -3 -4 8 -2 -2 -5 -4 -3 -3 -2 -2 -6 23 | S 1 -1 0 -1 -2 -1 -1 -1 -2 -3 -3 -1 -2 -3 -2 5 1 -4 -3 -2 0 -1 -1 -6 24 | T 0 -2 0 -2 -2 -1 -1 -3 -2 -1 -2 -1 -1 -3 -2 1 6 -4 -2 -1 -1 -1 -1 -6 25 | W -4 -4 -5 -6 -4 -3 -5 -4 -3 -4 -3 -5 -2 0 -5 -4 -4 11 2 -3 -6 -4 -3 -6 26 | Y -3 -3 -3 -4 -4 -3 -4 -5 1 -2 -2 -3 -2 3 -4 -3 -2 2 8 -3 -4 -3 -2 -6 27 | V -1 -3 -4 -5 -2 -3 -3 -5 -4 3 0 -3 0 -2 -3 -2 -1 -3 -3 5 -4 -3 -2 -6 28 | B -2 -2 4 4 -4 -1 0 -2 -1 -5 -5 -1 -4 -4 -3 0 -1 -6 -4 -4 4 0 -2 -6 29 | Z -1 0 -1 0 -5 4 4 -3 0 -4 -4 1 -2 -4 -2 -1 -1 -4 -3 -3 0 4 -1 -6 30 | X -1 -2 -2 -2 -3 -1 -2 -2 -2 -2 -2 -1 -1 -2 -2 -1 -1 -3 -2 -2 -2 -1 -2 -6 31 | * -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 1 32 | -------------------------------------------------------------------------------- /levmar/misc.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Levenberg - Marquardt non-linear minimization algorithm 4 | // Copyright (C) 2004-05 Manolis Lourakis (lourakis@ics.forth.gr) 5 | // Institute of Computer Science, Foundation for Research & Technology - Hellas 6 | // Heraklion, Crete, Greece. 7 | // 8 | // This program is free software; you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation; either version 2 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | ///////////////////////////////////////////////////////////////////////////////// 19 | 20 | /******************************************************************************** 21 | * Miscelaneous functions for Levenberg-Marquardt nonlinear minimization. The 22 | * same core code is used with appropriate #defines to derive single and double 23 | * precision versions, see also misc_core.c 24 | ********************************************************************************/ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "lm.h" 32 | #include "misc.h" 33 | 34 | /* single precision (float) definitions */ 35 | #define LM_REAL float 36 | #define LM_PREFIX s 37 | 38 | #define LM_REAL_EPSILON FLT_EPSILON 39 | #define SUBCNST(x) x##F 40 | #define CNST(x) SUBCNST(x) // force substitution 41 | 42 | #include "misc_core.c" // read in core code 43 | 44 | #undef LM_REAL 45 | #undef LM_PREFIX 46 | #undef LM_REAL_EPSILON 47 | #undef SUBCNST 48 | #undef CNST 49 | 50 | /* double precision definitions */ 51 | #define LM_REAL double 52 | #define LM_PREFIX d 53 | 54 | #define LM_REAL_EPSILON DBL_EPSILON 55 | #define CNST(x) (x) 56 | 57 | #include "misc_core.c" // read in core code 58 | 59 | #undef LM_REAL 60 | #undef LM_PREFIX 61 | #undef LM_REAL_EPSILON 62 | #undef CNST 63 | -------------------------------------------------------------------------------- /librna/utils.h: -------------------------------------------------------------------------------- 1 | /* Header file for utils.c */ 2 | #ifdef HAVE_CONFIG_H 3 | #include 4 | #endif 5 | #ifdef WITH_DMALLOC 6 | /* use dmalloc library to check for memory management bugs */ 7 | #include "dmalloc.h" 8 | #define space(S) calloc(1,(S)) 9 | #else 10 | extern /*@only@*/ /*@notnull@*/ 11 | void *space(unsigned size) /*@ensures MaxSet(result) == (size-1);@*/; 12 | /* allocate space safely */ 13 | extern /*@only@*/ /*@notnull@*/ 14 | void *xrealloc(/*@null@*/ /*@only@*/ /*@out@*/ /*@returned@*/ void *p, unsigned size) /*@modifies *p @*/ /*@ensures MaxSet(result) == (size-1) @*/; 15 | #endif 16 | 17 | extern /*@exits@*/ void nrerror(const char message[]); /* die with error message */ 18 | extern void init_rand(void); /* make random number seeds */ 19 | extern unsigned short xsubi[3]; /* current 48bit random number */ 20 | extern double urn(void); /* random number from [0..1] */ 21 | extern int int_urn(int from, int to); /* random integer */ 22 | extern void filecopy(FILE *from, FILE *to); /* inefficient `cp' */ 23 | extern /*@observer@*/ char *time_stamp(void); /* current date in a string */ 24 | extern /*@only@*/ /*@notnull@*/ char *random_string(int l, const char symbols[]); 25 | /* random string of length l using characters from symbols[] */ 26 | extern int hamming(const char *s1, const char *s2); 27 | /* calculate hamming distance */ 28 | extern /*@only@*/ /*@null@*/ char *get_line(const FILE *fp); /* read one (arbitrary length) line from fp */ 29 | 30 | 31 | extern char *pack_structure(const char *struc); 32 | /* pack secondary secondary structure, 5:1 compression using base 3 encoding */ 33 | extern char *unpack_structure(const char *packed); 34 | /* unpack sec structure packed with pack_structure() */ 35 | extern short *make_pair_table(const char *structure); 36 | /* returns a newly allocated table, such that: table[i]=j if (i.j) pair or 37 | 0 if i is unpaired, table[0] contains the length of the structure. */ 38 | 39 | extern int bp_distance(const char *str1, const char *str2); 40 | /* dist = {number of base pairs in one structure but not in the other} 41 | same as edit distance with open-pair close-pair as move-set */ 42 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | /* Header file for utils.c */ 2 | #ifdef HAVE_CONFIG_H 3 | #include 4 | #endif 5 | #ifdef WITH_DMALLOC 6 | /* use dmalloc library to check for memory management bugs */ 7 | #include "dmalloc.h" 8 | #define space(S) calloc(1,(S)) 9 | #else 10 | extern /*@only@*/ /*@notnull@*/ 11 | void *space(unsigned size) /*@ensures MaxSet(result) == (size-1);@*/; 12 | /* allocate space safely */ 13 | extern /*@only@*/ /*@notnull@*/ 14 | void *xrealloc(/*@null@*/ /*@only@*/ /*@out@*/ /*@returned@*/ void *p, unsigned size) /*@modifies *p @*/ /*@ensures MaxSet(result) == (size-1) @*/; 15 | #endif 16 | 17 | extern /*@exits@*/ void nrerror(const char message[]); /* die with error message */ 18 | extern void init_rand(void); /* make random number seeds */ 19 | extern unsigned short xsubi[3]; /* current 48bit random number */ 20 | extern double urn(void); /* random number from [0..1] */ 21 | extern int int_urn(int from, int to); /* random integer */ 22 | extern void filecopy(FILE *from, FILE *to); /* inefficient `cp' */ 23 | extern /*@observer@*/ char *time_stamp(void); /* current date in a string */ 24 | extern /*@only@*/ /*@notnull@*/ char *random_string(int l, const char symbols[]); 25 | /* random string of length l using characters from symbols[] */ 26 | extern int hamming(const char *s1, const char *s2); 27 | /* calculate hamming distance */ 28 | extern /*@only@*/ /*@null@*/ char *get_line(const FILE *fp); /* read one (arbitrary length) line from fp */ 29 | 30 | 31 | extern char *pack_structure(const char *struc); 32 | /* pack secondary secondary structure, 5:1 compression using base 3 encoding */ 33 | extern char *unpack_structure(const char *packed); 34 | /* unpack sec structure packed with pack_structure() */ 35 | extern short *make_pair_table(const char *structure); 36 | /* returns a newly allocated table, such that: table[i]=j if (i.j) pair or 37 | 0 if i is unpaired, table[0] contains the length of the structure. */ 38 | 39 | extern int bp_distance(const char *str1, const char *str2); 40 | /* dist = {number of base pairs in one structure but not in the other} 41 | same as edit distance with open-pair close-pair as move-set */ 42 | -------------------------------------------------------------------------------- /levmar/Axb.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Solution of linear systems involved in the Levenberg - Marquardt 4 | // minimization algorithm 5 | // Copyright (C) 2004 Manolis Lourakis (lourakis@ics.forth.gr) 6 | // Institute of Computer Science, Foundation for Research & Technology - Hellas 7 | // Heraklion, Crete, Greece. 8 | // 9 | // This program is free software; you can redistribute it and/or modify 10 | // it under the terms of the GNU General Public License as published by 11 | // the Free Software Foundation; either version 2 of the License, or 12 | // (at your option) any later version. 13 | // 14 | // This program is distributed in the hope that it will be useful, 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | // GNU General Public License for more details. 18 | // 19 | ///////////////////////////////////////////////////////////////////////////////// 20 | 21 | /******************************************************************************** 22 | * LAPACK-based implementations for various linear system solvers. The same core 23 | * code is used with appropriate #defines to derive single and double precision 24 | * solver versions, see also Axb_core.c 25 | ********************************************************************************/ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include "lm.h" 32 | #include "misc.h" 33 | 34 | /* double precision definitions */ 35 | #define LM_REAL double 36 | #define LM_PREFIX d 37 | #define CNST(x) (x) 38 | #ifndef HAVE_LAPACK 39 | #include 40 | #define LM_REAL_EPSILON DBL_EPSILON 41 | #endif 42 | 43 | #include "Axb_core.c" 44 | 45 | #undef LM_REAL 46 | #undef LM_PREFIX 47 | #undef CNST 48 | #undef LM_REAL_EPSILON 49 | 50 | /* single precision (float) definitions */ 51 | #define LM_REAL float 52 | #define LM_PREFIX s 53 | #define SUBCNST(x) x##F 54 | #define CNST(x) SUBCNST(x) // force substitution 55 | #ifndef HAVE_LAPACK 56 | #define LM_REAL_EPSILON FLT_EPSILON 57 | #endif 58 | 59 | #include "Axb_core.c" 60 | 61 | #undef LM_REAL 62 | #undef LM_PREFIX 63 | #undef SUBCNST 64 | #undef CNST 65 | #undef LM_REAL_EPSILON 66 | -------------------------------------------------------------------------------- /seqgen/progress.h: -------------------------------------------------------------------------------- 1 | /* Header file for progress.c */ 2 | 3 | /* 4 | Sequence Generator - seq-gen, version 1.3.2 5 | Copyright (c)1996-2004, Andrew Rambaut & Nick Grassly 6 | Department of Zoology, University of Oxford 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | 2. Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | 3. The names of its contributors may not be used to endorse or promote 21 | products derived from this software without specific prior written 22 | permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | Any feedback is very welcome. 38 | http://evolve.zoo.ox.ac.uk/software/Seq-Gen/ 39 | email: andrew.rambaut@zoo.ox.ac.uk 40 | */ 41 | 42 | #ifndef _PROGRESS_H_ 43 | #define _PROGRESS_H_ 44 | 45 | #define MAX_BAR_LENGTH 20 46 | 47 | /* prototypes */ 48 | 49 | void InitProgressBar(int total); 50 | void DrawProgressBar(); 51 | void ProgressBar(); 52 | 53 | #endif /* _PROGRESS_H_ */ 54 | -------------------------------------------------------------------------------- /levmar/lmlec.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Levenberg - Marquardt non-linear minimization algorithm 4 | // Copyright (C) 2004-05 Manolis Lourakis (lourakis@ics.forth.gr) 5 | // Institute of Computer Science, Foundation for Research & Technology - Hellas 6 | // Heraklion, Crete, Greece. 7 | // 8 | // This program is free software; you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation; either version 2 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | ///////////////////////////////////////////////////////////////////////////////// 19 | 20 | /******************************************************************************* 21 | * Wrappers for linearly constrained Levenberg-Marquardt minimization. The same 22 | * core code is used with appropriate #defines to derive single and double 23 | * precision versions, see also lmlec_core.c 24 | *******************************************************************************/ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "lm.h" 31 | #include "misc.h" 32 | 33 | 34 | #ifndef HAVE_LAPACK 35 | 36 | #ifdef _MSC_VER 37 | #pragma message("Linearly constrained optimization requires LAPACK and was not compiled!") 38 | #else 39 | #endif // _MSC_VER 40 | 41 | #else // LAPACK present 42 | 43 | /* single precision (float) definitions */ 44 | #define LM_REAL float 45 | #define LM_PREFIX s 46 | 47 | #define SUBCNST(x) x##F 48 | #define CNST(x) SUBCNST(x) // force substitution 49 | 50 | #include "lmlec_core.c" // read in core code 51 | 52 | #undef LM_REAL 53 | #undef LM_PREFIX 54 | #undef SUBCNST 55 | #undef CNST 56 | 57 | /* double precision definitions */ 58 | #define LM_REAL double 59 | #define LM_PREFIX d 60 | 61 | #define CNST(x) (x) 62 | 63 | #include "lmlec_core.c" // read in core code 64 | 65 | #undef LM_REAL 66 | #undef LM_PREFIX 67 | #undef CNST 68 | 69 | #endif /* HAVE_LAPACK */ 70 | 71 | -------------------------------------------------------------------------------- /examples/coding.aln: -------------------------------------------------------------------------------- 1 | CLUSTAL W(1.81) multiple sequence alignment 2 | 3 | 4 | ec_K12.chr_fwd/3401506-3401703 TGCAGGCGTTACTTTTAGAACAGCAGGACGGCAAAACTCTCGCATCAGTACA--GACTCT 5 | ec_O157H7.chr_fwd/4138444-4138641 TGCAGGCGTTACTTTTAGAACAGCAGGACGGCAAAACTCTCGCATCAGTACA--GACTCT 6 | ec_APEC_O1.chr_fwd/3685781-3685978 TGCAGGCGTTACTTTTAGAACAGCAGGACGGCAAAACTCTCGCATCAGTACA--GACTCT 7 | ente638.chr_fwd/4000173-4000370 TGCAGGCATTGATCTTAGAACAACAAGACGGCAAAACCCTGGCTTCGGTTCA--ATCCAT 8 | shigFlex_2A.chr_fwd/3391056-3391253 TGCAGGCGTTACTTTTAGAACAGCAGGACGGCAAAACTCTCGCATCAGTACA--GACTCT 9 | salmTyph.chr_fwd/3400613-3400810 TGCAGGCGTTGATCTTAGAACAGCAGGACGGTAAAACCCTCGCATCCGTGCA--ACATCT 10 | salmEnte_PARATYPI_ATC.chr_fwd/3353535-3353732 TGCAGGCGTTGATCTTAGAACAGCAGGACGGTAAAACCCTCGCATCCGTGCA--ACATCT 11 | yersPest_CO92.chr_rev/569086-569283 TGCGAGCACTGATACTTGAGCAAATTGAAGGGCGTACCACCGCAGAAGTACGTCAAATTT 12 | 13 | 14 | ec_K12.chr_fwd/3401506-3401703 GGACGAAAGTCGCCTGCCGGAGGGCGATGTCACGGTCGATGTTCACTGGTCGAGCCTGAA 15 | ec_O157H7.chr_fwd/4138444-4138641 GGACGAAAGTCGCCTGCCGGAGGGCGATGTCACGGTCGATGTTCACTGGTCGAGCCTGAA 16 | ec_APEC_O1.chr_fwd/3685781-3685978 GGACGAAAGTCGCCAGCCGGAAGGCGATGTCACGGTTGATGTTCACTGGTCGAGCCTGAA 17 | ente638.chr_fwd/4000173-4000370 CGAGGCTACCCGCCTGCCCGAAGGCGACGTCACCGTTGACATTGACTGGTCCAGCCTGAA 18 | shigFlex_2A.chr_fwd/3391056-3391253 GGACGAACGTCGCCTGCCGGAGGGCGATGTCACGGTCGATGTTCACTGGTCGAGCCTGAA 19 | salmTyph.chr_fwd/3400613-3400810 CGAAGAGAGTCAACTGCCGGCAGGTGATGTGACGGTGGATGTCCACTGGTCCAGCCTGAA 20 | salmEnte_PARATYPI_ATC.chr_fwd/3353535-3353732 CGAAGAGAGTCAACTGCCGGCAGGTGATGTGACGGTGGATGTCCACTGGTCCAGCCTGAA 21 | yersPest_CO92.chr_rev/569086-569283 CGGCCTCA--CAACTGCCTGCGGGTAATGTCACCGTAGATGTCAATTGGTCCAGCCTGAA 22 | 23 | 24 | ec_K12.chr_fwd/3401506-3401703 CTATAAAGATGCGCTGG 25 | ec_O157H7.chr_fwd/4138444-4138641 CTATAAAGATGCGCTGG 26 | ec_APEC_O1.chr_fwd/3685781-3685978 CTACAAAGATGCGCTGG 27 | ente638.chr_fwd/4000173-4000370 TTACAAGGACGCGCTCG 28 | shigFlex_2A.chr_fwd/3391056-3391253 CTATAAAGATGCGCTGG 29 | salmTyph.chr_fwd/3400613-3400810 TTATAAAGATGCTCTGG 30 | salmEnte_PARATYPI_ATC.chr_fwd/3353535-3353732 TTATAAAGATGCTCTGG 31 | yersPest_CO92.chr_rev/569086-569283 TTATAAAGATGCGTTGG 32 | 33 | 34 | -------------------------------------------------------------------------------- /levmar/lm.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Levenberg - Marquardt non-linear minimization algorithm 4 | // Copyright (C) 2004 Manolis Lourakis (lourakis@ics.forth.gr) 5 | // Institute of Computer Science, Foundation for Research & Technology - Hellas 6 | // Heraklion, Crete, Greece. 7 | // 8 | // This program is free software; you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation; either version 2 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | ///////////////////////////////////////////////////////////////////////////////// 19 | 20 | /******************************************************************************** 21 | * Levenberg-Marquardt nonlinear minimization. The same core code is used with 22 | * appropriate #defines to derive single and double precision versions, see 23 | * also lm_core.c 24 | ********************************************************************************/ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "lm.h" 32 | #include "misc.h" 33 | 34 | #define EPSILON 1E-12 35 | #define ONE_THIRD 0.3333333334 /* 1.0/3.0 */ 36 | 37 | /* single precision (float) definitions */ 38 | #define LM_REAL float 39 | #define LM_PREFIX s 40 | 41 | #define LM_REAL_MAX FLT_MAX 42 | #define LM_REAL_MIN FLT_MIN 43 | #define LM_REAL_EPSILON FLT_EPSILON 44 | #define SUBCNST(x) x##F 45 | #define CNST(x) SUBCNST(x) // force substitution 46 | 47 | #include "lm_core.c" // read in core code 48 | 49 | #undef LM_REAL 50 | #undef LM_PREFIX 51 | #undef LM_REAL_MAX 52 | #undef LM_REAL_EPSILON 53 | #undef LM_REAL_MIN 54 | #undef SUBCNST 55 | #undef CNST 56 | 57 | /* double precision definitions */ 58 | #define LM_REAL double 59 | #define LM_PREFIX d 60 | 61 | #define LM_REAL_MAX DBL_MAX 62 | #define LM_REAL_MIN DBL_MIN 63 | #define LM_REAL_EPSILON DBL_EPSILON 64 | #define CNST(x) (x) 65 | 66 | #include "lm_core.c" // read in core code 67 | 68 | #undef LM_REAL 69 | #undef LM_PREFIX 70 | #undef LM_REAL_MAX 71 | #undef LM_REAL_EPSILON 72 | #undef LM_REAL_MIN 73 | #undef CNST 74 | -------------------------------------------------------------------------------- /levmar/lmbc.c: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Levenberg - Marquardt non-linear minimization algorithm 4 | // Copyright (C) 2004-05 Manolis Lourakis (lourakis@ics.forth.gr) 5 | // Institute of Computer Science, Foundation for Research & Technology - Hellas 6 | // Heraklion, Crete, Greece. 7 | // 8 | // This program is free software; you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation; either version 2 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | ///////////////////////////////////////////////////////////////////////////////// 19 | 20 | /******************************************************************************** 21 | * Box-constrained Levenberg-Marquardt nonlinear minimization. The same core code 22 | * is used with appropriate #defines to derive single and double precision versions, 23 | * see also lmbc_core.c 24 | ********************************************************************************/ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "lm.h" 32 | #include "misc.h" 33 | 34 | #define EPSILON 1E-12 35 | #define ONE_THIRD 0.3333333334 /* 1.0/3.0 */ 36 | 37 | /* single precision (float) definitions */ 38 | #define LM_REAL float 39 | #define LM_PREFIX s 40 | 41 | #define LM_REAL_MAX FLT_MAX 42 | #define LM_REAL_MIN FLT_MIN 43 | #define LM_REAL_EPSILON FLT_EPSILON 44 | #define SUBCNST(x) x##F 45 | #define CNST(x) SUBCNST(x) // force substitution 46 | 47 | #include "lmbc_core.c" // read in core code 48 | 49 | #undef LM_REAL 50 | #undef LM_PREFIX 51 | #undef LM_REAL_MAX 52 | #undef LM_REAL_EPSILON 53 | #undef LM_REAL_MIN 54 | #undef SUBCNST 55 | #undef CNST 56 | 57 | /* double precision definitions */ 58 | #define LM_REAL double 59 | #define LM_PREFIX d 60 | 61 | #define LM_REAL_MAX DBL_MAX 62 | #define LM_REAL_MIN DBL_MIN 63 | #define LM_REAL_EPSILON DBL_EPSILON 64 | #define CNST(x) (x) 65 | 66 | #include "lmbc_core.c" // read in core code 67 | 68 | #undef LM_REAL 69 | #undef LM_PREFIX 70 | #undef LM_REAL_MAX 71 | #undef LM_REAL_EPSILON 72 | #undef LM_REAL_MIN 73 | #undef CNST 74 | -------------------------------------------------------------------------------- /phyml/lk.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PHYML : a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #ifndef ML_H 14 | #define ML_H 15 | 16 | 17 | void Init_Tips_At_One_Site_Nucleotides_Float(char state,phydbl *p_lk); 18 | void Init_Tips_At_One_Site_AA_Float(char aa,phydbl *p_lk); 19 | void Get_All_Partial_Lk(arbre *tree,edge *b_fcus,node *a,node *d); 20 | void Get_All_Partial_Lk_Scale(arbre *tree,edge *b_fcus,node *a,node *d); 21 | void Post_Order_Lk(node *pere,node *fils, arbre *tree); 22 | void Pre_Order_Lk(node *pere,node *fils, arbre *tree); 23 | void Lk(arbre *tree); 24 | void Site_Lk(arbre *tree); 25 | phydbl Lk_At_Given_Edge(edge *b_fcus,arbre *tree); 26 | phydbl Return_Lk(arbre *tree); 27 | phydbl Return_Abs_Lk(arbre *tree); 28 | matrix *ML_Dist(allseq *data,model *mod); 29 | phydbl Lk_Given_Two_Seq(allseq *data,int numseq1,int numseq2,phydbl dist,model *mod,phydbl *loglk); 30 | void Unconstraint_Lk(arbre *tree); 31 | void Update_P_Lk(arbre *tree,edge *b_fcus,node *n); 32 | void Make_Tree_4_Lk(arbre *tree,allseq *alldata,int n_site); 33 | void Init_P_Lk_Tips_Double(arbre *tree); 34 | void Init_P_Lk_Tips_Int(arbre *tree); 35 | void Init_P_Lk_At_One_Node(node *a, arbre *tree); 36 | void Update_PMat_At_Given_Edge(edge *b_fcus, arbre *tree); 37 | void Sort_Sites_Based_On_Lk(arbre *tree); 38 | void Get_Partial_Lk_Scale(arbre *tree, edge *b_fcus, node *a, node *d); 39 | void Get_Partial_Lk(arbre *tree, edge *b_fcus, node *a, node *d); 40 | void Init_Tips_At_One_Site_Nucleotides_Int(char state, short int *p_pars); 41 | void Init_Tips_At_One_Site_AA_Int(char aa, short int *p_pars); 42 | void Update_P_Lk_Along_A_Path(node **path, int path_length, arbre *tree); 43 | phydbl Lk_Dist(phydbl *F, phydbl dist, model *mod); 44 | phydbl Update_Lk_At_Given_Edge(edge *b_fcus, arbre *tree); 45 | void Update_P_Lk_Greedy(arbre *tree, edge *b_fcus, node *n); 46 | void Get_All_Partial_Lk_Scale_Greedy(arbre *tree, edge *b_fcus, node *a, node *d); 47 | phydbl Lk_Core(edge *b, arbre *tree); 48 | phydbl Lk_Triplet(node *a, node *d, arbre *tree); 49 | void Print_Lk_Given_Edge_Recurr(node *a, node *d, edge *b, arbre *tree); 50 | phydbl *Post_Prob_Rates_At_Given_Edge(edge *b, phydbl *post_prob, arbre *tree); 51 | phydbl Lk_With_MAP_Branch_Rates(arbre *tree); 52 | 53 | 54 | 55 | #endif 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /seqgen/tree.h: -------------------------------------------------------------------------------- 1 | /* Header file to define tree and node structures */ 2 | 3 | /* 4 | Sequence Generator - seq-gen, version 1.3.2 5 | Copyright (c)1996-2004, Andrew Rambaut & Nick Grassly 6 | Department of Zoology, University of Oxford 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | 2. Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | 3. The names of its contributors may not be used to endorse or promote 21 | products derived from this software without specific prior written 22 | permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | Any feedback is very welcome. 38 | http://evolve.zoo.ox.ac.uk/software/Seq-Gen/ 39 | email: andrew.rambaut@zoo.ox.ac.uk 40 | */ 41 | 42 | #ifndef _TREE_H_ 43 | #define _TREE_H_ 44 | 45 | #define MAX_NAME_LEN 256 46 | 47 | typedef struct TNode TNode; 48 | struct TNode { 49 | TNode *branch0, *branch1, *branch2, *next; 50 | double length0, length1, length2, param; 51 | int tipNo; 52 | 53 | char *sequence; 54 | }; 55 | 56 | 57 | typedef struct TTree TTree; 58 | struct TTree { 59 | int rooted, lengths; 60 | TNode *root, *nodeList; 61 | int numTips, numNodes; 62 | double totalLength; 63 | char **names; 64 | TNode **tips; 65 | int capacity; 66 | }; 67 | 68 | #endif /* _TREE_H_ */ 69 | 70 | -------------------------------------------------------------------------------- /seqgen/model.h: -------------------------------------------------------------------------------- 1 | /* Header file for model.c */ 2 | 3 | /* 4 | Sequence Generator - seq-gen, version 1.3.2 5 | Copyright (c)1996-2004, Andrew Rambaut & Nick Grassly 6 | Department of Zoology, University of Oxford 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | 2. Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | 3. The names of its contributors may not be used to endorse or promote 21 | products derived from this software without specific prior written 22 | permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | Any feedback is very welcome. 38 | http://evolve.zoo.ox.ac.uk/software/Seq-Gen/ 39 | email: andrew.rambaut@zoo.ox.ac.uk 40 | */ 41 | 42 | #ifndef _MODEL_H_ 43 | #define _MODEL_H_ 44 | 45 | extern char *stateCharacters; 46 | 47 | enum { NONE=-1, F84, HKY, GTR, JTT, WAG, PAM, BLOSUM, MTREV, CPREV, GENERAL, numModels }; 48 | 49 | extern char *modelNames[numModels]; 50 | extern char *modelTitles[numModels]; 51 | 52 | extern int model, isNucModel, numStates, userFreqs, equalFreqs; 53 | 54 | extern double *freq, *addFreq; 55 | 56 | void SetModel(int theModel); 57 | void SetMatrix(double *matrix, double len); 58 | void SetVector(double *vector, short state, double len); 59 | 60 | #endif /* _MODEL_H_ */ 61 | -------------------------------------------------------------------------------- /levmar/README.txt: -------------------------------------------------------------------------------- 1 | ************************************************************** 2 | LEVMAR 3 | version 2.1.2 4 | By Manolis Lourakis 5 | 6 | Institute of Computer Science 7 | Foundation for Research and Technology - Hellas 8 | Heraklion, Crete, Greece 9 | ************************************************************** 10 | 11 | 12 | GENERAL 13 | This is levmar, a copylefted C/C++ implementation of the Levenberg-Marquardt non-linear 14 | least squares algorithm. levmar includes double and single precision LM versions, both 15 | with analytic and finite difference approximated jacobians. levmar also has some support 16 | for constrained non-linear least squares, allowing linear equation and box constraints. 17 | You have the following options regarding the solution of the underlying augmented normal 18 | equations: 19 | 20 | 1) Assuming that you have LAPACK (or an equivalent vendor library such as ESSL, MKL, 21 | NAG, ...) installed, you can use the included LAPACK-based solvers (default). 22 | 23 | 2) If you don't have LAPACK or decide not to use it, undefine HAVE_LAPACK in lm.h 24 | and a LAPACK-free, LU-based linear systems solver will by used. 25 | 26 | It is strongly recommended that you *do* employ LAPACK; if you don't have it already, 27 | I suggest getting clapack from http://www.netlib.org/clapack. However, LAPACK's 28 | use is not mandatory and the 2nd option makes levmar totally self-contained. 29 | See lmdemo.c for examples of use and http://www.ics.forth.gr/~lourakis/levmar 30 | for general comments. 31 | 32 | The mathematical theory behind levmar is described in the lecture notes entitled 33 | "Methods for Non-Linear Least Squares Problems", by K. Madsen, H.B. Nielsen and O. Tingleff, 34 | Technical University of Denmark (http://www.imm.dtu.dk/courses/02611/nllsq.pdf). 35 | 36 | 37 | COMPILATION 38 | - On a Linux/Unix system, typing "make" will build both levmar and the demo 39 | program using gcc. Alternatively, if Intel's C++ compiler is installed, it 40 | can be used by typing "make -f Makefile.icc". 41 | 42 | - Under Windows and if Visual C is installed & configured for command line 43 | use, type "nmake /f Makefile.vc" in a cmd window to build levmar and the 44 | demo program. In case of trouble, read the comments on top of Makefile.vc 45 | 46 | Notice that *_core.c files are not to be compiled directly; For example, 47 | Axb_core.c is included by Axb.c, to provide single and double precision 48 | routine versions. 49 | 50 | 51 | Send your comments/bug reports to lourakis@ics.forth.gr 52 | -------------------------------------------------------------------------------- /librna/energy_par.h: -------------------------------------------------------------------------------- 1 | /* 2 | prototypes for energy_par.c 3 | */ 4 | 5 | #include "energy_const.h" 6 | 7 | extern double lxc37; /* parameter for logarithmic loop 8 | energy extrapolation */ 9 | 10 | extern int stack37[NBPAIRS+1][NBPAIRS+1]; 11 | extern int enthalpies[NBPAIRS+1][NBPAIRS+1]; /* stack enthalpies */ 12 | extern int entropies[NBPAIRS+1][NBPAIRS+1]; /* not used anymore */ 13 | 14 | extern int hairpin37[31]; 15 | extern int bulge37[31]; 16 | extern int internal_loop37[31]; 17 | extern int internal2_energy; 18 | extern int old_mismatch_37[NBPAIRS+1][5][5]; 19 | extern int mismatchI37[NBPAIRS+1][5][5]; /* interior loop mismatches */ 20 | extern int mismatchH37[NBPAIRS+1][5][5]; /* same for hairpins */ 21 | extern int mismatchM37[NBPAIRS+1][5][5]; /* same for multiloops */ 22 | extern int mism_H[NBPAIRS+1][5][5]; /* mismatch enthalpies */ 23 | 24 | extern int dangle5_37[NBPAIRS+1][5]; /* 5' dangle exterior of pair */ 25 | extern int dangle3_37[NBPAIRS+1][5]; /* 3' dangle */ 26 | extern int dangle3_H[NBPAIRS+1][5]; /* corresponding enthalpies */ 27 | extern int dangle5_H[NBPAIRS+1][5]; 28 | 29 | extern int int11_37[NBPAIRS+1][NBPAIRS+1][5][5]; /* 1x1 interior loops */ 30 | extern int int11_H[NBPAIRS+1][NBPAIRS+1][5][5]; 31 | 32 | extern int int21_37[NBPAIRS+1][NBPAIRS+1][5][5][5]; /* 2x1 interior loops */ 33 | extern int int21_H[NBPAIRS+1][NBPAIRS+1][5][5][5]; 34 | 35 | extern int int22_37[NBPAIRS+1][NBPAIRS+1][5][5][5][5]; /* 2x2 interior loops */ 36 | extern int int22_H[NBPAIRS+1][NBPAIRS+1][5][5][5][5]; 37 | 38 | /* constants for linearly destabilizing contributions for multi-loops 39 | F = ML_closing + ML_intern*(k-1) + ML_BASE*u */ 40 | extern int ML_BASE37; 41 | extern int ML_closing37; 42 | extern int ML_intern37; 43 | 44 | /* Ninio-correction for asymmetric internal loops with branches n1 and n2 */ 45 | /* ninio_energy = min{max_ninio, |n1-n2|*F_ninio[min{4.0, n1, n2}] } */ 46 | extern int MAX_NINIO; /* maximum correction */ 47 | extern int F_ninio37[5]; 48 | 49 | /* penalty for helices terminated by AU (actually not GC) */ 50 | extern int TerminalAU; 51 | /* penalty for forming bi-molecular duplex */ 52 | extern int DuplexInit; 53 | /* stabilizing contribution due to special hairpins of size 4 (tetraloops) */ 54 | extern char Tetraloops[]; /* string containing the special tetraloops */ 55 | extern int TETRA_ENERGY37[]; /* Bonus energy for special tetraloops */ 56 | extern int TETRA_ENTH37; 57 | extern char Triloops[]; /* string containing the special triloops */ 58 | extern int Triloop_E37[]; /* Bonus energy for special Triloops */ 59 | 60 | extern double Tmeasure; /* temperature of param measurements */ 61 | -------------------------------------------------------------------------------- /.github/workflows/dist_archives.yaml: -------------------------------------------------------------------------------- 1 | name: Make distribution archives 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | config-flags: 7 | description: 'Configure flags to prepare the source directory' 8 | default: '' 9 | required: false 10 | type: string 11 | zip: 12 | description: 'Additionally create ZIP archive next to default GZIP' 13 | required: false 14 | default: false 15 | type: boolean 16 | artifact-name: 17 | description: 'Name of the artifact' 18 | required: false 19 | default: 'distribution-archives' 20 | type: string 21 | workflow_call: 22 | inputs: 23 | config-flags: 24 | description: 'Configure flags to prepare the source directory' 25 | default: '' 26 | required: false 27 | type: string 28 | zip: 29 | description: 'Additionally create ZIP archive next to default GZIP' 30 | required: false 31 | default: false 32 | type: boolean 33 | artifact-name: 34 | description: 'Name of the artifact' 35 | required: false 36 | default: 'distribution-archives' 37 | type: string 38 | outputs: 39 | version_number: 40 | description: "The Version number of this build" 41 | value: ${{ jobs.make_dist.outputs.version_number }} 42 | 43 | jobs: 44 | make_dist: 45 | runs-on: ubuntu-latest 46 | # Map the job outputs to step outputs 47 | outputs: 48 | version_number: ${{ steps.tarball.outputs.version_number }} 49 | 50 | steps: 51 | - name: Checkout 52 | uses: actions/checkout@v4 53 | - name: Install prerequisites 54 | run: | 55 | sudo apt-get update 56 | sudo apt-get -y install \ 57 | build-essential \ 58 | autoconf \ 59 | automake \ 60 | gengetopt \ 61 | libtool 62 | - name: Autotools setup 63 | run: | 64 | autoreconf -i 65 | - name: Configure 66 | run: ./configure ${{ inputs.config-flags }} 67 | - name: Make tarball 68 | id: tarball 69 | run: | 70 | make dist-gzip 71 | version_number=$(ls RNAcode-*.tar.gz) 72 | version_number="${version_number#RNAcode-}" 73 | version_number="${version_number%.tar.gz}" 74 | echo "version_number=${version_number}" >> "$GITHUB_OUTPUT" 75 | - name: Make ZIP 76 | if: ${{ inputs.zip }} 77 | run: make dist-zip 78 | - name: Upload artifacts 79 | uses: actions/upload-artifact@v4 80 | with: 81 | name: ${{ inputs.artifact-name }} 82 | path: | 83 | RNAcode-*.tar.gz 84 | RNAcode-*.zip 85 | retention-days: 3 86 | -------------------------------------------------------------------------------- /seqgen/treefile.h: -------------------------------------------------------------------------------- 1 | /* Header file for treefile.c */ 2 | 3 | /* 4 | Sequence Generator - seq-gen, version 1.3.2 5 | Copyright (c)1996-2004, Andrew Rambaut & Nick Grassly 6 | Department of Zoology, University of Oxford 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | 2. Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | 3. The names of its contributors may not be used to endorse or promote 21 | products derived from this software without specific prior written 22 | permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | Any feedback is very welcome. 38 | http://evolve.zoo.ox.ac.uk/software/Seq-Gen/ 39 | email: andrew.rambaut@zoo.ox.ac.uk 40 | */ 41 | 42 | #ifndef _TREEFILE_H_ 43 | #define _TREEFILE_H_ 44 | 45 | /* This contains the structures, TTree and TNode which */ 46 | /* can be edited to add more elements */ 47 | #include "tree.h" 48 | 49 | TTree *NewTree(); 50 | void DisposeTree(TTree *tree); 51 | void FreeTree(TTree *tree); 52 | void WriteAvailInfo(); 53 | 54 | int CountTrees(FILE *fv); 55 | void ReadTree(FILE *fv, TTree *tree, int treeNum, int numNames, char **names, 56 | int *outNumSites, double *outRelRate); 57 | int IsTreeAvail(FILE *fv); 58 | void WriteTree(FILE *fv, TTree *tree); 59 | 60 | void UnrootRTree(TTree *tree); 61 | void RerootUTree(TTree *tree, int tip); 62 | 63 | #endif /* _TREEFILE_H_ */ 64 | 65 | -------------------------------------------------------------------------------- /seqgen/global.h: -------------------------------------------------------------------------------- 1 | /* Header file for global.c */ 2 | 3 | /* 4 | Sequence Generator - seq-gen, version 1.3.2 5 | Copyright (c)1996-2004, Andrew Rambaut & Nick Grassly 6 | Department of Zoology, University of Oxford 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | 2. Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | 3. The names of its contributors may not be used to endorse or promote 21 | products derived from this software without specific prior written 22 | permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | Any feedback is very welcome. 38 | http://evolve.zoo.ox.ac.uk/software/Seq-Gen/ 39 | email: andrew.rambaut@zoo.ox.ac.uk 40 | */ 41 | 42 | #ifndef _GLOBAL_H_ 43 | #define _GLOBAL_H_ 44 | 45 | extern int verbose, verboseMemory, quiet, userSeed; 46 | extern long totalMem; 47 | extern unsigned long randomSeed; 48 | 49 | /* prototypes */ 50 | void *AllocMem(long n, char *name, char *func, int showInfo); 51 | void *CAllocMem(long n, char *name, char *func, int showInfo); 52 | 53 | int GetDoubleParams(int argc, char **argv, int *argn, char *pos, int numParams, double *params); 54 | int GetIntParams(int argc, char **argv, int *argn, char *pos, int numParams, int *params); 55 | int GetUnsignedLongParams(int argc, char **argv, int *argn, char *pos, int numParams, unsigned long *params); 56 | int GetStrParam(int argc, char **argv, int *argn, char *pos, char *param, int len); 57 | 58 | #endif /* _GLOBAL_H_ */ 59 | -------------------------------------------------------------------------------- /seqgen/nucmodels.h: -------------------------------------------------------------------------------- 1 | /* Header file for nucmodels.c */ 2 | 3 | /* 4 | Sequence Generator - seq-gen, version 1.3.2 5 | Copyright (c)1996-2004, Andrew Rambaut & Nick Grassly 6 | Department of Zoology, University of Oxford 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | 2. Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | 3. The names of its contributors may not be used to endorse or promote 21 | products derived from this software without specific prior written 22 | permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | Any feedback is very welcome. 38 | http://evolve.zoo.ox.ac.uk/software/Seq-Gen/ 39 | email: andrew.rambaut@zoo.ox.ac.uk 40 | */ 41 | 42 | #ifndef _NUC_MODELS_H_ 43 | #define _NUC_MODELS_H_ 44 | 45 | #include "evolve.h" 46 | 47 | #define NUM_NUC 4 48 | #define SQNUM_NUC 16 49 | #define CUNUM_NUC 256 50 | #define NUM_NUC_REL_RATES 6 51 | 52 | enum { NUC_NONE = -1, NUC_HKY, NUC_F84, NUC_GTR, numNucModels }; 53 | 54 | extern char *nucleotides; 55 | 56 | enum { A, C, G, T }; 57 | 58 | extern int equalTstv; 59 | 60 | extern double nucFreq[NUM_NUC]; 61 | extern double nucAddFreq[NUM_NUC]; 62 | extern double nucMatrix[MAX_RATE_CATS][SQNUM_NUC]; 63 | extern double nucVector[NUM_NUC]; 64 | 65 | extern double nucRelativeRates[NUM_NUC_REL_RATES]; 66 | extern double tstv, kappa; 67 | 68 | void SetNucModel(int theModel); 69 | void SetNucMatrix(double *matrix, double len); 70 | void SetNucVector(double *vector, short state, double len); 71 | 72 | #endif /* _NUC_MODELS_H_ */ 73 | -------------------------------------------------------------------------------- /seqgen/aamodels.h: -------------------------------------------------------------------------------- 1 | /* Header file for aamodels.c */ 2 | 3 | /* 4 | Sequence Generator - seq-gen, version 1.3.2 5 | Copyright (c)1996-2004, Andrew Rambaut & Nick Grassly 6 | Department of Zoology, University of Oxford 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | 2. Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | 3. The names of its contributors may not be used to endorse or promote 21 | products derived from this software without specific prior written 22 | permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | Any feedback is very welcome. 38 | http://evolve.zoo.ox.ac.uk/software/Seq-Gen/ 39 | email: andrew.rambaut@zoo.ox.ac.uk 40 | */ 41 | 42 | #ifndef _AA_MODELS_H_ 43 | #define _AA_MODELS_H_ 44 | 45 | #include "evolve.h" 46 | 47 | #define NUM_AA 20 48 | #define SQNUM_AA 400 49 | #define CUNUM_AA 8000 50 | #define NUM_AA_REL_RATES 190 51 | 52 | enum { AA_NONE = -1, AA_JTT, AA_WAG, AA_DAYHOFF78, AA_BLOSUM62, AA_MTREV24, AA_CPREV45, AA_GENERAL, numAAModels }; 53 | 54 | extern char *aminoAcids; 55 | 56 | enum { ala, arg, asn, asp, cys, gln, glu, gly, his, ileu, leu, lys, met, phe, pro, ser, thr, trp, tyr, val}; 57 | 58 | extern int aaFreqSet; 59 | 60 | extern double aaFreq[NUM_AA]; 61 | extern double aaAddFreq[NUM_AA]; 62 | extern double aaMatrix[MAX_RATE_CATS][SQNUM_AA]; 63 | extern double aaVector[NUM_AA]; 64 | 65 | extern double aaRelativeRate[NUM_AA_REL_RATES]; 66 | 67 | void SetAAModel(int theAAModel); 68 | void SetAAMatrix(double *matrix, double len); 69 | void SetAAVector(double *vector, short state, double len); 70 | 71 | #endif /* _AA_MODELS_H_ */ 72 | -------------------------------------------------------------------------------- /seqgen/evolve.h: -------------------------------------------------------------------------------- 1 | /* Header file for evolve.c */ 2 | 3 | /* 4 | Sequence Generator - seq-gen, version 1.3.2 5 | Copyright (c)1996-2004, Andrew Rambaut & Nick Grassly 6 | Department of Zoology, University of Oxford 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | 2. Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | 3. The names of its contributors may not be used to endorse or promote 21 | products derived from this software without specific prior written 22 | permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | Any feedback is very welcome. 38 | http://evolve.zoo.ox.ac.uk/software/Seq-Gen/ 39 | email: andrew.rambaut@zoo.ox.ac.uk 40 | */ 41 | 42 | 43 | #ifndef _EVOLVE_H_ 44 | #define _EVOLVE_H_ 45 | 46 | #include "tree.h" 47 | 48 | #define MAX_RATE_CATS 32 49 | 50 | extern int numTaxa, numSites, maxPartitions, numPartitions, fileFormat; 51 | 52 | extern double gammaShape, proportionInvariable; 53 | extern int numCats, rateHetero, invariableSites; 54 | extern double catRate[MAX_RATE_CATS]; 55 | 56 | enum { 57 | NoRates, 58 | CodonRates, 59 | GammaRates, 60 | DiscreteGammaRates 61 | }; 62 | 63 | enum { 64 | PHYLIPFormat, 65 | RelaxedFormat, 66 | NEXUSFormat 67 | }; 68 | 69 | /* prototypes */ 70 | 71 | void SetModel(int model); 72 | void SetCategories(); 73 | void CreateRates(); 74 | void CreateSequences(TTree *tree, int inNumSites); 75 | void EvolveSequences(TTree *tree, int inFromSite, int inNumSites, double scale, char *ancestor); 76 | 77 | void WriteSequences(FILE *fv, int treeNo, int datasetNo, TTree **treeSet, int *partitionLengths); 78 | 79 | void WriteAncestralSequences(FILE *fv, TTree *tree); 80 | 81 | void WriteRates(FILE *fv); 82 | 83 | void FreeRates(); 84 | 85 | 86 | #endif /* _EVOLVE_H_ */ 87 | -------------------------------------------------------------------------------- /seqgen/progress.c: -------------------------------------------------------------------------------- 1 | /* 2 | Sequence Generator - seq-gen, version 1.3.2 3 | Copyright (c)1996-2004, Andrew Rambaut & Nick Grassly 4 | Department of Zoology, University of Oxford 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | 3. The names of its contributors may not be used to endorse or promote 19 | products derived from this software without specific prior written 20 | permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | Any feedback is very welcome. 36 | http://evolve.zoo.ox.ac.uk/software/Seq-Gen/ 37 | email: andrew.rambaut@zoo.ox.ac.uk 38 | */ 39 | 40 | #include 41 | #include 42 | #include "progress.h" 43 | 44 | static int barLength, dotGap, dots, bar; 45 | 46 | /*********************/ 47 | void InitProgressBar(int total) 48 | { 49 | barLength=total; 50 | dotGap=1; 51 | if (barLength>MAX_BAR_LENGTH) { 52 | dotGap=barLength/MAX_BAR_LENGTH; 53 | if (barLength%dotGap) 54 | barLength=(barLength/dotGap)+1; 55 | else 56 | barLength/=dotGap; 57 | } 58 | } 59 | 60 | 61 | /*********************/ 62 | void DrawProgressBar() 63 | { 64 | int i; 65 | 66 | if (barLength<2) 67 | return; 68 | 69 | fprintf(stderr, "0%%|"); 70 | for (i=0; i<(barLength); i++) 71 | fputc('_', stderr); 72 | fprintf(stderr, "|100%%\n ["); 73 | fflush(stderr); 74 | dots=0; 75 | bar=0; 76 | } 77 | 78 | 79 | /*********************/ 80 | void ProgressBar() 81 | { 82 | if (barLength<2) 83 | return; 84 | 85 | if (bar%dotGap==0) { 86 | fputc('.', stderr); 87 | fflush(stderr); 88 | dots++; 89 | if (dots==barLength) { 90 | fputc(']', stderr); 91 | fputc('\n', stderr); 92 | } 93 | fflush(stderr); 94 | } 95 | 96 | bar++; 97 | } 98 | 99 | 100 | -------------------------------------------------------------------------------- /phyml/mg.h: -------------------------------------------------------------------------------- 1 | #ifndef MULTIGENE_H 2 | #define MULTIGENE_H 3 | 4 | #include "utilities.h" 5 | 6 | void Menu_Supertree(option *input); 7 | void Mg_Print_Nodes(node *a, node *d, superarbre *st); 8 | superarbre *Mg_Make_Superarbre_Light(option *input); 9 | void Mg_Make_Superarbre_Full(superarbre *st, option *input, allseq **data); 10 | void Mg_Get_List_Of_Reachable_Tips(node *a, node *d, allseq **data, superarbre *st); 11 | void Mg_Get_List_Of_Reachable_Tips_Pre(node *a, node *d, superarbre *st); 12 | void Mg_Get_List_Of_Reachable_Tips_Post(node *a, node *d, superarbre *st); 13 | void Mg_Prune_St_Topo(arbre *tree, allseq *data, superarbre *st); 14 | void Mg_Match_St_Nodes_In_Gt_Recurr(node *a_gt, node *d_gt, node *a_st, node *d_st, arbre *gt, superarbre *st); 15 | void Mg_Match_St_Nodes_In_Gt(arbre *tree, superarbre *st); 16 | void Mg_Match_St_Edges_In_Gt(arbre *gt, superarbre *st); 17 | void Mg_Match_St_Edges_In_Gt_Recurr(node *a, node *d, node *a_st, node *d_st, arbre *gt, superarbre *st); 18 | void Mg_Simu(superarbre *tr); 19 | int Mg_Mov_Backward_Topo_Bl(superarbre *st, phydbl lk_old, edge **tested_b, int n_tested); 20 | int Mg_Get_Species_Found_In_St(superarbre *st, allseq *data); 21 | void Mg_Map_St_Nodes_In_Gt_Pre(node *a_st, node *d_st, arbre *gt, superarbre *st); 22 | void Mg_Map_St_Nodes_In_Gt_Post(node *a_st, node *d_st, arbre *gt, superarbre *st); 23 | void Mg_Map_St_Nodes_In_Gt(arbre *gt, superarbre *st); 24 | void Mg_Map_St_Nodes_In_Gt_One_Edge(node *a_st, node *d_st, edge *b_st, arbre *gt, superarbre *st); 25 | void Mg_Map_St_Edges_In_Gt(arbre *gt, superarbre *st); 26 | phydbl Mg_Lk(superarbre *st); 27 | int Mg_Pars(superarbre *st); 28 | int Mg_Spr(phydbl init_lnL, superarbre *st); 29 | void Mg_Speed_Spr(superarbre *st); 30 | int Map_Spr_Move(edge *st_pruned, edge *st_target, node *st_link, arbre *gt, superarbre *st); 31 | void Mg_Test_All_Spr_Targets(edge *pruned, node *n_link, superarbre *st); 32 | void Mg_Test_One_Spr_Target_Recur(node *a, node *d, edge *target, edge *pruned, node *n_link, superarbre *st); 33 | void Mg_Test_One_Spr_Target(edge *st_p, edge *st_t, node *n_link, superarbre *st); 34 | int Mg_Test_List_Of_Regraft_Pos(spr **st_spr_list, int list_size, superarbre *st); 35 | int Mg_Try_One_Spr_Move(spr *st_move, superarbre *st); 36 | void Mg_Map_Gt_Edges_In_St(arbre *gt, superarbre *st); 37 | void Mg_NNI(edge *st_b, superarbre *st); 38 | void Mg_Swap(node *st_a, node *st_b, node *st_c, node *st_d, superarbre *st); 39 | void Mg_Set_Bl(double **bl, superarbre *st); 40 | void Mg_Restore_Br_Len(superarbre *st); 41 | void Mg_Record_Br_Len(superarbre *st); 42 | phydbl Mg_Lk_At_Given_Edge(edge *st_b, superarbre *st); 43 | phydbl Mg_Update_Lk_At_Given_Edge(edge *st_b, superarbre *st); 44 | void Mg_Fill_Model_Partitions_Table(superarbre *st); 45 | phydbl Mg_Br_Len_Brent(edge *st_b, superarbre *tree); 46 | void Mg_Initialise_Bl_Partition(superarbre *st); 47 | void Mg_Update_P_Lk(edge *st_b, node *st_n, superarbre *st); 48 | void Mg_Optimize_Br_Len_Serie(node *st_a, node *st_d, edge *st_b, superarbre *st); 49 | void Mg_Update_Bl_Swaped(edge **st_b, int n, superarbre *st); 50 | void Mg_Update_Bl(phydbl fact, superarbre *st); 51 | void Mg_Make_N_Swap(edge **st_b, int beg, int end, superarbre *st); 52 | void Mg_Do_Mapping(superarbre *st); 53 | void Mg_Update_PMat(edge *st_b, superarbre *st); 54 | void Mg_Print_Bl(superarbre *st); 55 | void Mg_Check_Extra_Taxa(superarbre *st); 56 | int MG_main(int argc, char **argv); 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /src/weight.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | float *weights(float **D, int N) { 7 | float **DD, s; 8 | float *aans; 9 | float MINDIST = 0.000001; 10 | int i,j; 11 | 12 | /** working arrays **/ 13 | DD = (float **) malloc(sizeof(float*)*N); 14 | for(i=0;i amax) { 93 | pivot[k] = i; 94 | amax = absa; 95 | } 96 | } 97 | 98 | if (amax == 0.) goto endf; 99 | 100 | 101 | // COEFFICIENTS MATRIX IS SINGULAR 102 | 103 | 104 | if (pivot[k] != k) { 105 | 106 | // SWITCH ROWS K AND PIVOT(K) 107 | 108 | i = pivot[k]; 109 | temp = b[k]; 110 | b[k] = b[i]; 111 | b[i] = temp; 112 | 113 | for (j = k; j < N; j++) { 114 | temp = a[k][j]; 115 | a[k][j] = a[i][j]; 116 | a[i][j] = temp; 117 | } 118 | } 119 | 120 | /* PERFORM STEP #K OF ELIMINATION */ 121 | 122 | for (i = k + 1; i < N; i++) { 123 | mult = a[i][k] / a[k][ k]; 124 | a[i][k] = mult; 125 | b[i] =b[i] - mult * b[k]; 126 | 127 | for (j = k + 1; j < N; j++) 128 | a[i][j] = a[i][j] - mult * a[k][j]; 129 | } 130 | 131 | } 132 | if (a[N-1][N-1] == 0.) goto endf; // COEFFICIENT MATRIX IS SINGULAR 133 | 134 | 135 | /* SOLVE FOR SOLUTION X USING BACK SUBSTITUTION */ 136 | 137 | for (i= N-1; i>= 0; i--) { 138 | sum = 0.; 139 | for (j = i+1; j < N; j++) 140 | sum =sum+ a[i][j] * b[j]; 141 | 142 | b[i] = (b[i] - sum)/a[i][i]; 143 | } 144 | 145 | endf: 146 | return 1; 147 | } 148 | 149 | -------------------------------------------------------------------------------- /levmar/misc.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Levenberg - Marquardt non-linear minimization algorithm 4 | // Copyright (C) 2004 Manolis Lourakis (lourakis@ics.forth.gr) 5 | // Institute of Computer Science, Foundation for Research & Technology - Hellas 6 | // Heraklion, Crete, Greece. 7 | // 8 | // This program is free software; you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation; either version 2 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | ///////////////////////////////////////////////////////////////////////////////// 19 | 20 | #ifndef _MISC_H_ 21 | #define _MISC_H_ 22 | 23 | #define LCAT_(a, b) #a b 24 | #define LCAT(a, b) LCAT_(a, b) // force substitution 25 | #define RCAT_(a, b) a #b 26 | #define RCAT(a, b) RCAT_(a, b) // force substitution 27 | 28 | #define __BLOCKSZ__ 32 /* block size for cache-friendly matrix-matrix multiply. It should be 29 | * such that __BLOCKSZ__^2*sizeof(LM_REAL) is smaller than the CPU (L1) 30 | * data cache size. Notice that a value of 32 when LM_REAL=double assumes 31 | * an 8Kb L1 data cache (32*32*8=8K). This is a concervative choice since 32 | * newer Pentium 4s have a L1 data cache of size 16K, capable of holding 33 | * up to 45x45 double blocks. 34 | */ 35 | #define __BLOCKSZ__SQ (__BLOCKSZ__)*(__BLOCKSZ__) 36 | 37 | #ifdef _MSC_VER 38 | #define inline __inline //MSVC 39 | #elif !defined(__GNUC__) 40 | #define inline //other than MSVC, GCC: define empty 41 | #endif 42 | 43 | /* add a prefix in front of a token */ 44 | #define LM_CAT__(a, b) a ## b 45 | #define LM_CAT_(a, b) LM_CAT__(a, b) // force substitution 46 | #define LM_ADD_PREFIX(s) LM_CAT_(LM_PREFIX, s) 47 | 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | 52 | /* blocking-based matrix multiply */ 53 | extern void strans_mat_mat_mult(float *a, float *b, int n, int m); 54 | extern void dtrans_mat_mat_mult(double *a, double *b, int n, int m); 55 | 56 | /* forward finite differences */ 57 | extern void sfdif_forw_jac_approx(void (*func)(float *p, float *hx, int m, int n, void *adata), 58 | float *p, float *hx, float *hxx, float delta, 59 | float *jac, int m, int n, void *adata); 60 | extern void dfdif_forw_jac_approx(void (*func)(double *p, double *hx, int m, int n, void *adata), 61 | double *p, double *hx, double *hxx, double delta, 62 | double *jac, int m, int n, void *adata); 63 | 64 | /* central finite differences */ 65 | extern void sfdif_cent_jac_approx(void (*func)(float *p, float *hx, int m, int n, void *adata), 66 | float *p, float *hxm, float *hxp, float delta, 67 | float *jac, int m, int n, void *adata); 68 | extern void dfdif_cent_jac_approx(void (*func)(double *p, double *hx, int m, int n, void *adata), 69 | double *p, double *hxm, double *hxp, double delta, 70 | double *jac, int m, int n, void *adata); 71 | 72 | /* covariance of LS fit */ 73 | extern int slevmar_covar(float *JtJ, float *C, float sumsq, int m, int n); 74 | extern int dlevmar_covar(double *JtJ, double *C, double sumsq, int m, int n); 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /* _MISC_H */ 81 | -------------------------------------------------------------------------------- /librna/pair_mat.h: -------------------------------------------------------------------------------- 1 | #include 2 | #define NBASES 8 3 | /*@notnull@*/ 4 | static const char Law_and_Order[] = "_ACGUTXKI"; 5 | static int BP_pair[NBASES][NBASES]= 6 | /* _ A C G U X K I */ 7 | {{ 0, 0, 0, 0, 0, 0, 0, 0}, 8 | { 0, 0, 0, 0, 5, 0, 0, 5}, 9 | { 0, 0, 0, 1, 0, 0, 0, 0}, 10 | { 0, 0, 2, 0, 3, 0, 0, 0}, 11 | { 0, 6, 0, 4, 0, 0, 0, 6}, 12 | { 0, 0, 0, 0, 0, 0, 2, 0}, 13 | { 0, 0, 0, 0, 0, 1, 0, 0}, 14 | { 0, 6, 0, 0, 5, 0, 0, 0}}; 15 | 16 | #define MAXALPHA 20 /* maximal length of alphabet */ 17 | 18 | static short alias[MAXALPHA+1]; 19 | static int pair[MAXALPHA+1][MAXALPHA+1]; 20 | /* rtype[pair[i][j]]:=pair[j][i] */ 21 | static int rtype[8] = {0, 2, 1, 4, 3, 6, 5, 7}; 22 | 23 | /* for backward compatibility */ 24 | #define ENCODE(c) encode_char(c) 25 | 26 | static int encode_char(char c) { 27 | /* return numerical representation of base used e.g. in pair[][] */ 28 | int code; 29 | if (energy_set>0) code = (int) (c-'A')+1; 30 | else { 31 | char *pos; 32 | pos = strchr(Law_and_Order, c); 33 | if (pos==NULL) code=0; 34 | else code = (int) (pos-Law_and_Order); 35 | if (code>4) code--; /* make T and U equivalent */ 36 | } 37 | return code; 38 | } 39 | 40 | /*@+boolint +charint@*/ 41 | /*@null@*/ 42 | extern char *nonstandards; 43 | extern void nrerror(const char message[]); 44 | static void make_pair_matrix(void) 45 | { 46 | int i,j; 47 | 48 | if (energy_set==0) { 49 | for (i=0; i<5; i++) alias[i] = (short) i; 50 | alias[5] = 3; /* X <-> G */ 51 | alias[6] = 2; /* K <-> C */ 52 | alias[7] = 0; /* I <-> default base '@' */ 53 | for (i=0; i G */ 75 | alias[i++] = 2; /* B <-> C */ 76 | } 77 | for (i=1; i GC */ 79 | i++; 80 | pair[i][i-1] = 1; /* BA <-> CG */ 81 | } 82 | } 83 | else if (energy_set==2) { 84 | for (i=1; i A*/ 86 | alias[i++] = 4; /* B <-> U */ 87 | } 88 | for (i=1; i AU */ 90 | i++; 91 | pair[i][i-1] = 6; /* BA <-> UA */ 92 | } 93 | } 94 | else if (energy_set==3) { 95 | for (i=1; i G */ 97 | alias[i++] = 2; /* B <-> C */ 98 | alias[i++] = 1; /* C <-> A */ 99 | alias[i++] = 4; /* D <-> U */ 100 | } 101 | for (i=1; i GC */ 103 | i++; 104 | pair[i][i-1] = 1; /* BA <-> CG */ 105 | i++; 106 | pair[i][i+1] = 5; /* CD <-> AU */ 107 | i++; 108 | pair[i][i-1] = 6; /* DC <-> UA */ 109 | } 110 | } 111 | else nrerror("What energy_set are YOU using??"); 112 | for (i=0; i<=MAXALPHA; i++) { 113 | for (j=0; j<=MAXALPHA; j++) 114 | rtype[pair[i][j]] = pair[j][i]; 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/score.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2009, Stefan Washietl 2 | 3 | This file is part of RNAcode. 4 | 5 | RNAcode is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | RNAcode is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with RNAcode. If not, see . */ 17 | 18 | #ifndef _SCORE_H_ 19 | #define _SCORE_H_ 20 | 21 | #include "rnaz_utils.h" 22 | #include "tree.h" 23 | #include "treeSimulate.h" 24 | 25 | #define UNDEF -9.0 26 | #define MINUS_INF -99.0 27 | 28 | #define MAX(x,y) (((x)>(y)) ? (x) : (y)) 29 | #define MAX3(x,y,z) (MAX( (MAX((x),(y))) ,(z))) 30 | #define CMP(x,y) (((x) > (y) ? ((x)-(y)) : ((y)-(x))) < 0.00001) 31 | 32 | typedef struct _bgModel bgModel; 33 | 34 | struct _bgModel { 35 | 36 | float scores[4]; 37 | float probs[4]; 38 | float kappa; 39 | float dist; 40 | float freqs[4]; 41 | int** matrix; 42 | float weight; 43 | 44 | }; 45 | 46 | typedef struct _segmentStats segmentStats; 47 | 48 | struct _segmentStats { 49 | 50 | int start; /* Relative start position (nt) */ 51 | int end; 52 | int startGenomic; /* Absolute genomic start/end position when MAF is given */ 53 | int endGenomic; 54 | int startSite; /* Relative start/end in amino acids */ 55 | int endSite; 56 | int strand; /* Strand '+' or '-' */ 57 | int frame; /* Frame 1,2,3 */ 58 | char *name; 59 | float score; 60 | float pvalue; 61 | int hide; 62 | 63 | }; 64 | 65 | typedef struct _backtrackData backtrackData; 66 | 67 | struct _backtrackData { 68 | float* scores; 69 | int* z; 70 | int* states; 71 | int *transitions; // 0 stay the same, 1 ... Omega, 2 ... Delta; 72 | }; 73 | 74 | 75 | 76 | 77 | 78 | /* Values set in main() */ 79 | extern int ntMap[256]; 80 | 81 | extern int transcode[4][4][4]; 82 | 83 | float probHKY(int i, int j, float d, float freqs[4], float kappa); 84 | 85 | int** getScoringMatrix(); 86 | 87 | void freeScoringMatrix(int** matrix); 88 | 89 | void calculateBG(bgModel* models); 90 | 91 | void stripGaps(struct aln* AS[]); 92 | 93 | void countFreqsMono(const struct aln *alignment[], float freqs[]); 94 | 95 | float* sumOfPairScore(bgModel* models, const struct aln *alignment[],int from, int to); 96 | 97 | float* getCumSum(float* scores, int N); 98 | 99 | bgModel* getModelMatrix(TTree* tree, struct aln *alignment[], float kappa); 100 | 101 | void freeModelMatrix(bgModel* models, int N); 102 | 103 | int getExtremeValuePars(TTree* tree, const struct aln *alignment[], 104 | int sampleN, float maxNativeScore, float* parMu, float* parLambda); 105 | 106 | segmentStats* getHSS(float** S, const struct aln** inputAln, char strand); 107 | 108 | void getPairwiseScoreMatrix(bgModel* models, const struct aln *alignment[]); 109 | float** getMultipleScoreMatrix(float**** Sk, bgModel* models, const struct aln *alignment[]); 110 | 111 | backtrackData* backtrack(int opt_b, int opt_i, float**** SSk , const struct aln *alignment[]); 112 | 113 | void freeSk (float**** S, const struct aln *alignment[]); 114 | void freeS (float** S, const struct aln *alignment[]); 115 | 116 | segmentStats* scoreAln(const struct aln *alignment[], TTree* tree, float kappa, int backtrack); 117 | 118 | bgModel* getModels(TTree* tree, struct aln *alignment[], float kappa); 119 | 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | wash/rnacode @ GitHub 9 | 10 | 33 | 34 | 35 | 36 | 37 | Fork me on GitHub 38 | 39 |
40 | 41 |
42 | 43 | 44 | 45 | 46 |
47 | 48 |

rnacode 49 | by wash

50 | 51 |
52 | RNAcode - Analyze the protein coding potential in multiple sequence alignments 53 |
54 | 55 |

The purpose of RNA code is to detect protein coding regions in a set of homologous nucleotide sequences. RNAcode relies on evolutionary signatures, mainly synonymous/conservative mutations and conservation of the reading frame. These characteristics indicate negative selection acting on an encoded protein and allow sensitive and specific detection of coding regions. 56 | 57 | RNAcode does not rely on any species specific sequence characteristics whatsoever and does not use any machine learning techniques. 58 | 59 | The only input required for RNAcode is a multiple sequence alignment either in MAF or Clustal W format. RNAcode reports local regions with high coding potential and an associated p-value. 60 | 61 | 62 |

Install

63 |

Extract the file and run: 64 | ./configure 65 | make 66 | make install (as root) 67 | 68 | See file INSTALL for details

69 |

License

70 |

RNAcode is licenced under The GNU General Public License version 3.

71 |

Authors

72 |

Stefan Washietl (washietl@ebi.ac.uk)

73 |

Contact

74 |

Stefan Washietl (washietl@ebi.ac.uk)

75 | 76 | 77 |

Download

78 |

79 | You can download this project in either 80 | zip or 81 | tar formats. 82 |

83 |

You can also clone the project with Git 84 | by running: 85 |

$ git clone git://github.com/wash/rnacode
86 |

87 | 88 | 91 | 92 |
93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /librna/aln_util.c: -------------------------------------------------------------------------------- 1 | /* 2 | aln_util.c 3 | Helper functions frelated to alignments 4 | */ 5 | /* Last changed Time-stamp: <2006-01-16 11:42:38 ivo> */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "utils.h" 15 | #include "fold_vars.h" 16 | #include "pair_mat.h" 17 | /*@unused@*/ 18 | static char rcsid[] = "$Id: aln_util.c,v 1.1 2007-07-22 20:58:48 wash Exp $"; 19 | 20 | #define MAX_NUM_NAMES 500 21 | int read_clustal(FILE *clust, char *AlignedSeqs[], char *names[]) { 22 | char *line, name[100]="", *seq; 23 | int n, nn=0, num_seq = 0; 24 | 25 | if ((line=get_line(clust)) == NULL) { 26 | fprintf(stderr, "Empty CLUSTAL file\n"); return 0; 27 | } 28 | 29 | if (strncmp(line,"CLUSTAL", 7) !=0) { 30 | fprintf(stderr, "This doesn't look like a CLUSTAL file, sorry\n"); 31 | free(line); return 0; 32 | } 33 | free(line); 34 | line = get_line(clust); 35 | 36 | while (line!=NULL) { 37 | if (((n=strlen(line))<4) || isspace((int)line[0])) { 38 | /* skip non-sequence line */ 39 | free(line); line = get_line(clust); 40 | nn=0; /* reset seqence number */ 41 | continue; 42 | } 43 | 44 | seq = (char *) space( (n+1)*sizeof(char) ); 45 | sscanf(line,"%99s %s", name, seq); 46 | if (nn == num_seq) { /* first time */ 47 | names[nn] = strdup(name); 48 | AlignedSeqs[nn] = strdup(seq); 49 | } 50 | else { 51 | if (strcmp(name, names[nn])!=0) { 52 | /* name doesn't match */ 53 | fprintf(stderr, 54 | "Sorry, your file is fucked up (inconsitent seq-names)\n"); 55 | free(line); free(seq); 56 | return 0; 57 | } 58 | AlignedSeqs[nn] = (char *) 59 | xrealloc(AlignedSeqs[nn], strlen(seq)+strlen(AlignedSeqs[nn])+1); 60 | strcat(AlignedSeqs[nn], seq); 61 | } 62 | nn++; 63 | if (nn>num_seq) num_seq = nn; 64 | free(seq); 65 | free(line); 66 | if (num_seq>=MAX_NUM_NAMES) { 67 | fprintf(stderr, "Too many sequences in CLUSTAL file"); 68 | return 0; 69 | } 70 | 71 | line = get_line(clust); 72 | } 73 | 74 | AlignedSeqs[num_seq] = NULL; 75 | names[num_seq] = NULL; 76 | if (num_seq == 0) { 77 | fprintf(stderr, "No sequences found in CLSUATL file\n"); 78 | return 0; 79 | } 80 | n = strlen(AlignedSeqs[0]); 81 | for (nn=1; nnfm) {c=s, fm=freq[c];} 105 | if (s>4) s++; /* skip T */ 106 | string[i]=Law_and_Order[c]; 107 | } 108 | return string; 109 | } 110 | 111 | /* IUP nucleotide classes indexed by a bit string of the present bases */ 112 | /* A C AC G AG CG ACG U AU CU ACU GU AGU CGU ACGU */ 113 | static char IUP[17] = "-ACMGRSVUWYHKDBN"; 114 | char *consens_mis(const char*AS[]) { 115 | /* MIS displays the 'most informative sequence' (Freyhult et al 2004), 116 | elements in columns with frequency greater than the background 117 | frequency are projected into iupac notation. Columns where gaps are 118 | over-represented are in lower case. */ 119 | 120 | char *cons; 121 | int i, s, n, N, c; 122 | int bgfreq[8] = {0,0,0,0,0,0,0,0}; 123 | 124 | n = strlen(AS[0]); 125 | for (N=0; AS[N]!=NULL; N++); 126 | cons = (char *) space((n+1)*sizeof(char)); 127 | 128 | for (i=0; i4) c=5; 132 | bgfreq[c]++; 133 | } 134 | 135 | for (i=0; i4) c=5; 141 | freq[c]++; 142 | } 143 | for (c=4; c>0; c--) { 144 | code <<=1; 145 | if (freq[c]*n>=bgfreq[c]) code++; 146 | } 147 | cons[i] = IUP[code]; 148 | if (freq[0]*n>bgfreq[0]) 149 | cons[i] = tolower(IUP[code]); 150 | } 151 | return cons; 152 | } 153 | -------------------------------------------------------------------------------- /phyml/rates.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PhyML: a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences. 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward. 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | 14 | /* Routines for molecular clock trees and molecular dating */ 15 | 16 | #include "spr.h" 17 | #include "utilities.h" 18 | #include "lk.h" 19 | #include "optimiz.h" 20 | #include "bionj.h" 21 | #include "models.h" 22 | #include "free.h" 23 | #include "options.h" 24 | #include "simu.h" 25 | #include "eigen.h" 26 | #include "pars.h" 27 | #include "alrt.h" 28 | #include "mc.h" 29 | #include "m4.h" 30 | #include "draw.h" 31 | #include "rates.h" 32 | 33 | 34 | 35 | 36 | /*********************************************************/ 37 | 38 | void RATES_Monte_Carlo_Mean_Rates(arbre *tree) 39 | { 40 | RATES_Monte_Carlo_Mean_Rates_Pre(tree->n_root,tree->n_root->v[0],NULL,1.0,tree); 41 | RATES_Monte_Carlo_Mean_Rates_Pre(tree->n_root,tree->n_root->v[1],NULL,1.0,tree); 42 | } 43 | 44 | /*********************************************************/ 45 | 46 | void RATES_Monte_Carlo_Mean_Rates_Pre(node *a, node *d, edge *b, phydbl curr_rate, arbre *tree) 47 | { 48 | if(b) 49 | { 50 | phydbl curr_t, next_t, mean_rate; 51 | phydbl shape,exp; 52 | 53 | /**/ 54 | shape = 1.0; 55 | /**/ 56 | 57 | mean_rate = curr_rate; 58 | curr_t = a->t - Rexp(tree->rates->lexp[b->num]);; 59 | 60 | 61 | while(curr_t > d->t) 62 | { 63 | curr_rate = Rgamma(shape,tree->rates->br_r[b->num] / shape); 64 | exp = Rexp(tree->rates->lexp[b->num]); 65 | 66 | /* printf("\n. curr_rate=%f mean_r=%f exp=%f curr_t=%f lim=%f", */ 67 | /* curr_rate,mean_rate,exp,curr_t,d->t); */ 68 | 69 | next_t = curr_t - exp; 70 | 71 | if(next_t > d->t) 72 | { 73 | mean_rate = (1./(a->t - next_t)) * (mean_rate * (a->t - curr_t) + curr_rate * (curr_t - next_t)); 74 | } 75 | else 76 | { 77 | mean_rate = (1./(a->t - d->t)) * (mean_rate * (a->t - curr_t) + curr_rate * (curr_t - d->t)); 78 | } 79 | 80 | curr_t = next_t; 81 | } 82 | 83 | tree->rates->mc_mr[d->num][tree->rates->curr_mc_run] = mean_rate; 84 | /* printf("\n. %3d %f %f",d->num,mean_rate,tree->rates->br_r[b->num]); */ 85 | } 86 | 87 | if(d->tax) return; 88 | else 89 | { 90 | int i; 91 | For(i,3) 92 | { 93 | if((d->v[i] != a) && (d->b[i] != tree->e_root)) 94 | { 95 | RATES_Monte_Carlo_Mean_Rates_Pre(d,d->v[i],d->b[i],curr_rate,tree); 96 | } 97 | } 98 | } 99 | return; 100 | } 101 | 102 | /*********************************************************/ 103 | 104 | void RATES_Print_Rates(arbre *tree) 105 | { 106 | RATES_Print_Rates_Pre(tree->n_root,tree->n_root->v[0],NULL,tree); 107 | RATES_Print_Rates_Pre(tree->n_root,tree->n_root->v[1],NULL,tree); 108 | } 109 | 110 | /*********************************************************/ 111 | 112 | void RATES_Print_Rates_Pre(node *a, node *d, edge *b, arbre *tree) 113 | { 114 | 115 | if(b) 116 | { 117 | printf("\n. Edge %3d m_rate = %10f r_rate = %10f t_a = %15f t_d = %15f", 118 | b->num, 119 | tree->rates->mean_r, 120 | tree->rates->br_r[b->num], 121 | a->t,d->t); 122 | } 123 | if(d->tax) return; 124 | else 125 | { 126 | int i; 127 | 128 | For(i,3) 129 | { 130 | if((d->v[i] != a) && (d->b[i] != tree->e_root)) 131 | { 132 | RATES_Print_Rates_Pre(d,d->v[i],d->b[i],tree); 133 | } 134 | } 135 | } 136 | } 137 | 138 | /*********************************************************/ 139 | 140 | trate *RATES_Make_Rate_Struct(arbre *tree) 141 | { 142 | trate *rates; 143 | 144 | rates = (trate *)mCalloc(1,sizeof(trate)); 145 | rates->br_r = (phydbl *)mCalloc(2*tree->n_otu-3,sizeof(phydbl)); 146 | rates->lexp = (phydbl *)mCalloc(2*tree->n_otu-3,sizeof(phydbl)); 147 | rates->mc_mr = (phydbl **)mCalloc(2*tree->n_otu-1,sizeof(phydbl *)); 148 | 149 | return rates; 150 | } 151 | 152 | /*********************************************************/ 153 | 154 | void RATES_Init_Rate_Struct(trate *rates, arbre *tree) 155 | { 156 | int i; 157 | 158 | rates->n_mc_runs = 500; 159 | rates->mean_r = 0.00001; 160 | rates->curr_mc_run = 0; 161 | 162 | For(i,2*tree->n_otu-3) 163 | { 164 | rates->br_r[i] = 1.0; 165 | rates->lexp[i] = 0.001; 166 | } 167 | 168 | For(i,2*tree->n_otu-1) 169 | rates->mc_mr[i] = (phydbl *)mCalloc(rates->n_mc_runs,sizeof(phydbl)); 170 | 171 | } 172 | 173 | /*********************************************************/ 174 | 175 | /*********************************************************/ 176 | /*********************************************************/ 177 | -------------------------------------------------------------------------------- /librna/alicircfold.inc: -------------------------------------------------------------------------------- 1 | /* -*-C-*- */ 2 | /* this file contains code for alifolding circular RNAs */ 3 | /* it's #include'd into alifold.c */ 4 | 5 | float circalifold(const char **strings, char *structure) { 6 | /* variant of alifold() for circular RNAs */ 7 | /* auxiliarry arrays: 8 | fM2 = multiloop region with exactly two stems, extending to 3' end 9 | for stupid dangles=1 case we also need: 10 | fM_d3 = multiloop region with >= 2 stems, starting at pos 2 11 | (a pair (k,n) will form 3' dangle with pos 1) 12 | fM_d5 = multiloop region with >= 2 stems, extending to pos n-1 13 | (a pair (1,k) will form a 5' dangle with pos n) 14 | */ 15 | int *fM2, Fc, FcH, FcI, FcM, Hi, Hj, Ii, Ij, Ip, Iq, Mi; 16 | int FcMd3, FcMd5; 17 | int i,j, p,q,length, energy; 18 | int n_seq, psc, s=0; 19 | int *type; 20 | 21 | /* if (!uniq_ML) {uniq_ML=1; init_length=-1;} */ 22 | length = (int) strlen(strings[0]); 23 | if (length>init_length) init_alifold(length); 24 | if ((P==NULL)||(fabs(P->temperature - temperature)>1e-6)) { 25 | update_fold_params(); P = scale_parameters(); 26 | } 27 | 28 | for (s=0; strings[s]!=NULL; s++); 29 | n_seq = s; 30 | type = (int *) space(n_seq*sizeof(int)); 31 | S = (short **) space(n_seq*sizeof(short *)); 32 | for (s=0; sMAXLOOP) break; 82 | qmin = u1+i-1+length-MAXLOOP; 83 | if (qminMAXLOOP) continue; 91 | for (energy = s=0; sMLclosing; 123 | if (fm 41 | #include 42 | #include 43 | #include 44 | 45 | #include "global.h" 46 | 47 | int verbose=0, verboseMemory=0, quiet=0, userSeed; 48 | long totalMem=0; 49 | unsigned long randomSeed; 50 | 51 | /* functions */ 52 | 53 | /*************************************/ 54 | void *AllocMem(long n, char *name, char *func, int showInfo) 55 | { 56 | void *P; 57 | 58 | if ( (P=malloc(n))==NULL ) { 59 | fprintf(stderr, "Out of memory allocating '%s': %s()\n", name, func); 60 | exit(0); 61 | } 62 | 63 | totalMem+=n; 64 | 65 | if (showInfo && verboseMemory) 66 | fprintf(stderr, "%s in %s() - %ld bytes\n", name, func, n); 67 | 68 | return P; 69 | } 70 | 71 | 72 | /*************************************/ 73 | void *CAllocMem(long n, char *name, char *func, int showInfo) 74 | { 75 | void *P; 76 | 77 | if ( (P=calloc(n, 1))==NULL ) { 78 | fprintf(stderr, "Out of memory allocating '%s': %s()\n", name, func); 79 | exit(0); 80 | } 81 | 82 | totalMem+=n; 83 | if (showInfo && verboseMemory) 84 | fprintf(stderr, "%s in %s() - %ld bytes\n", name, func, n); 85 | 86 | return P; 87 | } 88 | 89 | 90 | /*************************************/ 91 | int GetDoubleParams(int argc, char **argv, int *argn, char *pos, int numParams, double *params) 92 | { 93 | int i; 94 | char *st, buf[256]; 95 | 96 | i=0; 97 | strcpy(buf, pos); 98 | st=strtok(buf, "\t,/"); 99 | do { 100 | if (st==NULL) { 101 | if ((*argn)+190$\%) identity 53 | they only contribute little new information. Our benchmarks showed 54 | that alginments with 5--10 sequences and amean pairwise identity 55 | $<90$\% give good results. 56 | 57 | There are different possible scenarios how to obtain alignments for 58 | your sequences. 59 | 60 | \subsection{Download pre-made alignments} 61 | 62 | These days, for many organisms the complete genomic sequence is 63 | known. Moreover, for many organisms also related species have been 64 | sequenced and pre-calculated multiple alignments are available for 65 | download. Well known resources for major model organism are for 66 | example \url{genome.ucsc.edu} or \url{ensemble.org}, but also many 67 | independent smaller genome projects provide multiple alignments. 68 | 69 | \subsection{Create alignments of long genomic regions} 70 | 71 | If you want to analyze longer genomic regions ($>1kb$) but cannot find 72 | pre-made alignments, we recommend using the \texttt{MultiZ} program 73 | suite to create alignments. It can be downloaded here 74 | \url{http://www.bx.psu.edu/miller_lab/dist} and comes with excellent 75 | documentation. 76 | 77 | You will need homologous genomic sequences for your region in other 78 | species. For example, you can align the complete genomes of bacteria 79 | or align homologous loci in the megabase range of higher organisms 80 | with \texttt{MultiZ}. 81 | 82 | \subsection{Create alignments of individual short regions} 83 | 84 | If your sequence of interest is relatively short (a few hundred 85 | nucleotides) we recommend using a simple global alignment program like 86 | for example \texttt{ClustalW}. Use \texttt{Blast} to find homologous 87 | sequences in a sequence database (e.g. GenBank, 88 | \url{www.ncbi.nlm.nih.gov/genbank/}). Collect the significant hits 89 | that match to your region of interest and align the sequences 90 | afterwards with an alignment program. 91 | 92 | \section{Formatting the alignments} 93 | 94 | \texttt{RNAcode} can process alignments in two different formats: MAF 95 | and CLUSTAL W. You have to make sure that your alignment is in one of 96 | these formats before you can use \texttt{RNAcode}. 97 | 98 | The MAF format was popularized by the USCS genome browser and is very 99 | useful to represent genome-wide alignments. The detailed specification 100 | can be found here: \url{http://genome.ucsc.edu/FAQ/FAQformat.html}. If 101 | you download alignments from an UCSC resource it is usually formatted 102 | as MAF. Also if you align your sequences using \texttt{MultiZ} the 103 | default output format is MAF. 104 | 105 | For shorter alignments of individual regions, the CLUSTAL W format is 106 | useful. Apart from CLUSTAL W, many other alignment programs output 107 | their alignments in this format. 108 | 109 | \section{Pre-processing alignments} 110 | 111 | If your alignments contain blocks of long genomic regions it is 112 | usually no reasonable to score these long regions as a whole. The 113 | \texttt{tar.gz} package contains a script \texttt{breakMAF.pl} that 114 | allows you to easily pre-process your MAF files: 115 | 116 | \begin{verbatim} 117 | # scripts/breakMAF.pl examples/genomic.maf > genomic-preprocessed.maf 118 | \end{verbatim} 119 | 120 | This command breaks blocks longer than 400 in shorter blocks of an 121 | average size of 200. 122 | 123 | \section{Running RNAcode} 124 | 125 | Analyze alignment with standard options and print detailed results 126 | page: 127 | 128 | \begin{verbatim} 129 | 130 | # RNAcode examples/coding.aln 131 | 132 | \end{verbatim} 133 | 134 | Analyze alignment and show best non-overlapping hits below a $p$-value 135 | cutoff of 0.01 in gtf format: 136 | 137 | \begin{verbatim} 138 | # RNAcode --outfile out.gtf --gtf --best-only --cutoff 0.01 genomic-preprocessed.maf 139 | \end{verbatim} 140 | 141 | Create color annotations for high scoring coding segments: 142 | 143 | \begin{verbatim} 144 | 145 | # RNAcode --eps coding.aln 146 | 147 | \end{verbatim} 148 | 149 | Please refer to the more detailed README file that explains all 150 | options of \texttt{RNAcode} and how to interpret the results. 151 | 152 | For details on the methodology refer to the paper: 153 | 154 | \textbf{RNAcode: robust discrimination of coding and noncoding regions in 155 | comparative sequence data}\\ 156 | Washietl S, Findei\ss\ S, M{\"u}ller S, Kalkhof S, von~Bergen M, Hofacker IL, Stadler PF, Goldman N\\ 157 | \emph{RNA} (2011), in revision 158 | 159 | \end{document} -------------------------------------------------------------------------------- /phyml/optimiz.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | PHYML : a program that computes maximum likelihood phylogenies from 4 | DNA or AA homologous sequences 5 | 6 | Copyright (C) Stephane Guindon. Oct 2003 onward 7 | 8 | All parts of the source except where indicated are distributed under 9 | the GNU public licence. See http://www.opensource.org for details. 10 | 11 | */ 12 | 13 | #ifndef OPTIMIZ_H 14 | #define OPTIMIZ_H 15 | 16 | void Optimiz_Ext_Br(arbre *tree); 17 | void Optimize_Alpha(arbre *tree); 18 | void Optimize_Kappa(arbre *tree); 19 | void Optimize_Lambda(arbre *tree); 20 | void Optimize_Param_Parall(arbre *tree); 21 | phydbl Optimize_Branch_Quad(arbre *tree, allseq *alldata, edge *b_fcus); 22 | void Optimize_After_Hide(arbre *tree, allseq *alldata, node *h); 23 | void Round_Optimize(arbre *tree, allseq *data); 24 | int Dist_Seq_Brak(phydbl *ax, phydbl *bx, phydbl *cx, 25 | phydbl *fa, phydbl *fb, phydbl *fc, 26 | allseq *data, int num1, int num2, model *mod); 27 | phydbl Dist_Seq_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, 28 | phydbl *xmin, allseq *data, 29 | int num1, int num2, model *mod); 30 | phydbl Kappa_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, 31 | phydbl *xmin, arbre *tree, allseq *alldata); 32 | phydbl Lambda_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, 33 | phydbl *xmin, arbre *tree, allseq *alldata); 34 | phydbl Alpha_Golden_Br_Opt(phydbl ax, phydbl bx, phydbl cx, phydbl tol, 35 | phydbl *xmin, arbre *tree, allseq *alldata, 36 | int n_opt, phydbl *init_l); 37 | phydbl Alpha_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol,phydbl *xmin, 38 | arbre *tree, allseq *alldata); 39 | phydbl Br_Len_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, 40 | phydbl *xmin, edge *b_fcus, arbre *tree); 41 | phydbl Br_Len_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, 42 | edge *b_fcus, arbre *tree, int n_iter_max); 43 | int Br_Len_Brak(phydbl *ax, phydbl *bx, phydbl *cx, 44 | phydbl *fa, phydbl *fb, phydbl *fc, 45 | edge *b_fcus, arbre *tree); 46 | phydbl Optimize_Path_Length(model *mod, allseq *alldata, edge *a, 47 | int lra, edge *b, int lrb, phydbl i_len); 48 | void Optimize_Param_Serie(node *a, node *d, edge *b_fcus, arbre *tree, 49 | allseq *alldata, int n_passes); 50 | phydbl Optimize_Dist(model *mod, phydbl init, allseq *twoseqs); 51 | phydbl Pinvar_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, 52 | phydbl *xmin, arbre *tree, allseq *alldata, int n_iter_max); 53 | void Optimize_Pinvar(arbre *tree); 54 | int Lambda_Brak(phydbl *ax, phydbl *bx, phydbl *cx, 55 | phydbl *fa, phydbl *fb, phydbl *fc, 56 | arbre *tree); 57 | int Kappa_Brak(phydbl *ax, phydbl *bx, phydbl *cx, 58 | phydbl *fa, phydbl *fb, phydbl *fc, 59 | arbre *tree); 60 | int Alpha_Brak(phydbl *ax, phydbl *bx, phydbl *cx, 61 | phydbl *fa, phydbl *fb, phydbl *fc, 62 | arbre *tree); 63 | int Pinvar_Brak(phydbl *ax, phydbl *bx, phydbl *cx, 64 | phydbl *fa, phydbl *fb, phydbl *fc, 65 | arbre *tree); 66 | void Optimiz_All_Free_Param(arbre *tree, int verbose); 67 | void Optimiz_RRparam_GTR(arbre *tree, int num_param); 68 | phydbl RRparam_GTR_Golden(phydbl ax, phydbl bx, phydbl cx, phydbl tol, 69 | phydbl *xmin, arbre *tree, allseq *alldata, phydbl *param, int n_iter_max); 70 | 71 | int Powell_GTR_Param(arbre *tree, phydbl *p, int n, phydbl ftol); 72 | phydbl Linmin_GTR_Param(arbre *tree,phydbl *p, phydbl *xi, int n); 73 | phydbl F1dim(arbre *tree, phydbl x, phydbl *p, phydbl *xi, phydbl n); 74 | int Mnbrak_1dim(phydbl *ax, phydbl *bx, phydbl *cx, 75 | phydbl *fa, phydbl *fb, phydbl *fc, 76 | arbre *tree, 77 | phydbl *p, phydbl *xi, phydbl n); 78 | phydbl Brent_1dim(phydbl ax, phydbl bx, phydbl cx, 79 | phydbl tol, phydbl *xmin, 80 | arbre *tree, 81 | phydbl *p, phydbl *xi, phydbl n); 82 | 83 | int Min_With_Derivatives(arbre *tree, phydbl *p, int n, phydbl ftol, phydbl step_size, 84 | phydbl (*func) (), void (*dfunc)(), phydbl (*linmin)()); 85 | void BFGS(arbre *tree, phydbl *p, int n, phydbl gtol, phydbl step_size, 86 | phydbl(*func)(), void (*dfunc)(), void (*lnsrch)(),int *failed); 87 | void Lnsrch_RR_Param(arbre *tree, int n, phydbl *xold, phydbl fold, phydbl *g, phydbl *p, phydbl *x, 88 | phydbl *f, phydbl stpmax, int *check); 89 | void Optimize_Single_Param_Generic(arbre *tree, phydbl *param, phydbl lim_inf, phydbl lim_sup, phydbl tol, int n_max_iter); 90 | int Generic_Brak(phydbl *param, 91 | phydbl *ax, phydbl *bx, phydbl *cx, 92 | phydbl *fa, phydbl *fb, phydbl *fc, 93 | phydbl lim_inf, phydbl lim_sup, 94 | arbre *tree); 95 | phydbl Generic_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, 96 | phydbl *xmin, arbre *tree, int n_iter_max); 97 | void Optimize_Br_Len_Serie(node *a, node *d, edge *b_fcus, arbre *tree,allseq *alldata); 98 | void Lnsrch_Nucleotide_Frequencies(arbre *tree, int n, phydbl *xold, 99 | phydbl fold, phydbl *g, phydbl *p, phydbl *x, 100 | phydbl *f, phydbl stpmax, int *check); 101 | 102 | void Optimize_Global_Rate(arbre *tree); 103 | phydbl Br_Len_Brent_Default(edge *b_fcus, arbre *tree); 104 | 105 | void EM_Dist(model *mod, allseq *data); 106 | phydbl Dist_F_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, int n_iter_max, 107 | phydbl *param, phydbl *F, model *mod); 108 | int Dist_F_Brak(phydbl *ax, phydbl *bx, phydbl *cx, phydbl *F, phydbl *param, model *mod); 109 | void Opt_Dist_F(phydbl *dist, phydbl *F, model *mod); 110 | phydbl Missing_Dist_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, int n_iter_max, 111 | int x, int y, matrix *mat); 112 | int Missing_Dist_Brak(phydbl *ax, phydbl *bx, phydbl *cx, int x, int y, matrix *mat); 113 | void Opt_Missing_Dist(int x, int y, matrix *mat); 114 | int Optimiz_Alpha_And_Pinv(arbre *tree); 115 | void Lnsrch_RR_Cov_Param(arbre *tree, int n, phydbl *xold, phydbl fold, 116 | phydbl *g, phydbl *p, phydbl *x, 117 | phydbl *f, phydbl stpmax, int *check); 118 | phydbl Node_Time_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, 119 | node *anc, node *des, arbre *tree, int n_iter_max); 120 | phydbl Time_Stamps_Mult_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, 121 | arbre *tree, int n_iter_max); 122 | phydbl Branch_Rate_Shape_Brent(phydbl ax, phydbl bx, phydbl cx, phydbl tol, 123 | phydbl *xmin, arbre *tree, int n_iter_max); 124 | 125 | 126 | #endif 127 | 128 | -------------------------------------------------------------------------------- /src/getopt.h: -------------------------------------------------------------------------------- 1 | /* Declarations for getopt. 2 | Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Library General Public License as 7 | published by the Free Software Foundation; either version 2 of the 8 | License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Library General Public License for more details. 14 | 15 | You should have received a copy of the GNU Library General Public 16 | License along with the GNU C Library; see the file COPYING.LIB. If not, 17 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | Boston, MA 02111-1307, USA. */ 19 | 20 | #ifndef _GETOPT_H 21 | 22 | #ifndef __need_getopt 23 | # define _GETOPT_H 1 24 | #endif 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* For communication from `getopt' to the caller. 31 | When `getopt' finds an option that takes an argument, 32 | the argument value is returned here. 33 | Also, when `ordering' is RETURN_IN_ORDER, 34 | each non-option ARGV-element is returned here. */ 35 | 36 | extern char *optarg; 37 | 38 | /* Index in ARGV of the next element to be scanned. 39 | This is used for communication to and from the caller 40 | and for communication between successive calls to `getopt'. 41 | 42 | On entry to `getopt', zero means this is the first call; initialize. 43 | 44 | When `getopt' returns -1, this is the index of the first of the 45 | non-option elements that the caller should itself scan. 46 | 47 | Otherwise, `optind' communicates from one call to the next 48 | how much of ARGV has been scanned so far. */ 49 | 50 | extern int optind; 51 | 52 | /* Callers store zero here to inhibit the error message `getopt' prints 53 | for unrecognized options. */ 54 | 55 | extern int opterr; 56 | 57 | /* Set to an option character which was unrecognized. */ 58 | 59 | extern int optopt; 60 | 61 | #ifndef __need_getopt 62 | /* Describe the long-named options requested by the application. 63 | The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 64 | of `struct option' terminated by an element containing a name which is 65 | zero. 66 | 67 | The field `has_arg' is: 68 | no_argument (or 0) if the option does not take an argument, 69 | required_argument (or 1) if the option requires an argument, 70 | optional_argument (or 2) if the option takes an optional argument. 71 | 72 | If the field `flag' is not NULL, it points to a variable that is set 73 | to the value given in the field `val' when the option is found, but 74 | left unchanged if the option is not found. 75 | 76 | To have a long-named option do something other than set an `int' to 77 | a compiled-in constant, such as set a value from `optarg', set the 78 | option's `flag' field to zero and its `val' field to a nonzero 79 | value (the equivalent single-letter option character, if there is 80 | one). For long options that have a zero `flag' field, `getopt' 81 | returns the contents of the `val' field. */ 82 | 83 | struct option 84 | { 85 | # if defined __STDC__ && __STDC__ 86 | const char *name; 87 | # else 88 | char *name; 89 | # endif 90 | /* has_arg can't be an enum because some compilers complain about 91 | type mismatches in all the code that assumes it is an int. */ 92 | int has_arg; 93 | int *flag; 94 | int val; 95 | }; 96 | 97 | /* Names for the values of the `has_arg' field of `struct option'. */ 98 | 99 | # define no_argument 0 100 | # define required_argument 1 101 | # define optional_argument 2 102 | #endif /* need getopt */ 103 | 104 | 105 | /* Get definitions and prototypes for functions to process the 106 | arguments in ARGV (ARGC of them, minus the program name) for 107 | options given in OPTS. 108 | 109 | Return the option character from OPTS just read. Return -1 when 110 | there are no more options. For unrecognized options, or options 111 | missing arguments, `optopt' is set to the option letter, and '?' is 112 | returned. 113 | 114 | The OPTS string is a list of characters which are recognized option 115 | letters, optionally followed by colons, specifying that that letter 116 | takes an argument, to be placed in `optarg'. 117 | 118 | If a letter in OPTS is followed by two colons, its argument is 119 | optional. This behavior is specific to the GNU `getopt'. 120 | 121 | The argument `--' causes premature termination of argument 122 | scanning, explicitly telling `getopt' that there are no more 123 | options. 124 | 125 | If OPTS begins with `--', then non-option arguments are treated as 126 | arguments to the option '\0'. This behavior is specific to the GNU 127 | `getopt'. */ 128 | 129 | #if defined __STDC__ && __STDC__ 130 | # ifdef __GNU_LIBRARY__ 131 | /* Many other libraries have conflicting prototypes for getopt, with 132 | differences in the consts, in stdlib.h. To avoid compilation 133 | errors, only prototype getopt for the GNU C library. */ 134 | extern int getopt (int __argc, char *const *__argv, const char *__shortopts); 135 | # else /* not __GNU_LIBRARY__ */ 136 | extern int getopt (); 137 | # endif /* __GNU_LIBRARY__ */ 138 | 139 | # ifndef __need_getopt 140 | extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, 141 | const struct option *__longopts, int *__longind); 142 | extern int getopt_long_only (int __argc, char *const *__argv, 143 | const char *__shortopts, 144 | const struct option *__longopts, int *__longind); 145 | 146 | /* Internal only. Users should not call this directly. */ 147 | extern int _getopt_internal (int __argc, char *const *__argv, 148 | const char *__shortopts, 149 | const struct option *__longopts, int *__longind, 150 | int __long_only); 151 | # endif 152 | #else /* not __STDC__ */ 153 | extern int getopt (); 154 | # ifndef __need_getopt 155 | extern int getopt_long (); 156 | extern int getopt_long_only (); 157 | 158 | extern int _getopt_internal (); 159 | # endif 160 | #endif /* __STDC__ */ 161 | 162 | #ifdef __cplusplus 163 | } 164 | #endif 165 | 166 | /* Make sure we later can get all the definitions and declarations. */ 167 | #undef __need_getopt 168 | 169 | #endif /* getopt.h */ 170 | -------------------------------------------------------------------------------- /src/treeML.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2009, Stefan Washietl 2 | 3 | This file is part of RNAcode. 4 | 5 | RNAcode is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | RNAcode is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with RNAcode. If not, see . */ 17 | 18 | 19 | #include "spr.h" 20 | #include "utilities.h" 21 | #include "lk.h" 22 | #include "optimiz.h" 23 | #include "bionj.h" 24 | #include "models.h" 25 | #include "free.h" 26 | #include "options.h" 27 | #include "simu.h" 28 | #include "eigen.h" 29 | #include "pars.h" 30 | #include "alrt.h" 31 | #include "rnaz_utils.h" 32 | 33 | seq **Get_Seq_local(seq**, option *io, int rw); 34 | 35 | int treeML(const struct aln *alignment[], char** treeString, float* kappa){ 36 | 37 | int i; 38 | seq **data; 39 | allseq *alldata; 40 | option *io; 41 | arbre *tree; 42 | int n_otu; 43 | matrix *mat; 44 | model *mod; 45 | time_t t_beg,t_end; 46 | div_t hour,min; 47 | phydbl best_lnL; 48 | int L,r_seed; 49 | 50 | /* Initialize data structures */ 51 | 52 | tree = NULL; 53 | mod = NULL; 54 | data = NULL; 55 | best_lnL = UNLIKELY; 56 | 57 | io = (option *)Make_Input(); 58 | Set_Defaults_Input(io); 59 | Set_Defaults_Model(io->mod); 60 | Set_Defaults_Optimiz(io->mod->s_opt); 61 | r_seed = time(NULL); 62 | srand(r_seed); 63 | Make_Model_Complete(io->mod); 64 | mod = io->mod; 65 | 66 | 67 | /* Set options */ 68 | 69 | io->mod->datatype=NT; /* Nucleotides not amino acids */ 70 | io->mod->s_opt->print=0; /* Shut of verbose output */ 71 | io->mod->s_opt->opt_topo = 0; /* Do not optimize topology */ 72 | io->mod->s_opt->opt_bl = 1; /* Optimize branch lengths*/ 73 | io->mod->s_opt->opt_num_param = 1; /* Optimize kappa, initialize with 4.0*/ 74 | io->mod->s_opt->opt_kappa = 1; 75 | io->mod->kappa = 4.0; 76 | 77 | /* Manually fill data structure with the alignment */ 78 | 79 | n_otu = 0; 80 | 81 | L=strlen(alignment[0]->seq); 82 | for (n_otu=0; alignment[n_otu]!=NULL; n_otu++); 83 | 84 | io->mod->n_otu=n_otu; 85 | 86 | data = (seq **)mCalloc(n_otu,sizeof(seq *)); 87 | 88 | for (i=0;ilen = L; 91 | data[i]->name = (char *)mCalloc(T_MAX_NAME,sizeof(char)); 92 | strcpy(data[i]->name,alignment[i]->name); 93 | data[i]->state = (char *)mCalloc(T_MAX_SEQ,sizeof(char)); 94 | strcpy(data[i]->state,alignment[i]->seq); 95 | data[i]->is_ambigu = NULL; 96 | } 97 | 98 | /* Call modified version of Get_Seq, that does some processing */ 99 | data=Get_Seq_local(data, io, 0); 100 | alldata = Compact_Seq(data,io); 101 | Free_Seq(data,alldata->n_otu); 102 | Check_Ambiguities(alldata,io->mod->datatype,io->mod->stepsize); 103 | if (Init_Model(alldata,mod)!=1){ 104 | return(0); 105 | } 106 | 107 | /* Calculate pairwise distances and make BIONJ tree*/ 108 | mat = ML_Dist(alldata,mod); 109 | Fill_Missing_Dist(mat); 110 | mat->tree = Make_Tree_From_Scratch(alldata->n_otu,alldata); 111 | Bionj(mat); 112 | tree = mat->tree; 113 | tree->mat = mat; 114 | tree->mod = mod; 115 | tree->io = io; 116 | tree->data = alldata; 117 | tree->both_sides = 1; 118 | tree->n_pattern = tree->data->crunch_len/tree->mod->stepsize; 119 | time(&t_beg); 120 | time(&(tree->t_beg)); 121 | 122 | /* Prepare for optimization and optimize */ 123 | 124 | Fill_Dir_Table(tree); 125 | Update_Dirs(tree); 126 | Make_Tree_4_Pars(tree,alldata,alldata->init_len); 127 | Make_Tree_4_Lk(tree,alldata,alldata->init_len); 128 | tree->triplet_struct = Make_Triplet_Struct(mod); 129 | Br_Len_Not_Involving_Invar(tree); 130 | Order_Tree_CSeq(tree,alldata); 131 | Round_Optimize(tree,tree->data); 132 | 133 | //treeString=(char *)mCalloc(T_MAX_LINE,sizeof(char)); 134 | 135 | *treeString=Write_Tree(tree); 136 | *kappa=io->mod->kappa; 137 | 138 | Free_Mat(tree->mat); 139 | Free_Triplet(tree->triplet_struct); 140 | Free_Tree_Pars(tree); 141 | Free_Tree_Lk(tree); 142 | Free_Tree(tree); 143 | 144 | Free_Cseq(alldata); 145 | 146 | Free_Model(mod); 147 | 148 | Free_Input(io); 149 | 150 | return(1); 151 | 152 | } 153 | 154 | /* Function from Seqgen (c) Andrew Rambaut & Nick Grassly */ 155 | 156 | seq **Get_Seq_local(seq** data, option *io, int rw) 157 | { 158 | int i,j; 159 | char **buff; 160 | int n_unkn,n_removed,pos; 161 | int *remove; 162 | 163 | 164 | /* rewind(fp_seq); */ 165 | 166 | 167 | if(data) 168 | { 169 | buff = (char **)mCalloc(io->mod->n_otu,sizeof(char *)); 170 | For(i,io->mod->n_otu) buff[i] = (char *)mCalloc(data[0]->len,sizeof(char)); 171 | remove = (int *)mCalloc(data[0]->len,sizeof(int)); 172 | 173 | n_removed = 0; 174 | 175 | For(i,data[0]->len) 176 | { 177 | For(j,io->mod->n_otu) 178 | { 179 | if((data[j]->state[i] == '?') || (data[j]->state[i] == '-')) data[j]->state[i] = 'X'; 180 | if((io->mod->datatype == NT) && (data[j]->state[i] == 'N')) data[j]->state[i] = 'X'; 181 | if(data[j]->state[i] == 'U') data[j]->state[i] = 'T'; 182 | } 183 | 184 | n_unkn = 0; 185 | For(j,io->mod->n_otu) if(data[j]->state[i] == 'X') n_unkn++; 186 | 187 | if(n_unkn == io->mod->n_otu) 188 | { 189 | remove[i] = 1; 190 | n_removed++; 191 | } 192 | 193 | For(j,io->mod->n_otu) buff[j][i] = data[j]->state[i]; 194 | } 195 | 196 | if(n_removed > 0) 197 | { 198 | if(io->mod->datatype == NT) 199 | printf("\n. %d sites are made from completely undetermined states ('X', '-', '?' or 'N')...\n",n_removed); 200 | else 201 | printf("\n. %d sites are made from completely undetermined states ('X', '-', '?')...\n",n_removed); 202 | } 203 | 204 | pos = 0; 205 | For(i,data[0]->len) 206 | { 207 | /* if(!remove[i]) */ 208 | /* { */ 209 | For(j,io->mod->n_otu) data[j]->state[pos] = buff[j][i]; 210 | pos++; 211 | /* } */ 212 | } 213 | 214 | For(i,io->mod->n_otu) data[i]->len = pos; 215 | For(i,io->mod->n_otu) Free(buff[i]); 216 | Free(buff); 217 | Free(remove); 218 | } 219 | return data; 220 | } 221 | -------------------------------------------------------------------------------- /src/treeSimulate.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2009, Stefan Washietl 2 | 3 | This file is part of RNAcode. 4 | 5 | RNAcode is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | RNAcode is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with RNAcode. If not, see . */ 17 | 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "rnaz_utils.h" 28 | 29 | #include "treeSimulate.h" 30 | 31 | #include "global.h" 32 | #include "treefile.h" 33 | #include "evolve.h" 34 | #include "model.h" 35 | #include "nucmodels.h" 36 | #include "aamodels.h" 37 | #include "progress.h" 38 | #include "twister.h" 39 | 40 | extern int model; 41 | extern int numStates; 42 | extern int isNucModel; 43 | extern int userFreqs; 44 | extern int equalFreqs; 45 | extern int numSites; 46 | extern double tstv; 47 | extern double nucFreq[NUM_NUC]; 48 | extern int numTaxa; 49 | char* P; 50 | 51 | 52 | void simulateTree(TTree* tree, float freqs[], float kap, int L){ 53 | 54 | int i,j,k; 55 | int* tmp; 56 | double** matrix; 57 | double freqR,freqY,freqAG,freqCT; 58 | double freqA, freqC, freqG, freqT; 59 | 60 | isNucModel = 1; 61 | numStates = 4; 62 | model=0; /*0 means HKY, take care model constants are a tricky in 63 | seqgen and if set to defined constant HKY this does not 64 | work*/ 65 | 66 | equalFreqs = 0; 67 | equalTstv = 0; 68 | 69 | 70 | freqA=nucFreq[0]=(double)freqs[0]; 71 | freqC=nucFreq[1]=(double)freqs[1]; 72 | freqG=nucFreq[2]=(double)freqs[2]; 73 | freqT=nucFreq[3]=(double)freqs[3]; 74 | 75 | freqR=freqA+freqG; 76 | freqY=freqC+freqT; 77 | freqAG=freqA*freqG; 78 | freqCT=freqC*freqT; 79 | 80 | tstv=(double)kap*(freqAG+freqCT)/(freqR*freqY); 81 | 82 | numSites=L; 83 | 84 | randomSeed = CreateSeed(); 85 | SetSeed(randomSeed); 86 | CreateRates(); 87 | 88 | numTaxa=tree->numTips; 89 | 90 | CreateSequences(tree, numSites); 91 | SetModel(model); 92 | 93 | EvolveSequences(tree, 0, numSites, 1.0, NULL); 94 | 95 | FreeRates(); 96 | 97 | } 98 | 99 | 100 | TTree* string2tree(char* treeString){ 101 | 102 | FILE * tmpfh; 103 | TTree* tree; 104 | int dummy1; 105 | double dummy2; 106 | 107 | tmpfh = tmpfile(); 108 | fprintf(tmpfh,"%s",treeString); 109 | rewind(tmpfh); 110 | tree=NewTree(); 111 | ReadTree(tmpfh, tree, 0, 0, NULL, &dummy1, &dummy2); 112 | fclose(tmpfh); 113 | return tree; 114 | 115 | } 116 | 117 | 118 | float** getDistanceMatrix(TTree* tree, struct aln *alignment[]){ 119 | 120 | TNode* LCA; 121 | TNode* nodeA=NULL; 122 | TNode* nodeB=NULL; 123 | float sum=0.0; 124 | float** matrix; 125 | int N,i,j,k; 126 | 127 | for (N=0; alignment[N]!=NULL; N++); 128 | 129 | matrix=(float**)malloc(sizeof(float*)*N); 130 | 131 | for (i=0;ij) continue; 146 | 147 | for (k=0;knumTips;k++){ 148 | if (strcmp(tree->names[k],alignment[i]->name)==0){ 149 | nodeA=tree->tips[k]; 150 | break; 151 | } 152 | } 153 | 154 | for (k=0;knumTips;k++){ 155 | if (strcmp(tree->names[k],alignment[j]->name)==0){ 156 | nodeB=tree->tips[k]; 157 | break; 158 | } 159 | } 160 | 161 | LCA=NULL; 162 | 163 | LCA=getLCA(tree,nodeA, nodeB); 164 | sum=0.0; 165 | 166 | while (1){ 167 | if (nodeA != LCA){ 168 | sum+=nodeA->length0; 169 | nodeA=nodeA->branch0; 170 | } else { 171 | break; 172 | } 173 | } 174 | 175 | while (1){ 176 | if (nodeB != LCA){ 177 | sum+=nodeB->length0; 178 | nodeB=nodeB->branch0; 179 | } else { 180 | break; 181 | } 182 | } 183 | 184 | matrix[i][j]=sum; 185 | matrix[j][i]=sum; 186 | 187 | } 188 | } 189 | return matrix; 190 | } 191 | 192 | 193 | 194 | 195 | 196 | TNode* getLCA(TTree* tree, TNode* nodeA, TNode* nodeB){ 197 | 198 | TNode** listA; 199 | TNode** listB; 200 | TNode** tmp; 201 | TNode* lca; 202 | int i,j; 203 | int numAncestorsA,numAncestorsB; 204 | int minNumAncestors,maxNumAncestors; 205 | 206 | listA=(TNode**)malloc(sizeof(TNode*)*tree->numNodes); 207 | listB=(TNode**)malloc(sizeof(TNode*)*tree->numNodes); 208 | 209 | numAncestorsA=0; 210 | 211 | do { 212 | listA[numAncestorsA++]=nodeA; 213 | nodeA=nodeA->branch0; 214 | } while (nodeA != tree->root); 215 | listA[numAncestorsA++]=tree->root; 216 | 217 | 218 | numAncestorsB=0; 219 | 220 | do { 221 | listB[numAncestorsB++]=nodeB; 222 | nodeB=nodeB->branch0; 223 | } while (nodeB != tree->root); 224 | listB[numAncestorsB++]=tree->root; 225 | 226 | if (numAncestorsA < numAncestorsB){ 227 | minNumAncestors=numAncestorsA; 228 | maxNumAncestors=numAncestorsB; 229 | 230 | } else { 231 | minNumAncestors=numAncestorsB; 232 | maxNumAncestors=numAncestorsA; 233 | 234 | tmp=listA; 235 | listA=listB; 236 | listB=tmp; 237 | } 238 | 239 | for (i=0;inumTips; i++) { 262 | 263 | seq=(char*)malloc((sizeof(char))*(numSites+1)); 264 | 265 | encodedSeq=tree->tips[i]->sequence; 266 | 267 | for (j=0; j %s\n",seq); 275 | 276 | 277 | alignment[i]=createAlnEntry(strdup(tree->names[i]), 278 | seq,0,0,0,'+'); 279 | 280 | } 281 | 282 | alignment[i]=NULL; 283 | } 284 | 285 | /* tree is free'd manually since the function "FreeTree" in seq-gen 286 | do not seem to free everything */ 287 | 288 | void freeSeqgenTree(TTree* tree){ 289 | 290 | int i; 291 | TNode *node, *nextNode; 292 | 293 | for (i=0;icapacity;i++){ 294 | free(tree->names[i]); 295 | } 296 | 297 | node=tree->nodeList; 298 | while (node != NULL){ 299 | nextNode=node->next; 300 | free(node->sequence); 301 | free(node); 302 | node=nextNode; 303 | } 304 | 305 | free(tree->names); 306 | free(tree->tips); 307 | free(tree); 308 | 309 | } 310 | -------------------------------------------------------------------------------- /levmar/lm.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Prototypes and definitions for the Levenberg - Marquardt minimization algorithm 4 | // Copyright (C) 2004 Manolis Lourakis (lourakis@ics.forth.gr) 5 | // Institute of Computer Science, Foundation for Research & Technology - Hellas 6 | // Heraklion, Crete, Greece. 7 | // 8 | // This program is free software; you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation; either version 2 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | ///////////////////////////////////////////////////////////////////////////////// 19 | 20 | #ifndef _LM_H_ 21 | #define _LM_H_ 22 | 23 | #undef HAVE_LAPACK // uncomment this to force not using LAPACK 24 | 25 | #define LINSOLVERS_RETAIN_MEMORY // comment this is if you don't want routines in Axb.c retain working memory between calls 26 | 27 | /* no changes necessary beyond this point */ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | 34 | #define FABS(x) (((x)>=0.0)? (x) : -(x)) 35 | 36 | /* work arrays size for LM with & without jacobian, should be multiplied by sizeof(double) 37 | * or sizeof(float) to be converted to bytes 38 | */ 39 | #define LM_DER_WORKSZ(npar, nmeas) (2*(nmeas) + 4*(npar) + (nmeas)*(npar) + (npar)*(npar)) 40 | #define LM_DIF_WORKSZ(npar, nmeas) (3*(nmeas) + 4*(npar) + (nmeas)*(npar) + (npar)*(npar)) 41 | 42 | #define LM_OPTS_SZ 5 /* max(4, 5) */ 43 | #define LM_INFO_SZ 9 44 | #define LM_INIT_MU 1E-03 45 | #define LM_STOP_THRESH 1E-17 46 | #define LM_DIFF_DELTA 1E-06 47 | #define LM_VERSION "2.1.2 (Jan. 2006)" 48 | 49 | /* double precision LM, with & without jacobian */ 50 | /* unconstrained minimization */ 51 | extern int dlevmar_der( 52 | void (*func)(double *p, double *hx, int m, int n, void *adata), 53 | void (*jacf)(double *p, double *j, int m, int n, void *adata), 54 | double *p, double *x, int m, int n, int itmax, double *opts, 55 | double *info, double *work, double *covar, void *adata); 56 | 57 | extern int dlevmar_dif( 58 | void (*func)(double *p, double *hx, int m, int n, void *adata), 59 | double *p, double *x, int m, int n, int itmax, double *opts, 60 | double *info, double *work, double *covar, void *adata); 61 | 62 | /* box-constrained minimization */ 63 | extern int dlevmar_bc_der( 64 | void (*func)(double *p, double *hx, int m, int n, void *adata), 65 | void (*jacf)(double *p, double *j, int m, int n, void *adata), 66 | double *p, double *x, int m, int n, double *lb, double *ub, 67 | int itmax, double *opts, double *info, double *work, double *covar, void *adata); 68 | 69 | extern int dlevmar_bc_dif( 70 | void (*func)(double *p, double *hx, int m, int n, void *adata), 71 | double *p, double *x, int m, int n, double *lb, double *ub, 72 | int itmax, double *opts, double *info, double *work, double *covar, void *adata); 73 | 74 | #ifdef HAVE_LAPACK 75 | /* linear equation constrained minimization */ 76 | extern int dlevmar_lec_der( 77 | void (*func)(double *p, double *hx, int m, int n, void *adata), 78 | void (*jacf)(double *p, double *j, int m, int n, void *adata), 79 | double *p, double *x, int m, int n, double *A, double *b, int k, 80 | int itmax, double *opts, double *info, double *work, double *covar, void *adata); 81 | 82 | extern int dlevmar_lec_dif( 83 | void (*func)(double *p, double *hx, int m, int n, void *adata), 84 | double *p, double *x, int m, int n, double *A, double *b, int k, 85 | int itmax, double *opts, double *info, double *work, double *covar, void *adata); 86 | #endif /* HAVE_LAPACK */ 87 | 88 | 89 | /* single precision LM, with & without jacobian */ 90 | /* unconstrained minimization */ 91 | extern int slevmar_der( 92 | void (*func)(float *p, float *hx, int m, int n, void *adata), 93 | void (*jacf)(float *p, float *j, int m, int n, void *adata), 94 | float *p, float *x, int m, int n, int itmax, float *opts, 95 | float *info, float *work, float *covar, void *adata); 96 | 97 | extern int slevmar_dif( 98 | void (*func)(float *p, float *hx, int m, int n, void *adata), 99 | float *p, float *x, int m, int n, int itmax, float *opts, 100 | float *info, float *work, float *covar, void *adata); 101 | 102 | /* box-constrained minimization */ 103 | extern int slevmar_bc_der( 104 | void (*func)(float *p, float *hx, int m, int n, void *adata), 105 | void (*jacf)(float *p, float *j, int m, int n, void *adata), 106 | float *p, float *x, int m, int n, float *lb, float *ub, 107 | int itmax, float *opts, float *info, float *work, float *covar, void *adata); 108 | 109 | extern int slevmar_bc_dif( 110 | void (*func)(float *p, float *hx, int m, int n, void *adata), 111 | float *p, float *x, int m, int n, float *lb, float *ub, 112 | int itmax, float *opts, float *info, float *work, float *covar, void *adata); 113 | 114 | #ifdef HAVE_LAPACK 115 | /* linear equation constrained minimization */ 116 | extern int slevmar_lec_der( 117 | void (*func)(float *p, float *hx, int m, int n, void *adata), 118 | void (*jacf)(float *p, float *j, int m, int n, void *adata), 119 | float *p, float *x, int m, int n, float *A, float *b, int k, 120 | int itmax, float *opts, float *info, float *work, float *covar, void *adata); 121 | 122 | extern int slevmar_lec_dif( 123 | void (*func)(float *p, float *hx, int m, int n, void *adata), 124 | float *p, float *x, int m, int n, float *A, float *b, int k, 125 | int itmax, float *opts, float *info, float *work, float *covar, void *adata); 126 | #endif /* HAVE LAPACK */ 127 | 128 | /* linear system solvers */ 129 | #ifdef HAVE_LAPACK 130 | extern int dAx_eq_b_QR(double *A, double *B, double *x, int m); 131 | extern int dAx_eq_b_QRLS(double *A, double *B, double *x, int m, int n); 132 | extern int dAx_eq_b_Chol(double *A, double *B, double *x, int m); 133 | extern int dAx_eq_b_LU(double *A, double *B, double *x, int m); 134 | extern int dAx_eq_b_SVD(double *A, double *B, double *x, int m); 135 | 136 | extern int sAx_eq_b_QR(float *A, float *B, float *x, int m); 137 | extern int sAx_eq_b_QRLS(float *A, float *B, float *x, int m, int n); 138 | extern int sAx_eq_b_Chol(float *A, float *B, float *x, int m); 139 | extern int sAx_eq_b_LU(float *A, float *B, float *x, int m); 140 | extern int sAx_eq_b_SVD(float *A, float *B, float *x, int m); 141 | #else // no LAPACK 142 | extern int dAx_eq_b_LU_noLapack(double *A, double *B, double *x, int n); 143 | 144 | extern int sAx_eq_b_LU_noLapack(float *A, float *B, float *x, int n); 145 | #endif /* HAVE_LAPACK */ 146 | 147 | /* jacobian verification, double & single precision */ 148 | extern void dlevmar_chkjac( 149 | void (*func)(double *p, double *hx, int m, int n, void *adata), 150 | void (*jacf)(double *p, double *j, int m, int n, void *adata), 151 | double *p, int m, int n, void *adata, double *err); 152 | 153 | extern void slevmar_chkjac( 154 | void (*func)(float *p, float *hx, int m, int n, void *adata), 155 | void (*jacf)(float *p, float *j, int m, int n, void *adata), 156 | float *p, int m, int n, void *adata, float *err); 157 | 158 | #ifdef __cplusplus 159 | } 160 | #endif 161 | 162 | #endif /* _LM_H_ */ 163 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | RNAcode -- Analyze the protein coding potential in multiple sequence alignments 2 | 3 | 0. About RNAcode 4 | ================ 5 | 6 | RNAcode predicts protein coding regions in an alignment of homologous 7 | nucleotide sequences. The prediction is based on evolutionary 8 | signatures typical for protein genese, i.e. the presence of 9 | synonyomous/conservative nucleotide mutations, conservation of the 10 | reading frame and absence of stop codons. 11 | 12 | RNAcode does not rely on any species specific sequence characteristics 13 | whatsoever and does not use any machine learning techniques. The only 14 | input required for RNAcode is a multiple sequence alignment either in 15 | MAF or Clustal W format. RNAcode reports local regions of unusual high 16 | coding potential together with an associated p-value. 17 | 18 | 19 | 1. Installation 20 | =============== 21 | 22 | You can compile and install RNAcode like this: 23 | 24 | # ./configure 25 | # make 26 | # make install (as root) 27 | 28 | See INSTALL for details and more advanced installation options. 29 | 30 | 31 | 2. Usage 32 | ======== 33 | 34 | 2.1 Synopsis 35 | ------------ 36 | 37 | Analyze alignment (Clustal W or MAF form) with standard options and 38 | print detailed results page: 39 | 40 | # RNAcode data.aln 41 | 42 | Analyze alignment and show best non-overlapping hits below a p-value 43 | cutoff of 0.01 in gtf format: 44 | 45 | # RNAcode --outfile results.gtf --gtf --best-only --cutoff 0.01 46 | 47 | Create color annotations for high scoring coding segments: 48 | 49 | # RNAcode --eps data.aln 50 | 51 | 52 | 2.2 Input alignment 53 | ------------------- 54 | 55 | The input alignment needs to be formatted in ClustalW format or MAF 56 | format (http://genome.ucsc.edu/FAQ/FAQformat#format5). The latter 57 | format allows to include genomic coordinates which can be used to 58 | produce annotation files. 59 | 60 | Important: RNAcode uses the first sequence as reference sequence, 61 | i.e. all results and reported coding regions apply to this reference 62 | sequence. 63 | 64 | Currently the alignments has to contain at least 3 sequences. Gaps 65 | have to be given as dash ('-'). Unspecified letters given as 'N' are 66 | allowed and treated neurally during all calculations. No difference is 67 | made between uppercase or lowercase input, i.e. 'softly'-repeat masked 68 | sequences which use lowercase letters for masked regions are treated 69 | the same way as unmasked sequences. 70 | 71 | 72 | 2.3. Command line 73 | ----------------- 74 | 75 | RNAcode is invoked as follows: 76 | 77 | # RNAcode [OPTIONS] alignment.aln 78 | 79 | alignment is the alignment file and OPTIONS is one of the follwing 80 | command-line options either given in one-letter form with a single 81 | dash or as long option with double dash: 82 | 83 | --outfile -o (default: stdout) 84 | 85 | File to which the output is written. Defaults to standard output. 86 | 87 | --cutoff -p (default: 1.0) 88 | 89 | Show only regions that have a p-value below the given number. By 90 | default all hits are shown. 91 | 92 | --num-samples -n (default: 100) 93 | 94 | Number of random alignments that are sampled to calculate the 95 | p-value. RNAcode estimates the significance of a coding prediction by 96 | sampling a given number of random alignments. Default is 100 which 97 | gives reasonably stable p-values that are useful for assessing the 98 | relevance of a prediction. 99 | 100 | --stop-early -s 101 | 102 | Setting this option stops the sampling process as soon as it is clear 103 | that the best hit will not fall below the given p-value cutoff. For 104 | example, assume a p-value cutoff of 0.05 (see --cutoff) and a sample 105 | size of 1000 is given (see --num-samples). As soon as 50 random 106 | samples score better than the original alignment, the process is 107 | stopped and all hits in the original alignment are reported as p>0.05 108 | (or by convention as 1.0 in gtf and tabular output). 109 | 110 | --best-region -r Show only best non-overlapping hits 111 | 112 | By default all positive scoring segments are shown in the output if 113 | they fall below the given p-value cutoff. If two hits overlap 114 | (different frame or different strand) and --best-region is given only 115 | the hit with the highest score is shown. Strong coding regions often 116 | lead to statistically significant signals also in other frames. These 117 | hits are suppressed by this option and only the correct reading frame 118 | is reported. 119 | 120 | --best-only -b Show only best hit 121 | 122 | This options shows only the one single best hit for each alignment. 123 | 124 | --pars -c 125 | 126 | Scoring parameters as comma separated string: 127 | 128 | "DELTA,OMEGA,omega,stop_penalty" 129 | 130 | See the appendix of the Paper for an explanation for the meaning of 131 | these parameters. Default: "-10.0,-4.0,-2.0,-8.0" 132 | 133 | --gtf -g 134 | --tabular -t 135 | 136 | Changes the default output to two different machine readable formats 137 | (see next section). 138 | 139 | --eps -e 140 | 141 | Create colored plots in EPS format. The generated plots are resolution 142 | independent vector graphics that can be included in any graphics 143 | software. For each high scoring segment below a given cutoff (see 144 | --eps-cutoff) a file named hss-N.eps is created (N is the running 145 | number of the high scoring segment). See documents/color-legend.pdf 146 | for an explanation of the color scheme. 147 | 148 | --eps-cutoff -i 149 | 150 | Create plots only for high scoring segments with p better than this 151 | cutoff (default: 0.05) 152 | 153 | --eps-dir -d 154 | 155 | Directory to save EPS files in. Default: "eps" 156 | 157 | 158 | 159 | 2.4. Output format 160 | ------------------ 161 | 162 | In the default output each prediction is reported on one line by 10 fields. 163 | 164 | 165 | 1. HSS id Unique running number for each high scoring segment 166 | predicted in one RNAcode call 167 | 168 | 169 | 2. Frame: The reading frame phasing relative to the starting 170 | nucleotide position in the reference sequence. +1 means 171 | that the first nucleotide in the reference sequence is in 172 | the same frame as the predicted coding region. Negative 173 | frames indicate that the predicted regions are on the 174 | reverse complement strand. 175 | 176 | 3. Length: The length of the predicted region in amino acids 177 | 178 | 4. From: The position of the first/last amino acid in the translated 179 | 5. To: nucleotide sequence of the reference sequence starting 180 | with 1. 181 | 182 | 6. Name The name of the reference sequence as given in the input alignment. 183 | 184 | 7. Start The nucleotide position in the reference sequence of the 185 | 186 | 8. End predicted coding region. If no genomic coordinates are given 187 | (if you provide a CLUSTAL W as input) the first nucleotide position in 188 | the references sequence is set to 1, otherwise the positions are the 189 | 1-based genomic coordinates as given in the input MAF file. 190 | 191 | 9. Score The coding potential score. High scores indicate high coding potential. 192 | 193 | 10. P The p-value associated with the score. This is the probability 194 | that a random alignment with same properties contains an equally good 195 | or better hit. 196 | 197 | If --tabular is given, the output is printed as tab-delimited list 198 | without header or any other output. With --gtf the output is formated 199 | as GTF genome annotation file. 200 | 201 | 202 | 4. Citing RNAcode 203 | ================= 204 | 205 | RNAcode: robust discrimination of coding and noncoding regions in 206 | comparative sequence data 207 | Washietl S, Findeiss S, Muller S, Kalkhof S, von Bergen M, Hofacker IL, Stadler PF, Goldman N 208 | RNA (2011), in revision 209 | 210 | 3. Contact 211 | ========== 212 | 213 | Stefan Washietl 214 | -------------------------------------------------------------------------------- /seqgen/twister.c: -------------------------------------------------------------------------------- 1 | /* 2 | Sequence Generator - seq-gen, version 1.3.2 3 | Andrew Rambaut & Nick Grassly 4 | Department of Zoology, University of Oxford 5 | 6 | The code in this file is covered by the license and copyright message 7 | given below. 8 | 9 | Any feedback is very welcome. 10 | http://evolve.zoo.ox.ac.uk/software/Seq-Gen/ 11 | email: andrew.rambaut@zoo.ox.ac.uk 12 | */ 13 | 14 | /* 15 | A C-program for MT19937, with initialization improved 2002/1/26. 16 | Coded by Takuji Nishimura and Makoto Matsumoto. 17 | 18 | Before using, initialize the state by using init_genrand(seed) 19 | or init_by_array(init_key, key_length). 20 | 21 | Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, 22 | All rights reserved. 23 | 24 | Redistribution and use in source and binary forms, with or without 25 | modification, are permitted provided that the following conditions 26 | are met: 27 | 28 | 1. Redistributions of source code must retain the above copyright 29 | notice, this list of conditions and the following disclaimer. 30 | 31 | 2. Redistributions in binary form must reproduce the above copyright 32 | notice, this list of conditions and the following disclaimer in the 33 | documentation and/or other materials provided with the distribution. 34 | 35 | 3. The names of its contributors may not be used to endorse or promote 36 | products derived from this software without specific prior written 37 | permission. 38 | 39 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 40 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 41 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 42 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 43 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 44 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 45 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 46 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 47 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 48 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 49 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 50 | 51 | 52 | Any feedback is very welcome. 53 | http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html 54 | email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) 55 | */ 56 | 57 | #include 58 | #include 59 | #include 60 | #include "twister.h" 61 | 62 | /* Period parameters */ 63 | #define N 624 64 | #define M 397 65 | #define MATRIX_A 0x9908b0dfUL /* constant vector a */ 66 | #define UPPER_MASK 0x80000000UL /* most significant w-r bits */ 67 | #define LOWER_MASK 0x7fffffffUL /* least significant r bits */ 68 | 69 | static unsigned long mt[N]; /* the array for the state vector */ 70 | static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */ 71 | 72 | /* initializes mt[N] with a seed */ 73 | void init_genrand(unsigned long s) 74 | { 75 | mt[0]= s & 0xffffffffUL; 76 | for (mti=1; mti> 30)) + mti); 79 | /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ 80 | /* In the previous versions, MSBs of the seed affect */ 81 | /* only MSBs of the array mt[]. */ 82 | /* 2002/01/09 modified by Makoto Matsumoto */ 83 | mt[mti] &= 0xffffffffUL; 84 | /* for >32 bit machines */ 85 | } 86 | } 87 | 88 | /* initialize by an array with array-length */ 89 | /* init_key is the array for initializing keys */ 90 | /* key_length is its length */ 91 | /* slight change for C++, 2004/2/26 */ 92 | void init_by_array(unsigned long init_key[], int key_length) 93 | { 94 | int i, j, k; 95 | init_genrand(19650218UL); 96 | i=1; j=0; 97 | k = (N>key_length ? N : key_length); 98 | for (; k; k--) { 99 | mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL)) 100 | + init_key[j] + j; /* non linear */ 101 | mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ 102 | i++; j++; 103 | if (i>=N) { mt[0] = mt[N-1]; i=1; } 104 | if (j>=key_length) j=0; 105 | } 106 | for (k=N-1; k; k--) { 107 | mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL)) 108 | - i; /* non linear */ 109 | mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ 110 | i++; 111 | if (i>=N) { mt[0] = mt[N-1]; i=1; } 112 | } 113 | 114 | mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */ 115 | } 116 | 117 | /* generates a random number on [0,0xffffffff]-interval */ 118 | unsigned long genrand_int32(void) 119 | { 120 | unsigned long y; 121 | static unsigned long mag01[2]={0x0UL, MATRIX_A}; 122 | /* mag01[x] = x * MATRIX_A for x=0,1 */ 123 | 124 | if (mti >= N) { /* generate N words at one time */ 125 | int kk; 126 | 127 | if (mti == N+1) /* if init_genrand() has not been called, */ 128 | init_genrand(5489UL); /* a default initial seed is used */ 129 | 130 | for (kk=0;kk> 1) ^ mag01[y & 0x1UL]; 133 | } 134 | for (;kk> 1) ^ mag01[y & 0x1UL]; 137 | } 138 | y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK); 139 | mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL]; 140 | 141 | mti = 0; 142 | } 143 | 144 | y = mt[mti++]; 145 | 146 | /* Tempering */ 147 | y ^= (y >> 11); 148 | y ^= (y << 7) & 0x9d2c5680UL; 149 | y ^= (y << 15) & 0xefc60000UL; 150 | y ^= (y >> 18); 151 | 152 | return y; 153 | } 154 | 155 | /* generates a random number on [0,0x7fffffff]-interval */ 156 | long genrand_int31(void) 157 | { 158 | return (long)(genrand_int32()>>1); 159 | } 160 | 161 | /* generates a random number on [0,1]-real-interval */ 162 | double genrand_real1(void) 163 | { 164 | return genrand_int32()*(1.0/4294967295.0); 165 | /* divided by 2^32-1 */ 166 | } 167 | 168 | /* generates a random number on [0,1)-real-interval */ 169 | double genrand_real2(void) 170 | { 171 | return genrand_int32()*(1.0/4294967296.0); 172 | /* divided by 2^32 */ 173 | } 174 | 175 | /* generates a random number on (0,1)-real-interval */ 176 | double genrand_real3(void) 177 | { 178 | return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0); 179 | /* divided by 2^32 */ 180 | } 181 | 182 | /* generates a random number on [0,1) with 53-bit resolution*/ 183 | double genrand_res53(void) 184 | { 185 | unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6; 186 | return(a*67108864.0+b)*(1.0/9007199254740992.0); 187 | } 188 | /* These real versions are due to Isaku Wada, 2002/01/09 added */ 189 | 190 | void SetSeed(unsigned long seed) 191 | { 192 | init_genrand(seed); 193 | } 194 | 195 | unsigned long CreateSeed( ) 196 | { 197 | static unsigned long differ = 0; // guarantee time-based seeds will change 198 | 199 | // Get a uint32 from t and c 200 | // Better than uint32(x) in case x is floating point in [0,1] 201 | // Based on code by Lawrence Kirby (fred@genesis.demon.co.uk) 202 | time_t t = time(NULL); 203 | clock_t c = clock(); 204 | 205 | unsigned long h1 = 0; 206 | unsigned long h2 = 0; 207 | 208 | unsigned char *p = (unsigned char *) &t; 209 | 210 | size_t i, j; 211 | 212 | for( i = 0; i < sizeof(t); ++i ) 213 | { 214 | h1 *= UCHAR_MAX + 2U; 215 | h1 += p[i]; 216 | } 217 | p = (unsigned char *) &c; 218 | for( j = 0; j < sizeof(c); ++j ) 219 | { 220 | h2 *= UCHAR_MAX + 2U; 221 | h2 += p[j]; 222 | } 223 | return ( h1 + differ++ ) ^ h2; 224 | } 225 | 226 | double rndu() 227 | { 228 | return genrand_real1(); 229 | } 230 | 231 | 232 | --------------------------------------------------------------------------------