tripal_feature.drush.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. 'type' => dt('The type of feature to retrieve (e.g. mRNA). All features that match this type will be retrieved.'),
  31. 'name' => dt('The name of the feature to retrieve.'),
  32. 'up' => dt('An integer value specifying the number of upstream bases to include.'),
  33. 'down' => dt('An integer value specifying the number of downstream bases to incldue.'),
  34. 'out' => dt('The output format. Valid options are "fasta_html", "fasta_txt" and raw.'),
  35. '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.'),
  36. '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'),
  37. ),
  38. 'examples' => array(
  39. 'Standard example' => 'drush tripal-current-job',
  40. ),
  41. 'aliases' => array('trp-get-seq'),
  42. );
  43. return $items;
  44. }
  45. /**
  46. * Executes jobs in the Tripal Jobs Queue
  47. *
  48. * NOTE: The following code is executed when drush 'trpjob-run' or 'drush tripal-launch-jobs' is called
  49. */
  50. function drush_tripal_feature_tripal_get_sequence() {
  51. $org_commonname = drush_get_option('org');
  52. $type = drush_get_option('type');
  53. $feature_name = drush_get_option('name');
  54. $upstream = drush_get_option('up');
  55. $downstream = drush_get_option('down');
  56. $output_format = drush_get_option('out');
  57. $derive_from_parent = drush_get_option('parent');
  58. $aggregate = drush_get_option('agg');
  59. if (!$output_format) {
  60. $output_format = 'fasta_txt';
  61. }
  62. if (!$type and !$feature_name and !$org_commonname) {
  63. print "Please provide a type, feature name or organism common name\n";
  64. return;
  65. }
  66. // get the list of features
  67. $vars = array();
  68. $sql = "SELECT DISTINCT F.feature_id, F.name ".
  69. "FROM feature F ".
  70. " INNER JOIN organism O on O.organism_id = F.organism_id ".
  71. " INNER JOIN cvterm CVT on CVT.cvterm_id = F.type_id ".
  72. "WHERE (1=1) ";
  73. if ($org_commonname) {
  74. $sql .= "AND O.common_name = '%s' ";
  75. $vars[] = $org_commonname;
  76. }
  77. if ($type) {
  78. $sql .= "AND CVT.name = '%s' ";
  79. $vars[] = $type;
  80. }
  81. if ($feature_name) {
  82. $sql .= "AND F.name = '%s'";
  83. $vars[] = $feature_name;
  84. }
  85. $num_bases_per_line = 50;
  86. $q = chado_query($sql, $vars);
  87. while ($feature = db_fetch_object($q)) {
  88. $feature_id = $feature->feature_id;
  89. $feature_name = $feature->name;
  90. $sequence = trpial_feature_get_formatted_sequence($feature_id, $feature_name,
  91. $num_bases_per_line, $derive_from_parent, $aggregate, $output_format,
  92. $upstream, $downstream);
  93. print $sequence;
  94. }
  95. }