GFF3ImporterTest.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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 unescaped whitespace 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 small_gene.gff for testing.
  172. *
  173. * This gff has many attributes that we would like to test in the
  174. * testGFFImporterAttribute*() methods.
  175. */
  176. private function initGFFImporterAttributes() {
  177. $gff = ['file_local' => __DIR__ . '/../data/small_gene.gff'];
  178. $fasta = ['file_local' => __DIR__ . '/../data/short_scaffold.fasta'];
  179. $analysis = factory('chado.analysis')->create();
  180. $organism = factory('chado.organism')->create();
  181. $run_args = [
  182. 'analysis_id' => $analysis->analysis_id,
  183. 'organism_id' => $organism->organism_id,
  184. 'use_transaction' => 1,
  185. 'add_only' => 0,
  186. 'update' => 1,
  187. 'create_organism' => 0,
  188. 'create_target' => 0,
  189. ///regexps for mRNA and protein.
  190. 're_mrna' => NULL,
  191. 're_protein' => NULL,
  192. //optional
  193. 'target_organism_id' => $organism->organism_id,
  194. 'target_type' => NULL,
  195. 'start_line' => NULL,
  196. 'landmark_type' => NULL,
  197. 'alt_id_attr' => NULL,
  198. ];
  199. $this->loadLandmarks($analysis, $organism, $fasta);
  200. $this->runGFFLoader($run_args, $gff);
  201. $this->organism = $organism;
  202. $this->analysis = $analysis;
  203. $this->gene_cvt = chado_get_cvterm(array(
  204. 'name' => 'gene',
  205. 'cv_id' => array(
  206. 'name' => 'sequence',
  207. ),
  208. ))->cvterm_id;
  209. $this->mrna_cvt = chado_get_cvterm(array(
  210. 'name' => 'mRNA',
  211. 'cv_id' => array(
  212. 'name' => 'sequence',
  213. ),
  214. ))->cvterm_id;
  215. $this->supercontig_cvt = chado_get_cvterm(array(
  216. 'name' => 'supercontig',
  217. 'cv_id' => array(
  218. 'name' => 'sequence',
  219. ),
  220. ))->cvterm_id;
  221. $this->gene_1_uname = 'test_gene_001';
  222. $this->gene_2_uname = 'test_gene_002';
  223. $this->scaffold_1_uname = 'scaffold1';
  224. }
  225. /**
  226. * Ensures that the feature record is loaded correctly into chado.
  227. *
  228. * @group gff
  229. */
  230. public function testGFFImporterAttributeFeature() {
  231. $this->initGFFImporterAttributes();
  232. $organism = $this->organism;
  233. $query = db_select('chado.feature', 'f')
  234. ->fields('f')
  235. ->condition('uniquename', $this->gene_1_uname)
  236. ->condition('type_id', $this->gene_cvt)
  237. ->execute();
  238. $gene_1 = $query->fetchObject();
  239. $this->assertEquals('test_gene_001', $gene_1->uniquename);
  240. $this->assertEquals('test_gene_001', $gene_1->name);
  241. $this->assertEquals($organism->organism_id, $gene_1->organism_id);
  242. $this->assertEquals($this->gene_cvt, $gene_1->type_id);
  243. }
  244. /**
  245. * Ensures the feature alias is loaded correctly into chado.
  246. *
  247. * @group gff
  248. */
  249. public function testGFFImporterAttributeAlias() {
  250. $this->initGFFImporterAttributes();
  251. $alias = 'first_test_gene';
  252. $gene_1 = db_select('chado.feature', 'f')
  253. ->fields('f')
  254. ->condition('uniquename', $this->gene_1_uname)
  255. ->condition('type_id', $this->gene_cvt)
  256. ->execute()->fetchObject();
  257. $query = db_select('chado.feature_synonym', 'fs');
  258. $query->join('chado.synonym', 's', 's.synonym_id = fs.synonym_id');
  259. $query->fields('s');
  260. $query->condition('fs.feature_id', $gene_1->feature_id);
  261. $query = $query->execute();
  262. $result = $query->fetchObject();
  263. $this->assertEquals($alias, $result->name);
  264. }
  265. /**
  266. * Ensures that the dbxref records are loaded correctly into chado.
  267. *
  268. * @group gff
  269. */
  270. public function testGFFImporterAttributeDbxref() {
  271. $this->initGFFImporterAttributes();
  272. $test_db_name = 'TEST_DB';
  273. $dbx_accession = 'test_gene_dbx_001';
  274. $test_db = chado_get_db(array('name' => $test_db_name));
  275. $gff_db = chado_get_db(array('name' => 'GFF_source'));
  276. $gene_1 = db_select('chado.feature', 'f')
  277. ->fields('f')
  278. ->condition('uniquename', $this->gene_1_uname)
  279. ->condition('type_id', $this->gene_cvt)
  280. ->execute()->fetchObject();
  281. $dbx_query = db_select('chado.feature_dbxref', 'fdbx');
  282. $dbx_query->join('chado.dbxref', 'dbx', 'dbx.dbxref_id = fdbx.dbxref_id');
  283. $dbx_query->fields('dbx');
  284. $dbx_query->condition('fdbx.feature_id', $gene_1->feature_id);
  285. $gff_query = clone $dbx_query;
  286. $dbx_query->condition('dbx.db_id', $test_db->db_id);
  287. $dbx_query = $dbx_query->execute();
  288. $gff_query->condition('dbx.db_id', $gff_db->db_id);
  289. $gff_query = $gff_query->execute();
  290. $dbxref = $dbx_query->fetchObject();
  291. $gff_dbxref = $gff_query->fetchObject();
  292. $this->assertEquals($dbx_accession, $dbxref->accession);
  293. $this->assertEquals($this->gene_1_uname, $gff_dbxref->accession);
  294. }
  295. /**
  296. * Ensures ontology term records loaded correctly into chado.
  297. *
  298. * @group gff
  299. */
  300. public function testGFFImporterAttributeOntology() {
  301. $this->initGFFImporterAttributes();
  302. $ontology_db = 'SO';
  303. $ontology_accession = '0000704';
  304. $gene_1 = db_select('chado.feature', 'f')
  305. ->fields('f')
  306. ->condition('uniquename', $this->gene_1_uname)
  307. ->condition('type_id', $this->gene_cvt)
  308. ->execute()->fetchObject();
  309. $term = chado_get_cvterm(array(
  310. 'dbxref_id' => array(
  311. 'accession' => $ontology_accession,
  312. 'db_id' => array(
  313. 'name' => $ontology_db,
  314. ),
  315. ),
  316. ));
  317. $feature_cvt = db_select('chado.feature_cvterm', 'fcvt')
  318. ->fields('fcvt')
  319. ->condition('cvterm_id', $term->cvterm_id)
  320. ->condition('feature_id', $gene_1->feature_id)
  321. ->execute();
  322. $this->assertEquals(1, $feature_cvt->rowCount());
  323. }
  324. /**
  325. * Ensures feature parent record loaded correctly into chado.
  326. *
  327. * @group gff
  328. */
  329. public function testGFFImporterAttributeParent() {
  330. $this->initGFFImporterAttributes();
  331. $mrna_uname = 'test_mrna_001.1';
  332. $rel_cvt = chado_get_cvterm(array(
  333. 'name' => 'part_of',
  334. 'cv_id' => array(
  335. 'name' => 'sequence',
  336. ),
  337. ))->cvterm_id;
  338. $mrna = db_select('chado.feature', 'f')
  339. ->fields('f')
  340. ->condition('uniquename', $mrna_uname)
  341. ->condition('type_id', $this->mrna_cvt)
  342. ->execute()->fetchObject();
  343. $query = db_select('chado.feature_relationship', 'fr');
  344. $query->join('chado.feature', 'f', 'f.feature_id = fr.object_id');
  345. $query->fields('f');
  346. $query->condition('fr.subject_id', $mrna->feature_id);
  347. $query->condition('fr.type_id', $rel_cvt);
  348. $query = $query->execute();
  349. $parent = $query->fetchObject();
  350. $this->assertEquals('test_gene_001', $parent->uniquename);
  351. $this->assertEquals('test_gene_001', $parent->name);
  352. $this->assertEquals($this->gene_cvt, $parent->type_id);
  353. $this->assertEquals($this->organism->organism_id, $parent->organism_id);
  354. }
  355. /**
  356. * Ensure target record loaded correctly into chado.
  357. *
  358. * @group gff
  359. */
  360. public function testGFFImporterAttributeTarget() {
  361. $this->initGFFImporterAttributes();
  362. $target_feature = 'scaffold1';
  363. $start = 99;
  364. $end = 200;
  365. $target_type = 'supercontig';
  366. $target_cvt = chado_get_cvterm(array(
  367. 'name' => $target_type,
  368. 'cv_id' => array(
  369. 'name' => 'sequence',
  370. ),
  371. ))->cvterm_id;
  372. $source_feature = db_select('chado.feature', 'f')
  373. ->fields('f')
  374. ->condition('uniquename', $target_feature)
  375. ->condition('type_id', $target_cvt)
  376. ->execute()->fetchObject();
  377. $gene_1 = db_select('chado.feature', 'f')
  378. ->fields('f')
  379. ->condition('uniquename', $this->gene_1_uname)
  380. ->condition('type_id', $this->gene_cvt)
  381. ->execute()->fetchObject();
  382. $featureloc = db_select('chado.featureloc', 'fl')
  383. ->fields('fl')
  384. ->condition('fl.feature_id', $gene_1->feature_id)
  385. ->condition('fl.srcfeature_id', $source_feature->feature_id)
  386. ->execute()->fetchObject();
  387. $this->assertEquals($start, $featureloc->fmin);
  388. $this->assertEquals($end, $featureloc->fmax);
  389. }
  390. /**
  391. * Ensure properties loaded correctly into chado.
  392. *
  393. * @group gff
  394. */
  395. public function testGFFImporterAttributeProperty() {
  396. $this->initGFFImporterAttributes();
  397. $gap_1 = 'test_gap_1';
  398. $gap_2 = 'test_gap_2';
  399. $note_val = 'test_gene_001_note';
  400. $gene_1 = db_select('chado.feature', 'f')
  401. ->fields('f')
  402. ->condition('uniquename', $this->gene_1_uname)
  403. ->condition('type_id', $this->gene_cvt)
  404. ->execute()->fetchObject();
  405. $gap_cvt = chado_get_cvterm(array(
  406. 'name' => 'Gap',
  407. 'cv_id' => array(
  408. 'name' => 'feature_property',
  409. ),
  410. ))->cvterm_id;
  411. $note_cvt = chado_get_cvterm(array(
  412. 'name' => 'Note',
  413. 'cv_id' => array(
  414. 'name' => 'feature_property',
  415. ),
  416. ))->cvterm_id;
  417. // Assert gaps loaded correctly
  418. $gaps_query = db_select('chado.featureprop', 'fp')
  419. ->fields('fp')
  420. ->condition('feature_id', $gene_1->feature_id)
  421. ->condition('type_id', $gap_cvt)
  422. ->execute();
  423. while (($gap = $gaps_query->fetchObject())) {
  424. $gaps[$gap->value] = $gap;
  425. }
  426. $this->assertEquals($gap_1, $gaps[$gap_1]->value);
  427. $this->assertEquals(0, $gaps[$gap_1]->rank);
  428. // Assert note loaded correctly
  429. $note = db_select('chado.featureprop', 'fp')
  430. ->fields('fp')
  431. ->condition('feature_id', $gene_1->feature_id)
  432. ->condition('type_id', $note_cvt)
  433. ->execute()->fetchObject();
  434. $this->assertEquals($note_val, $note->value);
  435. $this->assertEquals(0, $note->rank);
  436. }
  437. /**
  438. * Ensure derives from information loaded correctly into chado.
  439. *
  440. * @group gff
  441. */
  442. public function testGFFImporterAttributeDerivesFrom() {
  443. $this->initGFFImporterAttributes();
  444. $gene_2 = db_select('chado.feature', 'f')
  445. ->fields('f')
  446. ->condition('uniquename', $this->gene_2_uname)
  447. ->condition('type_id', $this->gene_cvt)
  448. ->execute()->fetchObject();
  449. $derivesfrom_cvt = chado_get_cvterm(array(
  450. 'name' => 'derives_from',
  451. 'cv_id' => array(
  452. 'name' => 'sequence',
  453. ),
  454. ))->cvterm_id;
  455. $query = db_select('chado.feature', 'f');
  456. $query->join('chado.feature_relationship', 'fr', 'f.feature_id = fr.object_id');
  457. $query->fields('f');
  458. $query->condition('fr.subject_id', $gene_2->feature_id);
  459. $query->condition('fr.type_id', $derivesfrom_cvt);
  460. $query = $query->execute();
  461. $derivesfrom_feature = $query->fetchObject();
  462. $this->assertEquals($this->gene_1_uname, $derivesfrom_feature->uniquename);
  463. $this->assertEquals($this->gene_1_uname, $derivesfrom_feature->name);
  464. $this->assertEquals($this->gene_cvt, $derivesfrom_feature->type_id);
  465. }
  466. /**
  467. * Ensure FASTA information loaded correctly into chado.
  468. *
  469. * @group gff
  470. */
  471. public function testGFFImporterAttributeFastas() {
  472. $this->initGFFImporterAttributes();
  473. $scaffold = db_select('chado.feature', 'f')
  474. ->fields('f')
  475. ->condition('uniquename', $this->scaffold_1_uname)
  476. ->condition('type_id', $this->supercontig_cvt)
  477. ->execute()->fetchObject();
  478. $this->assertEquals(720, $scaffold->seqlen);
  479. $this->assertEquals(720, strlen($scaffold->residues));
  480. $this->assertEquals('83578d8afdaec399c682aa6c0ddd29c9', $scaffold->md5checksum);
  481. }
  482. /**
  483. * Test that when checked, explicit proteins are created when specified within
  484. * the GFF file. Explicit proteins will not respect the skip_protein argument
  485. * and will therefore be added to the database.
  486. *
  487. * @group gff
  488. * @ticket 77
  489. *
  490. */
  491. public function testGFFPolypeptide() {
  492. $gff_file = ['file_local' => __DIR__ . '/../data/simpleGFF.gff'];
  493. $analysis = factory('chado.analysis')->create();
  494. $organism = factory('chado.organism')->create();
  495. $run_args = [
  496. // The new argument
  497. 'skip_protein' => 1,
  498. 'analysis_id' => $analysis->analysis_id,
  499. 'organism_id' => $organism->organism_id,
  500. 'use_transaction' => 1,
  501. 'add_only' => 0,
  502. 'update' => 1,
  503. 'create_organism' => 0,
  504. 'create_target' => 0,
  505. // regexps for mRNA and protein.
  506. 're_mrna' => NULL,
  507. 're_protein' => NULL,
  508. // optional
  509. 'target_organism_id' => NULL,
  510. 'target_type' => NULL,
  511. 'start_line' => NULL,
  512. 'landmark_type' => NULL,
  513. 'alt_id_attr' => NULL,
  514. ];
  515. $this->loadLandmarks($analysis, $organism);
  516. $this->runGFFLoader($run_args, $gff_file);
  517. $identifier = [
  518. 'cv_id' => ['name' => 'sequence'],
  519. 'name' => 'polypeptide',
  520. ];
  521. $protein_type_id = tripal_get_cvterm($identifier);
  522. $name = 'FRAEX38873_v2_000000010.1.3_test_protein';
  523. $query = db_select('chado.feature', 'f')
  524. ->fields('f', ['uniquename'])
  525. ->condition('f.uniquename', $name)
  526. ->condition('f.type_id', $protein_type_id->cvterm_id)
  527. ->execute()
  528. ->fetchAll();
  529. $this->assertEquals(1, count($query));
  530. }
  531. /**
  532. * Add a skip protein option. Test that when checked, implicit proteins are
  533. * not created, but that they are created when unchecked.
  534. *
  535. * @group gff
  536. * @ticket 77
  537. *
  538. */
  539. public function testGFFNoProteinOption() {
  540. $gff_file = ['file_local' => __DIR__ . '/../data/gff_protein_generation.gff'];
  541. $analysis = factory('chado.analysis')->create();
  542. $organism = factory('chado.organism')->create();
  543. $run_args = [
  544. //Skip protein feature generation
  545. 'skip_protein' => 1,
  546. 'analysis_id' => $analysis->analysis_id,
  547. 'organism_id' => $organism->organism_id,
  548. 'use_transaction' => 1,
  549. 'add_only' => 0,
  550. 'update' => 1,
  551. 'create_organism' => 0,
  552. 'create_target' => 0,
  553. ///regexps for mRNA and protein.
  554. 're_mrna' => NULL,
  555. 're_protein' => NULL,
  556. //optional
  557. 'target_organism_id' => NULL,
  558. 'target_type' => NULL,
  559. 'start_line' => NULL,
  560. 'landmark_type' => NULL,
  561. 'alt_id_attr' => NULL,
  562. ];
  563. $this->loadLandmarks($analysis, $organism);
  564. $this->runGFFLoader($run_args, $gff_file);
  565. $identifier = [
  566. 'cv_id' => ['name' => 'sequence'],
  567. 'name' => 'polypeptide',
  568. ];
  569. $protein_type_id = tripal_get_cvterm($identifier);
  570. $name = "FRAEX38873_v2_000000190.1-protein";
  571. $results = db_select('chado.feature', 'f')
  572. ->fields('f', ['uniquename'])
  573. ->condition('f.uniquename', $name)
  574. ->condition('f.type_id', $protein_type_id->cvterm_id)
  575. ->execute()
  576. ->fetchAll();
  577. // There should be no proteins since we used the skip_proteins flag and no
  578. // explicit proteins were specified in the test file
  579. $this->assertEquals(0, count($results));
  580. // Now perform a unit test where we do not skip proteins generation
  581. $run_args['skip_protein'] = 0;
  582. $this->runGFFLoader($run_args, $gff_file);
  583. $query = db_select('chado.feature', 'f')
  584. ->fields('f', ['uniquename'])
  585. ->condition('f.uniquename', $name)
  586. ->condition('f.type_id', $protein_type_id->cvterm_id)
  587. ->execute()
  588. ->fetchObject();
  589. $this->assertEquals($name, $query->uniquename);
  590. }
  591. /**
  592. * The GFF importer should still create explicitly defined proteins if
  593. * skip_protein is true.
  594. *
  595. * @group gff
  596. * @ticket 77
  597. */
  598. public function testGFFImporterLoadsExplicitProteins() {
  599. $gff_file = ['file_local' => __DIR__ . '/../data/simpleGFF.gff'];
  600. $analysis = factory('chado.analysis')->create();
  601. $organism = factory('chado.organism')->create();
  602. $run_args = [
  603. //The new argument
  604. 'skip_protein' => 1,
  605. ///
  606. 'analysis_id' => $analysis->analysis_id,
  607. 'organism_id' => $organism->organism_id,
  608. 'use_transaction' => 1,
  609. 'add_only' => 0,
  610. 'update' => 1,
  611. 'create_organism' => 0,
  612. 'create_target' => 0,
  613. ///regexps for mRNA and protein.
  614. 're_mrna' => NULL,
  615. 're_protein' => NULL,
  616. //optional
  617. 'target_organism_id' => NULL,
  618. 'target_type' => NULL,
  619. 'start_line' => NULL,
  620. 'landmark_type' => NULL,
  621. 'alt_id_attr' => NULL,
  622. ];
  623. $this->loadLandmarks($analysis, $organism);
  624. $this->runGFFLoader($run_args, $gff_file);
  625. $name = 'FRAEX38873_v2_000000010.1.3_test_protein';
  626. $query = db_select('chado.feature', 'f')
  627. ->fields('f', ['uniquename'])
  628. ->condition('f.uniquename', $name)
  629. ->execute()
  630. ->fetchField();
  631. $this->assertEquals($name, $query);
  632. }
  633. private function runGFFLoader($run_args, $file) {
  634. // silent(function ($run_args, $file) {
  635. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/GFF3Importer');
  636. $importer = new \GFF3Importer();
  637. $importer->create($run_args, $file);
  638. $importer->prepareFiles();
  639. $importer->run();
  640. // });
  641. }
  642. private function loadLandmarks($analysis, $organism, $landmark_file = array()) {
  643. if (empty($landmark_file)) {
  644. $landmark_file = ['file_local' => __DIR__ . '/../data/empty_landmarks.fasta'];
  645. }
  646. $run_args = [
  647. 'organism_id' => $organism->organism_id,
  648. 'analysis_id' => $analysis->analysis_id,
  649. 'seqtype' => 'supercontig',
  650. 'method' => 2, //default insert and update
  651. 'match_type' => 1, //unique name default
  652. //optional
  653. 're_name' => NULL,
  654. 're_uname' => NULL,
  655. 're_accession' => NULL,
  656. 'db_id' => NULL,
  657. 'rel_type' => NULL,
  658. 're_subject' => NULL,
  659. 'parent_type' => NULL,
  660. ];
  661. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/FASTAImporter');
  662. //silent(function ($run_args, $landmark_file) {
  663. $importer = new \FASTAImporter();
  664. $importer->create($run_args, $landmark_file);
  665. $importer->prepareFiles();
  666. $importer->run();
  667. // });
  668. }
  669. }