GFF3ImporterTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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_unescaped_ids.gff for testing.
  49. *
  50. * This tests whether the GFF loader detects invalid ID that contains
  51. * unescaped whitespaces. The GFF loader should throw an exception which this
  52. * unit test detects.
  53. */
  54. public function testGFFImporterUnescapedWhitespaceID() {
  55. $gff_file = ['file_local' => __DIR__ . '/../data/gff_unescaped_ids.gff'];
  56. $analysis = factory('chado.analysis')->create();
  57. $organism = factory('chado.organism')->create();
  58. $run_args = [
  59. 'analysis_id' => $analysis->analysis_id,
  60. 'organism_id' => $organism->organism_id,
  61. 'use_transaction' => 1,
  62. 'add_only' => 0,
  63. 'update' => 1,
  64. 'create_organism' => 0,
  65. 'create_target' => 0,
  66. // regexps for mRNA and protein.
  67. 're_mrna' => NULL,
  68. 're_protein' => NULL,
  69. // optional
  70. 'target_organism_id' => NULL,
  71. 'target_type' => NULL,
  72. 'start_line' => NULL,
  73. 'landmark_type' => NULL,
  74. 'alt_id_attr' => NULL,
  75. ];
  76. $hasException = false;
  77. try {
  78. $this->loadLandmarks($analysis, $organism);
  79. // This will produce an exception due to unescaped whitespace in ID
  80. $this->runGFFLoader($run_args, $gff_file);
  81. }
  82. catch(\Exception $ex) {
  83. $hasException = true;
  84. }
  85. // We expect an exception to happen so we are looking for a return of true
  86. $this->assertEquals($hasException, true);
  87. }
  88. /**
  89. * Run the GFF loader on gff_rightarrow_ids.gff for testing.
  90. *
  91. * This tests whether the GFF loader detects invalid ID that contains
  92. * beginning arrow >. The GFF loader should throw an exception which this
  93. * unit detects.
  94. */
  95. public function testGFFImporterRightArrowID() {
  96. $gff_file = ['file_local' => __DIR__ . '/../data/gff_rightarrow_id.gff'];
  97. $analysis = factory('chado.analysis')->create();
  98. $organism = factory('chado.organism')->create();
  99. $run_args = [
  100. 'analysis_id' => $analysis->analysis_id,
  101. 'organism_id' => $organism->organism_id,
  102. 'use_transaction' => 1,
  103. 'add_only' => 0,
  104. 'update' => 1,
  105. 'create_organism' => 0,
  106. 'create_target' => 0,
  107. // regexps for mRNA and protein.
  108. 're_mrna' => NULL,
  109. 're_protein' => NULL,
  110. // optional
  111. 'target_organism_id' => NULL,
  112. 'target_type' => NULL,
  113. 'start_line' => NULL,
  114. 'landmark_type' => NULL,
  115. 'alt_id_attr' => NULL,
  116. ];
  117. $hasException = false;
  118. try {
  119. $this->loadLandmarks($analysis, $organism);
  120. // This will produce an exception due to right arrow in ID
  121. $this->runGFFLoader($run_args, $gff_file);
  122. }
  123. catch(\Exception $ex) {
  124. $hasException = true;
  125. }
  126. // We expect an exception to happen so we are looking for a return of true
  127. $this->assertEquals($hasException, true);
  128. }
  129. /**
  130. * Run the GFF loader on gff_duplicate_ids.gff for testing.
  131. *
  132. * This tests whether the GFF loader detects duplicate IDs which makes a
  133. * GFF file invalid since IDs should be unique. The GFF loader should throw
  134. * and exception which this test checks for
  135. */
  136. public function testGFFImporterDuplicateIDsExceptionCheck() {
  137. $gff_file = ['file_local' => __DIR__ . '/../data/gff_duplicate_ids.gff'];
  138. $analysis = factory('chado.analysis')->create();
  139. $organism = factory('chado.organism')->create();
  140. $run_args = [
  141. 'analysis_id' => $analysis->analysis_id,
  142. 'organism_id' => $organism->organism_id,
  143. 'use_transaction' => 1,
  144. 'add_only' => 0,
  145. 'update' => 1,
  146. 'create_organism' => 0,
  147. 'create_target' => 0,
  148. // regexps for mRNA and protein.
  149. 're_mrna' => NULL,
  150. 're_protein' => NULL,
  151. // optional
  152. 'target_organism_id' => NULL,
  153. 'target_type' => NULL,
  154. 'start_line' => NULL,
  155. 'landmark_type' => NULL,
  156. 'alt_id_attr' => NULL,
  157. ];
  158. $hasException = false;
  159. try {
  160. $this->loadLandmarks($analysis, $organism);
  161. // This will produce an exception of duplicate feature ID
  162. $this->runGFFLoader($run_args, $gff_file);
  163. }
  164. catch(\Exception $ex) {
  165. $hasException = true;
  166. }
  167. // We expect an exception to happen so we are looking for a return of true
  168. $this->assertEquals($hasException, true);
  169. }
  170. /**
  171. * Run the GFF loader on gff_invalidstartend.gff for testing.
  172. *
  173. * This tests whether the GFF loader fixes start end values
  174. */
  175. public function testGFFImporterInvalidStartEnd() {
  176. $gff_file = ['file_local' => __DIR__ . '/../data/gff_invalidstartend.gff'];
  177. $analysis = factory('chado.analysis')->create();
  178. $organism = factory('chado.organism')->create();
  179. $run_args = [
  180. 'analysis_id' => $analysis->analysis_id,
  181. 'organism_id' => $organism->organism_id,
  182. 'use_transaction' => 1,
  183. 'add_only' => 0,
  184. 'update' => 1,
  185. 'create_organism' => 0,
  186. 'create_target' => 0,
  187. // regexps for mRNA and protein.
  188. 're_mrna' => NULL,
  189. 're_protein' => NULL,
  190. // optional
  191. 'target_organism_id' => NULL,
  192. 'target_type' => NULL,
  193. 'start_line' => NULL,
  194. 'landmark_type' => NULL,
  195. 'alt_id_attr' => NULL,
  196. ];
  197. $this->loadLandmarks($analysis, $organism);
  198. // This will produce an exception of duplicate feature ID
  199. $this->runGFFLoader($run_args, $gff_file);
  200. $results = db_select('chado.feature', 'f')
  201. ->fields('f', ['uniquename'])
  202. ->condition('f.uniquename', 'FRAEX38873_v2_000000010')
  203. ->execute()
  204. ->fetchAll();
  205. // We expect the feature to still be added to the database
  206. // since the GFF Loader caters for reversing backward numbers
  207. $this->assertEquals(count($results), 1);
  208. }
  209. /**
  210. * Run the GFF loader on small_gene.gff for testing.
  211. *
  212. * This gff has many attributes that we would like to test in the
  213. * testGFFImporterAttribute*() methods.
  214. */
  215. private function initGFFImporterAttributes() {
  216. $gff = ['file_local' => __DIR__ . '/../data/small_gene.gff'];
  217. $fasta = ['file_local' => __DIR__ . '/../data/short_scaffold.fasta'];
  218. $analysis = factory('chado.analysis')->create();
  219. $organism = factory('chado.organism')->create();
  220. $run_args = [
  221. 'analysis_id' => $analysis->analysis_id,
  222. 'organism_id' => $organism->organism_id,
  223. 'use_transaction' => 1,
  224. 'add_only' => 0,
  225. 'update' => 1,
  226. 'create_organism' => 0,
  227. 'create_target' => 0,
  228. ///regexps for mRNA and protein.
  229. 're_mrna' => NULL,
  230. 're_protein' => NULL,
  231. //optional
  232. 'target_organism_id' => $organism->organism_id,
  233. 'target_type' => NULL,
  234. 'start_line' => NULL,
  235. 'landmark_type' => NULL,
  236. 'alt_id_attr' => NULL,
  237. ];
  238. $this->loadLandmarks($analysis, $organism, $fasta);
  239. $this->runGFFLoader($run_args, $gff);
  240. $this->organism = $organism;
  241. $this->analysis = $analysis;
  242. $this->gene_cvt = chado_get_cvterm(array(
  243. 'name' => 'gene',
  244. 'cv_id' => array(
  245. 'name' => 'sequence',
  246. ),
  247. ))->cvterm_id;
  248. $this->mrna_cvt = chado_get_cvterm(array(
  249. 'name' => 'mRNA',
  250. 'cv_id' => array(
  251. 'name' => 'sequence',
  252. ),
  253. ))->cvterm_id;
  254. $this->supercontig_cvt = chado_get_cvterm(array(
  255. 'name' => 'supercontig',
  256. 'cv_id' => array(
  257. 'name' => 'sequence',
  258. ),
  259. ))->cvterm_id;
  260. $this->gene_1_uname = 'test_gene_001';
  261. $this->gene_2_uname = 'test_gene_002';
  262. $this->scaffold_1_uname = 'scaffold1';
  263. }
  264. /**
  265. * Ensures that the feature record is loaded correctly into chado.
  266. *
  267. * @group gff
  268. */
  269. public function testGFFImporterAttributeFeature() {
  270. $this->initGFFImporterAttributes();
  271. $organism = $this->organism;
  272. $query = db_select('chado.feature', 'f')
  273. ->fields('f')
  274. ->condition('uniquename', $this->gene_1_uname)
  275. ->condition('type_id', $this->gene_cvt)
  276. ->execute();
  277. $gene_1 = $query->fetchObject();
  278. $this->assertEquals('test_gene_001', $gene_1->uniquename);
  279. $this->assertEquals('test_gene_001', $gene_1->name);
  280. $this->assertEquals($organism->organism_id, $gene_1->organism_id);
  281. $this->assertEquals($this->gene_cvt, $gene_1->type_id);
  282. }
  283. /**
  284. * Ensures the feature alias is loaded correctly into chado.
  285. *
  286. * @group gff
  287. */
  288. public function testGFFImporterAttributeAlias() {
  289. $this->initGFFImporterAttributes();
  290. $alias = 'first_test_gene';
  291. $gene_1 = db_select('chado.feature', 'f')
  292. ->fields('f')
  293. ->condition('uniquename', $this->gene_1_uname)
  294. ->condition('type_id', $this->gene_cvt)
  295. ->execute()->fetchObject();
  296. $query = db_select('chado.feature_synonym', 'fs');
  297. $query->join('chado.synonym', 's', 's.synonym_id = fs.synonym_id');
  298. $query->fields('s');
  299. $query->condition('fs.feature_id', $gene_1->feature_id);
  300. $query = $query->execute();
  301. $result = $query->fetchObject();
  302. $this->assertEquals($alias, $result->name);
  303. }
  304. /**
  305. * Ensures that the dbxref records are loaded correctly into chado.
  306. *
  307. * @group gff
  308. */
  309. public function testGFFImporterAttributeDbxref() {
  310. $this->initGFFImporterAttributes();
  311. $test_db_name = 'TEST_DB';
  312. $dbx_accession = 'test_gene_dbx_001';
  313. $test_db = chado_get_db(array('name' => $test_db_name));
  314. $gff_db = chado_get_db(array('name' => 'GFF_source'));
  315. $gene_1 = db_select('chado.feature', 'f')
  316. ->fields('f')
  317. ->condition('uniquename', $this->gene_1_uname)
  318. ->condition('type_id', $this->gene_cvt)
  319. ->execute()->fetchObject();
  320. $dbx_query = db_select('chado.feature_dbxref', 'fdbx');
  321. $dbx_query->join('chado.dbxref', 'dbx', 'dbx.dbxref_id = fdbx.dbxref_id');
  322. $dbx_query->fields('dbx');
  323. $dbx_query->condition('fdbx.feature_id', $gene_1->feature_id);
  324. $gff_query = clone $dbx_query;
  325. $dbx_query->condition('dbx.db_id', $test_db->db_id);
  326. $dbx_query = $dbx_query->execute();
  327. $gff_query->condition('dbx.db_id', $gff_db->db_id);
  328. $gff_query = $gff_query->execute();
  329. $dbxref = $dbx_query->fetchObject();
  330. $gff_dbxref = $gff_query->fetchObject();
  331. $this->assertEquals($dbx_accession, $dbxref->accession);
  332. $this->assertEquals($this->gene_1_uname, $gff_dbxref->accession);
  333. }
  334. /**
  335. * Ensures ontology term records loaded correctly into chado.
  336. *
  337. * @group gff
  338. */
  339. public function testGFFImporterAttributeOntology() {
  340. $this->initGFFImporterAttributes();
  341. $ontology_db = 'SO';
  342. $ontology_accession = '0000704';
  343. $gene_1 = db_select('chado.feature', 'f')
  344. ->fields('f')
  345. ->condition('uniquename', $this->gene_1_uname)
  346. ->condition('type_id', $this->gene_cvt)
  347. ->execute()->fetchObject();
  348. $term = chado_get_cvterm(array(
  349. 'dbxref_id' => array(
  350. 'accession' => $ontology_accession,
  351. 'db_id' => array(
  352. 'name' => $ontology_db,
  353. ),
  354. ),
  355. ));
  356. $feature_cvt = db_select('chado.feature_cvterm', 'fcvt')
  357. ->fields('fcvt')
  358. ->condition('cvterm_id', $term->cvterm_id)
  359. ->condition('feature_id', $gene_1->feature_id)
  360. ->execute();
  361. $this->assertEquals(1, $feature_cvt->rowCount());
  362. }
  363. /**
  364. * Ensures feature parent record loaded correctly into chado.
  365. *
  366. * @group gff
  367. */
  368. public function testGFFImporterAttributeParent() {
  369. $this->initGFFImporterAttributes();
  370. $mrna_uname = 'test_mrna_001.1';
  371. $rel_cvt = chado_get_cvterm(array(
  372. 'name' => 'part_of',
  373. 'cv_id' => array(
  374. 'name' => 'sequence',
  375. ),
  376. ))->cvterm_id;
  377. $mrna = db_select('chado.feature', 'f')
  378. ->fields('f')
  379. ->condition('uniquename', $mrna_uname)
  380. ->condition('type_id', $this->mrna_cvt)
  381. ->execute()->fetchObject();
  382. $query = db_select('chado.feature_relationship', 'fr');
  383. $query->join('chado.feature', 'f', 'f.feature_id = fr.object_id');
  384. $query->fields('f');
  385. $query->condition('fr.subject_id', $mrna->feature_id);
  386. $query->condition('fr.type_id', $rel_cvt);
  387. $query = $query->execute();
  388. $parent = $query->fetchObject();
  389. $this->assertEquals('test_gene_001', $parent->uniquename);
  390. $this->assertEquals('test_gene_001', $parent->name);
  391. $this->assertEquals($this->gene_cvt, $parent->type_id);
  392. $this->assertEquals($this->organism->organism_id, $parent->organism_id);
  393. }
  394. /**
  395. * Ensure target record loaded correctly into chado.
  396. *
  397. * @group gff
  398. */
  399. public function testGFFImporterAttributeTarget() {
  400. $this->initGFFImporterAttributes();
  401. $target_feature = 'scaffold1';
  402. $start = 99;
  403. $end = 200;
  404. $target_type = 'supercontig';
  405. $target_cvt = chado_get_cvterm(array(
  406. 'name' => $target_type,
  407. 'cv_id' => array(
  408. 'name' => 'sequence',
  409. ),
  410. ))->cvterm_id;
  411. $source_feature = db_select('chado.feature', 'f')
  412. ->fields('f')
  413. ->condition('uniquename', $target_feature)
  414. ->condition('type_id', $target_cvt)
  415. ->execute()->fetchObject();
  416. $gene_1 = db_select('chado.feature', 'f')
  417. ->fields('f')
  418. ->condition('uniquename', $this->gene_1_uname)
  419. ->condition('type_id', $this->gene_cvt)
  420. ->execute()->fetchObject();
  421. $featureloc = db_select('chado.featureloc', 'fl')
  422. ->fields('fl')
  423. ->condition('fl.feature_id', $gene_1->feature_id)
  424. ->condition('fl.srcfeature_id', $source_feature->feature_id)
  425. ->execute()->fetchObject();
  426. $this->assertEquals($start, $featureloc->fmin);
  427. $this->assertEquals($end, $featureloc->fmax);
  428. }
  429. /**
  430. * Ensure properties loaded correctly into chado.
  431. *
  432. * @group gff
  433. */
  434. public function testGFFImporterAttributeProperty() {
  435. $this->initGFFImporterAttributes();
  436. $gap_1 = 'test_gap_1';
  437. $gap_2 = 'test_gap_2';
  438. $note_val = 'test_gene_001_note';
  439. $gene_1 = db_select('chado.feature', 'f')
  440. ->fields('f')
  441. ->condition('uniquename', $this->gene_1_uname)
  442. ->condition('type_id', $this->gene_cvt)
  443. ->execute()->fetchObject();
  444. $gap_cvt = chado_get_cvterm(array(
  445. 'name' => 'Gap',
  446. 'cv_id' => array(
  447. 'name' => 'feature_property',
  448. ),
  449. ))->cvterm_id;
  450. $note_cvt = chado_get_cvterm(array(
  451. 'name' => 'Note',
  452. 'cv_id' => array(
  453. 'name' => 'feature_property',
  454. ),
  455. ))->cvterm_id;
  456. // Assert gaps loaded correctly
  457. $gaps_query = db_select('chado.featureprop', 'fp')
  458. ->fields('fp')
  459. ->condition('feature_id', $gene_1->feature_id)
  460. ->condition('type_id', $gap_cvt)
  461. ->execute();
  462. while (($gap = $gaps_query->fetchObject())) {
  463. $gaps[$gap->value] = $gap;
  464. }
  465. $this->assertEquals($gap_1, $gaps[$gap_1]->value);
  466. $this->assertEquals(0, $gaps[$gap_1]->rank);
  467. // Assert note loaded correctly
  468. $note = db_select('chado.featureprop', 'fp')
  469. ->fields('fp')
  470. ->condition('feature_id', $gene_1->feature_id)
  471. ->condition('type_id', $note_cvt)
  472. ->execute()->fetchObject();
  473. $this->assertEquals($note_val, $note->value);
  474. $this->assertEquals(0, $note->rank);
  475. }
  476. /**
  477. * Ensure derives from information loaded correctly into chado.
  478. *
  479. * @group gff
  480. */
  481. public function testGFFImporterAttributeDerivesFrom() {
  482. $this->initGFFImporterAttributes();
  483. $gene_2 = db_select('chado.feature', 'f')
  484. ->fields('f')
  485. ->condition('uniquename', $this->gene_2_uname)
  486. ->condition('type_id', $this->gene_cvt)
  487. ->execute()->fetchObject();
  488. $derivesfrom_cvt = chado_get_cvterm(array(
  489. 'name' => 'derives_from',
  490. 'cv_id' => array(
  491. 'name' => 'sequence',
  492. ),
  493. ))->cvterm_id;
  494. $query = db_select('chado.feature', 'f');
  495. $query->join('chado.feature_relationship', 'fr', 'f.feature_id = fr.object_id');
  496. $query->fields('f');
  497. $query->condition('fr.subject_id', $gene_2->feature_id);
  498. $query->condition('fr.type_id', $derivesfrom_cvt);
  499. $query = $query->execute();
  500. $derivesfrom_feature = $query->fetchObject();
  501. $this->assertEquals($this->gene_1_uname, $derivesfrom_feature->uniquename);
  502. $this->assertEquals($this->gene_1_uname, $derivesfrom_feature->name);
  503. $this->assertEquals($this->gene_cvt, $derivesfrom_feature->type_id);
  504. }
  505. /**
  506. * Ensure FASTA information loaded correctly into chado.
  507. *
  508. * @group gff
  509. */
  510. public function testGFFImporterAttributeFastas() {
  511. $this->initGFFImporterAttributes();
  512. $scaffold = db_select('chado.feature', 'f')
  513. ->fields('f')
  514. ->condition('uniquename', $this->scaffold_1_uname)
  515. ->condition('type_id', $this->supercontig_cvt)
  516. ->execute()->fetchObject();
  517. $this->assertEquals(720, $scaffold->seqlen);
  518. $this->assertEquals(720, strlen($scaffold->residues));
  519. $this->assertEquals('83578d8afdaec399c682aa6c0ddd29c9', $scaffold->md5checksum);
  520. }
  521. /**
  522. * Test that when checked, explicit proteins are created when specified within
  523. * the GFF file. Explicit proteins will not respect the skip_protein argument
  524. * and will therefore be added to the database.
  525. *
  526. * @group gff
  527. * @ticket 77
  528. *
  529. */
  530. public function testGFFPolypeptide() {
  531. $gff_file = ['file_local' => __DIR__ . '/../data/simpleGFF.gff'];
  532. $analysis = factory('chado.analysis')->create();
  533. $organism = factory('chado.organism')->create();
  534. $run_args = [
  535. // The new argument
  536. 'skip_protein' => 1,
  537. 'analysis_id' => $analysis->analysis_id,
  538. 'organism_id' => $organism->organism_id,
  539. 'use_transaction' => 1,
  540. 'add_only' => 0,
  541. 'update' => 1,
  542. 'create_organism' => 0,
  543. 'create_target' => 0,
  544. // regexps for mRNA and protein.
  545. 're_mrna' => NULL,
  546. 're_protein' => NULL,
  547. // optional
  548. 'target_organism_id' => NULL,
  549. 'target_type' => NULL,
  550. 'start_line' => NULL,
  551. 'landmark_type' => NULL,
  552. 'alt_id_attr' => NULL,
  553. ];
  554. $this->loadLandmarks($analysis, $organism);
  555. $this->runGFFLoader($run_args, $gff_file);
  556. $identifier = [
  557. 'cv_id' => ['name' => 'sequence'],
  558. 'name' => 'polypeptide',
  559. ];
  560. $protein_type_id = tripal_get_cvterm($identifier);
  561. $name = 'FRAEX38873_v2_000000010.1.3_test_protein';
  562. $query = db_select('chado.feature', 'f')
  563. ->fields('f', ['uniquename'])
  564. ->condition('f.uniquename', $name)
  565. ->condition('f.type_id', $protein_type_id->cvterm_id)
  566. ->execute()
  567. ->fetchAll();
  568. $this->assertEquals(1, count($query));
  569. }
  570. /**
  571. * Add a skip protein option. Test that when checked, implicit proteins are
  572. * not created, but that they are created when unchecked.
  573. *
  574. * @group gff
  575. * @ticket 77
  576. *
  577. */
  578. public function testGFFNoProteinOption() {
  579. $gff_file = ['file_local' => __DIR__ . '/../data/gff_protein_generation.gff'];
  580. $analysis = factory('chado.analysis')->create();
  581. $organism = factory('chado.organism')->create();
  582. $run_args = [
  583. //Skip protein feature generation
  584. 'skip_protein' => 1,
  585. 'analysis_id' => $analysis->analysis_id,
  586. 'organism_id' => $organism->organism_id,
  587. 'use_transaction' => 1,
  588. 'add_only' => 0,
  589. 'update' => 1,
  590. 'create_organism' => 0,
  591. 'create_target' => 0,
  592. ///regexps for mRNA and protein.
  593. 're_mrna' => NULL,
  594. 're_protein' => NULL,
  595. //optional
  596. 'target_organism_id' => NULL,
  597. 'target_type' => NULL,
  598. 'start_line' => NULL,
  599. 'landmark_type' => NULL,
  600. 'alt_id_attr' => NULL,
  601. ];
  602. $this->loadLandmarks($analysis, $organism);
  603. $this->runGFFLoader($run_args, $gff_file);
  604. $identifier = [
  605. 'cv_id' => ['name' => 'sequence'],
  606. 'name' => 'polypeptide',
  607. ];
  608. $protein_type_id = tripal_get_cvterm($identifier);
  609. $name = "FRAEX38873_v2_000000190.1-protein";
  610. $results = db_select('chado.feature', 'f')
  611. ->fields('f', ['uniquename'])
  612. ->condition('f.uniquename', $name)
  613. ->condition('f.type_id', $protein_type_id->cvterm_id)
  614. ->execute()
  615. ->fetchAll();
  616. // There should be no proteins since we used the skip_proteins flag and no
  617. // explicit proteins were specified in the test file
  618. $this->assertEquals(0, count($results));
  619. // Now perform a unit test where we do not skip proteins generation
  620. $run_args['skip_protein'] = 0;
  621. $this->runGFFLoader($run_args, $gff_file);
  622. $query = db_select('chado.feature', 'f')
  623. ->fields('f', ['uniquename'])
  624. ->condition('f.uniquename', $name)
  625. ->condition('f.type_id', $protein_type_id->cvterm_id)
  626. ->execute()
  627. ->fetchObject();
  628. $this->assertEquals($name, $query->uniquename);
  629. }
  630. /**
  631. * The GFF importer should still create explicitly defined proteins if
  632. * skip_protein is true.
  633. *
  634. * @group gff
  635. * @ticket 77
  636. */
  637. public function testGFFImporterLoadsExplicitProteins() {
  638. $gff_file = ['file_local' => __DIR__ . '/../data/simpleGFF.gff'];
  639. $analysis = factory('chado.analysis')->create();
  640. $organism = factory('chado.organism')->create();
  641. $run_args = [
  642. //The new argument
  643. 'skip_protein' => 1,
  644. ///
  645. 'analysis_id' => $analysis->analysis_id,
  646. 'organism_id' => $organism->organism_id,
  647. 'use_transaction' => 1,
  648. 'add_only' => 0,
  649. 'update' => 1,
  650. 'create_organism' => 0,
  651. 'create_target' => 0,
  652. ///regexps for mRNA and protein.
  653. 're_mrna' => NULL,
  654. 're_protein' => NULL,
  655. //optional
  656. 'target_organism_id' => NULL,
  657. 'target_type' => NULL,
  658. 'start_line' => NULL,
  659. 'landmark_type' => NULL,
  660. 'alt_id_attr' => NULL,
  661. ];
  662. $this->loadLandmarks($analysis, $organism);
  663. $this->runGFFLoader($run_args, $gff_file);
  664. $name = 'FRAEX38873_v2_000000010.1.3_test_protein';
  665. $query = db_select('chado.feature', 'f')
  666. ->fields('f', ['uniquename'])
  667. ->condition('f.uniquename', $name)
  668. ->execute()
  669. ->fetchField();
  670. $this->assertEquals($name, $query);
  671. }
  672. private function runGFFLoader($run_args, $file) {
  673. // silent(function ($run_args, $file) {
  674. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/GFF3Importer');
  675. $importer = new \GFF3Importer();
  676. $importer->create($run_args, $file);
  677. $importer->prepareFiles();
  678. $importer->run();
  679. // });
  680. }
  681. private function loadLandmarks($analysis, $organism, $landmark_file = array()) {
  682. if (empty($landmark_file)) {
  683. $landmark_file = ['file_local' => __DIR__ . '/../data/empty_landmarks.fasta'];
  684. }
  685. $run_args = [
  686. 'organism_id' => $organism->organism_id,
  687. 'analysis_id' => $analysis->analysis_id,
  688. 'seqtype' => 'supercontig',
  689. 'method' => 2, //default insert and update
  690. 'match_type' => 1, //unique name default
  691. //optional
  692. 're_name' => NULL,
  693. 're_uname' => NULL,
  694. 're_accession' => NULL,
  695. 'db_id' => NULL,
  696. 'rel_type' => NULL,
  697. 're_subject' => NULL,
  698. 'parent_type' => NULL,
  699. ];
  700. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/FASTAImporter');
  701. //silent(function ($run_args, $landmark_file) {
  702. $importer = new \FASTAImporter();
  703. $importer->create($run_args, $landmark_file);
  704. $importer->prepareFiles();
  705. $importer->run();
  706. // });
  707. }
  708. }