gff_loader.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. <?php
  2. /**
  3. * @defgroup gff3_loader GFF3 Feature Loader
  4. * @{
  5. * Provides gff3 loading functionality. Creates features based on their specification in a GFF3 file.
  6. * @}
  7. * @ingroup tripal_feature
  8. */
  9. // TODO: The rank column on the feature_relationship table needs to be used to
  10. // make sure the ordering of CDS (exons) is correct.
  11. // The entries in the GFF file are not in order so the order of the relationships
  12. // is not put in correctly.
  13. /**
  14. *
  15. *
  16. * @ingroup gff3_loader
  17. */
  18. function tripal_feature_gff3_load_form (){
  19. $form['gff_file']= array(
  20. '#type' => 'textfield',
  21. '#title' => t('GFF3 File'),
  22. '#description' => t('Please enter the full system path for the GFF file, or a path within the Drupal
  23. installation (e.g. /sites/default/files/xyz.gff). The path must be accessible to the
  24. server on which this Drupal instance is running.'),
  25. '#required' => TRUE,
  26. '#weight' => 1
  27. );
  28. // get the list of organisms
  29. $sql = "SELECT * FROM {organism} ORDER BY genus, species";
  30. $previous_db = tripal_db_set_active('chado'); // use chado database
  31. $org_rset = db_query($sql);
  32. tripal_db_set_active($previous_db); // now use drupal database
  33. $organisms = array();
  34. $organisms[''] = '';
  35. while($organism = db_fetch_object($org_rset)){
  36. $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
  37. }
  38. $form['organism_id'] = array (
  39. '#title' => t('Organism'),
  40. '#type' => t('select'),
  41. '#description' => t("Choose the organism to which these sequences are associated "),
  42. '#required' => TRUE,
  43. '#options' => $organisms,
  44. );
  45. $form['import_options'] = array(
  46. '#type' => 'fieldset',
  47. '#title' => t('Import Options'),
  48. '#weight'=> 6,
  49. '#collapsed' => TRUE
  50. );
  51. $form['import_options']['add_only']= array(
  52. '#type' => 'checkbox',
  53. '#title' => t('Import only new features'),
  54. '#required' => FALSE,
  55. '#description' => t('The job will skip features in the GFF file that already
  56. exist in the database and import only new features.'),
  57. '#weight' => 2
  58. );
  59. $form['import_options']['update']= array(
  60. '#type' => 'checkbox',
  61. '#title' => t('Import all and update'),
  62. '#required' => FALSE,
  63. '#default_value' => 'checked',
  64. '#description' => t('Existing features will be updated and new features will be added. Attributes
  65. for a feature that are not present in the GFF but which are present in the
  66. database will not be altered.'),
  67. '#weight' => 3
  68. );
  69. $form['import_options']['refresh']= array(
  70. '#type' => 'checkbox',
  71. '#title' => t('Import all and replace'),
  72. '#required' => FALSE,
  73. '#description' => t('Existing features will be updated and feature properties not
  74. present in the GFF file will be removed.'),
  75. '#weight' => 4
  76. );
  77. $form['import_options']['remove']= array(
  78. '#type' => 'checkbox',
  79. '#title' => t('Delete features'),
  80. '#required' => FALSE,
  81. '#description' => t('Features present in the GFF file that exist in the database
  82. will be removed rather than imported'),
  83. '#weight' => 5
  84. );
  85. $form['analysis'] = array(
  86. '#type' => 'fieldset',
  87. '#title' => t('Analysis Used to Derive Features'),
  88. '#weight'=> 6,
  89. '#collapsed' => TRUE
  90. );
  91. $form['analysis']['desc'] = array(
  92. '#type' => 'markup',
  93. '#value' => t("Why specify an analysis for a data load? All data comes
  94. from some place, even if downloaded from Genbank. By specifying
  95. analysis details for all data uploads, it allows an end user to reproduce the
  96. data set, but at least indicates the source of the data."),
  97. );
  98. // get the list of analyses
  99. $sql = "SELECT * FROM {analysis} ORDER BY name";
  100. $previous_db = tripal_db_set_active('chado'); // use chado database
  101. $org_rset = db_query($sql);
  102. tripal_db_set_active($previous_db); // now use drupal database
  103. $analyses = array();
  104. $analyses[''] = '';
  105. while($analysis = db_fetch_object($org_rset)){
  106. $analyses[$analysis->analysis_id] = "$analysis->name ($analysis->program $analysis->programversion, $analysis->sourcename)";
  107. }
  108. $form['analysis']['analysis_id'] = array (
  109. '#title' => t('Analysis'),
  110. '#type' => t('select'),
  111. '#description' => t("Choose the analysis to which these features are associated "),
  112. '#required' => TRUE,
  113. '#options' => $analyses,
  114. );
  115. $form['button'] = array(
  116. '#type' => 'submit',
  117. '#value' => t('Import GFF3 file'),
  118. '#weight' => 10,
  119. );
  120. return $form;
  121. }
  122. /**
  123. *
  124. *
  125. * @ingroup gff3_loader
  126. */
  127. function tripal_feature_gff3_load_form_validate ($form, &$form_state){
  128. $gff_file = $form_state['values']['gff_file'];
  129. $organism_id = $form_state['values']['organism_id'];
  130. $add_only = $form_state['values']['add_only'];
  131. $update = $form_state['values']['update'];
  132. $refresh = $form_state['values']['refresh'];
  133. $remove = $form_state['values']['remove'];
  134. // check to see if the file is located local to Drupal
  135. $dfile = $_SERVER['DOCUMENT_ROOT'] . base_path() . $gff_file;
  136. if(!file_exists($dfile)){
  137. // if not local to Drupal, the file must be someplace else, just use
  138. // the full path provided
  139. $dfile = $gff_file;
  140. }
  141. if(!file_exists($dfile)){
  142. form_set_error('gff_file',t("Cannot find the file on the system. Check that the file exists or that the web server has permissions to read the file."));
  143. }
  144. if (($add_only and ($update or $refresh or $remove)) or
  145. ($update and ($add_only or $refresh or $remove)) or
  146. ($refresh and ($update or $add_only or $remove)) or
  147. ($remove and ($update or $refresh or $add_only))){
  148. form_set_error('add_only',t("Please select only one checkbox from the import options section"));
  149. }
  150. }
  151. /**
  152. *
  153. * @ingroup gff3_loader
  154. */
  155. function tripal_feature_gff3_load_form_submit ($form, &$form_state){
  156. global $user;
  157. $gff_file = $form_state['values']['gff_file'];
  158. $organism_id = $form_state['values']['organism_id'];
  159. $add_only = $form_state['values']['add_only'];
  160. $update = $form_state['values']['update'];
  161. $refresh = $form_state['values']['refresh'];
  162. $remove = $form_state['values']['remove'];
  163. $analysis_id = $form_state['values']['analysis_id'];
  164. $args = array($gff_file,$organism_id,$analysis_id,$add_only,$update,$refresh,$remove);
  165. $type = '';
  166. if($add_only){
  167. $type = 'import only new features';
  168. }
  169. if($update){
  170. $type = 'import all and update';
  171. }
  172. if($refresh){
  173. $type = 'import all and replace';
  174. }
  175. if($remove){
  176. $type = 'delete features';
  177. }
  178. tripal_add_job("$type GFF3 file $gff_file",'tripal_feature',
  179. 'tripal_feature_load_gff3',$args,$user->uid);
  180. return '';
  181. }
  182. /**
  183. *
  184. *
  185. * @ingroup gff3_loader
  186. */
  187. function tripal_feature_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0,
  188. $update = 0, $refresh = 0, $remove = 0, $job = NULL)
  189. {
  190. // this array is used to cache all of the features in the GFF file and
  191. // used to lookup parent and target relationships
  192. $gff_features = array();
  193. // check to see if the file is located local to Drupal
  194. $dfile = $_SERVER['DOCUMENT_ROOT'] . base_path() . $gff_file;
  195. if(!file_exists($dfile)){
  196. // if not local to Drupal, the file must be someplace else, just use
  197. // the full path provided
  198. $dfile = $gff_file;
  199. }
  200. if(!file_exists($dfile)){
  201. print "ERROR: cannot find the file: $dfile\n";
  202. return 0;
  203. }
  204. $previous_db = tripal_db_set_active('chado');
  205. print "Opening $gff_file\n";
  206. //$lines = file($dfile,FILE_SKIP_EMPTY_LINES);
  207. $fh = fopen($dfile,'r');
  208. if(!$fh){
  209. print "ERROR: cannot open file: $dfile\n";
  210. return 0;
  211. }
  212. $filesize = filesize($dfile);
  213. // get the controlled vocaubulary that we'll be using. The
  214. // default is the 'sequence' ontology
  215. $sql = "SELECT * FROM cv WHERE name = '%s'";
  216. $cv = db_fetch_object(db_query($sql,'sequence'));
  217. if(!$cv){
  218. print "ERROR: cannot find the 'sequence' ontology\n";
  219. return '';
  220. }
  221. // get the organism for which this GFF3 file belongs
  222. $sql = "SELECT * FROM organism WHERE organism_id = %d";
  223. $organism = db_fetch_object(db_query($sql,$organism_id));
  224. $interval = intval($filesize * 0.01);
  225. if($interval == 0){
  226. $interval = 1;
  227. }
  228. $in_fasta = 0;
  229. // foreach ($lines as $line_num => $line) {
  230. $line_num = 0;
  231. $num_read = 0;
  232. while($line = fgets($fh)){
  233. $line_num++;
  234. $num_read += strlen($line);
  235. // update the job status every 1% features
  236. if($job and $num_read % $interval == 0){
  237. tripal_job_set_progress($job,intval(($num_read/$filesize)*100));
  238. }
  239. // check to see if we have FASTA section, if so then set the variable
  240. // to start parsing
  241. if(preg_match('/^##FASTA/i',$line)){
  242. $in_fasta = 1;
  243. break;
  244. }
  245. // skip comments
  246. if(preg_match('/^#/',$line)){
  247. continue;
  248. }
  249. // skip empty lines
  250. if(preg_match('/^\s*$/',$line)){
  251. continue;
  252. }
  253. // handle FASTA section
  254. // TODO: handle URL encoding
  255. // remove URL encoding and get the columns
  256. $cols = explode("\t",$line);
  257. if(sizeof($cols) != 9){
  258. print "ERROR: improper number of columns on line $line_num\n";
  259. print_r($cols);
  260. return '';
  261. }
  262. // get the column values
  263. $landmark = $cols[0];
  264. $source = $cols[1];
  265. $type = $cols[2];
  266. $start = $cols[3];
  267. $end = $cols[4];
  268. $score = $cols[5];
  269. $strand = $cols[6];
  270. $phase = $cols[7];
  271. $attrs = explode(";",$cols[8]); // split by a semi-colon
  272. // ready the start and stop for chado. Chado expects these positions
  273. // to be zero-based, so we substract 1 from the fmin
  274. $fmin = $start - 1;
  275. $fmax = $end;
  276. if($end < $start){
  277. $fmin = $end - 1;
  278. $fmax = $start;
  279. }
  280. // format the strand for chado
  281. if(strcmp($strand,'.')==0){
  282. $strand = 0;
  283. }
  284. elseif(strcmp($strand,'+')==0){
  285. $strand = 1;
  286. }
  287. elseif(strcmp($strand,'-')==0){
  288. $strand = -1;
  289. }
  290. if(strcmp($phase,'.')==0){
  291. $phase = '';
  292. }
  293. // get the type record
  294. $cvtermsql = "SELECT CVT.cvterm_id, CVT.cv_id, CVT.name, CVT.definition,
  295. CVT.dbxref_id, CVT.is_obsolete, CVT.is_relationshiptype
  296. FROM {cvterm} CVT
  297. INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
  298. LEFT JOIN {cvtermsynonym} CVTS on CVTS.cvterm_id = CVT.cvterm_id
  299. WHERE CV.cv_id = %d and (CVT.name = '%s' or CVTS.synonym = '%s')";
  300. $cvterm = db_fetch_object(db_query($cvtermsql,$cv->cv_id,$type,$type));
  301. if(!$cvterm){
  302. print "ERROR: cannot find ontology term '$type' on line $line_num.\n";
  303. return '';
  304. }
  305. // break apart each of the attributes
  306. $tags = array();
  307. $attr_name = '';
  308. $attr_uniquename = '';
  309. $attr_residue_info = '';
  310. $attr_locgroup = 0;
  311. $attr_fmin_partial = 'f';
  312. $attr_fmax_partial = 'f';
  313. $attr_is_obsolete = 'f';
  314. $attr_is_analysis = 'f';
  315. $attr_others = '';
  316. $residues = '';
  317. foreach($attrs as $attr){
  318. $attr = rtrim($attr);
  319. $attr = ltrim($attr);
  320. if(strcmp($attr,'')==0){
  321. continue;
  322. }
  323. if(!preg_match('/^[^\=]+\=[^\=]+$/',$attr)){
  324. print "ERROR: attribute is not correctly formatted on line $line_num: $attr\n";
  325. return '';
  326. }
  327. // break apart each tag
  328. $tag = explode("=",$attr); // split by equals sign
  329. // multiple instances of an attribute are separated by commas
  330. $tags[$tag[0]] = explode(",",$tag[1]); // split by comma
  331. if(strcmp($tag[0],'ID')==0){
  332. $attr_uniquename = $tag[1];
  333. }
  334. elseif(strcmp($tag[0],'Name')==0){
  335. $attr_name = $tag[1];
  336. }
  337. // get the list of other attributes other than those reserved ones.
  338. elseif(strcmp($tag[0],'Alias')!=0 and strcmp($tag[0],'Parent')!=0 and
  339. strcmp($tag[0],'Target')!=0 and strcmp($tag[0],'Gap')!=0 and
  340. strcmp($tag[0],'Derives_from')!=0 and strcmp($tag[0],'Note')!=0 and
  341. strcmp($tag[0],'Dbxref')!=0 and strcmp($tag[0],'Ontology_term')!=0 and
  342. strcmp($tag[0],'Is_circular')!=0){
  343. $attr_others[$tag[0]] = $tag[1];
  344. }
  345. }
  346. // if neither name nor uniquename are provided then generate one
  347. if(!$attr_uniquename and !$attr_name){
  348. if(array_key_exists('Parent',$tags)){
  349. $attr_uniquename = $tags['Parent'][0]."-$type-$landmark:$fmin..$fmax";
  350. } else {
  351. print "ERROR: cannot generate a uniquename for feature on line $line_num\n";
  352. exit;
  353. }
  354. $attr_name = $attr_uniquename;
  355. }
  356. // if a name is not specified then use the unique name
  357. if(strcmp($attr_name,'')==0){
  358. $attr_name = $attr_uniquename;
  359. }
  360. // if an ID attribute is not specified then use the attribute name and
  361. // hope for the best
  362. if(!$attr_uniquename){
  363. $attr_uniquename = $attr_name;
  364. }
  365. // make sure the landmark sequence exists in the database. We don't
  366. // know the type of the landmark so we'll hope that it's unique across
  367. // all types. If not we'll error out. This test is only necessary if
  368. // if the landmark and the uniquename are different. If they are the same
  369. // then this is the information for the landmark
  370. if(strcmp($landmark,$attr_uniquename)!=0){
  371. $feature_sql = "SELECT count(*) as num_landmarks
  372. FROM {feature}
  373. WHERE organism_id = %d and uniquename = '%s'";
  374. $count = db_fetch_object(db_query($feature_sql,$organism_id,$landmark));
  375. if(!$count or $count->num_landmarks == 0){
  376. print "ERROR: the landmark '$landmark' cannot be found for this organism. ".
  377. "Please add the landmark and then retry the import of this GFF3 ".
  378. "file.\n";
  379. return '';
  380. }
  381. if($count->num_landmarks > 1){
  382. print "ERROR: the landmark '$landmark' is not unique for this organism. ".
  383. "The features cannot be associated.\n";
  384. return '';
  385. }
  386. }
  387. // if the option is to remove or refresh then we want to remove
  388. // the feature from the database.
  389. if($remove or $refresh){
  390. print "Removing feature '$attr_uniquename'\n";
  391. $sql = "DELETE FROM {feature}
  392. WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
  393. $result = db_query($sql,$organism->organism_id,$attr_uniquename,$cvterm->cvterm_id);
  394. if(!$result){
  395. print "ERROR: cannot delete feature $attr_uniquename\n";
  396. }
  397. $feature = 0;
  398. }
  399. // add or update the feature and all properties
  400. if($update or $refresh or $add_only){
  401. // add/update the feature
  402. print "line $line_num, ". intval(($num_read/$filesize)*100). "%. ";
  403. $feature = tripal_feature_load_gff3_feature($organism,$analysis_id,$cvterm,
  404. $attr_uniquename,$attr_name,$residues,$attr_is_analysis,
  405. $attr_is_obsolete, $add_only,$score);
  406. // store all of the features for use later by parent and target
  407. // relationships
  408. $gff_features[$feature->uniquename]['type'] = $type;
  409. $gff_features[$feature->uniquename]['strand'] = $strand;
  410. if($feature){
  411. // add/update the featureloc if the landmark and the ID are not the same
  412. // if they are the same then this entry in the GFF is probably a landmark identifier
  413. if(strcmp($landmark,$attr_uniquename)!=0){
  414. tripal_feature_load_gff3_featureloc($feature,$organism,
  415. $landmark,$fmin,$fmax,$strand,$phase,$attr_fmin_partial,
  416. $attr_fmax_partial,$attr_residue_info,$attr_locgroup);
  417. }
  418. // add any aliases for this feature
  419. if(array_key_exists('Alias',$tags)){
  420. tripal_feature_load_gff3_alias($feature,$tags['Alias']);
  421. }
  422. // add any dbxrefs for this feature
  423. if(array_key_exists('Dbxref',$tags)){
  424. tripal_feature_load_gff3_dbxref($feature,$tags['Dbxref']);
  425. }
  426. // add any ontology terms for this feature
  427. if(array_key_exists('Ontology_term',$tags)){
  428. tripal_feature_load_gff3_ontology($feature,$tags['Ontology_term']);
  429. }
  430. // add parent relationships
  431. if(array_key_exists('Parent',$tags)){
  432. tripal_feature_load_gff3_parents($feature,$cvterm,$tags['Parent'],$gff_features,$organism_id,$fmin);
  433. }
  434. // add target relationships
  435. if(array_key_exists('Target',$tags)){
  436. $target = explode(" ",$tags['Target'][0]);
  437. $target_feature = $target[0];
  438. $target_start = $target[1];
  439. $target_end = $target[2];
  440. $target_dir = $target[3];
  441. #print "Target: $target_feature, $target_start-$target_end\n";
  442. tripal_feature_load_gff3_featureloc($feature,$organism,
  443. $target_feature,$target_start,$target_end,$strand,$phase,$attr_fmin_partial,
  444. $attr_fmax_partial,$attr_residue_info,$attr_locgroup);
  445. }
  446. // add gap information. This goes in simply as a property
  447. if(array_key_exists('Gap',$tags)){
  448. tripal_feature_load_gff3_property($feature,'Gap',$tags['Gap'][0]);
  449. }
  450. // add notes. This goes in simply as a property
  451. if(array_key_exists('Note',$tags)){
  452. tripal_feature_load_gff3_property($feature,'Note',$tags['Note'][0]);
  453. }
  454. // add the Derives_from relationship (e.g. polycistronic genes).
  455. if(array_key_exists('Derives_from',$tags)){
  456. tripal_feature_load_gff3_derives_from($feature,$tags['Derives_from'][0],$gff_features,$organism);
  457. }
  458. // add in the GFF3_source dbxref so that GBrowse can find the feature using the source column
  459. $source_ref = array('GFF_source:'.$source);
  460. tripal_feature_load_gff3_dbxref($feature,$source_ref);
  461. // add any additional attributes
  462. if($attr_others){
  463. foreach($attr_others as $property => $value){
  464. tripal_feature_load_gff3_property($feature,$property,$value);
  465. }
  466. }
  467. }
  468. }
  469. }
  470. // now set the rank of any parent/child relationships. The order is based
  471. // on the fmin. The start rank is 1. This allows features with other
  472. // relationships to be '0' (the default), and doesn't interfer with the
  473. // ordering defined here.
  474. foreach($gff_features as $parent => $details){
  475. // only iterate through parents that have children
  476. if($details['children']){
  477. // get the parent
  478. $values = array(
  479. 'uniquename' => $parent,
  480. 'type_id' => array(
  481. 'cv_id' => array(
  482. 'name' => 'sequence'
  483. ),
  484. 'name' => $details['type'],
  485. ),
  486. 'organism_id' => $organism->organism_id,
  487. );
  488. $pfeature = tripal_core_chado_select('feature',array('*'),$values);
  489. // sort the children by order of their fmin positions (values of assoc. array)
  490. // if the parent is on the reverse strand then sort in reverse
  491. if($details['strand'] == -1){
  492. arsort($details['children']);
  493. } else {
  494. asort($details['children']);
  495. }
  496. // now iterate through the children and set their rank
  497. $rank = 1;
  498. print "Updating child ranks for $parent (".$details['type'].")\n";
  499. foreach($details['children'] as $kfeature_id => $kfmin){
  500. $match = array(
  501. 'object_id' => $pfeature[0]->feature_id,
  502. 'subject_id' => $kfeature_id,
  503. 'type_id' => array(
  504. 'cv_id' => array(
  505. 'name' => 'relationship'
  506. ),
  507. 'name' => 'part_of',
  508. ),
  509. );
  510. $values = array(
  511. 'rank' => $rank,
  512. );
  513. tripal_core_chado_update('feature_relationship',$match,$values);
  514. $rank++;
  515. }
  516. }
  517. }
  518. tripal_db_set_active($previous_db);
  519. return '';
  520. }
  521. /**
  522. *
  523. *
  524. * @ingroup gff3_loader
  525. */
  526. function tripal_feature_load_gff3_derives_from($feature,$subject,$gff_features,$organism){
  527. // first get the subject feature
  528. $match = array(
  529. 'organism_id' => $organism->organism_id,
  530. 'uniquename' => $subject,
  531. 'type_id' => array(
  532. 'name' => $gff_features[$subject]['type'],
  533. 'cv_id' => array(
  534. 'name' => 'sequence'
  535. ),
  536. ),
  537. );
  538. $sfeature = tripal_core_chado_select('feature',array('*'),$match);
  539. if(count($sfeature)==0){
  540. print "ERROR: could not add 'Derives_from' relationship for $feature->uniquename and $subject. Subject feature, '$subject', cannot be found\n";
  541. return;
  542. }
  543. // now check to see if the relationship already exists
  544. $values = array(
  545. 'object_id' => $sfeature[0]->feature_id,
  546. 'subject_id' => $feature->feature_id,
  547. 'type_id' => array(
  548. 'cv_id' => array(
  549. 'name' => 'relationship'
  550. ),
  551. 'name' => 'derives_from',
  552. ),
  553. 'rank' => 0
  554. );
  555. $rel = tripal_core_chado_select('feature_relationship',array('*'),$values);
  556. if(count($rel) > 0){
  557. print " Relationship already exists: $feature->uniquename derives_from $subject\n";
  558. return;
  559. }
  560. // finally insert the relationship if it doesn't exist
  561. $ret = tripal_core_chado_insert('feature_relationship',$values);
  562. if(!$ret){
  563. print "ERROR: could not add 'Derives_from' relationship for $feature->uniquename and $subject\n";
  564. } else {
  565. print " Added relationship: $feature->uniquename derives_from $subject\n";
  566. }
  567. }
  568. /**
  569. *
  570. *
  571. * @ingroup gff3_loader
  572. */
  573. function tripal_feature_load_gff3_parents($feature,$cvterm,$parents,&$gff_features,$organism_id,$fmin){
  574. $uname = $feature->uniquename;
  575. $type = $cvterm->name;
  576. $rel_type = 'part_of';
  577. // create these SQL statements that will be used repeatedly below.
  578. $cvtermsql = "SELECT CVT.cvterm_id
  579. FROM {cvterm} CVT
  580. INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
  581. LEFT JOIN {cvtermsynonym} CVTS on CVTS.cvterm_id = CVT.cvterm_id
  582. WHERE cv.name = '%s' and (CVT.name = '%s' or CVTS.synonym = '%s')";
  583. $feature_sql = "SELECT * FROM {feature}
  584. WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
  585. // iterate through the parents in the list
  586. foreach($parents as $parent){
  587. $parent_type = $gff_features[$parent]['type'];
  588. // try to find the parent
  589. $parentcvterm = db_fetch_object(db_query($cvtermsql,'sequence',$parent_type,$parent_type));
  590. $relcvterm = db_fetch_object(db_query($cvtermsql,'relationship',$rel_type,$rel_type));
  591. $parent_feature = db_fetch_object(db_query($feature_sql,$organism_id,$parent,$parentcvterm->cvterm_id));
  592. // we want to add this feature to the child list for the parent
  593. // when the loader finishes, it will go back through the parent
  594. // features and rank the children by position
  595. $gff_features[$parent]['children'][$feature->feature_id] = $fmin;
  596. // if the parent exists then add the relationship otherwise print error and skip
  597. if($parent_feature){
  598. // check to see if the relationship already exists
  599. $sql = "SELECT * FROM {feature_relationship} WHERE subject_id = %d and object_id = %d and type_id = %d";
  600. $rel = db_fetch_object(db_query($sql,$feature->feature_id,$parent_feature->feature_id,$relcvterm->cvterm_id));
  601. if($rel){
  602. print " Relationship already exists, skipping '$uname' ($type) $rel_type '$parent' ($parent_type)\n";
  603. } else {
  604. // the relationship doesn't already exist, so add it.
  605. $sql = "INSERT INTO {feature_relationship} (subject_id,object_id,type_id)
  606. VALUES (%d,%d,%d)";
  607. $result = db_query($sql,$feature->feature_id,$parent_feature->feature_id,$relcvterm->cvterm_id);
  608. if(!$result){
  609. print "WARNING: failed to insert feature relationship '$uname' ($type) $rel_type '$parent' ($parent_type)\n";
  610. } else {
  611. print " Inserted relationship relationship: '$uname' ($type) $rel_type '$parent' ($parent_type)\n";
  612. }
  613. }
  614. }
  615. else {
  616. print "WARNING: cannot establish relationship '$uname' ($type) $rel_type '$parent' ($parent_type): Cannot find the parent\n";
  617. }
  618. }
  619. }
  620. /**
  621. *
  622. *
  623. * @ingroup gff3_loader
  624. */
  625. function tripal_feature_load_gff3_dbxref($feature,$dbxrefs){
  626. // iterate through each of the dbxrefs
  627. foreach($dbxrefs as $dbxref){
  628. // get the database name from the reference. If it doesn't exist then create one.
  629. $ref = explode(":",$dbxref);
  630. $dbname = $ref[0];
  631. $accession = $ref[1];
  632. // first look for the database name if it doesn't exist then create one.
  633. // first check for the fully qualified URI (e.g. DB:<dbname>. If that
  634. // can't be found then look for the name as is. If it still can't be found
  635. // the create the database
  636. $db = tripal_core_chado_select('db',array('db_id'),array('name' => "DB:$dbname"));
  637. if(sizeof($db) == 0){
  638. $db = tripal_core_chado_select('db',array('db_id'),array('name' => "$dbname"));
  639. }
  640. if(sizeof($db) == 0){
  641. $ret = tripal_core_chado_insert('db',array('name' => $dbname,
  642. 'description' => 'Added automatically by the GFF loader'));
  643. if($ret){
  644. print " Added new database: $dbname\n";
  645. $db = tripal_core_chado_select('db',array('db_id'),array('name' => "$dbname"));
  646. } else {
  647. print "ERROR: cannot find or add the database $dbname\n";
  648. return 0;
  649. }
  650. }
  651. $db = $db[0];
  652. // now check to see if the accession exists
  653. $dbxref = tripal_core_chado_select('dbxref',array('dbxref_id'),array(
  654. 'accession' => $accession,'db_id' => $db->db_id));
  655. // if the accession doesn't exist then we want to add it
  656. if(sizeof($dbxref) == 0){
  657. $ret = tripal_core_chado_insert('dbxref',array('db_id' => $db->db_id,
  658. 'accession' => $accession,'version' => ''));
  659. $dbxref = tripal_core_chado_select('dbxref',array('dbxref_id'),array(
  660. 'accession' => $accession,'db_id' => $db->db_id));
  661. }
  662. $dbxref = $dbxref[0];
  663. // check to see if this feature dbxref already exists
  664. $fdbx = tripal_core_chado_select('feature_dbxref',array('feature_dbxref_id'),
  665. array('dbxref_id' => $dbxref->dbxref_id,'feature_id' => $feature->feature_id));
  666. // now associate this feature with the database reference if it doesn't
  667. // already exist
  668. if(sizeof($fdbx)==0){
  669. $ret = tripal_core_chado_insert('feature_dbxref',array(
  670. 'feature_id' => $feature->feature_id,
  671. 'dbxref_id' => $dbxref->dbxref_id));
  672. if($ret){
  673. print " Adding Dbxref $dbname:$accession\n";
  674. } else {
  675. print "ERROR: failed to insert Dbxref: $dbname:$accession\n";
  676. return 0;
  677. }
  678. } else {
  679. print " Dbxref already associated, skipping $dbname:$accession\n";
  680. }
  681. }
  682. return 1;
  683. }
  684. /**
  685. *
  686. *
  687. * @ingroup gff3_loader
  688. */
  689. function tripal_feature_load_gff3_ontology($feature,$dbxrefs){
  690. // iterate through each of the dbxrefs
  691. foreach($dbxrefs as $dbxref){
  692. // get the database name from the reference. If it doesn't exist then create one.
  693. $ref = explode(":",$dbxref);
  694. $dbname = $ref[0];
  695. $accession = $ref[1];
  696. // first look for the database name
  697. $db = tripal_core_chado_select('db',array('db_id'),array('name' => "DB:$dbname"));
  698. if(sizeof($db) == 0){
  699. $db = tripal_core_chado_select('db',array('db_id'),array('name' => "$dbname"));
  700. }
  701. if(sizeof($db) == 0){
  702. print "ERROR: Database, $dbname is missing for reference: $dbname:$accession\n";
  703. return 0;
  704. }
  705. $db = $db[0];
  706. // now check to see if the accession exists
  707. $dbxref = tripal_core_chado_select('dbxref',array('dbxref_id'),array(
  708. 'accession' => $accession,'db_id' => $db->db_id));
  709. if(sizeof($dbxref) == 0){
  710. print "ERROR: Accession, $accession is missing for reference: $dbname:$accession\n";
  711. return 0;
  712. }
  713. $dbxref = $dbxref[0];
  714. // now check to see if the cvterm exists
  715. $cvterm = tripal_core_chado_select('cvterm',array('cvterm_id'),array(
  716. 'dbxref_id' => $dbxref->dbxref_id));
  717. // if it doesn't exist in the cvterm table, look for an alternate id
  718. if(sizeof($cvterm) == 0){
  719. $cvterm = tripal_core_chado_select('cvterm_dbxref',array('cvterm_id'),array(
  720. 'dbxref_id' => $dbxref->dbxref_id));
  721. }
  722. if(sizeof($cvterm) == 0){
  723. print "ERROR: CVTerm is missing for reference: $dbname:$accession\n";
  724. return 0;
  725. }
  726. $cvterm = $cvterm[0];
  727. // check to see if this feature cvterm already exists
  728. $fcvt = tripal_core_chado_select('feature_cvterm',array('feature_cvterm_id'),
  729. array('cvterm_id' => $cvterm->cvterm_id,'feature_id' => $feature->feature_id));
  730. // now associate this feature with the cvterm if it doesn't already exist
  731. if(sizeof($fcvt)==0){
  732. $values = array(
  733. 'feature_id' => $feature->feature_id,
  734. 'cvterm_id' => $cvterm->cvterm_id,
  735. 'pub_id' => array(
  736. 'uniquename' => 'null',
  737. ),
  738. );
  739. $ret = tripal_core_chado_insert('feature_cvterm',$values);
  740. if($ret){
  741. print " Adding ontology term $dbname:$accession\n";
  742. } else {
  743. print "ERROR: failed to insert ontology term: $dbname:$accession\n";
  744. return 0;
  745. }
  746. } else {
  747. print " Ontology term already associated, skipping $dbname:$accession\n";
  748. }
  749. }
  750. return 1;
  751. }
  752. /**
  753. *
  754. *
  755. * @ingroup gff3_loader
  756. */
  757. function tripal_feature_load_gff3_alias($feature,$aliases){
  758. // make sure we have a 'synonym_type' vocabulary
  759. $sql = "SELECT * FROM {cv} WHERE name='synonym_type'";
  760. $syncv = db_fetch_object(db_query($sql));
  761. if(!$syncv){
  762. $sql = "INSERT INTO {cv} (name,definition) VALUES ('synonym_type','')";
  763. if(!db_query($sql)){
  764. print("ERROR: Failed to add the synonyms type vocabulary");
  765. return 0;
  766. }
  767. $syncv = db_fetch_object(db_query($sql));
  768. }
  769. // get the 'exact' cvterm, which is the type of synonym we're adding
  770. $cvtsql = "
  771. SELECT * FROM {cvterm} CVT
  772. INNER JOIN {cv} CV ON CVT.cv_id = CV.cv_id
  773. WHERE CVT.name = '%s' and CV.name = '%s'
  774. ";
  775. $syntype = db_fetch_object(db_query($cvtsql,'exact','synonym_type'));
  776. if(!$syntype){
  777. $term = array(
  778. 'name' => array('exact'),
  779. 'id' => array("internal:exact"),
  780. 'definition' => array(''),
  781. 'is_obsolete' => array(0),
  782. );
  783. $syntype = tripal_cv_add_cvterm($term,$syncv,0,1);
  784. if(!$syntype){
  785. print("Cannot add synonym type: internal:$type");
  786. return 0;
  787. }
  788. }
  789. // iterate through all of the aliases and add each one
  790. foreach($aliases as $alias){
  791. print " Adding Alias $alias\n";
  792. // check to see if the alias already exists in the synonym table
  793. // if not, then add it
  794. $synsql = "SELECT * FROM {synonym}
  795. WHERE name = '%s' and type_id = %d";
  796. $synonym = db_fetch_object(db_query($synsql,$alias,$syntype->cvterm_id));
  797. if(!$synonym){
  798. $sql = "INSERT INTO {synonym}
  799. (name,type_id,synonym_sgml)
  800. VALUES ('%s',%d,'%s')";
  801. $result = db_query($sql,$alias,$syntype->cvterm_id,'');
  802. if(!$result){
  803. print "ERROR: cannot add alias $alias to synonym table\n";
  804. }
  805. }
  806. $synonym = db_fetch_object(db_query($synsql,$alias,$syntype->cvterm_id));
  807. // check to see if we have a NULL publication in the pub table. If not,
  808. // then add one.
  809. $pubsql = "SELECT * FROM {pub} WHERE uniquename = 'null'";
  810. $pub = db_fetch_object(db_query($pubsql));
  811. if(!$pub){
  812. $sql = "INSERT INTO pub (uniquename,type_id) VALUES ('%s',
  813. (SELECT cvterm_id
  814. FROM cvterm CVT
  815. INNER JOIN dbxref DBX on DBX.dbxref_id = CVT.dbxref_id
  816. INNER JOIN db DB on DB.db_id = DBX.db_id
  817. WHERE CVT.name = 'null' and DB.name = 'null')";
  818. $result = db_query($sql,'null');
  819. if(!$result){
  820. print "ERROR: cannot add null publication needed for setup of alias\n";
  821. return 0;
  822. }
  823. }
  824. $pub = db_fetch_object(db_query($pubsql));
  825. // check to see if the synonym exists in the feature_synonym table
  826. // if not, then add it.
  827. $synsql = "SELECT * FROM {feature_synonym}
  828. WHERE synonym_id = %d and feature_id = %d and pub_id = %d";
  829. $fsyn = db_fetch_object(db_query($synsql,$synonym->synonym_id,$feature->feature_id,$pub->pub_id));
  830. if(!$fsyn){
  831. $sql = "INSERT INTO {feature_synonym}
  832. (synonym_id,feature_id,pub_id)
  833. VALUES (%d,%d,%d)";
  834. $result = db_query($sql,$synonym->synonym_id,$feature->feature_id,$pub->pub_id);
  835. if(!$result){
  836. print "ERROR: cannot add alias $alias to feature synonym table\n";
  837. return 0;
  838. }
  839. } else {
  840. print " Synonym $alias already exists. Skipping\n";
  841. }
  842. }
  843. return 1;
  844. }
  845. /**
  846. *
  847. *
  848. * @ingroup gff3_loader
  849. */
  850. function tripal_feature_load_gff3_feature($organism,$analysis_id,$cvterm,$uniquename,$name,
  851. $residues,$is_analysis='f',$is_obsolete='f',$add_only,$score) {
  852. // check to see if the feature already exists
  853. $feature_sql = "SELECT * FROM {feature}
  854. WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
  855. $feature = db_fetch_object(db_query($feature_sql,$organism->organism_id,$uniquename,$cvterm->cvterm_id));
  856. if(strcmp($is_obsolete,'f')==0){
  857. $is_obsolete = 'false';
  858. }
  859. if(strcmp($is_analysis,'f')==0){
  860. $is_analysis = 'false';
  861. }
  862. // insert the feature if it does not exist otherwise perform an update
  863. if(!$feature){
  864. print "Adding feature '$uniquename' ($cvterm->name)\n";
  865. $isql = "INSERT INTO {feature} (organism_id, name, uniquename, residues, seqlen,
  866. md5checksum, type_id,is_analysis,is_obsolete)
  867. VALUES(%d,'%s','%s','%s',%d, '%s', %d, %s, %s)";
  868. $result = db_query($isql,$organism->organism_id,$name,$uniquename,$residues,strlen($residues),
  869. md5($residues),$cvterm->cvterm_id,$is_analysis,$is_obsolete);
  870. if(!$result){
  871. print "ERROR: failed to insert feature '$uniquename' ($cvterm->name)\n";
  872. return 0;
  873. }
  874. }
  875. elseif(!$add_only) {
  876. print "Updating feature '$uniquename' ($cvterm->name)\n";
  877. $usql = "UPDATE {feature}
  878. SET name = '%s', residues = '%s', seqlen = '%s', md5checksum = '%s',
  879. is_analysis = %s, is_obsolete = %s
  880. WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
  881. $result = db_query($usql,$name,$residues,strlen($residues),md5($residues),$is_analysis,$is_obsolete,
  882. $organism_id,$uniquename,$cvterm->cvterm_id);
  883. if(!$result){
  884. print "ERROR: failed to update feature '$uniquename' ($cvterm->name)\n";
  885. return 0;
  886. }
  887. }
  888. else {
  889. // the feature exists and we don't want to update it so return
  890. // a value of 0. This will stop all downstream property additions
  891. print "Skipping existing feature: '$uniquename' ($cvterm->name).\n";
  892. return 0;
  893. }
  894. // get the newly added feature
  895. $feature = db_fetch_object(db_query($feature_sql,$organism->organism_id,$uniquename,$cvterm->cvterm_id));
  896. // add the analysisfeature entry to the analysisfeature table if it doesn't already exist
  897. $af_values = array(
  898. 'analysis_id' => $analysis_id,
  899. 'feature_id' => $feature->feature_id
  900. );
  901. $afeature = tripal_core_chado_select('analysisfeature',array('analysisfeature_id'),$af_values,array('has_record'));
  902. if(count($afeature)==0){
  903. // if a score is avaialble then set that to be the significance field
  904. if(strcmp($score,'.')!=0){
  905. $af_values['significance'] = $score;
  906. }
  907. if(!tripal_core_chado_insert('analysisfeature',$af_values)){
  908. print "ERROR: could not add analysisfeature record: $analysis_id, $feature->feature_id\n";
  909. } else {
  910. print " Added analysisfeature record\n";
  911. }
  912. } else {
  913. // if a score is available then set that to be the significance field
  914. $new_vals = array();
  915. if(strcmp($score,'.')!=0){
  916. $new_vals['significance'] = $score;
  917. } else {
  918. $new_vals['significance'] = '__NULL__';
  919. }
  920. if(!$add_only){
  921. $ret = tripal_core_chado_update('analysisfeature',$af_values,$new_vals);
  922. if(!$ret){
  923. print "ERROR: could not update analysisfeature record: $analysis_id, $feature->feature_id\n";
  924. } else {
  925. print " Updated analysisfeature record\n";
  926. }
  927. }
  928. }
  929. return $feature;
  930. }
  931. /**
  932. *
  933. *
  934. * @ingroup gff3_loader
  935. */
  936. function tripal_feature_load_gff3_featureloc($feature,$organism,$landmark,$fmin,
  937. $fmax,$strand,$phase,$is_fmin_partial,$is_fmax_partial,$residue_info,$locgroup)
  938. {
  939. // get the source feature
  940. $sql = "SELECT * FROM {feature}
  941. WHERE organism_id = %d and uniquename = '%s'";
  942. $srcfeature = db_fetch_object(db_query($sql,$organism->organism_id,$landmark));
  943. if(!$srcfeature){
  944. print "ERROR: cannot find landmark feature $landmark. Cannot add the feature location record\n";
  945. return 0;
  946. }
  947. // TODO: create an attribute that recognizes the residue_info,locgroup, is_fmin_partial and is_fmax_partial, right now these are
  948. // hardcoded to be false and 0 below.
  949. // check to see if this featureloc already exists, but also keep track of the
  950. // last rank value
  951. $rank = 0;
  952. $exists = 0;
  953. $featureloc_sql = "SELECT FL.featureloc_id,FL.fmin,FL.fmax,F.uniquename as srcname,
  954. rank
  955. FROM {featureloc} FL
  956. INNER JOIN {feature} F on F.feature_id = FL.srcfeature_id
  957. WHERE FL.feature_id = %d
  958. ORDER BY rank ASC";
  959. $recs = db_query($featureloc_sql,$feature->feature_id);
  960. while ($featureloc = db_fetch_object($recs)){
  961. if(strcmp($featureloc->srcname,$landmark)==0 and
  962. $featureloc->fmin == $fmin and $featureloc->fmax == $fmax){
  963. // this is the same featureloc, so do nothing... no need to update
  964. //TODO: need more checks here
  965. print " No change to featureloc\n";
  966. $exists = 1;
  967. }
  968. $rank = $featureloc->rank + 1;
  969. }
  970. if(!$exists){
  971. $rank++;
  972. // this feature location is new so add it
  973. if(!$phase){
  974. $phase = 'NULL';
  975. }
  976. if(strcmp($is_fmin_partial,'f')==0){
  977. $is_fmin_partial = 'false';
  978. }
  979. elseif(strcmp($is_fmin_partial,'t')==0){
  980. $is_fmin_partial = 'true';
  981. }
  982. if(strcmp($is_fmax_partial,'f')==0){
  983. $is_fmax_partial = 'false';
  984. }
  985. elseif(strcmp($is_fmax_partial,'t')==0){
  986. $is_fmax_partial = 'true';
  987. }
  988. print " Adding featureloc $srcfeature->uniquename fmin: $fmin, fmax: $fmax, strand: $strand, phase: $phase, rank: $rank\n";
  989. $fl_isql = "INSERT INTO {featureloc}
  990. (feature_id, srcfeature_id, fmin, is_fmin_partial, fmax, is_fmax_partial,
  991. strand, phase, residue_info, locgroup, rank)
  992. VALUES (%d,%d,%d,%s,%d,%s,%d,%s,'%s',%d,%d)";
  993. $result = db_query($fl_isql,$feature->feature_id,$srcfeature->feature_id,$fmin,$is_fmin_partial,$fmax,$is_fmax_partial,
  994. $strand,$phase,$residue_info,$locgroup,$rank);
  995. if(!$result){
  996. print "ERROR: failed to insert featureloc\n";
  997. exit;
  998. return 0;
  999. }
  1000. }
  1001. return 1;
  1002. }
  1003. /**
  1004. *
  1005. *
  1006. * @ingroup gff3_loader
  1007. */
  1008. function tripal_feature_load_gff3_property($feature,$property,$value){
  1009. // first make sure the cvterm exists. If the term already exists then
  1010. // the function should return it of not, then add it
  1011. $cvt_sql = "SELECT * FROM {cvterm} CVT
  1012. INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
  1013. WHERE CV.name = '%s' and CVT.name = '%s'";
  1014. $cvterm = db_fetch_object(db_query($cvt_sql,'feature_property',$property));
  1015. if(!$cvterm){
  1016. $term = array(
  1017. 'id' => "null:$property",
  1018. 'name' => $property,
  1019. 'namespace' => 'feature_property',
  1020. 'is_obsolete' => 0,
  1021. );
  1022. print " Adding cvterm, $property\n";
  1023. $cvterm = (object) tripal_cv_add_cvterm($term,'feature_property',0,0);
  1024. }
  1025. if(!$cvterm){
  1026. print "ERROR: cannot add cvterm, $property\n";
  1027. exit;
  1028. }
  1029. // check to see if the property already exists for this feature
  1030. // if it does but the value is unique then increment the rank and add it.
  1031. // if the value is not unique then don't add it.
  1032. $add = 1;
  1033. $rank = 0;
  1034. $sql = "SELECT rank,value FROM {featureprop}
  1035. WHERE feature_id = %d and type_id = %d
  1036. ORDER BY rank ASC";
  1037. $result = db_query($sql,$feature->feature_id,$cvterm->cvterm_id);
  1038. while($prop = db_fetch_object($result)){
  1039. if(strcmp($prop->value,$value)==0){
  1040. $add = NULL; // don't add it, it already exists
  1041. print " Property already exists, skipping\n";
  1042. }
  1043. $rank = $prop->rank + 1;
  1044. }
  1045. // add the property if we pass the check above
  1046. if($add){
  1047. print " Setting feature property. $property: $value\n";
  1048. $isql = "INSERT INTO {featureprop} (feature_id,type_id,value,rank)
  1049. VALUES (%d,%d,'%s',%d)";
  1050. db_query($isql,$feature->feature_id,$cvterm->cvterm_id,$value,$rank);
  1051. }
  1052. }
  1053. /*
  1054. function tripal_feature_load_gff3_property($feature,$property,$value){
  1055. // first make sure the cvterm exists. If the term already exists then
  1056. // the function should return it
  1057. $match = array(
  1058. 'name' => $property,
  1059. 'cv_id' => array(
  1060. 'name' => 'feature_property',
  1061. ),
  1062. );
  1063. $cvterm = tripal_core_chado_select('cvterm',array('*'),$match);
  1064. if(sizeof($cvterm) == 0){
  1065. $term = array(
  1066. 'id' => "null:$property",
  1067. 'name' => $property,
  1068. 'namespace' => 'feature_property',
  1069. 'is_obsolete' => 0,
  1070. );
  1071. print " Adding cvterm, $property\n";
  1072. $cvterm = tripal_cv_add_cvterm($term,'feature_property',0,0);
  1073. }
  1074. if(!$cvterm){
  1075. print "ERROR: cannot add cvterm, $property, before adding property\n";
  1076. exit;
  1077. }
  1078. // next give the feature the property
  1079. tripal_core_insert_property('feature',$feature->feature_id,$property,'feature_property',$value,1);
  1080. }
  1081. */