function tripal_feature_load_gff3_fasta
2.x tripal_feature.gff_loader.inc | tripal_feature_load_gff3_fasta($fh, $interval, &$num_read, &$intv_read, &$line_num, |
1.x gff_loader.inc | tripal_feature_load_gff3_fasta($fh, $interval, &$num_read, &$intv_read, &$line_num) |
1 call to tripal_feature_load_gff3_fasta()
- tripal_feature_load_gff3 in tripal_feature/
includes/ gff_loader.inc
File
- tripal_feature/
includes/ gff_loader.inc, line 1810 - @todo Add file header description
Code
function tripal_feature_load_gff3_fasta($fh, $interval, &$num_read, &$intv_read, &$line_num) {
print "Loading FASTA sequences\n";
$residues = '';
$sql = "
PREPARE sel_gfftemp_un (text) AS
SELECT feature_id FROM tripal_gff_temp
WHERE uniquename = $1
";
$status = tripal_core_chado_prepare('sel_gfftemp_un', $sql, array('text'));
if (!$status) {
watchdog('T_gff3_loader', 'Cannot prepare statement \'sel_gfftemp_un\'.',
array(), WATCHDOG_ERROR);
return '';
}
$id = NULL;
// iterate through the remaining lines of the file
while ($line = fgets($fh)) {
$line_num++;
$size = drupal_strlen($line);
$num_read += $size;
$intv_read += $size;
$line = trim($line);
// update the job status every 1% features
if ($job and $intv_read >= $interval) {
$intv_read = 0;
$percent = sprintf("%.2f", ($num_read / $filesize) * 100);
print "Parsing Line $line_num (" . $percent . "%). Memory: " . number_format(memory_get_usage()) . " bytes.\r";
tripal_job_set_progress($job, intval(($num_read / $filesize) * 100));
}
// if we encounter a definition line then get the name, uniquename,
// accession and relationship subject from the definition line
if (preg_match('/^>/', $line)) {
// if we are beginning a new sequence then save the last one we
// just finished.
if ($id) {
$sql = "EXECUTE sel_gfftemp_un('%s')";
$result = tripal_core_chado_execute_prepared('sel_gfftemp_un', $sql, array($id));
if (!$result) {
watchdog('T_gff3_loader', 'Cannot find feature to assign FASTA sequence: %uname',
array('%uname' => $id), WATCHDOG_WARNING);
}
// if we have a feature then add the residues
else {
$feature = db_fetch_object($result);
$values = array('residues' => $residues);
$match = array('feature_id' => $feature->feature_id);
$options = array('statement_name' => 'upd_feature_re');
tripal_core_chado_update('feature', $match, $values, $options);
}
}
// get the feature ID for this ID from the tripal_gff_temp table
$id = preg_replace('/^>(.*)$/', '\1', $line);
$residues = '';
}
else {
$residues .= trim($line);
}
}
// add in the last sequence
$sql = "EXECUTE sel_gfftemp_un('%s')";
$result = tripal_core_chado_execute_prepared('sel_gfftemp_un', $sql, array($id));
if (!$result) {
watchdog('T_gff3_loader', 'Cannot find feature to assign FASTA sequence: %uname',
array('%uname' => $id), WATCHDOG_WARNING);
}
// if we have a feature then add the residues
else {
$feature = db_fetch_object($result);
$values = array('residues' => $residues);
$match = array('feature_id' => $feature->feature_id);
$options = array('statement_name' => 'upd_feature_re');
tripal_core_chado_update('feature', $match, $values, $options);
}
}