tripal_feature.drush.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * @file
  4. * Contains function relating to drush-integration of this module.
  5. */
  6. /**
  7. * Describes each drush command implemented by the module
  8. *
  9. * @return
  10. * The first line of description when executing the help for a given command
  11. */
  12. function tripal_feature_drush_help($command) {
  13. switch ($command) {
  14. case 'drush:tripal-get_sequence':
  15. return dt('Prints sequences that match specified categories.');
  16. }
  17. }
  18. /**
  19. * Registers a drush command and constructs the full help for that command
  20. *
  21. * @return
  22. * And array of command descriptions
  23. */
  24. function tripal_feature_drush_command() {
  25. $items = array();
  26. $items['tripal-get-sequence'] = array(
  27. 'description' => dt('Prints sequences that match specified categories.'),
  28. 'options' => array(
  29. 'org' => dt('The organism\'s common name. If specified, features for this organism will be retrieved.'),
  30. 'genus' => dt('The organism\'s genus. If specified, features for all organism with this genus will be retrieved.'),
  31. 'species' => dt('The organism\'s species name. If specified, features for this all organism with this species will be retrieved.'),
  32. 'analysis' => dt('The analysis name. If specified, features for this analysis will be retrieved.'),
  33. 'type' => dt('The type of feature to retrieve (e.g. mRNA). All features that match this type will be retrieved.'),
  34. 'name' => dt('The name of the feature to retrieve.'),
  35. 'up' => dt('An integer value specifying the number of upstream bases to include.'),
  36. 'down' => dt('An integer value specifying the number of downstream bases to incldue.'),
  37. 'out' => dt('The output format. Valid options are "fasta_html", "fasta_txt" and raw.'),
  38. 'parent' => dt('Set this argument to 1 to retrieve the sequence from the parent in an alignment rather than the residues column of the feature itself.'),
  39. 'agg' => dt('Set this argument to 1 to aggregate sub features into a single sequence. This is useful, for example, for obtaining CDS sequence from an mRNA'),
  40. 'child' => dt('Set this argument to the sequence ontology term for the children to aggregate. This is useful in the case where a gene has exons as well as CDSs and UTRs. You may sepcify as many feature types as desired by separating each with a single comma (no spaces).'),
  41. ),
  42. 'examples' => array(
  43. 'Standard example' => 'drush tripal-current-job',
  44. ),
  45. 'aliases' => array('trp-get-seq'),
  46. );
  47. $items['tripal-feature-sync'] = array(
  48. 'description' => dt('Syncs an individual feature.'),
  49. 'options' => array(
  50. 'id' => dt('The feature ID of the feature to sync'),
  51. ),
  52. 'examples' => array(
  53. 'Standard example' => 'drush tripal-feature-sync --id=48273',
  54. ),
  55. 'aliases' => array('trp-fsync'),
  56. );
  57. return $items;
  58. }
  59. /**
  60. * Executes jobs in the Tripal Jobs Queue
  61. *
  62. * NOTE: The following code is executed when drush 'trpjob-run' or 'drush tripal-launch-jobs' is called
  63. */
  64. function drush_tripal_feature_tripal_get_sequence() {
  65. $org_commonname = drush_get_option('org');
  66. $genus = drush_get_option('genus');
  67. $species = drush_get_option('species');
  68. $analysis_name = drush_get_option('analysis');
  69. $type = drush_get_option('type');
  70. $feature_name = drush_get_option('name');
  71. $upstream = drush_get_option('up');
  72. $downstream = drush_get_option('down');
  73. $output_format = drush_get_option('out');
  74. $derive_from_parent = drush_get_option('parent');
  75. $aggregate = drush_get_option('agg');
  76. $child = drush_get_option('child');
  77. $sub_features = explode(',', $child);
  78. if (!$output_format) {
  79. $output_format = 'fasta_txt';
  80. }
  81. if (!$type and !$feature_name and !$org_commonname) {
  82. print "Please provide a type, feature name or organism common name\n";
  83. return;
  84. }
  85. // get the list of features
  86. $vars = array();
  87. $sql = "SELECT DISTINCT F.feature_id, F.name, F.uniquename, O.genus, O.species, CVT.name as feature_type ".
  88. "FROM feature F ".
  89. " INNER JOIN organism O on O.organism_id = F.organism_id ".
  90. " INNER JOIN cvterm CVT on CVT.cvterm_id = F.type_id ";
  91. if ($analysis_name) {
  92. $sql .= " INNER JOIN analysisfeature AF on AF.feature_id = F.feature_id ".
  93. " INNER JOIN analysis A on AF.analysis_id = A.analysis_id ";
  94. }
  95. $sql .= "WHERE (1=1) ";
  96. if ($org_commonname) {
  97. $sql .= "AND O.common_name = '%s' ";
  98. $vars[] = $org_commonname;
  99. }
  100. if ($genus) {
  101. $sql .= "AND O.genus = '%s' ";
  102. $vars[] = $genus;
  103. }
  104. if ($species) {
  105. $sql .= "AND O.species = '%s' ";
  106. $vars[] = $species;
  107. }
  108. if ($type) {
  109. $sql .= "AND CVT.name = '%s' ";
  110. $vars[] = $type;
  111. }
  112. if ($feature_name) {
  113. $sql .= "AND F.name = '%s'";
  114. $vars[] = $feature_name;
  115. }
  116. if ($analysis_name) {
  117. $sql .= "AND A.name = '%s'";
  118. $vars[] = $analysis_name;
  119. }
  120. $num_bases_per_line = 50;
  121. $q = chado_query($sql, $vars);
  122. while ($feature = db_fetch_object($q)) {
  123. $feature_id = $feature->feature_id;
  124. $feature_name = "$feature->uniquename $feature->name $feature->feature_type ($feature->genus $feature->species)";
  125. $sequence = tripal_feature_get_formatted_sequence($feature_id, $feature_name,
  126. $num_bases_per_line, $derive_from_parent, $aggregate, $output_format,
  127. $upstream, $downstream, $sub_features);
  128. print $sequence;
  129. }
  130. }
  131. /*
  132. *
  133. */
  134. function drush_tripal_feature_sync() {
  135. $feature_id = drush_get_option('id');
  136. tripal_feature_sync_feature($feature_id);
  137. }