This file is indexed.

/usr/share/stacks/php/fst_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
<?php
//
// Copyright 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");

$database   = isset($_GET['db'])       ? $_GET['db']       : "";
$tag_id     = isset($_GET['tag_id'])   ? $_GET['tag_id']   : 0;
$batch_id   = isset($_GET['batch_id']) ? $_GET['batch_id'] : 0;
$batch_type = isset($_GET['type'])     ? $_GET['type']     : "map";

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

// Save these variables for automatic URL formation later on.
$display = array();
$display['db']       = $database;
$display['tag_id']   = $tag_id;
$display['batch_id'] = $batch_id;

//
// Prepare some SQL queries
//
$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__);

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

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

    while ($row = $result->fetchRow())
        $pop_names[$row['pop_id']] = $row['pop_name'];
}

$result = $db['fst_sth']->execute(array($batch_id, $tag_id));
check_db_error($result, __FILE__, __LINE__);

$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']);

  if (!isset($stats[$row['col']]))
    $stats[$row['col']] = array();

  array_push($stats[$row['col']], $a);

  $pops[$row['pop_id_1']] = $row['pop_id_1'];
  $pops[$row['pop_id_2']] = $row['pop_id_2'];
}

ksort($stats);
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;

ksort($pop_names);

$json_str = 
  "{" .
  "\"path\": \"$root_path\"," .
  "\"batch_id\": \"$batch_id\"," .
  "\"db\": \"$database\"," .
  "\"id\": \"$tag_id\"," .
  "\"type\": \"$batch_type\",";

$json_str .=  "\"popkey\": {";
//
// Print the population key.
//
foreach ($pop_names as $pop_id => $population) {
  $json_str .=
    "\"$pop_id\": \"$population\",";
}

$json_str  = substr($json_str, 0, -1);
$json_str .= 
  "}," .
  "\"columns\": {";

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\"" .
      "},";
  }
  
  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 .= 
  "}}";

echo $json_str;

?>