Tripal Plant PopGen Submit
markers_genotypes_utils.inc
Go to the documentation of this file.
1 <?php
2 
11 function tpps_remove_all_markers_genotypes($accession, TripalJob $job = NULL) {
12  $accession = trim($accession);
13  if($accession == "") {
14  throw new Exception('Accession must be valid, empty accession was provided');
15  }
16  $job->logMessage('[INFO] Performing removal of markers and genotypes on study: ' . $accession);
17  $job->setInterval(1);
18 
19  $transaction = db_transaction();
20  try {
21  $job->logMessage('[INFO] Removing records from chado.genotype table...');
22  $sql = "";
23  $sql .= "delete from chado.genotype where genotype_id in ";
24  $sql .= " (select distinct genotype_id from chado.genotype_call where project_id = (";
25  $sql .= " select project_id from chado.project_dbxref where dbxref_id = (";
26  $sql .= " select dbxref_id from chado.dbxref where accession = '" . $accession . "'";
27  $sql .= " )";
28  $sql .= " )";
29  $sql .= ");";
30  chado_query($sql, []);
31  $job->logMessage('[INFO] Done.');
32 
33  $job->logMessage('[INFO] Removing records from chado.feature table...');
34  $sql = "";
35  $sql .= "delete from chado.feature where feature_id in (";
36  $sql .= " select distinct marker_id from chado.genotype_call where project_id = (";
37  $sql .= " select project_id from chado.project_dbxref where dbxref_id = (";
38  $sql .= " select dbxref_id from chado.dbxref where accession = '" . $accession . "'";
39  $sql .= " )";
40  $sql .= " )";
41  $sql .= ")";
42  $sql .= "or feature_id in (";
43  $sql .= " select distinct variant_id from chado.genotype_call where project_id = (";
44  $sql .= " select project_id from chado.project_dbxref where dbxref_id = (";
45  $sql .= " select dbxref_id from chado.dbxref where accession = '" . $accession . "'";
46  $sql .= " )";
47  $sql .= " )";
48  $sql .= ");";
49  chado_query($sql, []);
50  $job->logMessage('[INFO] Done.');
51 
52  $job->logMessage('[INFO] Removing records from chado.genotype_call table...');
53  $sql = "";
54  $sql .= "delete from chado.genotype_call where project_id = (";
55  $sql .= " select project_id from chado.project_dbxref where dbxref_id = (";
56  $sql .= " select dbxref_id from chado.dbxref where accession = '" . $accession . "'";
57  $sql .= " )";
58  $sql .= ");";
59  chado_query($sql, []);
60  $job->logMessage('[INFO] Done.');
61  $job->logMessage('[STATUS] Job has been completed successfully without errors.');
62  }
63  catch (Exception $e) {
64  $transaction->rollback();
65  $job->logMessage('[ERROR] Job failed', array(), TRIPAL_ERROR);
66  $job->logMessage('[ERROR] Error message: @msg', array('@msg' => $e->getMessage()), TRIPAL_ERROR);
67  $job->logMessage("[ERROR] Trace: \n@trace", array('@trace' => $e->getTraceAsString()), TRIPAL_ERROR);
68  watchdog_exception('tpps', $e);
69  }
70 }
tpps_remove_all_markers_genotypes($accession, TripalJob $job=NULL)