GFF3ImporterTest.php 41 KB

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