GFF3ImporterTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace Tests;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. class GFF3ImporterTest extends TripalTestCase {
  6. // Uncomment to auto start and rollback db transactions per test method.
  7. use DBTransaction;
  8. /**
  9. * Confirm GFF loads.
  10. *
  11. * @group gff
  12. */
  13. public function testGFFImporter() {
  14. $gff_file = ['file_remote' => 'https://raw.githubusercontent.com/statonlab/tripal_dev_seed/master/Fexcel_mini/gff/filtered.gff'];
  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);
  36. $this->runGFFLoader($run_args, $gff_file);
  37. $name = 'FRAEX38873_v2_000000110.2.exon4';
  38. $query = db_select('chado.feature', 'f')
  39. ->fields('f', ['uniquename'])
  40. ->condition('f.uniquename', $name)
  41. ->execute()
  42. ->fetchField();
  43. $this->assertEquals($name, $query);
  44. }
  45. /**
  46. * @group gff
  47. * @ticket 77
  48. *
  49. */
  50. public function testGFFNoProteinOption() {
  51. $gff_file = ['file_remote' => 'https://raw.githubusercontent.com/statonlab/tripal_dev_seed/master/Fexcel_mini/gff/filtered.gff'];
  52. $analysis = factory('chado.analysis')->create();
  53. $organism = factory('chado.organism')->create();
  54. $run_args = [
  55. //The new argument
  56. 'skip_protein' => 1,
  57. ///
  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->runGFFLoader($run_args, $gff_file);
  77. $identifier = [
  78. 'cv_id' => ['name' => 'sequence'],
  79. 'name' => 'polypeptide',
  80. ];
  81. $protein_type_id = tripal_get_cvterm($identifier);
  82. //This works i think i just dont have proteins described in the GFF.
  83. $name = 'FRAEX38873_v2_000000110.1-protein';
  84. $query = db_select('chado.feature', 'f')
  85. ->fields('f', ['uniquename'])
  86. ->condition('f.uniquename', $name)
  87. ->condition('f.type_id', $protein_type_id->cvterm_id)
  88. ->execute()
  89. ->fetchField();
  90. $this->assertFalse($query);
  91. $run_args['skip_protein'] = 0;
  92. $this->runGFFLoader($run_args, $gff_file);
  93. $query = db_select('chado.feature', 'f')
  94. ->fields('f', ['uniquename'])
  95. ->condition('f.uniquename', $name)
  96. ->condition('f.type_id', $protein_type_id->cvterm_id)
  97. ->execute()
  98. ->fetchObject();
  99. $this->assertEquals($name, $query->uniquename);
  100. }
  101. private function runGFFLoader($run_args, $file) {
  102. // silent(function ($run_args, $file) {
  103. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/GFF3Importer');
  104. $importer = new \GFF3Importer();
  105. $importer->create($run_args, $file);
  106. $importer->prepareFiles();
  107. $importer->run();
  108. // });
  109. }
  110. private function loadLandmarks($analysis, $organism) {
  111. $landmark_file = ['file_remote' => 'https://raw.githubusercontent.com/statonlab/tripal_dev_seed/master/Fexcel_mini/sequences/empty_landmarks.fasta'];
  112. $run_args = [
  113. 'organism_id' => $organism->organism_id,
  114. 'analysis_id' => $analysis->analysis_id,
  115. 'seqtype' => 'scaffold',
  116. 'method' => 2, //default insert and update
  117. 'match_type' => 1, //unique name default
  118. //optional
  119. 're_name' => NULL,
  120. 're_uname' => NULL,
  121. 're_accession' => NULL,
  122. 'db_id' => NULL,
  123. 'rel_type' => NULL,
  124. 're_subject' => NULL,
  125. 'parent_type' => NULL,
  126. ];
  127. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/FASTAImporter');
  128. //silent(function ($run_args, $landmark_file) {
  129. $importer = new \FASTAImporter();
  130. $importer->create($run_args, $landmark_file);
  131. $importer->prepareFiles();
  132. $importer->run();
  133. // });
  134. }
  135. }