[med-svn] [stacks] 03/06: Imported Upstream version 1.37
Andreas Tille
tille at debian.org
Thu Mar 10 22:44:54 UTC 2016
This is an automated email from the git hooks/post-receive script.
tille pushed a commit to branch master
in repository stacks.
commit 1574dea36edce85a373af9df981245d35d1d8deb
Author: Andreas Tille <tille at debian.org>
Date: Thu Mar 10 23:30:35 2016 +0100
Imported Upstream version 1.37
---
ChangeLog | 18 ++
Makefile.am | 2 +-
Makefile.in | 2 +-
README | 34 ++--
configure | 20 +--
configure.ac | 2 +-
php/CatalogClass.php | 150 +++++++++-------
php/annotate_marker.php | 45 +++--
php/catalog.php | 230 ++++++++++++++----------
php/catalog_genotypes.php | 31 ++--
php/correct_genotype.php | 51 +++---
php/correct_genotypes.php | 71 +++++---
php/db_functions.php | 44 ++---
php/export_batch.php | 6 +-
php/fst_view.php | 104 ++++++-----
php/hapstat_view.php | 48 ++---
php/header.php | 3 +-
php/index.php | 13 +-
php/last_modified.php | 2 +-
php/phist_view.php | 50 +++---
php/pop_view.php | 193 +++++++++++---------
php/population_view.js | 3 +
php/samples.php | 70 +++++---
php/sequence_blast.php | 28 +--
php/stack_view.php | 49 +++--
php/stacks.css | 5 +
php/stacks_functions.php | 1 +
php/sumstat_view.php | 134 +++++++-------
php/tag.php | 368 ++++++++++++++++++++++++++++++++++++++
php/tags.php | 132 +++++++++-----
php/view_sequence.php | 15 +-
scripts/convert_stacks.pl | 0
scripts/denovo_map.pl | 65 ++++---
scripts/exec_velvet.pl | 0
scripts/export_sql.pl | 0
scripts/extract_interpop_chars.pl | 0
scripts/index_radtags.pl | 0
scripts/load_radtags.pl | 0
scripts/load_sequences.pl | 0
scripts/ref_map.pl | 62 ++++---
scripts/sort_read_pairs.pl | 0
scripts/stacks_export_notify.pl | 0
src/BamI.h | 35 ++--
src/FastaI.h | 6 +-
src/catalog_utils.cc | 2 +-
src/clone_filter.cc | 317 ++++++++++++++++----------------
src/file_io.cc | 23 +++
src/file_io.h | 43 ++---
src/gzFasta.h | 8 +-
src/pstacks.cc | 1 +
src/renz.h | 22 ++-
src/sstacks.cc | 35 +++-
src/sstacks.h | 2 +-
src/ustacks.cc | 1 +
54 files changed, 1648 insertions(+), 898 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5e3cc89..dbd196d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+Stacks 1.37 - Feb 24, 2016
+--------------------------
+ Feature: converted PHP database code from MDB2 to MySQLi. MDB2 is no longer a
+ prerequisite for installing Stacks.
+
+Stacks 1.36 - Feb 18, 2016
+--------------------------
+ Feature: Added the BfaI, BspDI, AseI, and AciI restriction enzymes to process_radtags.
+ Feature: Changed the way denovo_map.pl and ref_map.pl run sstacks. It is now set to run
+ sstacks once for all samples, instead of one time per sample. Should provide a significant
+ speed-up.
+ Bugfix: corrected error in pstacks when handling long reads with complex SAM/BAM alignments.
+ Bugfix: fixed memory leak in sstacks when more than one sample file was specified.
+ Bugfix: corrected error in clone_filter causing it to fail when processing gzipped data
+ without a random oligo attached.
+ Bugfix: corrected error when reading gzipped FASTA files and the last sequence of the file
+ was improperly doubled in length.
+
Stacks 1.35 - Sept 09, 2015
---------------------------
Feature: Added --retain_header flag to process_radtags/process_shortreads which will keep
diff --git a/Makefile.am b/Makefile.am
index 3756218..f3f958e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -142,7 +142,7 @@ dist_bin_SCRIPTS = scripts/denovo_map.pl scripts/ref_map.pl scripts/export_sql.p
dist_noinst_SCRIPTS = autogen.sh scripts/extract_interpop_chars.pl scripts/convert_stacks.pl
nobase_pkgdata_DATA = sql/mysql.cnf.dist sql/catalog_index.sql sql/stacks.sql sql/tag_index.sql sql/chr_index.sql \
- php/CatalogClass.php php/annotate_marker.php php/constants.php.dist php/index.php php/tags.php \
+ php/CatalogClass.php php/annotate_marker.php php/constants.php.dist php/index.php php/tags.php php/tag.php \
php/Locus.php php/catalog.php php/correct_genotypes.php php/correct_genotype.php php/export_batch.php php/last_modified.php \
php/version.php php/catalog_genotypes.php php/db_functions.php php/header.php php/samples.php \
php/stacks_functions.php php/view_sequence.php php/sequence_blast.php \
diff --git a/Makefile.in b/Makefile.in
index 79bdcb0..b585d3d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -791,7 +791,7 @@ dist_bin_SCRIPTS = scripts/denovo_map.pl scripts/ref_map.pl scripts/export_sql.p
dist_noinst_SCRIPTS = autogen.sh scripts/extract_interpop_chars.pl scripts/convert_stacks.pl
nobase_pkgdata_DATA = sql/mysql.cnf.dist sql/catalog_index.sql sql/stacks.sql sql/tag_index.sql sql/chr_index.sql \
- php/CatalogClass.php php/annotate_marker.php php/constants.php.dist php/index.php php/tags.php \
+ php/CatalogClass.php php/annotate_marker.php php/constants.php.dist php/index.php php/tags.php php/tag.php \
php/Locus.php php/catalog.php php/correct_genotypes.php php/correct_genotype.php php/export_batch.php php/last_modified.php \
php/version.php php/catalog_genotypes.php php/db_functions.php php/header.php php/samples.php \
php/stacks_functions.php php/view_sequence.php php/sequence_blast.php \
diff --git a/README b/README
index afa3d43..6ac640c 100644
--- a/README
+++ b/README
@@ -46,8 +46,8 @@ package manager. If you are using Ubuntu, you can install the following packages
% sudo apt-get install samtools
% sudo apt-get install libbam-dev
-A similar set of commands can be executed on a RedHat derived Linux system using yum,
-or another package manager on other Linux distributions.
+A similar set of commands can be executed on Debian using apt-get, or on a RedHat derived Linux
+system using yum, or another package manager on other Linux distributions.
2. Build the software. Stacks uses the standard autotools install:
@@ -106,27 +106,27 @@ The Stacks Web Interface
To visualize data, Stacks uses a web-based interface (written in PHP) that interacts
with a MySQL database server. MySQL provides various functions to store, sort, and
-export data from a database. For this to work, you must have a PHP-enabled Apache web
-server installed as well as the MDB2 Pear module to provide MySQL interaction.
+export data from a database.
0. Prerequisites
-If you want to export data in Microsoft Excel Spreadsheets, you will need the
-Spreadsheet::WriteExcel Perl module.
+Most server installations will provide Apache, MySQL, Perl, and PHP by default. If you want
+to export data in Microsoft Excel Spreadsheets, you will need the
+Spreadsheet::WriteExcel Perl module. While installing these components is beyond these
+instructions, here are some links that might be useful:
-Most server installations will provide Apache, MySQL, Perl, and PHP by default. While
-installing these components is beyond these instructions, here are some links that might
-be useful:
+ 1. MySQL Database: http://dev.mysql.com/downloads/mysql/
+ 2. Spreadsheet Perl Module: http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.40/
- 1. MySQL Database: http://www.mysql.com/downloads/mysql/
- 2. Spreadsheet Perl Module: http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.37/
- 3. MDB2 Pear Module: http://pear.php.net/package/MDB2/
- 4. MDB2 MySQL driver: http://pear.php.net/package/MDB2_Driver_mysql/
+If you are running a version of Linux, the above software can be installed via the
+package manager. If you are using Ubuntu, you can install the following packages:
+
+% sudo apt-get install mysql-server mysql-client
+% sudo apt-get install php5 php5-mysqlnd
+% sudo apt-get install libspreadsheet-writeexcel-perl
-(PHP modules are easily installed with the pear tool. Many operating systems already
- have these tools installed - such as OS X and some Linux distributions. Most Linux systems
- will provide all of these tools as packages that can be installed using yum, apt-get, or a
- similar piece of software.)
+A similar set of commands can be executed on Debian using apt-get, or on a RedHat derived Linux
+system using yum, or another package manager on other Linux distributions.
1. Edit the MySQL configuration file, installed in
/usr/local/share/stacks/sql/mysql.cnf.dist, to enable access to the
diff --git a/configure b/configure
index b91af92..58fc063 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for Stacks 1.35.
+# Generated by GNU Autoconf 2.69 for Stacks 1.37.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@ -577,8 +577,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='Stacks'
PACKAGE_TARNAME='stacks'
-PACKAGE_VERSION='1.35'
-PACKAGE_STRING='Stacks 1.35'
+PACKAGE_VERSION='1.37'
+PACKAGE_STRING='Stacks 1.37'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''
@@ -1283,7 +1283,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures Stacks 1.35 to adapt to many kinds of systems.
+\`configure' configures Stacks 1.37 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1349,7 +1349,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of Stacks 1.35:";;
+ short | recursive ) echo "Configuration of Stacks 1.37:";;
esac
cat <<\_ACEOF
@@ -1456,7 +1456,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-Stacks configure 1.35
+Stacks configure 1.37
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1913,7 +1913,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by Stacks $as_me 1.35, which was
+It was created by Stacks $as_me 1.37, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@@ -2776,7 +2776,7 @@ fi
# Define the identity of the package.
PACKAGE='stacks'
- VERSION='1.35'
+ VERSION='1.37'
cat >>confdefs.h <<_ACEOF
@@ -6224,7 +6224,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by Stacks $as_me 1.35, which was
+This file was extended by Stacks $as_me 1.37, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -6290,7 +6290,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-Stacks config.status 1.35
+Stacks config.status 1.37
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
diff --git a/configure.ac b/configure.ac
index 9cce910..ba9ec98 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
-AC_INIT([Stacks], [1.35])
+AC_INIT([Stacks], [1.37])
AC_CONFIG_AUX_DIR([config])
AM_INIT_AUTOMAKE([-Wall -Werror foreign parallel-tests subdir-objects])
AC_CONFIG_SRCDIR([src/ustacks.cc])
diff --git a/php/CatalogClass.php b/php/CatalogClass.php
index c96a839..938a47d 100644
--- a/php/CatalogClass.php
+++ b/php/CatalogClass.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2010, Julian Catchen <jcatchen at uoregon.edu>
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -44,22 +44,22 @@ class Catalog {
$query =
"SELECT allele FROM catalog_alleles " .
"WHERE batch_id=? AND tag_id=?";
- $this->db['allele_sth'] = $this->db['dbh']->prepare($query);
- check_db_error($this->db['allele_sth'], __FILE__, __LINE__);
+ if (!($this->db['allele_sth'] = $this->db['dbh']->prepare($query)))
+ write_db_error($this->db['dbh'], __FILE__, __LINE__);
$query =
"SELECT col, rank_1, rank_2 FROM catalog_snps " .
"WHERE batch_id=? AND tag_id=? ORDER BY col";
- $this->db['snp_sth'] = $this->db['dbh']->prepare($query);
- check_db_error($this->db['snp_sth'], __FILE__, __LINE__);
+ if (!($this->db['snp_sth'] = $this->db['dbh']->prepare($query)))
+ write_db_error($this->db['dbh'], __FILE__, __LINE__);
$query =
"SELECT samples.id, samples.sample_id, samples.type, file, tag_id, allele " .
"FROM matches " .
"JOIN samples ON (matches.sample_id=samples.id) " .
"WHERE matches.batch_id=? AND catalog_id=? ORDER BY samples.id";
- $this->db['mat_sth'] = $this->db['dbh']->prepare($query);
- check_db_error($this->db['mat_sth'], __FILE__, __LINE__);
+ if (!($this->db['mat_sth'] = $this->db['dbh']->prepare($query)))
+ write_db_error($this->db['dbh'], __FILE__, __LINE__);
$query =
"SELECT COUNT(tag_id) as count FROM catalog_index " .
@@ -84,63 +84,65 @@ class Catalog {
}
function prepare_filter_parameters() {
- array_push($this->params, $this->batch);
+ $this->params[] = &$this->batch;
+ $typestr = "i";
$filters = $this->display['filter_type'];
- if (!isset($filters))
+ if (!isset($filters)) {
+ array_unshift($param, $typestr);
return;
+ }
foreach ($filters as $filter) {
if ($filter == "snps") {
- array_push($this->params, $this->display['filter_snps_l']);
- array_push($this->params, $this->display['filter_snps_u']);
+ $this->params[] = &$this->display['filter_snps_l'];
+ $this->params[] = &$this->display['filter_snps_u'];
+ $typestr .= "ii";
} else if ($filter == "alle") {
- array_push($this->params, $this->display['filter_alle_l']);
- array_push($this->params, $this->display['filter_alle_u']);
+ $this->params[] = &$this->display['filter_alle_l'];
+ $this->params[] = &$this->display['filter_alle_u'];
+ $typestr .= "ii";
} else if ($filter == "pare") {
- array_push($this->params, $this->display['filter_pare_l']);
- array_push($this->params, $this->display['filter_pare_u']);
-
+ $this->params[] = &$this->display['filter_pare_l'];
+ $this->params[] = &$this->display['filter_pare_u'];
+ $typestr .= "ii";
+
} else if ($filter == "prog") {
- array_push($this->params, $this->display['filter_prog']);
+ $this->params[] = &$this->display['filter_prog'];
+ $typestr .= "i";
} else if ($filter == "vprog") {
- array_push($this->params, $this->display['filter_vprog']);
+ $this->params[] = &$this->display['filter_vprog'];
+ $typestr .= "i";
} else if ($filter == "cata") {
- array_push($this->params, $this->display['filter_cata']);
+ $this->params[] = &$this->display['filter_cata'];
+ $typestr .= "i";
} else if ($filter == "gcnt") {
- array_push($this->params, $this->display['filter_gcnt']);
-
- } else if ($filter == "est") {
- array_push($this->params, 0);
-
- } else if ($filter == "pe") {
- array_push($this->params, 0);
-
- } else if ($filter == "blast") {
- array_push($this->params, 0);
+ $this->params[] = &$this->display['filter_gcnt'];
+ $typestr .= "i";
} else if ($filter == "ref") {
- array_push($this->params, $this->display['filter_ref']);
-
+ $this->params[] = &$this->display['filter_ref'];
+ $typestr .= "i";
+
} else if ($filter == "loc") {
- array_push($this->params, $this->display['filter_chr']);
- array_push($this->params, $this->display['filter_sbp'] * 1000000);
- array_push($this->params, $this->display['filter_ebp'] * 1000000);
+ $this->params[] = &$this->display['filter_chr'];
+ $this->params[] = &$this->display['filter_sbp'];
+ $this->params[] = &$this->display['filter_ebp'];
+ $typestr .= "sii";
} else if ($filter == "mark") {
- if ($this->display['filter_mark'] == "Any")
- array_push($this->params, "%/%");
- else
- array_push($this->params, $this->display['filter_mark']);
+ $this->params[] = &$this->display['filter_mark'];
}
}
+
+ array_unshift($this->params, $typestr);
}
function apply_query_filters() {
@@ -152,9 +154,9 @@ class Catalog {
"prog" => "(progeny >= ?)",
"vprog" => "(valid_progeny >= ?)",
"mark" => "(marker LIKE ?)",
- "est" => "(ests > ?)",
- "pe" => "(pe_radtags > ?)",
- "blast" => "(blast_hits > ?)",
+ "est" => "(ests > 0)",
+ "pe" => "(pe_radtags > 0)",
+ "blast" => "(blast_hits > 0)",
"gcnt" => "(geno_cnt >= ?)",
"ref" => "(catalog_index.type = ?)",
"loc" => "(catalog_index.chr = ? && catalog_index.bp >= ? && catalog_index.bp <= ?)");
@@ -188,15 +190,19 @@ class Catalog {
function determine_count() {
- $this->db['tag_count_sth'] = $this->db['dbh']->prepare($this->queries['tag_count']);
- check_db_error($this->db['tag_count_sth'], __FILE__, __LINE__);
+ if (!($this->db['tag_count_sth'] = $this->db['dbh']->prepare($this->queries['tag_count'])))
+ write_db_error($this->db['dbh'], __FILE__, __LINE__);
$this->prepare_filter_parameters();
- $result =& $this->db['tag_count_sth']->execute($this->params);
- check_db_error($result, __FILE__, __LINE__);
-
- $row = $result->fetchRow();
+ array_unshift($this->params, $this->db['tag_count_sth']);
+ call_user_func_array("mysqli_stmt_bind_param", $this->params);
+ array_shift($this->params);
+ if (!$this->db['tag_count_sth']->execute())
+ write_db_error($this->db['tag_count_sth'], __FILE__, __LINE__);
+ $res = $this->db['tag_count_sth']->get_result();
+
+ $row = $res->fetch_assoc();
$this->num_loci = $row['count'];
}
@@ -204,21 +210,24 @@ class Catalog {
//
// We only want to load genes between $start_gene and $end_gene.
//
- $this->db['dbh']->setLimit($num_groups, $start_group);
- check_db_error($this->db['dbh'], __FILE__, __LINE__);
-
- $this->db['tag_sth'] = $this->db['dbh']->prepare($this->queries['tag']);
- check_db_error($this->db['tag_sth'], __FILE__, __LINE__);
+ $this->queries['tag'] .= " LIMIT " . $start_group . ", " . $num_groups;
+
+ if (!($this->db['tag_sth'] = $this->db['dbh']->prepare($this->queries['tag'])))
+ write_db_error($this->db['dbh'], __FILE__, __LINE__);
$this->prepare_filter_parameters();
//
// Fetch the results and populate the array of groups.
//
- $result = $this->db['tag_sth']->execute($this->params);
- check_db_error($result, __FILE__, __LINE__);
-
- while ($row = $result->fetchRow()) {
+ array_unshift($this->params, $this->db['tag_sth']);
+ call_user_func_array("mysqli_stmt_bind_param", $this->params);
+ array_shift($this->params);
+ if (!$this->db['tag_sth']->execute())
+ write_db_error($this->db['tag_sth'], __FILE__, __LINE__);
+ $res = $this->db['tag_sth']->get_result();
+
+ while ($row = $res->fetch_assoc()) {
$locus = new Locus();
$locus->id = $row['tag_id'];
$locus->annotation = $row['external_id'];
@@ -239,16 +248,24 @@ class Catalog {
//
// Fetch SNPs and Alleles
//
- $snp_res = $this->db['snp_sth']->execute(array($this->batch, $locus->id));
- check_db_error($snp_res, __FILE__, __LINE__);
- while ($snp_row = $snp_res->fetchRow()) {
+ if (!$this->db['snp_sth']->bind_param("ii", $this->batch, $locus->id))
+ write_db_error($db['snp_sth'], __FILE__, __LINE__);
+ if (!$this->db['snp_sth']->execute())
+ write_db_error($db['snp_sth'], __FILE__, __LINE__);
+ $snp_res = $this->db['snp_sth']->get_result();
+
+ while ($snp_row = $snp_res->fetch_assoc()) {
$locus->snps .= $snp_row['col'] . "," . $snp_row['rank_1'] . ">" . $snp_row['rank_2'] . ";";
}
$locus->snps = substr($locus->snps, 0, -1);
- $all_res = $this->db['allele_sth']->execute(array($this->batch, $locus->id));
- check_db_error($all_res, __FILE__, __LINE__);
- while ($all_row = $all_res->fetchRow()) {
+ if (!$this->db['all_sth']->bind_param("ii", $this->batch, $locus->id))
+ write_db_error($db['all_sth'], __FILE__, __LINE__);
+ if (!$this->db['all_sth']->execute())
+ write_db_error($db['all_sth'], __FILE__, __LINE__);
+ $all_res = $this->db['all_sth']->get_result();
+
+ while ($all_row = $all_res->fetch_assoc()) {
$locus->alleles .= $all_row['allele'] . ";";
}
$locus->alleles = substr($locus->alleles, 0, -1);
@@ -256,10 +273,13 @@ class Catalog {
//
// Add genotypes
//
- $gen_res = $this->db['mat_sth']->execute(array($this->batch, $locus->id));
- check_db_error($genres, __FILE__, __LINE__);
+ if (!$this->db['mat_sth']->bind_param("ii", $this->batch, $locus->id))
+ write_db_error($db['mat_sth'], __FILE__, __LINE__);
+ if (!$this->db['mat_sth']->execute())
+ write_db_error($db['mat_sth'], __FILE__, __LINE__);
+ $gen_res = $this->db['mat_sth']->get_result();
- while ($gen_row = $gen_res->fetchRow())
+ while ($gen_row = $gen_res->fetch_assoc())
$locus->add_genotype($gen_row['id'], $gen_row['file'], $gen_row['allele']);
$this->loci[$row['tag_id']] = $locus;
diff --git a/php/annotate_marker.php b/php/annotate_marker.php
index e41e8a7..cae337d 100644
--- a/php/annotate_marker.php
+++ b/php/annotate_marker.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2010, Julian Catchen <jcatchen at uoregon.edu>
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -42,34 +42,37 @@ $query =
"SELECT id, external_id " .
"FROM catalog_annotations " .
"WHERE batch_id=? and catalog_id=?";
-$db['sel_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['sel_sth'], __FILE__, __LINE__);
+if (!($db['sel_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"UPDATE catalog_annotations SET external_id=? WHERE id=?";
-$db['upd_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['upd_sth'], __FILE__, __LINE__);
+if (!($db['upd_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"INSERT INTO catalog_annotations SET batch_id=?, catalog_id=?, external_id=?";
-$db['ins_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['ins_sth'], __FILE__, __LINE__);
+if (!($db['ins_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"DELETE FROM catalog_annotations WHERE id=?";
-$db['del_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['del_sth'], __FILE__, __LINE__);
+if (!($db['del_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
//
// Fetch any existing annotation for this marker
//
-$result = $db['sel_sth']->execute(array($display['batch_id'], $display['tag_id']));
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['sel_sth']->bind_param("ii", $display['batch_id'], $display['tag_id']))
+ write_db_error($db['sel_sth'], __FILE__, __LINE__);
+if (!$db['sel_sth']->execute())
+ write_db_error($db['sel_sth'], __FILE__, __LINE__);
+$res = $db['sel_sth']->get_result();
$external_id = "";
$sql_id = 0;
-if ($row = $result->fetchRow()) {
+if ($row = $res->fetch_assoc()) {
$external_id = $row['external_id'];
$sql_id = $row['id'];
}
@@ -79,20 +82,26 @@ if ($external_id != $ext_id) {
// Is this annotation being reset to the original value? If so, delete the corrected record.
//
if (strlen($external_id) > 0 && strlen($ext_id) == 0) {
- $result = $db['del_sth']->execute($sql_id);
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['del_sth']->bind_param("i", $sql_id))
+ write_db_error($db['del_sth'], __FILE__, __LINE__);
+ if (!$db['del_sth']->execute())
+ write_db_error($db['del_sth'], __FILE__, __LINE__);
//
// Are we changing an existing annotation?
//
} else if (strlen($external_id) > 0 && strlen($ext_id) > 0) {
- $result = $db['upd_sth']->execute(array($ext_id, $sql_id));
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['upd_sth']->bind_param("si", $ext_id, $sql_id))
+ write_db_error($db['upd_sth'], __FILE__, __LINE__);
+ if (!$db['upd_sth']->execute())
+ write_db_error($db['upd_sth'], __FILE__, __LINE__);
//
// Otherwise, add a new annotation.
//
} else if (strlen($ext_id) > 0) {
- $result = $db['ins_sth']->execute(array($display['batch_id'], $display['tag_id'], $ext_id));
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['ins_sth']->bind_param("iis", $display['batch_id'], $display['tag_id'], $ext_id))
+ write_db_error($db['ins_sth'], __FILE__, __LINE__);
+ if (!$db['ins_sth']->execute())
+ write_db_error($db['ins_sth'], __FILE__, __LINE__);
}
}
diff --git a/php/catalog.php b/php/catalog.php
index 9926a8e..15abced 100644
--- a/php/catalog.php
+++ b/php/catalog.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2010-2015, Julian Catchen <jcatchen at illinois.edu>
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -38,7 +38,7 @@ $display['filter_type'] = array();
//
// Process the filtering parameters
//
-$param = array($batch_id);
+$param = array();
process_filter($display);
prepare_filter_parameters($display, $param);
@@ -48,45 +48,47 @@ prepare_filter_parameters($display, $param);
$query =
"SELECT batches.id as id, date, description, type FROM batches " .
"WHERE batches.id=?";
-$db['batch_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['batch_sth'], __FILE__, __LINE__);
+if (!($db['batch_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT COUNT(tag_id) as count FROM catalog_index " .
"WHERE batch_id=?";
$query .= apply_query_filters($display);
-$db['count_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['count_sth'], __FILE__, __LINE__);
+if (!($db['count_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT alleles as count FROM catalog_index " .
"WHERE batch_id=? AND tag_id=?";
-$db['allele_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['allele_sth'], __FILE__, __LINE__);
+if (!($db['allele_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT col, rank_2 FROM catalog_snps " .
"JOIN batches ON (catalog_snps.batch_id=batches.id) " .
"WHERE batch_id=? AND tag_id=? ORDER BY col";
-$db['snp_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['snp_sth'], __FILE__, __LINE__);
+if (!($db['snp_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT chr, max_len FROM chr_index " .
"WHERE batch_id=?";
-$db['chrs_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['chrs_sth'], __FILE__, __LINE__);
+if (!($db['chrs_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT max(ests) as ests, max(pe_radtags) as pe_radtags, max(blast_hits) as blast_hits " .
"FROM catalog_index WHERE batch_id=?";
-$db['seq_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['seq_sth'], __FILE__, __LINE__);
-
-$result = $db['seq_sth']->execute($batch_id);
-check_db_error($result, __FILE__, __LINE__);
-$row = $result->fetchRow();
+if (!($db['seq_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
+if (!$db['seq_sth']->bind_param("i", $batch_id))
+ write_db_error($db['seq_sth'], __FILE__, __LINE__);
+if (!$db['seq_sth']->execute())
+ write_db_error($db['seq_sth'], __FILE__, __LINE__);
+$res = $db['seq_sth']->get_result();
+$row = $res->fetch_assoc();
$cols = array();
@@ -99,12 +101,15 @@ else
$query =
"SELECT count(id) as cnt FROM catalog_genotypes WHERE batch_id=?";
-$db['gcnt_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['gcnt_sth'], __FILE__, __LINE__);
+if (!($db['gcnt_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
-$result = $db['gcnt_sth']->execute($batch_id);
-check_db_error($result, __FILE__, __LINE__);
-$row = $result->fetchRow();
+if (!$db['gcnt_sth']->bind_param("i", $batch_id))
+ write_db_error($db['gcnt_sth'], __FILE__, __LINE__);
+if (!$db['gcnt_sth']->execute())
+ write_db_error($db['gcnt_sth'], __FILE__, __LINE__);
+$res = $db['gcnt_sth']->get_result();
+$row = $res->fetch_assoc();
if ($row['cnt'] > 0)
$cols['gcnt'] = true;
@@ -114,9 +119,13 @@ else
//
// Pull information about this batch
//
-$result = $db['batch_sth']->execute($batch_id);
-check_db_error($result, __FILE__, __LINE__);
-$row = $result->fetchRow();
+if (!$db['batch_sth']->bind_param("i", $batch_id))
+ write_db_error($db['batch_sth'], __FILE__, __LINE__);
+if (!$db['batch_sth']->execute())
+ write_db_error($db['batch_sth'], __FILE__, __LINE__);
+$res = $db['batch_sth']->get_result();
+$row = $res->fetch_assoc();
+
$batch = array();
$batch['id'] = $row['id'];
$batch['desc'] = $row['description'];
@@ -229,9 +238,14 @@ EOQ;
// Figure out how many results there are (including filtering)
// and write out the proper pagination links
//
-$result = $db['count_sth']->execute($param);
-check_db_error($result, __FILE__, __LINE__);
-$row = $result->fetchRow();
+array_unshift($param, $db['count_sth']);
+call_user_func_array("mysqli_stmt_bind_param", $param);
+array_shift($param);
+if (!$db['count_sth']->execute())
+ write_db_error($db['count_sth'], __FILE__, __LINE__);
+$res = $db['count_sth']->get_result();
+$row = $res->fetch_assoc();
+
$pagination_count = $row['count'];
$start_group = 0;
$end_group = 0;
@@ -270,9 +284,6 @@ if ($cols['seq'] == true)
print " <th style=\"width: 10%\">Sequence</th>\n";
print "</tr>\n";
-$db['dbh']->setLimit($display['pp'], $start_group - 1);
-check_db_error($db['dbh'], __FILE__, __LINE__);
-
$query =
"SELECT catalog_index.tag_id as tag_id, alleles, parents, progeny, valid_progeny, " .
"seq, marker, uncor_marker, chisq_pval, lnl, ratio, ests, pe_radtags, blast_hits, external_id, geno_cnt, " .
@@ -283,24 +294,37 @@ $query =
"LEFT JOIN ref_radome ON (catalog_index.ref_id=ref_radome.id) " .
"WHERE catalog_index.batch_id=?";
$query .= apply_query_filters($display);
+$query .= " LIMIT " . ($start_group - 1) . ", " . $display['pp'];
-$db['tag_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['tag_sth'], __FILE__, __LINE__);
+if (!($db['tag_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
-$result = $db['tag_sth']->execute($param);
-check_db_error($result, __FILE__, __LINE__);
+array_unshift($param, $db['tag_sth']);
+call_user_func_array("mysqli_stmt_bind_param", $param);
+array_shift($param);
+if (!$db['tag_sth']->execute())
+ write_db_error($db['tag_sth'], __FILE__, __LINE__);
+$res = $db['tag_sth']->get_result();
-while ($row = $result->fetchRow()) {
+$tag_id = 0;
+$db['snp_sth']->bind_param("ii", $batch_id, $tag_id);
+while ($row = $res->fetch_assoc()) {
+ $tag_id = $row['tag_id'];
+
+ //
// Query the database to find how many SNPs were found in this sample.
+ //
$snps = array();
- $snp_res = $db['snp_sth']->execute(array($batch_id, $row['tag_id']));
- check_db_error($snp_res, __FILE__, __LINE__);
- while ($snp_row = $snp_res->fetchRow()) {
+ if (!$db['snp_sth']->execute())
+ write_db_error($db['snp_sth'], __FILE__, __LINE__);
+ $snp_res = $db['snp_sth']->get_result();
+
+ while ($snp_row = $snp_res->fetch_assoc()) {
array_push($snps, array('col' => $snp_row['col'], 'rank' => $snp_row['rank_2']));
}
- $url = "$root_path/pop_view.php?db=$database&batch_id=$batch_id&type=$batch[type]&tag_id=$row[tag_id]";
+ $url = "$root_path/pop_view.php?db=$database&batch_id=$batch_id&type=$batch[type]&tag_id=$tag_id";
$annotation = strlen($row['external_id']) > 0 ? $row['external_id'] : "annotate";
echo <<< EOQ
@@ -1003,8 +1027,8 @@ function write_pop_filter($cols) {
$fch = isset($display['filter_chr']) ? $display['filter_chr'] : "";
$fsb = isset($display['filter_sbp']) ? $display['filter_sbp'] : 0;
$feb = isset($display['filter_ebp']) ? $display['filter_ebp'] : $max_chr_len;
- $flnl = isset($display['filter_lnl_l']) ? $display['filter_lnl_l'] : 0;
- $flnu = isset($display['filter_lnl_u']) ? $display['filter_lnl_u'] : -500;
+ $flnl = isset($display['filter_lnl_l']) ? $display['filter_lnl_l'] : -500;
+ $flnu = isset($display['filter_lnl_u']) ? $display['filter_lnl_u'] : 0;
$r = range(1, 9);
$r = array_merge($r, range(10, 100, 5));
@@ -1281,7 +1305,7 @@ function process_filter(&$display_params) {
$display_params['filter_cata'] = $_GET['filter_cata'];
} else if ($filter == "mark") {
- $display_params['filter_mark'] = $_GET['filter_mark'];
+ $display_params['filter_mark'] = ($_GET['filter_mark'] == "Any") ? "%/%" : $_GET['filter_mark'];
} else if ($filter == "gcnt") {
$display_params['filter_gcnt'] = $_GET['filter_gcnt'];
@@ -1295,77 +1319,82 @@ function process_filter(&$display_params) {
} else if ($filter == "loc") {
$display_params['filter_chr'] = $_GET['filter_chr'];
- $display_params['filter_sbp'] = $_GET['filter_sbp'];
- $display_params['filter_ebp'] = $_GET['filter_ebp'];
+ $display_params['filter_sbp'] = $_GET['filter_sbp'] * 1000000;
+ $display_params['filter_ebp'] = $_GET['filter_ebp'] * 1000000;
}
}
}
-function prepare_filter_parameters($display_params, &$param) {
+function prepare_filter_parameters(&$display_params, &$param) {
$filters = $display_params['filter_type'];
- if (!isset($filters))
- return;
+ $param[] = &$display_params['id'];
+ $typestr = "i";
+
+ if (!isset($filters)) {
+ array_unshift($param, $typestr);
+ return;
+ }
foreach ($filters as $filter) {
if ($filter == "snps") {
- array_push($param, $display_params['filter_snps_l']);
- array_push($param, $display_params['filter_snps_u']);
-
+ $param[] = &$display_params['filter_snps_l'];
+ $param[] = &$display_params['filter_snps_u'];
+ $typestr .= "ii";
+
} else if ($filter == "alle") {
- array_push($param, $display_params['filter_alle_l']);
- array_push($param, $display_params['filter_alle_u']);
-
+ $param[] = &$display_params['filter_alle_l'];
+ $param[] = &$display_params['filter_alle_u'];
+ $typestr .= "ii";
+
} else if ($filter == "pare") {
- array_push($param, $display_params['filter_pare_l']);
- array_push($param, $display_params['filter_pare_u']);
+ $param[] = &$display_params['filter_pare_l'];
+ $param[] = &$display_params['filter_pare_u'];
+ $typestr .= "ii";
} else if ($filter == "lnl") {
- array_push($param, $display_params['filter_lnl_l']);
- array_push($param, $display_params['filter_lnl_u']);
+ $param[] = &$display_params['filter_lnl_l'];
+ $param[] = &$display_params['filter_lnl_u'];
+ $typestr .= "ii";
} else if ($filter == "prog") {
- array_push($param, $display_params['filter_prog']);
-
+ $param[] = &$display_params['filter_prog'];
+ $typestr .= "i";
+
} else if ($filter == "vprog") {
- array_push($param, $display_params['filter_vprog']);
-
+ $param[] = &$display_params['filter_vprog'];
+ $typestr .= "i";
+
} else if ($filter == "cata") {
- array_push($param, $display_params['filter_cata']);
-
- } else if ($filter == "est") {
- array_push($param, 0);
-
- } else if ($filter == "pe") {
- array_push($param, 0);
-
- } else if ($filter == "blast") {
- array_push($param, 0);
-
+ $param[] = &$display_params['filter_cata'];
+ $typestr .= "i";
+
} else if ($filter == "gcnt") {
- array_push($param, $display_params['filter_gcnt']);
-
+ $param[] = &$display_params['filter_gcnt'];
+ $typestr .= "i";
+
} else if ($filter == "chisq") {
- array_push($param, $display_params['filter_chisq_l']);
- array_push($param, $display_params['filter_chisq_u']);
-
+ $param[] = &$display_params['filter_chisq_l'];
+ $param[] = &$display_params['filter_chisq_u'];
+ $typestr .= "dd";
+
} else if ($filter == "ref") {
- array_push($param, $display_params['filter_ref']);
-
+ $param[] = &$display_params['filter_ref'];
+ $typestr .= "s";
+
} else if ($filter == "loc") {
- array_push($param, $display_params['filter_chr']);
- array_push($param, $display_params['filter_sbp'] * 1000000);
- array_push($param, $display_params['filter_ebp'] * 1000000);
-
+ $param[] = &$display_params['filter_chr'];
+ $param[] = &$display_params['filter_sbp'];
+ $param[] = &$display_params['filter_ebp'];
+ $typestr .= "sii";
+
} else if ($filter == "mark") {
- if ($display_params['filter_mark'] == "Any")
- array_push($param, "%/%");
- else
- array_push($param, $display_params['filter_mark']);
-
+ $param[] = &$display_params['filter_mark'];
}
}
+
+ array_unshift($param, $typestr);
}
function apply_query_filters($display_params) {
@@ -1380,9 +1409,9 @@ function apply_query_filters($display_params) {
"vprog" => "(valid_progeny >= ?)",
"lnl" => "(lnl >= ? AND lnl <= ?)",
"mark" => "(marker LIKE ?)",
- "est" => "(ests > ?)",
- "pe" => "(pe_radtags > ?)",
- "blast" => "(blast_hits > ?)",
+ "est" => "(ests > 0)",
+ "pe" => "(pe_radtags > 0)",
+ "blast" => "(blast_hits > 0)",
"gcnt" => "(geno_cnt >= ?)",
"chisq" => "(chisq_pval >= ? AND chisq_pval <= ?)",
"ref" => "(catalog_index.type = ?)",
@@ -1414,14 +1443,17 @@ function fetch_chrs(&$max_len) {
$max_len = 0;
$chrs = array();
- $res = $db['chrs_sth']->execute($batch_id);
- check_db_error($res, __FILE__, __LINE__);
+ if (!$db['chrs_sth']->bind_param("i", $batch_id))
+ write_db_error($db['chrs_sth'], __FILE__, __LINE__);
+ if (!$db['chrs_sth']->execute())
+ write_db_error($db['chrs_sth'], __FILE__, __LINE__);
+ $res = $db['chrs_sth']->get_result();
- while ($row = $res->fetchRow()) {
- if ($row['max_len'] > $max_len)
- $max_len = $row['max_len'];
+ while ($row = $res->fetch_assoc()) {
+ if ($row['max_len'] > $max_len)
+ $max_len = $row['max_len'];
- array_push($chrs, $row['chr']);
+ array_push($chrs, $row['chr']);
}
return $chrs;
diff --git a/php/catalog_genotypes.php b/php/catalog_genotypes.php
index 6bbd4c2..c62fb45 100644
--- a/php/catalog_genotypes.php
+++ b/php/catalog_genotypes.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2010, Julian Catchen <jcatchen at uoregon.edu>
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -65,8 +65,8 @@ $marker_types = array('ab/--' => array('aa', 'bb', '-'),
//
$query =
"SELECT count(samples.id) as count FROM samples WHERE batch_id=?";
-$db['samp_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['samp_sth'], __FILE__, __LINE__);
+if (!($db['samp_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT marker, catalog_genotypes.sample_id, file, " .
@@ -81,8 +81,8 @@ $query =
"catalog_genotypes.batch_id=catalog_index.batch_id) " .
"WHERE catalog_genotypes.batch_id=? and catalog_genotypes.catalog_id=? " .
"ORDER BY catalog_genotypes.sample_id";
-$db['geno_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['geno_sth'], __FILE__, __LINE__);
+if (!($db['geno_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$page_title = "Catalog Genotype Viewer";
write_compact_header($page_title);
@@ -91,18 +91,25 @@ write_compact_header($page_title);
// Get number of samples so we can determine how many rows to display
// in the genotype table.
//
-$result = $db['samp_sth']->execute($batch_id);
-check_db_error($result, __FILE__, __LINE__);
-$row = $result->fetchRow();
+if (!$db['samp_sth']->bind_param("i", $batch_id))
+ write_db_error($db['samp_sth'], __FILE__, __LINE__);
+if (!$db['samp_sth']->execute())
+ write_db_error($db['samp_sth'], __FILE__, __LINE__);
+$res = $db['samp_sth']->get_result();
+$row = $res->fetch_assoc();
+
$num_samples = $row['count'];
$num_cols = 10;
$num_rows = ceil($num_samples / $num_cols);
$gtypes = array();
-$result = $db['geno_sth']->execute(array($batch_id, $tag_id));
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['geno_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['geno_sth'], __FILE__, __LINE__);
+if (!$db['geno_sth']->execute())
+ write_db_error($db['geno_sth'], __FILE__, __LINE__);
+$res = $db['geno_sth']->get_result();
-if ($result->numRows() == 0) {
+if ($res->num_rows == 0) {
print
"<h4 style=\"margin-left: auto; margin-right: auto; text-align: center;\">" .
"This marker has no genotypes, probably because this tag does not have enough mappable progeny.</h4>\n";
@@ -110,7 +117,7 @@ if ($result->numRows() == 0) {
return;
}
-while ($row = $result->fetchRow()) {
+while ($row = $res->fetch_assoc()) {
$gtypes[$row['sample_id']] = array('file' => $row['file'],
'genotype' => $row['genotype'],
'corrected' => $row['corrected'],
diff --git a/php/correct_genotype.php b/php/correct_genotype.php
index 0399ce7..7e964a8 100644
--- a/php/correct_genotype.php
+++ b/php/correct_genotype.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2011, Julian Catchen <jcatchen at uoregon.edu>
+// Copyright 2011-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -33,18 +33,18 @@ $db = db_connect($database);
//
$query =
"UPDATE genotype_corrections SET genotype=? WHERE id=?";
-$db['upd_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['upd_sth'], __FILE__, __LINE__);
+if (!($db['upd_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"INSERT INTO genotype_corrections SET batch_id=?, catalog_id=?, sample_id=?, genotype=?";
-$db['ins_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['ins_sth'], __FILE__, __LINE__);
+if (!($db['ins_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"DELETE FROM genotype_corrections WHERE id=?";
-$db['del_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['del_sth'], __FILE__, __LINE__);
+if (!($db['del_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT catalog_genotypes.id as id, catalog_genotypes.sample_id, catalog_genotypes.genotype, " .
@@ -57,16 +57,19 @@ $query =
"WHERE catalog_genotypes.batch_id=? AND " .
"catalog_genotypes.catalog_id=? AND " .
"catalog_genotypes.sample_id=?";
-$db['geno_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['geno_sth'], __FILE__, __LINE__);
+if (!($db['geno_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['geno_sth'], __FILE__, __LINE__);
//
// Fetch the existing genotypes from the database
//
-$result = $db['geno_sth']->execute(array($batch_id, $tag_id, $sample_id));
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['geno_sth']->bind_param("iii", $batch_id, $tag_id, $sample_id))
+ write_db_error($db['geno_sth'], __FILE__, __LINE__);
+if (!$db['geno_sth']->execute())
+ write_db_error($db['geno_sth'], __FILE__, __LINE__);
+$res = $db['geno_sth']->get_result();
-if ($row = $result->fetchRow()) {
+if ($row = $res->fetch_assoc()) {
$sample = array('id' => $row['id'],
'genotype' => strtolower($row['genotype']),
'corrected' => $row['correction'],
@@ -78,8 +81,10 @@ if ($row = $result->fetchRow()) {
$corrected = "false";
if ($gtype == "clr") {
- $result = $db['del_sth']->execute($sample['corrected_id']);
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['del_sth']->bind_param("i", $sample['corrected_id']))
+ write_db_error($db['del_sth'], __FILE__, __LINE__);
+ if (!$db['del_sth']->execute())
+ write_db_error($db['del_sth'], __FILE__, __LINE__);
$corrected = "false";
$gtype = $sample['genotype'];
@@ -88,8 +93,10 @@ if ($gtype == "clr") {
//
} else if ($gtype == $sample['genotype'] &&
strlen($sample['corrected_id']) > 0) {
- $result = $db['del_sth']->execute($sample['corrected_id']);
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['del_sth']->bind_param("i", $sample['corrected_id']))
+ write_db_error($db['del_sth'], __FILE__, __LINE__);
+ if (!$db['del_sth']->execute())
+ write_db_error($db['del_sth'], __FILE__, __LINE__);
$corrected = "false";
//
@@ -97,16 +104,20 @@ if ($gtype == "clr") {
//
} else if ($gtype != $sample['genotype'] &&
strlen($sample['corrected_id']) > 0) {
- $result = $db['upd_sth']->execute(array(strtoupper($gtype), $sample['corrected_id']));
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['upd_sth']->bind_param("si", strtoupper($gtype), $sample['corrected_id']))
+ write_db_error($db['upd_sth'], __FILE__, __LINE__);
+ if (!$db['upd_sth']->execute())
+ write_db_error($db['upd_sth'], __FILE__, __LINE__);
$corrected = "true";
//
// Otherwise, add a new correction.
//
} else if ($gtype != $sample['genotype']) {
- $result = $db['ins_sth']->execute(array($batch_id, $tag_id, $sample_id, strtoupper($gtype)));
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['ins_sth']->bind_param("iiis", $batch_id, $tag_id, $sample_id, strtoupper($gtype)))
+ write_db_error($db['ins_sth'], __FILE__, __LINE__);
+ if (!$db['ins_sth']->execute())
+ write_db_error($db['ins_sth'], __FILE__, __LINE__);
$corrected = "true";
}
diff --git a/php/correct_genotypes.php b/php/correct_genotypes.php
index 7c25177..d158ad7 100644
--- a/php/correct_genotypes.php
+++ b/php/correct_genotypes.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2010, Julian Catchen <jcatchen at uoregon.edu>
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -48,23 +48,23 @@ $query =
"JOIN samples ON (catalog_genotypes.sample_id=samples.id) " .
"WHERE catalog_genotypes.batch_id=? and catalog_genotypes.catalog_id=? " .
"ORDER BY catalog_genotypes.sample_id";
-$db['geno_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['geno_sth'], __FILE__, __LINE__);
+if (!($db['geno_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"UPDATE genotype_corrections SET genotype=? WHERE id=?";
-$db['upd_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['upd_sth'], __FILE__, __LINE__);
+if (!($db['upd_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"INSERT INTO genotype_corrections SET batch_id=?, catalog_id=?, sample_id=?, genotype=?";
-$db['ins_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['ins_sth'], __FILE__, __LINE__);
+if (!($db['ins_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"DELETE FROM genotype_corrections WHERE id=?";
-$db['del_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['del_sth'], __FILE__, __LINE__);
+if (!($db['del_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT genotype_corrections.id FROM genotype_corrections " .
@@ -73,8 +73,8 @@ $query =
"genotype_corrections.sample_id=catalog_genotypes.sample_id AND " .
"genotype_corrections.batch_id=catalog_genotypes.batch_id) " .
"WHERE genotype_corrections.batch_id=? AND genotype_corrections.catalog_id=?";
-$db['res_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['res_sth'], __FILE__, __LINE__);
+if (!($db['res_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
if ($op == "reset") {
reset_marker($display);
@@ -88,12 +88,22 @@ include_once("catalog_genotypes.php");
function reset_marker($display) {
global $db;
- $result = $db['res_sth']->execute(array($display['batch_id'], $display['tag_id']));
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['res_sth']->bind_param("ii", $display['batch_id'], $display['tag_id']))
+ write_db_error($db['res_sth'], __FILE__, __LINE__);
+ if (!$db['res_sth']->execute())
+ write_db_error($db['res_sth'], __FILE__, __LINE__);
+ $res = $db['res_sth']->get_result();
- while ($row = $result->fetchRow()) {
- $r = $db['del_sth']->execute($row['id']);
- check_db_error($r, __FILE__, __LINE__);
+ $row_id = 0;
+
+ if (!$db['del_sth']->bind_param("i", $row_id))
+ write_db_error($db['del_sth'], __FILE__, __LINE__);
+
+ while ($row = $res->fetch_assoc()) {
+ $row_id = $row['id'];
+
+ if (!$db['del_sth']->execute())
+ write_db_error($db['del_sth'], __FILE__, __LINE__);
}
}
@@ -105,10 +115,13 @@ function correct_marker($display) {
//
// Fetch the existing genotypes from the database
//
- $result = $db['geno_sth']->execute(array($display['batch_id'], $display['tag_id']));
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['geno_sth']->bind_param("ii", $display['batch_id'], $display['tag_id']))
+ write_db_error($db['geno_sth'], __FILE__, __LINE__);
+ if (!$db['geno_sth']->execute())
+ write_db_error($db['geno_sth'], __FILE__, __LINE__);
+ $res = $db['geno_sth']->get_result();
- while ($row = $result->fetchRow()) {
+ while ($row = $res->fetch_assoc()) {
$gtypes[$row['sample_id']] = array('id' => $row['id'],
'file' => $row['file'],
'genotype' => strtolower($row['genotype']),
@@ -136,21 +149,29 @@ function correct_marker($display) {
//
if ($sample == $gtypes[$sample_id]['genotype'] &&
strlen($gtypes[$sample_id]['corrected_id']) > 0) {
- $result = $db['del_sth']->execute($gtypes[$sample_id]['corrected_id']);
- check_db_error($result, __FILE__, __LINE__);
+
+ if (!$db['del_sth']->bind_param("i", $gtypes[$sample_id]['corrected_id'])
+ write_db_error($db['del_sth'], __FILE__, __LINE__);
+ if (!$db['del_sth']->execute())
+ write_db_error($db['del_sth'], __FILE__, __LINE__);
//
// Is the corrected value for this genotype being changed? If so, update the corrected record.
//
} else if ($sample != $gtypes[$sample_id]['genotype'] &&
strlen($gtypes[$sample_id]['corrected_id']) > 0) {
- $result = $db['upd_sth']->execute(array(strtoupper($sample), $gtypes[$sample_id]['corrected_id']));
- check_db_error($result, __FILE__, __LINE__);
+
+ if (!$db['upd_sth']->bind_param("si", strtoupper($sample), $gtypes[$sample_id]['corrected_id'])
+ write_db_error($db['upd_sth'], __FILE__, __LINE__);
+ if (!$db['upd_sth']->execute())
+ write_db_error($db['upd_sth'], __FILE__, __LINE__);
//
// Otherwise, add a new correction.
//
} else if ($sample != $gtypes[$sample_id]['genotype']) {
- $result = $db['ins_sth']->execute(array($display['batch_id'], $display['tag_id'], $sample_id, strtoupper($sample)));
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['ins_sth']->bind_param("iiis", $display['batch_id'], $display['tag_id'], $sample_id, strtoupper($sample))
+ write_db_error($db['ins_sth'], __FILE__, __LINE__);
+ if (!$db['ins_sth']->execute())
+ write_db_error($db['ins_sth'], __FILE__, __LINE__);
}
}
}
diff --git a/php/db_functions.php b/php/db_functions.php
index ca63b91..5ebf049 100644
--- a/php/db_functions.php
+++ b/php/db_functions.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2010, Julian Catchen <jcatchen at uoregon.edu>
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -21,32 +21,16 @@
function db_connect($database) {
global $db_user, $db_pass, $db_host;
- $dsn = array(
- 'phptype' => 'mysql',
- 'username' => $db_user,
- 'password' => $db_pass,
- 'hostspec' => $db_host,
- 'port' => 3306
- );
- $options = array();
+ $dbh = new mysqli($db_host, $db_user, $db_pass, $database);
- if (strlen($database) > 0)
- $dsn['database'] = $database;
- else
- $dsn['database'] = false;
-
- $dbh = MDB2::connect($dsn, $options);
-
- if (MDB2::isError($dbh)) {
- die("File: " . __FILE__ . " (line " . __LINE__ . ") " . $dbh->getMessage());
+ if ($dbh->connect_errno) {
+ die("File: " . __FILE__ . " (line " . __LINE__ . ") Failed to connect to MySQL: (" . $dbh->connect_errno . ") " . $dbh->connect_error);
}
- // Set the database package to always return
- // results as an associative array
- $dbh->setFetchMode(MDB2_FETCHMODE_ASSOC);
-
+ //
// The $db array will hold the database handle and
// common, prepared SQL statements.
+ //
$db = array();
$db['dbh'] = $dbh;
$db['name'] = $database;
@@ -54,17 +38,11 @@ function db_connect($database) {
return $db;
}
-function check_db_error($sth, $file, $line) {
-
- if (MDB2::isError($sth)) {
-
- $error_str =
- "File: $file (line $line)<br />\n " .
- "<strong>" . $sth->getMessage() . "</strong><br />\n" .
- $sth->getUserInfo() . "<br />\n";
-
- die($error_str);
- }
+function write_db_error($sth, $file, $line) {
+ $error_str =
+ "File: $file (line $line)<br />\n " .
+ $sth->errno . ": <strong>" . $sth->error . "</strong><br />\n";
+ die($error_str);
}
?>
diff --git a/php/export_batch.php b/php/export_batch.php
index cea8529..fcd2bbd 100644
--- a/php/export_batch.php
+++ b/php/export_batch.php
@@ -120,7 +120,7 @@ function process_filter(&$display_params, &$filters) {
array_push($filters, "cata=" . $_GET['filter_cata']);
} else if ($filter == "mark") {
- $display_params['filter_mark'] = $_GET['filter_mark'];
+ $display_params['filter_mark'] = ($_GET['filter_mark'] == "Any") ? "%/%" : $_GET['filter_mark'];
array_push($filters, "mark=" . $_GET['filter_mark']);
} else if ($filter == "gcnt") {
@@ -134,9 +134,9 @@ function process_filter(&$display_params, &$filters) {
} else if ($filter == "loc") {
$display_params['filter_chr'] = $_GET['filter_chr'];
array_push($filters, "chr=" . $_GET['filter_chr']);
- $display_params['filter_sbp'] = $_GET['filter_sbp'];
+ $display_params['filter_sbp'] = $_GET['filter_sbp'] * 1000000;
array_push($filters, "sbp=" . $_GET['filter_sbp']);
- $display_params['filter_ebp'] = $_GET['filter_ebp'];
+ $display_params['filter_ebp'] = $_GET['filter_ebp'] * 1000000;
array_push($filters, "ebp=" . $_GET['filter_ebp']);
}
}
diff --git a/php/fst_view.php b/php/fst_view.php
index 84c4e0a..057769e 100644
--- a/php/fst_view.php
+++ b/php/fst_view.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2015, Julian Catchen <jcatchen at illinois.edu>
+// Copyright 2015-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -39,49 +39,55 @@ $display['batch_id'] = $batch_id;
$query =
"SELECT pop_id, pop_name FROM populations " .
"WHERE batch_id=?";
-$db['pop_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['pop_sth'], __FILE__, __LINE__);
+if (!($db['pop_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT col, pop_id_1, pop_id_2, pi_o, amova_fst_c as fst, fishers_p, lod FROM fst " .
"WHERE batch_id=? AND tag_id=?";
-$db['fst_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['fst_sth'], __FILE__, __LINE__);
+if (!($db['fst_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
//
// Fetch population names if available.
//
$pop_names = array();
if ($batch_type == "population") {
- $result = $db['pop_sth']->execute($batch_id);
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['pop_sth']->bind_param("i", $batch_id))
+ write_db_error($db['pop_sth'], __FILE__, __LINE__);
+ if (!$db['pop_sth']->execute())
+ write_db_error($db['pop_sth'], __FILE__, __LINE__);
+ $res = $db['pop_sth']->get_result();
- while ($row = $result->fetchRow())
+ while ($row = $res->fetch_assoc())
$pop_names[$row['pop_id']] = $row['pop_name'];
}
-$result = $db['fst_sth']->execute(array($batch_id, $tag_id));
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['fst_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['fst_sth'], __FILE__, __LINE__);
+if (!$db['fst_sth']->execute())
+ write_db_error($db['fst_sth'], __FILE__, __LINE__);
+$res = $db['fst_sth']->get_result();
$stats = array();
$pops = array();
-while ($row = $result->fetchRow()) {
- $a = array('col' => $row['col'],
- 'pid_1' => $row['pop_id_1'],
- 'pid_2' => $row['pop_id_2'],
- 'pi_o' => $row['pi_o'],
- 'fishers_p' => $row['fishers_p'],
- 'lod' => $row['lod'],
- 'fst' => $row['fst']);
+while ($row = $res->fetch_assoc()) {
+ $a = array('col' => $row['col'],
+ 'pid_1' => $row['pop_id_1'],
+ 'pid_2' => $row['pop_id_2'],
+ 'pi_o' => $row['pi_o'],
+ 'fishers_p' => $row['fishers_p'],
+ 'lod' => $row['lod'],
+ 'fst' => $row['fst']);
- if (!isset($stats[$row['col']]))
- $stats[$row['col']] = array();
+ if (!isset($stats[$row['col']]))
+ $stats[$row['col']] = array();
- array_push($stats[$row['col']], $a);
+ array_push($stats[$row['col']], $a);
- $pops[$row['pop_id_1']] = $row['pop_id_1'];
- $pops[$row['pop_id_2']] = $row['pop_id_2'];
+ $pops[$row['pop_id_1']] = $row['pop_id_1'];
+ $pops[$row['pop_id_2']] = $row['pop_id_2'];
}
ksort($stats);
@@ -91,8 +97,8 @@ ksort($pops);
// Assign population IDs for any missing population names.
//
foreach ($pops as $pop_id)
- if (!isset($pop_names[$pop_id]))
- $pop_names[$pop_id] = $pop_id;
+ if (!isset($pop_names[$pop_id]))
+ $pop_names[$pop_id] = $pop_id;
ksort($pop_names);
@@ -109,7 +115,7 @@ $json_str .= "\"popkey\": {";
// Print the population key.
//
foreach ($pop_names as $pop_id => $population) {
- $json_str .=
+ $json_str .=
"\"$pop_id\": \"$population\",";
}
@@ -120,33 +126,33 @@ $json_str .=
foreach ($stats as $col => $stat) {
- $json_str .= "\"$col\": [";
-
- foreach ($stat as $s) {
-
- $fst = $s['fst'] != 0 ? sprintf("%.3f", $s['fst']) : "0";
- $lod = $s['lod'] != 0 ? sprintf("%.3f", $s['lod']) : "0";
- $pio = $s['pi_o'] != 0 ? sprintf("%.3f", $s['pi_o']) : "0";
- $p = $s['fishers_p'] != 0 ? sprintf("%.3f", $s['fishers_p']) : "0";
-
- $json_str .=
- "{" .
- "\"pid_1\": \"$s[pid_1]\"," .
- "\"pid_2\": \"$s[pid_2]\"," .
- "\"pi_o\": \"$pio\"," .
- "\"p\": \"$p\"," .
- "\"lod\": \"$lod\"," .
- "\"fst\": \"$fst\"" .
- "},";
- }
+ $json_str .= "\"$col\": [";
+
+ foreach ($stat as $s) {
+
+ $fst = $s['fst'] != 0 ? sprintf("%.3f", $s['fst']) : "0";
+ $lod = $s['lod'] != 0 ? sprintf("%.3f", $s['lod']) : "0";
+ $pio = $s['pi_o'] != 0 ? sprintf("%.3f", $s['pi_o']) : "0";
+ $p = $s['fishers_p'] != 0 ? sprintf("%.3f", $s['fishers_p']) : "0";
+
+ $json_str .=
+ "{" .
+ "\"pid_1\": \"$s[pid_1]\"," .
+ "\"pid_2\": \"$s[pid_2]\"," .
+ "\"pi_o\": \"$pio\"," .
+ "\"p\": \"$p\"," .
+ "\"lod\": \"$lod\"," .
+ "\"fst\": \"$fst\"" .
+ "},";
+ }
- if (count($stat) > 0)
- $json_str = substr($json_str, 0, -1);
- $json_str .= "],";
+ if (count($stat) > 0)
+ $json_str = substr($json_str, 0, -1);
+ $json_str .= "],";
}
if (count($stats) > 0)
- $json_str = substr($json_str, 0, -1);
+ $json_str = substr($json_str, 0, -1);
$json_str .=
"}}";
diff --git a/php/hapstat_view.php b/php/hapstat_view.php
index 49a57d2..4efe825 100644
--- a/php/hapstat_view.php
+++ b/php/hapstat_view.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2015, Julian Catchen <jcatchen at illinois.edu>
+// Copyright 2015-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -39,41 +39,47 @@ $display['batch_id'] = $batch_id;
$query =
"SELECT pop_id, pop_name FROM populations " .
"WHERE batch_id=?";
-$db['pop_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['pop_sth'], __FILE__, __LINE__);
+if (!($db['pop_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT pop_id, bp, n, hapcnt, gene_div, hap_div FROM hapstats " .
"WHERE batch_id=? AND tag_id=?";
-$db['stats_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['stats_sth'], __FILE__, __LINE__);
+if (!($db['stats_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
//
// Fetch population names if available.
//
$pop_names = array();
if ($batch_type == "population") {
- $result = $db['pop_sth']->execute($batch_id);
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['pop_sth']->bind_param("i", $batch_id))
+ write_db_error($db['pop_sth'], __FILE__, __LINE__);
+ if (!$db['pop_sth']->execute())
+ write_db_error($db['pop_sth'], __FILE__, __LINE__);
+ $res = $db['pop_sth']->get_result();
- while ($row = $result->fetchRow())
+ while ($row = $res->fetch_assoc())
$pop_names[$row['pop_id']] = $row['pop_name'];
}
-$result = $db['stats_sth']->execute(array($batch_id, $tag_id));
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['stats_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['stats_sth'], __FILE__, __LINE__);
+if (!$db['stats_sth']->execute())
+ write_db_error($db['stats_sth'], __FILE__, __LINE__);
+$res = $db['stats_sth']->get_result();
$stats = array();
-while ($row = $result->fetchRow()) {
- $a = array('bp' => $row['bp'],
- 'n' => $row['n'],
- 'hapcnt' => $row['hapcnt'],
- 'gene_div' => $row['gene_div'],
- 'hap_div' => $row['hap_div'],
- 'pop_id' => $row['pop_id']);
+while ($row = $res->fetch_assoc()) {
+ $a = array('bp' => $row['bp'],
+ 'n' => $row['n'],
+ 'hapcnt' => $row['hapcnt'],
+ 'gene_div' => $row['gene_div'],
+ 'hap_div' => $row['hap_div'],
+ 'pop_id' => $row['pop_id']);
- $stats[$row['pop_id']] = $a;
+ $stats[$row['pop_id']] = $a;
}
ksort($stats);
@@ -89,8 +95,8 @@ $json_str =
$json_str .= "\"hapstats\": [";
foreach ($stats as $pop_id => $stat)
- if (!isset($pop_names[$pop_id]))
- $pop_names[$pop_id] = $pop_id;
+ if (!isset($pop_names[$pop_id]))
+ $pop_names[$pop_id] = $pop_id;
$rows = 0;
foreach ($stats as $pop_id => $s) {
@@ -111,7 +117,7 @@ foreach ($stats as $pop_id => $s) {
}
if ($rows > 0)
- $json_str = substr($json_str, 0, -1);
+ $json_str = substr($json_str, 0, -1);
$json_str .=
"]}";
diff --git a/php/header.php b/php/header.php
index b0bf757..8784783 100644
--- a/php/header.php
+++ b/php/header.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2010, Julian Catchen <jcatchen at uoregon.edu>
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -17,7 +17,6 @@
// You should have received a copy of the GNU General Public License
// along with Stacks. If not, see <http://www.gnu.org/licenses/>.
//
-require_once("MDB2.php");
require_once("constants.php");
require_once("db_functions.php");
require_once("stacks_functions.php");
diff --git a/php/index.php b/php/index.php
index 5a2f1b1..85eaf65 100644
--- a/php/index.php
+++ b/php/index.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2010, Julian Catchen <jcatchen at uoregon.edu>
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -78,8 +78,8 @@ function write_database($database) {
//
$query =
"SELECT id, date, description, type FROM batches";
- $db['batch_sth'] = $db['dbh']->prepare($query);
- check_db_error($db['batch_sth'], __FILE__, __LINE__);
+ if (!($db['batch_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$page_title = "RAD-Tag Analyses";
write_header($page_title);
@@ -103,10 +103,11 @@ function write_database($database) {
EOQ;
- $result = $db['batch_sth']->execute();
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['batch_sth']->execute())
+ write_db_error($db['batch_sth'], __FILE__, __LINE__);
+ $res = $db['batch_sth']->get_result();
- while ($row = $result->fetchRow()) {
+ while ($row = $res->fetch_assoc()) {
print
"<tr>\n" .
" <td class=\"s\"><a href=\"$root_path/catalog.php?db=$database&id=$row[id]\">Catalog</a></td>\n" .
diff --git a/php/last_modified.php b/php/last_modified.php
index ff59991..395fdaa 100644
--- a/php/last_modified.php
+++ b/php/last_modified.php
@@ -1 +1 @@
-Wed Apr 29 13:05:18 PDT 2015
+Tue Feb 23 15:53:56 PST 2016
diff --git a/php/phist_view.php b/php/phist_view.php
index 34b34af..db2339d 100644
--- a/php/phist_view.php
+++ b/php/phist_view.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2015, Julian Catchen <jcatchen at illinois.edu>
+// Copyright 2015-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -39,43 +39,49 @@ $display['batch_id'] = $batch_id;
$query =
"SELECT pop_id, pop_name FROM populations " .
"WHERE batch_id=?";
-$db['pop_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['pop_sth'], __FILE__, __LINE__);
+if (!($db['pop_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT pop_id_1, pop_id_2, phist, fpst FROM phist " .
"WHERE batch_id=? AND tag_id=?";
-$db['fst_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['fst_sth'], __FILE__, __LINE__);
+if (!($db['fst_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
//
// Fetch population names if available.
//
$pop_names = array();
if ($batch_type == "population") {
- $result = $db['pop_sth']->execute($batch_id);
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['pop_sth']->bind_param("i", $batch_id))
+ write_db_error($db['pop_sth'], __FILE__, __LINE__);
+ if (!$db['pop_sth']->execute())
+ write_db_error($db['pop_sth'], __FILE__, __LINE__);
+ $res = $db['pop_sth']->get_result();
- while ($row = $result->fetchRow())
+ while ($row = $res->fetch_assoc())
$pop_names[$row['pop_id']] = $row['pop_name'];
}
-$result = $db['fst_sth']->execute(array($batch_id, $tag_id));
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['fst_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['fst_sth'], __FILE__, __LINE__);
+if (!$db['fst_sth']->execute())
+ write_db_error($db['fst_sth'], __FILE__, __LINE__);
+$res = $db['fst_sth']->get_result();
$stats = array();
$pops = array();
-while ($row = $result->fetchRow()) {
- $a = array('pid_1' => $row['pop_id_1'],
- 'pid_2' => $row['pop_id_2'],
- 'phist' => $row['phist'],
- 'fpst' => $row['fpst']);
+while ($row = $res->fetch_assoc()) {
+ $a = array('pid_1' => $row['pop_id_1'],
+ 'pid_2' => $row['pop_id_2'],
+ 'phist' => $row['phist'],
+ 'fpst' => $row['fpst']);
- array_push($stats, $a);
+ array_push($stats, $a);
- $pops[$row['pop_id_1']] = $row['pop_id_1'];
- $pops[$row['pop_id_2']] = $row['pop_id_2'];
+ $pops[$row['pop_id_1']] = $row['pop_id_1'];
+ $pops[$row['pop_id_2']] = $row['pop_id_2'];
}
ksort($stats);
@@ -103,7 +109,7 @@ $json_str .= "\"popkey\": {";
// Print the population key.
//
foreach ($pop_names as $pop_id => $population) {
- $json_str .=
+ $json_str .=
"\"$pop_id\": \"$population\",";
}
@@ -114,8 +120,8 @@ $json_str .=
foreach ($stats as $s) {
- $phist = $s['phist'] != 0 ? sprintf("%.3f", $s['phist']) : "0";
- $fpst = $s['fpst'] != 0 ? sprintf("%.3f", $s['fpst']) : "0";
+ $phist = $s['phist'] != 0 ? sprintf("%.3f", $s['phist']) : "0";
+ $fpst = $s['fpst'] != 0 ? sprintf("%.3f", $s['fpst']) : "0";
$json_str .=
"{" .
@@ -127,7 +133,7 @@ foreach ($stats as $s) {
}
if (count($stats) > 0)
- $json_str = substr($json_str, 0, -1);
+ $json_str = substr($json_str, 0, -1);
$json_str .=
"]}";
diff --git a/php/pop_view.php b/php/pop_view.php
index 7dccc09..41c9605 100644
--- a/php/pop_view.php
+++ b/php/pop_view.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2015, Julian Catchen <jcatchen at illinois.edu>
+// Copyright 2015-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -41,56 +41,56 @@ $query =
"FROM matches " .
"JOIN samples ON (matches.sample_id=samples.id) " .
"WHERE matches.batch_id=? AND catalog_id=? ORDER BY samples.id";
-$db['mat_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['mat_sth'], __FILE__, __LINE__);
+if (!($db['mat_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT col, rank_1, rank_2, rank_3, rank_4 FROM catalog_snps " .
"WHERE batch_id=? AND tag_id=? ORDER BY col";
-$db['snp_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['snp_sth'], __FILE__, __LINE__);
+if (!($db['snp_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT allele FROM catalog_alleles " .
"WHERE batch_id=? AND tag_id=? ";
-$db['all_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['all_sth'], __FILE__, __LINE__);
+if (!($db['all_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT geno_map FROM markers " .
"WHERE batch_id=? AND catalog_id=? ";
-$db['map_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['map_sth'], __FILE__, __LINE__);
+if (!($db['map_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT pop_id, pop_name FROM populations " .
"WHERE batch_id=?";
-$db['pop_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['pop_sth'], __FILE__, __LINE__);
+if (!($db['pop_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT count(batch_id) as cnt FROM sumstats " .
"WHERE batch_id=? AND tag_id=?";
-$db['stats_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['stats_sth'], __FILE__, __LINE__);
+if (!($db['stats_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT count(batch_id) as cnt FROM fst " .
"WHERE batch_id=? AND tag_id=?";
-$db['fst_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['fst_sth'], __FILE__, __LINE__);
+if (!($db['fst_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT count(batch_id) as cnt FROM hapstats " .
"WHERE batch_id=? AND tag_id=?";
-$db['hapstats_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['hapstats_sth'], __FILE__, __LINE__);
+if (!($db['hapstats_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT count(batch_id) as cnt FROM phist " .
"WHERE batch_id=? AND tag_id=?";
-$db['phist_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['phist_sth'], __FILE__, __LINE__);
+if (!($db['phist_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
@@ -106,8 +106,8 @@ $query =
"catalog_genotypes.batch_id=catalog_index.batch_id) " .
"WHERE catalog_genotypes.batch_id=? and catalog_genotypes.catalog_id=? " .
"ORDER BY catalog_genotypes.sample_id";
-$db['geno_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['geno_sth'], __FILE__, __LINE__);
+if (!($db['geno_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
//
// Check for the existence of SNP summary statistics or Fst data.
@@ -117,36 +117,48 @@ $snp_fst_vals = 0;
$hap_sumstats = 0;
$hap_fst_vals = 0;
if ($batch_type == "population") {
- $result = $db['stats_sth']->execute(array($batch_id, $tag_id));
- check_db_error($result, __FILE__, __LINE__);
-
- if ($row = $result->fetchRow()) {
- if ($row['cnt'] > 0)
- $snp_sumstats = 1;
+ if (!$db['stats_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['stats_sth'], __FILE__, __LINE__);
+ if (!$db['stats_sth']->execute())
+ write_db_error($db['stats_sth'], __FILE__, __LINE__);
+ $res = $db['stats_sth']->get_result();
+
+ if ($row = $res->fetch_assoc()) {
+ if ($row['cnt'] > 0)
+ $snp_sumstats = 1;
}
- $result = $db['fst_sth']->execute(array($batch_id, $tag_id));
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['fst_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['fst_sth'], __FILE__, __LINE__);
+ if (!$db['fst_sth']->execute())
+ write_db_error($db['fst_sth'], __FILE__, __LINE__);
+ $res = $db['fst_sth']->get_result();
- if ($row = $result->fetchRow()) {
- if ($row['cnt'] > 0)
- $snp_fst_vals = 1;
+ if ($row = $res->fetch_assoc()) {
+ if ($row['cnt'] > 0)
+ $snp_fst_vals = 1;
}
- $result = $db['hapstats_sth']->execute(array($batch_id, $tag_id));
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['hapstats_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['hapstats_sth'], __FILE__, __LINE__);
+ if (!$db['hapstats_sth']->execute())
+ write_db_error($db['hapstats_sth'], __FILE__, __LINE__);
+ $res = $db['hapstats_sth']->get_result();
- if ($row = $result->fetchRow()) {
- if ($row['cnt'] > 0)
- $hap_sumstats = 1;
+ if ($row = $res->fetch_assoc()) {
+ if ($row['cnt'] > 0)
+ $hap_sumstats = 1;
}
- $result = $db['phist_sth']->execute(array($batch_id, $tag_id));
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['phist_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['phist_sth'], __FILE__, __LINE__);
+ if (!$db['phist_sth']->execute())
+ write_db_error($db['phist_sth'], __FILE__, __LINE__);
+ $res = $db['phist_sth']->get_result();
- if ($row = $result->fetchRow()) {
- if ($row['cnt'] > 0)
- $hap_fst_vals = 1;
+ if ($row = $res->fetch_assoc()) {
+ if ($row['cnt'] > 0)
+ $hap_fst_vals = 1;
}
}
@@ -155,15 +167,21 @@ if ($batch_type == "population") {
//
$pop_names = array();
if ($batch_type == "population") {
- $result = $db['pop_sth']->execute($batch_id);
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['pop_sth']->bind_param("i", $batch_id))
+ write_db_error($db['pop_sth'], __FILE__, __LINE__);
+ if (!$db['pop_sth']->execute())
+ write_db_error($db['pop_sth'], __FILE__, __LINE__);
+ $res = $db['pop_sth']->get_result();
- while ($row = $result->fetchRow())
+ while ($row = $res->fetch_assoc())
$pop_names[$row['pop_id']] = $row['pop_name'];
}
-$result = $db['snp_sth']->execute(array($batch_id, $tag_id));
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['snp_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['snp_sth'], __FILE__, __LINE__);
+if (!$db['snp_sth']->execute())
+ write_db_error($db['snp_sth'], __FILE__, __LINE__);
+$res = $db['snp_sth']->get_result();
$json_str =
"{" .
@@ -179,7 +197,7 @@ $json_str =
$json_str .= "\"snps\": [";
$rows = 0;
-while ($row = $result->fetchRow()) {
+while ($row = $res->fetch_assoc()) {
$json_str .=
"{" .
"\"col\": \"$row[col]\"," .
@@ -196,46 +214,49 @@ $json_str .=
"]," .
"\"alleles\": [";
-$result = $db['map_sth']->execute(array($batch_id, $tag_id));
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['map_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['map_sth'], __FILE__, __LINE__);
+if (!$db['map_sth']->execute())
+ write_db_error($db['map_sth'], __FILE__, __LINE__);
+$res = $db['map_sth']->get_result();
-if ($result->numRows() > 0) {
- $row = $result->fetchRow();
-} else {
- $row = array();
-}
+if ($res->num_rows > 0)
+ $row = $res->fetch_assoc();
$rows = 0;
-if (isset($row['geno_map'])) {
- $map = array();
-
- $genos = explode(";", $row['geno_map']);
- $i = 0;
- foreach ($genos as $g) {
- if (strlen($g) == 0) continue;
- $m = explode(":", $g);
- $map[$m[0]] = $m[1];
- $alleles[$m[0]] = $colors[$i % $color_size];
- $i++;
- }
- asort($map);
- foreach ($map as $hapl => $geno) {
- $json_str .=
+if ($res->num_rows > 0 && strlen($row['geno_map']) > 0) {
+ $map = array();
+
+ $genos = explode(";", $row['geno_map']);
+ $i = 0;
+ foreach ($genos as $g) {
+ if (strlen($g) == 0) continue;
+ $m = explode(":", $g);
+ $map[$m[0]] = $m[1];
+ $alleles[$m[0]] = $colors[$i % $color_size];
+ $i++;
+ }
+ asort($map);
+ foreach ($map as $hapl => $geno) {
+ $json_str .=
"{" .
"\"gtype\": \"$geno\"," .
"\"htype\": \"$hapl\"" .
"},";
- }
- $rows++;
+ }
+ $rows++;
} else {
- $result = $db['all_sth']->execute(array($batch_id, $tag_id));
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['all_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['all_sth'], __FILE__, __LINE__);
+ if (!$db['all_sth']->execute())
+ write_db_error($db['all_sth'], __FILE__, __LINE__);
+ $res = $db['all_sth']->get_result();
$gtypes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$i = 0;
- while ($row = $result->fetchRow()) {
+ while ($row = $res->fetch_assoc()) {
$json_str .=
"{" .
"\"gtype\": \"" . $gtypes[$i % 52] . "\"," .
@@ -247,7 +268,7 @@ if (isset($row['geno_map'])) {
}
if ($rows > 0)
- $json_str = substr($json_str, 0, -1);
+ $json_str = substr($json_str, 0, -1);
$json_str .=
"]," .
"\"popkey\": {";
@@ -257,15 +278,18 @@ $gtypes = array();
//
// Fetch and record Observed Haplotypes
//
-$result = $db['mat_sth']->execute(array($batch_id, $tag_id));
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['mat_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['mat_sth'], __FILE__, __LINE__);
+if (!$db['mat_sth']->execute())
+ write_db_error($db['mat_sth'], __FILE__, __LINE__);
+$res = $db['mat_sth']->get_result();
-while ($row = $result->fetchRow()) {
+while ($row = $res->fetch_assoc()) {
$a = array('id' => $row['id'],
'file' => $row['file'],
'allele' => $row['allele'],
'tag_id' => $row['tag_id'],
- 'depth' => $row['depth'],
+ 'depth' => $row['depth'],
'lnl' => $row['lnl'],
'pop_id' => $row['pop_id']);
if (!isset($htypes[$row['pop_id']]))
@@ -280,10 +304,13 @@ while ($row = $result->fetchRow()) {
//
// Fetch and record Genotypes
//
-$result = $db['geno_sth']->execute(array($batch_id, $tag_id));
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['geno_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['geno_sth'], __FILE__, __LINE__);
+if (!$db['geno_sth']->execute())
+ write_db_error($db['geno_sth'], __FILE__, __LINE__);
+$res = $db['geno_sth']->get_result();
-while ($row = $result->fetchRow()) {
+while ($row = $res->fetch_assoc()) {
$gtypes[$row['file']] = array('id' => $row['sample_id'],
'file' => $row['file'],
'genotype' => $row['genotype'],
diff --git a/php/population_view.js b/php/population_view.js
index 8ee7978..a7039e0 100644
--- a/php/population_view.js
+++ b/php/population_view.js
@@ -74,6 +74,9 @@ function ajax_locus_population_view(id, root_path, url) {
tr_obj.style.display = "";
caret.src = root_path + "/caret-d.png";
+ var div_obj = document.getElementById(id + "_popview_div");
+ div_obj.innerHTML = "<i class=\"fa fa-spinner fa-pulse fa-3x\"></i>";
+
//
// Make the AJAX query for JSON encoded data for this locus.
//
diff --git a/php/samples.php b/php/samples.php
index 753add3..7b9a33a 100644
--- a/php/samples.php
+++ b/php/samples.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2010, Julian Catchen <jcatchen at uoregon.edu>
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -30,33 +30,37 @@ $db = db_connect($database);
//
$query =
"SELECT id, date, description FROM batches WHERE id=?";
-$db['batch_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['batch_sth'], __FILE__, __LINE__);
+if (!($db['batch_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT id, sample_id, type, file FROM samples " .
"WHERE batch_id=? ORDER BY id";
-$db['samp_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['samp_sth'], __FILE__, __LINE__);
+if (!($db['samp_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT COUNT(tag_id) AS count FROM tag_index " .
"WHERE batch_id=? AND sample_id=?";
-$db['count_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['count_sth'], __FILE__, __LINE__);
+if (!($db['count_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT snps FROM tag_index " .
"WHERE batch_id=? AND sample_id=? AND snps>0";
-$db['snp_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['snp_sth'], __FILE__, __LINE__);
+if (!($db['snp_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
//
// Pull information about this batch
//
-$result = $db['batch_sth']->execute($batch_id);
-check_db_error($result, __FILE__, __LINE__);
-$row = $result->fetchRow();
+if (!$db['batch_sth']->bind_param("i", $batch_id))
+ write_db_error($db['batch_sth'], __FILE__, __LINE__);
+if (!$db['batch_sth']->execute())
+ write_db_error($db['batch_sth'], __FILE__, __LINE__);
+$res = $db['batch_sth']->get_result();
+$row = $res->fetch_assoc();
+
$batch = array();
$batch['id'] = $row['id'];
$batch['desc'] = $row['description'];
@@ -88,24 +92,40 @@ echo <<< EOQ
EOQ;
-$result = $db['samp_sth']->execute($batch_id);
-check_db_error($result, __FILE__, __LINE__);
-
-while ($row = $result->fetchRow()) {
- $snps = 0;
- $poly = 0;
-
+if (!$db['samp_sth']->bind_param("i", $batch_id))
+ write_db_error($db['samp_sth'], __FILE__, __LINE__);
+if (!$db['samp_sth']->execute())
+ write_db_error($db['samp_sth'], __FILE__, __LINE__);
+$res = $db['samp_sth']->get_result();
+
+$tag_id = 0;
+if (!$db['count_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['count_sth'], __FILE__, __LINE__);
+if (!$db['snp_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['count_sth'], __FILE__, __LINE__);
+
+while ($row = $res->fetch_assoc()) {
+ $snps = 0;
+ $poly = 0;
+ $tag_id = $row['id'];
+
+ //
// Query the database to determine how many tags belong to this sample.
- $count_res = $db['count_sth']->execute(array($batch_id, $row['id']));
- check_db_error($count_res, __FILE__, __LINE__);
- $count_row = $count_res->fetchRow();
+ //
+ if (!$db['count_sth']->execute())
+ write_db_error($db['count_sth'], __FILE__, __LINE__);
+ $count_res = $db['count_sth']->get_result();
+ $count_row = $count_res->fetch_assoc();
$count = $count_row['count'];
+ //
// Query the database to find how many SNPs were found in this sample.
- $count_res = $db['snp_sth']->execute(array($batch_id, $row['id']));
- check_db_error($count_res, __FILE__, __LINE__);
+ //
+ if (!$db['snp_sth']->execute())
+ write_db_error($db['snp_sth'], __FILE__, __LINE__);
+ $count_res = $db['snp_sth']->get_result();
- while ($count_row = $count_res->fetchRow()) {
+ while ($count_row = $count_res->fetch_assoc()) {
$snps += $count_row['snps'];
$poly += $count_row['snps'] > 0 ? 1 : 0;
}
diff --git a/php/sequence_blast.php b/php/sequence_blast.php
index 8413265..bcfd80a 100644
--- a/php/sequence_blast.php
+++ b/php/sequence_blast.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2010, Julian Catchen <jcatchen at uoregon.edu>
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -42,22 +42,25 @@ $display['pp'] = $per_page;
$query =
"SELECT id, catalog_id, seq_id, type FROM sequence " .
"WHERE batch_id=? AND catalog_id=?";
-$db['seq_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['seq_sth'], __FILE__, __LINE__);
+if (!($db['seq_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT id, catalog_id, seq_id, algorithm, query_id, query_len, hit_id, hit_len, score, e_value, percent_ident, hsp_rank, " .
"aln_len, query_aln_start, query_aln_end, hit_aln_start, hit_aln_end " .
"FROM sequence_blast " .
"WHERE batch_id=? AND catalog_id=?";
-$db['blast_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['blast_sth'], __FILE__, __LINE__);
+if (!($db['blast_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$page_title = "Catalog RAD-Tag Sequence/BLAST Hits Viewer";
write_compact_header($page_title);
-$result = $db['seq_sth']->execute(array($batch_id, $tag_id));
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['seq_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['seq_sth'], __FILE__, __LINE__);
+if (!$db['seq_sth']->execute())
+ write_db_error($db['seq_sth'], __FILE__, __LINE__);
+$res = $db['seq_sth']->get_result();
$seqs = array();
@@ -69,7 +72,7 @@ $a = array('id' => -1,
'type' => "se_radtag");
array_push($seqs, $a);
-while ($row = $result->fetchRow()) {
+while ($row = $res->fetch_assoc()) {
$a = array('id' => $row['id'],
'catalog_id' => $row['catalog_id'],
'seq_id' => $row['seq_id'],
@@ -78,12 +81,15 @@ while ($row = $result->fetchRow()) {
array_push($seqs, $a);
}
-$result = $db['blast_sth']->execute(array($batch_id, $tag_id));
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['blast_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['blast_sth'], __FILE__, __LINE__);
+if (!$db['blast_sth']->execute())
+ write_db_error($db['blast_sth'], __FILE__, __LINE__);
+$res = $db['blast_sth']->get_result();
$hits = array();
-while ($row = $result->fetchRow()) {
+while ($row = $res->fetch_assoc()) {
$a = array('sql_id' => $row['id'],
'query_id' => $row['query_id'],
'hit_id' => $row['hit_id'],
diff --git a/php/stack_view.php b/php/stack_view.php
index 2ad88e1..92fd097 100644
--- a/php/stack_view.php
+++ b/php/stack_view.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2010-2015, Julian Catchen <jcatchen at illinois.edu>
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -40,28 +40,37 @@ $query =
"JOIN samples ON (unique_tags.sample_id=samples.id) " .
"JOIN batches ON (samples.batch_id=batches.id) " .
"WHERE batch_id=? AND unique_tags.sample_id=? AND tag_id=?";
-$db['seq_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['seq_sth'], __FILE__, __LINE__);
+if (!($db['seq_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT col, rank_1, rank_2 FROM snps " .
"JOIN samples ON (snps.sample_id=samples.id) " .
"JOIN batches ON (samples.batch_id=batches.id) " .
"WHERE batch_id=? AND snps.sample_id=? AND tag_id=? AND snps.type='E' ORDER BY col";
-$db['snp_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['snp_sth'], __FILE__, __LINE__);
+if (!($db['snp_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT col FROM catalog_snps " .
"WHERE batch_id=? AND tag_id=?";
-$db['cat_snp_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['cat_snp_sth'], __FILE__, __LINE__);
+if (!($db['cat_snp_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$json_str =
"{" .
"\"id\": \"$cat_id\"," .
"\"stacks\": [";
+$sample_id = 0;
+$tag_id = 0;
+if (!$db['snp_sth']->bind_param("iii", $batch_id, $sample_id, $tag_id))
+ write_db_error($db['snp_sth'], __FILE__, __LINE__);
+if (!$db['cat_snp_sth']->bind_param("ii", $batch_id, $cat_id))
+ write_db_error($db['cat_snp_sth'], __FILE__, __LINE__);
+if (!$db['seq_sth']->bind_param("iii", $batch_id, $sample_id, $tag_id))
+ write_db_error($db['seq_sth'], __FILE__, __LINE__);
+
for ($i = 0; $i < count($tags); $i++) {
$sample_id = $samples[$i];
$tag_id = $tags[$i];
@@ -69,10 +78,12 @@ for ($i = 0; $i < count($tags); $i++) {
//
// Fetch and store the SNPs.
//
- $snps = array();
- $result = $db['snp_sth']->execute(array($batch_id, $sample_id, $tag_id));
- check_db_error($result, __FILE__, __LINE__);
- while ($row = $result->fetchRow()) {
+ $snps = array();
+ if (!$db['snp_sth']->execute())
+ write_db_error($db['snp_sth'], __FILE__, __LINE__);
+ $res = $db['snp_sth']->get_result();
+
+ while ($row = $res->fetch_assoc()) {
$snps[$row['col']] = array('col' => $row['col'], 'rank_1' => $row['rank_1'], 'rank_2' => $row['rank_2']);
}
@@ -80,9 +91,11 @@ for ($i = 0; $i < count($tags); $i++) {
// Fetch and store the catalog SNPs.
//
$cat_snps = array();
- $result = $db['cat_snp_sth']->execute(array($batch_id, $cat_id));
- check_db_error($result, __FILE__, __LINE__);
- while ($row = $result->fetchRow()) {
+ if (!$db['snp_sth']->execute())
+ write_db_error($db['snp_sth'], __FILE__, __LINE__);
+ $res = $db['snp_sth']->get_result();
+
+ while ($row = $res->fetch_assoc()) {
if (!isset($cat_snps[$row['col']]))
$cat_snps[$row['col']] = 0;
$cat_snps[$row['col']]++;
@@ -99,10 +112,12 @@ for ($i = 0; $i < count($tags); $i++) {
$file = "";
$stacks = array();
$secondary = array();
- $result = $db['seq_sth']->execute(array($batch_id, $sample_id, $tag_id));
- check_db_error($result, __FILE__, __LINE__);
- while ($row = $result->fetchRow()) {
+ if (!$db['seq_sth']->execute())
+ write_db_error($db['seq_sth'], __FILE__, __LINE__);
+ $res = $db['seq_sth']->get_result();
+
+ while ($row = $res->fetch_assoc()) {
if ($row['relationship'] == "consensus") {
$deleveraged = $row['deleveraged'];
diff --git a/php/stacks.css b/php/stacks.css
index e918c14..43d7595 100644
--- a/php/stacks.css
+++ b/php/stacks.css
@@ -861,3 +861,8 @@ table.stack td.tag
padding-right: 10px;
border-right: thin solid #aaaaaa;
}
+
+i.fa-spinner
+{
+ padding: 0.5em;
+}
\ No newline at end of file
diff --git a/php/stacks_functions.php b/php/stacks_functions.php
index b804b19..e48a434 100644
--- a/php/stacks_functions.php
+++ b/php/stacks_functions.php
@@ -29,6 +29,7 @@ function write_header($page_title) {
<meta charset="utf-8">
<title>$site_title: $page_title</title>
<link rel="stylesheet" type="text/css" href="$root_path/stacks.css" />
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<script type="text/javascript" src="$root_path/stacks.js"></script>
<script type="text/javascript" src="$root_path/annotate.js"></script>
<script type="text/javascript" src="$root_path/export.js"></script>
diff --git a/php/sumstat_view.php b/php/sumstat_view.php
index 84d5aac..54f1457 100644
--- a/php/sumstat_view.php
+++ b/php/sumstat_view.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2015, Julian Catchen <jcatchen at illinois.edu>
+// Copyright 2015-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -39,54 +39,60 @@ $display['batch_id'] = $batch_id;
$query =
"SELECT pop_id, pop_name FROM populations " .
"WHERE batch_id=?";
-$db['pop_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['pop_sth'], __FILE__, __LINE__);
+if (!($db['pop_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT pop_id, col, bp, p_nuc, q_nuc, n, p, obs_het, obs_hom, exp_het, exp_hom, pi, fis FROM sumstats " .
"WHERE batch_id=? AND tag_id=?";
-$db['stats_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['stats_sth'], __FILE__, __LINE__);
+if (!($db['stats_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
//
// Fetch population names if available.
//
$pop_names = array();
if ($batch_type == "population") {
- $result = $db['pop_sth']->execute($batch_id);
- check_db_error($result, __FILE__, __LINE__);
+ if (!$db['pop_sth']->bind_param("i", $batch_id))
+ write_db_error($db['pop_sth'], __FILE__, __LINE__);
+ if (!$db['pop_sth']->execute())
+ write_db_error($db['pop_sth'], __FILE__, __LINE__);
+ $res = $db['pop_sth']->get_result();
- while ($row = $result->fetchRow())
+ while ($row = $res->fetch_assoc())
$pop_names[$row['pop_id']] = $row['pop_name'];
}
-$result = $db['stats_sth']->execute(array($batch_id, $tag_id));
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['stats_sth']->bind_param("ii", $batch_id, $tag_id))
+ write_db_error($db['stats_sth'], __FILE__, __LINE__);
+if (!$db['stats_sth']->execute())
+ write_db_error($db['stats_sth'], __FILE__, __LINE__);
+$res = $db['stats_sth']->get_result();
$stats = array();
$pops = array();
-while ($row = $result->fetchRow()) {
- $a = array('col' => $row['col'],
- 'bp' => $row['bp'],
- 'p_nuc' => $row['p_nuc'],
- 'q_nuc' => $row['q_nuc'],
- 'n' => $row['n'],
- 'p' => $row['p'],
- 'obs_het' => $row['obs_het'],
- 'obs_hom' => $row['obs_hom'],
- 'exp_het' => $row['exp_het'],
- 'exp_hom' => $row['exp_hom'],
- 'pi' => $row['pi'],
- 'fis' => $row['fis'],
- 'pop_id' => $row['pop_id']);
-
- if (!isset($stats[$row['col']]))
- $stats[$row['col']] = array();
-
- $stats[$row['col']][$row['pop_id']] = $a;
-
- $pops[$row['pop_id']] = $row['pop_id'];
+while ($row = $res->fetch_assoc()) {
+ $a = array('col' => $row['col'],
+ 'bp' => $row['bp'],
+ 'p_nuc' => $row['p_nuc'],
+ 'q_nuc' => $row['q_nuc'],
+ 'n' => $row['n'],
+ 'p' => $row['p'],
+ 'obs_het' => $row['obs_het'],
+ 'obs_hom' => $row['obs_hom'],
+ 'exp_het' => $row['exp_het'],
+ 'exp_hom' => $row['exp_hom'],
+ 'pi' => $row['pi'],
+ 'fis' => $row['fis'],
+ 'pop_id' => $row['pop_id']);
+
+ if (!isset($stats[$row['col']]))
+ $stats[$row['col']] = array();
+
+ $stats[$row['col']][$row['pop_id']] = $a;
+
+ $pops[$row['pop_id']] = $row['pop_id'];
}
ksort($stats);
@@ -111,43 +117,43 @@ $index = count($pop_names) == 0 ? $pops : $pop_names;
$rows = 0;
foreach ($stats as $col => $stat) {
- foreach ($index as $pop_id => $pop_name) {
- if (!isset($stat[$pop_id]))
- continue;
-
- $s = $stat[$pop_id];
- $p = $s['p'] < 1 ? sprintf("%.5f", $s['p']) : $s['p'];
- $ohet = $s['obs_het'] > 0 ? sprintf("%.3f", $s['obs_het']) : $s['obs_het'];
- $ohom = $s['obs_hom'] < 1 ? sprintf("%.3f", $s['obs_hom']) : $s['obs_hom'];
- $ehet = $s['exp_het'] > 0 ? sprintf("%.3f", $s['exp_het']) : $s['exp_het'];
- $ehom = $s['exp_hom'] < 1 ? sprintf("%.3f", $s['exp_hom']) : $s['exp_hom'];
- $pi = $s['pi'] > 0 ? sprintf("%.3f", $s['pi']) : $s['pi'];
- $fis = $s['fis'] != 0 ? sprintf("%.3f", $s['fis']) : "0";
-
- $json_str .=
- "{" .
- "\"pop_id\": \"$pop_name\"," .
- "\"col\": \"$s[col]\"," .
- "\"bp\": \"$s[bp]\"," .
- "\"p_allele\": \"$s[p_nuc]\"," .
- "\"q_allele\": \"$s[q_nuc]\"," .
- "\"p\": \"$p\"," .
- "\"n\": \"$s[n]\"," .
- "\"obshet\": \"$ohet\"," .
- "\"obshom\": \"$ohom\"," .
- "\"exphet\": \"$ehet\"," .
- "\"exphom\": \"$ehom\"," .
- "\"pi\": \"$pi\"," .
- "\"fis\": \"$fis\"" .
- "},";
- $rows++;
- }
+ foreach ($index as $pop_id => $pop_name) {
+ if (!isset($stat[$pop_id]))
+ continue;
+
+ $s = $stat[$pop_id];
+ $p = $s['p'] < 1 ? sprintf("%.5f", $s['p']) : $s['p'];
+ $ohet = $s['obs_het'] > 0 ? sprintf("%.3f", $s['obs_het']) : $s['obs_het'];
+ $ohom = $s['obs_hom'] < 1 ? sprintf("%.3f", $s['obs_hom']) : $s['obs_hom'];
+ $ehet = $s['exp_het'] > 0 ? sprintf("%.3f", $s['exp_het']) : $s['exp_het'];
+ $ehom = $s['exp_hom'] < 1 ? sprintf("%.3f", $s['exp_hom']) : $s['exp_hom'];
+ $pi = $s['pi'] > 0 ? sprintf("%.3f", $s['pi']) : $s['pi'];
+ $fis = $s['fis'] != 0 ? sprintf("%.3f", $s['fis']) : "0";
+
+ $json_str .=
+ "{" .
+ "\"pop_id\": \"$pop_name\"," .
+ "\"col\": \"$s[col]\"," .
+ "\"bp\": \"$s[bp]\"," .
+ "\"p_allele\": \"$s[p_nuc]\"," .
+ "\"q_allele\": \"$s[q_nuc]\"," .
+ "\"p\": \"$p\"," .
+ "\"n\": \"$s[n]\"," .
+ "\"obshet\": \"$ohet\"," .
+ "\"obshom\": \"$ohom\"," .
+ "\"exphet\": \"$ehet\"," .
+ "\"exphom\": \"$ehom\"," .
+ "\"pi\": \"$pi\"," .
+ "\"fis\": \"$fis\"" .
+ "},";
+ $rows++;
+ }
}
if ($rows > 0)
- $json_str = substr($json_str, 0, -1);
+ $json_str = substr($json_str, 0, -1);
$json_str .=
- "]}";
+"]}";
echo $json_str;
diff --git a/php/tag.php b/php/tag.php
new file mode 100644
index 0000000..0d23f11
--- /dev/null
+++ b/php/tag.php
@@ -0,0 +1,368 @@
+<?php
+//
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
+//
+// This file is part of Stacks.
+//
+// Stacks is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Stacks is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Stacks. If not, see <http://www.gnu.org/licenses/>.
+//
+require_once("header.php");
+
+$tag_id = isset($_GET['tag_id']) ? $_GET['tag_id'] : 0;
+$batch_id = isset($_GET['batch_id']) ? $_GET['batch_id'] : 0;
+$sample_id = isset($_GET['sample_id']) ? $_GET['sample_id'] : 0;
+$database = isset($_GET['db']) ? $_GET['db'] : "";
+$page = isset($_GET['p']) ? $_GET['p'] : 1;
+$per_page = isset($_GET['pp']) ? $_GET['pp'] : 10;
+
+// Connect to the database
+$db = db_connect($database);
+
+// Save these variables for automatic URL formation later on.
+$display = array();
+$display['tag_id'] = $tag_id;
+$display['batch_id'] = $batch_id;
+$display['sample_id'] = $sample_id;
+$display['db'] = $database;
+$display['p'] = $page;
+$display['pp'] = $per_page;
+
+//
+// Prepare some SQL queries
+//
+$query =
+ "SELECT batches.id as id, date, description, samples.id as sample_id, samples.sample_id as samp_id, samples.type, file " .
+ "FROM batches " .
+ "JOIN samples ON (batch_id=batches.id) " .
+ "WHERE batches.id=? AND samples.id=?";
+if (!($db['batch_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
+
+$query =
+ "SELECT count(id) as depth FROM unique_tags " .
+ "WHERE relationship!='consensus' AND relationship!='model' AND sample_id=? AND tag_id=?";
+if (!($db['depth_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
+
+$query =
+ "SELECT tag_id, sub_id, relationship, seq_id, seq, deleveraged, blacklisted, removed " .
+ "FROM unique_tags " .
+ "JOIN samples ON (unique_tags.sample_id=samples.id) " .
+ "JOIN batches ON (samples.batch_id=batches.id) " .
+ "WHERE batch_id=? AND unique_tags.sample_id=? AND tag_id=?";
+if (!($db['seq_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
+
+$query =
+ "SELECT col, rank_1, rank_2 FROM snps " .
+ "JOIN samples ON (snps.sample_id=samples.id) " .
+ "JOIN batches ON (samples.batch_id=batches.id) " .
+ "WHERE batch_id=? AND snps.sample_id=? AND tag_id=? AND snps.type='E' ORDER BY col";
+if (!($db['snp_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
+
+$query =
+ "SELECT allele, read_pct FROM alleles " .
+ "WHERE sample_id=? AND tag_id=? ";
+if (!($db['all_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
+
+$query =
+ "SELECT catalog_id FROM matches " .
+ "WHERE batch_id=? AND sample_id=? AND tag_id=? " .
+ "GROUP BY catalog_id";
+if (!($db['cat_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
+
+$query =
+ "SELECT col FROM catalog_snps " .
+ "WHERE batch_id=? AND tag_id=?";
+if (!($db['cat_snp_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
+
+//
+// Pull information about this batch
+//
+if (!$db['batch_sth']->bind_param("ii", $batch_id, $sample_id))
+ write_db_error($db['batch_sth'], __FILE__, __LINE__);
+if (!$db['batch_sth']->execute())
+ write_db_error($db['batch_sth'], __FILE__, __LINE__);
+$res = $db['batch_sth']->get_result();
+$row = $res->fetch_assoc();
+
+$batch = array();
+$batch['id'] = $row['id'];
+$batch['desc'] = $row['description'];
+$batch['date'] = $row['date'];
+$batch['file'] = $row['file'];
+$batch['sample_id'] = $row['sample_id'];
+$batch['samp_id'] = $row['samp_id'];
+$batch['sample_type'] = $row['type'];
+
+$page_title = "RAD-Tag Viewer";
+write_header($page_title, $batch);
+
+echo <<< EOQ
+<form id="page_state" name="page_state"></form>
+<h3 style="margin-left: 1em;">
+<a href="$root_path/samples.php?db=$database&id=$batch[id]">
+Batch #$batch[id] <span class="s">[$batch[date]; $batch[desc]]</span></a></h3>
+
+<h4 style="margin-left: 1em;">
+<a href="$root_path/tags.php?db=$database&batch_id=$batch[id]&sample_id=$batch[sample_id]&p=$display[p]&pp=$display[pp]">
+ RAD-Tag Sample #$batch[samp_id] [<span class="s">$batch[file]</span>]</a>
+</h4>
+
+<h4 class="info_head" style="margin-left: 1em;">
+ <img id="sources_img" src="$img_path/caret-d.png" />
+ <a onclick="toggle_div('sources', '$img_path', 'page_state');">
+ Sequence #$display[tag_id]</a>
+</h4>
+
+<div id="sources" style="width: 100%;">
+<table class="radtag" style="width: 90%; margin-left: 2.5%; margin-right: auto; margin-bottom: 1em;">
+<tr>
+ <th style="width: 10%;">Catalog ID</th>
+ <th style="width: 5%;">Depth</th>
+ <th style="width: 25%;">SNPs</th>
+ <th style="width: 25%;">Alleles</th>
+ <th style="width: 10%;">Deleveraged?</th>
+ <th style="width: 15%;">Lumberjackstack?</th>
+ <th style="width: 10%;">Blacklisted?</th>
+</tr>
+<tr>
+
+EOQ;
+
+//
+// Fetch the seqeunces
+//
+$deleveraged = 0;
+$lumberjackstack = 0;
+$blacklisted = 0;
+$seqs = array('consensus' => array(),
+ 'primary' => array(),
+ 'secondary' => array(),
+ 'model' => array());
+
+if (!$db['seq_sth']->bind_param("iii", $batch_id, $sample_id, $tag_id))
+ write_db_error($db['seq_sth'], __FILE__, __LINE__);
+if (!$db['seq_sth']->execute())
+ write_db_error($db['seq_sth'], __FILE__, __LINE__);
+$res = $db['seq_sth']->get_result();
+
+while ($row = $res->fetch_assoc()) {
+ array_push($seqs[$row['relationship']], array('s' => $row['seq'], 'id' => $row['seq_id'], 'sub_id' => $row['sub_id']));
+
+ if ($row['relationship'] == "consensus") {
+ $deleveraged = $row['deleveraged'];
+ $lumberjackstack = $row['removed'];
+ $blacklisted = $row['blacklisted'];
+ }
+}
+
+if (!$db['cat_sth']->bind_param("iii", $batch_id, $sample_id, $tag_id))
+ write_db_error($db['cat_sth'], __FILE__, __LINE__);
+if (!$db['cat_sth']->execute())
+ write_db_error($db['cat_sth'], __FILE__, __LINE__);
+$res = $db['cat_sth']->get_result();
+$row = $res->fetch_assoc();
+
+if (isset($row['catalog_id']))
+ $catalog_id = $row['catalog_id'];
+else
+ $catalog_id = -1;
+
+print "<td style=\"text-align: center; vertical-align: top;\">\n";
+if ($catalog_id >= 0)
+ print " <a href=\"$root_path/catalog.php?db=$database&id=$batch_id&filter_type[]=cata&filter_cata=$catalog_id\">#$catalog_id</a>\n";
+print "</td>\n";
+
+if (!$db['depth_sth']->bind_param("ii", $sample_id, $tag_id))
+ write_db_error($db['depth_sth'], __FILE__, __LINE__);
+if (!$db['depth_sth']->execute())
+ write_db_error($db['depth_sth'], __FILE__, __LINE__);
+$res = $db['depth_sth']->get_result();
+$row = $res->fetch_assoc();
+
+echo <<< EOQ
+<td style="text-align: center; vertical-align: top;">
+ $row[depth]x
+</td>
+
+EOQ;
+
+$snps = array();
+if (!$db['snp_sth']->bind_param("iii", $batch_id, $sample_id, $tag_id))
+ write_db_error($db['snp_sth'], __FILE__, __LINE__);
+if (!$db['snp_sth']->execute())
+ write_db_error($db['snp_sth'], __FILE__, __LINE__);
+$res = $db['snp_sth']->get_result();
+
+while ($row = $res->fetch_assoc()) {
+ $snps[$row['col']] = array('col' => $row['col'], 'rank_1' => $row['rank_1'], 'rank_2' => $row['rank_2']);
+}
+
+$cat_snps = array();
+if ($catalog_id >= 0) {
+
+ if (!$db['cat_snp_sth']->bind_param("ii", $batch_id, $catalog_id))
+ write_db_error($db['cat_snp_sth'], __FILE__, __LINE__);
+ if (!$db['cat_snp_sth']->execute())
+ write_db_error($db['cat_snp_sth'], __FILE__, __LINE__);
+ $res = $db['cat_snp_sth']->get_result();
+
+ while ($row = $res->fetch_assoc()) {
+ if (!isset($cat_snps[$row['col']]))
+ $cat_snps[$row['col']] = 0;
+ $cat_snps[$row['col']]++;
+ }
+}
+
+print
+" <td style=\"vertical-align: top;\">\n".
+" <table style=\"margin-left: auto; margin-right: auto; width: 60%;\">\n";
+
+foreach ($snps as $snp) {
+ print
+ "<tr>\n" .
+ " <td>Column: $snp[col]</td><td style=\"text-align: right;\">$snp[rank_1]/$snp[rank_2]</td>\n" .
+ "</tr>\n";
+}
+
+print
+" </table>\n" .
+" </td>\n";
+
+if (!$db['all_sth']->bind_param("ii", $sample_id, $tag_id))
+ write_db_error($db['all_sth'], __FILE__, __LINE__);
+if (!$db['all_sth']->execute())
+ write_db_error($db['all_sth'], __FILE__, __LINE__);
+$res = $db['all_sth']->get_result();
+
+$alleles = array();
+$i = 0;
+
+print
+" <td style=\"vertical-align: top;\">\n" .
+" <table style=\"margin-left: auto; margin-right: auto; width: 50%;\">\n";
+
+while ($row = $res->fetch_assoc()) {
+ $alleles[$row['allele']] = $colors[$i % $color_size];
+
+ print
+ " <tr>\n" .
+ " <td><span style=\"color: " . $alleles[$row['allele']] . ";\">$row[allele]</span></td>\n" .
+ " <td style=\"text-align: right;\">" . sprintf("%.2f%%", $row['read_pct']) . "</td>\n" .
+ " </tr>\n";
+
+ $i++;
+}
+print
+" </table>\n" .
+" </td>\n";
+
+$deleveraged == 1 ?
+ print " <td style=\"text-align: center; color: #870214;\">True</td>" :
+ print " <td style=\"text-align: center\">False</td>";
+$lumberjackstack == 1 ?
+ print " <td style=\"text-align: center; color: #870214;\">True</td>" :
+ print " <td style=\"text-align: center\">False</td>";
+$blacklisted == 1 ?
+ print " <td style=\"text-align: center; color: #870214;\">True</td>" :
+ print " <td style=\"text-align: center\">False</td>";
+
+echo <<< EOQ
+</tr>
+</table>
+
+<a name="results_top"></a>
+<div class="seq_frame_head">
+<table class="radtag">
+<tr>
+ <th style="width: 5%;"> </th>
+ <th style="width: 15%;">Relationship</th>
+ <th style="width: 20%;">Seq ID</th>
+ <th style="width: 60%;">Sequence</th>
+</tr>
+
+EOQ;
+
+$con_len = isset($seqs['consensus'][0]) ? strlen($seqs['consensus'][0]['s']) : 0;
+$con_seq = isset($seqs['consensus'][0]) ? $seqs['consensus'][0]['s'] : "";
+
+$s = print_scale($con_len);
+print
+ "<tr>\n" .
+ " <td class=\"num\"> </td>\n" .
+ " <td class=\"con\"> </td>\n" .
+ " <td class=\"id\"> </td>\n" .
+ " <td class=\"tag\">" . $s . "</td>\n" .
+ "</tr>\n";
+
+$s = print_snps($display['tag_id'], $con_seq, $con_seq, $snps, false);
+print
+ "<tr>\n" .
+ " <td class=\"num\"> </td>\n" .
+ " <td class=\"con\">consensus</td>\n" .
+ " <td class=\"id\">" . (isset($seqs['consensus'][0]) ? $seqs['consensus'][0]['id'] : "") . "</td>\n" .
+ " <td class=\"tag\">" . $s . "</td>\n" .
+ "</tr>\n";
+
+$s = isset($seqs['model'][0]) ? $seqs['model'][0]['s'] : "";
+echo <<< EOQ
+</table>
+</div>
+<div class="seq_frame">
+<table class="radtag">
+<tr>
+ <td class="num"> </td>
+ <td class="con">model</td>
+ <td class="id"></td>
+ <td class="tag">$s</td>
+</tr>
+
+EOQ;
+
+$i = 1;
+foreach (array('primary', 'secondary') as $key) {
+ foreach ($seqs[$key] as $seq) {
+ $s = print_snps_errs($con_seq, $seq['s'], $snps, $cat_snps);
+
+ if ($key == "primary" && $seq['sub_id'] % 2 == 1)
+ $bg = "style=\"background-color: #dddddd;\"";
+ else
+ $bg = "";
+
+ print
+ "<tr>\n" .
+ " <td class=\"num\">$i</td>\n" .
+ " <td class=\"$key\">$key</td>\n" .
+ " <td class=\"id\">$seq[id]</td>\n" .
+ " <td class=\"tag\"$bg>$s</td>\n" .
+ "</tr>\n";
+ $i++;
+ }
+}
+
+echo <<< EOQ
+</table>
+</div>
+</div>
+
+EOQ;
+
+write_footer();
+
+?>
diff --git a/php/tags.php b/php/tags.php
index de25f4d..bf9e4c2 100644
--- a/php/tags.php
+++ b/php/tags.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2010, Julian Catchen <jcatchen at uoregon.edu>
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -40,7 +40,7 @@ $display['filter_type'] = array();
//
// Process the filtering parameters
//
-$param = array($batch_id, $sample_id);
+$param = array();
process_filter($display);
prepare_filter_parameters($display, $param);
@@ -51,40 +51,43 @@ $query =
"SELECT batches.id as id, date, description, samples.id as sample_id, file FROM batches " .
"JOIN samples ON (batch_id=batches.id) " .
"WHERE batches.id=? AND samples.id=?";
-$db['batch_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['batch_sth'], __FILE__, __LINE__);
+if (!($db['batch_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT COUNT(tag_id) as count FROM tag_index " .
"WHERE batch_id=? AND sample_id=?";
$query .= apply_query_filters($display);
-$db['count_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['count_sth'], __FILE__, __LINE__);
+if (!($db['count_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT depth as count FROM tag_index " .
"WHERE batch_id=? AND sample_id=? AND tag_id=?";
-$db['depth_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['depth_sth'], __FILE__, __LINE__);
+if (!($db['depth_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$query =
"SELECT col, rank_2 FROM snps " .
"JOIN samples ON (snps.sample_id=samples.id) " .
"JOIN batches ON (samples.batch_id=batches.id) " .
"WHERE snps.type='E' AND batch_id=? AND snps.sample_id=? AND tag_id=? ORDER BY col";
-$db['snp_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['snp_sth'], __FILE__, __LINE__);
+if (!($db['snp_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
//
// Pull information about this batch
//
-$result = $db['batch_sth']->execute(array($batch_id, $sample_id));
-check_db_error($result, __FILE__, __LINE__);
-$row = $result->fetchRow();
-$batch = array();
-$batch['id'] = $row['id'];
-$batch['desc'] = $row['description'];
-$batch['date'] = $row['date'];
+if (!$db['batch_sth']->bind_param("ii", $batch_id, $sample_id))
+ write_db_error($db['batch_sth'], __FILE__, __LINE__);
+if (!$db['batch_sth']->execute())
+ write_db_error($db['batch_sth'], __FILE__, __LINE__);
+$res = $db['batch_sth']->get_result();
+$row = $res->fetch_assoc();
+$batch = array();
+$batch['id'] = $row['id'];
+$batch['desc'] = $row['description'];
+$batch['date'] = $row['date'];
$batch['sample_id'] = $row['sample_id'];
$batch['file'] = $row['file'];
@@ -120,9 +123,15 @@ EOQ;
// Figure out how many results there are (including filtering)
// and write out the proper pagination links
//
-$result = $db['count_sth']->execute($param);
-check_db_error($result, __FILE__, __LINE__);
-$row = $result->fetchRow();
+array_unshift($param, $db['count_sth']);
+call_user_func_array("mysqli_stmt_bind_param", $param);
+array_shift($param);
+
+if (!$db['count_sth']->execute())
+ write_db_error($db['count_sth'], __FILE__, __LINE__);
+$res = $db['count_sth']->get_result();
+$row = $res->fetch_assoc();
+
$pagination_count = $row['count'];
$start_group = 0;
$end_group = 0;
@@ -142,9 +151,6 @@ echo <<< EOQ
EOQ;
-$db['dbh']->setLimit($display['pp'], $start_group - 1);
-check_db_error($db['dbh'], __FILE__, __LINE__);
-
$query =
"SELECT con_tag_id as id, tag_index.tag_id as tag_id, " .
"depth, seq, catalog_id, " .
@@ -153,20 +159,34 @@ $query =
"JOIN unique_tags ON (con_tag_id=unique_tags.id) " .
"WHERE tag_index.batch_id=? AND tag_index.sample_id=?";
$query .= apply_query_filters($display);
+$query .= " LIMIT " . ($start_group - 1) . ", " . $display['pp'];
+if (!($db['tag_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
-$db['tag_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['tag_sth'], __FILE__, __LINE__);
-$result = $db['tag_sth']->execute($param);
-check_db_error($result, __FILE__, __LINE__);
+array_unshift($param, $db['tag_sth']);
+call_user_func_array("mysqli_stmt_bind_param", $param);
+array_shift($param);
-while ($row = $result->fetchRow()) {
+if (!$db['tag_sth']->execute())
+ write_db_error($db['tag_sth'], __FILE__, __LINE__);
+$res = $db['tag_sth']->get_result();
+$tag_id = 0;
+if (!$db['snp_sth']->bind_param("iii", $batch_id, $sample_id, $tag_id))
+ write_db_error($db['snp_sth'], __FILE__, __LINE__);
+
+while ($row = $res->fetch_assoc()) {
+ $tag_id = $row['tag_id'];
+ //
// Query the database to find how many SNPs were found in this sample.
+ //
$snps = array();
- $snp_res = $db['snp_sth']->execute(array($batch_id, $sample_id, $row['tag_id']));
- check_db_error($snp_res, __FILE__, __LINE__);
- while ($snp_row = $snp_res->fetchRow()) {
- array_push($snps, array('col' => $snp_row['col'], 'rank' => $snp_row['rank_2']));
+ if (!$db['snp_sth']->execute())
+ write_db_error($db['snp_sth'], __FILE__, __LINE__);
+ $snp_res = $db['snp_sth']->get_result();
+
+ while ($snp_row = $snp_res->fetch_assoc()) {
+ array_push($snps, array('col' => $snp_row['col'], 'rank' => $snp_row['rank_2']));
}
print
@@ -187,9 +207,9 @@ while ($row = $result->fetchRow()) {
$row['catalog_id'] > 0 ?
print
- " <td><a href=\"$root_path/catalog.php?db=$database&id=$batch_id&filter_type[]=cata&filter_cata=$row[catalog_id]\">$row[catalog_id]</a></td>\n" :
+ " <td><a href=\"$root_path/catalog.php?db=$database&id=$batch_id&filter_type[]=cata&filter_cata=$row[catalog_id]\">$row[catalog_id]</a></td>\n" :
print
- " <td><span style=\"color: #888888; font-weight: bold;\">absent</span></td>\n";
+ " <td><span style=\"color: #888888; font-weight: bold;\">absent</span></td>\n";
print "</tr>\n";
}
@@ -405,10 +425,10 @@ EOQ;
" <span class=\"s\">($num_tags tags)</span>\n" .
"</td>\n";
- if ($num_pages > 1)
- $page_list = generate_page_list($page, $num_pages, $destination);
-
- print $page_list;
+ if ($num_pages > 1) {
+ $page_list = generate_page_list($page, $num_pages, $destination);
+ print $page_list;
+ }
$hidden_vars = generate_hidden_form_vars("pp");
$per_page_ctl = generate_per_page_select("pp", $display['pp']);
@@ -565,33 +585,51 @@ function process_filter(&$display_params) {
}
}
-function prepare_filter_parameters($display_params, &$param) {
+function prepare_filter_parameters(&$display_params, &$param) {
$filters = $display_params['filter_type'];
- if (!isset($filters))
- return;
+ $param[] = &$display_params['batch_id'];
+ $param[] = &$display_params['sample_id'];
+ $typestr = "ii";
+
+ if (!isset($filters)) {
+ array_unshift($param, $typestr);
+ return;
+ }
foreach ($filters as $filter) {
if ($filter == "snps") {
- array_push($param, $display_params['filter_snps']);
+ $param[] = &$display_params['filter_snps'];
+ $typestr .= "i";
} else if ($filter == "depth") {
- array_push($param, $display_params['filter_depth']);
+ $param[] = &$display_params['filter_depth'];
+ $typestr .= "i";
+
} else if ($filter == "tagid") {
- array_push($param, $display_params['filter_tagid']);
+ $param[] = &$display_params['filter_tagid'];
+ $typestr .= "i";
+
} else if ($filter == "delv") {
- array_push($param, $display_params['filter_delv']);
+ $param[] = &$display_params['filter_delv'];
+ $typestr .= "i";
+
} else if ($filter == "black") {
- array_push($param, $display_params['filter_black']);
+ $param[] = &$display_params['filter_black'];
+ $typestr .= "i";
+
} else if ($filter == "rem") {
- array_push($param, $display_params['filter_rem']);
+ $param[] = &$display_params['filter_rem'];
+ $typestr .= "i";
}
}
+
+ array_unshift($param, $typestr);
}
function apply_query_filters($display_params) {
diff --git a/php/view_sequence.php b/php/view_sequence.php
index 0dfaf83..d3837a9 100644
--- a/php/view_sequence.php
+++ b/php/view_sequence.php
@@ -1,6 +1,6 @@
<?php
//
-// Copyright 2010, Julian Catchen <jcatchen at uoregon.edu>
+// Copyright 2010-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -36,17 +36,20 @@ $display['seq_id'] = $seq_id;
$query =
"SELECT id, catalog_id, seq_id, type, seq FROM sequence " .
"WHERE id=?";
-$db['seq_sth'] = $db['dbh']->prepare($query);
-check_db_error($db['seq_sth'], __FILE__, __LINE__);
+if (!($db['seq_sth'] = $db['dbh']->prepare($query)))
+ write_db_error($db['dbh'], __FILE__, __LINE__);
$page_title = "Catalog RAD-Tag Sequence Viewer";
write_compact_header($page_title);
-$result = $db['seq_sth']->execute($seq_id);
-check_db_error($result, __FILE__, __LINE__);
+if (!$db['seq_sth']->bind_param("i", $seq_id))
+ write_db_error($db['seq_sth'], __FILE__, __LINE__);
+if (!$db['seq_sth']->execute())
+ write_db_error($db['seq_sth'], __FILE__, __LINE__);
+$res = $db['seq_sth']->get_result();
-$row = $result->fetchRow();
+$row = $res->fetch_assoc();
//
// Line wrap the sequence to 80 characters
diff --git a/scripts/convert_stacks.pl b/scripts/convert_stacks.pl
old mode 100644
new mode 100755
diff --git a/scripts/denovo_map.pl b/scripts/denovo_map.pl
old mode 100644
new mode 100755
index 7f7d142..858d80c
--- a/scripts/denovo_map.pl
+++ b/scripts/denovo_map.pl
@@ -215,12 +215,13 @@ foreach $sample (@parents, @progeny, @samples) {
$sample_id++ if ($sql == 0);
}
-my ($rid, $pfile, $parents, $cat_file);
+my ($pfile, $cat_file);
#
# Generate catalog of RAD-Tags
#
print STDERR "Generating catalog...\n";
+my $file_paths = "";
foreach $sample (@parents, @samples) {
my ($prefix, $suffix) = ($sample =~ /^(.+)\.(.+)$/);
@@ -234,11 +235,11 @@ foreach $sample (@parents, @samples) {
$pfile = $prefix;
}
- $parents .= "-s $out_path/$pfile ";
+ $file_paths .= "-s $out_path/$pfile ";
}
$cat_file = "batch_" . $batch_id;
-$cmd = $exe_path . "cstacks -b $batch_id -o $out_path $parents " . join(" ", @_cstacks) . " 2>&1";
+$cmd = $exe_path . "cstacks -b $batch_id -o $out_path $file_paths " . join(" ", @_cstacks) . " 2>&1";
print STDERR " $cmd\n";
print $log_fh "$cmd\n";
@@ -278,8 +279,8 @@ print STDERR "done.\n" if ($sql == 1);
#
# Match parents and progeny to the catalog
#
-$i = 1;
-$num_files = scalar(@parents) + scalar(@progeny) + scalar(@samples);
+$file_paths = "";
+print STDERR "Matching samples to the catalog...\n";
foreach $sample (@parents, @progeny, @samples) {
@@ -295,27 +296,49 @@ foreach $sample (@parents, @progeny, @samples) {
$pfile = $prefix;
}
- printf(STDERR "Matching samples to catalog; file % 3s of % 3s [%s]\n", $i, $num_files, $pfile);
+ $file_paths .= "-s $out_path/$pfile ";
+}
- $cmd = $exe_path . "sstacks -b $batch_id -c $out_path/$cat_file -s $out_path/$pfile -o $out_path " . join(" ", @_sstacks) . " 2>&1";
- print STDERR " $cmd\n";
- print $log_fh "$cmd\n";
- @results = `$cmd` if ($dry_run == 0);
- print $log_fh @results;
+$cmd = $exe_path . "sstacks -b $batch_id -c $out_path/$cat_file -o $out_path $file_paths " . join(" ", @_sstacks) . " 2>&1";
+print STDERR " $cmd\n";
+print $log_fh "$cmd\n";
+ at results = `$cmd` if ($dry_run == 0);
+print $log_fh @results;
- print STDERR " Loading sstacks output to $db..." if ($sql == 1);
+#
+# Load the sstacks results to the database if requested.
+#
+if ($sql == 1) {
+ $i = 1;
+ $num_files = scalar(@parents) + scalar(@progeny) + scalar(@samples);
- if ($gzip == 1) {
- $file = "$out_path/" . $pfile . ".matches.tsv.gz";
- import_gzsql_file($log_fh, $file, "matches", 1);
+ foreach $sample (@parents, @progeny, @samples) {
- } else {
- $file = "$out_path/" . $pfile . ".matches.tsv";
- import_sql_file($log_fh, $file, "matches", 1);
- }
- print STDERR "done.\n" if ($sql == 1);
+ my ($prefix, $suffix) = ($sample =~ /^(.+)\.(.+)$/);
- $i++;
+ if ($suffix eq "gz") {
+ ($prefix, $suffix) = ($prefix =~ /^(.+)\.(.+)$/);
+ }
+
+ if ($prefix =~ /^.*\/.+$/) {
+ ($pfile) = ($prefix =~ /^.*\/(.+)$/);
+ } else {
+ $pfile = $prefix;
+ }
+
+ printf(STDERR "Loading sstacks output to $db; file % 3s of % 3s [%s]\n", $i, $num_files, $pfile);
+
+ if ($gzip == 1) {
+ $file = "$out_path/" . $pfile . ".matches.tsv.gz";
+ import_gzsql_file($log_fh, $file, "matches", 1);
+
+ } else {
+ $file = "$out_path/" . $pfile . ".matches.tsv";
+ import_sql_file($log_fh, $file, "matches", 1);
+ }
+
+ $i++;
+ }
}
if ($data_type eq "map") {
diff --git a/scripts/exec_velvet.pl b/scripts/exec_velvet.pl
old mode 100644
new mode 100755
diff --git a/scripts/export_sql.pl b/scripts/export_sql.pl
old mode 100644
new mode 100755
diff --git a/scripts/extract_interpop_chars.pl b/scripts/extract_interpop_chars.pl
old mode 100644
new mode 100755
diff --git a/scripts/index_radtags.pl b/scripts/index_radtags.pl
old mode 100644
new mode 100755
diff --git a/scripts/load_radtags.pl b/scripts/load_radtags.pl
old mode 100644
new mode 100755
diff --git a/scripts/load_sequences.pl b/scripts/load_sequences.pl
old mode 100644
new mode 100755
diff --git a/scripts/ref_map.pl b/scripts/ref_map.pl
old mode 100644
new mode 100755
index 70bbdd9..0448dcb
--- a/scripts/ref_map.pl
+++ b/scripts/ref_map.pl
@@ -197,12 +197,14 @@ foreach $sample (@parents, @progeny, @samples) {
$sample_id++ if ($sql == 0);
}
-my ($rid, $pfile, $parents, $cat_file);
+my ($pfile, $cat_file);
#
# Generate catalog of RAD-Tags
#
print STDERR "Generating catalog...\n";
+my $file_paths = "";
+
foreach $sample (@parents, @samples) {
my ($prefix, $suffix) = ($sample =~ /^(.+)\.(.+)$/);
@@ -212,11 +214,11 @@ foreach $sample (@parents, @samples) {
$pfile = $prefix;
}
- $parents .= "-s $out_path/$pfile ";
+ $file_paths .= "-s $out_path/$pfile ";
}
$cat_file = "batch_" . $batch_id;
-$cmd = $exe_path . "cstacks -g -b $batch_id -o $out_path $parents " . join(" ", @_cstacks) . " 2>&1";
+$cmd = $exe_path . "cstacks -g -b $batch_id -o $out_path $file_paths " . join(" ", @_cstacks) . " 2>&1";
print STDERR " $cmd\n";
print $log_fh "$cmd\n";
@@ -256,8 +258,8 @@ print STDERR "done.\n" if ($sql == 1);
#
# Match parents and progeny to the catalog
#
-$i = 1;
-$num_files = scalar(@parents) + scalar(@progeny) + scalar(@samples);
+$file_paths = "";
+print STDERR "Matching samples to the catalog...\n";
foreach $sample (@parents, @progeny, @samples) {
@@ -269,29 +271,45 @@ foreach $sample (@parents, @progeny, @samples) {
$pfile = $prefix;
}
- printf(STDERR "Matching samples to catalog; file % 3s of % 3s [%s]\n", $i, $num_files, $pfile);
+ $file_paths .= "-s $out_path/$pfile ";
+}
- $rid = $map{$pfile};
+$cmd = $exe_path . "sstacks -g -b $batch_id -c $out_path/$cat_file -o $out_path $file_paths " . join(" ", @_sstacks) . " 2>&1";
+print STDERR " $cmd\n";
+print $log_fh "$cmd\n";
+ at results = `$cmd` if ($dry_run == 0);
+print $log_fh @results;
- $cmd = $exe_path . "sstacks -g -b $batch_id -c $out_path/$cat_file -s $out_path/$pfile -o $out_path " . join(" ", @_sstacks) . " 2>&1";
- print STDERR " $cmd\n";
- print $log_fh "$cmd\n";
- @results = `$cmd` if ($dry_run == 0);
- print $log_fh @results;
+#
+# Load the sstacks results to the database if requested.
+#
+if ($sql == 1) {
+ $i = 1;
+ $num_files = scalar(@parents) + scalar(@progeny) + scalar(@samples);
- print STDERR " Loading sstacks output to $db..." if ($sql == 1);
+ foreach $sample (@parents, @progeny, @samples) {
- if ($gzip == 1) {
- $file = "$out_path/" . $pfile . ".matches.tsv.gz";
- import_gzsql_file($log_fh, $file, "matches", 1);
+ my ($prefix, $suffix) = ($sample =~ /^(.+)\.(.+)$/);
- } else {
- $file = "$out_path/" . $pfile . ".matches.tsv";
- import_sql_file($log_fh, $file, "matches", 1);
- }
- print STDERR "done.\n" if ($sql == 1);
+ if ($prefix =~ /^.*\/.+$/) {
+ ($pfile) = ($prefix =~ /^.*\/(.+)$/);
+ } else {
+ $pfile = $prefix;
+ }
- $i++;
+ printf(STDERR "Loading sstacks output to $db; file % 3s of % 3s [%s]\n", $i, $num_files, $pfile);
+
+ if ($gzip == 1) {
+ $file = "$out_path/" . $pfile . ".matches.tsv.gz";
+ import_gzsql_file($log_fh, $file, "matches", 1);
+
+ } else {
+ $file = "$out_path/" . $pfile . ".matches.tsv";
+ import_sql_file($log_fh, $file, "matches", 1);
+ }
+
+ $i++;
+ }
}
if ($data_type eq "map") {
diff --git a/scripts/sort_read_pairs.pl b/scripts/sort_read_pairs.pl
old mode 100644
new mode 100755
diff --git a/scripts/stacks_export_notify.pl b/scripts/stacks_export_notify.pl
old mode 100644
new mode 100755
diff --git a/src/BamI.h b/src/BamI.h
index d9e14e6..a769089 100644
--- a/src/BamI.h
+++ b/src/BamI.h
@@ -1,6 +1,6 @@
// -*-mode:c++; c-style:k&r; c-basic-offset:4;-*-
//
-// Copyright 2013, Julian Catchen <jcatchen at uoregon.edu>
+// Copyright 2013-2016, Julian Catchen <jcatchen at illinois.edu>
//
// This file is part of Stacks.
//
@@ -292,14 +292,17 @@ Bam::find_start_bp_pos(int aln_bp, vector<pair<char, uint> > &cigar)
int
Bam::edit_gaps(vector<pair<char, uint> > &cigar, char *seq)
{
- char buf[id_len];
- uint size = cigar.size();
- char op;
- uint dist, bp, len, buf_len, j, k, stop;
+ char *buf;
+ uint size = cigar.size();
+ char op;
+ uint dist, bp, len, buf_len, buf_size, j, k, stop;
len = strlen(seq);
bp = 0;
+ buf = new char[len + 1];
+ buf_size = len + 1;
+
for (uint i = 0; i < size; i++) {
op = cigar[i].first;
dist = cigar[i].second;
@@ -319,8 +322,10 @@ Bam::edit_gaps(vector<pair<char, uint> > &cigar, char *seq)
// Pad the read with sufficent Ns to match the deletion, shifting the existing
// sequence down. Trim the final length to keep the read length consistent.
//
- strncpy(buf, seq + bp, id_len - 1);
- buf[id_len - 1] = '\0';
+ k = bp >= len ? len : bp;
+
+ strncpy(buf, seq + k, buf_size - 1);
+ buf[buf_size - 1] = '\0';
buf_len = strlen(buf);
stop = bp + dist;
@@ -341,12 +346,14 @@ Bam::edit_gaps(vector<pair<char, uint> > &cigar, char *seq)
case 'I':
//
// An insertion has occurred in the read relative to the reference genome. Delete the
- // inserted bases and padd the end of the read with Ns.
+ // inserted bases and pad the end of the read with Ns.
//
- k = bp + dist;
- strncpy(buf, seq + k, id_len - 1);
- buf[id_len - 1] = '\0';
- buf_len = strlen(buf);
+ if (bp >= len) break;
+
+ k = bp + dist > len ? len : bp + dist;
+ strncpy(buf, seq + k, buf_size - 1);
+ buf[buf_size - 1] = '\0';
+ buf_len = strlen(buf);
j = bp;
k = 0;
@@ -366,9 +373,13 @@ Bam::edit_gaps(vector<pair<char, uint> > &cigar, char *seq)
case 'M':
bp += dist;
break;
+ default:
+ break;
}
}
+ delete [] buf;
+
return 0;
}
diff --git a/src/FastaI.h b/src/FastaI.h
index 7a9b8bd..e50a36c 100644
--- a/src/FastaI.h
+++ b/src/FastaI.h
@@ -71,7 +71,8 @@ Seq *Fasta::next_seq() {
len = strlen(this->line);
if (this->line[len - 1] == '\r') this->line[len - 1] = '\0';
- this->buf += this->line;
+ this->buf += this->line;
+ this->line[0] = '\0';
this->fh.getline(this->line, max_len);
}
@@ -124,7 +125,8 @@ int Fasta::next_seq(Seq &s) {
len = strlen(this->line);
if (len > 0 && this->line[len - 1] == '\r') this->line[len - 1] = '\0';
- this->buf += this->line;
+ this->buf += this->line;
+ this->line[0] = '\0';
this->fh.getline(this->line, max_len);
}
diff --git a/src/catalog_utils.cc b/src/catalog_utils.cc
index 52c36b6..b01316e 100644
--- a/src/catalog_utils.cc
+++ b/src/catalog_utils.cc
@@ -289,7 +289,7 @@ reduce_catalog_snps(map<int, CSLocus *> &catalog, map<int, set<int> > &whitelist
// for this locus to account for the pruned SNPs.
//
for (it = loc->alleles.begin(); it != loc->alleles.end(); it++) {
- strncpy(allele_old, it->first.c_str(), id_len - 2);
+ strncpy(allele_old, it->first.c_str(), id_len - 1);
allele_old[id_len - 1] = '\0';
for (uint k = 0; k < cols.size(); k++)
diff --git a/src/clone_filter.cc b/src/clone_filter.cc
index 4c1d99a..9a3b2fc 100644
--- a/src/clone_filter.cc
+++ b/src/clone_filter.cc
@@ -128,10 +128,11 @@ int main (int argc, char* argv[]) {
map<int, int> clone_dist;
vector<char *> clone_map_keys;
+ int result = 1;
for (uint i = 0; i < files.size(); i++) {
cerr << "Processing file " << i+1 << " of " << files.size() << " [" << files[i].first.c_str() << "]\n";
- int result = 1;
+ result = 1;
if (paired) {
if (barcode_type == null_null)
result = process_paired_reads_by_sequence(files[i].first, files[i].second, counters, clone_map, clone_map_keys);
@@ -148,8 +149,9 @@ int main (int argc, char* argv[]) {
}
}
- if (barcode_type == null_null) {
+ if (barcode_type == null_null && result) {
write_clonereduced_sequence(files[0].first, files[0].second, clone_map, clone_dist, counters);
+
} else {
for (OligoHash::iterator i = oligo_map.begin(); i != oligo_map.end(); i++)
for (map<string, uint16_t>::iterator j = i->second.begin(); j != i->second.end(); j++)
@@ -200,24 +202,34 @@ process_paired_reads_by_sequence(string prefix_1, string prefix_2, map<string, l
<< path_1 << " and\n "
<< path_2 << "\n";
- if (in_file_type == FileT::fastq) {
+ switch (in_file_type) {
+ case FileT::fastq:
fh_1 = new Fastq(path_1);
- fh_2 = new Fastq(path_2);
- } else if (in_file_type == FileT::fasta) {
- fh_1 = new Fasta(path_1);
- fh_2 = new Fasta(path_2);
- } else if (in_file_type == FileT::gzfastq) {
+ fh_2 = interleaved ? fh_1 : new Fastq(path_2);
+ break;
+ case FileT::gzfastq:
fh_1 = new GzFastq(path_1);
- fh_2 = new GzFastq(path_2);
- } else if (in_file_type == FileT::gzfasta) {
+ fh_2 = interleaved ? fh_1 : new GzFastq(path_2);
+ break;
+ case FileT::fasta:
+ fh_1 = new Fasta(path_1);
+ fh_2 = interleaved ? fh_1 : new Fasta(path_2);
+ break;
+ case FileT::gzfasta:
fh_1 = new GzFasta(path_1);
- fh_2 = new GzFasta(path_2);
- } else if (in_file_type == FileT::bustard) {
- fh_1 = new Bustard(path_1.c_str());
- fh_2 = new Bustard(path_2.c_str());
- } else {
- fh_1 = NULL;
- fh_2 = NULL;
+ fh_2 = interleaved ? fh_1 : new GzFasta(path_2);
+ break;
+ case FileT::bam:
+ fh_1 = new BamUnAln(path_1);
+ fh_2 = fh_1;
+ break;
+ case FileT::bustard:
+ fh_1 = new Bustard(path_1);
+ fh_2 = interleaved ? fh_1 : new Bustard(path_2);
+ default:
+ fh_1 = NULL;
+ fh_2 = NULL;
+ break;
}
//
@@ -227,7 +239,7 @@ process_paired_reads_by_sequence(string prefix_1, string prefix_2, map<string, l
Seq *s_2 = fh_2->next_seq();
if (s_1 == NULL || s_2 == NULL) {
cerr << "Unable to allocate Seq object.\n";
- return -1;
+ return 0;
}
long i = 1;
@@ -250,9 +262,11 @@ process_paired_reads_by_sequence(string prefix_1, string prefix_2, map<string, l
clone_map_keys.push_back(hash_key);
}
- if (out_file_type == FileT::fastq)
- clone_map[hash_key][s_2->seq].push_back(Pair(s_1->id, s_2->id, s_1->qual, s_2->qual));
- else if (out_file_type == FileT::fasta)
+ if (out_file_type == FileT::fastq ||
+ out_file_type == FileT::gzfastq)
+ clone_map[hash_key][s_2->seq].push_back(Pair(s_1->id, s_2->id, s_1->qual, s_2->qual));
+ else if (out_file_type == FileT::fasta ||
+ out_file_type == FileT::gzfasta)
clone_map[hash_key][s_2->seq].push_back(Pair(s_1->id, s_2->id));
delete s_1;
@@ -276,7 +290,7 @@ write_clonereduced_sequence(string prefix_1, string prefix_2,
map<string, long> &counters)
{
ofstream out_fh_1, out_fh_2, discard_fh_1, discard_fh_2;
- gzFile out_gzfh_1, out_gzfh_2;
+ gzFile out_gzfh_1, out_gzfh_2, discard_gzfh_1, discard_gzfh_2;
int return_val = 1;
@@ -305,15 +319,9 @@ write_clonereduced_sequence(string prefix_1, string prefix_2,
suffix_2 = ".2.fa";
}
- string file_1 = prefix_1;
- int pos = file_1.find_last_of(".");
- if ((in_file_type == FileT::gzfastq || in_file_type == FileT::gzfasta) &&
- file_1.substr(pos) == ".gz") {
- file_1 = file_1.substr(0, pos);
- pos = file_1.find_last_of(".");
- }
+ string file_1 = remove_suffix(in_file_type, prefix_1);
path_1 = out_path + file_1 + suffix_1;
- if (in_file_type == FileT::gzfastq || in_file_type == FileT::gzfasta) {
+ if (out_file_type == FileT::gzfastq || out_file_type == FileT::gzfasta) {
out_gzfh_1 = gzopen(path_1.c_str(), "wb");
if (!(out_gzfh_1)) {
cerr << "Error opening output file '" << path_1 << "'\n";
@@ -327,15 +335,9 @@ write_clonereduced_sequence(string prefix_1, string prefix_2,
}
}
- string file_2 = prefix_2;
- pos = file_2.find_last_of(".");
- if ((in_file_type == FileT::gzfastq || in_file_type == FileT::gzfasta) &&
- file_2.substr(pos) == ".gz") {
- file_2 = file_2.substr(0, pos);
- pos = file_2.find_last_of(".");
- }
+ string file_2 = remove_suffix(in_file_type, prefix_2);
path_2 = out_path + file_2 + suffix_2;
- if (in_file_type == FileT::gzfastq || in_file_type == FileT::gzfasta) {
+ if (out_file_type == FileT::gzfastq || out_file_type == FileT::gzfasta) {
out_gzfh_2 = gzopen(path_2.c_str(), "wb");
if (!(out_gzfh_2)) {
cerr << "Error opening output file '" << path_2 << "'\n";
@@ -354,119 +356,140 @@ write_clonereduced_sequence(string prefix_1, string prefix_2,
//
if (discards) {
path_1 = out_path + file_1 + ".discards" + suffix_1;
- discard_fh_1.open(path_1.c_str(), ifstream::out);
-
- if (discard_fh_1.fail()) {
- cerr << "Error opening discard output file '" << path_1 << "'\n";
- return -1;
- }
+ if (out_file_type == FileT::gzfastq || out_file_type == FileT::gzfasta) {
+ discard_gzfh_1 = gzopen(path_1.c_str(), "wb");
+ if (!(discard_gzfh_1)) {
+ cerr << "Error opening output file '" << path_1 << "'\n";
+ return -1;
+ }
+ } else {
+ discard_fh_1.open(path_1.c_str(), ifstream::out);
+ if (discard_fh_1.fail()) {
+ cerr << "Error opening discard output file '" << path_1 << "'\n";
+ return -1;
+ }
+ }
path_2 = out_path + file_2 + ".discards" + suffix_2;
- discard_fh_2.open(path_2.c_str(), ifstream::out);
-
- if (discard_fh_2.fail()) {
- cerr << "Error opening discard output file '" << path_2 << "'\n";
- return -1;
- }
+ if (out_file_type == FileT::gzfastq || out_file_type == FileT::gzfasta) {
+ discard_gzfh_2 = gzopen(path_2.c_str(), "wb");
+ if (!(discard_gzfh_2)) {
+ cerr << "Error opening output file '" << path_2 << "'\n";
+ return -1;
+ }
+ } else {
+ discard_fh_2.open(path_2.c_str(), ifstream::out);
+ if (discard_fh_2.fail()) {
+ cerr << "Error opening discard output file '" << path_2 << "'\n";
+ return -1;
+ }
+ }
}
CloneHash::iterator hash_it;
map<string, vector<Pair> >::iterator map_it;
- stringstream sstr;
+ stringstream sstr_1, sstr_2;
- cerr << "Writing filtered data...";
+ cerr << "Writing filtered data...\n";
for (hash_it = clone_map.begin(); hash_it != clone_map.end(); hash_it++) {
for (map_it = hash_it->second.begin(); map_it != hash_it->second.end(); map_it++) {
-
- if (out_file_type == FileT::gzfastq) {
- sstr.str();
- sstr << "@" << map_it->second[0].p1_id << "\n"
- << hash_it->first << "\n"
- << "+\n"
- << map_it->second[0].p1_qual << "\n";
- gzputs(out_gzfh_1, sstr.str().c_str());
- sstr.str();
- sstr << "@" << map_it->second[0].p2_id << "\n"
- << map_it->first << "\n"
- << "+\n"
- << map_it->second[0].p2_qual << "\n";
- gzputs(out_gzfh_2, sstr.str().c_str());
-
- } else if (out_file_type == FileT::fastq) {
- out_fh_1 << "@" << map_it->second[0].p1_id << "\n"
- << hash_it->first << "\n"
- << "+\n"
- << map_it->second[0].p1_qual << "\n";
- out_fh_2 << "@" << map_it->second[0].p2_id << "\n"
- << map_it->first << "\n"
- << "+\n"
- << map_it->second[0].p2_qual << "\n";
-
- } else if (out_file_type == FileT::gzfasta) {
- sstr.str();
- sstr <<
- ">" <<
- map_it->second[0].p1_id << "\n" <<
- hash_it->first << "\n";
- gzputs(out_gzfh_1, sstr.str().c_str());
- sstr.str();
- sstr <<
- ">" <<
- map_it->second[0].p2_id << "\n" <<
- map_it->first << "\n";
- gzputs(out_gzfh_2, sstr.str().c_str());
-
- } else if (out_file_type == FileT::fasta) {
- out_fh_1 << ">" << map_it->second[0].p1_id << "\n"
- << hash_it->first << "\n";
- out_fh_2 << ">" << map_it->second[0].p2_id << "\n"
- << map_it->first << "\n";
-
- }
-
+ sstr_1.str("");
+ sstr_2.str("");
+
+ if (out_file_type == FileT::gzfastq || out_file_type == FileT::fastq) {
+ sstr_1 << "@" << map_it->second[0].p1_id << "\n"
+ << hash_it->first << "\n"
+ << "+\n"
+ << map_it->second[0].p1_qual << "\n";
+ sstr_2 << "@" << map_it->second[0].p2_id << "\n"
+ << map_it->first << "\n"
+ << "+\n"
+ << map_it->second[0].p2_qual << "\n";
+ } else {
+ sstr_1 << ">" << map_it->second[0].p1_id << "\n"
+ << hash_it->first << "\n";
+ sstr_2 << ">" << map_it->second[0].p2_id << "\n"
+ << map_it->first << "\n";
+ }
+
+ switch(out_file_type) {
+ case FileT::gzfastq:
+ case FileT::gzfasta:
+ gzputs(out_gzfh_1, sstr_1.str().c_str());
+ gzputs(out_gzfh_2, sstr_2.str().c_str());
+ break;
+ case FileT::fastq:
+ case FileT::fasta:
+ default:
+ out_fh_1 << sstr_2.str();
+ out_fh_2 << sstr_2.str();
+ }
+
counters["dis_reads"] += map_it->second.size() - 1;
clone_dist[map_it->second.size()]++;
//
// Write cloned read pairs that we are discarding
//
- if (discards)
+ if (discards) {
for (uint i = 1; i < map_it->second.size(); i++) {
-
- if (out_file_type == FileT::fasta) {
- discard_fh_1 << ">" << map_it->second[i].p1_id << "\n"
- << hash_it->first << "\n";
- discard_fh_2 << ">" << map_it->second[i].p2_id << "\n"
- << map_it->first << "\n";
-
- } else if (out_file_type == FileT::fastq) {
- discard_fh_1 << "@" << map_it->second[i].p1_id << "\n"
- << hash_it->first << "\n"
- << "+\n"
- << map_it->second[i].p1_qual << "\n";
- discard_fh_2 << "@" << map_it->second[i].p2_id << "\n"
- << map_it->first << "\n"
- << "+\n"
- << map_it->second[i].p2_qual << "\n";
- }
+ sstr_1.str("");
+ sstr_2.str("");
+
+ if (out_file_type == FileT::gzfastq || out_file_type == FileT::fastq) {
+ sstr_1 << "@" << map_it->second[i].p1_id << "\n"
+ << hash_it->first << "\n"
+ << "+\n"
+ << map_it->second[i].p1_qual << "\n";
+ sstr_2 << "@" << map_it->second[i].p2_id << "\n"
+ << map_it->first << "\n"
+ << "+\n"
+ << map_it->second[i].p2_qual << "\n";
+ } else {
+ sstr_1 << ">" << map_it->second[i].p1_id << "\n"
+ << hash_it->first << "\n";
+ sstr_2 << ">" << map_it->second[i].p2_id << "\n"
+ << map_it->first << "\n";
+ }
+
+ switch(out_file_type) {
+ case FileT::gzfastq:
+ case FileT::gzfasta:
+ gzputs(discard_gzfh_1, sstr_1.str().c_str());
+ gzputs(discard_gzfh_2, sstr_2.str().c_str());
+ break;
+ case FileT::fastq:
+ case FileT::fasta:
+ default:
+ discard_fh_1 << sstr_2.str();
+ discard_fh_2 << sstr_2.str();
+ }
}
-
+ }
counters["red_reads"]++;
}
}
cerr << "done.\n";
- out_fh_1.close();
- out_fh_2.close();
-
- if (discards) {
- discard_fh_1.close();
- discard_fh_2.close();
+ if (out_file_type == FileT::gzfastq || out_file_type == FileT::gzfasta) {
+ gzclose(out_gzfh_1);
+ gzclose(out_gzfh_2);
+ if (discards) {
+ gzclose(discard_gzfh_1);
+ gzclose(discard_gzfh_2);
+ }
+ } else {
+ out_fh_1.close();
+ out_fh_2.close();
+ if (discards) {
+ discard_fh_1.close();
+ discard_fh_2.close();
+ }
}
-
+
return return_val;
}
int
@@ -496,7 +519,7 @@ process_paired_reads(string prefix_1, string prefix_2, map<string, long> &counte
fh_2 = interleaved ? fh_1 : new Fastq(path_2);
break;
case FileT::gzfastq:
- fh_1 = new GzFastq(path_1.c_str());
+ fh_1 = new GzFastq(path_1);
fh_2 = interleaved ? fh_1 : new GzFastq(path_2);
break;
case FileT::fasta:
@@ -515,6 +538,8 @@ process_paired_reads(string prefix_1, string prefix_2, map<string, long> &counte
fh_1 = new Bustard(path_1);
fh_2 = interleaved ? fh_1 : new Bustard(path_2);
default:
+ fh_1 = NULL;
+ fh_2 = NULL;
break;
}
@@ -537,14 +562,8 @@ process_paired_reads(string prefix_1, string prefix_2, map<string, long> &counte
suffix_2 = ".2.fa";
}
- string file_1 = prefix_1;
- int pos_1 = file_1.find_last_of(".");
- if ((in_file_type == FileT::gzfastq || in_file_type == FileT::gzfasta) &&
- file_1.substr(pos_1) == ".gz") {
- file_1 = file_1.substr(0, pos_1);
- pos_1 = file_1.find_last_of(".");
- }
- path_1 = out_path + file_1.substr(0, pos_1) + suffix_1;
+ string file_1 = remove_suffix(in_file_type, prefix_1);
+ path_1 = out_path + file_1 + suffix_1;
if (in_file_type == FileT::gzfastq || in_file_type == FileT::gzfasta) {
out_gzfh_1 = gzopen(path_1.c_str(), "wb");
if (!(out_gzfh_1)) {
@@ -559,14 +578,8 @@ process_paired_reads(string prefix_1, string prefix_2, map<string, long> &counte
}
}
- string file_2 = prefix_2;
- int pos_2 = file_2.find_last_of(".");
- if ((in_file_type == FileT::gzfastq || in_file_type == FileT::gzfasta) &&
- file_2.substr(pos_2) == ".gz") {
- file_2 = file_2.substr(0, pos_2);
- pos_2 = file_2.find_last_of(".");
- }
- path_2 = out_path + file_2.substr(0, pos_2) + suffix_2;
+ string file_2 = remove_suffix(in_file_type, prefix_2);
+ path_2 = out_path + file_2 + suffix_2;
if (in_file_type == FileT::gzfastq || in_file_type == FileT::gzfasta) {
out_gzfh_2 = gzopen(path_2.c_str(), "wb");
if (!(out_gzfh_2)) {
@@ -585,7 +598,7 @@ process_paired_reads(string prefix_1, string prefix_2, map<string, long> &counte
// Open files for recording discarded reads.
//
if (discards) {
- path_1 = out_path + file_1.substr(0, pos_1) + ".discards" + suffix_1;
+ path_1 = out_path + file_1 + ".discards" + suffix_1;
if (in_file_type == FileT::gzfastq || in_file_type == FileT::gzfasta) {
discard_gzfh_1 = gzopen(path_1.c_str(), "wb");
@@ -601,7 +614,7 @@ process_paired_reads(string prefix_1, string prefix_2, map<string, long> &counte
}
}
- path_2 = out_path + file_2.substr(0, pos_2) + ".discards" + suffix_2;
+ path_2 = out_path + file_2 + ".discards" + suffix_2;
if (in_file_type == FileT::gzfastq || in_file_type == FileT::gzfasta) {
discard_gzfh_2 = gzopen(path_2.c_str(), "wb");
@@ -1102,7 +1115,7 @@ int parse_command_line(int argc, char* argv[]) {
// Detect the end of the options.
if (c == -1)
break;
-
+
switch (c) {
case 'h':
help();
@@ -1120,10 +1133,14 @@ int parse_command_line(int argc, char* argv[]) {
in_file_type = FileT::fastq;
break;
case 'y':
- if (strcasecmp(optarg, "fasta") == 0)
- out_file_type = FileT::fasta;
- else
+ if (strcasecmp(optarg, "fastq") == 0)
out_file_type = FileT::fastq;
+ else if (strcasecmp(optarg, "gzfastq") == 0)
+ out_file_type = FileT::gzfastq;
+ else if (strcasecmp(optarg, "fasta") == 0)
+ out_file_type = FileT::fasta;
+ else if (strcasecmp(optarg, "gzfasta") == 0)
+ out_file_type = FileT::gzfasta;
break;
case 'D':
discards = true;
@@ -1260,9 +1277,9 @@ void help() {
<< " P: files contained within directory specified by '-p' are paired.\n"
<< " 1: first input file in a set of paired-end sequences.\n"
<< " 2: second input file in a set of paired-end sequences.\n"
- << " i: input file type, either 'bustard' for the Illumina BUSTARD output files, 'fastq', 'fasta', 'gzfasta', or 'gzfastq' (default 'fastq').\n"
+ << " i: input file type, either 'bustard', 'fastq', 'fasta', 'gzfasta', or 'gzfastq' (default 'fastq').\n"
<< " o: path to output the processed files.\n"
- << " y: output type, either 'fastq' or 'fasta' (default fastq).\n"
+ << " y: output type, either 'fastq', 'fasta', 'gzfasta', or 'gzfastq' (default same as input type).\n"
<< " D: capture discarded reads to a file.\n"
<< " h: display this help messsage.\n"
<< " --oligo_len_1 len: length of the single-end oligo sequence in data set.\n"
diff --git a/src/file_io.cc b/src/file_io.cc
index c85f57d..d297a92 100644
--- a/src/file_io.cc
+++ b/src/file_io.cc
@@ -973,3 +973,26 @@ build_file_list(vector<pair<string, string> > &files)
return 0;
}
+string
+remove_suffix(FileT type, string file)
+{
+ int pos = file.find_last_of(".");
+
+ if ((type == FileT::gzfastq || type == FileT::gzfasta) && file.substr(pos) == ".gz")
+ file = file.substr(0, pos);
+
+ pos = file.find_last_of(".");
+
+ if (type == FileT::gzfastq || type == FileT::fastq) {
+
+ if (file.substr(pos) == ".fastq" || file.substr(pos) == ".fq")
+ file = file.substr(0, pos);
+
+ } else if (type == FileT::gzfasta || type == FileT::fasta) {
+
+ if (file.substr(pos) == ".fasta" || file.substr(pos) == ".fa")
+ file = file.substr(0, pos);
+ }
+
+ return file;
+}
diff --git a/src/file_io.h b/src/file_io.h
index c1f30b0..580ec2c 100644
--- a/src/file_io.h
+++ b/src/file_io.h
@@ -72,25 +72,26 @@ extern string in_path_2;
//
void help( void );
-int build_file_list(vector<pair<string, string> > &);
-int load_barcodes(string, vector<BarcodePair> &,
- set<string> &, set<string> &,
- uint &, uint &, uint &, uint &);
-int open_files(vector<pair<string, string> > &,
- vector<BarcodePair> &,
- map<BarcodePair, ofstream *> &,
- map<BarcodePair, ofstream *> &,
- map<BarcodePair, ofstream *> &,
- map<BarcodePair, ofstream *> &,
- map<string, map<string, long> > &);
-int open_files(vector<pair<string, string> > &,
- vector<BarcodePair> &,
- map<BarcodePair, gzFile *> &,
- map<BarcodePair, gzFile *> &,
- map<BarcodePair, gzFile *> &,
- map<BarcodePair, gzFile *> &,
- map<string, map<string, long> > &);
-int close_file_handles(map<BarcodePair, ofstream *> &);
-int close_file_handles(map<BarcodePair, gzFile *> &);
-
+int build_file_list(vector<pair<string, string> > &);
+int load_barcodes(string, vector<BarcodePair> &,
+ set<string> &, set<string> &,
+ uint &, uint &, uint &, uint &);
+int open_files(vector<pair<string, string> > &,
+ vector<BarcodePair> &,
+ map<BarcodePair, ofstream *> &,
+ map<BarcodePair, ofstream *> &,
+ map<BarcodePair, ofstream *> &,
+ map<BarcodePair, ofstream *> &,
+ map<string, map<string, long> > &);
+int open_files(vector<pair<string, string> > &,
+ vector<BarcodePair> &,
+ map<BarcodePair, gzFile *> &,
+ map<BarcodePair, gzFile *> &,
+ map<BarcodePair, gzFile *> &,
+ map<BarcodePair, gzFile *> &,
+ map<string, map<string, long> > &);
+int close_file_handles(map<BarcodePair, ofstream *> &);
+int close_file_handles(map<BarcodePair, gzFile *> &);
+string remove_suffix(FileT, string);
+
#endif // __FILE_IO_H__
diff --git a/src/gzFasta.h b/src/gzFasta.h
index 9ca48f6..59a522f 100644
--- a/src/gzFasta.h
+++ b/src/gzFasta.h
@@ -98,7 +98,8 @@ Seq *GzFasta::next_seq() {
if (len > 0 && this->line[len - 1] == '\n') this->line[len - 1] = '\0';
if (len > 0 && this->line[len - 2] == '\r') this->line[len - 2] = '\0';
- this->buf += this->line;
+ this->buf += this->line;
+ this->line[0] = '\0';
gzgets(this->gz_fh, this->line, max_len);
}
@@ -108,6 +109,7 @@ Seq *GzFasta::next_seq() {
if (len > 0 && this->line[len - 2] == '\r') this->line[len - 2] = '\0';
this->buf += this->line;
+ this->line[0] = '\0';
}
s->seq = new char[this->buf.length() + 1];
@@ -154,7 +156,8 @@ int GzFasta::next_seq(Seq &s) {
if (len > 0 && this->line[len - 1] == '\n') this->line[len - 1] = '\0';
if (len > 0 && this->line[len - 2] == '\r') this->line[len - 2] = '\0';
- this->buf += this->line;
+ this->buf += this->line;
+ this->line[0] = '\0';
gzgets(this->gz_fh, this->line, max_len);
}
@@ -164,6 +167,7 @@ int GzFasta::next_seq(Seq &s) {
if (len > 0 && this->line[len - 2] == '\r') this->line[len - 2] = '\0';
this->buf += this->line;
+ this->line[0] = '\0';
}
strcpy(s.seq, this->buf.c_str());
diff --git a/src/pstacks.cc b/src/pstacks.cc
index e7397af..5965ff6 100644
--- a/src/pstacks.cc
+++ b/src/pstacks.cc
@@ -737,6 +737,7 @@ int load_radtags(string in_file, HashMap &radtags) {
int i = 1;
while ((c = fh->next_seq()) != NULL) {
if (i % 10000 == 0) cerr << "Loading aligned sequence " << i << " \r";
+ // cerr << "Loading aligned sequence " << i << " \n";
radtags[c->seq].push_back(c);
i++;
diff --git a/src/renz.h b/src/renz.h
index 4ea8258..b009c52 100644
--- a/src/renz.h
+++ b/src/renz.h
@@ -26,6 +26,8 @@ using std::map;
#include <string>
using std::string;
+const char *aciI[] = {"CGC", "CGG", // C/CGC, AciI
+ "GCG", "CCG"};
const char *ageI[] = {"CCGGT", // A/CCGGT, AgeI
"ACCGG"};
const char *aluI[] = {"CT", // AG/CT, AluI
@@ -34,10 +36,16 @@ const char *apeKI[] = {"CAGC", "CTGC", // G/CWGC, ApeKI; W=A or T
"GTCG", "GACG"};
const char *apoI[] = {"AATTC", "AATTT", // R/AATTY, ApoI (also known as XapI)
"GAATT", "AAATT"};
+const char *aseI[] = {"TAAT", // AT/TAAT, AseI
+ "ATTA"};
const char *bamHI[] = {"GATCC", // G/GATCC, BamHI
"GGATC"};
+const char *bfaI[] = {"TAG", // C/TAG, BfaI
+ "CTA"};
const char *bgIII[] = {"GATCT", // A/GATCT, BgIII
"AGATC"};
+const char *bspDI[] = {"CGAT", // AT/CGAT, BspDI
+ "ATCG"};
const char *bstYI[] = {"GATCC", "GATCT", // R/GATCY, BstYI (also known as PsuI)
"GGATC", "AGATC"};
const char *claI[] = {"CGAT", // AT/CGAT, ClaI
@@ -138,7 +146,11 @@ initialize_renz(map<string, const char **> &renz, map<string, int> &renz_cnt, ma
renz["aluI"] = aluI; // AG/CT, AluI
renz["ageI"] = ageI; // A/CCGGT, AgeI
renz["rsaI"] = rsaI; // GT/AC, RsaI
-
+ renz["aciI"] = aciI; // C/CGC, AciI
+ renz["bfaI"] = bfaI; // C/TAG, BfaI
+ renz["aseI"] = aseI; // AT/TAAT, AseI
+ renz["bspDI"] = bspDI; // AT/CGAT, BspDI
+
renz_cnt["sbfI"] = 1;
renz_cnt["pstI"] = 1;
renz_cnt["notI"] = 1;
@@ -175,6 +187,10 @@ initialize_renz(map<string, const char **> &renz, map<string, int> &renz_cnt, ma
renz_cnt["aluI"] = 1;
renz_cnt["ageI"] = 1;
renz_cnt["rsaI"] = 1;
+ renz_cnt["aciI"] = 2;
+ renz_cnt["bfaI"] = 1;
+ renz_cnt["aseI"] = 1;
+ renz_cnt["bspDI"] = 1;
renz_len["sbfI"] = 6;
renz_len["pstI"] = 5;
@@ -212,6 +228,10 @@ initialize_renz(map<string, const char **> &renz, map<string, int> &renz_cnt, ma
renz_len["aluI"] = 2;
renz_len["ageI"] = 5;
renz_len["rsaI"] = 2;
+ renz_len["aciI"] = 3;
+ renz_len["bfaI"] = 3;
+ renz_len["aseI"] = 4;
+ renz_len["bspDI"] = 4;
}
void
diff --git a/src/sstacks.cc b/src/sstacks.cc
index ae4eec8..adf81a7 100644
--- a/src/sstacks.cc
+++ b/src/sstacks.cc
@@ -107,6 +107,13 @@ int main (int argc, char* argv[]) {
write_matches(sample_path, sample);
i++;
+
+ //
+ // Free memory associated with sample
+ //
+ for (map<int, QLocus *>::iterator j = sample.begin(); j != sample.end(); j++)
+ delete j->second;
+ sample.clear();
}
return 0;
@@ -527,14 +534,17 @@ find_matches_by_sequence(map<int, Locus *> &sample_1, map<int, QLocus *> &sample
sample_2.begin()->second->len : sample_1.begin()->second->len;
//
- // Build a hash map out of the first sample (usually the catalog),
- // using only the minimum length substring of the longest reads;
+ // Build a hash map out of the catalog, using only the minimum length
+ // substring of the longest reads;
//
- HashMap sample_1_map;
- populate_hash(sample_1, sample_1_map, min_tag_len);
+ HashMap sample_1_map;
+ vector<char *> sample_1_map_keys;
+ populate_hash(sample_1, sample_1_map, sample_1_map_keys, min_tag_len);
+ //
// OpenMP can't parallelize random access iterators, so we convert
// our map to a vector of integer keys.
+ //
vector<int> keys;
for (i = sample_2.begin(); i != sample_2.end(); i++)
keys.push_back(i->first);
@@ -553,7 +563,7 @@ find_matches_by_sequence(map<int, Locus *> &sample_1, map<int, QLocus *> &sample
{
#pragma omp for reduction(+:matches) reduction(+:tot_hap) reduction(+:ver_hap) reduction(+:nomatch) reduction(+:mmatch)
for (uint k = 0; k < keys.size(); k++) {
- QLocus *query = sample_2[keys[k]];
+ QLocus *query = sample_2[keys[k]];
//
// Iterate through the haplotypes for this tag in sample_2
@@ -601,6 +611,16 @@ find_matches_by_sequence(map<int, Locus *> &sample_1, map<int, QLocus *> &sample
}
}
+ //
+ // Free memory associated with the hash.
+ //
+ for (HashMap::iterator i = sample_1_map.begin(); i != sample_1_map.end(); i++)
+ i->second.clear();
+ sample_1_map.clear();
+ for (uint i = 0; i < sample_1_map_keys.size(); i++)
+ delete [] sample_1_map_keys[i];
+ sample_1_map_keys.clear();
+
cerr << keys.size() << " stacks compared against the catalog containing " << sample_1.size() << " loci.\n"
<< " " << matches << " matching loci, " << nomatch << " contained no verified haplotypes.\n"
<< " " << mmatch << " loci matched more than one catalog locus and were excluded.\n"
@@ -687,7 +707,9 @@ int verify_sequence_match(map<int, Locus *> &sample_1, QLocus *query,
return verified;
}
-int populate_hash(map<int, Locus *> &sample, HashMap &hash_map, int min_tag_len) {
+int
+populate_hash(map<int, Locus *> &sample, HashMap &hash_map, vector<char *> &hash_map_keys, int min_tag_len)
+{
map<int, Locus *>::iterator it;
vector<pair<allele_type, string> >::iterator all_it;
Locus *tag;
@@ -705,6 +727,7 @@ int populate_hash(map<int, Locus *> &sample, HashMap &hash_map, int min_tag_len)
key[min_tag_len] = '\0';
hash_map[key].push_back(make_pair(tag->id, all_it->first));
+ hash_map_keys.push_back(key);
}
}
diff --git a/src/sstacks.h b/src/sstacks.h
index 248492e..49a794e 100644
--- a/src/sstacks.h
+++ b/src/sstacks.h
@@ -78,7 +78,7 @@ typedef unordered_map<const char *, vector<pair<int, allele_type> >, hash_charpt
void help( void );
void version( void );
int parse_command_line(int, char**);
-int populate_hash(map<int, Locus *> &, HashMap &, int);
+int populate_hash(map<int, Locus *> &, HashMap &, vector<char *> &, int);
int find_matches_by_sequence(map<int, Locus *> &, map<int, QLocus *> &);
int find_matches_by_genomic_loc(map<int, Locus *> &, map<int, QLocus *> &);
int verify_sequence_match(map<int, Locus *> &, QLocus *, set<int> &, map<string, vector<string> > &, uint, unsigned long &, unsigned long &);
diff --git a/src/ustacks.cc b/src/ustacks.cc
index d75b846..e04c32b 100644
--- a/src/ustacks.cc
+++ b/src/ustacks.cc
@@ -1910,6 +1910,7 @@ int load_radtags(string in_file, DNASeqHashMap &radtags, vector<DNASeq *> &radta
corrected++;
}
+ cerr << "seql: " << seql << "; prev_seql: " << prev_seql << "\n";
if (seql != prev_seql && prev_seql > 0) len_mismatch = true;
d = new DNASeq(seql, c.seq);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/stacks.git
More information about the debian-med-commit
mailing list