Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch all select objects to chado select objects #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions includes/repositories/EUtilsAssemblyRepository.inc
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,21 @@ class EUtilsAssemblyRepository extends EUtilsRepository {
throw new Exception('The organism_analysis linker table doesnt exist. No way to link this organism.');
}

$result = db_select('chado.organism_analysis', 't')
->fields('t', ['organism_analysis_id'])
$query = chado_db_select('organism_analysis', 't');
$result = $query->fields('t', ['organism_analysis_id'])
->condition('t.organism_id', $organism->organism_id)
->condition('t.analysis_id', $this->base_record_id)
->execute()
->fetchField();

if (!$result) {
$result = db_insert('chado.organism_analysis')
->fields([
'organism_id' => $organism->organism_id,
'analysis_id' => $this->base_record_id,
])
->execute();
$values = [
'organism_id' => $organism->organism_id,
'analysis_id' => $this->base_record_id,
];

$result = chado_insert_record('organism_analysis', $values);

}

if (!$result) {
Expand All @@ -238,7 +239,7 @@ class EUtilsAssemblyRepository extends EUtilsRepository {

$base = $this->base_fields;

$id = db_insert('chado.analysis')->fields([
$values = [
'name' => $base['name'],
'description' => $base['description'] ?? '',
'program' => $base['program'],
Expand All @@ -248,14 +249,17 @@ class EUtilsAssemblyRepository extends EUtilsRepository {
'sourceversion' => $base['sourceversion'] ?? '',
'sourceuri' => $base['sourceuri'] ?? '',
'timeexecuted' => $base['timeexecuted'] ?? date_now(),
])->execute();
];
$record = chado_insert_record('analysis', $values);

$id = $record['analysis_id'];

if (!$id) {
throw new Exception('Unable to create chado.analysis record');
}

$analysis = db_select('chado.analysis', 't')
->fields('t')
$query = chado_db_select('analysis', 't');
$analysis = $query->fields('t')
->condition('analysis_id', $id)
->execute()
->fetchObject();
Expand All @@ -278,8 +282,8 @@ class EUtilsAssemblyRepository extends EUtilsRepository {
return static::$cache['analysis'];
}

$exists = db_select('chado.analysis', 't')
->fields('t')
$query = chado_db_select('analysis', 't');
$exists = $query->fields('t')
->condition('name', $base['name'])
->condition('program', $base['program'])
->condition('programversion', $base['programversion'])
Expand All @@ -298,11 +302,13 @@ class EUtilsAssemblyRepository extends EUtilsRepository {
/**
* Associates FTPs as properties.
*
* @param $ftps
* @param array $ftps
* Array of key value pars, where the key is the XML FTP type, the value is
* the FTP address.
*
* @throws \Exception
*/
public function addFTPLinks($ftps) {
public function addFTPLinks(array $ftps) {

$cvterm_id = chado_get_cvterm(['id' => 'local:ncbi_FTP_links'])->cvterm_id;
foreach ($ftps as $type => $ftp) {
Expand All @@ -318,6 +324,11 @@ class EUtilsAssemblyRepository extends EUtilsRepository {
* The type/category passed from the parser.
*
* @return bool
* Output of chado_insert_property.
*
* @see createProperty
*
* @throws \Exception
*/
private function setAnalysisType(string $type) {

Expand Down
28 changes: 16 additions & 12 deletions includes/repositories/EUtilsBioProjectRepository.inc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class EUtilsBioProjectRepository extends EUtilsRepository {
$this->createPubs($pubs);
}


return $project;
}

Expand Down Expand Up @@ -108,8 +107,8 @@ class EUtilsBioProjectRepository extends EUtilsRepository {
throw new Exception('Unable to create chado.project record');
}

$project = db_select('chado.project', 't')
->fields('t')
$query = chado_db_select('project', 't');
$project = $query->fields('t')
->condition('project_id', $id)
->execute()
->fetchObject();
Expand All @@ -121,8 +120,10 @@ class EUtilsBioProjectRepository extends EUtilsRepository {
* Get project from db or cache.
*
* @param string $name
* Chado project name field.
*
* @return null
* Returns a project object or NULL.
*/
public function getProject($name) {
// If the project is available in our static cache, return it.
Expand All @@ -131,8 +132,8 @@ class EUtilsBioProjectRepository extends EUtilsRepository {
}

// Find the project and add it to the cache.
$project = db_select('chado.project', 'p')
->fields('p')
$query = chado_db_select('project', 't');
$project = $query->fields('t')
->condition('name', $name)
->execute()
->fetchObject();
Expand Down Expand Up @@ -184,7 +185,8 @@ class EUtilsBioProjectRepository extends EUtilsRepository {
foreach ($accessions as $db => $accession) {
try {
$data[] = $this->createAccession(['db' => $db, 'value' => $accession]);
} catch (Exception $exception) {
}
catch (Exception $exception) {
// For the time being, ignore all exceptions.
}
}
Expand Down Expand Up @@ -227,7 +229,7 @@ class EUtilsBioProjectRepository extends EUtilsRepository {
public function linkBiomaterial($record) {
$biomaterial_id = $record->biomaterial_id;

db_insert('chado.biomaterial_project')->fields([
chado_insert_record('biomaterial_project', [
'biomaterial_id' => $biomaterial_id,
'project_id' => $this->base_record_id,
]);
Expand All @@ -238,13 +240,13 @@ class EUtilsBioProjectRepository extends EUtilsRepository {
* Links an analysis to the base project record.
*
* @param $record
* Assembly record object.
* Assembly/analysis record object.
*/
private function linkAssembly($record) {
$analysis_id = $record->analysis_id;

$exists = db_select('chado.project_analysis', 't')
->fields('t')
$query = chado_db_select('project_analysis', 't');
$exists = $query->fields('t')
->condition('project_id', $this->base_record_id)
->condition('analysis_id', $analysis_id)
->execute()
Expand Down Expand Up @@ -278,8 +280,10 @@ class EUtilsBioProjectRepository extends EUtilsRepository {
'project_id' => $this->base_record_id,
'pub_id' => $pub->pub_id,
];
$exists = db_select('chado.project_pub', 't')
->fields('t')

$query = chado_db_select('project_pub', 't');

$exists = $query->fields('t')
->condition('project_id', $this->base_record_id)
->condition('pub_id', $pub->pub_id)
->execute()
Expand Down
16 changes: 10 additions & 6 deletions includes/repositories/EUtilsBioSampleRepository.inc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ class EUtilsBioSampleRepository extends EUtilsRepository {
throw new Exception('Unable to create chado.biomaterial record');
}

$biosample = db_select('chado.biomaterial', 'B')->fields('B')->condition(
$query = chado_db_select('biomaterial', 'B');

$biosample = $query->fields('B')->condition(
'biomaterial_id', $id
)->execute()->fetchObject();

Expand All @@ -145,8 +147,10 @@ class EUtilsBioSampleRepository extends EUtilsRepository {
* Get biosample from db or cache.
*
* @param string $name
* Name for the name field of biomaterial table.
*
* @return null
* @return mixed
* The Chado biosample record.
*/
public function getBioSample($name) {
// If the biosample is available in our static cache, return it.
Expand All @@ -155,17 +159,17 @@ class EUtilsBioSampleRepository extends EUtilsRepository {
}

// Find the biosample and add it to the cache.
$biosample = db_select('chado.biomaterial', 'b')
->fields('b')
$query = chado_db_select('biomaterial', 'b');

// Name is in fact a unique key.
$biosample = $query->fields('b')
->condition('name', $name)
->execute()
->fetchObject();

if ($biosample) {
return static::$cache['biosamples'][$name] = $biosample;
}

return NULL;
}

/**
Expand Down
11 changes: 8 additions & 3 deletions includes/repositories/EUtilsPubmedRepository.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class EUtilsPubmedRepository extends EUtilsRepository {
'description',
];

/**
* Required base table attribute.
*
* @var string
*/
protected $base_table = 'pub';

/**
Expand All @@ -27,14 +32,14 @@ class EUtilsPubmedRepository extends EUtilsRepository {
*
* @return pub
* A Chado publication record object.
**/
*/
public function create(array $data) {
module_load_include('inc', 'tripal_chado', '/includes/loaders/tripal_chado.pub_importers');

tripal_pub_add_publications([$data], FALSE);
$uname = $data['Citation'];
$pub = db_select('chado.pub', 'p')->fields('p')->condition('p.uniquename', $uname)->execute()->fetchObject();

$connection = chado_db_select('pub', 'p');
$pub = $connection->fields('p')->condition('p.uniquename', $uname)->execute()->fetchObject();
return $pub;
}

Expand Down
Loading