├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── LICENSE ├── Makefile.am ├── Makefile.in ├── NEWS ├── README ├── README.md ├── aclocal.m4 ├── configure ├── configure.ac ├── data ├── oracle_beta.txt ├── oracle_theta.txt ├── output_theta.txt ├── run.sh ├── test.bed ├── test.bim └── test.fam ├── depcomp ├── docs └── supplementary_materials.pdf ├── install-sh ├── missing ├── scripts └── data │ ├── HGDP.txt │ ├── HGDP_text_to_tped.py │ ├── TGP.txt │ └── TGP_unrel.txt └── src ├── Makefile.am ├── Makefile.in ├── env.hh ├── lib.hh ├── log.cc ├── log.hh ├── main.cc ├── matrix.hh ├── snp.cc ├── snp.hh ├── snpsamplinge.cc ├── snpsamplinge.hh ├── thread.cc ├── thread.hh └── tsqueue.hh /AUTHORS: -------------------------------------------------------------------------------- 1 | Prem Gopalan 2 | pgopalan@cs.princeton.edu 3 | 4 | Wei Hao 5 | whao@princeton.edu 6 | 7 | David M. Blei 8 | blei@cs.princeton.edu 9 | 10 | John D. Storey 11 | jstorey@princeton.edu 12 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StoreyLab/terastructure/6ae8854253822effb010a56a3ef6caf8909f6861/ChangeLog -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Installation Instructions 2 | ************************* 3 | 4 | Copyright (C) 1994-1996, 1999-2002, 2004-2011 Free Software Foundation, 5 | Inc. 6 | 7 | Copying and distribution of this file, with or without modification, 8 | are permitted in any medium without royalty provided the copyright 9 | notice and this notice are preserved. This file is offered as-is, 10 | without warranty of any kind. 11 | 12 | Basic Installation 13 | ================== 14 | 15 | Briefly, the shell commands `./configure; make; make install' should 16 | configure, build, and install this package. The following 17 | more-detailed instructions are generic; see the `README' file for 18 | instructions specific to this package. Some packages provide this 19 | `INSTALL' file but do not implement all of the features documented 20 | below. The lack of an optional feature in a given package is not 21 | necessarily a bug. More recommendations for GNU packages can be found 22 | in *note Makefile Conventions: (standards)Makefile Conventions. 23 | 24 | The `configure' shell script attempts to guess correct values for 25 | various system-dependent variables used during compilation. It uses 26 | those values to create a `Makefile' in each directory of the package. 27 | It may also create one or more `.h' files containing system-dependent 28 | definitions. Finally, it creates a shell script `config.status' that 29 | you can run in the future to recreate the current configuration, and a 30 | file `config.log' containing compiler output (useful mainly for 31 | debugging `configure'). 32 | 33 | It can also use an optional file (typically called `config.cache' 34 | and enabled with `--cache-file=config.cache' or simply `-C') that saves 35 | the results of its tests to speed up reconfiguring. Caching is 36 | disabled by default to prevent problems with accidental use of stale 37 | cache files. 38 | 39 | If you need to do unusual things to compile the package, please try 40 | to figure out how `configure' could check whether to do them, and mail 41 | diffs or instructions to the address given in the `README' so they can 42 | be considered for the next release. If you are using the cache, and at 43 | some point `config.cache' contains results you don't want to keep, you 44 | may remove or edit it. 45 | 46 | The file `configure.ac' (or `configure.in') is used to create 47 | `configure' by a program called `autoconf'. You need `configure.ac' if 48 | you want to change it or regenerate `configure' using a newer version 49 | of `autoconf'. 50 | 51 | The simplest way to compile this package is: 52 | 53 | 1. `cd' to the directory containing the package's source code and type 54 | `./configure' to configure the package for your system. 55 | 56 | Running `configure' might take a while. While running, it prints 57 | some messages telling which features it is checking for. 58 | 59 | 2. Type `make' to compile the package. 60 | 61 | 3. Optionally, type `make check' to run any self-tests that come with 62 | the package, generally using the just-built uninstalled binaries. 63 | 64 | 4. Type `make install' to install the programs and any data files and 65 | documentation. When installing into a prefix owned by root, it is 66 | recommended that the package be configured and built as a regular 67 | user, and only the `make install' phase executed with root 68 | privileges. 69 | 70 | 5. Optionally, type `make installcheck' to repeat any self-tests, but 71 | this time using the binaries in their final installed location. 72 | This target does not install anything. Running this target as a 73 | regular user, particularly if the prior `make install' required 74 | root privileges, verifies that the installation completed 75 | correctly. 76 | 77 | 6. You can remove the program binaries and object files from the 78 | source code directory by typing `make clean'. To also remove the 79 | files that `configure' created (so you can compile the package for 80 | a different kind of computer), type `make distclean'. There is 81 | also a `make maintainer-clean' target, but that is intended mainly 82 | for the package's developers. If you use it, you may have to get 83 | all sorts of other programs in order to regenerate files that came 84 | with the distribution. 85 | 86 | 7. Often, you can also type `make uninstall' to remove the installed 87 | files again. In practice, not all packages have tested that 88 | uninstallation works correctly, even though it is required by the 89 | GNU Coding Standards. 90 | 91 | 8. Some packages, particularly those that use Automake, provide `make 92 | distcheck', which can by used by developers to test that all other 93 | targets like `make install' and `make uninstall' work correctly. 94 | This target is generally not run by end users. 95 | 96 | Compilers and Options 97 | ===================== 98 | 99 | Some systems require unusual options for compilation or linking that 100 | the `configure' script does not know about. Run `./configure --help' 101 | for details on some of the pertinent environment variables. 102 | 103 | You can give `configure' initial values for configuration parameters 104 | by setting variables in the command line or in the environment. Here 105 | is an example: 106 | 107 | ./configure CC=c99 CFLAGS=-g LIBS=-lposix 108 | 109 | *Note Defining Variables::, for more details. 110 | 111 | Compiling For Multiple Architectures 112 | ==================================== 113 | 114 | You can compile the package for more than one kind of computer at the 115 | same time, by placing the object files for each architecture in their 116 | own directory. To do this, you can use GNU `make'. `cd' to the 117 | directory where you want the object files and executables to go and run 118 | the `configure' script. `configure' automatically checks for the 119 | source code in the directory that `configure' is in and in `..'. This 120 | is known as a "VPATH" build. 121 | 122 | With a non-GNU `make', it is safer to compile the package for one 123 | architecture at a time in the source code directory. After you have 124 | installed the package for one architecture, use `make distclean' before 125 | reconfiguring for another architecture. 126 | 127 | On MacOS X 10.5 and later systems, you can create libraries and 128 | executables that work on multiple system types--known as "fat" or 129 | "universal" binaries--by specifying multiple `-arch' options to the 130 | compiler but only a single `-arch' option to the preprocessor. Like 131 | this: 132 | 133 | ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 134 | CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 135 | CPP="gcc -E" CXXCPP="g++ -E" 136 | 137 | This is not guaranteed to produce working output in all cases, you 138 | may have to build one architecture at a time and combine the results 139 | using the `lipo' tool if you have problems. 140 | 141 | Installation Names 142 | ================== 143 | 144 | By default, `make install' installs the package's commands under 145 | `/usr/local/bin', include files under `/usr/local/include', etc. You 146 | can specify an installation prefix other than `/usr/local' by giving 147 | `configure' the option `--prefix=PREFIX', where PREFIX must be an 148 | absolute file name. 149 | 150 | You can specify separate installation prefixes for 151 | architecture-specific files and architecture-independent files. If you 152 | pass the option `--exec-prefix=PREFIX' to `configure', the package uses 153 | PREFIX as the prefix for installing programs and libraries. 154 | Documentation and other data files still use the regular prefix. 155 | 156 | In addition, if you use an unusual directory layout you can give 157 | options like `--bindir=DIR' to specify different values for particular 158 | kinds of files. Run `configure --help' for a list of the directories 159 | you can set and what kinds of files go in them. In general, the 160 | default for these options is expressed in terms of `${prefix}', so that 161 | specifying just `--prefix' will affect all of the other directory 162 | specifications that were not explicitly provided. 163 | 164 | The most portable way to affect installation locations is to pass the 165 | correct locations to `configure'; however, many packages provide one or 166 | both of the following shortcuts of passing variable assignments to the 167 | `make install' command line to change installation locations without 168 | having to reconfigure or recompile. 169 | 170 | The first method involves providing an override variable for each 171 | affected directory. For example, `make install 172 | prefix=/alternate/directory' will choose an alternate location for all 173 | directory configuration variables that were expressed in terms of 174 | `${prefix}'. Any directories that were specified during `configure', 175 | but not in terms of `${prefix}', must each be overridden at install 176 | time for the entire installation to be relocated. The approach of 177 | makefile variable overrides for each directory variable is required by 178 | the GNU Coding Standards, and ideally causes no recompilation. 179 | However, some platforms have known limitations with the semantics of 180 | shared libraries that end up requiring recompilation when using this 181 | method, particularly noticeable in packages that use GNU Libtool. 182 | 183 | The second method involves providing the `DESTDIR' variable. For 184 | example, `make install DESTDIR=/alternate/directory' will prepend 185 | `/alternate/directory' before all installation names. The approach of 186 | `DESTDIR' overrides is not required by the GNU Coding Standards, and 187 | does not work on platforms that have drive letters. On the other hand, 188 | it does better at avoiding recompilation issues, and works well even 189 | when some directory options were not specified in terms of `${prefix}' 190 | at `configure' time. 191 | 192 | Optional Features 193 | ================= 194 | 195 | If the package supports it, you can cause programs to be installed 196 | with an extra prefix or suffix on their names by giving `configure' the 197 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. 198 | 199 | Some packages pay attention to `--enable-FEATURE' options to 200 | `configure', where FEATURE indicates an optional part of the package. 201 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE 202 | is something like `gnu-as' or `x' (for the X Window System). The 203 | `README' should mention any `--enable-' and `--with-' options that the 204 | package recognizes. 205 | 206 | For packages that use the X Window System, `configure' can usually 207 | find the X include and library files automatically, but if it doesn't, 208 | you can use the `configure' options `--x-includes=DIR' and 209 | `--x-libraries=DIR' to specify their locations. 210 | 211 | Some packages offer the ability to configure how verbose the 212 | execution of `make' will be. For these packages, running `./configure 213 | --enable-silent-rules' sets the default to minimal output, which can be 214 | overridden with `make V=1'; while running `./configure 215 | --disable-silent-rules' sets the default to verbose, which can be 216 | overridden with `make V=0'. 217 | 218 | Particular systems 219 | ================== 220 | 221 | On HP-UX, the default C compiler is not ANSI C compatible. If GNU 222 | CC is not installed, it is recommended to use the following options in 223 | order to use an ANSI C compiler: 224 | 225 | ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" 226 | 227 | and if that doesn't work, install pre-built binaries of GCC for HP-UX. 228 | 229 | HP-UX `make' updates targets which have the same time stamps as 230 | their prerequisites, which makes it generally unusable when shipped 231 | generated files such as `configure' are involved. Use GNU `make' 232 | instead. 233 | 234 | On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot 235 | parse its `' header file. The option `-nodtk' can be used as 236 | a workaround. If GNU CC is not installed, it is therefore recommended 237 | to try 238 | 239 | ./configure CC="cc" 240 | 241 | and if that doesn't work, try 242 | 243 | ./configure CC="cc -nodtk" 244 | 245 | On Solaris, don't put `/usr/ucb' early in your `PATH'. This 246 | directory contains several dysfunctional programs; working variants of 247 | these programs are available in `/usr/bin'. So, if you need `/usr/ucb' 248 | in your `PATH', put it _after_ `/usr/bin'. 249 | 250 | On Haiku, software installed for all users goes in `/boot/common', 251 | not `/usr/local'. It is recommended to use the following options: 252 | 253 | ./configure --prefix=/boot/common 254 | 255 | Specifying the System Type 256 | ========================== 257 | 258 | There may be some features `configure' cannot figure out 259 | automatically, but needs to determine by the type of machine the package 260 | will run on. Usually, assuming the package is built to be run on the 261 | _same_ architectures, `configure' can figure that out, but if it prints 262 | a message saying it cannot guess the machine type, give it the 263 | `--build=TYPE' option. TYPE can either be a short name for the system 264 | type, such as `sun4', or a canonical name which has the form: 265 | 266 | CPU-COMPANY-SYSTEM 267 | 268 | where SYSTEM can have one of these forms: 269 | 270 | OS 271 | KERNEL-OS 272 | 273 | See the file `config.sub' for the possible values of each field. If 274 | `config.sub' isn't included in this package, then this package doesn't 275 | need to know the machine type. 276 | 277 | If you are _building_ compiler tools for cross-compiling, you should 278 | use the option `--target=TYPE' to select the type of system they will 279 | produce code for. 280 | 281 | If you want to _use_ a cross compiler, that generates code for a 282 | platform different from the build platform, you should specify the 283 | "host" platform (i.e., that on which the generated programs will 284 | eventually be run) with `--host=TYPE'. 285 | 286 | Sharing Defaults 287 | ================ 288 | 289 | If you want to set default values for `configure' scripts to share, 290 | you can create a site shell script called `config.site' that gives 291 | default values for variables like `CC', `cache_file', and `prefix'. 292 | `configure' looks for `PREFIX/share/config.site' if it exists, then 293 | `PREFIX/etc/config.site' if it exists. Or, you can set the 294 | `CONFIG_SITE' environment variable to the location of the site script. 295 | A warning: not all `configure' scripts look for a site script. 296 | 297 | Defining Variables 298 | ================== 299 | 300 | Variables not defined in a site shell script can be set in the 301 | environment passed to `configure'. However, some packages may run 302 | configure again during the build, and the customized values of these 303 | variables may be lost. In order to avoid this problem, you should set 304 | them in the `configure' command line, using `VAR=value'. For example: 305 | 306 | ./configure CC=/usr/local2/bin/gcc 307 | 308 | causes the specified `gcc' to be used as the C compiler (unless it is 309 | overridden in the site shell script). 310 | 311 | Unfortunately, this technique does not work for `CONFIG_SHELL' due to 312 | an Autoconf bug. Until the bug is fixed you can use this workaround: 313 | 314 | CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash 315 | 316 | `configure' Invocation 317 | ====================== 318 | 319 | `configure' recognizes the following options to control how it 320 | operates. 321 | 322 | `--help' 323 | `-h' 324 | Print a summary of all of the options to `configure', and exit. 325 | 326 | `--help=short' 327 | `--help=recursive' 328 | Print a summary of the options unique to this package's 329 | `configure', and exit. The `short' variant lists options used 330 | only in the top level, while the `recursive' variant lists options 331 | also present in any nested packages. 332 | 333 | `--version' 334 | `-V' 335 | Print the version of Autoconf used to generate the `configure' 336 | script, and exit. 337 | 338 | `--cache-file=FILE' 339 | Enable the cache: use and save the results of the tests in FILE, 340 | traditionally `config.cache'. FILE defaults to `/dev/null' to 341 | disable caching. 342 | 343 | `--config-cache' 344 | `-C' 345 | Alias for `--cache-file=config.cache'. 346 | 347 | `--quiet' 348 | `--silent' 349 | `-q' 350 | Do not print messages saying which checks are being made. To 351 | suppress all normal output, redirect it to `/dev/null' (any error 352 | messages will still be shown). 353 | 354 | `--srcdir=DIR' 355 | Look for the package's source code in directory DIR. Usually 356 | `configure' can determine that directory automatically. 357 | 358 | `--prefix=DIR' 359 | Use DIR as the installation prefix. *note Installation Names:: 360 | for more details, including other options available for fine-tuning 361 | the installation locations. 362 | 363 | `--no-create' 364 | `-n' 365 | Run the configure checks, but stop before creating any output 366 | files. 367 | 368 | `configure' also accepts some other, not widely useful, options. Run 369 | `configure --help' for more details. 370 | 371 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = src 2 | EXTRA_DIST = 3 | -------------------------------------------------------------------------------- /Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile.in generated by automake 1.11.1 from Makefile.am. 2 | # @configure_input@ 3 | 4 | # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 5 | # 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, 6 | # Inc. 7 | # This Makefile.in is free software; the Free Software Foundation 8 | # gives unlimited permission to copy and/or distribute it, 9 | # with or without modifications, as long as this notice is preserved. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without 13 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A 14 | # PARTICULAR PURPOSE. 15 | 16 | @SET_MAKE@ 17 | VPATH = @srcdir@ 18 | pkgdatadir = $(datadir)/@PACKAGE@ 19 | pkgincludedir = $(includedir)/@PACKAGE@ 20 | pkglibdir = $(libdir)/@PACKAGE@ 21 | pkglibexecdir = $(libexecdir)/@PACKAGE@ 22 | am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd 23 | install_sh_DATA = $(install_sh) -c -m 644 24 | install_sh_PROGRAM = $(install_sh) -c 25 | install_sh_SCRIPT = $(install_sh) -c 26 | INSTALL_HEADER = $(INSTALL_DATA) 27 | transform = $(program_transform_name) 28 | NORMAL_INSTALL = : 29 | PRE_INSTALL = : 30 | POST_INSTALL = : 31 | NORMAL_UNINSTALL = : 32 | PRE_UNINSTALL = : 33 | POST_UNINSTALL = : 34 | subdir = . 35 | DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \ 36 | $(srcdir)/Makefile.in $(top_srcdir)/configure AUTHORS COPYING \ 37 | ChangeLog INSTALL NEWS depcomp install-sh missing 38 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 39 | am__aclocal_m4_deps = $(top_srcdir)/configure.ac 40 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ 41 | $(ACLOCAL_M4) 42 | am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ 43 | configure.lineno config.status.lineno 44 | mkinstalldirs = $(install_sh) -d 45 | CONFIG_CLEAN_FILES = 46 | CONFIG_CLEAN_VPATH_FILES = 47 | SOURCES = 48 | DIST_SOURCES = 49 | RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ 50 | html-recursive info-recursive install-data-recursive \ 51 | install-dvi-recursive install-exec-recursive \ 52 | install-html-recursive install-info-recursive \ 53 | install-pdf-recursive install-ps-recursive install-recursive \ 54 | installcheck-recursive installdirs-recursive pdf-recursive \ 55 | ps-recursive uninstall-recursive 56 | RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ 57 | distclean-recursive maintainer-clean-recursive 58 | AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ 59 | $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \ 60 | distdir dist dist-all distcheck 61 | ETAGS = etags 62 | CTAGS = ctags 63 | DIST_SUBDIRS = $(SUBDIRS) 64 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) 65 | distdir = $(PACKAGE)-$(VERSION) 66 | top_distdir = $(distdir) 67 | am__remove_distdir = \ 68 | { test ! -d "$(distdir)" \ 69 | || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \ 70 | && rm -fr "$(distdir)"; }; } 71 | am__relativize = \ 72 | dir0=`pwd`; \ 73 | sed_first='s,^\([^/]*\)/.*$$,\1,'; \ 74 | sed_rest='s,^[^/]*/*,,'; \ 75 | sed_last='s,^.*/\([^/]*\)$$,\1,'; \ 76 | sed_butlast='s,/*[^/]*$$,,'; \ 77 | while test -n "$$dir1"; do \ 78 | first=`echo "$$dir1" | sed -e "$$sed_first"`; \ 79 | if test "$$first" != "."; then \ 80 | if test "$$first" = ".."; then \ 81 | dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ 82 | dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ 83 | else \ 84 | first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ 85 | if test "$$first2" = "$$first"; then \ 86 | dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ 87 | else \ 88 | dir2="../$$dir2"; \ 89 | fi; \ 90 | dir0="$$dir0"/"$$first"; \ 91 | fi; \ 92 | fi; \ 93 | dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ 94 | done; \ 95 | reldir="$$dir2" 96 | DIST_ARCHIVES = $(distdir).tar.gz 97 | GZIP_ENV = --best 98 | distuninstallcheck_listfiles = find . -type f -print 99 | distcleancheck_listfiles = find . -type f -print 100 | ACLOCAL = @ACLOCAL@ 101 | AMTAR = @AMTAR@ 102 | AUTOCONF = @AUTOCONF@ 103 | AUTOHEADER = @AUTOHEADER@ 104 | AUTOMAKE = @AUTOMAKE@ 105 | AWK = @AWK@ 106 | CC = @CC@ 107 | CCDEPMODE = @CCDEPMODE@ 108 | CFLAGS = @CFLAGS@ 109 | CPP = @CPP@ 110 | CPPFLAGS = @CPPFLAGS@ 111 | CXX = @CXX@ 112 | CXXDEPMODE = @CXXDEPMODE@ 113 | CXXFLAGS = @CXXFLAGS@ 114 | CYGPATH_W = @CYGPATH_W@ 115 | DEFS = @DEFS@ 116 | DEPDIR = @DEPDIR@ 117 | ECHO_C = @ECHO_C@ 118 | ECHO_N = @ECHO_N@ 119 | ECHO_T = @ECHO_T@ 120 | EGREP = @EGREP@ 121 | EXEEXT = @EXEEXT@ 122 | GREP = @GREP@ 123 | INSTALL = @INSTALL@ 124 | INSTALL_DATA = @INSTALL_DATA@ 125 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 126 | INSTALL_SCRIPT = @INSTALL_SCRIPT@ 127 | INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ 128 | LDFLAGS = @LDFLAGS@ 129 | LIBOBJS = @LIBOBJS@ 130 | LIBS = @LIBS@ 131 | LTLIBOBJS = @LTLIBOBJS@ 132 | MAKEINFO = @MAKEINFO@ 133 | MKDIR_P = @MKDIR_P@ 134 | OBJEXT = @OBJEXT@ 135 | PACKAGE = @PACKAGE@ 136 | PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ 137 | PACKAGE_NAME = @PACKAGE_NAME@ 138 | PACKAGE_STRING = @PACKAGE_STRING@ 139 | PACKAGE_TARNAME = @PACKAGE_TARNAME@ 140 | PACKAGE_VERSION = @PACKAGE_VERSION@ 141 | PATH_SEPARATOR = @PATH_SEPARATOR@ 142 | POW_LIB = @POW_LIB@ 143 | SET_MAKE = @SET_MAKE@ 144 | SHELL = @SHELL@ 145 | STRIP = @STRIP@ 146 | VERSION = @VERSION@ 147 | abs_builddir = @abs_builddir@ 148 | abs_srcdir = @abs_srcdir@ 149 | abs_top_builddir = @abs_top_builddir@ 150 | abs_top_srcdir = @abs_top_srcdir@ 151 | ac_ct_CC = @ac_ct_CC@ 152 | ac_ct_CXX = @ac_ct_CXX@ 153 | am__include = @am__include@ 154 | am__leading_dot = @am__leading_dot@ 155 | am__quote = @am__quote@ 156 | am__tar = @am__tar@ 157 | am__untar = @am__untar@ 158 | bindir = @bindir@ 159 | build_alias = @build_alias@ 160 | builddir = @builddir@ 161 | datadir = @datadir@ 162 | datarootdir = @datarootdir@ 163 | docdir = @docdir@ 164 | dvidir = @dvidir@ 165 | exec_prefix = @exec_prefix@ 166 | host_alias = @host_alias@ 167 | htmldir = @htmldir@ 168 | includedir = @includedir@ 169 | infodir = @infodir@ 170 | install_sh = @install_sh@ 171 | libdir = @libdir@ 172 | libexecdir = @libexecdir@ 173 | localedir = @localedir@ 174 | localstatedir = @localstatedir@ 175 | mandir = @mandir@ 176 | mkdir_p = @mkdir_p@ 177 | oldincludedir = @oldincludedir@ 178 | pdfdir = @pdfdir@ 179 | prefix = @prefix@ 180 | program_transform_name = @program_transform_name@ 181 | psdir = @psdir@ 182 | sbindir = @sbindir@ 183 | sharedstatedir = @sharedstatedir@ 184 | srcdir = @srcdir@ 185 | sysconfdir = @sysconfdir@ 186 | target_alias = @target_alias@ 187 | top_build_prefix = @top_build_prefix@ 188 | top_builddir = @top_builddir@ 189 | top_srcdir = @top_srcdir@ 190 | SUBDIRS = src 191 | EXTRA_DIST = 192 | all: all-recursive 193 | 194 | .SUFFIXES: 195 | am--refresh: 196 | @: 197 | $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) 198 | @for dep in $?; do \ 199 | case '$(am__configure_deps)' in \ 200 | *$$dep*) \ 201 | echo ' cd $(srcdir) && $(AUTOMAKE) --gnu'; \ 202 | $(am__cd) $(srcdir) && $(AUTOMAKE) --gnu \ 203 | && exit 0; \ 204 | exit 1;; \ 205 | esac; \ 206 | done; \ 207 | echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \ 208 | $(am__cd) $(top_srcdir) && \ 209 | $(AUTOMAKE) --gnu Makefile 210 | .PRECIOUS: Makefile 211 | Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status 212 | @case '$?' in \ 213 | *config.status*) \ 214 | echo ' $(SHELL) ./config.status'; \ 215 | $(SHELL) ./config.status;; \ 216 | *) \ 217 | echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \ 218 | cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \ 219 | esac; 220 | 221 | $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) 222 | $(SHELL) ./config.status --recheck 223 | 224 | $(top_srcdir)/configure: $(am__configure_deps) 225 | $(am__cd) $(srcdir) && $(AUTOCONF) 226 | $(ACLOCAL_M4): $(am__aclocal_m4_deps) 227 | $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) 228 | $(am__aclocal_m4_deps): 229 | 230 | # This directory's subdirectories are mostly independent; you can cd 231 | # into them and run `make' without going through this Makefile. 232 | # To change the values of `make' variables: instead of editing Makefiles, 233 | # (1) if the variable is set in `config.status', edit `config.status' 234 | # (which will cause the Makefiles to be regenerated when you run `make'); 235 | # (2) otherwise, pass the desired values on the `make' command line. 236 | $(RECURSIVE_TARGETS): 237 | @fail= failcom='exit 1'; \ 238 | for f in x $$MAKEFLAGS; do \ 239 | case $$f in \ 240 | *=* | --[!k]*);; \ 241 | *k*) failcom='fail=yes';; \ 242 | esac; \ 243 | done; \ 244 | dot_seen=no; \ 245 | target=`echo $@ | sed s/-recursive//`; \ 246 | list='$(SUBDIRS)'; for subdir in $$list; do \ 247 | echo "Making $$target in $$subdir"; \ 248 | if test "$$subdir" = "."; then \ 249 | dot_seen=yes; \ 250 | local_target="$$target-am"; \ 251 | else \ 252 | local_target="$$target"; \ 253 | fi; \ 254 | ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ 255 | || eval $$failcom; \ 256 | done; \ 257 | if test "$$dot_seen" = "no"; then \ 258 | $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ 259 | fi; test -z "$$fail" 260 | 261 | $(RECURSIVE_CLEAN_TARGETS): 262 | @fail= failcom='exit 1'; \ 263 | for f in x $$MAKEFLAGS; do \ 264 | case $$f in \ 265 | *=* | --[!k]*);; \ 266 | *k*) failcom='fail=yes';; \ 267 | esac; \ 268 | done; \ 269 | dot_seen=no; \ 270 | case "$@" in \ 271 | distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ 272 | *) list='$(SUBDIRS)' ;; \ 273 | esac; \ 274 | rev=''; for subdir in $$list; do \ 275 | if test "$$subdir" = "."; then :; else \ 276 | rev="$$subdir $$rev"; \ 277 | fi; \ 278 | done; \ 279 | rev="$$rev ."; \ 280 | target=`echo $@ | sed s/-recursive//`; \ 281 | for subdir in $$rev; do \ 282 | echo "Making $$target in $$subdir"; \ 283 | if test "$$subdir" = "."; then \ 284 | local_target="$$target-am"; \ 285 | else \ 286 | local_target="$$target"; \ 287 | fi; \ 288 | ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ 289 | || eval $$failcom; \ 290 | done && test -z "$$fail" 291 | tags-recursive: 292 | list='$(SUBDIRS)'; for subdir in $$list; do \ 293 | test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ 294 | done 295 | ctags-recursive: 296 | list='$(SUBDIRS)'; for subdir in $$list; do \ 297 | test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ 298 | done 299 | 300 | ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) 301 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 302 | unique=`for i in $$list; do \ 303 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 304 | done | \ 305 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ 306 | END { if (nonempty) { for (i in files) print i; }; }'`; \ 307 | mkid -fID $$unique 308 | tags: TAGS 309 | 310 | TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ 311 | $(TAGS_FILES) $(LISP) 312 | set x; \ 313 | here=`pwd`; \ 314 | if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ 315 | include_option=--etags-include; \ 316 | empty_fix=.; \ 317 | else \ 318 | include_option=--include; \ 319 | empty_fix=; \ 320 | fi; \ 321 | list='$(SUBDIRS)'; for subdir in $$list; do \ 322 | if test "$$subdir" = .; then :; else \ 323 | test ! -f $$subdir/TAGS || \ 324 | set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ 325 | fi; \ 326 | done; \ 327 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 328 | unique=`for i in $$list; do \ 329 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 330 | done | \ 331 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ 332 | END { if (nonempty) { for (i in files) print i; }; }'`; \ 333 | shift; \ 334 | if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ 335 | test -n "$$unique" || unique=$$empty_fix; \ 336 | if test $$# -gt 0; then \ 337 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ 338 | "$$@" $$unique; \ 339 | else \ 340 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ 341 | $$unique; \ 342 | fi; \ 343 | fi 344 | ctags: CTAGS 345 | CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ 346 | $(TAGS_FILES) $(LISP) 347 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 348 | unique=`for i in $$list; do \ 349 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 350 | done | \ 351 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ 352 | END { if (nonempty) { for (i in files) print i; }; }'`; \ 353 | test -z "$(CTAGS_ARGS)$$unique" \ 354 | || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ 355 | $$unique 356 | 357 | GTAGS: 358 | here=`$(am__cd) $(top_builddir) && pwd` \ 359 | && $(am__cd) $(top_srcdir) \ 360 | && gtags -i $(GTAGS_ARGS) "$$here" 361 | 362 | distclean-tags: 363 | -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags 364 | 365 | distdir: $(DISTFILES) 366 | $(am__remove_distdir) 367 | test -d "$(distdir)" || mkdir "$(distdir)" 368 | @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 369 | topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 370 | list='$(DISTFILES)'; \ 371 | dist_files=`for file in $$list; do echo $$file; done | \ 372 | sed -e "s|^$$srcdirstrip/||;t" \ 373 | -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ 374 | case $$dist_files in \ 375 | */*) $(MKDIR_P) `echo "$$dist_files" | \ 376 | sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ 377 | sort -u` ;; \ 378 | esac; \ 379 | for file in $$dist_files; do \ 380 | if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ 381 | if test -d $$d/$$file; then \ 382 | dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ 383 | if test -d "$(distdir)/$$file"; then \ 384 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ 385 | fi; \ 386 | if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ 387 | cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ 388 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ 389 | fi; \ 390 | cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ 391 | else \ 392 | test -f "$(distdir)/$$file" \ 393 | || cp -p $$d/$$file "$(distdir)/$$file" \ 394 | || exit 1; \ 395 | fi; \ 396 | done 397 | @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ 398 | if test "$$subdir" = .; then :; else \ 399 | test -d "$(distdir)/$$subdir" \ 400 | || $(MKDIR_P) "$(distdir)/$$subdir" \ 401 | || exit 1; \ 402 | fi; \ 403 | done 404 | @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ 405 | if test "$$subdir" = .; then :; else \ 406 | dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ 407 | $(am__relativize); \ 408 | new_distdir=$$reldir; \ 409 | dir1=$$subdir; dir2="$(top_distdir)"; \ 410 | $(am__relativize); \ 411 | new_top_distdir=$$reldir; \ 412 | echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ 413 | echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ 414 | ($(am__cd) $$subdir && \ 415 | $(MAKE) $(AM_MAKEFLAGS) \ 416 | top_distdir="$$new_top_distdir" \ 417 | distdir="$$new_distdir" \ 418 | am__remove_distdir=: \ 419 | am__skip_length_check=: \ 420 | am__skip_mode_fix=: \ 421 | distdir) \ 422 | || exit 1; \ 423 | fi; \ 424 | done 425 | -test -n "$(am__skip_mode_fix)" \ 426 | || find "$(distdir)" -type d ! -perm -755 \ 427 | -exec chmod u+rwx,go+rx {} \; -o \ 428 | ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ 429 | ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ 430 | ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ 431 | || chmod -R a+r "$(distdir)" 432 | dist-gzip: distdir 433 | tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz 434 | $(am__remove_distdir) 435 | 436 | dist-bzip2: distdir 437 | tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2 438 | $(am__remove_distdir) 439 | 440 | dist-lzma: distdir 441 | tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma 442 | $(am__remove_distdir) 443 | 444 | dist-xz: distdir 445 | tardir=$(distdir) && $(am__tar) | xz -c >$(distdir).tar.xz 446 | $(am__remove_distdir) 447 | 448 | dist-tarZ: distdir 449 | tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z 450 | $(am__remove_distdir) 451 | 452 | dist-shar: distdir 453 | shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz 454 | $(am__remove_distdir) 455 | 456 | dist-zip: distdir 457 | -rm -f $(distdir).zip 458 | zip -rq $(distdir).zip $(distdir) 459 | $(am__remove_distdir) 460 | 461 | dist dist-all: distdir 462 | tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz 463 | $(am__remove_distdir) 464 | 465 | # This target untars the dist file and tries a VPATH configuration. Then 466 | # it guarantees that the distribution is self-contained by making another 467 | # tarfile. 468 | distcheck: dist 469 | case '$(DIST_ARCHIVES)' in \ 470 | *.tar.gz*) \ 471 | GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ 472 | *.tar.bz2*) \ 473 | bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ 474 | *.tar.lzma*) \ 475 | lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\ 476 | *.tar.xz*) \ 477 | xz -dc $(distdir).tar.xz | $(am__untar) ;;\ 478 | *.tar.Z*) \ 479 | uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ 480 | *.shar.gz*) \ 481 | GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\ 482 | *.zip*) \ 483 | unzip $(distdir).zip ;;\ 484 | esac 485 | chmod -R a-w $(distdir); chmod u+w $(distdir) 486 | mkdir $(distdir)/_build 487 | mkdir $(distdir)/_inst 488 | chmod a-w $(distdir) 489 | test -d $(distdir)/_build || exit 0; \ 490 | dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ 491 | && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ 492 | && am__cwd=`pwd` \ 493 | && $(am__cd) $(distdir)/_build \ 494 | && ../configure --srcdir=.. --prefix="$$dc_install_base" \ 495 | $(DISTCHECK_CONFIGURE_FLAGS) \ 496 | && $(MAKE) $(AM_MAKEFLAGS) \ 497 | && $(MAKE) $(AM_MAKEFLAGS) dvi \ 498 | && $(MAKE) $(AM_MAKEFLAGS) check \ 499 | && $(MAKE) $(AM_MAKEFLAGS) install \ 500 | && $(MAKE) $(AM_MAKEFLAGS) installcheck \ 501 | && $(MAKE) $(AM_MAKEFLAGS) uninstall \ 502 | && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \ 503 | distuninstallcheck \ 504 | && chmod -R a-w "$$dc_install_base" \ 505 | && ({ \ 506 | (cd ../.. && umask 077 && mkdir "$$dc_destdir") \ 507 | && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \ 508 | && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \ 509 | && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \ 510 | distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \ 511 | } || { rm -rf "$$dc_destdir"; exit 1; }) \ 512 | && rm -rf "$$dc_destdir" \ 513 | && $(MAKE) $(AM_MAKEFLAGS) dist \ 514 | && rm -rf $(DIST_ARCHIVES) \ 515 | && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \ 516 | && cd "$$am__cwd" \ 517 | || exit 1 518 | $(am__remove_distdir) 519 | @(echo "$(distdir) archives ready for distribution: "; \ 520 | list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ 521 | sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' 522 | distuninstallcheck: 523 | @$(am__cd) '$(distuninstallcheck_dir)' \ 524 | && test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \ 525 | || { echo "ERROR: files left after uninstall:" ; \ 526 | if test -n "$(DESTDIR)"; then \ 527 | echo " (check DESTDIR support)"; \ 528 | fi ; \ 529 | $(distuninstallcheck_listfiles) ; \ 530 | exit 1; } >&2 531 | distcleancheck: distclean 532 | @if test '$(srcdir)' = . ; then \ 533 | echo "ERROR: distcleancheck can only run from a VPATH build" ; \ 534 | exit 1 ; \ 535 | fi 536 | @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \ 537 | || { echo "ERROR: files left in build directory after distclean:" ; \ 538 | $(distcleancheck_listfiles) ; \ 539 | exit 1; } >&2 540 | check-am: all-am 541 | check: check-recursive 542 | all-am: Makefile 543 | installdirs: installdirs-recursive 544 | installdirs-am: 545 | install: install-recursive 546 | install-exec: install-exec-recursive 547 | install-data: install-data-recursive 548 | uninstall: uninstall-recursive 549 | 550 | install-am: all-am 551 | @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am 552 | 553 | installcheck: installcheck-recursive 554 | install-strip: 555 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ 556 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ 557 | `test -z '$(STRIP)' || \ 558 | echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install 559 | mostlyclean-generic: 560 | 561 | clean-generic: 562 | 563 | distclean-generic: 564 | -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) 565 | -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) 566 | 567 | maintainer-clean-generic: 568 | @echo "This command is intended for maintainers to use" 569 | @echo "it deletes files that may require special tools to rebuild." 570 | clean: clean-recursive 571 | 572 | clean-am: clean-generic mostlyclean-am 573 | 574 | distclean: distclean-recursive 575 | -rm -f $(am__CONFIG_DISTCLEAN_FILES) 576 | -rm -f Makefile 577 | distclean-am: clean-am distclean-generic distclean-tags 578 | 579 | dvi: dvi-recursive 580 | 581 | dvi-am: 582 | 583 | html: html-recursive 584 | 585 | html-am: 586 | 587 | info: info-recursive 588 | 589 | info-am: 590 | 591 | install-data-am: 592 | 593 | install-dvi: install-dvi-recursive 594 | 595 | install-dvi-am: 596 | 597 | install-exec-am: 598 | 599 | install-html: install-html-recursive 600 | 601 | install-html-am: 602 | 603 | install-info: install-info-recursive 604 | 605 | install-info-am: 606 | 607 | install-man: 608 | 609 | install-pdf: install-pdf-recursive 610 | 611 | install-pdf-am: 612 | 613 | install-ps: install-ps-recursive 614 | 615 | install-ps-am: 616 | 617 | installcheck-am: 618 | 619 | maintainer-clean: maintainer-clean-recursive 620 | -rm -f $(am__CONFIG_DISTCLEAN_FILES) 621 | -rm -rf $(top_srcdir)/autom4te.cache 622 | -rm -f Makefile 623 | maintainer-clean-am: distclean-am maintainer-clean-generic 624 | 625 | mostlyclean: mostlyclean-recursive 626 | 627 | mostlyclean-am: mostlyclean-generic 628 | 629 | pdf: pdf-recursive 630 | 631 | pdf-am: 632 | 633 | ps: ps-recursive 634 | 635 | ps-am: 636 | 637 | uninstall-am: 638 | 639 | .MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \ 640 | install-am install-strip tags-recursive 641 | 642 | .PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ 643 | all all-am am--refresh check check-am clean clean-generic \ 644 | ctags ctags-recursive dist dist-all dist-bzip2 dist-gzip \ 645 | dist-lzma dist-shar dist-tarZ dist-xz dist-zip distcheck \ 646 | distclean distclean-generic distclean-tags distcleancheck \ 647 | distdir distuninstallcheck dvi dvi-am html html-am info \ 648 | info-am install install-am install-data install-data-am \ 649 | install-dvi install-dvi-am install-exec install-exec-am \ 650 | install-html install-html-am install-info install-info-am \ 651 | install-man install-pdf install-pdf-am install-ps \ 652 | install-ps-am install-strip installcheck installcheck-am \ 653 | installdirs installdirs-am maintainer-clean \ 654 | maintainer-clean-generic mostlyclean mostlyclean-generic pdf \ 655 | pdf-am ps ps-am tags tags-recursive uninstall uninstall-am 656 | 657 | 658 | # Tell versions [3.59,3.63) of GNU make to not export all variables. 659 | # Otherwise a system limit (for SysV at least) may be exceeded. 660 | .NOEXPORT: 661 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | Oct 21, 2014: public release 2 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | *This package implements a scalable, multi-threaded implementation of the TeraStructure algorithm for fitting a Bayesian model of genetic variation in human populations on tera-sample-sized data sets (10^12 observed genotypes, e.g., 1M individuals at 1M SNPs).* 2 | 3 | Manual 4 | ------ 5 | 6 | See our wiki for instructions and other details: https://github.com/StoreyLab/terastructure/wiki 7 | 8 | Citation 9 | -------- 10 | 11 | **Fitting probabilistic models of genetic variation on millions of humans** 12 | **P. Gopalan, W. Hao, D.M. Blei, J.D. Storey** 13 | link: http://www.nature.com/ng/journal/vaop/ncurrent/full/ng.3710.html 14 | 15 | Abstract 16 | -------- 17 | 18 | The goal of population genetics is to quantitatively understand variation of genetic polymorphisms among individuals. Researchers have developed sophisticated statistical methods to capture the complex population structure that underlies observed genotypes in humans. The number of humans that have been densely genotyped across the genome has grown significantly in recent years. In aggregate about 1M individuals have been densely genotyped to date, and if we could analyze this data then we would have a nearly complete picture of human genetic variation. Existing state-of-the-art methods, however, cannot scale to data of this size. To this end, we have developed TeraStructure. 19 | 20 | TeraStructure is a new algorithm to fit Bayesian models of genetic variation in human populations on tera-sample-sized data sets (10^12 observed genotypes, e.g., 1M individuals at 1M SNPs). It is a principled approach to approximate Bayesian inference that iterates between subsampling locations of the genome and updating an estimate of the latent population structure. On real and simulated data sets of up to 10K individuals, TeraStructure is twice as fast as existing methods and recovers the latent population structure with equal accuracy. On genomic data simulated at the tera-sample-size scales, TeraStructure continues to be accurate and is the only method that can complete its analysis. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | *This package implements a scalable, multi-threaded implementation of the TeraStructure algorithm for fitting a Bayesian model of genetic variation in human populations on tera-sample-sized data sets (10^12 observed genotypes, e.g., 1M individuals at 1M SNPs).* 2 | 3 | Manual 4 | ------ 5 | 6 | See our wiki for instructions and other details: https://github.com/StoreyLab/terastructure/wiki 7 | 8 | Citation 9 | -------- 10 | 11 | **Fitting probabilistic models of genetic variation on millions of humans** 12 | **P. Gopalan, W. Hao, D.M. Blei, J.D. Storey** 13 | link: http://www.nature.com/ng/journal/vaop/ncurrent/full/ng.3710.html 14 | 15 | Abstract 16 | -------- 17 | 18 | The goal of population genetics is to quantitatively understand variation of genetic polymorphisms among individuals. Researchers have developed sophisticated statistical methods to capture the complex population structure that underlies observed genotypes in humans. The number of humans that have been densely genotyped across the genome has grown significantly in recent years. In aggregate about 1M individuals have been densely genotyped to date, and if we could analyze this data then we would have a nearly complete picture of human genetic variation. Existing state-of-the-art methods, however, cannot scale to data of this size. To this end, we have developed TeraStructure. 19 | 20 | TeraStructure is a new algorithm to fit Bayesian models of genetic variation in human populations on tera-sample-sized data sets (10^12 observed genotypes, e.g., 1M individuals at 1M SNPs). It is a principled approach to approximate Bayesian inference that iterates between subsampling locations of the genome and updating an estimate of the latent population structure. On real and simulated data sets of up to 10K individuals, TeraStructure is twice as fast as existing methods and recovers the latent population structure with equal accuracy. On genomic data simulated at the tera-sample-size scales, TeraStructure continues to be accurate and is the only method that can complete its analysis. 21 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.63]) 5 | AC_INIT([terastructure], [1.0], [https://github.com/StoreyLab/terastructure/issues]) 6 | : ${CFLAGS="-O3"} 7 | : ${CXXFLAGS="-O3"} 8 | AM_INIT_AUTOMAKE([terastructure], [0.1]) 9 | AC_CONFIG_SRCDIR([src/env.hh]) 10 | # AC_CONFIG_HEADERS([config.h]) 11 | 12 | # Checks for programs. 13 | AC_PROG_CXX 14 | AC_PROG_CC 15 | 16 | # Checks for libraries. 17 | AC_CHECK_LIB([gslcblas], [cblas_sdot], [], [AC_MSG_ERROR([gslcblas library was not found])]) 18 | AC_CHECK_LIB([pthread], [pthread_self], [], [AC_MSG_ERROR([pthread library was not found])]) 19 | AC_CHECK_LIB([gsl], [gsl_sf_lngamma], [], [AC_MSG_ERROR([gsl library was not found])]) 20 | 21 | # Checks for header files. 22 | AC_CHECK_HEADERS([stdint.h stdlib.h string.h sys/file.h sys/time.h unistd.h]) 23 | 24 | # Checks for typedefs, structures, and compiler characteristics. 25 | AC_HEADER_STDBOOL 26 | AC_C_INLINE 27 | AC_TYPE_UINT16_T 28 | AC_TYPE_UINT32_T 29 | AC_TYPE_UINT64_T 30 | AC_TYPE_UINT8_T 31 | 32 | # Checks for library functions. 33 | AC_FUNC_MALLOC 34 | AC_FUNC_STRTOD 35 | AC_CHECK_FUNCS([gettimeofday localtime_r memset mkdir pow sqrt strerror strtol]) 36 | 37 | AC_CONFIG_FILES([Makefile src/Makefile]) 38 | AC_OUTPUT 39 | 40 | AC_ARG_ENABLE(debug, 41 | AS_HELP_STRING([--enable-debug], 42 | [enable debugging, default: no]), 43 | [case "${enableval}" in 44 | yes) debug=true ;; 45 | no) debug=false ;; 46 | *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;; 47 | esac], 48 | [debug=false]) 49 | 50 | AM_CONDITIONAL(DEBUG, test x"$debug" = x"true") 51 | -------------------------------------------------------------------------------- /data/oracle_theta.txt: -------------------------------------------------------------------------------- 1 | 0.0000962006850322267382863081208733 0.9997860576227513007552261115051806 0.0001177416922165243584564794931957 2 | 0.9922837672434573486057729496678803 0.0060167611340567212635521698871344 0.0016994716224859852081452427086106 3 | 0.0336152525379859040688401705665456 0.0000001406308429349058058860805773 0.9663846068311711112741591023223009 4 | 0.4216216357356734056871516713727033 0.0003124969775427617417994097248624 0.5780658672867838854259048275707755 5 | 0.9189431163832257887236210081027821 0.0810568835632636819354956969618797 0.0000000000535105780404384646684884 6 | 0.9106416514110837745477056159870699 0.0004826020605242989499825134736000 0.0888757465283918773879534569459793 7 | 0.1666400900591909206571727963819285 0.0001380025791570089154208095250098 0.8332219073616521365366338613966946 8 | 0.9680997976300727003717838670127094 0.0295800605297107215008178826565199 0.0023201418402166492510607653798616 9 | 0.0267363544977335179653188390602736 0.9732636454848815343865453542093746 0.0000000000173850026303334479758542 10 | 0.9667570492851437213843723839090671 0.0000000351722944444297236843922016 0.0332429155425619723973618135914876 11 | 0.9197571091229507223019368211680558 0.0802428908770474041967091238802823 0.0000000000000018059273830313307738 12 | 0.9860615306252784595386629007407464 0.0020314096326239402916236098661784 0.0119070597420976274916082360277869 13 | 0.0001515523985218150508635925888257 0.9998484475660004422437054927286226 0.0000000000354777667067974115218089 14 | 0.0000000000375297040743507503067190 0.0006957818555829233279561019109849 0.9993042181068874096894205649732612 15 | 0.3961196530184094566351404864690267 0.1994230613695074094682269105760497 0.4044572856120830506299057560681831 16 | 0.8789469614780054396163677665754221 0.0000000336594893263467506886923032 0.1210530048625051424693310764268972 17 | 0.0000001520149047586085019706064443 0.9999776552864236833784161717630923 0.0000221926986717630429389244706151 18 | 0.0000619537272792777571643260681178 0.7931976656421785287776060613396112 0.2067403806305422309108621448103804 19 | 0.6724157323194303037539043543802109 0.0000000005549950197333639038238166 0.3275842671255747573511030168447178 20 | 0.0129053922340548257730041825652734 0.0000781880841312144098153094629033 0.9870164196818139723532681273354683 21 | 0.1996339110038897746157715573644964 0.8003660889960760860262212190718856 0.0000000000000341300166258444327896 22 | 0.0101178336574529494085172842687825 0.7221528578641787099456905707484111 0.2677293084783682886040878656785935 23 | 0.9985808384671222004413948525325395 0.0000001136166528914713917615791059 0.0014190479162247888501868775534831 24 | 0.0000000000000075620974188460787476 0.3633200759379544564353636815212667 0.6366799240620379940480688674142584 25 | 0.5610132730860231120573189400602132 0.4389867269131202953680315204110229 0.0000000000008566890491352167127496 26 | 0.2956291379410727615528742262540618 0.7043708601786071721306825565989129 0.0000000018803200700792220627920502 27 | 0.0018146980048312502057511474973239 0.9847531862794475232547597443044651 0.0134321157157213204313972454428949 28 | 0.0000000593963938056535754198398162 0.9999998257281064173440654485602863 0.0000001148754998522665900080689258 29 | 0.0000000536903607517847758708954002 0.0000000000000000013721371732134683 0.9999999463096391760785763835883699 30 | 0.0000000540160449518597855923091305 0.9620121788955342534421788514009677 0.0379877670884206791734882813216245 31 | 0.3504092313848359285799460849375464 0.0000917544349497475809863608620098 0.6494990141802143845950467948568985 32 | 0.0690214989564475189798287146913935 0.9259020054800174426290482188051101 0.0050764955635350236459735207006361 33 | 0.0307896454462425438192152427063775 0.9692099168733636638251027761725709 0.0000004376803938595460940660355955 34 | 0.0052040355273469708630162955387277 0.0000774347405476422828186910951587 0.9947185297321053942809498948918190 35 | 0.6371329656519129081004848558222875 0.2943708757582904622651653880893718 0.0684961585897966435121375639027974 36 | 0.6395909576414844366354373050853610 0.3522506748800608988858584780246019 0.0081583674784547286634728280318996 37 | 0.0000013756808752245922601158698365 0.0463505661868632637401255180975568 0.9536480581322615002193288091802970 38 | 0.0018974930279602206066591474353800 0.0000029633538839820300669132980415 0.9980995436181557822763465992466081 39 | 0.0001973493571241082911258551968459 0.8977642678928458019882441476511303 0.1020383827500300627511009565751010 40 | 0.0000000043416013487492520383626835 0.0142937384422954696233665217164344 0.9857062572161031654971452553581912 41 | 0.8932480042271111475571387927629985 0.0176877846274302134854661261442743 0.0890642111454587187546749760258535 42 | 0.0008425475823629011975710034754172 0.0021550661321661115747694292821279 0.9970023862854709983949419438431505 43 | 0.0008939230385132160804084744398779 0.5480472413712215162817642521986272 0.4510588355902653279194680635555414 44 | 0.9999226308883675251593103894265369 0.0000773691111551176325658238375205 0.0000000000004772472636781299063360 45 | 0.0000001861864222678627537360982825 0.9997180503959375297284850603318773 0.0002817634176402375304794356569715 46 | 0.0000001282929159203035789967316293 0.9999998586523314303420306714542676 0.0000000130547525470355929390752506 47 | 0.0083354616392226129478748575252212 0.9914033405708606583317532567889430 0.0002611977899167456881358850839803 48 | 0.0000001485342687534212130020687187 0.0031496637399306458629522076364537 0.9968501877258006960147440622677095 49 | 0.0018257005019904912548889264201080 0.9981742151868104873102538476814516 0.0000000843111989694981982669435617 50 | 0.0113831223888755939110950521353516 0.0135543530827329731375252563907452 0.9750625245283914832583604948013090 51 | 0.0446742905460452005561577948355989 0.9553061761191012912775022414280102 0.0000195333348533804812053628341406 52 | 0.7643095458629619587398451585613657 0.2122762027997353584396478254348040 0.0234142513373026793510600640502162 53 | 0.0000000266834220279300779336211191 0.9904186768062380741284300711413380 0.0095812965103398411298440962013956 54 | 0.0347058505725196739244431398674351 0.9652936626169793532525886803341564 0.0000004868105010713099241767792651 55 | 0.0000000001631524840926590784896343 0.9999999998367954390232625883072615 0.0000000000000520904929519563276899 56 | 0.9999361821720742504737700073746964 0.0000635558173943014386320787822982 0.0000002620105314305332106589120546 57 | 0.9999999999972868369724210424465127 0.0000000000027130882946878662324584 0.0000000000000000001709010140674588 58 | 0.0252108304390496855418302146745191 0.0138962916416716254081054060520728 0.9608928779192786873153409032966010 59 | 0.9815652947725777011100944946520030 0.0176901889794182642923203729878878 0.0007445162480040437048833812383464 60 | 0.0151377697267855697987881669064336 0.9848543537553978710619162484363187 0.0000078765178164962979212278607055 61 | 0.8999774411248411265518143409281038 0.1000208499809322054696636428161582 0.0000017088942268025396583247315849 62 | 0.6899274316901510273325470734562259 0.0862284830392946316512947646515386 0.2238440852705542438716435071910382 63 | 0.9993526460522702548061602101370227 0.0006473538115080021068670212969209 0.0000000001362218243164155726360840 64 | 0.0079263676768115964854644062143052 0.2019042791468202147076027586081182 0.7901693531763681610513572195486631 65 | 0.9996806840031473573304765523062088 0.0000237736929477840880787619520786 0.0002955423039048754780579175704958 66 | 0.9033378058627616891129719078890048 0.0966513104292384961357953443439328 0.0000108837079996571048487365857005 67 | 0.0351550221633298368151265833603247 0.6524820090646691328473139037669171 0.3123629687720010372764534167799866 68 | 0.0258020762608249243363900404801825 0.0000000000000001414580929446320158 0.9741979237391750201524587282619905 69 | 0.9905463896818225144613734300946817 0.0000021335951380090824556774297543 0.0094514767230394602232079748205251 70 | 0.0000000000000000169932413579876486 0.9994788694113113658445968212618027 0.0005211305886885539244424148108692 71 | 0.0000000000000000000046147905452955 0.9998580059800741270947810335201211 0.0001419940199259501275187017599322 72 | 0.0020889126984365027038526019254050 0.6301312679333602728704022410965990 0.3677798193682032534823633795895148 73 | 0.6596764355674157309650240677001420 0.2924711883757570851649632004409796 0.0478523760568272671367395787456189 74 | 0.0033849653593296608403151459754099 0.0000128919714189916797652656760276 0.9966021426692514006973055984417442 75 | 0.1265684314304765523129248094846844 0.3810273544021700042883082915068371 0.4924042141673534711543425146373920 76 | 0.4921616232395621404194230308348779 0.5070141942194399398147197643993422 0.0008241825409978198024169016022711 77 | 0.0000049020889684491077140158880876 0.0125457320776257638672568361926096 0.9874493658334057011316531315969769 78 | 0.0029686667519322629954503511839903 0.9970054758516324611150594137143344 0.0000258573964353991293959288133575 79 | 0.0037840437211621659636950898430996 0.9834101673698780743393399461638182 0.0128057889089597289056232654047562 80 | 0.0000000000000431732728149997655385 0.9947951981381654151803672903042752 0.0052048018617915315850441793088521 81 | 0.0000000000168871057803005474243064 0.8604208285025582991778492214507423 0.1395791714805547090172410662489710 82 | 0.9999239726147808315914744525798596 0.0000578238324081816276343512295277 0.0000182035528110006010807635917770 83 | 0.0000000004937465907643470268249117 0.0000000000000036952111649968391664 0.9999999995062497371023368941678200 84 | 0.0085674682336897914347595417439152 0.0279200205855283691003254631368691 0.9635125111807818498732558509800583 85 | 0.0000000000000000000000000001478055 0.6502885320544541380982650480291341 0.3497114679455458063905837207130389 86 | 0.0373784194587116827546147135308274 0.9578879461216015522850852903502528 0.0047336344196866348560392978583877 87 | 0.0000001967449672766753367976033228 0.0014727062240650120455986993306396 0.9985270970309677585063923288544174 88 | 0.0000239749579932042971273670889376 0.0000005165881689004280188061359221 0.9999755084538379801273322300403379 89 | 0.9278669290311527539927283214638010 0.0582078704946527164532099618554639 0.0139252004741944653692931055388726 90 | 0.1879101802138848642531598898131051 0.0002004136709292092240284471893474 0.8118894061151858965175165394612122 91 | 0.9682351789840023537081492577272002 0.0188719147698616501740431772304873 0.0128929062461360568331292242305608 92 | 0.5343307701228195982778856887307484 0.0000008378580968150743825197958835 0.4656683920190834991004180665186141 93 | 0.0000617007320816597202130585064772 0.9999382208323823739704039326170459 0.0000000784355359332139131704094413 94 | 0.9999712229801261953454627473547589 0.0000287758345663760742403226161601 0.0000000011853073483820751475659892 95 | 0.0001645080105440745968804067134172 0.0000000180226499933635030658243570 0.9998354739668059432133873087877873 96 | 0.1455341263630065828937887317806599 0.0000807412767107649429485297098985 0.8543851323602826841607793539878912 97 | 0.9631788069989356548816772374266293 0.0000008078871863660127035372407814 0.0368203851138780152707496995390102 98 | 0.0002436678501184357805656871542865 0.7114950546050454738278290278685745 0.2882612775448360475927245261118514 99 | 0.9999990921001992161265548020310234 0.0000008868610591886414555199769430 0.0000000210387416563334326296751348 100 | 0.0000001109632894104430778204570815 0.2212656759209777335151159149972955 0.7787342131157328761759117696783505 101 | 0.3829193393659945932050447936489945 0.6162240210893388248081237179576419 0.0008566395446666392327061956279977 102 | 0.0000000000000056288956412840158926 0.0000000001008999016979427501303611 0.9999999998990944938270786224165931 103 | 0.0000000000000000087512758409199707 0.9997983565765080626874805602710694 0.0002016434234919003954354665975046 104 | 0.8858723656964475612340947918710299 0.0574611472662426084334619247329101 0.0566664870373097956379737638599181 105 | 0.2766786192930174026471945580851752 0.7233213803849655176847477378032636 0.0000000003220170286464790334184099 106 | 0.9999758661305738760560757327766623 0.0000241112273915589176635602963739 0.0000000226420345365934690150784363 107 | 0.0000000000000186693604037727296849 0.9999998627955919427989783798693679 0.0000001372043894780451432554311056 108 | 0.9968817842351274105539005176979117 0.0000004117278211175811219091260490 0.0031178040370514509445343254157024 109 | 0.0043243174265235632611203975272929 0.7462069592095931236386263663007412 0.2494687233638832879467628345082630 110 | 0.0003447547655918157595046624752655 0.9996552452344081851620671841374133 0.0000000000000000008283830538596370 111 | 0.0000000006776247324850832678859347 0.0000096522990020755742717221623006 0.9999903470233731939131871513382066 112 | 0.0001421587524273340379359770180301 0.0440802001973539872570206910040724 0.9557776410502186736906082842324395 113 | 0.9959798819860777863155476552492473 0.0040201180137917754894849586833061 0.0000000000001304868869745634072059 114 | 0.0009831754058980061560663044062380 0.0000208613308889930977282119867189 0.9989959632632130492879696248564869 115 | 0.0017464624387705921827740329632661 0.2870078216132842530150526272336720 0.7112457159479451673789185406349134 116 | 0.9992078870755752850740805115492549 0.0000102952811849403427969405419584 0.0007818176432397803141474690313828 117 | 0.1893272684459972599047006269756821 0.4380893881953616397773032531404169 0.3725833433586411280735717355128145 118 | 0.4325943907051726378121259131148690 0.5674055936196177318819877655187156 0.0000000156752094165412733012072088 119 | 0.0042953785645038558560493413551740 0.9957046214352057722507538528589066 0.0000000000002903886787045351184765 120 | 0.6200450221127009609034530512872152 0.3799549778870734417779431169037707 0.0000000000002255302580616635941980 121 | 0.0000000000000023228186606173570125 0.0000168102815819380235643019233516 0.9999831897184158213676141713222023 122 | 0.9746614289766118988111998078238685 0.0000000000017103106078023822917828 0.0253385710216776777192748681954981 123 | 0.0026522701889440045142087853946578 0.0005293125676047044387423357036937 0.9968184172434513268257205709232949 124 | 0.0017961453546258860248380218038733 0.9982038546453237959354964914382435 0.0000000000000503481637634073590292 125 | 0.0000000296551699631630345383249064 0.0000094017764598316150130314500233 0.9999905685683703193689098043250851 126 | 0.9999994579556296114830615806567948 0.0000000651020706261356868740968135 0.0000004769422997332656851234618939 127 | 0.0000000000000000000070973741124717 0.9960948218620692129476879017602187 0.0039051781379308377929737705613888 128 | 0.3340983505392387531429676528205164 0.0000001224368940007249931079078443 0.6659015270238674011338275704474654 129 | 0.0000072530128738788841990929069647 0.9999910840103131137723835308861453 0.0000016629768130686059223193214163 130 | 0.8987151470951448839485919961589389 0.0000000000034603482820576218199367 0.1012848529013947590504685081214120 131 | 0.9985778598557270013813536024827044 0.0000000000114754142319144240328711 0.0014221401327975068378667300450502 132 | 0.9999999951215894355982527486048639 0.0000000000000002193248719701578432 0.0000000048784102690981990867928017 133 | 0.0000000000447664558208629428873191 0.0000000000952154991461894663534694 0.9999999998600181960739519126946107 134 | 0.5401348135388169824366855209518690 0.4598651025825800098267848170507932 0.0000000838786030657112100458952931 135 | 0.9822961081438963404366404574830085 0.0176820355871334378150550037389621 0.0000218562689700751980521366280019 136 | 0.9037152162207825467632460458844434 0.0885607476341959409804616143446765 0.0077240361450215616959114051098823 137 | 0.0002695195455683037691861636542257 0.9997296900450004519811386671790387 0.0000007904094313242185851150372645 138 | 0.9119237618436305536917529934726190 0.0880754614560122633948324732955371 0.0000007767003571863446391234406078 139 | 0.0482474491425261345356467757028440 0.8191951837964811522496688667160925 0.1325573670609927201535782614882919 140 | 0.5640011607960865314126408520678524 0.3361860816306308508139011337334523 0.0998127575732825345067311673119548 141 | 0.9331326437126589157244893613096792 0.0025615114710073778880872197305507 0.0643058448163336821012947552844707 142 | 0.1118091173542040683841491954808589 0.8881417351268178217438276078610215 0.0000491475189781977059516951400475 143 | 0.0000007193826767669980676298056681 0.9998970976443981584225184633396566 0.0001021829729250999733557864201927 144 | 0.7299421876693683586267979990225285 0.2700370800859774322866257989517180 0.0000207322446543217758395047378706 145 | 0.0000000044871948725005484548834863 0.9999999947614788275984665233409032 0.0000000007513262506124970242288749 146 | 0.0009257626238088391152497580449676 0.2899668635692468354747575176588725 0.7091073738069443299636418487352785 147 | 0.4869540578385222473478677329694619 0.5130459418352938394392026566492859 0.0000000003261840511423313111026143 148 | 0.6723776710427036285011581639992073 0.3246975324322127209875077369360952 0.0029247965250837736767008934180012 149 | 0.0003286102086458489294519547119222 0.0452548330505189166927948463126086 0.9544165567408352535139215433446225 150 | 0.0000000527675919937448688749134665 0.9999998469995884375904893204278778 0.0000001002328197159125383354359067 151 | 0.0000000000001662095061887995886875 0.0283459778434738407515425251403940 0.9716540221563598755949442420387641 152 | 0.1517702512136477888127217283908976 0.0000000000678480526555552696537246 0.8482297487185040951729320113372523 153 | 0.0013352320193947108794424449840221 0.9986647679806027744220386921369936 0.0000000000000025772463011646987894 154 | 0.0541778485565713938121312764906179 0.9457865700901321170945834637677763 0.0000355813532963919419943414623742 155 | 0.8720647002087856813901112218445633 0.1279352988567818427689815052872291 0.0000000009344324339608628743298860 156 | 0.3448763554022825084111047999613220 0.6551236445977164368770218061399646 0.0000000000000009927261320791880342 157 | 0.0000000057331174752042389275182344 0.8626909905780801857133610610617325 0.1373090036888022225092242933897069 158 | 0.1844678963665425941442777002521325 0.1125329203451144177705600668559782 0.7029991832883429880851622328918893 159 | 0.0000233208025187908386712930947082 0.9998823027927745688003824398037978 0.0000943764047066834952520730794845 160 | 0.0000000000000066448806277643002506 0.0098759158578949676060565465718355 0.9901240841420984040155417460482568 161 | 0.0019386170157706589852603107360096 0.0000000000726797304234411748856635 0.9980613829115495549970660249528009 162 | 0.9907149677747782989811753395770211 0.0092849991053950212127610086554341 0.0000000331198267331535486286030667 163 | 0.7183683578856925322497772867791355 0.2816316421143074677502227132208645 0.0000000000000000433023060958156384 164 | 0.9993275326412808245990504474320915 0.0000014601992395360298765340408000 0.0006710071594796957741499432437138 165 | 0.0978680740268932924941225337533979 0.8869556526120966344350904364546295 0.0151762733610100713360635538151655 166 | 0.0000177217810996602584069654212628 0.1296743474953657715431631913816091 0.8703079307235346284699062380241230 167 | 0.0000216682590444599208962580400017 0.0000012451932728055337383656726510 0.9999770865476826919859831832582131 168 | 0.9400513811315974743720857986772899 0.0265885973748887227685600009863265 0.0333600214935137612259907768930134 169 | 0.9999997639845107366696197459532414 0.0000002349166469856378699266371678 0.0000000010988421535118812811579428 170 | 0.0000621499691415143041845620119901 0.8594100729001697969167139490309637 0.1405277771306886192004270696997992 171 | 0.0279781721979168104819102325109270 0.0000310026414647784155685997231622 0.9719908251606182991721993857936468 172 | 0.6443410249337341300090997719962616 0.3504769028005371156453406911168713 0.0051820722657286355170014324755812 173 | 0.9999962423008064149598794756457210 0.0000000000000000000463994317788107 0.0000037576991934937100635360802264 174 | 0.0001229120401875979917954290199233 0.9998770879378348075405824602057692 0.0000000000219774919791980468428675 175 | 0.0012078139810084392684330634182288 0.0000000179307092097619589316650850 0.9987921680882823061153885646490380 176 | 0.9999997076012084873397611772816163 0.0000002923237225473582640587809443 0.0000000000750689259145529206735052 177 | 0.2179787498907268805670156552878325 0.0000023086485885984472826476694707 0.7820189414606845135224943987850565 178 | 0.0000037477627481055059004719318821 0.9355729484305205234662139446299989 0.0644233038067313495966814684834389 179 | 0.0080150048929800050967475755214764 0.3776573318101355547504738296993310 0.6143276632968844852555889701761771 180 | 0.0000000000000000000037862395035011 0.0000000000015150625008382419699905 0.9999999999984848786382940488692839 181 | 0.9955435968721525474833811131247785 0.0044564026674407328232341285456641 0.0000000004604067181013743398462179 182 | 0.8577998812615954538074447555118240 0.1400616358925655391409748062869767 0.0021384828458392126163123414528400 183 | 0.0399283415595329330138874013300665 0.4237670191515908735269135831913445 0.5363046392888761726425173037569039 184 | 0.2692636599171326361457090570183937 0.6608521679587154862289821721788030 0.0698841721241519053808843864317168 185 | 0.0052786173286013243072245515463692 0.3750281228007211198338666235940764 0.6196932598706775818797609645116609 186 | 0.0016260311880302203042802933197208 0.9983735965964722902654671088384930 0.0000003722154973503551718343293660 187 | 0.6394471469070116542710024987172801 0.3395511172044143877180033541662851 0.0210017358885738053553282611574105 188 | 0.0006990827383977843900372817209643 0.8325341480609154132253024727106094 0.1667667692006868096488148012213060 189 | 0.0142370194786960255900476468582383 0.0000015945066170018178509335286461 0.9857613860146868800526931408967357 190 | 0.9654539039708143199902679043589160 0.0000000181421240130314739273951824 0.0345460778870616200264542783315846 191 | 0.0006520642464608184928759326837167 0.0000000000000000207134002145088287 0.9993479357535391960354331786220428 192 | 0.0000138221742620714722221166026461 0.7098723093951565532577774320088793 0.2901138684305814563479941625701031 193 | 0.9999990379034211507303098187549040 0.0000000000000026855598431509792874 0.0000009620965762175872392148378784 194 | 0.9983244592639475278872396302176639 0.0002914398685455792613850645178530 0.0013841008675068897613991136807954 195 | 0.0034032111642159461328827063653080 0.0040605369585149124131429054784803 0.9925362518772691267088248423533514 196 | 0.0000352014803705767487023922668321 0.9997352792159577283825910853920504 0.0002295193036717324769693804320525 197 | 0.0000099877056426920217142156888102 0.0000003964226083003377491977394301 0.9999896158717489491607466334244236 198 | 0.0001717959943775128437305071971153 0.9992086218788904794507743645226583 0.0006195821267320634605918483472919 199 | 0.9994170388435462681897547554399353 0.0004923904175240100423299738352512 0.0000905707389297761271016937167921 200 | 0.9992625920991050625374896299035754 0.0007374079008950252828863414222837 0.0000000000000000000000000123797088 201 | -------------------------------------------------------------------------------- /data/output_theta.txt: -------------------------------------------------------------------------------- 1 | 0.03186940 0.11388809 0.85424251 2 | 0.02277310 0.94627341 0.03095349 3 | 0.93198349 0.02871458 0.03930194 4 | 0.56156115 0.36531649 0.07312237 5 | 0.03786410 0.88286252 0.07927338 6 | 0.07890857 0.89395589 0.02713553 7 | 0.75595297 0.18466648 0.05938055 8 | 0.06647220 0.89877223 0.03475557 9 | 0.01734217 0.07051259 0.91214523 10 | 0.09525077 0.87698669 0.02776254 11 | 0.06503768 0.84968330 0.08527902 12 | 0.04280569 0.93482801 0.02236629 13 | 0.04644484 0.03561770 0.91793746 14 | 0.93960202 0.02450530 0.03589267 15 | 0.37803750 0.41983267 0.20212983 16 | 0.15508561 0.77312921 0.07178517 17 | 0.01166930 0.05652164 0.93180906 18 | 0.25358506 0.03263837 0.71377657 19 | 0.34905139 0.62824105 0.02270756 20 | 0.94721343 0.02883901 0.02394756 21 | 0.02815506 0.20511404 0.76673090 22 | 0.25419159 0.03798970 0.70781871 23 | 0.07377150 0.91324845 0.01298005 24 | 0.59358816 0.02238570 0.38402614 25 | 0.05214509 0.52066289 0.42719202 26 | 0.07133185 0.37094969 0.55771847 27 | 0.02350008 0.05456380 0.92193612 28 | 0.05726678 0.06637671 0.87635651 29 | 0.92447584 0.01956599 0.05595818 30 | 0.09725529 0.06274204 0.84000267 31 | 0.57700195 0.40766039 0.01533767 32 | 0.03785200 0.11700526 0.84514274 33 | 0.04431633 0.05913389 0.89654978 34 | 0.94245013 0.01558632 0.04196355 35 | 0.11856085 0.62006119 0.26137796 36 | 0.05888453 0.62068632 0.32042915 37 | 0.89004364 0.06600902 0.04394734 38 | 0.94435589 0.02441552 0.03122860 39 | 0.11505625 0.05493175 0.83001200 40 | 0.91665619 0.03992945 0.04341436 41 | 0.10149288 0.86127090 0.03723622 42 | 0.91986364 0.01929772 0.06083863 43 | 0.39743652 0.04733398 0.55522951 44 | 0.07071977 0.90769907 0.02158116 45 | 0.02937411 0.04069325 0.92993264 46 | 0.02942084 0.03988260 0.93069656 47 | 0.04178075 0.07475200 0.88346724 48 | 0.91117223 0.03228642 0.05654134 49 | 0.02440965 0.03922380 0.93636655 50 | 0.92816352 0.03130592 0.04053056 51 | 0.01598854 0.14827342 0.83573804 52 | 0.08223508 0.71544216 0.20232276 53 | 0.02919075 0.03004685 0.94076240 54 | 0.05161809 0.07675209 0.87162982 55 | 0.04805190 0.04831260 0.90363550 56 | 0.02734041 0.95243819 0.02022141 57 | 0.05068762 0.91755631 0.03175607 58 | 0.90050520 0.02840208 0.07109271 59 | 0.06062439 0.90259879 0.03677682 60 | 0.04502387 0.04412500 0.91085113 61 | 0.04119016 0.85230835 0.10650149 62 | 0.17313155 0.72415925 0.10270921 63 | 0.02731424 0.93524077 0.03744499 64 | 0.73511678 0.06235733 0.20252589 65 | 0.04410667 0.90557160 0.05032173 66 | 0.06296009 0.82925753 0.10778238 67 | 0.31423000 0.08807613 0.59769388 68 | 0.95063587 0.02975700 0.01960712 69 | 0.06077778 0.92980650 0.00941573 70 | 0.03711438 0.05111991 0.91176571 71 | 0.04584376 0.04823661 0.90591963 72 | 0.30236031 0.05620711 0.64143258 73 | 0.05930597 0.70664819 0.23404584 74 | 0.92617205 0.03928678 0.03454117 75 | 0.47231192 0.14899622 0.37869186 76 | 0.05895687 0.48695149 0.45409165 77 | 0.93574544 0.03393371 0.03032085 78 | 0.04781394 0.06075971 0.89142635 79 | 0.05640901 0.07916644 0.86442455 80 | 0.03338635 0.02204770 0.94456595 81 | 0.15271753 0.04019995 0.80708251 82 | 0.04595755 0.94311045 0.01093200 83 | 0.93742471 0.03352419 0.02905110 84 | 0.90511463 0.03115634 0.06372904 85 | 0.32995712 0.06126627 0.60877661 86 | 0.01803716 0.12021252 0.86175032 87 | 0.90153357 0.05697120 0.04149523 88 | 0.94442297 0.01177038 0.04380665 89 | 0.05792792 0.87211414 0.06995793 90 | 0.75938147 0.16557697 0.07504156 91 | 0.08181520 0.90583995 0.01234485 92 | 0.47538114 0.48980131 0.03481754 93 | 0.03927881 0.05908119 0.90163999 94 | 0.02616800 0.93625142 0.03758058 95 | 0.92700593 0.04296862 0.03002545 96 | 0.79150057 0.13784506 0.07065437 97 | 0.05261511 0.89764070 0.04974419 98 | 0.25249083 0.06052737 0.68698180 99 | 0.05866520 0.93315209 0.00818271 100 | 0.75305847 0.03787581 0.20906572 101 | 0.07728047 0.33713302 0.58558651 102 | 0.96172603 0.01170656 0.02656742 103 | 0.04524561 0.04743790 0.90731649 104 | 0.14345623 0.80013426 0.05640951 105 | 0.06876046 0.31143974 0.61979979 106 | 0.05243132 0.93799594 0.00957274 107 | 0.05581521 0.04021683 0.90396796 108 | 0.02488093 0.94013572 0.03498335 109 | 0.22162621 0.06370428 0.71466952 110 | 0.05974831 0.05947021 0.88078148 111 | 0.96840012 0.00708387 0.02451601 112 | 0.88813515 0.04238137 0.06948348 113 | 0.05354393 0.92599590 0.02046017 114 | 0.90949819 0.03686353 0.05363828 115 | 0.66863540 0.04298445 0.28838015 116 | 0.05247436 0.92977231 0.01775333 117 | 0.38973410 0.18092638 0.42933952 118 | 0.03282609 0.43569577 0.53147814 119 | 0.05211383 0.02659073 0.92129544 120 | 0.03629309 0.60244480 0.36126211 121 | 0.93002680 0.02155083 0.04842237 122 | 0.10096063 0.86223230 0.03680708 123 | 0.93627353 0.01723493 0.04649154 124 | 0.04008928 0.08284506 0.87706566 125 | 0.93175138 0.02079874 0.04744988 126 | 0.01901788 0.97322984 0.00775228 127 | 0.02652334 0.05898059 0.91449607 128 | 0.64537136 0.28517296 0.06945568 129 | 0.03131103 0.04668980 0.92199917 130 | 0.10914124 0.86180386 0.02905490 131 | 0.07228801 0.90086604 0.02684595 132 | 0.05377528 0.93520967 0.01101506 133 | 0.95315490 0.02141385 0.02543126 134 | 0.07171547 0.50941156 0.41887298 135 | 0.04126103 0.90767348 0.05106550 136 | 0.10613044 0.84138536 0.05248420 137 | 0.03287816 0.03733498 0.92978686 138 | 0.04851027 0.82804596 0.12344377 139 | 0.14584907 0.10137248 0.75277845 140 | 0.11656003 0.56287112 0.32056885 141 | 0.09233991 0.86304248 0.04461761 142 | 0.06441626 0.13180641 0.80377733 143 | 0.02891644 0.02758364 0.94349992 144 | 0.04487255 0.68042403 0.27470342 145 | 0.07298263 0.04196886 0.88504851 146 | 0.65181302 0.07224110 0.27594588 147 | 0.08548725 0.47987045 0.43464229 148 | 0.05945980 0.61810852 0.32243168 149 | 0.91178939 0.01787827 0.07033235 150 | 0.02636615 0.06000066 0.91363319 151 | 0.94811938 0.02593796 0.02594266 152 | 0.74902849 0.21735286 0.03361865 153 | 0.02470847 0.02983250 0.94545904 154 | 0.02602653 0.08500140 0.88897208 155 | 0.08676168 0.79125783 0.12198049 156 | 0.06702097 0.35243827 0.58054076 157 | 0.14104096 0.05325317 0.80570587 158 | 0.62833927 0.23228010 0.13938062 159 | 0.08160858 0.05159009 0.86680133 160 | 0.94832221 0.02847060 0.02320719 161 | 0.91700980 0.03201920 0.05097100 162 | 0.04259162 0.92546674 0.03194164 163 | 0.06948229 0.68405056 0.24646715 164 | 0.05445267 0.92381681 0.02173053 165 | 0.06795380 0.09613309 0.83591311 166 | 0.83879065 0.03897032 0.12223903 167 | 0.91041549 0.05623568 0.03334883 168 | 0.05850502 0.87179129 0.06970369 169 | 0.03347525 0.95936289 0.00716186 170 | 0.21545122 0.04435420 0.74019458 171 | 0.92138614 0.04596166 0.03265221 172 | 0.06418554 0.61046611 0.32534835 173 | 0.02153382 0.96367425 0.01479193 174 | 0.04987337 0.02862559 0.92150104 175 | 0.93839617 0.01544203 0.04616180 176 | 0.06876893 0.89829999 0.03293108 177 | 0.75643041 0.18364259 0.05992700 178 | 0.04191677 0.03023491 0.92784832 179 | 0.61178880 0.08080548 0.30740572 180 | 0.94012074 0.01456633 0.04531293 181 | 0.02411017 0.94256087 0.03332897 182 | 0.04568843 0.79566385 0.15864772 183 | 0.49297280 0.11134673 0.39568047 184 | 0.12028551 0.28632680 0.59338769 185 | 0.53000301 0.03689584 0.43310115 186 | 0.01669597 0.03358360 0.94972043 187 | 0.08047226 0.59984756 0.31968018 188 | 0.19720126 0.04434452 0.75845422 189 | 0.87347155 0.07796114 0.04856730 190 | 0.08373269 0.89773329 0.01853402 191 | 0.94984429 0.02091774 0.02923797 192 | 0.28688947 0.03894195 0.67416859 193 | 0.06067522 0.91425409 0.02507069 194 | 0.04133148 0.89919042 0.05947809 195 | 0.95714975 0.01005844 0.03279180 196 | 0.03449696 0.06932386 0.89617917 197 | 0.97205925 0.00786128 0.02007947 198 | 0.02667376 0.04348883 0.92983741 199 | 0.03855628 0.93965065 0.02179307 200 | 0.02711184 0.93506739 0.03782076 201 | -------------------------------------------------------------------------------- /data/run.sh: -------------------------------------------------------------------------------- 1 | ../src/terastructure -file test.bed -n 200 -l 10000 -k 3 -stochastic -nthreads 1 -rfreq 1000 -seed 1234 -label test 2 | cd n200-k3-l10000-test-seed1234/ 3 | ../../src/terastructure -file ../test.bed -n 200 -l 10000 -k 3 -stochastic -nthreads 1 -compute-beta 4 | -------------------------------------------------------------------------------- /data/test.bed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StoreyLab/terastructure/6ae8854253822effb010a56a3ef6caf8909f6861/data/test.bed -------------------------------------------------------------------------------- /data/test.fam: -------------------------------------------------------------------------------- 1 | 1 1 4 5 1 0 2 | 2 2 4 5 1 0 3 | 3 3 4 5 1 0 4 | 4 4 4 5 1 0 5 | 5 5 4 5 1 0 6 | 6 6 4 5 1 0 7 | 7 7 4 5 1 0 8 | 8 8 4 5 1 0 9 | 9 9 4 5 1 0 10 | 10 10 4 5 1 0 11 | 11 11 4 5 1 0 12 | 12 12 4 5 1 0 13 | 13 13 4 5 1 0 14 | 14 14 4 5 1 0 15 | 15 15 4 5 1 0 16 | 16 16 4 5 1 0 17 | 17 17 4 5 1 0 18 | 18 18 4 5 1 0 19 | 19 19 4 5 1 0 20 | 20 20 4 5 1 0 21 | 21 21 4 5 1 0 22 | 22 22 4 5 1 0 23 | 23 23 4 5 1 0 24 | 24 24 4 5 1 0 25 | 25 25 4 5 1 0 26 | 26 26 4 5 1 0 27 | 27 27 4 5 1 0 28 | 28 28 4 5 1 0 29 | 29 29 4 5 1 0 30 | 30 30 4 5 1 0 31 | 31 31 4 5 1 0 32 | 32 32 4 5 1 0 33 | 33 33 4 5 1 0 34 | 34 34 4 5 1 0 35 | 35 35 4 5 1 0 36 | 36 36 4 5 1 0 37 | 37 37 4 5 1 0 38 | 38 38 4 5 1 0 39 | 39 39 4 5 1 0 40 | 40 40 4 5 1 0 41 | 41 41 4 5 1 0 42 | 42 42 4 5 1 0 43 | 43 43 4 5 1 0 44 | 44 44 4 5 1 0 45 | 45 45 4 5 1 0 46 | 46 46 4 5 1 0 47 | 47 47 4 5 1 0 48 | 48 48 4 5 1 0 49 | 49 49 4 5 1 0 50 | 50 50 4 5 1 0 51 | 51 51 4 5 1 0 52 | 52 52 4 5 1 0 53 | 53 53 4 5 1 0 54 | 54 54 4 5 1 0 55 | 55 55 4 5 1 0 56 | 56 56 4 5 1 0 57 | 57 57 4 5 1 0 58 | 58 58 4 5 1 0 59 | 59 59 4 5 1 0 60 | 60 60 4 5 1 0 61 | 61 61 4 5 1 0 62 | 62 62 4 5 1 0 63 | 63 63 4 5 1 0 64 | 64 64 4 5 1 0 65 | 65 65 4 5 1 0 66 | 66 66 4 5 1 0 67 | 67 67 4 5 1 0 68 | 68 68 4 5 1 0 69 | 69 69 4 5 1 0 70 | 70 70 4 5 1 0 71 | 71 71 4 5 1 0 72 | 72 72 4 5 1 0 73 | 73 73 4 5 1 0 74 | 74 74 4 5 1 0 75 | 75 75 4 5 1 0 76 | 76 76 4 5 1 0 77 | 77 77 4 5 1 0 78 | 78 78 4 5 1 0 79 | 79 79 4 5 1 0 80 | 80 80 4 5 1 0 81 | 81 81 4 5 1 0 82 | 82 82 4 5 1 0 83 | 83 83 4 5 1 0 84 | 84 84 4 5 1 0 85 | 85 85 4 5 1 0 86 | 86 86 4 5 1 0 87 | 87 87 4 5 1 0 88 | 88 88 4 5 1 0 89 | 89 89 4 5 1 0 90 | 90 90 4 5 1 0 91 | 91 91 4 5 1 0 92 | 92 92 4 5 1 0 93 | 93 93 4 5 1 0 94 | 94 94 4 5 1 0 95 | 95 95 4 5 1 0 96 | 96 96 4 5 1 0 97 | 97 97 4 5 1 0 98 | 98 98 4 5 1 0 99 | 99 99 4 5 1 0 100 | 100 100 4 5 1 0 101 | 101 101 4 5 1 0 102 | 102 102 4 5 1 0 103 | 103 103 4 5 1 0 104 | 104 104 4 5 1 0 105 | 105 105 4 5 1 0 106 | 106 106 4 5 1 0 107 | 107 107 4 5 1 0 108 | 108 108 4 5 1 0 109 | 109 109 4 5 1 0 110 | 110 110 4 5 1 0 111 | 111 111 4 5 1 0 112 | 112 112 4 5 1 0 113 | 113 113 4 5 1 0 114 | 114 114 4 5 1 0 115 | 115 115 4 5 1 0 116 | 116 116 4 5 1 0 117 | 117 117 4 5 1 0 118 | 118 118 4 5 1 0 119 | 119 119 4 5 1 0 120 | 120 120 4 5 1 0 121 | 121 121 4 5 1 0 122 | 122 122 4 5 1 0 123 | 123 123 4 5 1 0 124 | 124 124 4 5 1 0 125 | 125 125 4 5 1 0 126 | 126 126 4 5 1 0 127 | 127 127 4 5 1 0 128 | 128 128 4 5 1 0 129 | 129 129 4 5 1 0 130 | 130 130 4 5 1 0 131 | 131 131 4 5 1 0 132 | 132 132 4 5 1 0 133 | 133 133 4 5 1 0 134 | 134 134 4 5 1 0 135 | 135 135 4 5 1 0 136 | 136 136 4 5 1 0 137 | 137 137 4 5 1 0 138 | 138 138 4 5 1 0 139 | 139 139 4 5 1 0 140 | 140 140 4 5 1 0 141 | 141 141 4 5 1 0 142 | 142 142 4 5 1 0 143 | 143 143 4 5 1 0 144 | 144 144 4 5 1 0 145 | 145 145 4 5 1 0 146 | 146 146 4 5 1 0 147 | 147 147 4 5 1 0 148 | 148 148 4 5 1 0 149 | 149 149 4 5 1 0 150 | 150 150 4 5 1 0 151 | 151 151 4 5 1 0 152 | 152 152 4 5 1 0 153 | 153 153 4 5 1 0 154 | 154 154 4 5 1 0 155 | 155 155 4 5 1 0 156 | 156 156 4 5 1 0 157 | 157 157 4 5 1 0 158 | 158 158 4 5 1 0 159 | 159 159 4 5 1 0 160 | 160 160 4 5 1 0 161 | 161 161 4 5 1 0 162 | 162 162 4 5 1 0 163 | 163 163 4 5 1 0 164 | 164 164 4 5 1 0 165 | 165 165 4 5 1 0 166 | 166 166 4 5 1 0 167 | 167 167 4 5 1 0 168 | 168 168 4 5 1 0 169 | 169 169 4 5 1 0 170 | 170 170 4 5 1 0 171 | 171 171 4 5 1 0 172 | 172 172 4 5 1 0 173 | 173 173 4 5 1 0 174 | 174 174 4 5 1 0 175 | 175 175 4 5 1 0 176 | 176 176 4 5 1 0 177 | 177 177 4 5 1 0 178 | 178 178 4 5 1 0 179 | 179 179 4 5 1 0 180 | 180 180 4 5 1 0 181 | 181 181 4 5 1 0 182 | 182 182 4 5 1 0 183 | 183 183 4 5 1 0 184 | 184 184 4 5 1 0 185 | 185 185 4 5 1 0 186 | 186 186 4 5 1 0 187 | 187 187 4 5 1 0 188 | 188 188 4 5 1 0 189 | 189 189 4 5 1 0 190 | 190 190 4 5 1 0 191 | 191 191 4 5 1 0 192 | 192 192 4 5 1 0 193 | 193 193 4 5 1 0 194 | 194 194 4 5 1 0 195 | 195 195 4 5 1 0 196 | 196 196 4 5 1 0 197 | 197 197 4 5 1 0 198 | 198 198 4 5 1 0 199 | 199 199 4 5 1 0 200 | 200 200 4 5 1 0 201 | -------------------------------------------------------------------------------- /depcomp: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # depcomp - compile a program generating dependencies as side-effects 3 | 4 | scriptversion=2011-12-04.11; # UTC 5 | 6 | # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 7 | # 2011 Free Software Foundation, Inc. 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, or (at your option) 12 | # 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 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | 22 | # As a special exception to the GNU General Public License, if you 23 | # distribute this file as part of a program that contains a 24 | # configuration script generated by Autoconf, you may include it under 25 | # the same distribution terms that you use for the rest of that program. 26 | 27 | # Originally written by Alexandre Oliva . 28 | 29 | case $1 in 30 | '') 31 | echo "$0: No command. Try \`$0 --help' for more information." 1>&2 32 | exit 1; 33 | ;; 34 | -h | --h*) 35 | cat <<\EOF 36 | Usage: depcomp [--help] [--version] PROGRAM [ARGS] 37 | 38 | Run PROGRAMS ARGS to compile a file, generating dependencies 39 | as side-effects. 40 | 41 | Environment variables: 42 | depmode Dependency tracking mode. 43 | source Source file read by `PROGRAMS ARGS'. 44 | object Object file output by `PROGRAMS ARGS'. 45 | DEPDIR directory where to store dependencies. 46 | depfile Dependency file to output. 47 | tmpdepfile Temporary file to use when outputting dependencies. 48 | libtool Whether libtool is used (yes/no). 49 | 50 | Report bugs to . 51 | EOF 52 | exit $? 53 | ;; 54 | -v | --v*) 55 | echo "depcomp $scriptversion" 56 | exit $? 57 | ;; 58 | esac 59 | 60 | if test -z "$depmode" || test -z "$source" || test -z "$object"; then 61 | echo "depcomp: Variables source, object and depmode must be set" 1>&2 62 | exit 1 63 | fi 64 | 65 | # Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. 66 | depfile=${depfile-`echo "$object" | 67 | sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} 68 | tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 69 | 70 | rm -f "$tmpdepfile" 71 | 72 | # Some modes work just like other modes, but use different flags. We 73 | # parameterize here, but still list the modes in the big case below, 74 | # to make depend.m4 easier to write. Note that we *cannot* use a case 75 | # here, because this file can only contain one case statement. 76 | if test "$depmode" = hp; then 77 | # HP compiler uses -M and no extra arg. 78 | gccflag=-M 79 | depmode=gcc 80 | fi 81 | 82 | if test "$depmode" = dashXmstdout; then 83 | # This is just like dashmstdout with a different argument. 84 | dashmflag=-xM 85 | depmode=dashmstdout 86 | fi 87 | 88 | cygpath_u="cygpath -u -f -" 89 | if test "$depmode" = msvcmsys; then 90 | # This is just like msvisualcpp but w/o cygpath translation. 91 | # Just convert the backslash-escaped backslashes to single forward 92 | # slashes to satisfy depend.m4 93 | cygpath_u='sed s,\\\\,/,g' 94 | depmode=msvisualcpp 95 | fi 96 | 97 | if test "$depmode" = msvc7msys; then 98 | # This is just like msvc7 but w/o cygpath translation. 99 | # Just convert the backslash-escaped backslashes to single forward 100 | # slashes to satisfy depend.m4 101 | cygpath_u='sed s,\\\\,/,g' 102 | depmode=msvc7 103 | fi 104 | 105 | case "$depmode" in 106 | gcc3) 107 | ## gcc 3 implements dependency tracking that does exactly what 108 | ## we want. Yay! Note: for some reason libtool 1.4 doesn't like 109 | ## it if -MD -MP comes after the -MF stuff. Hmm. 110 | ## Unfortunately, FreeBSD c89 acceptance of flags depends upon 111 | ## the command line argument order; so add the flags where they 112 | ## appear in depend2.am. Note that the slowdown incurred here 113 | ## affects only configure: in makefiles, %FASTDEP% shortcuts this. 114 | for arg 115 | do 116 | case $arg in 117 | -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; 118 | *) set fnord "$@" "$arg" ;; 119 | esac 120 | shift # fnord 121 | shift # $arg 122 | done 123 | "$@" 124 | stat=$? 125 | if test $stat -eq 0; then : 126 | else 127 | rm -f "$tmpdepfile" 128 | exit $stat 129 | fi 130 | mv "$tmpdepfile" "$depfile" 131 | ;; 132 | 133 | gcc) 134 | ## There are various ways to get dependency output from gcc. Here's 135 | ## why we pick this rather obscure method: 136 | ## - Don't want to use -MD because we'd like the dependencies to end 137 | ## up in a subdir. Having to rename by hand is ugly. 138 | ## (We might end up doing this anyway to support other compilers.) 139 | ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 140 | ## -MM, not -M (despite what the docs say). 141 | ## - Using -M directly means running the compiler twice (even worse 142 | ## than renaming). 143 | if test -z "$gccflag"; then 144 | gccflag=-MD, 145 | fi 146 | "$@" -Wp,"$gccflag$tmpdepfile" 147 | stat=$? 148 | if test $stat -eq 0; then : 149 | else 150 | rm -f "$tmpdepfile" 151 | exit $stat 152 | fi 153 | rm -f "$depfile" 154 | echo "$object : \\" > "$depfile" 155 | alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 156 | ## The second -e expression handles DOS-style file names with drive letters. 157 | sed -e 's/^[^:]*: / /' \ 158 | -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 159 | ## This next piece of magic avoids the `deleted header file' problem. 160 | ## The problem is that when a header file which appears in a .P file 161 | ## is deleted, the dependency causes make to die (because there is 162 | ## typically no way to rebuild the header). We avoid this by adding 163 | ## dummy dependencies for each header file. Too bad gcc doesn't do 164 | ## this for us directly. 165 | tr ' ' ' 166 | ' < "$tmpdepfile" | 167 | ## Some versions of gcc put a space before the `:'. On the theory 168 | ## that the space means something, we add a space to the output as 169 | ## well. hp depmode also adds that space, but also prefixes the VPATH 170 | ## to the object. Take care to not repeat it in the output. 171 | ## Some versions of the HPUX 10.20 sed can't process this invocation 172 | ## correctly. Breaking it into two sed invocations is a workaround. 173 | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ 174 | | sed -e 's/$/ :/' >> "$depfile" 175 | rm -f "$tmpdepfile" 176 | ;; 177 | 178 | hp) 179 | # This case exists only to let depend.m4 do its work. It works by 180 | # looking at the text of this script. This case will never be run, 181 | # since it is checked for above. 182 | exit 1 183 | ;; 184 | 185 | sgi) 186 | if test "$libtool" = yes; then 187 | "$@" "-Wp,-MDupdate,$tmpdepfile" 188 | else 189 | "$@" -MDupdate "$tmpdepfile" 190 | fi 191 | stat=$? 192 | if test $stat -eq 0; then : 193 | else 194 | rm -f "$tmpdepfile" 195 | exit $stat 196 | fi 197 | rm -f "$depfile" 198 | 199 | if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 200 | echo "$object : \\" > "$depfile" 201 | 202 | # Clip off the initial element (the dependent). Don't try to be 203 | # clever and replace this with sed code, as IRIX sed won't handle 204 | # lines with more than a fixed number of characters (4096 in 205 | # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 206 | # the IRIX cc adds comments like `#:fec' to the end of the 207 | # dependency line. 208 | tr ' ' ' 209 | ' < "$tmpdepfile" \ 210 | | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ 211 | tr ' 212 | ' ' ' >> "$depfile" 213 | echo >> "$depfile" 214 | 215 | # The second pass generates a dummy entry for each header file. 216 | tr ' ' ' 217 | ' < "$tmpdepfile" \ 218 | | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 219 | >> "$depfile" 220 | else 221 | # The sourcefile does not contain any dependencies, so just 222 | # store a dummy comment line, to avoid errors with the Makefile 223 | # "include basename.Plo" scheme. 224 | echo "#dummy" > "$depfile" 225 | fi 226 | rm -f "$tmpdepfile" 227 | ;; 228 | 229 | aix) 230 | # The C for AIX Compiler uses -M and outputs the dependencies 231 | # in a .u file. In older versions, this file always lives in the 232 | # current directory. Also, the AIX compiler puts `$object:' at the 233 | # start of each line; $object doesn't have directory information. 234 | # Version 6 uses the directory in both cases. 235 | dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 236 | test "x$dir" = "x$object" && dir= 237 | base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 238 | if test "$libtool" = yes; then 239 | tmpdepfile1=$dir$base.u 240 | tmpdepfile2=$base.u 241 | tmpdepfile3=$dir.libs/$base.u 242 | "$@" -Wc,-M 243 | else 244 | tmpdepfile1=$dir$base.u 245 | tmpdepfile2=$dir$base.u 246 | tmpdepfile3=$dir$base.u 247 | "$@" -M 248 | fi 249 | stat=$? 250 | 251 | if test $stat -eq 0; then : 252 | else 253 | rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 254 | exit $stat 255 | fi 256 | 257 | for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" 258 | do 259 | test -f "$tmpdepfile" && break 260 | done 261 | if test -f "$tmpdepfile"; then 262 | # Each line is of the form `foo.o: dependent.h'. 263 | # Do two passes, one to just change these to 264 | # `$object: dependent.h' and one to simply `dependent.h:'. 265 | sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" 266 | # That's a tab and a space in the []. 267 | sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" 268 | else 269 | # The sourcefile does not contain any dependencies, so just 270 | # store a dummy comment line, to avoid errors with the Makefile 271 | # "include basename.Plo" scheme. 272 | echo "#dummy" > "$depfile" 273 | fi 274 | rm -f "$tmpdepfile" 275 | ;; 276 | 277 | icc) 278 | # Intel's C compiler understands `-MD -MF file'. However on 279 | # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c 280 | # ICC 7.0 will fill foo.d with something like 281 | # foo.o: sub/foo.c 282 | # foo.o: sub/foo.h 283 | # which is wrong. We want: 284 | # sub/foo.o: sub/foo.c 285 | # sub/foo.o: sub/foo.h 286 | # sub/foo.c: 287 | # sub/foo.h: 288 | # ICC 7.1 will output 289 | # foo.o: sub/foo.c sub/foo.h 290 | # and will wrap long lines using \ : 291 | # foo.o: sub/foo.c ... \ 292 | # sub/foo.h ... \ 293 | # ... 294 | 295 | "$@" -MD -MF "$tmpdepfile" 296 | stat=$? 297 | if test $stat -eq 0; then : 298 | else 299 | rm -f "$tmpdepfile" 300 | exit $stat 301 | fi 302 | rm -f "$depfile" 303 | # Each line is of the form `foo.o: dependent.h', 304 | # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. 305 | # Do two passes, one to just change these to 306 | # `$object: dependent.h' and one to simply `dependent.h:'. 307 | sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" 308 | # Some versions of the HPUX 10.20 sed can't process this invocation 309 | # correctly. Breaking it into two sed invocations is a workaround. 310 | sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" | 311 | sed -e 's/$/ :/' >> "$depfile" 312 | rm -f "$tmpdepfile" 313 | ;; 314 | 315 | hp2) 316 | # The "hp" stanza above does not work with aCC (C++) and HP's ia64 317 | # compilers, which have integrated preprocessors. The correct option 318 | # to use with these is +Maked; it writes dependencies to a file named 319 | # 'foo.d', which lands next to the object file, wherever that 320 | # happens to be. 321 | # Much of this is similar to the tru64 case; see comments there. 322 | dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 323 | test "x$dir" = "x$object" && dir= 324 | base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 325 | if test "$libtool" = yes; then 326 | tmpdepfile1=$dir$base.d 327 | tmpdepfile2=$dir.libs/$base.d 328 | "$@" -Wc,+Maked 329 | else 330 | tmpdepfile1=$dir$base.d 331 | tmpdepfile2=$dir$base.d 332 | "$@" +Maked 333 | fi 334 | stat=$? 335 | if test $stat -eq 0; then : 336 | else 337 | rm -f "$tmpdepfile1" "$tmpdepfile2" 338 | exit $stat 339 | fi 340 | 341 | for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" 342 | do 343 | test -f "$tmpdepfile" && break 344 | done 345 | if test -f "$tmpdepfile"; then 346 | sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile" 347 | # Add `dependent.h:' lines. 348 | sed -ne '2,${ 349 | s/^ *// 350 | s/ \\*$// 351 | s/$/:/ 352 | p 353 | }' "$tmpdepfile" >> "$depfile" 354 | else 355 | echo "#dummy" > "$depfile" 356 | fi 357 | rm -f "$tmpdepfile" "$tmpdepfile2" 358 | ;; 359 | 360 | tru64) 361 | # The Tru64 compiler uses -MD to generate dependencies as a side 362 | # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. 363 | # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 364 | # dependencies in `foo.d' instead, so we check for that too. 365 | # Subdirectories are respected. 366 | dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 367 | test "x$dir" = "x$object" && dir= 368 | base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 369 | 370 | if test "$libtool" = yes; then 371 | # With Tru64 cc, shared objects can also be used to make a 372 | # static library. This mechanism is used in libtool 1.4 series to 373 | # handle both shared and static libraries in a single compilation. 374 | # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d. 375 | # 376 | # With libtool 1.5 this exception was removed, and libtool now 377 | # generates 2 separate objects for the 2 libraries. These two 378 | # compilations output dependencies in $dir.libs/$base.o.d and 379 | # in $dir$base.o.d. We have to check for both files, because 380 | # one of the two compilations can be disabled. We should prefer 381 | # $dir$base.o.d over $dir.libs/$base.o.d because the latter is 382 | # automatically cleaned when .libs/ is deleted, while ignoring 383 | # the former would cause a distcleancheck panic. 384 | tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4 385 | tmpdepfile2=$dir$base.o.d # libtool 1.5 386 | tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5 387 | tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504 388 | "$@" -Wc,-MD 389 | else 390 | tmpdepfile1=$dir$base.o.d 391 | tmpdepfile2=$dir$base.d 392 | tmpdepfile3=$dir$base.d 393 | tmpdepfile4=$dir$base.d 394 | "$@" -MD 395 | fi 396 | 397 | stat=$? 398 | if test $stat -eq 0; then : 399 | else 400 | rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" 401 | exit $stat 402 | fi 403 | 404 | for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" 405 | do 406 | test -f "$tmpdepfile" && break 407 | done 408 | if test -f "$tmpdepfile"; then 409 | sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" 410 | # That's a tab and a space in the []. 411 | sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" 412 | else 413 | echo "#dummy" > "$depfile" 414 | fi 415 | rm -f "$tmpdepfile" 416 | ;; 417 | 418 | msvc7) 419 | if test "$libtool" = yes; then 420 | showIncludes=-Wc,-showIncludes 421 | else 422 | showIncludes=-showIncludes 423 | fi 424 | "$@" $showIncludes > "$tmpdepfile" 425 | stat=$? 426 | grep -v '^Note: including file: ' "$tmpdepfile" 427 | if test "$stat" = 0; then : 428 | else 429 | rm -f "$tmpdepfile" 430 | exit $stat 431 | fi 432 | rm -f "$depfile" 433 | echo "$object : \\" > "$depfile" 434 | # The first sed program below extracts the file names and escapes 435 | # backslashes for cygpath. The second sed program outputs the file 436 | # name when reading, but also accumulates all include files in the 437 | # hold buffer in order to output them again at the end. This only 438 | # works with sed implementations that can handle large buffers. 439 | sed < "$tmpdepfile" -n ' 440 | /^Note: including file: *\(.*\)/ { 441 | s//\1/ 442 | s/\\/\\\\/g 443 | p 444 | }' | $cygpath_u | sort -u | sed -n ' 445 | s/ /\\ /g 446 | s/\(.*\)/ \1 \\/p 447 | s/.\(.*\) \\/\1:/ 448 | H 449 | $ { 450 | s/.*/ / 451 | G 452 | p 453 | }' >> "$depfile" 454 | rm -f "$tmpdepfile" 455 | ;; 456 | 457 | msvc7msys) 458 | # This case exists only to let depend.m4 do its work. It works by 459 | # looking at the text of this script. This case will never be run, 460 | # since it is checked for above. 461 | exit 1 462 | ;; 463 | 464 | #nosideeffect) 465 | # This comment above is used by automake to tell side-effect 466 | # dependency tracking mechanisms from slower ones. 467 | 468 | dashmstdout) 469 | # Important note: in order to support this mode, a compiler *must* 470 | # always write the preprocessed file to stdout, regardless of -o. 471 | "$@" || exit $? 472 | 473 | # Remove the call to Libtool. 474 | if test "$libtool" = yes; then 475 | while test "X$1" != 'X--mode=compile'; do 476 | shift 477 | done 478 | shift 479 | fi 480 | 481 | # Remove `-o $object'. 482 | IFS=" " 483 | for arg 484 | do 485 | case $arg in 486 | -o) 487 | shift 488 | ;; 489 | $object) 490 | shift 491 | ;; 492 | *) 493 | set fnord "$@" "$arg" 494 | shift # fnord 495 | shift # $arg 496 | ;; 497 | esac 498 | done 499 | 500 | test -z "$dashmflag" && dashmflag=-M 501 | # Require at least two characters before searching for `:' 502 | # in the target name. This is to cope with DOS-style filenames: 503 | # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise. 504 | "$@" $dashmflag | 505 | sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile" 506 | rm -f "$depfile" 507 | cat < "$tmpdepfile" > "$depfile" 508 | tr ' ' ' 509 | ' < "$tmpdepfile" | \ 510 | ## Some versions of the HPUX 10.20 sed can't process this invocation 511 | ## correctly. Breaking it into two sed invocations is a workaround. 512 | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 513 | rm -f "$tmpdepfile" 514 | ;; 515 | 516 | dashXmstdout) 517 | # This case only exists to satisfy depend.m4. It is never actually 518 | # run, as this mode is specially recognized in the preamble. 519 | exit 1 520 | ;; 521 | 522 | makedepend) 523 | "$@" || exit $? 524 | # Remove any Libtool call 525 | if test "$libtool" = yes; then 526 | while test "X$1" != 'X--mode=compile'; do 527 | shift 528 | done 529 | shift 530 | fi 531 | # X makedepend 532 | shift 533 | cleared=no eat=no 534 | for arg 535 | do 536 | case $cleared in 537 | no) 538 | set ""; shift 539 | cleared=yes ;; 540 | esac 541 | if test $eat = yes; then 542 | eat=no 543 | continue 544 | fi 545 | case "$arg" in 546 | -D*|-I*) 547 | set fnord "$@" "$arg"; shift ;; 548 | # Strip any option that makedepend may not understand. Remove 549 | # the object too, otherwise makedepend will parse it as a source file. 550 | -arch) 551 | eat=yes ;; 552 | -*|$object) 553 | ;; 554 | *) 555 | set fnord "$@" "$arg"; shift ;; 556 | esac 557 | done 558 | obj_suffix=`echo "$object" | sed 's/^.*\././'` 559 | touch "$tmpdepfile" 560 | ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 561 | rm -f "$depfile" 562 | # makedepend may prepend the VPATH from the source file name to the object. 563 | # No need to regex-escape $object, excess matching of '.' is harmless. 564 | sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" 565 | sed '1,2d' "$tmpdepfile" | tr ' ' ' 566 | ' | \ 567 | ## Some versions of the HPUX 10.20 sed can't process this invocation 568 | ## correctly. Breaking it into two sed invocations is a workaround. 569 | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 570 | rm -f "$tmpdepfile" "$tmpdepfile".bak 571 | ;; 572 | 573 | cpp) 574 | # Important note: in order to support this mode, a compiler *must* 575 | # always write the preprocessed file to stdout. 576 | "$@" || exit $? 577 | 578 | # Remove the call to Libtool. 579 | if test "$libtool" = yes; then 580 | while test "X$1" != 'X--mode=compile'; do 581 | shift 582 | done 583 | shift 584 | fi 585 | 586 | # Remove `-o $object'. 587 | IFS=" " 588 | for arg 589 | do 590 | case $arg in 591 | -o) 592 | shift 593 | ;; 594 | $object) 595 | shift 596 | ;; 597 | *) 598 | set fnord "$@" "$arg" 599 | shift # fnord 600 | shift # $arg 601 | ;; 602 | esac 603 | done 604 | 605 | "$@" -E | 606 | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ 607 | -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | 608 | sed '$ s: \\$::' > "$tmpdepfile" 609 | rm -f "$depfile" 610 | echo "$object : \\" > "$depfile" 611 | cat < "$tmpdepfile" >> "$depfile" 612 | sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 613 | rm -f "$tmpdepfile" 614 | ;; 615 | 616 | msvisualcpp) 617 | # Important note: in order to support this mode, a compiler *must* 618 | # always write the preprocessed file to stdout. 619 | "$@" || exit $? 620 | 621 | # Remove the call to Libtool. 622 | if test "$libtool" = yes; then 623 | while test "X$1" != 'X--mode=compile'; do 624 | shift 625 | done 626 | shift 627 | fi 628 | 629 | IFS=" " 630 | for arg 631 | do 632 | case "$arg" in 633 | -o) 634 | shift 635 | ;; 636 | $object) 637 | shift 638 | ;; 639 | "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 640 | set fnord "$@" 641 | shift 642 | shift 643 | ;; 644 | *) 645 | set fnord "$@" "$arg" 646 | shift 647 | shift 648 | ;; 649 | esac 650 | done 651 | "$@" -E 2>/dev/null | 652 | sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" 653 | rm -f "$depfile" 654 | echo "$object : \\" > "$depfile" 655 | sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" 656 | echo " " >> "$depfile" 657 | sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" 658 | rm -f "$tmpdepfile" 659 | ;; 660 | 661 | msvcmsys) 662 | # This case exists only to let depend.m4 do its work. It works by 663 | # looking at the text of this script. This case will never be run, 664 | # since it is checked for above. 665 | exit 1 666 | ;; 667 | 668 | none) 669 | exec "$@" 670 | ;; 671 | 672 | *) 673 | echo "Unknown depmode $depmode" 1>&2 674 | exit 1 675 | ;; 676 | esac 677 | 678 | exit 0 679 | 680 | # Local Variables: 681 | # mode: shell-script 682 | # sh-indentation: 2 683 | # eval: (add-hook 'write-file-hooks 'time-stamp) 684 | # time-stamp-start: "scriptversion=" 685 | # time-stamp-format: "%:y-%02m-%02d.%02H" 686 | # time-stamp-time-zone: "UTC" 687 | # time-stamp-end: "; # UTC" 688 | # End: 689 | -------------------------------------------------------------------------------- /docs/supplementary_materials.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StoreyLab/terastructure/6ae8854253822effb010a56a3ef6caf8909f6861/docs/supplementary_materials.pdf -------------------------------------------------------------------------------- /install-sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # install - install a program, script, or datafile 3 | 4 | scriptversion=2011-01-19.21; # UTC 5 | 6 | # This originates from X11R5 (mit/util/scripts/install.sh), which was 7 | # later released in X11R6 (xc/config/util/install.sh) with the 8 | # following copyright and license. 9 | # 10 | # Copyright (C) 1994 X Consortium 11 | # 12 | # Permission is hereby granted, free of charge, to any person obtaining a copy 13 | # of this software and associated documentation files (the "Software"), to 14 | # deal in the Software without restriction, including without limitation the 15 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | # sell copies of the Software, and to permit persons to whom the Software is 17 | # furnished to do so, subject to the following conditions: 18 | # 19 | # The above copyright notice and this permission notice shall be included in 20 | # all copies or substantial portions of the Software. 21 | # 22 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26 | # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27 | # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | # 29 | # Except as contained in this notice, the name of the X Consortium shall not 30 | # be used in advertising or otherwise to promote the sale, use or other deal- 31 | # ings in this Software without prior written authorization from the X Consor- 32 | # tium. 33 | # 34 | # 35 | # FSF changes to this file are in the public domain. 36 | # 37 | # Calling this script install-sh is preferred over install.sh, to prevent 38 | # `make' implicit rules from creating a file called install from it 39 | # when there is no Makefile. 40 | # 41 | # This script is compatible with the BSD install script, but was written 42 | # from scratch. 43 | 44 | nl=' 45 | ' 46 | IFS=" "" $nl" 47 | 48 | # set DOITPROG to echo to test this script 49 | 50 | # Don't use :- since 4.3BSD and earlier shells don't like it. 51 | doit=${DOITPROG-} 52 | if test -z "$doit"; then 53 | doit_exec=exec 54 | else 55 | doit_exec=$doit 56 | fi 57 | 58 | # Put in absolute file names if you don't have them in your path; 59 | # or use environment vars. 60 | 61 | chgrpprog=${CHGRPPROG-chgrp} 62 | chmodprog=${CHMODPROG-chmod} 63 | chownprog=${CHOWNPROG-chown} 64 | cmpprog=${CMPPROG-cmp} 65 | cpprog=${CPPROG-cp} 66 | mkdirprog=${MKDIRPROG-mkdir} 67 | mvprog=${MVPROG-mv} 68 | rmprog=${RMPROG-rm} 69 | stripprog=${STRIPPROG-strip} 70 | 71 | posix_glob='?' 72 | initialize_posix_glob=' 73 | test "$posix_glob" != "?" || { 74 | if (set -f) 2>/dev/null; then 75 | posix_glob= 76 | else 77 | posix_glob=: 78 | fi 79 | } 80 | ' 81 | 82 | posix_mkdir= 83 | 84 | # Desired mode of installed file. 85 | mode=0755 86 | 87 | chgrpcmd= 88 | chmodcmd=$chmodprog 89 | chowncmd= 90 | mvcmd=$mvprog 91 | rmcmd="$rmprog -f" 92 | stripcmd= 93 | 94 | src= 95 | dst= 96 | dir_arg= 97 | dst_arg= 98 | 99 | copy_on_change=false 100 | no_target_directory= 101 | 102 | usage="\ 103 | Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE 104 | or: $0 [OPTION]... SRCFILES... DIRECTORY 105 | or: $0 [OPTION]... -t DIRECTORY SRCFILES... 106 | or: $0 [OPTION]... -d DIRECTORIES... 107 | 108 | In the 1st form, copy SRCFILE to DSTFILE. 109 | In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 110 | In the 4th, create DIRECTORIES. 111 | 112 | Options: 113 | --help display this help and exit. 114 | --version display version info and exit. 115 | 116 | -c (ignored) 117 | -C install only if different (preserve the last data modification time) 118 | -d create directories instead of installing files. 119 | -g GROUP $chgrpprog installed files to GROUP. 120 | -m MODE $chmodprog installed files to MODE. 121 | -o USER $chownprog installed files to USER. 122 | -s $stripprog installed files. 123 | -t DIRECTORY install into DIRECTORY. 124 | -T report an error if DSTFILE is a directory. 125 | 126 | Environment variables override the default commands: 127 | CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128 | RMPROG STRIPPROG 129 | " 130 | 131 | while test $# -ne 0; do 132 | case $1 in 133 | -c) ;; 134 | 135 | -C) copy_on_change=true;; 136 | 137 | -d) dir_arg=true;; 138 | 139 | -g) chgrpcmd="$chgrpprog $2" 140 | shift;; 141 | 142 | --help) echo "$usage"; exit $?;; 143 | 144 | -m) mode=$2 145 | case $mode in 146 | *' '* | *' '* | *' 147 | '* | *'*'* | *'?'* | *'['*) 148 | echo "$0: invalid mode: $mode" >&2 149 | exit 1;; 150 | esac 151 | shift;; 152 | 153 | -o) chowncmd="$chownprog $2" 154 | shift;; 155 | 156 | -s) stripcmd=$stripprog;; 157 | 158 | -t) dst_arg=$2 159 | # Protect names problematic for `test' and other utilities. 160 | case $dst_arg in 161 | -* | [=\(\)!]) dst_arg=./$dst_arg;; 162 | esac 163 | shift;; 164 | 165 | -T) no_target_directory=true;; 166 | 167 | --version) echo "$0 $scriptversion"; exit $?;; 168 | 169 | --) shift 170 | break;; 171 | 172 | -*) echo "$0: invalid option: $1" >&2 173 | exit 1;; 174 | 175 | *) break;; 176 | esac 177 | shift 178 | done 179 | 180 | if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 181 | # When -d is used, all remaining arguments are directories to create. 182 | # When -t is used, the destination is already specified. 183 | # Otherwise, the last argument is the destination. Remove it from $@. 184 | for arg 185 | do 186 | if test -n "$dst_arg"; then 187 | # $@ is not empty: it contains at least $arg. 188 | set fnord "$@" "$dst_arg" 189 | shift # fnord 190 | fi 191 | shift # arg 192 | dst_arg=$arg 193 | # Protect names problematic for `test' and other utilities. 194 | case $dst_arg in 195 | -* | [=\(\)!]) dst_arg=./$dst_arg;; 196 | esac 197 | done 198 | fi 199 | 200 | if test $# -eq 0; then 201 | if test -z "$dir_arg"; then 202 | echo "$0: no input file specified." >&2 203 | exit 1 204 | fi 205 | # It's OK to call `install-sh -d' without argument. 206 | # This can happen when creating conditional directories. 207 | exit 0 208 | fi 209 | 210 | if test -z "$dir_arg"; then 211 | do_exit='(exit $ret); exit $ret' 212 | trap "ret=129; $do_exit" 1 213 | trap "ret=130; $do_exit" 2 214 | trap "ret=141; $do_exit" 13 215 | trap "ret=143; $do_exit" 15 216 | 217 | # Set umask so as not to create temps with too-generous modes. 218 | # However, 'strip' requires both read and write access to temps. 219 | case $mode in 220 | # Optimize common cases. 221 | *644) cp_umask=133;; 222 | *755) cp_umask=22;; 223 | 224 | *[0-7]) 225 | if test -z "$stripcmd"; then 226 | u_plus_rw= 227 | else 228 | u_plus_rw='% 200' 229 | fi 230 | cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 231 | *) 232 | if test -z "$stripcmd"; then 233 | u_plus_rw= 234 | else 235 | u_plus_rw=,u+rw 236 | fi 237 | cp_umask=$mode$u_plus_rw;; 238 | esac 239 | fi 240 | 241 | for src 242 | do 243 | # Protect names problematic for `test' and other utilities. 244 | case $src in 245 | -* | [=\(\)!]) src=./$src;; 246 | esac 247 | 248 | if test -n "$dir_arg"; then 249 | dst=$src 250 | dstdir=$dst 251 | test -d "$dstdir" 252 | dstdir_status=$? 253 | else 254 | 255 | # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 256 | # might cause directories to be created, which would be especially bad 257 | # if $src (and thus $dsttmp) contains '*'. 258 | if test ! -f "$src" && test ! -d "$src"; then 259 | echo "$0: $src does not exist." >&2 260 | exit 1 261 | fi 262 | 263 | if test -z "$dst_arg"; then 264 | echo "$0: no destination specified." >&2 265 | exit 1 266 | fi 267 | dst=$dst_arg 268 | 269 | # If destination is a directory, append the input filename; won't work 270 | # if double slashes aren't ignored. 271 | if test -d "$dst"; then 272 | if test -n "$no_target_directory"; then 273 | echo "$0: $dst_arg: Is a directory" >&2 274 | exit 1 275 | fi 276 | dstdir=$dst 277 | dst=$dstdir/`basename "$src"` 278 | dstdir_status=0 279 | else 280 | # Prefer dirname, but fall back on a substitute if dirname fails. 281 | dstdir=` 282 | (dirname "$dst") 2>/dev/null || 283 | expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 284 | X"$dst" : 'X\(//\)[^/]' \| \ 285 | X"$dst" : 'X\(//\)$' \| \ 286 | X"$dst" : 'X\(/\)' \| . 2>/dev/null || 287 | echo X"$dst" | 288 | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 289 | s//\1/ 290 | q 291 | } 292 | /^X\(\/\/\)[^/].*/{ 293 | s//\1/ 294 | q 295 | } 296 | /^X\(\/\/\)$/{ 297 | s//\1/ 298 | q 299 | } 300 | /^X\(\/\).*/{ 301 | s//\1/ 302 | q 303 | } 304 | s/.*/./; q' 305 | ` 306 | 307 | test -d "$dstdir" 308 | dstdir_status=$? 309 | fi 310 | fi 311 | 312 | obsolete_mkdir_used=false 313 | 314 | if test $dstdir_status != 0; then 315 | case $posix_mkdir in 316 | '') 317 | # Create intermediate dirs using mode 755 as modified by the umask. 318 | # This is like FreeBSD 'install' as of 1997-10-28. 319 | umask=`umask` 320 | case $stripcmd.$umask in 321 | # Optimize common cases. 322 | *[2367][2367]) mkdir_umask=$umask;; 323 | .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 324 | 325 | *[0-7]) 326 | mkdir_umask=`expr $umask + 22 \ 327 | - $umask % 100 % 40 + $umask % 20 \ 328 | - $umask % 10 % 4 + $umask % 2 329 | `;; 330 | *) mkdir_umask=$umask,go-w;; 331 | esac 332 | 333 | # With -d, create the new directory with the user-specified mode. 334 | # Otherwise, rely on $mkdir_umask. 335 | if test -n "$dir_arg"; then 336 | mkdir_mode=-m$mode 337 | else 338 | mkdir_mode= 339 | fi 340 | 341 | posix_mkdir=false 342 | case $umask in 343 | *[123567][0-7][0-7]) 344 | # POSIX mkdir -p sets u+wx bits regardless of umask, which 345 | # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 346 | ;; 347 | *) 348 | tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 349 | trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 350 | 351 | if (umask $mkdir_umask && 352 | exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 353 | then 354 | if test -z "$dir_arg" || { 355 | # Check for POSIX incompatibilities with -m. 356 | # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 357 | # other-writeable bit of parent directory when it shouldn't. 358 | # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 359 | ls_ld_tmpdir=`ls -ld "$tmpdir"` 360 | case $ls_ld_tmpdir in 361 | d????-?r-*) different_mode=700;; 362 | d????-?--*) different_mode=755;; 363 | *) false;; 364 | esac && 365 | $mkdirprog -m$different_mode -p -- "$tmpdir" && { 366 | ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 367 | test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 368 | } 369 | } 370 | then posix_mkdir=: 371 | fi 372 | rmdir "$tmpdir/d" "$tmpdir" 373 | else 374 | # Remove any dirs left behind by ancient mkdir implementations. 375 | rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 376 | fi 377 | trap '' 0;; 378 | esac;; 379 | esac 380 | 381 | if 382 | $posix_mkdir && ( 383 | umask $mkdir_umask && 384 | $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 385 | ) 386 | then : 387 | else 388 | 389 | # The umask is ridiculous, or mkdir does not conform to POSIX, 390 | # or it failed possibly due to a race condition. Create the 391 | # directory the slow way, step by step, checking for races as we go. 392 | 393 | case $dstdir in 394 | /*) prefix='/';; 395 | [-=\(\)!]*) prefix='./';; 396 | *) prefix='';; 397 | esac 398 | 399 | eval "$initialize_posix_glob" 400 | 401 | oIFS=$IFS 402 | IFS=/ 403 | $posix_glob set -f 404 | set fnord $dstdir 405 | shift 406 | $posix_glob set +f 407 | IFS=$oIFS 408 | 409 | prefixes= 410 | 411 | for d 412 | do 413 | test X"$d" = X && continue 414 | 415 | prefix=$prefix$d 416 | if test -d "$prefix"; then 417 | prefixes= 418 | else 419 | if $posix_mkdir; then 420 | (umask=$mkdir_umask && 421 | $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 422 | # Don't fail if two instances are running concurrently. 423 | test -d "$prefix" || exit 1 424 | else 425 | case $prefix in 426 | *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 427 | *) qprefix=$prefix;; 428 | esac 429 | prefixes="$prefixes '$qprefix'" 430 | fi 431 | fi 432 | prefix=$prefix/ 433 | done 434 | 435 | if test -n "$prefixes"; then 436 | # Don't fail if two instances are running concurrently. 437 | (umask $mkdir_umask && 438 | eval "\$doit_exec \$mkdirprog $prefixes") || 439 | test -d "$dstdir" || exit 1 440 | obsolete_mkdir_used=true 441 | fi 442 | fi 443 | fi 444 | 445 | if test -n "$dir_arg"; then 446 | { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 447 | { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 448 | { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 449 | test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 450 | else 451 | 452 | # Make a couple of temp file names in the proper directory. 453 | dsttmp=$dstdir/_inst.$$_ 454 | rmtmp=$dstdir/_rm.$$_ 455 | 456 | # Trap to clean up those temp files at exit. 457 | trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 458 | 459 | # Copy the file name to the temp name. 460 | (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 461 | 462 | # and set any options; do chmod last to preserve setuid bits. 463 | # 464 | # If any of these fail, we abort the whole thing. If we want to 465 | # ignore errors from any of these, just make sure not to ignore 466 | # errors from the above "$doit $cpprog $src $dsttmp" command. 467 | # 468 | { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 469 | { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 470 | { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 471 | { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 472 | 473 | # If -C, don't bother to copy if it wouldn't change the file. 474 | if $copy_on_change && 475 | old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 476 | new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 477 | 478 | eval "$initialize_posix_glob" && 479 | $posix_glob set -f && 480 | set X $old && old=:$2:$4:$5:$6 && 481 | set X $new && new=:$2:$4:$5:$6 && 482 | $posix_glob set +f && 483 | 484 | test "$old" = "$new" && 485 | $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 486 | then 487 | rm -f "$dsttmp" 488 | else 489 | # Rename the file to the real destination. 490 | $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 491 | 492 | # The rename failed, perhaps because mv can't rename something else 493 | # to itself, or perhaps because mv is so ancient that it does not 494 | # support -f. 495 | { 496 | # Now remove or move aside any old file at destination location. 497 | # We try this two ways since rm can't unlink itself on some 498 | # systems and the destination file might be busy for other 499 | # reasons. In this case, the final cleanup might fail but the new 500 | # file should still install successfully. 501 | { 502 | test ! -f "$dst" || 503 | $doit $rmcmd -f "$dst" 2>/dev/null || 504 | { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 505 | { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 506 | } || 507 | { echo "$0: cannot unlink or rename $dst" >&2 508 | (exit 1); exit 1 509 | } 510 | } && 511 | 512 | # Now rename the file to the real destination. 513 | $doit $mvcmd "$dsttmp" "$dst" 514 | } 515 | fi || exit 1 516 | 517 | trap '' 0 518 | fi 519 | done 520 | 521 | # Local variables: 522 | # eval: (add-hook 'write-file-hooks 'time-stamp) 523 | # time-stamp-start: "scriptversion=" 524 | # time-stamp-format: "%:y-%02m-%02d.%02H" 525 | # time-stamp-time-zone: "UTC" 526 | # time-stamp-end: "; # UTC" 527 | # End: 528 | -------------------------------------------------------------------------------- /missing: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Common stub for a few missing GNU programs while installing. 3 | 4 | scriptversion=2012-01-06.13; # UTC 5 | 6 | # Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 7 | # 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. 8 | # Originally by Fran,cois Pinard , 1996. 9 | 10 | # This program is free software; you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation; either version 2, or (at your option) 13 | # any later version. 14 | 15 | # This program is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU General Public License for more details. 19 | 20 | # You should have received a copy of the GNU General Public License 21 | # along with this program. If not, see . 22 | 23 | # As a special exception to the GNU General Public License, if you 24 | # distribute this file as part of a program that contains a 25 | # configuration script generated by Autoconf, you may include it under 26 | # the same distribution terms that you use for the rest of that program. 27 | 28 | if test $# -eq 0; then 29 | echo 1>&2 "Try \`$0 --help' for more information" 30 | exit 1 31 | fi 32 | 33 | run=: 34 | sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p' 35 | sed_minuso='s/.* -o \([^ ]*\).*/\1/p' 36 | 37 | # In the cases where this matters, `missing' is being run in the 38 | # srcdir already. 39 | if test -f configure.ac; then 40 | configure_ac=configure.ac 41 | else 42 | configure_ac=configure.in 43 | fi 44 | 45 | msg="missing on your system" 46 | 47 | case $1 in 48 | --run) 49 | # Try to run requested program, and just exit if it succeeds. 50 | run= 51 | shift 52 | "$@" && exit 0 53 | # Exit code 63 means version mismatch. This often happens 54 | # when the user try to use an ancient version of a tool on 55 | # a file that requires a minimum version. In this case we 56 | # we should proceed has if the program had been absent, or 57 | # if --run hadn't been passed. 58 | if test $? = 63; then 59 | run=: 60 | msg="probably too old" 61 | fi 62 | ;; 63 | 64 | -h|--h|--he|--hel|--help) 65 | echo "\ 66 | $0 [OPTION]... PROGRAM [ARGUMENT]... 67 | 68 | Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an 69 | error status if there is no known handling for PROGRAM. 70 | 71 | Options: 72 | -h, --help display this help and exit 73 | -v, --version output version information and exit 74 | --run try to run the given command, and emulate it if it fails 75 | 76 | Supported PROGRAM values: 77 | aclocal touch file \`aclocal.m4' 78 | autoconf touch file \`configure' 79 | autoheader touch file \`config.h.in' 80 | autom4te touch the output file, or create a stub one 81 | automake touch all \`Makefile.in' files 82 | bison create \`y.tab.[ch]', if possible, from existing .[ch] 83 | flex create \`lex.yy.c', if possible, from existing .c 84 | help2man touch the output file 85 | lex create \`lex.yy.c', if possible, from existing .c 86 | makeinfo touch the output file 87 | yacc create \`y.tab.[ch]', if possible, from existing .[ch] 88 | 89 | Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and 90 | \`g' are ignored when checking the name. 91 | 92 | Send bug reports to ." 93 | exit $? 94 | ;; 95 | 96 | -v|--v|--ve|--ver|--vers|--versi|--versio|--version) 97 | echo "missing $scriptversion (GNU Automake)" 98 | exit $? 99 | ;; 100 | 101 | -*) 102 | echo 1>&2 "$0: Unknown \`$1' option" 103 | echo 1>&2 "Try \`$0 --help' for more information" 104 | exit 1 105 | ;; 106 | 107 | esac 108 | 109 | # normalize program name to check for. 110 | program=`echo "$1" | sed ' 111 | s/^gnu-//; t 112 | s/^gnu//; t 113 | s/^g//; t'` 114 | 115 | # Now exit if we have it, but it failed. Also exit now if we 116 | # don't have it and --version was passed (most likely to detect 117 | # the program). This is about non-GNU programs, so use $1 not 118 | # $program. 119 | case $1 in 120 | lex*|yacc*) 121 | # Not GNU programs, they don't have --version. 122 | ;; 123 | 124 | *) 125 | if test -z "$run" && ($1 --version) > /dev/null 2>&1; then 126 | # We have it, but it failed. 127 | exit 1 128 | elif test "x$2" = "x--version" || test "x$2" = "x--help"; then 129 | # Could not run --version or --help. This is probably someone 130 | # running `$TOOL --version' or `$TOOL --help' to check whether 131 | # $TOOL exists and not knowing $TOOL uses missing. 132 | exit 1 133 | fi 134 | ;; 135 | esac 136 | 137 | # If it does not exist, or fails to run (possibly an outdated version), 138 | # try to emulate it. 139 | case $program in 140 | aclocal*) 141 | echo 1>&2 "\ 142 | WARNING: \`$1' is $msg. You should only need it if 143 | you modified \`acinclude.m4' or \`${configure_ac}'. You might want 144 | to install the \`Automake' and \`Perl' packages. Grab them from 145 | any GNU archive site." 146 | touch aclocal.m4 147 | ;; 148 | 149 | autoconf*) 150 | echo 1>&2 "\ 151 | WARNING: \`$1' is $msg. You should only need it if 152 | you modified \`${configure_ac}'. You might want to install the 153 | \`Autoconf' and \`GNU m4' packages. Grab them from any GNU 154 | archive site." 155 | touch configure 156 | ;; 157 | 158 | autoheader*) 159 | echo 1>&2 "\ 160 | WARNING: \`$1' is $msg. You should only need it if 161 | you modified \`acconfig.h' or \`${configure_ac}'. You might want 162 | to install the \`Autoconf' and \`GNU m4' packages. Grab them 163 | from any GNU archive site." 164 | files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` 165 | test -z "$files" && files="config.h" 166 | touch_files= 167 | for f in $files; do 168 | case $f in 169 | *:*) touch_files="$touch_files "`echo "$f" | 170 | sed -e 's/^[^:]*://' -e 's/:.*//'`;; 171 | *) touch_files="$touch_files $f.in";; 172 | esac 173 | done 174 | touch $touch_files 175 | ;; 176 | 177 | automake*) 178 | echo 1>&2 "\ 179 | WARNING: \`$1' is $msg. You should only need it if 180 | you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. 181 | You might want to install the \`Automake' and \`Perl' packages. 182 | Grab them from any GNU archive site." 183 | find . -type f -name Makefile.am -print | 184 | sed 's/\.am$/.in/' | 185 | while read f; do touch "$f"; done 186 | ;; 187 | 188 | autom4te*) 189 | echo 1>&2 "\ 190 | WARNING: \`$1' is needed, but is $msg. 191 | You might have modified some files without having the 192 | proper tools for further handling them. 193 | You can get \`$1' as part of \`Autoconf' from any GNU 194 | archive site." 195 | 196 | file=`echo "$*" | sed -n "$sed_output"` 197 | test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` 198 | if test -f "$file"; then 199 | touch $file 200 | else 201 | test -z "$file" || exec >$file 202 | echo "#! /bin/sh" 203 | echo "# Created by GNU Automake missing as a replacement of" 204 | echo "# $ $@" 205 | echo "exit 0" 206 | chmod +x $file 207 | exit 1 208 | fi 209 | ;; 210 | 211 | bison*|yacc*) 212 | echo 1>&2 "\ 213 | WARNING: \`$1' $msg. You should only need it if 214 | you modified a \`.y' file. You may need the \`Bison' package 215 | in order for those modifications to take effect. You can get 216 | \`Bison' from any GNU archive site." 217 | rm -f y.tab.c y.tab.h 218 | if test $# -ne 1; then 219 | eval LASTARG=\${$#} 220 | case $LASTARG in 221 | *.y) 222 | SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` 223 | if test -f "$SRCFILE"; then 224 | cp "$SRCFILE" y.tab.c 225 | fi 226 | SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` 227 | if test -f "$SRCFILE"; then 228 | cp "$SRCFILE" y.tab.h 229 | fi 230 | ;; 231 | esac 232 | fi 233 | if test ! -f y.tab.h; then 234 | echo >y.tab.h 235 | fi 236 | if test ! -f y.tab.c; then 237 | echo 'main() { return 0; }' >y.tab.c 238 | fi 239 | ;; 240 | 241 | lex*|flex*) 242 | echo 1>&2 "\ 243 | WARNING: \`$1' is $msg. You should only need it if 244 | you modified a \`.l' file. You may need the \`Flex' package 245 | in order for those modifications to take effect. You can get 246 | \`Flex' from any GNU archive site." 247 | rm -f lex.yy.c 248 | if test $# -ne 1; then 249 | eval LASTARG=\${$#} 250 | case $LASTARG in 251 | *.l) 252 | SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` 253 | if test -f "$SRCFILE"; then 254 | cp "$SRCFILE" lex.yy.c 255 | fi 256 | ;; 257 | esac 258 | fi 259 | if test ! -f lex.yy.c; then 260 | echo 'main() { return 0; }' >lex.yy.c 261 | fi 262 | ;; 263 | 264 | help2man*) 265 | echo 1>&2 "\ 266 | WARNING: \`$1' is $msg. You should only need it if 267 | you modified a dependency of a manual page. You may need the 268 | \`Help2man' package in order for those modifications to take 269 | effect. You can get \`Help2man' from any GNU archive site." 270 | 271 | file=`echo "$*" | sed -n "$sed_output"` 272 | test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` 273 | if test -f "$file"; then 274 | touch $file 275 | else 276 | test -z "$file" || exec >$file 277 | echo ".ab help2man is required to generate this page" 278 | exit $? 279 | fi 280 | ;; 281 | 282 | makeinfo*) 283 | echo 1>&2 "\ 284 | WARNING: \`$1' is $msg. You should only need it if 285 | you modified a \`.texi' or \`.texinfo' file, or any other file 286 | indirectly affecting the aspect of the manual. The spurious 287 | call might also be the consequence of using a buggy \`make' (AIX, 288 | DU, IRIX). You might want to install the \`Texinfo' package or 289 | the \`GNU make' package. Grab either from any GNU archive site." 290 | # The file to touch is that specified with -o ... 291 | file=`echo "$*" | sed -n "$sed_output"` 292 | test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` 293 | if test -z "$file"; then 294 | # ... or it is the one specified with @setfilename ... 295 | infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` 296 | file=`sed -n ' 297 | /^@setfilename/{ 298 | s/.* \([^ ]*\) *$/\1/ 299 | p 300 | q 301 | }' $infile` 302 | # ... or it is derived from the source name (dir/f.texi becomes f.info) 303 | test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info 304 | fi 305 | # If the file does not exist, the user really needs makeinfo; 306 | # let's fail without touching anything. 307 | test -f $file || exit 1 308 | touch $file 309 | ;; 310 | 311 | *) 312 | echo 1>&2 "\ 313 | WARNING: \`$1' is needed, and is $msg. 314 | You might have modified some files without having the 315 | proper tools for further handling them. Check the \`README' file, 316 | it often tells you about the needed prerequisites for installing 317 | this package. You may also peek at any GNU archive site, in case 318 | some other package would contain this missing \`$1' program." 319 | exit 1 320 | ;; 321 | esac 322 | 323 | exit 0 324 | 325 | # Local variables: 326 | # eval: (add-hook 'write-file-hooks 'time-stamp) 327 | # time-stamp-start: "scriptversion=" 328 | # time-stamp-format: "%:y-%02m-%02d.%02H" 329 | # time-stamp-time-zone: "UTC" 330 | # time-stamp-end: "; # UTC" 331 | # End: 332 | -------------------------------------------------------------------------------- /scripts/data/HGDP.txt: -------------------------------------------------------------------------------- 1 | download from: http://www.hagsc.org/hgdp/files.html 2 | 3 | get sample info from rosenberg 2006: http://rosenberglab.stanford.edu/data/rosenberg2006ahg/SampleInformation.txt 4 | 5 | then, manually delete the last line of SampleInformation.txt, which are the column sums 6 | 7 | run the python script HGDP_text_to_tped.py 8 | 9 | then, run plink on the resulting .tped file to make a .bed file. maf filtering is done at this stage. example command: 10 | 11 | ~/Downloads/plink-1.07-x86_64/plink --tfile HGDP_940 --make-bed --out HGDP_940 --noweb 12 | 13 | run the code, e.g.: 14 | 15 | terastructure -file HGDP_940.bed -n 940 -l 642951 -E -nthreads 30 -k 3 -label E01 -seed 1 16 | -------------------------------------------------------------------------------- /scripts/data/HGDP_text_to_tped.py: -------------------------------------------------------------------------------- 1 | # bottom line of the file SampleInformation.txt has been removed 2 | f = open("SampleInformation.txt", "r") 3 | 4 | SampleInformationHeader = f.readline().strip().split() 5 | INDEX1 = SampleInformationHeader.index("IncludedInDataset952[No1stOr2ndDegreeRelatives]?") 6 | INDEX2 = SampleInformationHeader.index("PopulationName") 7 | indiv = {} 8 | 9 | #pull out the list that's in the H952 set 10 | for a in f: 11 | b = a.strip().split() 12 | if b[INDEX1] == '1': 13 | #a stupid trick 14 | tmp = '000000000000'+b[0] 15 | tmp = tmp[-5:] 16 | indiv['HGDP'+tmp] = b[INDEX2] 17 | 18 | 19 | #in H952 but not in website data; manually figured this out... 20 | del indiv['HGDP00987'] 21 | del indiv['HGDP00453'] 22 | del indiv['HGDP00452'] 23 | del indiv['HGDP01219'] 24 | del indiv['HGDP00247'] 25 | del indiv['HGDP00248'] 26 | del indiv['HGDP01149'] 27 | del indiv['HGDP00660'] 28 | del indiv['HGDP01344'] 29 | del indiv['HGDP01233'] 30 | del indiv['HGDP00754'] 31 | del indiv['HGDP00944'] 32 | 33 | 34 | g = open("HGDP_FinalReport_Forward.txt","r") 35 | h = open("HGDP_940.tped", "w") 36 | j = open("HGDP_Map.txt", "r") 37 | 38 | hgdpindiv = g.readline() #compute indices to keep 39 | hgdpindiv = hgdpindiv.strip() 40 | hgdpindiv = hgdpindiv.split() 41 | 42 | valid = [hgdpindiv.index(a) for a in indiv.keys()] 43 | 44 | counter = 0 45 | for a in g: 46 | snpinfo = j.readline().split() 47 | if snpinfo[1] not in map(str, range(1, 22+1)): 48 | continue 49 | a = a.strip() 50 | a = a.split() 51 | a = a[1:] 52 | geno = [a[b] for b in valid] 53 | outtped = [snpinfo[1], snpinfo[0], "1", snpinfo[2]] 54 | missing_count = 0.0 55 | allele1_count = 0.0 56 | total_allele = 0.0 57 | homozygous1 = '' 58 | for b in xrange(0,len(geno)): 59 | if geno[b] == '--': 60 | outtped.append("0 0") 61 | missing_count = missing_count + 1 62 | else: 63 | outtped.append(geno[b][0] + ' ' + geno[b][1]) 64 | if geno[b][1] != geno[b][0]: #heterozygous 65 | allele1_count = allele1_count + 1.0 66 | elif homozygous1 == '': #geno[b][0] == geno[b][1] is True 67 | homozygous1 = geno[b] 68 | allele1_count = allele1_count + 2.0 69 | elif homozygous1 == geno[b]: 70 | allele1_count = allele1_count + 2.0 71 | total_allele = total_allele + 2.0 72 | if missing_count <= 47: # 5% missing per SNP max! 73 | if allele1_count/total_allele >= 0.01 or allele1_count/total_allele <= 0.99: # 1% ma 74 | h.write(" ".join(outtped)+"\n") 75 | else: 76 | print("MAF FAILl; THIS SHOULDN'T HAPPEN FOR HGDP") 77 | # if counter%1000 ==0: 78 | # print(str(allele1_count/total_allele) + " " + str(total_allele) + " "+ " ".join(outtped)) 79 | if counter % 50000 == 0: 80 | print(counter) 81 | counter = counter+1 82 | 83 | #tfam 84 | k = open("HGDP_940.tfam", "w") 85 | 86 | for a in valid: 87 | outtfam = [str(a), hgdpindiv[a], '0', '0', '1', '0'] 88 | k.write(" ".join(outtfam) + "\n") 89 | 90 | k.close() 91 | f.close() 92 | g.close() 93 | h.close() 94 | j.close() 95 | -------------------------------------------------------------------------------- /scripts/data/TGP.txt: -------------------------------------------------------------------------------- 1 | raw data: ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/working/20120131_omni_genotypes_and_intensities/Omni25_genotypes_2141_samples.b37.vcf.gz 2 | 3 | text file TGP_unrel.txt contains individuals that were manually determined to be unrelated 4 | 5 | use vcftools (we used version 0.1.12b) to do all filtering. options we used: 6 | 7 | vcftools_0.1.12b/bin/vcftools --gzvcf Omni25_genotypes_2141_samples.b37.vcf.gz --keep TGP_unrel.txt --maf 0.01 --max-missing 0.95 --max-alleles 2 --min-alleles 2 --chr 1 --chr 2 --chr 3 --chr 4 --chr 5 --chr 6 --chr 7 --chr 8 --chr 9 --chr 10 --chr 11 --chr 12 --chr 13 --chr 14 --chr 15 --chr 16 --chr 17 --chr 18 --chr 19 --chr 20 --chr 21 --chr 22 --plink-tped --out TGP_plink 8 | 9 | now use plink to make a bed: 10 | 11 | ~/Downloads/plink-1.07-x86_64/plink --tfile TGP_plink --make-bed --out TGP_1718 --noweb 12 | 13 | run the code, e.g.: 14 | 15 | terastructure -file TGP_1718.bed -n 1718 -l 1854622 -E -nthreads 36 -k 10 -label E01 -seed 1 16 | 17 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = terastructure 2 | terastructure_SOURCES = env.hh snp.hh snp.cc matrix.hh main.cc log.cc log.hh lib.hh thread.hh thread.cc tsqueue.hh snpsamplinge.cc snpsamplinge.hh 3 | #if DEBUG 4 | #AM_CFLAGS = -g -O0 5 | #AM_CXXFLAGS = -g -O0 6 | #endif 7 | -------------------------------------------------------------------------------- /src/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile.in generated by automake 1.11.1 from Makefile.am. 2 | # @configure_input@ 3 | 4 | # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 5 | # 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, 6 | # Inc. 7 | # This Makefile.in is free software; the Free Software Foundation 8 | # gives unlimited permission to copy and/or distribute it, 9 | # with or without modifications, as long as this notice is preserved. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without 13 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A 14 | # PARTICULAR PURPOSE. 15 | 16 | @SET_MAKE@ 17 | 18 | VPATH = @srcdir@ 19 | pkgdatadir = $(datadir)/@PACKAGE@ 20 | pkgincludedir = $(includedir)/@PACKAGE@ 21 | pkglibdir = $(libdir)/@PACKAGE@ 22 | pkglibexecdir = $(libexecdir)/@PACKAGE@ 23 | am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd 24 | install_sh_DATA = $(install_sh) -c -m 644 25 | install_sh_PROGRAM = $(install_sh) -c 26 | install_sh_SCRIPT = $(install_sh) -c 27 | INSTALL_HEADER = $(INSTALL_DATA) 28 | transform = $(program_transform_name) 29 | NORMAL_INSTALL = : 30 | PRE_INSTALL = : 31 | POST_INSTALL = : 32 | NORMAL_UNINSTALL = : 33 | PRE_UNINSTALL = : 34 | POST_UNINSTALL = : 35 | bin_PROGRAMS = terastructure$(EXEEXT) 36 | subdir = src 37 | DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in 38 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 39 | am__aclocal_m4_deps = $(top_srcdir)/configure.ac 40 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ 41 | $(ACLOCAL_M4) 42 | mkinstalldirs = $(install_sh) -d 43 | CONFIG_CLEAN_FILES = 44 | CONFIG_CLEAN_VPATH_FILES = 45 | am__installdirs = "$(DESTDIR)$(bindir)" 46 | PROGRAMS = $(bin_PROGRAMS) 47 | am_terastructure_OBJECTS = snp.$(OBJEXT) main.$(OBJEXT) log.$(OBJEXT) \ 48 | thread.$(OBJEXT) snpsamplinge.$(OBJEXT) 49 | terastructure_OBJECTS = $(am_terastructure_OBJECTS) 50 | terastructure_LDADD = $(LDADD) 51 | DEFAULT_INCLUDES = -I.@am__isrc@ 52 | depcomp = $(SHELL) $(top_srcdir)/depcomp 53 | am__depfiles_maybe = depfiles 54 | am__mv = mv -f 55 | CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 56 | $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) 57 | CXXLD = $(CXX) 58 | CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ 59 | -o $@ 60 | COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ 61 | $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) 62 | CCLD = $(CC) 63 | LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ 64 | SOURCES = $(terastructure_SOURCES) 65 | DIST_SOURCES = $(terastructure_SOURCES) 66 | ETAGS = etags 67 | CTAGS = ctags 68 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) 69 | ACLOCAL = @ACLOCAL@ 70 | AMTAR = @AMTAR@ 71 | AUTOCONF = @AUTOCONF@ 72 | AUTOHEADER = @AUTOHEADER@ 73 | AUTOMAKE = @AUTOMAKE@ 74 | AWK = @AWK@ 75 | CC = @CC@ 76 | CCDEPMODE = @CCDEPMODE@ 77 | CFLAGS = @CFLAGS@ 78 | CPP = @CPP@ 79 | CPPFLAGS = @CPPFLAGS@ 80 | CXX = @CXX@ 81 | CXXDEPMODE = @CXXDEPMODE@ 82 | CXXFLAGS = @CXXFLAGS@ 83 | CYGPATH_W = @CYGPATH_W@ 84 | DEFS = @DEFS@ 85 | DEPDIR = @DEPDIR@ 86 | ECHO_C = @ECHO_C@ 87 | ECHO_N = @ECHO_N@ 88 | ECHO_T = @ECHO_T@ 89 | EGREP = @EGREP@ 90 | EXEEXT = @EXEEXT@ 91 | GREP = @GREP@ 92 | INSTALL = @INSTALL@ 93 | INSTALL_DATA = @INSTALL_DATA@ 94 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 95 | INSTALL_SCRIPT = @INSTALL_SCRIPT@ 96 | INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ 97 | LDFLAGS = @LDFLAGS@ 98 | LIBOBJS = @LIBOBJS@ 99 | LIBS = @LIBS@ 100 | LTLIBOBJS = @LTLIBOBJS@ 101 | MAKEINFO = @MAKEINFO@ 102 | MKDIR_P = @MKDIR_P@ 103 | OBJEXT = @OBJEXT@ 104 | PACKAGE = @PACKAGE@ 105 | PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ 106 | PACKAGE_NAME = @PACKAGE_NAME@ 107 | PACKAGE_STRING = @PACKAGE_STRING@ 108 | PACKAGE_TARNAME = @PACKAGE_TARNAME@ 109 | PACKAGE_VERSION = @PACKAGE_VERSION@ 110 | PATH_SEPARATOR = @PATH_SEPARATOR@ 111 | POW_LIB = @POW_LIB@ 112 | SET_MAKE = @SET_MAKE@ 113 | SHELL = @SHELL@ 114 | STRIP = @STRIP@ 115 | VERSION = @VERSION@ 116 | abs_builddir = @abs_builddir@ 117 | abs_srcdir = @abs_srcdir@ 118 | abs_top_builddir = @abs_top_builddir@ 119 | abs_top_srcdir = @abs_top_srcdir@ 120 | ac_ct_CC = @ac_ct_CC@ 121 | ac_ct_CXX = @ac_ct_CXX@ 122 | am__include = @am__include@ 123 | am__leading_dot = @am__leading_dot@ 124 | am__quote = @am__quote@ 125 | am__tar = @am__tar@ 126 | am__untar = @am__untar@ 127 | bindir = @bindir@ 128 | build_alias = @build_alias@ 129 | builddir = @builddir@ 130 | datadir = @datadir@ 131 | datarootdir = @datarootdir@ 132 | docdir = @docdir@ 133 | dvidir = @dvidir@ 134 | exec_prefix = @exec_prefix@ 135 | host_alias = @host_alias@ 136 | htmldir = @htmldir@ 137 | includedir = @includedir@ 138 | infodir = @infodir@ 139 | install_sh = @install_sh@ 140 | libdir = @libdir@ 141 | libexecdir = @libexecdir@ 142 | localedir = @localedir@ 143 | localstatedir = @localstatedir@ 144 | mandir = @mandir@ 145 | mkdir_p = @mkdir_p@ 146 | oldincludedir = @oldincludedir@ 147 | pdfdir = @pdfdir@ 148 | prefix = @prefix@ 149 | program_transform_name = @program_transform_name@ 150 | psdir = @psdir@ 151 | sbindir = @sbindir@ 152 | sharedstatedir = @sharedstatedir@ 153 | srcdir = @srcdir@ 154 | sysconfdir = @sysconfdir@ 155 | target_alias = @target_alias@ 156 | top_build_prefix = @top_build_prefix@ 157 | top_builddir = @top_builddir@ 158 | top_srcdir = @top_srcdir@ 159 | terastructure_SOURCES = env.hh snp.hh snp.cc matrix.hh main.cc log.cc log.hh lib.hh thread.hh thread.cc tsqueue.hh snpsamplinge.cc snpsamplinge.hh 160 | all: all-am 161 | 162 | .SUFFIXES: 163 | .SUFFIXES: .cc .o .obj 164 | $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) 165 | @for dep in $?; do \ 166 | case '$(am__configure_deps)' in \ 167 | *$$dep*) \ 168 | ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ 169 | && { if test -f $@; then exit 0; else break; fi; }; \ 170 | exit 1;; \ 171 | esac; \ 172 | done; \ 173 | echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ 174 | $(am__cd) $(top_srcdir) && \ 175 | $(AUTOMAKE) --gnu src/Makefile 176 | .PRECIOUS: Makefile 177 | Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status 178 | @case '$?' in \ 179 | *config.status*) \ 180 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ 181 | *) \ 182 | echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ 183 | cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ 184 | esac; 185 | 186 | $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) 187 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 188 | 189 | $(top_srcdir)/configure: $(am__configure_deps) 190 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 191 | $(ACLOCAL_M4): $(am__aclocal_m4_deps) 192 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 193 | $(am__aclocal_m4_deps): 194 | install-binPROGRAMS: $(bin_PROGRAMS) 195 | @$(NORMAL_INSTALL) 196 | test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" 197 | @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ 198 | for p in $$list; do echo "$$p $$p"; done | \ 199 | sed 's/$(EXEEXT)$$//' | \ 200 | while read p p1; do if test -f $$p; \ 201 | then echo "$$p"; echo "$$p"; else :; fi; \ 202 | done | \ 203 | sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ 204 | -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ 205 | sed 'N;N;N;s,\n, ,g' | \ 206 | $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ 207 | { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ 208 | if ($$2 == $$4) files[d] = files[d] " " $$1; \ 209 | else { print "f", $$3 "/" $$4, $$1; } } \ 210 | END { for (d in files) print "f", d, files[d] }' | \ 211 | while read type dir files; do \ 212 | if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ 213 | test -z "$$files" || { \ 214 | echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ 215 | $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ 216 | } \ 217 | ; done 218 | 219 | uninstall-binPROGRAMS: 220 | @$(NORMAL_UNINSTALL) 221 | @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ 222 | files=`for p in $$list; do echo "$$p"; done | \ 223 | sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ 224 | -e 's/$$/$(EXEEXT)/' `; \ 225 | test -n "$$list" || exit 0; \ 226 | echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ 227 | cd "$(DESTDIR)$(bindir)" && rm -f $$files 228 | 229 | clean-binPROGRAMS: 230 | -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) 231 | terastructure$(EXEEXT): $(terastructure_OBJECTS) $(terastructure_DEPENDENCIES) 232 | @rm -f terastructure$(EXEEXT) 233 | $(CXXLINK) $(terastructure_OBJECTS) $(terastructure_LDADD) $(LIBS) 234 | 235 | mostlyclean-compile: 236 | -rm -f *.$(OBJEXT) 237 | 238 | distclean-compile: 239 | -rm -f *.tab.c 240 | 241 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@ 242 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ 243 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snp.Po@am__quote@ 244 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snpsamplinge.Po@am__quote@ 245 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/thread.Po@am__quote@ 246 | 247 | .cc.o: 248 | @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< 249 | @am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po 250 | @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ 251 | @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 252 | @am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< 253 | 254 | .cc.obj: 255 | @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` 256 | @am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po 257 | @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ 258 | @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 259 | @am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` 260 | 261 | ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) 262 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 263 | unique=`for i in $$list; do \ 264 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 265 | done | \ 266 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ 267 | END { if (nonempty) { for (i in files) print i; }; }'`; \ 268 | mkid -fID $$unique 269 | tags: TAGS 270 | 271 | TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ 272 | $(TAGS_FILES) $(LISP) 273 | set x; \ 274 | here=`pwd`; \ 275 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 276 | unique=`for i in $$list; do \ 277 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 278 | done | \ 279 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ 280 | END { if (nonempty) { for (i in files) print i; }; }'`; \ 281 | shift; \ 282 | if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ 283 | test -n "$$unique" || unique=$$empty_fix; \ 284 | if test $$# -gt 0; then \ 285 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ 286 | "$$@" $$unique; \ 287 | else \ 288 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ 289 | $$unique; \ 290 | fi; \ 291 | fi 292 | ctags: CTAGS 293 | CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ 294 | $(TAGS_FILES) $(LISP) 295 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 296 | unique=`for i in $$list; do \ 297 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 298 | done | \ 299 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ 300 | END { if (nonempty) { for (i in files) print i; }; }'`; \ 301 | test -z "$(CTAGS_ARGS)$$unique" \ 302 | || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ 303 | $$unique 304 | 305 | GTAGS: 306 | here=`$(am__cd) $(top_builddir) && pwd` \ 307 | && $(am__cd) $(top_srcdir) \ 308 | && gtags -i $(GTAGS_ARGS) "$$here" 309 | 310 | distclean-tags: 311 | -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags 312 | 313 | distdir: $(DISTFILES) 314 | @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 315 | topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 316 | list='$(DISTFILES)'; \ 317 | dist_files=`for file in $$list; do echo $$file; done | \ 318 | sed -e "s|^$$srcdirstrip/||;t" \ 319 | -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ 320 | case $$dist_files in \ 321 | */*) $(MKDIR_P) `echo "$$dist_files" | \ 322 | sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ 323 | sort -u` ;; \ 324 | esac; \ 325 | for file in $$dist_files; do \ 326 | if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ 327 | if test -d $$d/$$file; then \ 328 | dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ 329 | if test -d "$(distdir)/$$file"; then \ 330 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ 331 | fi; \ 332 | if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ 333 | cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ 334 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ 335 | fi; \ 336 | cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ 337 | else \ 338 | test -f "$(distdir)/$$file" \ 339 | || cp -p $$d/$$file "$(distdir)/$$file" \ 340 | || exit 1; \ 341 | fi; \ 342 | done 343 | check-am: all-am 344 | check: check-am 345 | all-am: Makefile $(PROGRAMS) 346 | installdirs: 347 | for dir in "$(DESTDIR)$(bindir)"; do \ 348 | test -z "$$dir" || $(MKDIR_P) "$$dir"; \ 349 | done 350 | install: install-am 351 | install-exec: install-exec-am 352 | install-data: install-data-am 353 | uninstall: uninstall-am 354 | 355 | install-am: all-am 356 | @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am 357 | 358 | installcheck: installcheck-am 359 | install-strip: 360 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ 361 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ 362 | `test -z '$(STRIP)' || \ 363 | echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install 364 | mostlyclean-generic: 365 | 366 | clean-generic: 367 | 368 | distclean-generic: 369 | -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) 370 | -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) 371 | 372 | maintainer-clean-generic: 373 | @echo "This command is intended for maintainers to use" 374 | @echo "it deletes files that may require special tools to rebuild." 375 | clean: clean-am 376 | 377 | clean-am: clean-binPROGRAMS clean-generic mostlyclean-am 378 | 379 | distclean: distclean-am 380 | -rm -rf ./$(DEPDIR) 381 | -rm -f Makefile 382 | distclean-am: clean-am distclean-compile distclean-generic \ 383 | distclean-tags 384 | 385 | dvi: dvi-am 386 | 387 | dvi-am: 388 | 389 | html: html-am 390 | 391 | html-am: 392 | 393 | info: info-am 394 | 395 | info-am: 396 | 397 | install-data-am: 398 | 399 | install-dvi: install-dvi-am 400 | 401 | install-dvi-am: 402 | 403 | install-exec-am: install-binPROGRAMS 404 | 405 | install-html: install-html-am 406 | 407 | install-html-am: 408 | 409 | install-info: install-info-am 410 | 411 | install-info-am: 412 | 413 | install-man: 414 | 415 | install-pdf: install-pdf-am 416 | 417 | install-pdf-am: 418 | 419 | install-ps: install-ps-am 420 | 421 | install-ps-am: 422 | 423 | installcheck-am: 424 | 425 | maintainer-clean: maintainer-clean-am 426 | -rm -rf ./$(DEPDIR) 427 | -rm -f Makefile 428 | maintainer-clean-am: distclean-am maintainer-clean-generic 429 | 430 | mostlyclean: mostlyclean-am 431 | 432 | mostlyclean-am: mostlyclean-compile mostlyclean-generic 433 | 434 | pdf: pdf-am 435 | 436 | pdf-am: 437 | 438 | ps: ps-am 439 | 440 | ps-am: 441 | 442 | uninstall-am: uninstall-binPROGRAMS 443 | 444 | .MAKE: install-am install-strip 445 | 446 | .PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ 447 | clean-generic ctags distclean distclean-compile \ 448 | distclean-generic distclean-tags distdir dvi dvi-am html \ 449 | html-am info info-am install install-am install-binPROGRAMS \ 450 | install-data install-data-am install-dvi install-dvi-am \ 451 | install-exec install-exec-am install-html install-html-am \ 452 | install-info install-info-am install-man install-pdf \ 453 | install-pdf-am install-ps install-ps-am install-strip \ 454 | installcheck installcheck-am installdirs maintainer-clean \ 455 | maintainer-clean-generic mostlyclean mostlyclean-compile \ 456 | mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \ 457 | uninstall-am uninstall-binPROGRAMS 458 | 459 | #if DEBUG 460 | #AM_CFLAGS = -g -O0 461 | #AM_CXXFLAGS = -g -O0 462 | #endif 463 | 464 | # Tell versions [3.59,3.63) of GNU make to not export all variables. 465 | # Otherwise a system limit (for SysV at least) may be exceeded. 466 | .NOEXPORT: 467 | -------------------------------------------------------------------------------- /src/env.hh: -------------------------------------------------------------------------------- 1 | #ifndef ENV_HH 2 | #define ENV_HH 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "matrix.hh" 16 | #include "log.hh" 17 | 18 | typedef uint8_t yval_t; 19 | 20 | typedef D2Array AdjMatrix; 21 | typedef D2Array Matrix; 22 | typedef D3Array D3; 23 | typedef D2Array MatrixKV; 24 | typedef std::pair LocIndiv; 25 | typedef D1Array YArray; 26 | typedef std::map YArrayMap; 27 | 28 | typedef std::map SNPMap; 29 | typedef std::map LocIndivMap; 30 | typedef std::map IDMap; 31 | typedef std::map FreqMap; 32 | typedef std::map FreqStrMap; 33 | typedef std::map StrMap; 34 | typedef std::map StrMapInv; 35 | typedef D1Array *> SparseMatrix; 36 | typedef std::map NodeMap; 37 | typedef std::map BoolMap; 38 | typedef std::map BoolMap64; 39 | typedef std::map NodeValMap; 40 | typedef std::map > MapVec; 41 | typedef MapVec SparseMatrix2; 42 | typedef std::map SampleMap; 43 | typedef map > SNPByLoc; 44 | typedef vector IndivList; 45 | 46 | //typedef std::map CountMap; 47 | //typedef std::map ValueMap; 48 | typedef std::map StrMapInv; 49 | 50 | class Env { 51 | public: 52 | Env(uint32_t N, uint32_t K, uint32_t L, 53 | bool batch, 54 | bool force_overwrite_dir, string dfname, 55 | string label, 56 | string etype, 57 | uint32_t rfreq, bool logl, bool loadcmp, 58 | double seed, bool file_suffix, 59 | bool save_beta, bool adagrad, uint32_t nthreads, 60 | bool use_test_set, 61 | bool compute_beta, string locations_file, 62 | double stop_threshold); 63 | ~Env() { fclose(_plogf); } 64 | 65 | static string prefix; 66 | static Logger::Level level; 67 | 68 | uint32_t n; 69 | uint32_t k; 70 | uint32_t l; 71 | uint32_t t; 72 | uint32_t blocks; 73 | uint32_t indiv_sample_size; 74 | uint32_t nthreads; 75 | 76 | bool batch_mode; 77 | double meanchangethresh; 78 | double alpha; 79 | 80 | double validation_ratio; 81 | double heldout_indiv_ratio; 82 | double test_ratio; 83 | 84 | double eta0_dense; 85 | double eta1_dense; 86 | double eta0_regular; 87 | double eta1_regular; 88 | double eta0_uniform; 89 | double eta1_uniform; 90 | double eta0_sparse; 91 | double eta1_sparse; 92 | double eta0; 93 | double eta1; 94 | 95 | int reportfreq; 96 | double epsilon; 97 | double logepsilon; 98 | 99 | double tau0; 100 | double nodetau0; 101 | double nodekappa; 102 | double kappa; 103 | uint32_t online_iterations; 104 | bool terminate; 105 | string datfname; 106 | 107 | string label; 108 | string eta_type; 109 | 110 | bool use_validation_stop; 111 | bool use_training_stop; 112 | bool use_test_set; 113 | bool compute_logl; 114 | bool loadcmp; 115 | double seed; 116 | bool file_suffix; 117 | bool save_beta; 118 | bool adagrad; 119 | bool compute_beta; 120 | string locations_file; 121 | double stop_threshold; 122 | 123 | template static void plog(string s, const T &v); 124 | static string file_str(string fname); 125 | 126 | private: 127 | static FILE *_plogf; 128 | }; 129 | 130 | 131 | template inline void 132 | Env::plog(string s, const T &v) 133 | { 134 | fprintf(_plogf, "%s: %s\n", s.c_str(), v.s().c_str()); 135 | fflush(_plogf); 136 | } 137 | 138 | template<> inline void 139 | Env::plog(string s, const double &v) 140 | { 141 | fprintf(_plogf, "%s: %.9f\n", s.c_str(), v); 142 | fflush(_plogf); 143 | } 144 | 145 | template<> inline void 146 | Env::plog(string s, const bool &v) 147 | { 148 | fprintf(_plogf, "%s: %s\n", s.c_str(), v ? "True": "False"); 149 | fflush(_plogf); 150 | } 151 | 152 | template<> inline void 153 | Env::plog(string s, const int &v) 154 | { 155 | fprintf(_plogf, "%s: %d\n", s.c_str(), v); 156 | fflush(_plogf); 157 | } 158 | 159 | template<> inline void 160 | Env::plog(string s, const unsigned &v) 161 | { 162 | fprintf(_plogf, "%s: %d\n", s.c_str(), v); 163 | fflush(_plogf); 164 | } 165 | 166 | template<> inline void 167 | Env::plog(string s, const short unsigned int &v) 168 | { 169 | fprintf(_plogf, "%s: %d\n", s.c_str(), v); 170 | fflush(_plogf); 171 | } 172 | 173 | template<> inline void 174 | Env::plog(string s, const uint64_t &v) 175 | { 176 | fprintf(_plogf, "%s: %lu\n", s.c_str(), v); 177 | fflush(_plogf); 178 | } 179 | 180 | inline string 181 | Env::file_str(string fname) 182 | { 183 | string s = prefix + fname; 184 | return s; 185 | } 186 | 187 | inline 188 | Env::Env(uint32_t N, uint32_t K, uint32_t L, 189 | bool batch, 190 | bool force_overwrite_dir, string dfname, 191 | string lbl, 192 | string etype, 193 | uint32_t rfreq, bool logl, bool lcmp, 194 | double seedv, bool file_suffixv, 195 | bool save_betav, bool adagradv, 196 | uint32_t nthreadsv, 197 | bool use_test_setv, bool compute_betav, 198 | string locations_filev, 199 | double stop_thresholdv) 200 | : n(N), 201 | k(K), 202 | l(L), 203 | t(2), 204 | blocks(100), 205 | indiv_sample_size(N/blocks), 206 | nthreads(nthreadsv), 207 | batch_mode(batch), 208 | meanchangethresh(0.001), 209 | alpha((double)1.0/k), 210 | heldout_indiv_ratio(0.001), 211 | validation_ratio(0.005), 212 | test_ratio(0.005), 213 | eta0_dense(4700.59), 214 | eta1_dense(0.77), 215 | eta0_regular(3.87), 216 | eta1_regular(1.84), 217 | eta0_uniform(1.00), 218 | eta1_uniform(1.00), 219 | eta0_sparse(0.97), 220 | eta1_sparse(6.33), 221 | eta0(eta0_uniform), 222 | eta1(eta1_uniform), 223 | reportfreq(rfreq), 224 | epsilon(1e-30), 225 | logepsilon(log(epsilon)), 226 | 227 | tau0(1), //default 1 228 | kappa(0.5), 229 | nodetau0(1), //default 1 230 | nodekappa(0.5), 231 | 232 | online_iterations(10), //default 10 233 | terminate(false), 234 | 235 | datfname(dfname), 236 | label(lbl), 237 | eta_type(etype), 238 | use_validation_stop(true), 239 | use_training_stop(false), 240 | compute_logl(logl), 241 | loadcmp(lcmp), 242 | seed(seedv), 243 | file_suffix(file_suffixv), 244 | save_beta(save_betav), 245 | adagrad(adagradv), 246 | use_test_set(use_test_setv), 247 | compute_beta(compute_betav), 248 | locations_file(locations_filev), 249 | stop_threshold(stop_thresholdv) 250 | { 251 | ostringstream sa; 252 | sa << "n" << n << "-"; 253 | sa << "k" << k << "-"; 254 | sa << "l" << l; 255 | if (label != "") 256 | sa << "-" << label; 257 | else if (datfname.length() > 3) { 258 | string q = datfname.substr(0,2); 259 | if (q == "..") 260 | q = "xx"; 261 | sa << "-" << q; 262 | } 263 | 264 | if (seed != 0) 265 | sa << "-" << "seed" << seed; 266 | prefix = sa.str(); 267 | level = Logger::TEST; 268 | 269 | fprintf(stdout, "+ Creating directory %s\n", prefix.c_str()); 270 | assert (Logger::initialize(prefix, "infer.log", 271 | force_overwrite_dir, level) >= 0); 272 | fflush(stdout); 273 | _plogf = fopen(file_str("/param.txt").c_str(), "w"); 274 | if (!_plogf) { 275 | printf("cannot open param file:%s\n", strerror(errno)); 276 | exit(-1); 277 | } 278 | 279 | if (N > 10000) { 280 | blocks = 100; 281 | indiv_sample_size = N / blocks; 282 | } else { 283 | blocks = 10; 284 | indiv_sample_size = N / blocks; 285 | } 286 | 287 | plog("n", n); 288 | plog("k", k); 289 | plog("t", t); 290 | plog("l", l); 291 | plog("nthreads", nthreads); 292 | plog("tau0", tau0); 293 | plog("nodetau0", nodetau0); 294 | plog("kappa", kappa); 295 | plog("nodekappa", nodekappa); 296 | plog("alpha", alpha); 297 | plog("heldout_indiv_ratio", heldout_indiv_ratio); 298 | plog("validation_ratio", validation_ratio); 299 | plog("online_iterations", online_iterations); 300 | plog("GSL seed", seed); 301 | plog("file suffix", file_suffix); 302 | plog("save beta", save_beta); 303 | plog("adagrad", adagrad); 304 | plog("indiv sample size", indiv_sample_size); 305 | plog("blocks", blocks); 306 | plog("compute_beta", compute_beta); 307 | plog("stop_threshold", stop_threshold); 308 | 309 | string ndatfname = file_str("/network.dat"); 310 | unlink(ndatfname.c_str()); 311 | assert (symlink(datfname.c_str(), ndatfname.c_str()) >= 0); 312 | fprintf(stderr, "+ done initializing env\n"); 313 | } 314 | 315 | /* 316 | src: http://www.delorie.com/gnu/docs/glibc/libc_428.html 317 | Subtract the `struct timeval' values X and Y, 318 | storing the result in RESULT. 319 | Return 1 if the difference is negative, otherwise 0. 320 | */ 321 | inline int 322 | timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y) 323 | { 324 | /* Perform the carry for the later subtraction by updating y. */ 325 | if (x->tv_usec < y->tv_usec) { 326 | int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; 327 | y->tv_usec -= 1000000 * nsec; 328 | y->tv_sec += nsec; 329 | } 330 | if (x->tv_usec - y->tv_usec > 1000000) { 331 | int nsec = (x->tv_usec - y->tv_usec) / 1000000; 332 | y->tv_usec += 1000000 * nsec; 333 | y->tv_sec -= nsec; 334 | } 335 | 336 | /* Compute the time remaining to wait. 337 | tv_usec is certainly positive. */ 338 | result->tv_sec = x->tv_sec - y->tv_sec; 339 | result->tv_usec = x->tv_usec - y->tv_usec; 340 | 341 | /* Return 1 if result is negative. */ 342 | return x->tv_sec < y->tv_sec; 343 | } 344 | 345 | inline void 346 | timeval_add (struct timeval *result, const struct timeval *x) 347 | { 348 | result->tv_sec += x->tv_sec; 349 | result->tv_usec += x->tv_usec; 350 | 351 | if (result->tv_usec >= 1000000) { 352 | result->tv_sec++; 353 | result->tv_usec -= 1000000; 354 | } 355 | } 356 | 357 | #endif 358 | -------------------------------------------------------------------------------- /src/lib.hh: -------------------------------------------------------------------------------- 1 | #ifndef LIB_HH 2 | #define LIB_HH 3 | 4 | #include "env.hh" 5 | #include "matrix.hh" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class PopLib { 13 | public: 14 | static void set_dir_exp(const Matrix &u, Matrix &exp); 15 | static void set_dir_exp(const D3 &u, D3 &exp); 16 | static void set_dir_exp(uint32_t a, const Matrix &u, Matrix &exp); 17 | }; 18 | 19 | inline void 20 | PopLib::set_dir_exp(const Matrix &u, Matrix &exp) 21 | { 22 | const double ** const d = u.data(); 23 | double **e = exp.data(); 24 | for (uint32_t i = 0; i < u.m(); ++i) { 25 | double s = .0; 26 | for (uint32_t j = 0; j < u.n(); ++j) 27 | s += d[i][j]; 28 | assert (s > .0); 29 | double psi_sum = gsl_sf_psi(s); 30 | for (uint32_t j = 0; j < u.n(); ++j) { 31 | double v = d[i][j]; 32 | e[i][j] = gsl_sf_psi(v) - psi_sum; 33 | } 34 | } 35 | } 36 | 37 | inline void 38 | PopLib::set_dir_exp(const D3 &u, D3 &exp) 39 | { 40 | const double *** const d = u.data(); 41 | double ***e = exp.data(); 42 | 43 | for (uint32_t i = 0; i < u.m(); ++i) { 44 | for (uint32_t j = 0; j < u.n(); ++j) { 45 | double s = .0; 46 | for (uint32_t k = 0; k < u.k(); ++k) 47 | s += d[i][j][k]; 48 | assert (s > .0); 49 | double psi_sum = gsl_sf_psi(s); 50 | for (uint32_t k = 0; k < u.k(); ++k) { 51 | assert (d[i][j][k] > .0); 52 | double v = d[i][j][k]; 53 | e[i][j][k] = gsl_sf_psi(v) - psi_sum; 54 | } 55 | } 56 | } 57 | } 58 | 59 | inline void 60 | PopLib::set_dir_exp(uint32_t a, const Matrix &u, Matrix &exp) 61 | { 62 | const double ** const d = u.data(); 63 | double **e = exp.data(); 64 | 65 | double s = .0; 66 | for (uint32_t j = 0; j < u.n(); ++j) 67 | s += d[a][j]; 68 | double psi_sum = gsl_sf_psi(s); 69 | for (uint32_t j = 0; j < u.n(); ++j) 70 | e[a][j] = gsl_sf_psi(d[a][j]) - psi_sum; 71 | } 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/log.cc: -------------------------------------------------------------------------------- 1 | #include "log.hh" 2 | 3 | string Logger::_log_fname = "mmsb.log"; 4 | string Logger::_prefix = ""; 5 | FILE *Logger::_logfd = 0; 6 | bool Logger::_initialized = false; 7 | Logger::Level Logger::_level = DEBUG; 8 | 9 | int 10 | Logger::initialize(string prefix, string name, bool force, 11 | Level level) 12 | { 13 | if (!_initialized) { 14 | _prefix = prefix; 15 | _log_fname = name; 16 | _level = level; 17 | if (setup_logfd(force) < 0) 18 | return -1; 19 | 20 | _initialized = true; 21 | info("Setting log to %s", name.c_str()); 22 | } 23 | return 0; 24 | } 25 | 26 | int 27 | Logger::xlog(Level level, const char *format, ...) 28 | { 29 | if (!_initialized) { 30 | initialize(_prefix, string("/mmsb.log"), false); 31 | } 32 | if (level < _level) 33 | return 0; 34 | 35 | assert(_logfd); 36 | va_list ap; 37 | va_start (ap, format); 38 | string ts = get_time(); 39 | string l = get_level_str(level); 40 | fprintf(_logfd, "[%s] [%d] [%3s] ", ts.c_str(), getpid(), l.c_str()); 41 | vfprintf(_logfd, format, ap); 42 | fprintf(_logfd, "\n\n"); 43 | fflush(_logfd); 44 | va_end(ap); 45 | return 0; 46 | } 47 | 48 | string 49 | Logger::get_time() 50 | { 51 | time_t now = time(0); 52 | struct tm p; 53 | localtime_r(&now, &p); 54 | char buf[512]; 55 | strftime(buf, 512, "%b %e %T", &p); 56 | return string(buf); 57 | } 58 | 59 | string 60 | Logger::get_level_str(Level level) 61 | { 62 | string s; 63 | switch (level) { 64 | case INFO: s = "INF"; break; 65 | case DEBUG: s = "DBG"; break; 66 | case WARN: s = "WRN"; break; 67 | case ERROR: s = "ERR"; break; 68 | case FATAL: s = "FTL"; break; 69 | case TEST: s = "TST"; break; 70 | default: 71 | s = "unknown"; 72 | } 73 | return s; 74 | } 75 | 76 | int 77 | Logger::setup_logfd(bool force) 78 | { 79 | if (setup_log_dir(force) < 0) 80 | return -1; 81 | 82 | if (_logfd) { 83 | fclose(_logfd); 84 | _logfd = 0; 85 | } 86 | string fn = log_fname(); 87 | _logfd = fopen(fn.c_str(), "w"); 88 | if (_logfd) 89 | fprintf(stderr, "+ Writing log to %s\n", fn.c_str()); 90 | if (!_logfd) { 91 | _logfd = fopen("/dev/null", "w"); 92 | fprintf(stderr, "+ Writing log to /dev/null\n"); 93 | } 94 | return 0; 95 | } 96 | 97 | int 98 | Logger::setup_log_dir(bool force) 99 | { 100 | struct stat dirstat; 101 | if (stat(dirname().c_str(), &dirstat) != 0) { 102 | if (errno == ENOENT) { 103 | mkdir(dirname().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); 104 | if (stat(dirname().c_str(), &dirstat) != 0) { 105 | fprintf(stderr, "Warning: could not create dir %s\n", 106 | dirname().c_str()); 107 | return -1; 108 | } 109 | } else { 110 | fprintf(stderr, "Warning: could not stat dir %s\n", dirname().c_str()); 111 | return -1; 112 | } 113 | } else if (!force) { 114 | fprintf(stderr, "Error: dir %s already exists\n", dirname().c_str()); 115 | return -1; 116 | } 117 | return 0; 118 | } 119 | -------------------------------------------------------------------------------- /src/log.hh: -------------------------------------------------------------------------------- 1 | #ifndef LOG_HH 2 | #define LOG_HH 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | using namespace std; 17 | 18 | //#define DEBUG_MODE 1 19 | 20 | #define PREFIX "log" 21 | 22 | class Logger { 23 | public: 24 | typedef enum { DEBUG = 0, TEST, INFO, WARN, ERROR, FATAL } Level; 25 | static int xlog(Level l, const char *format, ...); 26 | static int initialize(string prefix, string name, 27 | bool force_overwrite_dir, 28 | Level level = DEBUG); 29 | static string log_fname() { return dirname() + string("/") + _log_fname; } 30 | static string dirname() { return _prefix; } 31 | 32 | private: 33 | static int setup_log_dir(bool force); 34 | static int setup_logfd(bool force); 35 | static string get_time(); 36 | static string get_level_str(Level level); 37 | 38 | static FILE *_logfd; 39 | static string _log_fname; 40 | static bool _initialized; 41 | static string _prefix; 42 | static Level _level; 43 | }; 44 | 45 | 46 | #ifndef DEBUG_MODE 47 | #define debug(X, ...) 48 | #define info(X, ...) 49 | #define tst(X, ...) 50 | #define lerr(format, ...) Logger::xlog(Logger::ERROR, format, ## __VA_ARGS__) 51 | #else 52 | #define tst(format, ...) Logger::xlog(Logger::TEST, format, ## __VA_ARGS__) 53 | #define debug(format, ...) Logger::xlog(Logger::DEBUG, format, ## __VA_ARGS__) 54 | #define info(format, ...) Logger::xlog(Logger::INFO, format, ## __VA_ARGS__) 55 | #define lerr(format, ...) Logger::xlog(Logger::ERROR, format, ## __VA_ARGS__) 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/main.cc: -------------------------------------------------------------------------------- 1 | #include "env.hh" 2 | //#include "marginf.hh" 3 | //#include "snpsamplinga.hh" 4 | //#include "snpsamplingb.hh" 5 | //#include "snpsamplingc.hh" 6 | //#include "snpsamplingd.hh" 7 | #include "snpsamplinge.hh" 8 | //#include "snpsamplingf.hh" 9 | //#include "snpsamplingg.hh" 10 | #include "log.hh" 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | string Env::prefix = ""; 19 | Logger::Level Env::level = Logger::DEBUG; 20 | FILE *Env::_plogf = NULL; 21 | void usage(); 22 | void test(); 23 | 24 | Env *env_global = NULL; 25 | 26 | volatile sig_atomic_t sig_handler_active = 0; 27 | 28 | void 29 | term_handler(int sig) 30 | { 31 | if (env_global) { 32 | printf("Got termination signal. Saving model state and quitting.\n"); 33 | fflush(stdout); 34 | env_global->terminate = 1; 35 | } else { 36 | signal(sig, SIG_DFL); 37 | raise(sig); 38 | } 39 | } 40 | 41 | int 42 | main(int argc, char **argv) 43 | { 44 | signal(SIGTERM, term_handler); 45 | 46 | bool force_overwrite_dir = false; 47 | string datfname = "network.dat"; 48 | string label = ""; 49 | uint32_t n = 0, k = 0, l = 0; 50 | int i = 0; 51 | 52 | bool batch = false; 53 | bool online = true; 54 | bool logl = false; 55 | string eta_type = "default"; // "default", "sparse", "regular" or "dense" 56 | uint32_t rfreq = 10000; 57 | bool rfreq_set = false; 58 | string idfile = ""; 59 | bool loadcmp = false; 60 | bool marginf = false; 61 | bool snpsamplinga = false; 62 | bool snpsamplingb = false; 63 | bool snpsamplingc = false; 64 | bool snpsamplingd = false; 65 | bool snpsamplinge = true; //false; 66 | bool snpsamplingf = false; 67 | bool snpsamplingg = false; 68 | double seed = 0; 69 | 70 | bool file_suffix = false; 71 | bool save_beta = false; 72 | bool adagrad = false; 73 | bool use_test_set = false; 74 | bool compute_beta = false; 75 | string locations_file = ""; 76 | uint32_t nthreads = 6; 77 | double stop_threshold = 1e-5; //1e-5 78 | 79 | if (argc == 1) { 80 | usage(); 81 | exit(-1); 82 | } 83 | 84 | while (i <= argc - 1) { 85 | if (strcmp(argv[i], "-help") == 0) { 86 | usage(); 87 | exit(0); 88 | } else if (strcmp(argv[i], "-force") == 0) { 89 | fprintf(stdout, "+ overwrite option set\n"); 90 | force_overwrite_dir = true; 91 | } else if (strcmp(argv[i], "-online") == 0) { 92 | fprintf(stdout, "+ online option set\n"); 93 | online = true; 94 | batch = false; 95 | } else if (strcmp(argv[i], "-file") == 0) { 96 | if (i + 1 > argc - 1) { 97 | fprintf(stderr, "+ insufficient arguments!\n"); 98 | exit(-1); 99 | } 100 | datfname = string(argv[++i]); 101 | fprintf(stdout, "+ using file %s\n", datfname.c_str()); 102 | } else if (strcmp(argv[i], "-bed") == 0) { 103 | if (i + 1 > argc - 1) { 104 | fprintf(stderr, "+ insufficient arguments!\n"); 105 | exit(-1); 106 | } 107 | datfname = string(argv[++i]); 108 | fprintf(stdout, "+ using file %s\n", datfname.c_str()); 109 | } else if (strcmp(argv[i], "-batch") == 0) { 110 | fprintf(stdout, "batch option currently not available"); 111 | exit(0); 112 | //batch = true; 113 | //online = false; 114 | //fprintf(stdout, "+ batch option set\n"); 115 | } else if (strcmp(argv[i], "-n") == 0) { 116 | n = atoi(argv[++i]); 117 | fprintf(stdout, "+ n = %d\n", n); 118 | } else if (strcmp(argv[i], "-k") == 0) { 119 | k = atoi(argv[++i]); 120 | fprintf(stdout, "+ K = %d\n", k); 121 | } else if (strcmp(argv[i], "-l") == 0) { 122 | l = atoi(argv[++i]); 123 | fprintf(stdout, "+ L = %d\n", l); 124 | } else if (strcmp(argv[i], "-label") == 0) { 125 | label = string(argv[++i]); 126 | } else if (strcmp(argv[i], "-eta-type") == 0) { 127 | eta_type = string(argv[++i]); 128 | fprintf(stdout, "+ eta-type = %s\n", eta_type.c_str()); 129 | } else if (strcmp(argv[i], "-rfreq") == 0) { 130 | rfreq = atoi(argv[++i]); 131 | fprintf(stdout, "+ rfreq = %d\n", rfreq); 132 | rfreq_set = true; 133 | } else if (strcmp(argv[i], "-logl") == 0) { 134 | logl = true; 135 | fprintf(stdout, "+ logl option set\n"); 136 | } else if (strcmp(argv[i], "-idfile") == 0) { 137 | idfile = string(argv[++i]); 138 | fprintf(stdout, "+ idfile = %s\n", idfile.c_str()); 139 | } else if (strcmp(argv[i], "-loadcmp") == 0) { 140 | loadcmp = true; 141 | fprintf(stdout, "+ loadcmp option set\n"); 142 | } /*else if (strcmp(argv[i], "-A") == 0) { 143 | marginf = true; 144 | fprintf(stdout, "+ algorithm A option set\n"); 145 | } else if (strcmp(argv[i], "-snpsamplinga") == 0) { 146 | snpsamplinga = true; 147 | fprintf(stdout, "+ snp sampling A option set\n"); 148 | } else if (strcmp(argv[i], "-B") == 0) { 149 | snpsamplingb = true; 150 | fprintf(stdout, "+ algorithm B option set\n"); 151 | } else if (strcmp(argv[i], "-C") == 0) { 152 | snpsamplingc = true; 153 | fprintf(stdout, "+ algorithm C option set\n"); 154 | } else if (strcmp(argv[i], "-D") == 0) { 155 | snpsamplingd = true; 156 | fprintf(stdout, "+ algorithm D option set\n"); 157 | }*/ else if (strcmp(argv[i], "-E") == 0) { 158 | snpsamplinge = true; 159 | fprintf(stdout, "+ algorithm E option set\n"); 160 | } else if (strcmp(argv[i], "-stochastic")==0) { 161 | snpsamplinge = true; 162 | fprintf(stdout, "+ stochastic option set\n"); 163 | } else if (strcmp(argv[i], "-seed") == 0) { 164 | seed = atof(argv[++i]); 165 | fprintf(stdout, "+ random seed set to %.5f\n", seed); 166 | } else if (strcmp(argv[i], "-file-suffix") == 0) { 167 | file_suffix = true; 168 | } else if (strcmp(argv[i], "-save-beta") == 0) { 169 | save_beta = true; 170 | } else if (strcmp(argv[i], "-adagrad") ==0){ 171 | adagrad = true; 172 | } else if (strcmp(argv[i], "-nthreads") ==0){ 173 | nthreads = atoi(argv[++i]); 174 | } else if (strcmp(argv[i], "-use-test-set") == 0){ 175 | use_test_set = true; 176 | } else if (strcmp(argv[i], "-locations-file") == 0) { 177 | locations_file = string(argv[++i]); 178 | } else if (strcmp(argv[i], "-compute-beta") == 0) { 179 | compute_beta = true; 180 | } else if (strcmp(argv[i], "-stop-threshold") == 0) { 181 | stop_threshold = atof(argv[++i]); 182 | } else if (i > 0) { 183 | fprintf(stdout, "error: unknown option %s\n", argv[i]); 184 | assert(0); 185 | } 186 | ++i; 187 | }; 188 | 189 | if (!rfreq_set) 190 | rfreq = 100000; 191 | 192 | assert (!(batch && online)); 193 | 194 | Env env(n, k, l, batch, 195 | force_overwrite_dir, datfname, label, eta_type, 196 | rfreq, logl, loadcmp, seed, file_suffix, 197 | save_beta, adagrad, nthreads, 198 | use_test_set, compute_beta, locations_file, stop_threshold); 199 | env_global = &env; 200 | 201 | SNP snp(env); 202 | 203 | if (snp.read(datfname.c_str()) < 0) { 204 | fprintf(stderr, "error reading %s; quitting\n", 205 | datfname.c_str()); 206 | return -1; 207 | } 208 | if (idfile != "" && snp.read_idfile(idfile.c_str()) < 0) 209 | fprintf(stderr, "error reading %s; quitting\n", 210 | idfile.c_str()); 211 | env.n = snp.n(); 212 | 213 | 214 | if (!loadcmp) { 215 | /* if (snpsamplinga) { 216 | SNPSamplingA snpsamplingA(env, snp); 217 | snpsamplingA.infer(); 218 | } else if (snpsamplingb) { 219 | SNPSamplingB snpsamplingB(env, snp); 220 | snpsamplingB.infer(); 221 | } else if (snpsamplingc) { 222 | SNPSamplingC snpsamplingC(env, snp); 223 | snpsamplingC.infer(); 224 | } else if (snpsamplingd) { 225 | SNPSamplingD snpsamplingD(env, snp); 226 | snpsamplingD.infer(); 227 | } else*/ if (snpsamplinge) { 228 | SNPSamplingE snpsamplingE(env, snp); 229 | snpsamplingE.infer(); 230 | }/* else if (snpsamplingf) { 231 | SNPSamplingF snpsamplingF(env, snp); 232 | snpsamplingF.infer(); 233 | } else if (snpsamplingg) { 234 | SNPSamplingG snpsamplingg(env, snp); 235 | snpsamplingg.infer(); 236 | } else { 237 | MargInf marg(env, snp); 238 | marg.infer(); 239 | }*/ 240 | } else {/* 241 | MargInf popinf1(env, snp); 242 | MargInf popinf2(env, snp); 243 | popinf1.load_model("beta_ps.txt", "theta_ps.txt"); 244 | popinf2.load_model("beta.txt", "theta.txt"); 245 | 246 | Matrix skl(env.n,env.l); 247 | Matrix js_skl(env.n,env.l); 248 | Array a(env.n); 249 | Array b(env.l); 250 | uArray ac(env.n); 251 | uArray bc(env.l); 252 | 253 | double **skld = skl.data(); 254 | double **js_skld = js_skl.data(); 255 | double s = .0, js = .0; 256 | 257 | uint32_t t = 0; 258 | for (uint32_t n = 0; n < env.n; n++) 259 | for (uint32_t l = 0; l < env.l; l++) { 260 | if (snp.is_missing(n, l)) { 261 | skld[n][l] = .0; 262 | continue; 263 | 264 | } 265 | 266 | Array p1(3), p2(3); 267 | popinf1.snp_likelihood(l, n, p1); 268 | popinf2.snp_likelihood(l, n, p2); 269 | 270 | skld[n][l] = snp.symmetrized_kl(p1, p2); 271 | js_skld[n][l] = snp.js_divergence(p1,p2); 272 | t++; 273 | s += skld[n][l]; 274 | js += js_skld[n][l]; 275 | 276 | a[n] += skld[n][l]; 277 | b[l] += skld[n][l]; 278 | 279 | ac[n]++; 280 | bc[l]++; 281 | 282 | if (n % 10 == 0) { 283 | printf("\r%d", n); 284 | fflush(stdout); 285 | } 286 | } 287 | printf("t = %d, s = %.4f, m = %.4f, thrown = %d\n", t, s, s/t, snp.thrown()); 288 | printf("t = %d, js = %.4f, m = %.4f", t, js, js/t); 289 | fflush(stdout); 290 | 291 | FILE *f = fopen("skln.txt", "w"); 292 | FILE *g = fopen("skll.txt", "w"); 293 | 294 | for (uint32_t n = 0; n < env.n; ++n) 295 | fprintf(f, "%d\t%d\t%f\n", n, ac[n], ac[n] > 0 ? a[n] / ac[n] : .0); 296 | 297 | for (uint32_t l = 0; l < env.l; ++l) 298 | fprintf(g, "%d\t%d\t%f\n", l, bc[l], bc[l] > 0 ? b[l] / bc[l] : .0); 299 | 300 | fclose(g); 301 | fclose(f);*/ 302 | } 303 | } 304 | 305 | void 306 | usage() 307 | { 308 | fprintf(stdout, "Population inference software for SNP data.\n" 309 | "popgen [OPTIONS]\n" 310 | "\t-help\t\tusage\n" 311 | "\t-file \t location by individuals ASCII matrix of SNP values (0,1,2)\n" 312 | "\t-n \t\t number of individuals\n" 313 | "\t-l \t\t number of locations\n" 314 | "\t-k \t\t number of populations\n" 315 | //"\t-batch\t\t run batch variational inference\n" 316 | //"\t-stochastic\t run stochastic variational inference\n" 317 | "\t-label\t\t descriptive tag for the output directory\n" 318 | "\t-force\t\t overwrite existing output directory\n" 319 | "\t-rfreq \t checks for convergence and logs output every iterations\n" 320 | "\t-idmap\t\t file containing individual name/meta-data, one per line\n" 321 | ); 322 | fflush(stdout); 323 | } 324 | -------------------------------------------------------------------------------- /src/snp.cc: -------------------------------------------------------------------------------- 1 | #include "snp.hh" 2 | #include "log.hh" 3 | 4 | static int scurr = 0; 5 | 6 | int 7 | SNP::read(string s) 8 | { 9 | //check extension 10 | string ext; 11 | ext = s.substr(s.length()-4, 4); 12 | if(ext == ".bed"){ 13 | printf("+ bed format detected\n"); 14 | int ret = SNP::read_bed(s); 15 | return ret; 16 | } else if(ext == ".012") { 17 | printf("+ .012 detected"); 18 | } else { 19 | lerr("unrecognized file extension"); 20 | return -1; 21 | } 22 | 23 | uint32_t missing = 0; 24 | fprintf(stdout, "+ reading (%d,%d) snps from %s\n", 25 | _env.n, _env.l, s.c_str()); 26 | fflush(stdout); 27 | 28 | uint64_t a0=0,a1=0,a2=0; 29 | 30 | _y = new AdjMatrix(_env.n, _env.l); 31 | 32 | yval_t **yd = _y->data(); 33 | 34 | //FILE *maff = fopen(Env::file_str("/maf.tsv").c_str(), "w"); 35 | FILE *f = fopen(s.c_str(), "r"); 36 | if (!f) { 37 | lerr("cannot open file %s:%s", s.c_str(), strerror(errno)); 38 | return -1; 39 | } 40 | char tmpbuf[2048*10]; 41 | assert (tmpbuf != NULL); 42 | string s1, s2; 43 | uint32_t id1, id2; 44 | 45 | uint32_t loc = 0; 46 | while (!feof(f)) { 47 | if (fscanf(f, "%s\n", tmpbuf) < 0) { 48 | printf("Error: unexpected lines in file\n"); 49 | exit(-1); 50 | } 51 | double m = 0; 52 | uint32_t c = 0; 53 | for (uint32_t i = 0; i < _env.n; ++i) { 54 | if (tmpbuf[i] == '-') { 55 | missing++; 56 | yd[i][loc] = 3; //mark as missing 57 | } else { 58 | yd[i][loc] = tmpbuf[i] - '0'; 59 | if (yd[i][loc] == 0) 60 | a0++; 61 | else if (yd[i][loc] == 1) 62 | a1++; 63 | else if (yd[i][loc] == 2) 64 | a2++; 65 | m += yd[i][loc]; 66 | c++; 67 | } 68 | debug("%c %d\n", tmpbuf[i], yd[i][loc]); 69 | } 70 | assert(c); 71 | /*m /= (2 * c); 72 | _maf[loc] = 0.5 - fabs(0.5 - m); 73 | fprintf(maff, "%d\t%.5f\t%.5f\n", loc, m, _maf[loc]);*/ 74 | 75 | loc++; 76 | if (loc >= _env.l) 77 | break; 78 | if (loc % 10000 == 0) { 79 | printf("\r%d locations read", loc); 80 | fflush(stdout); 81 | } 82 | } 83 | Env::plog("missing snps", missing); 84 | 85 | Env::plog("0s snps", a0); 86 | Env::plog("1s snps", a1); 87 | Env::plog("2s snps", a2); 88 | fflush(stdout); 89 | fclose(f); 90 | //fclose(maff); 91 | 92 | return 0; 93 | } 94 | 95 | int 96 | SNP::read_bed(string s) 97 | { 98 | uint32_t missing = 0; 99 | uint32_t n = 0, l = 0; 100 | string prefix = s.substr(0, s.length()-4); 101 | 102 | 103 | //read in number of SNPs from .bim 104 | string bim = prefix + ".bim"; 105 | FILE *bim_f = fopen(bim.c_str(), "r"); 106 | if(!bim_f) { 107 | lerr("cannot open file %s:%s", bim.c_str(), strerror(errno)); 108 | return -1; 109 | } 110 | char tmpbuf[2048*10]; 111 | assert (tmpbuf != NULL); 112 | while ( fgets(tmpbuf, 20480, bim_f) != NULL ) { 113 | l++; 114 | } 115 | fclose(bim_f); 116 | 117 | printf("+ bim file tells us %d SNPs\n", l); 118 | if(_env.l != l) { 119 | lerr("-l input doesn't match SNPs in bim file\n"); 120 | return -1; 121 | } 122 | 123 | //read in number of individuals from .fam 124 | string fam = prefix + ".fam"; 125 | FILE *fam_f = fopen(fam.c_str(), "r"); 126 | if(!fam_f) { 127 | lerr("cannot open file %s:%s", fam.c_str(), strerror(errno)); 128 | return -1; 129 | } 130 | while ( fgets(tmpbuf, 20480, fam_f) != NULL ) { 131 | n++; 132 | } 133 | fclose(fam_f); 134 | 135 | printf("+ fam file tells us %d individuals\n", n); 136 | if(_env.n != n) { 137 | lerr("-n input doesn't match individuals in fam file\n"); 138 | return -1; 139 | } 140 | 141 | uint64_t a0=0,a1=0,a2=0; 142 | _y = new AdjMatrix(_env.n, _env.l); 143 | yval_t **yd = _y->data(); 144 | 145 | //compute blocksize 146 | int numbytes = n/4; 147 | if(_env.n % 4 != 0) 148 | numbytes++; 149 | 150 | //begin bed reading 151 | string bed = prefix + ".bed"; 152 | FILE *bed_f = fopen(bed.c_str(), "r"); 153 | if(!bed_f) { 154 | lerr("cannot open file %s:%s", bed.c_str(), strerror(errno)); 155 | return -1; 156 | } 157 | 158 | char input; 159 | uint32_t counter = 0; 160 | 161 | //check first three bytes for what we're expecting 162 | input = fgetc(bed_f); 163 | if((int) input != 108) { // 108 164 | lerr("%s magic number incorrect\n", bed.c_str()); 165 | return -1; 166 | } 167 | 168 | input = fgetc(bed_f); 169 | if((int) input != 27) { // 27 170 | lerr("%s magic number incorrect\n", bed.c_str()); 171 | return -1; 172 | } 173 | 174 | input = fgetc(bed_f); 175 | if((int) input == 1) { 176 | ; 177 | } else if((int) input == 0) { 178 | lerr("individual major mode not supported yet!\n"); 179 | return -1; 180 | } else { 181 | lerr("mode problem in %s\n", bed.c_str()); 182 | return -1; 183 | } 184 | 185 | //now read in the SNPs! 186 | //FILE *maff = fopen(Env::file_str("/maf.tsv").c_str(), "w"); 187 | char buffer[numbytes]; 188 | uint8_t currbyte; 189 | uint32_t shiftcount = 0; //number of times i've shifted the bits 190 | uint32_t byteind = 0; //index on buffer 191 | uint32_t loc = 0; 192 | double m = 0; //maf 193 | uint32_t c = 0; //count 194 | 195 | while(fread(buffer, 1, numbytes, bed_f) == numbytes) { //assuming bed is well formed... 196 | shiftcount = 0; 197 | byteind = 0; 198 | c = 0; 199 | m = 0.0; 200 | currbyte = (uint8_t) buffer[0]; 201 | //loop over SNPs 202 | for(uint32_t i = 0; i < _env.n; i++) { 203 | if(currbyte % 4 == 1) { //missing val 204 | missing++; 205 | yd[i][loc] = 3; 206 | } else{ 207 | if(currbyte % 4 == 3) { //0 or 2? 208 | yd[i][loc] = 2; 209 | a0++; 210 | } else if(currbyte % 4 == 2) { //1 211 | yd[i][loc] = 1; 212 | a1++; 213 | } else if(currbyte % 4 == 0) { //2 or 0? 214 | yd[i][loc] = 0; 215 | a2++; 216 | } 217 | m += yd[i][loc]; 218 | c++; 219 | } 220 | 221 | currbyte >>= 2; 222 | shiftcount++; 223 | if(shiftcount == 4) { 224 | shiftcount = 0; 225 | byteind++; 226 | currbyte = (uint8_t) buffer[byteind]; 227 | } 228 | } 229 | assert(c); 230 | /*m /= (2 * c); 231 | _maf[loc] = 0.5 - fabs(0.5 - m); 232 | fprintf(maff, "%d\t%.5f\t%.5f\n", loc, m, _maf[loc]);*/ 233 | 234 | loc++; 235 | if (loc >= _env.l) 236 | break; 237 | if (loc % 20000 == 0){ 238 | printf("\r%d locations read", loc); 239 | fflush(stdout); 240 | } 241 | } 242 | 243 | Env::plog("missing snps", missing); 244 | 245 | Env::plog("0s snps", a0); 246 | Env::plog("1s snps", a1); 247 | Env::plog("2s snps", a2); 248 | fflush(stdout); 249 | 250 | fclose(bed_f); 251 | //fclose(maff); 252 | return 0; 253 | } 254 | 255 | int 256 | SNP::read_idfile(string s) 257 | { 258 | FILE *f = fopen(s.c_str(), "r"); 259 | if (!f) { 260 | lerr("cannot open file %s:%s", s.c_str(), strerror(errno)); 261 | return -1; 262 | } 263 | uint32_t id = 0; 264 | string idstr; 265 | char tmpbuf[128]; 266 | while (!feof(f)) { 267 | if (fscanf(f, "%s\n", tmpbuf) < 0) { 268 | fprintf(stderr, "error: unexpected line in file\n"); 269 | exit(-1); 270 | } 271 | _labels[id] = string(tmpbuf); 272 | id++; 273 | } 274 | fclose(f); 275 | return 0; 276 | } 277 | 278 | -------------------------------------------------------------------------------- /src/snp.hh: -------------------------------------------------------------------------------- 1 | #ifndef POP_HH 2 | #define POP_HH 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "matrix.hh" 10 | #include "env.hh" 11 | #include "lib.hh" 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | using namespace std; 22 | 23 | class SNP { 24 | public: 25 | SNP(Env &env); 26 | ~SNP() { } 27 | 28 | int read(string s); 29 | int read_bed(string s); 30 | int read_idfile(string s); 31 | const AdjMatrix &y() const { assert(_y); return *_y; } 32 | AdjMatrix &y() { assert(_y); return *_y; } 33 | //const map &missing_snps() const { return _missing_snps; } 34 | bool is_missing(uint32_t indiv, uint32_t loc) const; 35 | string label(uint32_t id) const; 36 | 37 | uint32_t n() const; 38 | uint32_t l() const; 39 | yval_t dad(uint32_t i, uint32_t j) const; 40 | yval_t mom(uint32_t i, uint32_t j) const; 41 | 42 | double maf(uint32_t l) const { return _maf[l]; } 43 | 44 | uint32_t thrown() const { return _thrown; } 45 | 46 | double symmetrized_kl(Array &p1, Array &p2); 47 | double js_divergence(Array &p1, Array &p2); 48 | double kl(Array &p1, Array &p2); 49 | 50 | private: 51 | Env &_env; 52 | AdjMatrix *_y; 53 | //map _missing_snps; 54 | map _labels; 55 | uint32_t _thrown; 56 | Array _maf; 57 | IDMap _loc_to_idx; 58 | gsl_rng *_r; 59 | 60 | 61 | }; 62 | 63 | inline 64 | SNP::SNP(Env &env): 65 | _env(env), 66 | _y(NULL), 67 | _thrown(0), 68 | _maf(_env.l), 69 | _r(NULL) 70 | { 71 | gsl_rng_env_setup(); 72 | const gsl_rng_type *T = gsl_rng_default; 73 | _r = gsl_rng_alloc(T); 74 | if (_env.seed) //is a local version of env in other code, ask prem 75 | gsl_rng_set(_r, _env.seed); 76 | } 77 | 78 | inline uint32_t 79 | SNP::n() const 80 | { 81 | assert(_y); 82 | return _y->m(); 83 | } 84 | 85 | inline uint32_t 86 | SNP::l() const 87 | { 88 | assert(_y); 89 | return _y->n(); 90 | } 91 | 92 | inline yval_t 93 | SNP::mom(uint32_t a, uint32_t b) const 94 | { 95 | assert(_y); 96 | assert (a < _y->m() && b < _y->n()); 97 | const yval_t **yd = _y->const_data(); 98 | //return (yd[a][b] == 2) ? 1 : 0; 99 | if (yd[a][b] == 2) 100 | return 1; 101 | else if (yd[a][b] == 1 && b % 2 == 0) 102 | return 1; 103 | return 0; 104 | } 105 | 106 | inline yval_t 107 | SNP::dad(uint32_t a, uint32_t b) const 108 | { 109 | assert(_y); 110 | assert (a < _y->m() && b < _y->n()); 111 | const yval_t **yd = _y->const_data(); 112 | //return (yd[a][b] == 1 || yd[a][b] == 2) ? 1 : 0; 113 | if (yd[a][b] == 2) 114 | return 1; 115 | else if (yd[a][b] == 1 && b % 2 == 1) 116 | return 1; 117 | return 0; 118 | } 119 | 120 | inline bool 121 | SNP::is_missing(uint32_t indiv, uint32_t loc) const 122 | { 123 | assert(_y); 124 | const yval_t **yd = _y->const_data(); 125 | if (yd[indiv][loc] == 3) 126 | return true; 127 | return false; 128 | } 129 | 130 | inline string 131 | SNP::label(uint32_t id) const 132 | { 133 | map::const_iterator i = _labels.find(id); 134 | if (i == _labels.end()) 135 | return ""; 136 | return i->second; 137 | } 138 | 139 | inline double 140 | SNP::symmetrized_kl(Array &p1, Array &p2) 141 | { 142 | return kl(p1, p2) + kl(p2, p1); 143 | } 144 | 145 | inline double 146 | SNP::js_divergence(Array &p1, Array &p2) 147 | { 148 | Array m(3); 149 | m.copy_from(p1); 150 | m.add_to(p2); 151 | m.scale(0.5); 152 | return 0.5 * kl(p1,m) + 0.5 * kl(p2, m); 153 | } 154 | 155 | inline double 156 | SNP::kl(Array &p1, Array &p2) 157 | { 158 | assert (p1.n() == 3 && p2.n() == 3); 159 | double s = .0; 160 | for (uint32_t x = 0; x < 3; ++x) { 161 | if (p1[x] != .0 && p2[x] != .0) 162 | s += log(p1[x] / p2[x]) * p1[x]; 163 | else 164 | _thrown++; 165 | } 166 | return s; 167 | } 168 | 169 | 170 | 171 | #endif 172 | -------------------------------------------------------------------------------- /src/snpsamplinge.hh: -------------------------------------------------------------------------------- 1 | #ifndef SNPSAMPLINGE_HH 2 | #define SNPSAMPLINGE_HH 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "env.hh" 11 | #include "matrix.hh" 12 | #include "lib.hh" 13 | #include "snp.hh" 14 | #include "thread.hh" 15 | #include "tsqueue.hh" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | typedef vector IndivsList; 23 | typedef std::map ChunkMap; 24 | class SNPSamplingE; 25 | class PhiRunnerE : public Thread { 26 | public: 27 | PhiRunnerE(const Env &env, gsl_rng **r, 28 | const uint32_t &iter, 29 | const uint32_t &x, 30 | uint32_t n, uint32_t k, 31 | uint32_t loc, uint32_t t, 32 | const SNP &snp, 33 | SNPSamplingE &pop, 34 | TSQueue &out_q, 35 | TSQueue &in_q, 36 | CondMutex &cm) 37 | : _env(env), _r(r), _iter(iter), _x(x), 38 | _prev_iter(0), 39 | _prev_x(0), 40 | _prev_hol_mode(false), 41 | _n(n), _k(k), _loc(loc), _t(t), 42 | _phidad(_n,_k), _phimom(_n,_k), 43 | _phinext(_k), _lambdat(_k,_t), 44 | _snp(snp), 45 | _pop(pop), 46 | _out_q(out_q), 47 | _in_q(in_q), 48 | _cm(cm), 49 | _oldilist(NULL), 50 | _idptr(NULL) 51 | { } 52 | ~PhiRunnerE() { if (_idptr) { delete _idptr; } } 53 | 54 | int do_work(); 55 | int process(const IndivsList &v); 56 | int init_process(const IndivsList &v); 57 | void reset(uint32_t loc); 58 | const Matrix& phimom() const { return _phimom; } 59 | const Matrix& phidad() const { return _phidad; } 60 | const Matrix& lambdat() const { return _lambdat; } 61 | uint32_t iter() const { return _iter; } 62 | 63 | void update_phis_all(); 64 | void update_phimom(uint32_t n); 65 | void update_phidad(uint32_t n); 66 | 67 | void update_gamma(const IndivsList &i); 68 | void update_lambda_t(const IndivsList &i); 69 | void estimate_theta(const IndivsList &i); 70 | void update_gamma(); 71 | void estimate_theta(); 72 | 73 | private: 74 | const Env &_env; 75 | gsl_rng **_r; 76 | const uint32_t &_iter; 77 | const uint32_t &_x; 78 | uint32_t _prev_iter; 79 | uint32_t _prev_x; 80 | bool _prev_hol_mode; 81 | 82 | uint32_t _n; 83 | uint32_t _k; 84 | uint32_t _loc; 85 | uint32_t _t; 86 | 87 | Matrix _phidad; 88 | Matrix _phimom; 89 | Array _phinext; 90 | Matrix _lambdat; 91 | 92 | const SNP &_snp; 93 | SNPSamplingE &_pop; 94 | 95 | TSQueue &_out_q; 96 | TSQueue &_in_q; 97 | CondMutex &_cm; 98 | IndivsList *_oldilist; 99 | pthread_t *_idptr; 100 | }; 101 | typedef std::map ThreadMapE; 102 | 103 | class SNPSamplingE { 104 | public: 105 | SNPSamplingE(Env &env, SNP &snp); 106 | ~SNPSamplingE(); 107 | 108 | void infer(); 109 | bool kv_ok(uint32_t indiv, uint32_t loc) const; 110 | void load_model(string betafile = "", string thetafile = ""); 111 | void snp_likelihood(uint32_t loc, uint32_t n, Array &p); 112 | bool hol_mode() const { return _hol_mode; } 113 | 114 | const uArray& shuffled_nodes() const { return _shuffled_nodes; } 115 | 116 | const Matrix &Elogtheta() const { return _Elogtheta; } 117 | const D3 &Elogbeta() const { return _Elogbeta; } 118 | const vector &indivs() const { return _indivs; } 119 | const uint32_t sampled_loc() const { return _loc; } 120 | 121 | const Matrix &gamma() const { return _gamma; } 122 | const D3 &lambda() const { return _lambda; } 123 | 124 | Matrix &gamma() { return _gamma; } 125 | D3 &lambda() { return _lambda; } 126 | Matrix &Etheta() { return _Etheta; } 127 | Matrix &Elogtheta() { return _Elogtheta; } 128 | 129 | void update_rho_indiv(uint32_t n); 130 | const double alpha(uint32_t k) const { return _alpha[k]; } 131 | //const double rho_indiv() const { return _rho_indiv; } 132 | const double rho_indiv(uint32_t n) const { return _rho_indiv[n]; } 133 | 134 | private: 135 | void init_heldout_sets(); 136 | void set_test_sample(); 137 | void set_validation_sample(); 138 | void set_validation_sample2(); 139 | void infer_init_phase(); 140 | 141 | void update_phis_until_conv(uint32_t loc); 142 | void update_lambda(uint32_t loc); 143 | void update_phimom(uint32_t n, uint32_t loc); 144 | void update_phidad(uint32_t n, uint32_t loc); 145 | void optimize_lambda(uint32_t loc); 146 | 147 | void estimate_beta(uint32_t loc); 148 | double logl(); 149 | 150 | void compute_all_lambda(); 151 | void compute_and_save_beta(); 152 | void save_beta(); 153 | void save_beta(const vector &locs); 154 | void save_gamma(); 155 | void save_model(); 156 | void load_gamma(); 157 | void compute_lambda(); 158 | void estimate_all_beta(); 159 | 160 | int start_threads(); 161 | void split_all_indivs(); 162 | double compute_likelihood(bool first, bool validation); 163 | 164 | void init_gamma(); 165 | void init_lambda(); 166 | 167 | void update_gamma(); 168 | void update_lambda(); 169 | 170 | void get_subsample(); 171 | void get_subsample_nonuniform(); 172 | uint32_t duration() const; 173 | 174 | void estimate_beta(); 175 | 176 | double approx_log_likelihood(); 177 | double logcoeff(yval_t x); 178 | 179 | double snp_likelihood(uint32_t loc, vector &indiv, bool first = false); 180 | void estimate_pi(uint32_t p, Array &pi_p) const; 181 | void shuffle_nodes(); 182 | 183 | void estimate_theta(uint32_t n, Array &theta) const; 184 | void estimate_all_theta(); 185 | string add_iter_suffix(const char *c); 186 | 187 | Env &_env; 188 | SNP &_snp; 189 | 190 | SNPMap _test_map; 191 | SNPMap _validation_map; 192 | 193 | uint64_t _n; 194 | uint32_t _k; 195 | uint64_t _l; 196 | uint32_t _t; 197 | uint32_t _nthreads; 198 | 199 | uint32_t _iter; 200 | uint32_t _x; 201 | Array _alpha; 202 | uint32_t _loc; 203 | 204 | Matrix _eta; 205 | 206 | vector _heldout_loc; 207 | vector _validation_loc; 208 | gsl_rng *_r; 209 | 210 | Matrix _gamma; 211 | D3 _lambda; 212 | Matrix _lambdat; 213 | 214 | double _tau0; 215 | double _kappa; 216 | double _nodetau0; 217 | double _nodekappa; 218 | 219 | Array _rho_indiv; 220 | uArray _c_indiv; 221 | 222 | double _rhot; 223 | double _noderhot; 224 | uint32_t _nodec; 225 | Array _nodeupdatec; 226 | 227 | time_t _start_time; 228 | struct timeval _last_iter; 229 | FILE *_lf; 230 | 231 | Matrix _Elogtheta; 232 | D3 _Elogbeta; 233 | Matrix _Etheta; 234 | Matrix _Ebeta; 235 | 236 | FILE *_vf; 237 | FILE *_tf; 238 | FILE *_trf; 239 | FILE *_hef; 240 | FILE *_vef; 241 | FILE *_tef; 242 | 243 | uArray _shuffled_nodes; 244 | vector _indivs; 245 | 246 | double _max_t, _max_h, _max_v, _prev_h, _prev_w, _prev_t; 247 | mutable uint32_t _nh, _nt; 248 | uint32_t _sampled_loc; 249 | uint64_t _total_locations; 250 | 251 | TSQueue _out_q; 252 | TSQueue _in_q; 253 | CondMutex _cm; 254 | ThreadMapE _thread_map; 255 | ChunkMap _chunk_map; 256 | BoolMap64 _cthreads; 257 | bool _hol_mode; 258 | 259 | Matrix _phimom; 260 | Matrix _phidad; 261 | Array _phinext; 262 | Matrix _lambdaold; 263 | Matrix _v; 264 | }; 265 | 266 | inline void 267 | PhiRunnerE::reset(uint32_t loc) 268 | { 269 | _lambdat.zero(); 270 | _loc = loc; 271 | _prev_iter = _iter; 272 | _prev_hol_mode = _pop.hol_mode(); 273 | _prev_x = 0; 274 | } 275 | 276 | inline void 277 | PhiRunnerE::update_phimom(uint32_t n) 278 | { 279 | //_phinext.zero(); 280 | const double ** const elogthetad = _pop.Elogtheta().const_data(); 281 | const double *** const elogbetad = _pop.Elogbeta().const_data(); 282 | for (uint32_t k = 0; k < _k; ++k) 283 | _phinext[k] = elogthetad[n][k] + elogbetad[_loc][k][0]; 284 | _phinext.lognormalize(); 285 | _phimom.set_elements(n, _phinext); 286 | debug("n = %d, phimom = %s", n, _phinext.s().c_str()); 287 | } 288 | 289 | inline void 290 | PhiRunnerE::update_phidad(uint32_t n) 291 | { 292 | //_phinext.zero(); 293 | const double ** const elogthetad = _pop.Elogtheta().const_data(); 294 | const double *** const elogbetad = _pop.Elogbeta().const_data(); 295 | for (uint32_t k = 0; k < _k; ++k) 296 | _phinext[k] = elogthetad[n][k] + elogbetad[_loc][k][1]; 297 | _phinext.lognormalize(); 298 | _phidad.set_elements(n, _phinext); 299 | debug("n = %d, phidad = %s", n, _phinext.s().c_str()); 300 | } 301 | 302 | inline void 303 | PhiRunnerE::update_phis_all() 304 | { 305 | double u = 1./_k; 306 | _phimom.set_elements(u); 307 | _phidad.set_elements(u); 308 | 309 | for (uint32_t i = 0; i < _n; ++i) { 310 | update_phimom(i); 311 | update_phidad(i); 312 | } 313 | } 314 | 315 | inline uint32_t 316 | SNPSamplingE::duration() const 317 | { 318 | time_t t = time(0); 319 | return t - _start_time; 320 | } 321 | 322 | inline double 323 | SNPSamplingE::snp_likelihood(uint32_t loc, vector &indivs, bool first) 324 | { 325 | D1Array a(_n); 326 | _snp.y().slice(1, loc, a); 327 | 328 | if (first) 329 | estimate_beta(loc); 330 | else { 331 | _loc = loc; 332 | optimize_lambda(loc); 333 | _iter++; 334 | } 335 | 336 | const double ** const thetad = _Etheta.const_data(); 337 | const double ** const betad = _Ebeta.const_data(); 338 | const yval_t ** const snpd = _snp.y().const_data(); 339 | double lsum = .0; 340 | for (uint32_t i = 0; i < indivs.size(); ++i) { 341 | uint32_t n = indivs[i]; 342 | assert (!_snp.is_missing(n, loc)); 343 | 344 | double sum = .0; 345 | 346 | yval_t x = snpd[n][loc]; 347 | double q = .0; 348 | double v = gsl_sf_fact(2) / 349 | (gsl_sf_fact(x) * gsl_sf_fact(2 - x)); 350 | 351 | for (uint32_t k = 0; k < _k; ++k) 352 | q += betad[loc][k] * thetad[n][k]; 353 | 354 | sum = v * pow(q, x) * pow(1 - q, 2 - x); 355 | if (sum < 1e-30) 356 | sum = 1e-30; 357 | lsum += log(sum); 358 | } 359 | tst("logsum=%.5f\t%.5f\n", lsum / indivs.size(), exp(lsum / indivs.size())); 360 | return lsum; 361 | } 362 | 363 | inline void 364 | SNPSamplingE::snp_likelihood(uint32_t loc, uint32_t n, Array &p) 365 | { 366 | assert (p.n() == 3); 367 | assert (loc < _l); 368 | assert (n < _n); 369 | 370 | const double ** const thetad = _Etheta.const_data(); 371 | const double ** const betad = _Ebeta.const_data(); 372 | 373 | assert (!_snp.is_missing(n, loc)); 374 | 375 | for (uint32_t x = 0; x < 3; ++x) { 376 | double q = .0; 377 | double v = gsl_sf_fact(2) / 378 | (gsl_sf_fact(x) * gsl_sf_fact(2 - x)); 379 | 380 | for (uint32_t k = 0; k < _k; ++k) 381 | q += betad[loc][k] * thetad[n][k]; 382 | 383 | double m = v * pow(q, x) * pow(1 - q, 2 - x); 384 | p[x] = m; 385 | } 386 | return; 387 | } 388 | 389 | inline bool 390 | SNPSamplingE::kv_ok(uint32_t indiv, uint32_t loc) const 391 | { 392 | assert (indiv < _n && loc < _l); 393 | 394 | KV kv(indiv, loc); 395 | 396 | const SNPMap::const_iterator u = _test_map.find(kv); 397 | if (u != _test_map.end()) 398 | return false; 399 | 400 | const SNPMap::const_iterator w = _validation_map.find(kv); 401 | if (w != _validation_map.end()) 402 | return false; 403 | 404 | if (_snp.is_missing(indiv, loc)) 405 | return false; 406 | 407 | return true; 408 | } 409 | 410 | inline double 411 | SNPSamplingE::logcoeff(yval_t x) { 412 | uint32_t c = 2; 413 | return log(gsl_sf_fact(c)) - log(gsl_sf_fact(x) * gsl_sf_fact(c - x)); 414 | } 415 | 416 | inline int 417 | PhiRunnerE::process(const IndivsList &v) 418 | { 419 | double u = 1./_k; 420 | for (uint32_t i = 0; i < v.size(); ++i) { 421 | uint32_t n = v[i]; 422 | if (!_pop.kv_ok(n, _loc)) 423 | continue; 424 | 425 | _phimom.set_elements(n, u); 426 | _phidad.set_elements(n, u); 427 | update_phimom(n); 428 | update_phidad(n); 429 | } 430 | update_lambda_t(v); 431 | } 432 | 433 | inline void 434 | PhiRunnerE::update_gamma() 435 | { 436 | update_gamma(*_oldilist); 437 | } 438 | 439 | inline void 440 | PhiRunnerE::estimate_theta() 441 | { 442 | estimate_theta(*_oldilist); 443 | } 444 | 445 | 446 | 447 | #endif 448 | -------------------------------------------------------------------------------- /src/thread.cc: -------------------------------------------------------------------------------- 1 | #include "thread.hh" 2 | #include 3 | #include 4 | 5 | pthread_mutex_t Thread::_file_mutex; 6 | 7 | void 8 | Thread::static_initialize() 9 | { 10 | pthread_mutex_init(&_file_mutex, NULL); 11 | } 12 | 13 | void 14 | Thread::static_uninitialize() 15 | { 16 | pthread_mutex_destroy(&_file_mutex); 17 | } 18 | 19 | Thread::Thread() 20 | { 21 | } 22 | 23 | Thread::~Thread() 24 | { 25 | } 26 | 27 | int 28 | Thread::create() 29 | { 30 | pthread_attr_init(&_attr); 31 | pthread_attr_setdetachstate(&_attr, PTHREAD_CREATE_JOINABLE); 32 | int r; 33 | if ((r = pthread_create(&_tid, &_attr, run, (void *)this)) != 0) 34 | return -1; 35 | return 0; 36 | } 37 | 38 | int 39 | Thread::join() 40 | { 41 | void *status; 42 | pthread_attr_destroy(&_attr); 43 | if (pthread_join(_tid, &status) != 0) 44 | return -1; 45 | return 0; 46 | } 47 | 48 | void * 49 | Thread::run(void *obj) // static method 50 | { 51 | Thread *t = reinterpret_cast(obj); 52 | t->do_work(); 53 | pthread_exit(NULL); 54 | } 55 | -------------------------------------------------------------------------------- /src/thread.hh: -------------------------------------------------------------------------------- 1 | #ifndef THREAD_HH 2 | #define THREAD_HH 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class Thread { 13 | public: 14 | Thread(); 15 | virtual ~Thread(); 16 | 17 | int create(); 18 | int join(); 19 | pthread_t id() const { return _tid; } 20 | 21 | virtual int do_work() { return 0; } 22 | 23 | static void static_initialize(); 24 | static void static_uninitialize(); 25 | 26 | protected: 27 | static void *run(void *); 28 | 29 | bool _done; 30 | pthread_t _tid; 31 | pthread_attr_t _attr; 32 | static pthread_mutex_t _file_mutex; 33 | }; 34 | 35 | class Mutex { 36 | public: 37 | Mutex(); 38 | ~Mutex(); 39 | 40 | int lock(); 41 | int unlock(); 42 | int try_lock(); 43 | 44 | private: 45 | pthread_mutex_t _mutex; 46 | pthread_t _owner; 47 | 48 | Mutex &operator=(const Mutex &); 49 | Mutex(const Mutex &); 50 | 51 | friend class CondMutex; 52 | }; 53 | 54 | inline 55 | Mutex::Mutex() 56 | { 57 | pthread_mutex_init(&_mutex, 0); 58 | } 59 | 60 | inline 61 | Mutex::~Mutex() 62 | { 63 | pthread_mutex_destroy(&_mutex); 64 | } 65 | 66 | inline int 67 | Mutex::lock() 68 | { 69 | int r = pthread_mutex_lock(&_mutex); 70 | return r; 71 | } 72 | 73 | inline int 74 | Mutex::try_lock() 75 | { 76 | int r = pthread_mutex_trylock(&_mutex); 77 | return r; 78 | } 79 | 80 | inline int 81 | Mutex::unlock() 82 | { 83 | return pthread_mutex_unlock(&_mutex); 84 | } 85 | 86 | class CondMutex { 87 | public: 88 | CondMutex(); 89 | ~CondMutex(); 90 | 91 | int wait(); 92 | int signal(); 93 | int broadcast(); 94 | int lock() { return _mutex.lock(); } 95 | int unlock() { return _mutex.unlock(); } 96 | 97 | private: 98 | pthread_cond_t _cond; 99 | Mutex _mutex; 100 | 101 | CondMutex &operator=(const CondMutex &); 102 | CondMutex(const CondMutex &); 103 | }; 104 | 105 | inline CondMutex::CondMutex() 106 | { 107 | pthread_cond_init(&_cond, NULL); 108 | } 109 | 110 | inline CondMutex::~CondMutex() 111 | { 112 | pthread_cond_destroy(&_cond); 113 | } 114 | 115 | inline int 116 | CondMutex::wait() 117 | { 118 | return pthread_cond_wait(&_cond, &_mutex._mutex); 119 | } 120 | 121 | inline int 122 | CondMutex::signal() 123 | { 124 | return pthread_cond_signal(&_cond); 125 | } 126 | 127 | inline int 128 | CondMutex::broadcast() 129 | { 130 | return pthread_cond_broadcast(&_cond); 131 | } 132 | #endif 133 | -------------------------------------------------------------------------------- /src/tsqueue.hh: -------------------------------------------------------------------------------- 1 | #ifndef TSQUEUE_HH 2 | #define TSQUEUE_HH 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | template 9 | class TSQueue : public std::queue 10 | { 11 | typedef std::queue Queue; 12 | 13 | public: 14 | TSQueue() { } 15 | ~TSQueue() { } 16 | 17 | void push(T *); 18 | T *pop(); 19 | T * top(); 20 | void clear(); 21 | 22 | private: 23 | mutable CondMutex _cm; 24 | }; 25 | 26 | template inline void 27 | TSQueue::push(T *el) 28 | { 29 | _cm.lock(); 30 | Queue::push(el); 31 | _cm.signal(); 32 | _cm.unlock(); 33 | } 34 | 35 | template inline T * 36 | TSQueue::pop() 37 | { 38 | T *result; 39 | for (;;) { 40 | _cm.lock(); 41 | while (Queue::empty()) 42 | _cm.wait(); 43 | if (!Queue::empty()) { 44 | result = Queue::front(); 45 | Queue::pop(); 46 | _cm.unlock(); 47 | return result; 48 | } else 49 | _cm.unlock(); 50 | } 51 | return NULL; 52 | } 53 | 54 | template inline void 55 | TSQueue::clear() 56 | { 57 | _cm.lock(); 58 | while (!Queue::empty()) 59 | Queue::pop(); 60 | _cm.unlock(); 61 | } 62 | 63 | #endif 64 | --------------------------------------------------------------------------------