This file is indexed.

/usr/share/stacks/php/stack_view.php is in stacks-web 1.35-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
//
// Copyright 2010-2015, Julian Catchen <jcatchen@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_str    = isset($_GET['tags'])     ? $_GET['tags']     : "";
$batch_id   = isset($_GET['batch_id']) ? $_GET['batch_id'] : 0;
$cat_id     = isset($_GET['tag_id'])   ? $_GET['tag_id']   : "";
$sample_str = isset($_GET['samples'])  ? $_GET['samples']  : "";
$database   = isset($_GET['db'])       ? $_GET['db']       : "";

$tags    = explode(",", $tag_str);
$samples = explode(",", $sample_str);

// Connect to the database
$db = db_connect($database);

//
// Prepare some SQL queries
//
$query = 
    "SELECT tag_id, sub_id, relationship, seq_id, seq, deleveraged, blacklisted, removed, file, pop_id " . 
    "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=?";
$db['seq_sth'] = $db['dbh']->prepare($query);
check_db_error($db['seq_sth'], __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__);

$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__);

$json_str = 
    "{" .
    "\"id\": \"$cat_id\"," .
    "\"stacks\": [";

for ($i = 0; $i < count($tags); $i++) {
    $sample_id = $samples[$i];
    $tag_id    = $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[$row['col']] = array('col' => $row['col'], 'rank_1' => $row['rank_1'], 'rank_2' => $row['rank_2']);
    }

    //
    // 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 (!isset($cat_snps[$row['col']]))
            $cat_snps[$row['col']] = 0;
        $cat_snps[$row['col']]++;
    }

    //
    // Fetch the sequences.
    //
    $deleveraged     = 0;
    $lumberjackstack = 0;
    $blacklisted     = 0;
    $consensus       = "";
    $model           = "";
    $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 ($row['relationship'] == "consensus") {
            $deleveraged     = $row['deleveraged'];
            $lumberjackstack = $row['removed'];
            $blacklisted     = $row['blacklisted'];
            $consensus       = $row['seq'];
            $file            = $row['file'];

        } else if ($row['relationship'] == "model") {
            $model = $row['seq'];

        } else if ($row['relationship'] == "secondary") {
            array_push($secondary, array('s' => $row['seq'], 'id' => $row['seq_id']));

        } else {
            if (!isset($stacks[$row['sub_id']]))
                $stacks[$row['sub_id']] = array();
            array_push($stacks[$row['sub_id']], array('s' => $row['seq'], 'id' => $row['seq_id']));
        }
    }

    $con_len = strlen($consensus);

    $c = print_snps($tags[$i], $consensus, $consensus, $snps, false);
    $c = addslashes($c);

    $scale = print_scale($con_len);
    $scale = addslashes($scale);

    $json_str .= 
        "{" .
        "\"sample_id\": \"$sample_id\"," .
        "\"sample_name\": \"$file\"," .
        "\"tag_id\": \"$tag_id\"," .
        "\"consensus\": \"$c\"," .
        "\"model\": \"$model\"," .
        "\"scale\": \"$scale\"," .
        "\"primary\": [";

    foreach ($stacks as $sub_id => $stack) {
        $s = print_snps_errs($consensus, $stack[0]['s'], $snps, $cat_snps);
        $s = addslashes($s);

        $json_str .=
            "{" .
            "\"seq\": \"$s\"," .
            "\"ids\": [";

        foreach ($stack as $seq) {
            $json_str .=
                "\"$seq[id]\",";
        }

        if (count($stack) > 0)
            $json_str = substr($json_str, 0, -1);
        $json_str .= 
            "]" .
            "},";
    }

    if (count($stacks) > 0)
        $json_str = substr($json_str, 0, -1);
    $json_str .=
        "]," .
        "\"secondary\": [";

    foreach ($secondary as $seq) {
        $s = print_snps_errs($consensus, $seq['s'], $snps, $cat_snps);
        $s = addslashes($s);

        $json_str .=
            "{" .
            "\"id\": \"$seq[id]\"," .
            "\"seq\": \"$s\"" .
            "},";
    }

    if (count($secondary) > 0)
        $json_str = substr($json_str, 0, -1);
    $json_str .= 
        "]},";
}

$json_str  = substr($json_str, 0, -1);
$json_str .= "]}";

echo $json_str;

?>