tripal_feature.drush.inc 3.9 KB

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