tripal_feature.api.inc 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. <?php
  2. /**
  3. * @file
  4. * Provides an application programming interface (API) for working with features
  5. *
  6. * @defgroup tripal_feature_api Feature Module API
  7. * @ingroup tripal_api
  8. */
  9. /**
  10. * Retrieve properties from the analysisfeatureprop table for a feature.
  11. *
  12. * @param $analysis_id
  13. * The analysis ID for the analysis feature. This argument is optional but
  14. * if specified it must also be accompanied with a feature ID.
  15. * @param $feature_id
  16. * The feature ID for the analysis feature. This argument is optional but
  17. * if specified it must also be accompanied with an analysis ID.
  18. * @param $analysisfeature_id
  19. * The analysis feature ID for the analysis feature. This argument is
  20. * optional and can be used rather than specifying the $analysis_id and
  21. * $feature_id arguments. If all three arguments are specified (e.g.
  22. * an $analysis_id, $feature_id and $analysisfeature_id, then the
  23. * $analysisfeature_id is used and the other two arguments are ignored.
  24. * @param $property
  25. * The cvterm name of the properties to retrieve
  26. * @param $cv_name
  27. * Optional. The name of the cv to which the property belongs. By
  28. * default this is the 'tripal' cv.
  29. *
  30. * @return
  31. * An analysisfeature chado variable with the specified properties expanded
  32. *
  33. * @ingroup tripal_feature_api
  34. */
  35. function tripal_feature_analysis_get_property($analysis_id = NULL, $feature_id = NUll,
  36. $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
  37. // check that the incoming arguments are correct
  38. if (($analysis_id and !$feature_id) or
  39. (!$analysis_id and $feature_id)) {
  40. watchdog('tripal_feature',
  41. 'tripal_feature_analysis_get_property: Both an analysis ID and feature ID should be specified',
  42. array(), WATCHDOG_WARNING);
  43. }
  44. // get the analysisfeature_id if one is not provided
  45. if (!$analysisfeature_id) {
  46. $columns = array('analysisfeature_id');
  47. $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
  48. $result = tripal_core_chado_select('analysisfeature', $columns, $values);
  49. $analysisfeature_id = $result[0]->analysisfeature_id;
  50. }
  51. // get the property.
  52. return tripal_core_get_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
  53. }
  54. /**
  55. * Insert a property for an analysis feature
  56. *
  57. * @param $analysis_id
  58. * The analysis ID for the analysis feature. This argument is optional but
  59. * if specified it must also be accompanied with a feature ID.
  60. * @param $feature_id
  61. * The feature ID for the analysis feature. This argument is optional but
  62. * if specified it must also be accompanied with an analysis ID.
  63. * @param $analysisfeature_id
  64. * The analysis feature ID for the analysis feature. This argument is
  65. * optional and can be used rather than specifying the $analysis_id and
  66. * $feature_id arguments. If all three arguments are specified (e.g.
  67. * an $analysis_id, $feature_id and $analysisfeature_id, then the
  68. * $analysisfeature_id is used and the other two arguments are ignored.
  69. * @param $property
  70. * The cvterm name of the property to insert
  71. * @param $value
  72. * The value of the property to insert
  73. * @param $update_if_present
  74. * A boolean indicated whether to update the record if it's already present
  75. * @param $cv_name
  76. * Optional. The name of the cv to which the property belongs. By
  77. * default this is the 'tripal' cv.
  78. *
  79. * @return
  80. * True of success, False otherwise
  81. *
  82. * @ingroup tripal_feature_api
  83. */
  84. function tripal_feature_analysis_insert_property($analysis_id = NULL, $feature_id = NUll,
  85. $analysisfeature_id = NULL, $property, $value, $update_if_present = 0, $cv_name = 'tripal') {
  86. // check that the incoming arguments are correct
  87. if (($analysis_id and !$feature_id) or
  88. (!$analysis_id and $feature_id)) {
  89. watchdog('tripal_feature',
  90. 'tripal_feature_analysis_insert_property: Both an analysis ID and feature ID should be specified',
  91. array(), WATCHDOG_WARNING);
  92. }
  93. // get the analysisfeature_id if one is not provided
  94. if (!$analysisfeature_id) {
  95. $columns = array('analysisfeature_id');
  96. $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
  97. $result = tripal_core_chado_select('analysisfeature', $columns, $values);
  98. $analysisfeature_id = $result[0]->analysisfeature_id;
  99. }
  100. // insert the property.
  101. $success = tripal_core_insert_property('analysisfeature', $analysisfeature_id,
  102. $property, $cv_name, $value, $update_if_present);
  103. if (!$success) {
  104. watchdog('tripal_feature',
  105. 'tripal_feature_analysis_insert_property: Failed to insert analysis feature property',
  106. array(), WATCHDOG_WARNING);
  107. return FALSE;
  108. }
  109. return $success;
  110. }
  111. /**
  112. * Update an analysis feature property using the property name. Use this
  113. * when a property only exists once for a given analysis feature. When more
  114. * than one value can exist for the same property use the
  115. * tripal_feature_analysis_update_property_by_id() function.
  116. *
  117. * @param $analysis_id
  118. * The analysis ID for the analysis feature. This argument is optional but
  119. * if specified it must also be accompanied with a feature ID.
  120. * @param $feature_id
  121. * The feature ID for the analysis feature. This argument is optional but
  122. * if specified it must also be accompanied with an analysis ID.
  123. * @param $analysisfeature_id
  124. * The analysis feature ID for the analysis feature. This argument is
  125. * optional and can be used rather than specifying the $analysis_id and
  126. * $feature_id arguments. If all three arguments are specified (e.g.
  127. * an $analysis_id, $feature_id and $analysisfeature_id, then the
  128. * $analysisfeature_id is used and the other two arguments are ignored.
  129. * @param $property
  130. * The cvterm name of the property to update
  131. * @param $value
  132. * The value of the property to update
  133. * @param $insert_if_missing
  134. * A boolean indicated whether to insert the record if it's absent
  135. * @param $cv_name
  136. * Optional. The name of the cv to which the property belongs. By
  137. * default this is the 'tripal' cv.
  138. *
  139. * Note: The property will be identified using the unique combination of the $analysis_id and $property
  140. * and then it will be updated with the supplied value
  141. *
  142. * @return
  143. * True of success, False otherwise
  144. *
  145. * @ingroup tripal_feature_api
  146. */
  147. function tripal_feature_analysis_update_property($analysis_id = NULL, $feature_id = NUll,
  148. $analysisfeature_id = NULL, $property, $value, $insert_if_missing = 0,
  149. $cv_name = 'tripal') {
  150. // check that the incoming arguments are correct
  151. if (($analysis_id and !$feature_id) or
  152. (!$analysis_id and $feature_id)) {
  153. watchdog('tripal_feature',
  154. 'tripal_feature_analysis_update_property: Both an analysis ID and feature ID should be specified',
  155. array(), WATCHDOG_WARNING);
  156. }
  157. // get the analysisfeature_id if one is not provided
  158. if (!$analysisfeature_id) {
  159. $columns = array('analysisfeature_id');
  160. $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
  161. $result = tripal_core_chado_select('analysisfeature', $columns, $values);
  162. $analysisfeature_id = $result[0]->analysisfeature_id;
  163. }
  164. // update the property.
  165. return tripal_core_update_property('analysisfeature', $analysisfeature_id, $property, $cv_name, $value, $insert_if_missing);
  166. }
  167. /**
  168. * Update a property for an analysis feature using the analysisfeatureprop_id.
  169. *
  170. * @param $analysisfeatureprop_id
  171. * The analysis feature property ID for the analysis feature.
  172. * @param $property
  173. * The cvterm name of the property
  174. * @param $value
  175. * The value of the property
  176. * @param $cv_name
  177. * Optional. The name of the cv to which the property belongs. By
  178. * default this is the 'tripal' cv.
  179. * *
  180. * @return
  181. * True of success, False otherwise
  182. *
  183. * @ingroup tripal_feature_api
  184. */
  185. function tripal_feature_analysis_update_property_by_id($analysisfeatureprop_id,
  186. $property, $value, $cv_name = 'tripal') {
  187. // update the property.
  188. return tripal_core_update_property_by_id('analysisfeature',
  189. $analysisfeatureprop_id, $property, $cv_name, $value);
  190. }
  191. /**
  192. * Delete an analysis feature property using the property name. Use this
  193. * when a property only exists once for a given analysis feature. When more
  194. * than one value can exist for the same property use the
  195. * tripal_feature_analysis_delete_property_by_id() function.
  196. *
  197. * @param $analysis_id
  198. * The analysis ID for the analysis feature. This argument is optional but
  199. * if specified it must also be accompanied with a feature ID.
  200. * @param $feature_id
  201. * The feature ID for the analysis feature. This argument is optional but
  202. * if specified it must also be accompanied with an analysis ID.
  203. * @param $analysisfeature_id
  204. * The analysis feature ID for the analysis feature. This argument is
  205. * optional and can be used rather than specifying the $analysis_id and
  206. * $feature_id arguments. If all three arguments are specified (e.g.
  207. * an $analysis_id, $feature_id and $analysisfeature_id, then the
  208. * $analysisfeature_id is used and the other two arguments are ignored.
  209. * @param $property
  210. * The cvterm name of the property to delete
  211. * @param $cv_name
  212. * Optional. The name of the cv to which the property belongs. By
  213. * default this is the 'tripal' cv.
  214. *
  215. * Note: The property will be identified using the unique combination of the $analysis_id and $property
  216. * and then it will be deleted
  217. *
  218. * @return
  219. * True of success, False otherwise
  220. *
  221. * @ingroup tripal_feature_api
  222. */
  223. function tripal_feature_analysis_delete_property($analysis_id = NULL, $feature_id = NUll,
  224. $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
  225. // check that the incoming arguments are correct
  226. if (($analysis_id and !$feature_id) or
  227. (!$analysis_id and $feature_id)) {
  228. watchdog('tripal_feature',
  229. 'tripal_feature_analysis_delete_property: Both an analysis ID and feature ID should be specified',
  230. array(), WATCHDOG_WARNING);
  231. }
  232. // get the analysisfeature_id if one is not provided
  233. if (!$analysisfeature_id) {
  234. $columns = array('analysisfeature_id');
  235. $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
  236. $result = tripal_core_chado_select('analysisfeature', $columns, $values);
  237. $analysisfeature_id = $result[0]->analysisfeature_id;
  238. }
  239. // get the property.
  240. return tripal_core_delete_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
  241. }
  242. /**
  243. * Delete a property using the analysisfeatureprop_id
  244. *
  245. * @param $analysisfeatureprop_id
  246. * The analysis feature property ID for the analysis feature.
  247. *
  248. * @return
  249. * True of success, False otherwise
  250. *
  251. * @ingroup tripal_feature_api
  252. */
  253. function tripal_feature_analysis_delete_property_by_id($analysisfeatureprop_id) {
  254. // get the property.
  255. return tripal_core_delete_property_by_id('analysisfeature', $analysisfeatureprop_id);
  256. }
  257. /**
  258. * Retrieve properties of a given type for a given feature
  259. *
  260. * @param $feature_id
  261. * The feature_id of the properties you would like to retrieve
  262. * @param $property
  263. * The cvterm name of the properties to retrieve
  264. * @param $cv_name
  265. * Optional. The name of the cv to which the property belongs. By
  266. * default this is the 'tripal' cv.
  267. *
  268. * @return
  269. * A feature chado variable with the specified properties expanded
  270. *
  271. * @ingroup tripal_feature_api
  272. */
  273. function tripal_feature_get_property($feature_id, $property, $cv_name='tripal') {
  274. return tripal_core_get_property('feature', $feature_id, $property, $cv_name);
  275. }
  276. /**
  277. * Insert a given property
  278. *
  279. * @param $feature_id
  280. * The feature_id of the property to insert
  281. * @param $property
  282. * The cvterm name of the property to insert
  283. * @param $value
  284. * The value of the property to insert
  285. * @param $update_if_present
  286. * A boolean indicated whether to update the record if it's already present
  287. * @param $cv_name
  288. * Optional. The name of the cv to which the property belongs. By
  289. * default this is the 'tripal' cv.
  290. *
  291. * @return
  292. * True of success, False otherwise
  293. *
  294. * @ingroup tripal_feature_api
  295. */
  296. function tripal_feature_insert_property($feature_id, $property, $value,
  297. $update_if_present = 0, $cv_name = 'tripal') {
  298. return tripal_core_insert_property('feature', $feature_id, $property,
  299. $cv_name, $value, $update_if_present);
  300. }
  301. /**
  302. * Update a feature property using the property name. Only use this
  303. * if the property is unique and only exist once for the feature.
  304. *
  305. * @param $feature_id
  306. * The feature_id of the property to update
  307. * @param $property
  308. * The cvterm name of the property to update
  309. * @param $value
  310. * The value of the property to update
  311. * @param $insert_if_missing
  312. * A boolean indicated whether to insert the record if it's absent
  313. * @param $cv_name
  314. * Optional. The name of the cv to which the property belongs. By
  315. * default this is the 'tripal' cv.
  316. *
  317. * Note: The property will be identified using the unique combination of the $feature_id and $property
  318. * and then it will be updated with the supplied value
  319. *
  320. * @return
  321. * True of success, False otherwise
  322. *
  323. * @ingroup tripal_feature_api
  324. */
  325. function tripal_feature_update_property($feature_id, $property,
  326. $value, $insert_if_missing = 0, $cv_name = 'tripal') {
  327. return tripal_core_update_property('feature', $feature_id, $property, $cv_name, $value, $insert_if_missing);
  328. }
  329. /**
  330. * Update a given feature property using the featureprop_id
  331. *
  332. * @param $featureprop_id
  333. * The featureprop_id of the property to update
  334. * @param $property
  335. * The cvterm name of the property
  336. * @param $value
  337. * The value of the property
  338. * @param $cv_name
  339. * Optional. The name of the cv to which the property belongs. By
  340. * default this is the 'tripal' cv.
  341. *
  342. * @return
  343. * True of success, False otherwise
  344. *
  345. * @ingroup tripal_feature_api
  346. */
  347. function tripal_feature_update_property_by_id($featureprop_id, $property,
  348. $value, $cv_name = 'tripal') {
  349. return tripal_core_update_property_by_id('feature', $featureprop_id, $property, $cv_name, $value);
  350. }
  351. /**
  352. * Delete a given feature property using the property name. Only use this
  353. * if the property is unique and only exists once for the feature.
  354. *
  355. * @param $feature_id
  356. * The feature_id of the property to delete
  357. * @param $property
  358. * The cvterm name of the property to delete
  359. * @param $cv_name
  360. * Optional. The name of the cv to which the property belongs. By
  361. * default this is the 'tripal' cv.
  362. *
  363. * Note: The property will be identified using the unique combination of the $feature_id and $property
  364. * and then it will be deleted
  365. *
  366. * @return
  367. * True of success, False otherwise
  368. *
  369. * @ingroup tripal_feature_api
  370. */
  371. function tripal_feature_delete_property($feature_id, $property, $cv_name='tripal') {
  372. return tripal_core_delete_property('feature', $feature_id, $property, $cv_name);
  373. }
  374. /**
  375. * Delete a given feature property using the featureprop_id
  376. *
  377. * @param $featureprop_id
  378. * The feature_id of the property to delete
  379. *
  380. * @return
  381. * True of success, False otherwise
  382. *
  383. * @ingroup tripal_feature_api
  384. */
  385. function tripal_feature_delete_property_by_id($featureprop_id) {
  386. return tripal_core_delete_property_by_id('feature', $featureprop_id);
  387. }
  388. /**
  389. * Performs a reverse compliment of a nucleotide sequence
  390. *
  391. * @param $sequence
  392. * The nucelotide sequence
  393. *
  394. * @return
  395. * an upper-case reverse complemented sequence
  396. *
  397. * @ingroup tripal_feature_api
  398. */
  399. function tripal_feature_reverse_complement($sequence) {
  400. $seq = strtoupper($sequence);
  401. $seq = strrev($seq);
  402. $seq = str_replace("A", "t", $seq);
  403. $seq = str_replace("T", "a", $seq);
  404. $seq = str_replace("G", "c", $seq);
  405. $seq = str_replace("C", "g", $seq);
  406. $seq = str_replace("Y", "r", $seq);
  407. $seq = str_replace("R", "y", $seq);
  408. $seq = str_replace("W", "w", $seq);
  409. $seq = str_replace("S", "s", $seq);
  410. $seq = str_replace("K", "m", $seq);
  411. $seq = str_replace("M", "k", $seq);
  412. $seq = str_replace("D", "h", $seq);
  413. $seq = str_replace("V", "b", $seq);
  414. $seq = str_replace("H", "d", $seq);
  415. $seq = str_replace("B", "v", $seq);
  416. return strtoupper($seq);
  417. }
  418. /**
  419. * Retrieves the sequence for a feature.
  420. *
  421. * @param $feature_id
  422. * The feature_id of the feature for which the sequence will be retrieved
  423. * @param $feature_name
  424. * The feature name. This will appear on the FASTA definition line
  425. * @param $num_bases_per_line
  426. * Indicate the number of bases to use per line. A new line will be added
  427. * after the specified number of bases on each line.
  428. * @param $derive_from_parent
  429. * Set to '1' if the sequence should be obtained from the parent to which
  430. * this feature is aligned.
  431. * @param $aggregate
  432. * Set to '1' if the sequence should only contain sub features, excluding
  433. * intra sub feature sequence. For example, set this option to obtain just
  434. * the coding sequence of an mRNA.
  435. * @param $output_format
  436. * The type of format. Valid formats include 'fasta_html', 'fasta_txt' and
  437. * 'raw'. The format 'fasta_txt' outputs line
  438. * breaks as <br> tags and the entire return value is in a <span> tag
  439. * with a fixed-width font definition. 'fasta_txt' outputs line breaks with
  440. * windows format carriage returns (e.g. \r\n) with no other formatting. The
  441. * raw format is simply the sequence with now FASTA formatting and no
  442. * line breaks.
  443. * @param $upstream
  444. * An integer specifing the number of upstream bases to include in the output
  445. * @param $downstream
  446. * An integer specifying the number of downstream bases to include in the
  447. * output.
  448. * @param $sub_features
  449. * Only include sub features (or child features) of the types provided in the array
  450. * @param $subject_rel
  451. * Retreives the sequence of any features in relationship with the feature_id
  452. * where the feature_id is the subject of the relationship.
  453. * @param $object_rel
  454. * Retreives the sequence of any features in relationship with the feature_id
  455. * where the feature_id is the object of the relationship.
  456. *
  457. * @return
  458. * The DNA/protein sequence formated as requested.
  459. *
  460. * @ingroup tripal_feature_api
  461. */
  462. function tripal_feature_get_formatted_sequence($feature_id, $feature_name,
  463. $num_bases_per_line, $derive_from_parent, $aggregate, $output_format,
  464. $upstream, $downstream, $sub_features = array(), $subject_rel, $object_rel) {
  465. // to speed things up we need to make sure we have a persistent connection
  466. $connection = tripal_db_persistent_chado();
  467. if (!$upstream) {
  468. $upstream = 0;
  469. }
  470. if (!$downstream) {
  471. $downstream = 0;
  472. }
  473. if ($subject_rel or $object_rel) {
  474. if($subject_rel) {
  475. $psql = '
  476. PREPARE feature_by_subject (int, text) AS
  477. SELECT F2.feature_id, F2.name, F2.uniquename, CVT2.name as feature_type, O.genus, O.species
  478. FROM feature F
  479. INNER JOIN feature_relationship FR ON FR.subject_id = F.feature_id
  480. INNER JOIN cvterm CVT ON CVT.cvterm_id = FR.type_id
  481. INNER JOIN feature F2 ON F2.feature_id = FR.object_id
  482. INNER JOIN cvterm CVT2 ON CVT2.cvterm_id = F2.type_id
  483. INNER JOIN organism O ON O.organism_id = F2.organism_id
  484. WHERE
  485. F.feature_id = $1 AND
  486. CVT.name = $2
  487. ';
  488. $status = tripal_core_chado_prepare('feature_by_subject', $psql, array('int', 'text'));
  489. if (!$status) {
  490. watchdog('tripal_feature', "init: not able to prepare SQL statement '%name'",
  491. array('%name' => 'feature_by_subject'), 'WATCHDOG ERROR');
  492. }
  493. $sql = "EXECUTE feature_by_subject (%d,'%s')";
  494. $features = chado_query($sql, $feature_id, $subject_rel);
  495. }
  496. if($object_rel) {
  497. $psql = '
  498. PREPARE feature_by_object (int, text) AS
  499. SELECT F2.feature_id, F2.name, F2.uniquename, CVT2.name as feature_type, O.genus, O.species
  500. FROM feature F
  501. INNER JOIN feature_relationship FR ON FR.object_id = F.feature_id
  502. INNER JOIN cvterm CVT ON CVT.cvterm_id = FR.type_id
  503. INNER JOIN feature F2 ON F2.feature_id = FR.subject_id
  504. INNER JOIN cvterm CVT2 ON CVT2.cvterm_id = F2.type_id
  505. INNER JOIN organism O ON O.organism_id = F2.organism_id
  506. WHERE
  507. F.feature_id = $1 AND
  508. CVT.name = $2
  509. ';
  510. $status = tripal_core_chado_prepare('feature_by_object', $psql, array('int', 'text'));
  511. if (!$status) {
  512. watchdog('tripal_feature', "init: not able to prepare SQL statement '%name'",
  513. array('%name' => 'feature_by_object'), 'WATCHDOG ERROR');
  514. }
  515. $sql = "EXECUTE feature_by_object (%d,'%s')";
  516. $features = chado_query($sql, $feature_id, $object_rel);
  517. }
  518. $sequences = '';
  519. while ($feature = db_fetch_object($features)) {
  520. // recurse and get the sequences for these in the relationship
  521. if ($subject_rel) {
  522. $defline = "$feature_name -> $subject_rel -> $feature->uniquename $feature->feature_type ($feature->genus $feature->species)";
  523. }
  524. if ($object_rel) {
  525. $defline = "$feature->uniquename $feature->feature_type ($feature->genus $feature->species) -> $object_rel -> $feature_name";
  526. }
  527. $sequences .= tripal_feature_get_formatted_sequence($feature->feature_id, $defline,
  528. $num_bases_per_line, $derive_from_parent, $aggregate, $output_format,
  529. $upstream, $downstream, $sub_features,'','');
  530. }
  531. return $sequences;
  532. }
  533. // prepare statements we'll need to use later
  534. if (!tripal_core_is_sql_prepared('sequence_by_parent')) {
  535. // prepare the queries we're going to use later during the render phase
  536. // This SQL statement uses conditionals in the select clause to handle
  537. // cases cases where the alignment is in the reverse direction and when
  538. // the upstream and downstream extensions go beyond the lenght of the
  539. // parent sequence.
  540. $psql ='
  541. PREPARE sequence_by_parent (int, int, int) AS
  542. SELECT srcname, srcfeature_id, strand, srctypename, typename,
  543. fmin, fmax, upstream, downstream, adjfmin, adjfmax,
  544. substring(residues from (adjfmin + 1) for (upstream + (fmax - fmin) + downstream)) as residues,
  545. genus, species
  546. FROM (
  547. SELECT
  548. OF.name srcname, FL.srcfeature_id, FL.strand,
  549. OCVT.name as srctypename, SCVT.name as typename,
  550. FL.fmin, FL.fmax, OO.genus, OO.species,
  551. CASE
  552. WHEN FL.strand >= 0 THEN
  553. CASE
  554. WHEN FL.fmin - $1 <= 0 THEN 0
  555. ELSE FL.fmin - $1
  556. END
  557. WHEN FL.strand < 0 THEN
  558. CASE
  559. WHEN FL.fmin - $2 <= 0 THEN 0
  560. ELSE FL.fmin - $2
  561. END
  562. END as adjfmin,
  563. CASE
  564. WHEN FL.strand >= 0 THEN
  565. CASE
  566. WHEN FL.fmax + $2 > OF.seqlen THEN OF.seqlen
  567. ELSE FL.fmax + $2
  568. END
  569. WHEN FL.strand < 0 THEN
  570. CASE
  571. WHEN FL.fmax + $1 > OF.seqlen THEN OF.seqlen
  572. ELSE FL.fmax + $1
  573. END
  574. END as adjfmax,
  575. CASE
  576. WHEN FL.strand >= 0 THEN
  577. CASE
  578. WHEN FL.fmin - $1 <= 0 THEN FL.fmin
  579. ELSE $1
  580. END
  581. ELSE
  582. CASE
  583. WHEN FL.fmax + $1 > OF.seqlen THEN OF.seqlen - FL.fmax
  584. ELSE $1
  585. END
  586. END as upstream,
  587. CASE
  588. WHEN FL.strand >= 0 THEN
  589. CASE
  590. WHEN FL.fmax + $2 > OF.seqlen THEN OF.seqlen - FL.fmax
  591. ELSE $2
  592. END
  593. ELSE
  594. CASE
  595. WHEN FL.fmin - $2 <= 0 THEN FL.fmin
  596. ELSE $2
  597. END
  598. END as downstream,
  599. OF.residues
  600. FROM {featureloc} FL
  601. INNER JOIN {feature} SF on FL.feature_id = SF.feature_id
  602. INNER JOIN {cvterm} SCVT on SF.type_id = SCVT.cvterm_id
  603. INNER JOIN {feature} OF on FL.srcfeature_id = OF.feature_id
  604. INNER JOIN {cvterm} OCVT on OF.type_id = OCVT.cvterm_id
  605. INNER JOIN {organism} OO on OF.organism_id = OO.organism_id
  606. WHERE SF.feature_id = $3 and NOT (OF.residues = \'\' or OF.residues IS NULL)) as tbl1
  607. ';
  608. $status = tripal_core_chado_prepare('sequence_by_parent', $psql, array('int', 'int', 'int'));
  609. if (!$status) {
  610. watchdog('tripal_feature',
  611. "init: not able to prepare SQL statement '%name'",
  612. array('%name' => 'sequence_by_parent'), 'WATCHDOG ERROR');
  613. }
  614. // this query is meant to get all of the sub features of any given
  615. // feature (arg #1) and order them as they appear on the reference
  616. // feature (arg #2).
  617. $psql ='PREPARE sub_features (int, int) AS
  618. SELECT SF.feature_id, CVT.name as type_name, SF.type_id
  619. FROM {feature_relationship} FR
  620. INNER JOIN {feature} SF on SF.feature_id = FR.subject_id
  621. INNER JOIN {cvterm} CVT on CVT.cvterm_id = SF.type_id
  622. INNER JOIN {featureloc} FL on FL.feature_id = FR.subject_id
  623. INNER JOIN {feature} PF on PF.feature_id = FL.srcfeature_id
  624. WHERE FR.object_id = $1 and PF.feature_id = $2
  625. ORDER BY FL.fmin ASC';
  626. $status = tripal_core_chado_prepare('sub_features', $psql, array('int', 'int'));
  627. if (!$status) {
  628. watchdog('tripal_views_handler_field_sequence',
  629. "init: not able to prepare SQL statement '%name'",
  630. array('%name' => 'ssub_features'), 'WATCHDOG ERROR');
  631. }
  632. $psql ='PREPARE count_sub_features (int, int) AS
  633. SELECT count(*) as num_children
  634. FROM {feature_relationship} FR
  635. INNER JOIN {feature} SF on SF.feature_id = FR.subject_id
  636. INNER JOIN {cvterm} CVT on CVT.cvterm_id = SF.type_id
  637. INNER JOIN {featureloc} FL on FL.feature_id = FR.subject_id
  638. INNER JOIN {feature} PF on PF.feature_id = FL.srcfeature_id
  639. WHERE FR.object_id = $1 and PF.feature_id = $2';
  640. $status = tripal_core_chado_prepare('count_sub_features', $psql, array('int', 'int'));
  641. if (!$status) {
  642. watchdog('tripal_views_handler_field_sequence',
  643. "init: not able to prepare SQL statement '%name'",
  644. array('%name' => 'count_sub_features'), 'WATCHDOG ERROR');
  645. }
  646. }
  647. // if we need to get the sequence from the parent then do so now.
  648. if ($derive_from_parent) {
  649. // execute the query to get the sequence from the parent
  650. $sql = "EXECUTE sequence_by_parent (%d, %d, %d)";
  651. $parents = chado_query($sql, $upstream, $downstream, $feature_id);
  652. while ($parent = db_fetch_object($parents)) {
  653. $seq = ''; // initialize the sequence for each parent
  654. // if we are to aggregate then we will ignore the feature returned
  655. // by the query above and rebuild it using the sub features
  656. if ($aggregate) {
  657. // now get the sub features that are located on the parent.
  658. $sql = "EXECUTE sub_features (%d, %d)";
  659. $children = chado_query($sql, $feature_id, $parent->srcfeature_id);
  660. $sql = "EXECUTE count_sub_features (%d, %d)";
  661. $num_children = db_fetch_object(chado_query($sql, $feature_id, $parent->srcfeature_id));
  662. // iterate through the sub features and concat their sequences. They
  663. // should already be in order.
  664. $types = array();
  665. $i = 0;
  666. while ($child = db_fetch_object($children)) {
  667. // if the callee has specified that only certain sub features should be
  668. // included then continue if this child is not one of those allowed
  669. // subfeatures
  670. if (count($sub_features) > 0 and !in_array($child->type_name, $sub_features)) {
  671. continue;
  672. }
  673. // keep up with the types
  674. if (!in_array($child->type_name, $types)) {
  675. $types[] = $child->type_name;
  676. }
  677. $sql = "EXECUTE sequence_by_parent (%d, %d, %d)";
  678. // if the first sub feature we need to include the upstream bases. first check if
  679. // the feature is in the foward direction or the reverse.
  680. if ($i == 0 and $parent->strand >= 0) { // forward direction
  681. // -------------------------- ref
  682. // ....----> ---->
  683. // up 1 2
  684. $q = chado_query($sql, $upstream, 0, $child->feature_id);
  685. }
  686. elseif ($i == 0 and $parent->strand < 0) { // reverse direction
  687. // -------------------------- ref
  688. // ....<---- <----
  689. // down 1 2
  690. $q = chado_query($sql, 0, $downstream, $child->feature_id);
  691. }
  692. // Next, if the last sub feature we need to include the downstream bases. first check if
  693. // the feature is in teh forward direction or the reverse
  694. if ($i == $num_children->num_children - 1 and $parent->strand >= 0) { // forward direction
  695. // -------------------------- ref
  696. // ----> ---->....
  697. // 1 2 down
  698. $q = chado_query($sql, 0, $downstream, $child->feature_id);
  699. }
  700. elseif ($i == $num_children->num_children - 1 and $parent->strand < 0) { // reverse direction
  701. // -------------------------- ref
  702. // <---- <----....
  703. // 1 2 up
  704. $q = chado_query($sql, $upstream, 0, $child->feature_id);
  705. }
  706. // for internal sub features we don't want upstream or downstream bases
  707. else {
  708. $sql = "EXECUTE sequence_by_parent (%d, %d, %d)";
  709. $q = chado_query($sql, 0, 0, $child->feature_id);
  710. }
  711. while ($subseq = db_fetch_object($q)) {
  712. // concatenate the sequences of all the sub features
  713. if ($subseq->srcfeature_id == $parent->srcfeature_id) {
  714. $seq .= $subseq->residues;
  715. }
  716. }
  717. $i++;
  718. }
  719. }
  720. // if this isn't an aggregate then use the parent residues
  721. else {
  722. $seq = $parent->residues;
  723. }
  724. // get the reverse compliment if feature is on the reverse strand
  725. $dir = 'forward';
  726. if ($parent->strand < 0) {
  727. $seq = tripal_feature_reverse_complement($seq);
  728. $dir = 'reverse';
  729. }
  730. // now format for display
  731. if ($output_format == 'fasta_html') {
  732. $seq = wordwrap($seq, $num_bases_per_line, "<br>", TRUE);
  733. }
  734. elseif ($output_format == 'fasta_txt') {
  735. $seq = wordwrap($seq, $num_bases_per_line, "\r\n", TRUE);
  736. }
  737. $residues .= ">$feature_name. Sequence derived from $parent->srctypename of $parent->genus $parent->species: $parent->srcname:" . ($parent->adjfmin + 1) . ".." . $parent->adjfmax ." ($dir). ";
  738. if (count($types) > 0) {
  739. $residues .= "Excludes all bases but those of type(s): " . implode(', ', $types) . ". " ;
  740. }
  741. if ($parent->upstream > 0) {
  742. $residues .= "Includes " . $parent->upstream . " bases upstream. ";
  743. }
  744. if ($parent->downstream > 0) {
  745. $residues .= "Includes " . $parent->downstream . " bases downstream. ";
  746. }
  747. if (!$seq) {
  748. if ($output_format == 'fasta_html') {
  749. $residues .= "No sequence available.</br>";
  750. }
  751. else {
  752. $residues .= "No sequence available.\r\n";
  753. }
  754. }
  755. else {
  756. if ($output_format == 'fasta_html') {
  757. $residues .= "<br>";
  758. }
  759. $residues .= "\r\n" . $seq . "\r\n";
  760. if ($output_format == 'fasta_html') {
  761. $residues .= "<br>";
  762. }
  763. }
  764. }
  765. }
  766. // if we are not getting the sequence from the parent sequence then
  767. // use what comes through from the feature record
  768. else {
  769. $sql = "SELECT * FROM {feature} F WHERE feature_id = %d";
  770. $values = db_fetch_object(chado_query($sql, $feature_id));
  771. $residues = $values->residues;
  772. if ($output_format == 'fasta_html') {
  773. $residues = wordwrap($residues, $num_bases_per_line, "<br>", TRUE);
  774. }
  775. elseif ($output_format == 'fasta_txt') {
  776. $residues = wordwrap($residues, $num_bases_per_line, "\r\n", TRUE);
  777. }
  778. $residues = ">$feature_name\r\n$residues\r\n";
  779. }
  780. // format the residues for display
  781. if ($residues and $num_bases_per_line) {
  782. if ($output_format == 'fasta_html') {
  783. $residues = '<span style="font-family: monospace;">' . $residues . '</span>';
  784. }
  785. }
  786. return $residues;
  787. }
  788. /**
  789. * This function defines the custom tables that will be created
  790. * in the chado schema.
  791. *
  792. * @ingroup tripal_feature
  793. */
  794. function tripal_feature_get_custom_tables($table = NULL) {
  795. if (!$table or strcmp($table, 'tripal_gff_temp')==0) {
  796. $schema['tripal_gff_temp'] = array(
  797. 'table' => 'tripal_gff_temp',
  798. 'fields' => array(
  799. 'feature_id' => array(
  800. 'type' => 'int',
  801. 'not null' => TRUE,
  802. ),
  803. 'organism_id' => array(
  804. 'type' => 'int',
  805. 'not null' => TRUE,
  806. ),
  807. 'uniquename' => array(
  808. 'type' => 'text',
  809. 'not null' => TRUE,
  810. ),
  811. 'type_name' => array(
  812. 'type' => 'varchar',
  813. 'length' => '1024',
  814. 'not null' => TRUE,
  815. ),
  816. ),
  817. 'indexes' => array(
  818. 'tripal_gff_temp_idx0' => array('feature_id'),
  819. 'tripal_gff_temp_idx0' => array('organism_id'),
  820. 'tripal_gff_temp_idx1' => array('uniquename'),
  821. ),
  822. 'unique keys' => array(
  823. 'tripal_gff_temp_uq0' => array('feature_id'),
  824. 'tripal_gff_temp_uq1' => array('uniquename', 'organism_id', 'type_name'),
  825. ),
  826. );
  827. }
  828. return $schema;
  829. }
  830. /**
  831. * Using the tripal_core_expand_chado_vars function to retrieve a set
  832. * of relationships can be very slow, especialy if there are many relationships
  833. * This function is intended to help speed up the retrieval of relationships
  834. * by only retrieving the base information for the relationship and returning
  835. * an array with
  836. *
  837. * @param $feature
  838. * The feature object
  839. * @return
  840. * An array with two objects
  841. *
  842. * @ingroup tripal_feature_api
  843. */
  844. function tripal_feature_get_feature_relationships($feature) {
  845. // expand the feature object to include the feature relationships.
  846. $options = array(
  847. 'return_array' => 1,
  848. 'order_by' => array('rank' => 'ASC'),
  849. );
  850. $feature = tripal_core_expand_chado_vars($feature, 'table',
  851. 'feature_relationship', $options);
  852. // get the subject relationships
  853. $srelationships = $feature->feature_relationship->subject_id;
  854. $orelationships = $feature->feature_relationship->object_id;
  855. // get alignment as child. The $feature->featureloc element
  856. // is already populated from the alignment preprocess function
  857. $feature = tripal_core_expand_chado_vars($feature, 'table', 'featureloc');
  858. $cfeaturelocs = $feature->featureloc->feature_id;
  859. if (!$cfeaturelocs) {
  860. $cfeaturelocs = array();
  861. }
  862. elseif (!is_array($cfeaturelocs)) {
  863. $cfeaturelocs = array($cfeaturelocs);
  864. }
  865. // prepare the SQL statement to get the featureloc for the
  866. // feature in the relationships.
  867. $connection = tripal_db_persistent_chado();
  868. $psql = "
  869. PREPARE sel_featureloc_preprocess_relationships (int, int) AS
  870. SELECT
  871. FL.featureloc_id, F.name as srcfeature_name, FL.srcfeature_id,
  872. FL.feature_id, FL.fmin, FL.fmax, FL.strand, FL.phase
  873. FROM featureloc FL
  874. INNER JOIN feature F ON F.feature_id = FL.srcfeature_id
  875. WHERE FL.feature_id = $1 and FL.srcfeature_id = $2
  876. ";
  877. tripal_core_chado_prepare('sel_featureloc_preprocess_relationships', $psql, array('int', 'int'));
  878. // combine both object and subject relationshisp into a single array
  879. $relationships = array();
  880. $relationships['object'] = array();
  881. $relationships['subject'] = array();
  882. // iterate through the object relationships
  883. if ($orelationships) {
  884. foreach ($orelationships as $relationship) {
  885. $rel = new stdClass();
  886. // get locations where the child feature and this feature overlap with the
  887. // same landmark feature.
  888. $rel->child_featurelocs = array();
  889. foreach ($cfeaturelocs as $featureloc) {
  890. $res = chado_query("EXECUTE sel_featureloc_preprocess_relationships (%d, %d)",
  891. $relationship->subject_id->feature_id,
  892. $featureloc->srcfeature_id->feature_id);
  893. while ($loc = db_fetch_object($res)) {
  894. // add in the node id of the src feature if it exists and save this location
  895. $loc->nid = $featureloc->srcfeature_id->nid;
  896. $rel->child_featurelocs[] = $loc;
  897. }
  898. }
  899. $rel->record = $relationship;
  900. // get the relationship and child types
  901. $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
  902. $child_type = $relationship->subject_id->type_id->name;
  903. // get the node id of the subject
  904. $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
  905. $n = db_fetch_object(db_query($sql, $relationship->subject_id->feature_id));
  906. if ($n) {
  907. $rel->record->nid = $n->nid;
  908. }
  909. if (!array_key_exists($rel_type, $relationships['object'])) {
  910. $relationships['object'][$rel_type] = array();
  911. }
  912. if (!array_key_exists($child_type, $relationships['object'][$rel_type])) {
  913. $relationships['object'][$rel_type][$child_type] = array();
  914. }
  915. $relationships['object'][$rel_type][$child_type][] = $rel;
  916. }
  917. }
  918. // now add in the subject relationships
  919. if ($srelationships) {
  920. foreach ($srelationships as $relationship) {
  921. $rel = new stdClass();
  922. // get locations where this feature overlaps with the parent
  923. $rel->parent_featurelocs = array();
  924. foreach ($cfeaturelocs as $featureloc) {
  925. $res = chado_query("EXECUTE sel_featureloc_preprocess_relationships (%d, %d)",
  926. $relationship->object_id->feature_id,
  927. $featureloc->srcfeature_id->feature_id);
  928. while ($loc = db_fetch_object($res)) {
  929. // add in the node id of the src feature if it exists and save this location
  930. $loc->nid = $featureloc->srcfeature_id->nid;
  931. $rel->parent_featurelocs[] = $loc;
  932. }
  933. }
  934. $rel->record = $relationship;
  935. $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
  936. $parent_type = $relationship->object_id->type_id->name;
  937. // get the node id of the subject
  938. $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
  939. $n = db_fetch_object(db_query($sql, $relationship->object_id->feature_id));
  940. if ($n) {
  941. $rel->record->nid = $n->nid;
  942. }
  943. if (!array_key_exists($rel_type, $relationships['subject'])) {
  944. $relationships['subject'][$rel_type] = array();
  945. }
  946. if (!array_key_exists($child_type, $relationships['subject'][$rel_type])) {
  947. $relationships['subject'][$rel_type][$parent_type] = array();
  948. }
  949. $relationships['subject'][$rel_type][$parent_type][] = $rel;
  950. }
  951. }
  952. return $relationships;
  953. }
  954. /*
  955. * This function adds an entry to the feature_dbxref table.
  956. *
  957. * @param $feature_id
  958. * The numeric feature_if of the feature
  959. * @param $dbname
  960. * The name of the database to which the term belongs
  961. * @param accession
  962. * The accession of the term
  963. *
  964. * @return
  965. * TRUE on success. FALSE on failure.
  966. *
  967. * @ingroup tripal_feature_api
  968. */
  969. function tripal_feature_add_dbxref($feature_id, $dbname, $accession) {
  970. // make sure the db exists. If it doesn't, then add it
  971. $values = array('name' => $dbname);
  972. $options = array('statement_name' => 'sel_db_na');
  973. $db = tripal_core_chado_select('db', array('db_id'), $values, $options);
  974. if (!$db or count($db) == 0) {
  975. $options = array('statement_name' => 'ins_db_na');
  976. $success = tripal_core_chado_insert('db', $values, $options);
  977. if (!$success) {
  978. watchdog('tripal_feature', 'tripal_feature_add_dbxref: The feature dbxref entry for feature, %feature_id, ".
  979. "could not be added because the database, %dbname, does not exist and cannot be added.',
  980. array('%feature_id' => $feature_id, '%dbname' => $dbname), WATCHDOG_WARNING);
  981. return FALSE;
  982. }
  983. }
  984. // first make sure that the record doesn't already exist
  985. $values = array(
  986. 'dbxref_id' => array(
  987. 'accession' => $accession,
  988. 'db_id' => array(
  989. 'name' => $dbname
  990. ),
  991. ),
  992. 'feature_id' => $feature_id,
  993. );
  994. $options = array('statement_name' => 'sel_featuredbxref_dbfe');
  995. $xref = tripal_core_chado_select('feature_dbxref', array('feature_dbxref_id'), $values, $options);
  996. if (count($xref) == 0) {
  997. // if the record doesn't exist then add it.
  998. $options = array('statement_name' => 'ins_featuredbxref_dbfe');
  999. $success = tripal_core_chado_insert('feature_dbxref', $values, $options);
  1000. if (!$success) {
  1001. watchdog('tripal_feature', 'tripal_feature_add_dbxref: The feature dbxref entry for feature, %feature_id, '.
  1002. 'could not be added: %db:%accession.', array('%feature_id' => $feature_id, '%db' => $dbname,
  1003. '%accession' => $accession), WATCHDOG_WARNING);
  1004. return FALSE;
  1005. }
  1006. }
  1007. return TRUE;
  1008. }
  1009. /*
  1010. * This function adds an entry to the feature_cvterm table.
  1011. *
  1012. * @param $feature_id
  1013. * The numeric feature_if of the feature
  1014. * @param $cvname
  1015. * The name of the controlled vocabulary to which the term belongs
  1016. * @param cvterm
  1017. * The name of the cvterm
  1018. *
  1019. * @return
  1020. * TRUE on success. FALSE on failure.
  1021. *
  1022. * @ingroup tripal_feature_api
  1023. */
  1024. function tripal_feature_add_cvterm($feature_id, $cvname, $cvterm) {
  1025. // make sure the cv exists. If it doesn't, then add it
  1026. $values = array('name' => $cvname);
  1027. $options = array('statement_name' => 'sel_cv_na');
  1028. $cv = tripal_core_chado_select('cv', array('cv_id'), $values, $options);
  1029. if (!$cv or count($cv) == 0) {
  1030. $options = array('statement_name' => 'ins_cv_na');
  1031. $success = tripal_core_chado_insert('cv', $values, $options);
  1032. if (!$success) {
  1033. watchdog('tripal_feature', 'tripal_feature_add_cvterm: The feature cvterm entry for feature, %feature_id, ".
  1034. "could not be added because the CV, %cvname, does not exist and cannot be added.',
  1035. array('%feature_id' => $feature_id, '%cvname' => $cvname), WATCHDOG_WARNING);
  1036. return FALSE;
  1037. }
  1038. }
  1039. // first make sure that the record doesn't already exist
  1040. $values = array(
  1041. 'cvterm_id' => array(
  1042. 'name' => $cvterm,
  1043. 'cv_id' => array(
  1044. 'name' => $cvname
  1045. ),
  1046. ),
  1047. 'feature_id' => $feature_id,
  1048. 'pub_id' => 1,
  1049. );
  1050. $options = array('statement_name' => 'sel_featuredcvterm_cvfepu');
  1051. $xref = tripal_core_chado_select('feature_cvterm', array('feature_cvterm_id'), $values, $options);
  1052. if (count($xref) == 0) {
  1053. // if the record doesn't exist then add it.
  1054. $options = array('statement_name' => 'ins_featurecvterm_cvfepu');
  1055. $success = tripal_core_chado_insert('feature_cvterm', $values, $options);
  1056. if (!$success) {
  1057. watchdog('tripal_feature', 'tripal_feature_add_cvterm: The feature cvterm entry for feature, %feature_id, '.
  1058. 'could not be added: %cvterm.', array('%feature_id' => $feature_id, '%cvterm' => $cvterm), WATCHDOG_WARNING);
  1059. return FALSE;
  1060. }
  1061. }
  1062. return TRUE;
  1063. }