GFF3ImporterTest.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. <?php
  2. namespace Tests;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. class GFF3ImporterTest extends TripalTestCase {
  6. use DBTransaction;
  7. /**
  8. * Confirm basic GFF importer functionality.
  9. *
  10. * @group gff
  11. */
  12. public function testGFFImporter() {
  13. $gff_file = ['file_local' => __DIR__ . '/../data/small_gene.gff'];
  14. $fasta = ['file_local' => __DIR__ . '/../data/short_scaffold.fasta'];
  15. $analysis = factory('chado.analysis')->create();
  16. $organism = factory('chado.organism')->create();
  17. $run_args = [
  18. 'analysis_id' => $analysis->analysis_id,
  19. 'organism_id' => $organism->organism_id,
  20. 'use_transaction' => 1,
  21. 'add_only' => 0,
  22. 'update' => 1,
  23. 'create_organism' => 0,
  24. 'create_target' => 0,
  25. // regexps for mRNA and protein.
  26. 're_mrna' => NULL,
  27. 're_protein' => NULL,
  28. // optional
  29. 'target_organism_id' => NULL,
  30. 'target_type' => NULL,
  31. 'start_line' => NULL,
  32. 'landmark_type' => NULL,
  33. 'alt_id_attr' => NULL,
  34. ];
  35. $this->loadLandmarks($analysis, $organism, $fasta);
  36. $this->runGFFLoader($run_args, $gff_file);
  37. // This protein is an explicit protein / polypeptide imported from the GFF
  38. // file.
  39. $name = 'test_protein_001.1';
  40. $query = db_select('chado.feature', 'f')
  41. ->fields('f', ['uniquename'])
  42. ->condition('f.uniquename', $name)
  43. ->execute()
  44. ->fetchField();
  45. $this->assertEquals($name, $query);
  46. }
  47. /**
  48. * Run the GFF loader on gff_tag_unescaped_character.gff for testing.
  49. *
  50. * This tests whether the GFF loader adds IDs that contain a comma.
  51. * The GFF loader should allow it
  52. */
  53. public function testGFFImporterUnescapedTagWithComma() {
  54. $gff_file = ['file_local' => __DIR__ . '/../data/gff_tag_unescaped_character.gff'];
  55. $analysis = factory('chado.analysis')->create();
  56. $organism = factory('chado.organism')->create();
  57. $run_args = [
  58. 'analysis_id' => $analysis->analysis_id,
  59. 'organism_id' => $organism->organism_id,
  60. 'use_transaction' => 1,
  61. 'add_only' => 0,
  62. 'update' => 1,
  63. 'create_organism' => 0,
  64. 'create_target' => 0,
  65. // regexps for mRNA and protein.
  66. 're_mrna' => NULL,
  67. 're_protein' => NULL,
  68. // optional
  69. 'target_organism_id' => NULL,
  70. 'target_type' => NULL,
  71. 'start_line' => NULL,
  72. 'landmark_type' => NULL,
  73. 'alt_id_attr' => NULL,
  74. ];
  75. $this->loadLandmarks($analysis, $organism);
  76. // This should throw an error based on the tag name having the comma
  77. $hasException = false;
  78. try {
  79. $this->runGFFLoader($run_args, $gff_file);
  80. }
  81. catch (\Exception $ex) {
  82. $hasException = true;
  83. }
  84. $this->assertEquals($hasException, true);
  85. }
  86. /**
  87. * Run the GFF loader on gff_tag_parent_verification.gff for testing.
  88. *
  89. * This tests whether the GFF loader adds Parent attributes
  90. * The GFF loader should allow it
  91. */
  92. public function testGFFImporterTagParentVerification() {
  93. $gff_file = ['file_local' =>
  94. __DIR__ . '/../data/gff_tag_parent_verification.gff'];
  95. $analysis = factory('chado.analysis')->create();
  96. $organism = factory('chado.organism')->create();
  97. $run_args = [
  98. 'analysis_id' => $analysis->analysis_id,
  99. 'organism_id' => $organism->organism_id,
  100. 'use_transaction' => 1,
  101. 'add_only' => 0,
  102. 'update' => 1,
  103. 'create_organism' => 0,
  104. 'create_target' => 0,
  105. // regexps for mRNA and protein.
  106. 're_mrna' => NULL,
  107. 're_protein' => NULL,
  108. // optional
  109. 'target_organism_id' => NULL,
  110. 'target_type' => NULL,
  111. 'start_line' => NULL,
  112. 'landmark_type' => NULL,
  113. 'alt_id_attr' => NULL,
  114. ];
  115. $this->loadLandmarks($analysis, $organism);
  116. $this->runGFFLoader($run_args, $gff_file);
  117. $results = db_query("SELECT * FROM chado.feature_relationship fr
  118. LEFT JOIN chado.feature f ON (fr.object_id = f.feature_id)
  119. WHERE f.uniquename = 'FRAEX38873_v2_000000010'
  120. ;",array());
  121. // Found parent via object_id FRAEX38873_v2_000000010
  122. $this->assertEquals($results->rowCount(), 1);
  123. }
  124. /**
  125. * Run the GFF loader on gff_tagvalue_unescaped_character.gff for testing.
  126. *
  127. * This tests whether the GFF loader adds IDs that contain a comma.
  128. * The GFF loader should allow it
  129. */
  130. public function testGFFImporterEscapedTagValueWithEncodedCharacter() {
  131. $gff_file = ['file_local' =>
  132. __DIR__ . '/../data/gff_tagvalue_encoded_character.gff'];
  133. $analysis = factory('chado.analysis')->create();
  134. $organism = factory('chado.organism')->create();
  135. $run_args = [
  136. 'analysis_id' => $analysis->analysis_id,
  137. 'organism_id' => $organism->organism_id,
  138. 'use_transaction' => 1,
  139. 'add_only' => 0,
  140. 'update' => 1,
  141. 'create_organism' => 0,
  142. 'create_target' => 0,
  143. // regexps for mRNA and protein.
  144. 're_mrna' => NULL,
  145. 're_protein' => NULL,
  146. // optional
  147. 'target_organism_id' => NULL,
  148. 'target_type' => NULL,
  149. 'start_line' => NULL,
  150. 'landmark_type' => NULL,
  151. 'alt_id_attr' => NULL,
  152. ];
  153. $this->loadLandmarks($analysis, $organism);
  154. $this->runGFFLoader($run_args, $gff_file);
  155. $results = db_query("SELECT * FROM chado.feature
  156. WHERE uniquename = 'FRAEX38873_v2_000000010,20';",array());
  157. $this->assertEquals($results->rowCount(), 1);
  158. }
  159. /**
  160. * Run the GFF loader on gff_tagvalue_unescaped_character.gff for testing.
  161. *
  162. * This tests whether the GFF loader adds IDs that contain a comma.
  163. * The GFF loader should allow it
  164. */
  165. public function testGFFImporterUnescapedTagValueWithComma() {
  166. $gff_file = ['file_local' => __DIR__ . '/../data/gff_tagvalue_unescaped_character.gff'];
  167. $analysis = factory('chado.analysis')->create();
  168. $organism = factory('chado.organism')->create();
  169. $run_args = [
  170. 'analysis_id' => $analysis->analysis_id,
  171. 'organism_id' => $organism->organism_id,
  172. 'use_transaction' => 1,
  173. 'add_only' => 0,
  174. 'update' => 1,
  175. 'create_organism' => 0,
  176. 'create_target' => 0,
  177. // regexps for mRNA and protein.
  178. 're_mrna' => NULL,
  179. 're_protein' => NULL,
  180. // optional
  181. 'target_organism_id' => NULL,
  182. 'target_type' => NULL,
  183. 'start_line' => NULL,
  184. 'landmark_type' => NULL,
  185. 'alt_id_attr' => NULL,
  186. ];
  187. $this->loadLandmarks($analysis, $organism);
  188. // This should throw an error based on the tag name having the comma
  189. $hasException = false;
  190. try {
  191. $this->runGFFLoader($run_args, $gff_file);
  192. }
  193. catch (\Exception $ex) {
  194. $hasException = true;
  195. }
  196. $this->assertEquals($hasException, true);
  197. }
  198. /**
  199. * Run the GFF loader on gff_seqid_invalid_character.gff for testing.
  200. * Seqids seem to also be called landmarks within GFF loader.
  201. * This tests whether the GFF loader has any issues with characters like
  202. * single quotes.
  203. */
  204. public function testGFFImporterSeqidWithInvalidCharacter() {
  205. $gff_file = ['file_local' =>
  206. __DIR__ . '/../data/gff_seqid_invalid_character.gff'];
  207. $analysis = factory('chado.analysis')->create();
  208. $organism = factory('chado.organism')->create();
  209. $run_args = [
  210. 'analysis_id' => $analysis->analysis_id,
  211. 'organism_id' => $organism->organism_id,
  212. 'use_transaction' => 1,
  213. 'add_only' => 0,
  214. 'update' => 1,
  215. 'create_organism' => 0,
  216. 'create_target' => 0,
  217. // regexps for mRNA and protein.
  218. 're_mrna' => NULL,
  219. 're_protein' => NULL,
  220. // optional
  221. 'target_organism_id' => NULL,
  222. 'target_type' => NULL,
  223. 'start_line' => NULL,
  224. 'landmark_type' => NULL,
  225. 'alt_id_attr' => NULL,
  226. ];
  227. $this->loadLandmarks($analysis, $organism);
  228. // This will produce an exception due to quote character in Seqid
  229. $hasException = false;
  230. try {
  231. $this->runGFFLoader($run_args, $gff_file);
  232. }
  233. catch (\Exception $ex) {
  234. $hasException = true;
  235. }
  236. $this->assertEquals($hasException, true);
  237. }
  238. /**
  239. * Run the GFF loader on gff_unescaped_ids.gff for testing.
  240. *
  241. * This tests whether the GFF loader adds IDs that contain whitespaces.
  242. * The GFF loader should allow it
  243. */
  244. public function testGFFImporterUnescapedWhitespaceID() {
  245. $gff_file = ['file_local' => __DIR__ . '/../data/gff_unescaped_ids.gff'];
  246. $analysis = factory('chado.analysis')->create();
  247. $organism = factory('chado.organism')->create();
  248. $run_args = [
  249. 'analysis_id' => $analysis->analysis_id,
  250. 'organism_id' => $organism->organism_id,
  251. 'use_transaction' => 1,
  252. 'add_only' => 0,
  253. 'update' => 1,
  254. 'create_organism' => 0,
  255. 'create_target' => 0,
  256. // regexps for mRNA and protein.
  257. 're_mrna' => NULL,
  258. 're_protein' => NULL,
  259. // optional
  260. 'target_organism_id' => NULL,
  261. 'target_type' => NULL,
  262. 'start_line' => NULL,
  263. 'landmark_type' => NULL,
  264. 'alt_id_attr' => NULL,
  265. ];
  266. $this->loadLandmarks($analysis, $organism);
  267. // This should go through just fine
  268. $this->runGFFLoader($run_args, $gff_file);
  269. $results = db_query("SELECT * FROM chado.feature WHERE uniquename =
  270. 'FRAEX38873_v2_000000010 SPACED';");
  271. $this->assertEquals($results->rowCount(), 1);
  272. }
  273. /**
  274. * Run the GFF loader on gff_rightarrow_ids.gff for testing.
  275. *
  276. * This tests whether the GFF loader fails if ID contains
  277. * arrow >. It should not fail.
  278. */
  279. public function testGFFImporterRightArrowID() {
  280. $gff_file = ['file_local' => __DIR__ . '/../data/gff_rightarrow_id.gff'];
  281. $analysis = factory('chado.analysis')->create();
  282. $organism = factory('chado.organism')->create();
  283. $run_args = [
  284. 'analysis_id' => $analysis->analysis_id,
  285. 'organism_id' => $organism->organism_id,
  286. 'use_transaction' => 1,
  287. 'add_only' => 0,
  288. 'update' => 1,
  289. 'create_organism' => 0,
  290. 'create_target' => 0,
  291. // regexps for mRNA and protein.
  292. 're_mrna' => NULL,
  293. 're_protein' => NULL,
  294. // optional
  295. 'target_organism_id' => NULL,
  296. 'target_type' => NULL,
  297. 'start_line' => NULL,
  298. 'landmark_type' => NULL,
  299. 'alt_id_attr' => NULL,
  300. ];
  301. $this->loadLandmarks($analysis, $organism);
  302. // This will produce an exception due to right arrow in ID
  303. $this->runGFFLoader($run_args, $gff_file);
  304. $results = db_query("SELECT * FROM chado.feature
  305. WHERE uniquename = '>FRAEX38873_v2_000000010';");
  306. // We expect this record to get inserted.
  307. $this->assertEquals($results->rowCount(), 1);
  308. }
  309. /**
  310. * Run the GFF loader on gff_duplicate_ids.gff for testing.
  311. *
  312. * This tests whether the GFF loader detects duplicate IDs which makes a
  313. * GFF file invalid since IDs should be unique. The GFF loader should throw
  314. * and exception which this test checks for
  315. */
  316. public function testGFFImporterDuplicateIDsExceptionCheck() {
  317. $gff_file = ['file_local' => __DIR__ . '/../data/gff_duplicate_ids.gff'];
  318. $analysis = factory('chado.analysis')->create();
  319. $organism = factory('chado.organism')->create();
  320. $run_args = [
  321. 'analysis_id' => $analysis->analysis_id,
  322. 'organism_id' => $organism->organism_id,
  323. 'use_transaction' => 1,
  324. 'add_only' => 0,
  325. 'update' => 1,
  326. 'create_organism' => 0,
  327. 'create_target' => 0,
  328. // regexps for mRNA and protein.
  329. 're_mrna' => NULL,
  330. 're_protein' => NULL,
  331. // optional
  332. 'target_organism_id' => NULL,
  333. 'target_type' => NULL,
  334. 'start_line' => NULL,
  335. 'landmark_type' => NULL,
  336. 'alt_id_attr' => NULL,
  337. ];
  338. $hasException = false;
  339. try {
  340. $this->loadLandmarks($analysis, $organism);
  341. // This will produce an exception of duplicate feature ID
  342. $this->runGFFLoader($run_args, $gff_file);
  343. }
  344. catch(\Exception $ex) {
  345. $hasException = true;
  346. }
  347. // We expect an exception to happen so we are looking for a return of true
  348. $this->assertEquals($hasException, true);
  349. }
  350. /**
  351. * Run the GFF loader on gff_invalidstartend.gff for testing.
  352. *
  353. * This tests whether the GFF loader fixes start end values
  354. */
  355. public function testGFFImporterInvalidStartEnd() {
  356. $gff_file = ['file_local' => __DIR__ . '/../data/gff_invalidstartend.gff'];
  357. $analysis = factory('chado.analysis')->create();
  358. $organism = factory('chado.organism')->create();
  359. $run_args = [
  360. 'analysis_id' => $analysis->analysis_id,
  361. 'organism_id' => $organism->organism_id,
  362. 'use_transaction' => 1,
  363. 'add_only' => 0,
  364. 'update' => 1,
  365. 'create_organism' => 0,
  366. 'create_target' => 0,
  367. // regexps for mRNA and protein.
  368. 're_mrna' => NULL,
  369. 're_protein' => NULL,
  370. // optional
  371. 'target_organism_id' => NULL,
  372. 'target_type' => NULL,
  373. 'start_line' => NULL,
  374. 'landmark_type' => NULL,
  375. 'alt_id_attr' => NULL,
  376. ];
  377. $this->loadLandmarks($analysis, $organism);
  378. // This will produce an exception of duplicate feature ID
  379. $this->runGFFLoader($run_args, $gff_file);
  380. $results = db_select('chado.feature', 'f')
  381. ->fields('f', ['uniquename'])
  382. ->condition('f.uniquename', 'FRAEX38873_v2_000000010')
  383. ->execute()
  384. ->fetchAll();
  385. // We expect the feature to still be added to the database
  386. // since the GFF Loader caters for reversing backward numbers
  387. $this->assertEquals(count($results), 1);
  388. }
  389. /**
  390. * Run the GFF loader on gff_score.gff for testing.
  391. *
  392. * This tests whether the GFF loader interprets the score values
  393. */
  394. public function testGFFImporterScoreTest() {
  395. $gff_file = ['file_local' => __DIR__ . '/../data/gff_score.gff'];
  396. $analysis = factory('chado.analysis')->create();
  397. $organism = factory('chado.organism')->create();
  398. $run_args = [
  399. 'analysis_id' => $analysis->analysis_id,
  400. 'organism_id' => $organism->organism_id,
  401. 'use_transaction' => 1,
  402. 'add_only' => 0,
  403. 'update' => 1,
  404. 'create_organism' => 0,
  405. 'create_target' => 0,
  406. // regexps for mRNA and protein.
  407. 're_mrna' => NULL,
  408. 're_protein' => NULL,
  409. // optional
  410. 'target_organism_id' => NULL,
  411. 'target_type' => NULL,
  412. 'start_line' => NULL,
  413. 'landmark_type' => NULL,
  414. 'alt_id_attr' => NULL,
  415. ];
  416. $this->loadLandmarks($analysis, $organism);
  417. $this->runGFFLoader($run_args, $gff_file);
  418. // Test that integer values get placed in the db
  419. $results = db_query('SELECT * FROM chado.analysisfeature WHERE significance = 2 LIMIT 1', array(
  420. ));
  421. foreach ($results as $row){
  422. $this->assertEquals($row->significance,2);
  423. }
  424. // Test that decimal/float values get placed in the db
  425. $results = db_query('SELECT * FROM chado.analysisfeature WHERE significance = 2.5 LIMIT 1', array(
  426. ));
  427. foreach ($results as $row){
  428. $this->assertEquals($row->significance,2.5);
  429. }
  430. // Test that negative score values get placed in the db
  431. $results = db_query('SELECT * FROM chado.analysisfeature WHERE significance = -2.5 LIMIT 1', array(
  432. ));
  433. foreach ($results as $row){
  434. $this->assertEquals($row->significance,-2.5);
  435. }
  436. }
  437. /**
  438. * Run the GFF loader on gff_strand.gff for testing.
  439. *
  440. * This tests whether the GFF loader interprets the strand values
  441. */
  442. public function testGFFImporterInvalidStrandTest() {
  443. $gff_file = ['file_local' => __DIR__ . '/../data/gff_strand_invalid.gff'];
  444. $analysis = factory('chado.analysis')->create();
  445. $organism = factory('chado.organism')->create();
  446. $run_args = [
  447. 'analysis_id' => $analysis->analysis_id,
  448. 'organism_id' => $organism->organism_id,
  449. 'use_transaction' => 1,
  450. 'add_only' => 0,
  451. 'update' => 1,
  452. 'create_organism' => 0,
  453. 'create_target' => 0,
  454. // regexps for mRNA and protein.
  455. 're_mrna' => NULL,
  456. 're_protein' => NULL,
  457. // optional
  458. 'target_organism_id' => NULL,
  459. 'target_type' => NULL,
  460. 'start_line' => NULL,
  461. 'landmark_type' => NULL,
  462. 'alt_id_attr' => NULL,
  463. ];
  464. $this->loadLandmarks($analysis, $organism);
  465. $isException = false;
  466. try {
  467. $this->runGFFLoader($run_args, $gff_file);
  468. }
  469. catch(\Exception $ex) {
  470. $isException = true;
  471. }
  472. $this->assertEquals($isException, true);
  473. }
  474. /**
  475. * Run the GFF loader on gff_strand.gff for testing.
  476. *
  477. * This tests whether the GFF loader interprets the strand values
  478. */
  479. public function testGFFImporterStrandTest() {
  480. $gff_file = ['file_local' => __DIR__ . '/../data/gff_strand.gff'];
  481. $analysis = factory('chado.analysis')->create();
  482. $organism = factory('chado.organism')->create();
  483. $run_args = [
  484. 'analysis_id' => $analysis->analysis_id,
  485. 'organism_id' => $organism->organism_id,
  486. 'use_transaction' => 1,
  487. 'add_only' => 0,
  488. 'update' => 1,
  489. 'create_organism' => 0,
  490. 'create_target' => 0,
  491. // regexps for mRNA and protein.
  492. 're_mrna' => NULL,
  493. 're_protein' => NULL,
  494. // optional
  495. 'target_organism_id' => NULL,
  496. 'target_type' => NULL,
  497. 'start_line' => NULL,
  498. 'landmark_type' => NULL,
  499. 'alt_id_attr' => NULL,
  500. ];
  501. $this->loadLandmarks($analysis, $organism);
  502. $this->runGFFLoader($run_args, $gff_file);
  503. // Test that integer values for strand that get placed in the db
  504. // Strand data gets saved in chado.featureloc
  505. $results = db_query('SELECT * FROM chado.featureloc fl
  506. LEFT JOIN chado.feature f ON (fl.feature_id = f.feature_id)
  507. WHERE uniquename = :uniquename LIMIT 1',
  508. array(
  509. ':uniquename' => 'FRAEX38873_v2_000000010'
  510. )
  511. );
  512. foreach ($results as $row) {
  513. $this->assertEquals($row->strand, 1); // +
  514. }
  515. $results = db_query('SELECT * FROM chado.featureloc fl
  516. LEFT JOIN chado.feature f ON (fl.feature_id = f.feature_id)
  517. WHERE uniquename = :uniquename LIMIT 1',
  518. array(
  519. ':uniquename' => 'FRAEX38873_v2_000000010.1'
  520. )
  521. );
  522. foreach ($results as $row) {
  523. $this->assertEquals($row->strand,-1); // -
  524. }
  525. $results = db_query('SELECT * FROM chado.featureloc fl
  526. LEFT JOIN chado.feature f ON (fl.feature_id = f.feature_id)
  527. WHERE uniquename = :uniquename LIMIT 1',
  528. array(
  529. ':uniquename' => 'FRAEX38873_v2_000000010.2'
  530. )
  531. );
  532. foreach ($results as $row) {
  533. $this->assertEquals($row->strand, 0); // ?
  534. }
  535. $results = db_query('SELECT * FROM chado.featureloc fl
  536. LEFT JOIN chado.feature f ON (fl.feature_id = f.feature_id)
  537. WHERE uniquename = :uniquename LIMIT 1',
  538. array(
  539. ':uniquename' => 'FRAEX38873_v2_000000010.3'
  540. )
  541. );
  542. foreach ($results as $row) {
  543. $this->assertEquals($row->strand, 0); // .
  544. }
  545. // This GFF should create 5 featureloc records
  546. $results = db_query('SELECT COUNT(*) as c FROM chado.featureloc;');
  547. foreach ($results as $row) {
  548. $this->assertEquals($row->c, 5);
  549. }
  550. }
  551. /**
  552. * Run the GFF loader on gff_phase.gff for testing.
  553. *
  554. * This tests whether the GFF loader interprets the phase values correctly
  555. * for CDS rows.
  556. */
  557. public function testGFFImporterPhaseTest() {
  558. $gff_file = ['file_local' => __DIR__ . '/../data/gff_phase.gff'];
  559. $analysis = factory('chado.analysis')->create();
  560. $organism = factory('chado.organism')->create();
  561. $run_args = [
  562. 'analysis_id' => $analysis->analysis_id,
  563. 'organism_id' => $organism->organism_id,
  564. 'use_transaction' => 1,
  565. 'add_only' => 0,
  566. 'update' => 1,
  567. 'create_organism' => 0,
  568. 'create_target' => 0,
  569. // regexps for mRNA and protein.
  570. 're_mrna' => NULL,
  571. 're_protein' => NULL,
  572. // optional
  573. 'target_organism_id' => NULL,
  574. 'target_type' => NULL,
  575. 'start_line' => NULL,
  576. 'landmark_type' => NULL,
  577. 'alt_id_attr' => NULL,
  578. ];
  579. $this->loadLandmarks($analysis, $organism);
  580. $this->runGFFLoader($run_args, $gff_file);
  581. $results = db_query("SELECT * FROM chado.feature
  582. WHERE uniquename = :uniquename LIMIT 1", array(
  583. ':uniquename' => 'FRAEX38873_v2_000000010.1.cds1'
  584. )
  585. );
  586. // Check to make sure it returns a single row (implying a match)
  587. // by the uniquename specified
  588. $this->assertEquals($results->rowCount(), 1);
  589. $results = db_query("SELECT * FROM chado.featureloc
  590. WHERE phase = 1 LIMIT 1", array(
  591. )
  592. );
  593. // Check to make sure it returns a single row (implying a match)
  594. // by phase value 1
  595. $this->assertEquals($results->rowCount(), 1);
  596. }
  597. /**
  598. * Run the GFF loader on gff_phase_invalid_number.gff for testing.
  599. *
  600. * This tests whether the GFF loader interprets the phase values correctly
  601. * for CDS rows when a number outside of the range 0,1,2 is specified.
  602. */
  603. public function testGFFImporterInvalidPhaseNumberTest() {
  604. $gff_file = ['file_local' => __DIR__ . '/../data/gff_phase_invalid_number.gff'];
  605. $analysis = factory('chado.analysis')->create();
  606. $organism = factory('chado.organism')->create();
  607. $run_args = [
  608. 'analysis_id' => $analysis->analysis_id,
  609. 'organism_id' => $organism->organism_id,
  610. 'use_transaction' => 1,
  611. 'add_only' => 0,
  612. 'update' => 1,
  613. 'create_organism' => 0,
  614. 'create_target' => 0,
  615. // regexps for mRNA and protein.
  616. 're_mrna' => NULL,
  617. 're_protein' => NULL,
  618. // optional
  619. 'target_organism_id' => NULL,
  620. 'target_type' => NULL,
  621. 'start_line' => NULL,
  622. 'landmark_type' => NULL,
  623. 'alt_id_attr' => NULL,
  624. ];
  625. $this->loadLandmarks($analysis, $organism);
  626. $hasException = false;
  627. try {
  628. $this->runGFFLoader($run_args, $gff_file);
  629. }
  630. catch (\Exception $ex) {
  631. $hasException = true;
  632. }
  633. // An exception should have been thrown since the phase number is invalid
  634. $this->assertEquals($hasException, true);
  635. }
  636. /**
  637. * Run the GFF loader on gff_phase_invalid_character.gff for testing.
  638. *
  639. * This tests whether the GFF loader interprets the phase values correctly
  640. * for CDS rows when a character outside of the range 0,1,2 is specified.
  641. */
  642. public function testGFFImporterInvalidPhaseCharacterTest() {
  643. $gff_file = ['file_local' => __DIR__ . '/../data/gff_phase_invalid_character.gff'];
  644. $analysis = factory('chado.analysis')->create();
  645. $organism = factory('chado.organism')->create();
  646. $run_args = [
  647. 'analysis_id' => $analysis->analysis_id,
  648. 'organism_id' => $organism->organism_id,
  649. 'use_transaction' => 1,
  650. 'add_only' => 0,
  651. 'update' => 1,
  652. 'create_organism' => 0,
  653. 'create_target' => 0,
  654. // regexps for mRNA and protein.
  655. 're_mrna' => NULL,
  656. 're_protein' => NULL,
  657. // optional
  658. 'target_organism_id' => NULL,
  659. 'target_type' => NULL,
  660. 'start_line' => NULL,
  661. 'landmark_type' => NULL,
  662. 'alt_id_attr' => NULL,
  663. ];
  664. $this->loadLandmarks($analysis, $organism);
  665. $hasException = false;
  666. try {
  667. $this->runGFFLoader($run_args, $gff_file);
  668. }
  669. catch (\Exception $ex) {
  670. $hasException = true;
  671. }
  672. // An exception should have been thrown since the phase number is invalid
  673. $this->assertEquals($hasException, true);
  674. }
  675. /**
  676. * Run the GFF loader on small_gene.gff for testing.
  677. *
  678. * This gff has many attributes that we would like to test in the
  679. * testGFFImporterAttribute*() methods.
  680. */
  681. private function initGFFImporterAttributes() {
  682. $gff = ['file_local' => __DIR__ . '/../data/small_gene.gff'];
  683. $fasta = ['file_local' => __DIR__ . '/../data/short_scaffold.fasta'];
  684. $analysis = factory('chado.analysis')->create();
  685. $organism = factory('chado.organism')->create();
  686. $run_args = [
  687. 'analysis_id' => $analysis->analysis_id,
  688. 'organism_id' => $organism->organism_id,
  689. 'use_transaction' => 1,
  690. 'add_only' => 0,
  691. 'update' => 1,
  692. 'create_organism' => 0,
  693. 'create_target' => 0,
  694. ///regexps for mRNA and protein.
  695. 're_mrna' => NULL,
  696. 're_protein' => NULL,
  697. //optional
  698. 'target_organism_id' => $organism->organism_id,
  699. 'target_type' => NULL,
  700. 'start_line' => NULL,
  701. 'landmark_type' => NULL,
  702. 'alt_id_attr' => NULL,
  703. ];
  704. $this->loadLandmarks($analysis, $organism, $fasta);
  705. $this->runGFFLoader($run_args, $gff);
  706. $this->organism = $organism;
  707. $this->analysis = $analysis;
  708. $this->gene_cvt = chado_get_cvterm(array(
  709. 'name' => 'gene',
  710. 'cv_id' => array(
  711. 'name' => 'sequence',
  712. ),
  713. ))->cvterm_id;
  714. $this->mrna_cvt = chado_get_cvterm(array(
  715. 'name' => 'mRNA',
  716. 'cv_id' => array(
  717. 'name' => 'sequence',
  718. ),
  719. ))->cvterm_id;
  720. $this->supercontig_cvt = chado_get_cvterm(array(
  721. 'name' => 'supercontig',
  722. 'cv_id' => array(
  723. 'name' => 'sequence',
  724. ),
  725. ))->cvterm_id;
  726. $this->gene_1_uname = 'test_gene_001';
  727. $this->gene_2_uname = 'test_gene_002';
  728. $this->scaffold_1_uname = 'scaffold1';
  729. }
  730. /**
  731. * Ensures that the feature record is loaded correctly into chado.
  732. *
  733. * @group gff
  734. */
  735. public function testGFFImporterAttributeFeature() {
  736. $this->initGFFImporterAttributes();
  737. $organism = $this->organism;
  738. $query = db_select('chado.feature', 'f')
  739. ->fields('f')
  740. ->condition('uniquename', $this->gene_1_uname)
  741. ->condition('type_id', $this->gene_cvt)
  742. ->execute();
  743. $gene_1 = $query->fetchObject();
  744. $this->assertEquals('test_gene_001', $gene_1->uniquename);
  745. $this->assertEquals('test_gene_001', $gene_1->name);
  746. $this->assertEquals($organism->organism_id, $gene_1->organism_id);
  747. $this->assertEquals($this->gene_cvt, $gene_1->type_id);
  748. }
  749. /**
  750. * Ensures the feature alias is loaded correctly into chado.
  751. *
  752. * @group gff
  753. */
  754. public function testGFFImporterAttributeAlias() {
  755. $this->initGFFImporterAttributes();
  756. $alias = 'first_test_gene';
  757. $gene_1 = db_select('chado.feature', 'f')
  758. ->fields('f')
  759. ->condition('uniquename', $this->gene_1_uname)
  760. ->condition('type_id', $this->gene_cvt)
  761. ->execute()->fetchObject();
  762. $query = db_select('chado.feature_synonym', 'fs');
  763. $query->join('chado.synonym', 's', 's.synonym_id = fs.synonym_id');
  764. $query->fields('s');
  765. $query->condition('fs.feature_id', $gene_1->feature_id);
  766. $query = $query->execute();
  767. $result = $query->fetchObject();
  768. $this->assertEquals($alias, $result->name);
  769. }
  770. /**
  771. * Ensures that the dbxref records are loaded correctly into chado.
  772. *
  773. * @group gff
  774. */
  775. public function testGFFImporterAttributeDbxref() {
  776. $this->initGFFImporterAttributes();
  777. $test_db_name = 'TEST_DB';
  778. $dbx_accession = 'test_gene_dbx_001';
  779. $test_db = chado_get_db(array('name' => $test_db_name));
  780. $gff_db = chado_get_db(array('name' => 'GFF_source'));
  781. $gene_1 = db_select('chado.feature', 'f')
  782. ->fields('f')
  783. ->condition('uniquename', $this->gene_1_uname)
  784. ->condition('type_id', $this->gene_cvt)
  785. ->execute()->fetchObject();
  786. $dbx_query = db_select('chado.feature_dbxref', 'fdbx');
  787. $dbx_query->join('chado.dbxref', 'dbx', 'dbx.dbxref_id = fdbx.dbxref_id');
  788. $dbx_query->fields('dbx');
  789. $dbx_query->condition('fdbx.feature_id', $gene_1->feature_id);
  790. $gff_query = clone $dbx_query;
  791. $dbx_query->condition('dbx.db_id', $test_db->db_id);
  792. $dbx_query = $dbx_query->execute();
  793. $gff_query->condition('dbx.db_id', $gff_db->db_id);
  794. $gff_query = $gff_query->execute();
  795. $dbxref = $dbx_query->fetchObject();
  796. $gff_dbxref = $gff_query->fetchObject();
  797. $this->assertEquals($dbx_accession, $dbxref->accession);
  798. $this->assertEquals($this->gene_1_uname, $gff_dbxref->accession);
  799. }
  800. /**
  801. * Ensures ontology term records loaded correctly into chado.
  802. *
  803. * @group gff
  804. */
  805. public function testGFFImporterAttributeOntology() {
  806. $this->initGFFImporterAttributes();
  807. $ontology_db = 'SO';
  808. $ontology_accession = '0000704';
  809. $gene_1 = db_select('chado.feature', 'f')
  810. ->fields('f')
  811. ->condition('uniquename', $this->gene_1_uname)
  812. ->condition('type_id', $this->gene_cvt)
  813. ->execute()->fetchObject();
  814. $term = chado_get_cvterm(array(
  815. 'dbxref_id' => array(
  816. 'accession' => $ontology_accession,
  817. 'db_id' => array(
  818. 'name' => $ontology_db,
  819. ),
  820. ),
  821. ));
  822. $feature_cvt = db_select('chado.feature_cvterm', 'fcvt')
  823. ->fields('fcvt')
  824. ->condition('cvterm_id', $term->cvterm_id)
  825. ->condition('feature_id', $gene_1->feature_id)
  826. ->execute();
  827. $this->assertEquals(1, $feature_cvt->rowCount());
  828. }
  829. /**
  830. * Ensures feature parent record loaded correctly into chado.
  831. *
  832. * @group gff
  833. */
  834. public function testGFFImporterAttributeParent() {
  835. $this->initGFFImporterAttributes();
  836. $mrna_uname = 'test_mrna_001.1';
  837. $rel_cvt = chado_get_cvterm(array(
  838. 'name' => 'part_of',
  839. 'cv_id' => array(
  840. 'name' => 'sequence',
  841. ),
  842. ))->cvterm_id;
  843. $mrna = db_select('chado.feature', 'f')
  844. ->fields('f')
  845. ->condition('uniquename', $mrna_uname)
  846. ->condition('type_id', $this->mrna_cvt)
  847. ->execute()->fetchObject();
  848. $query = db_select('chado.feature_relationship', 'fr');
  849. $query->join('chado.feature', 'f', 'f.feature_id = fr.object_id');
  850. $query->fields('f');
  851. $query->condition('fr.subject_id', $mrna->feature_id);
  852. $query->condition('fr.type_id', $rel_cvt);
  853. $query = $query->execute();
  854. $parent = $query->fetchObject();
  855. $this->assertEquals('test_gene_001', $parent->uniquename);
  856. $this->assertEquals('test_gene_001', $parent->name);
  857. $this->assertEquals($this->gene_cvt, $parent->type_id);
  858. $this->assertEquals($this->organism->organism_id, $parent->organism_id);
  859. }
  860. /**
  861. * Ensure target record loaded correctly into chado.
  862. *
  863. * @group gff
  864. */
  865. public function testGFFImporterAttributeTarget() {
  866. $this->initGFFImporterAttributes();
  867. $target_feature = 'scaffold1';
  868. $start = 99;
  869. $end = 200;
  870. $target_type = 'supercontig';
  871. $target_cvt = chado_get_cvterm(array(
  872. 'name' => $target_type,
  873. 'cv_id' => array(
  874. 'name' => 'sequence',
  875. ),
  876. ))->cvterm_id;
  877. $source_feature = db_select('chado.feature', 'f')
  878. ->fields('f')
  879. ->condition('uniquename', $target_feature)
  880. ->condition('type_id', $target_cvt)
  881. ->execute()->fetchObject();
  882. $gene_1 = db_select('chado.feature', 'f')
  883. ->fields('f')
  884. ->condition('uniquename', $this->gene_1_uname)
  885. ->condition('type_id', $this->gene_cvt)
  886. ->execute()->fetchObject();
  887. $featureloc = db_select('chado.featureloc', 'fl')
  888. ->fields('fl')
  889. ->condition('fl.feature_id', $gene_1->feature_id)
  890. ->condition('fl.srcfeature_id', $source_feature->feature_id)
  891. ->execute()->fetchObject();
  892. $this->assertEquals($start, $featureloc->fmin);
  893. $this->assertEquals($end, $featureloc->fmax);
  894. }
  895. /**
  896. * Ensure properties loaded correctly into chado.
  897. *
  898. * @group gff
  899. */
  900. public function testGFFImporterAttributeProperty() {
  901. $this->initGFFImporterAttributes();
  902. $gap_1 = 'test_gap_1';
  903. $gap_2 = 'test_gap_2';
  904. $note_val = 'test_gene_001_note';
  905. $gene_1 = db_select('chado.feature', 'f')
  906. ->fields('f')
  907. ->condition('uniquename', $this->gene_1_uname)
  908. ->condition('type_id', $this->gene_cvt)
  909. ->execute()->fetchObject();
  910. $gap_cvt = chado_get_cvterm(array(
  911. 'name' => 'Gap',
  912. 'cv_id' => array(
  913. 'name' => 'feature_property',
  914. ),
  915. ))->cvterm_id;
  916. $note_cvt = chado_get_cvterm(array(
  917. 'name' => 'Note',
  918. 'cv_id' => array(
  919. 'name' => 'feature_property',
  920. ),
  921. ))->cvterm_id;
  922. // Assert gaps loaded correctly
  923. $gaps_query = db_select('chado.featureprop', 'fp')
  924. ->fields('fp')
  925. ->condition('feature_id', $gene_1->feature_id)
  926. ->condition('type_id', $gap_cvt)
  927. ->execute();
  928. while (($gap = $gaps_query->fetchObject())) {
  929. $gaps[$gap->value] = $gap;
  930. }
  931. $this->assertEquals($gap_1, $gaps[$gap_1]->value);
  932. $this->assertEquals(0, $gaps[$gap_1]->rank);
  933. // Assert note loaded correctly
  934. $note = db_select('chado.featureprop', 'fp')
  935. ->fields('fp')
  936. ->condition('feature_id', $gene_1->feature_id)
  937. ->condition('type_id', $note_cvt)
  938. ->execute()->fetchObject();
  939. $this->assertEquals($note_val, $note->value);
  940. $this->assertEquals(0, $note->rank);
  941. }
  942. /**
  943. * Ensure derives from information loaded correctly into chado.
  944. *
  945. * @group gff
  946. */
  947. public function testGFFImporterAttributeDerivesFrom() {
  948. $this->initGFFImporterAttributes();
  949. $gene_2 = db_select('chado.feature', 'f')
  950. ->fields('f')
  951. ->condition('uniquename', $this->gene_2_uname)
  952. ->condition('type_id', $this->gene_cvt)
  953. ->execute()->fetchObject();
  954. $derivesfrom_cvt = chado_get_cvterm(array(
  955. 'name' => 'derives_from',
  956. 'cv_id' => array(
  957. 'name' => 'sequence',
  958. ),
  959. ))->cvterm_id;
  960. $query = db_select('chado.feature', 'f');
  961. $query->join('chado.feature_relationship', 'fr', 'f.feature_id = fr.object_id');
  962. $query->fields('f');
  963. $query->condition('fr.subject_id', $gene_2->feature_id);
  964. $query->condition('fr.type_id', $derivesfrom_cvt);
  965. $query = $query->execute();
  966. $derivesfrom_feature = $query->fetchObject();
  967. $this->assertEquals($this->gene_1_uname, $derivesfrom_feature->uniquename);
  968. $this->assertEquals($this->gene_1_uname, $derivesfrom_feature->name);
  969. $this->assertEquals($this->gene_cvt, $derivesfrom_feature->type_id);
  970. }
  971. /**
  972. * Ensure FASTA information loaded correctly into chado.
  973. *
  974. * @group gff
  975. */
  976. public function testGFFImporterAttributeFastas() {
  977. $this->initGFFImporterAttributes();
  978. $scaffold = db_select('chado.feature', 'f')
  979. ->fields('f')
  980. ->condition('uniquename', $this->scaffold_1_uname)
  981. ->condition('type_id', $this->supercontig_cvt)
  982. ->execute()->fetchObject();
  983. $this->assertEquals(720, $scaffold->seqlen);
  984. $this->assertEquals(720, strlen($scaffold->residues));
  985. $this->assertEquals('83578d8afdaec399c682aa6c0ddd29c9', $scaffold->md5checksum);
  986. }
  987. /**
  988. * Test that when checked, explicit proteins are created when specified within
  989. * the GFF file. Explicit proteins will not respect the skip_protein argument
  990. * and will therefore be added to the database.
  991. *
  992. * @group gff
  993. * @ticket 77
  994. *
  995. */
  996. public function testGFFPolypeptide() {
  997. $gff_file = ['file_local' => __DIR__ . '/../data/simpleGFF.gff'];
  998. $analysis = factory('chado.analysis')->create();
  999. $organism = factory('chado.organism')->create();
  1000. $run_args = [
  1001. // The new argument
  1002. 'skip_protein' => 1,
  1003. 'analysis_id' => $analysis->analysis_id,
  1004. 'organism_id' => $organism->organism_id,
  1005. 'use_transaction' => 1,
  1006. 'add_only' => 0,
  1007. 'update' => 1,
  1008. 'create_organism' => 0,
  1009. 'create_target' => 0,
  1010. // regexps for mRNA and protein.
  1011. 're_mrna' => NULL,
  1012. 're_protein' => NULL,
  1013. // optional
  1014. 'target_organism_id' => NULL,
  1015. 'target_type' => NULL,
  1016. 'start_line' => NULL,
  1017. 'landmark_type' => NULL,
  1018. 'alt_id_attr' => NULL,
  1019. ];
  1020. $this->loadLandmarks($analysis, $organism);
  1021. $this->runGFFLoader($run_args, $gff_file);
  1022. $identifier = [
  1023. 'cv_id' => ['name' => 'sequence'],
  1024. 'name' => 'polypeptide',
  1025. ];
  1026. $protein_type_id = tripal_get_cvterm($identifier);
  1027. $name = 'FRAEX38873_v2_000000010.1.3_test_protein';
  1028. $query = db_select('chado.feature', 'f')
  1029. ->fields('f', ['uniquename'])
  1030. ->condition('f.uniquename', $name)
  1031. ->condition('f.type_id', $protein_type_id->cvterm_id)
  1032. ->execute()
  1033. ->fetchAll();
  1034. $this->assertEquals(1, count($query));
  1035. }
  1036. /**
  1037. * Add a skip protein option. Test that when checked, implicit proteins are
  1038. * not created, but that they are created when unchecked.
  1039. *
  1040. * @group gff
  1041. * @ticket 77
  1042. *
  1043. */
  1044. public function testGFFNoProteinOption() {
  1045. $gff_file = ['file_local' => __DIR__ . '/../data/gff_protein_generation.gff'];
  1046. $analysis = factory('chado.analysis')->create();
  1047. $organism = factory('chado.organism')->create();
  1048. $run_args = [
  1049. //Skip protein feature generation
  1050. 'skip_protein' => 1,
  1051. 'analysis_id' => $analysis->analysis_id,
  1052. 'organism_id' => $organism->organism_id,
  1053. 'use_transaction' => 1,
  1054. 'add_only' => 0,
  1055. 'update' => 1,
  1056. 'create_organism' => 0,
  1057. 'create_target' => 0,
  1058. ///regexps for mRNA and protein.
  1059. 're_mrna' => NULL,
  1060. 're_protein' => NULL,
  1061. //optional
  1062. 'target_organism_id' => NULL,
  1063. 'target_type' => NULL,
  1064. 'start_line' => NULL,
  1065. 'landmark_type' => NULL,
  1066. 'alt_id_attr' => NULL,
  1067. ];
  1068. $this->loadLandmarks($analysis, $organism);
  1069. $this->runGFFLoader($run_args, $gff_file);
  1070. $identifier = [
  1071. 'cv_id' => ['name' => 'sequence'],
  1072. 'name' => 'polypeptide',
  1073. ];
  1074. $protein_type_id = tripal_get_cvterm($identifier);
  1075. $name = "FRAEX38873_v2_000000190.1-protein";
  1076. $results = db_select('chado.feature', 'f')
  1077. ->fields('f', ['uniquename'])
  1078. ->condition('f.uniquename', $name)
  1079. ->condition('f.type_id', $protein_type_id->cvterm_id)
  1080. ->execute()
  1081. ->fetchAll();
  1082. // There should be no proteins since we used the skip_proteins flag and no
  1083. // explicit proteins were specified in the test file
  1084. $this->assertEquals(0, count($results));
  1085. // Now perform a unit test where we do not skip proteins generation
  1086. $run_args['skip_protein'] = 0;
  1087. $this->runGFFLoader($run_args, $gff_file);
  1088. $query = db_select('chado.feature', 'f')
  1089. ->fields('f', ['uniquename'])
  1090. ->condition('f.uniquename', $name)
  1091. ->condition('f.type_id', $protein_type_id->cvterm_id)
  1092. ->execute()
  1093. ->fetchObject();
  1094. $this->assertEquals($name, $query->uniquename);
  1095. }
  1096. /**
  1097. * The GFF importer should still create explicitly defined proteins if
  1098. * skip_protein is true.
  1099. *
  1100. * @group gff
  1101. * @ticket 77
  1102. */
  1103. public function testGFFImporterLoadsExplicitProteins() {
  1104. $gff_file = ['file_local' => __DIR__ . '/../data/simpleGFF.gff'];
  1105. $analysis = factory('chado.analysis')->create();
  1106. $organism = factory('chado.organism')->create();
  1107. $run_args = [
  1108. //The new argument
  1109. 'skip_protein' => 1,
  1110. ///
  1111. 'analysis_id' => $analysis->analysis_id,
  1112. 'organism_id' => $organism->organism_id,
  1113. 'use_transaction' => 1,
  1114. 'add_only' => 0,
  1115. 'update' => 1,
  1116. 'create_organism' => 0,
  1117. 'create_target' => 0,
  1118. ///regexps for mRNA and protein.
  1119. 're_mrna' => NULL,
  1120. 're_protein' => NULL,
  1121. //optional
  1122. 'target_organism_id' => NULL,
  1123. 'target_type' => NULL,
  1124. 'start_line' => NULL,
  1125. 'landmark_type' => NULL,
  1126. 'alt_id_attr' => NULL,
  1127. ];
  1128. $this->loadLandmarks($analysis, $organism);
  1129. $this->runGFFLoader($run_args, $gff_file);
  1130. $name = 'FRAEX38873_v2_000000010.1.3_test_protein';
  1131. $query = db_select('chado.feature', 'f')
  1132. ->fields('f', ['uniquename'])
  1133. ->condition('f.uniquename', $name)
  1134. ->execute()
  1135. ->fetchField();
  1136. $this->assertEquals($name, $query);
  1137. }
  1138. private function runGFFLoader($run_args, $file) {
  1139. // silent(function ($run_args, $file) {
  1140. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/GFF3Importer');
  1141. $importer = new \GFF3Importer();
  1142. $importer->create($run_args, $file);
  1143. $importer->prepareFiles();
  1144. $importer->run();
  1145. // });
  1146. }
  1147. private function loadLandmarks($analysis, $organism, $landmark_file = array()) {
  1148. if (empty($landmark_file)) {
  1149. $landmark_file = ['file_local' => __DIR__ . '/../data/empty_landmarks.fasta'];
  1150. }
  1151. $run_args = [
  1152. 'organism_id' => $organism->organism_id,
  1153. 'analysis_id' => $analysis->analysis_id,
  1154. 'seqtype' => 'supercontig',
  1155. 'method' => 2, //default insert and update
  1156. 'match_type' => 1, //unique name default
  1157. //optional
  1158. 're_name' => NULL,
  1159. 're_uname' => NULL,
  1160. 're_accession' => NULL,
  1161. 'db_id' => NULL,
  1162. 'rel_type' => NULL,
  1163. 're_subject' => NULL,
  1164. 'parent_type' => NULL,
  1165. ];
  1166. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/FASTAImporter');
  1167. //silent(function ($run_args, $landmark_file) {
  1168. $importer = new \FASTAImporter();
  1169. $importer->create($run_args, $landmark_file);
  1170. $importer->prepareFiles();
  1171. $importer->run();
  1172. // });
  1173. }
  1174. }