tripal_feature.drush.inc

  1. 2.x tripal_feature/tripal_feature.drush.inc
  2. 3.x legacy/tripal_feature/tripal_feature.drush.inc
  3. 1.x tripal_feature/tripal_feature.drush.inc

Contains function relating to drush-integration of this module.

File

tripal_feature/tripal_feature.drush.inc
View source
  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. * @ingroup tripal_drush
  13. */
  14. function tripal_feature_drush_help($command) {
  15. switch ($command) {
  16. case 'drush:tripal-get_sequence':
  17. return dt('Prints sequences that match specified categories.');
  18. }
  19. }
  20. /**
  21. * Registers a drush command and constructs the full help for that command
  22. *
  23. * @return
  24. * And array of command descriptions
  25. *
  26. * @ingroup tripal_drush
  27. */
  28. function tripal_feature_drush_command() {
  29. $items = array();
  30. $items['tripal-get-sequence'] = array(
  31. 'description' => dt('Prints sequences that match specified categories.'),
  32. 'options' => array(
  33. 'org' => dt('The organism\'s common name. If specified, features for this organism will be retrieved.'),
  34. 'genus' => dt('The organism\'s genus. If specified, features for all organism with this genus will be retrieved.'),
  35. 'species' => dt('The organism\'s species name. If specified, features for this all organism with this species will be retrieved.'),
  36. 'analysis' => dt('The analysis name. If specified, features for this analysis will be retrieved.'),
  37. 'type' => dt('The type of feature to retrieve (e.g. mRNA). All features that match this type will be retrieved.'),
  38. 'name' => dt('The name of the feature to retrieve.'),
  39. 'up' => dt('An integer value specifying the number of upstream bases to include.'),
  40. 'down' => dt('An integer value specifying the number of downstream bases to incldue.'),
  41. '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.'),
  42. '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'),
  43. 'child' => dt('Set this argument to the exact 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). Term matching is case-sensitive.'),
  44. 'relationship' => dt('Retreives the sequence of any feature in the specified relationship with the matched features.'),
  45. 'rel_part' => dt('If a relationship is provided, then this will be "subject" or "object" indicating the side of the relationship for the matched features. If the matched features are the "object" then the "subject" features will have their sequences included in the output (and vice versa).'),
  46. 'width' => dt('The number of nucleotides per row (defaults to 50).')
  47. ),
  48. 'examples' => array(
  49. 'Standard example' => 'drush tripal-current-job',
  50. ),
  51. 'aliases' => array('trp-get-seq'),
  52. );
  53. $items['tripal-feature-sync'] = array(
  54. 'description' => dt('Syncs an individual feature.'),
  55. 'options' => array(
  56. 'id' => dt('The feature ID of the feature to sync'),
  57. ),
  58. 'examples' => array(
  59. 'Standard example' => 'drush tripal-feature-sync --id=48273',
  60. ),
  61. 'aliases' => array('trp-fsync'),
  62. );
  63. return $items;
  64. }
  65. /**
  66. * Retrieves the sequence of the indicated features
  67. *
  68. * @ingroup tripal_drush
  69. */
  70. function drush_tripal_feature_tripal_get_sequence() {
  71. $org_commonname = drush_get_option('org');
  72. $genus = drush_get_option('genus');
  73. $species = drush_get_option('species');
  74. $analysis_name = drush_get_option('analysis');
  75. $type = drush_get_option('type');
  76. $feature_name = drush_get_option('name');
  77. $upstream = drush_get_option('up') ? drush_get_option('up') : 0;
  78. $downstream = drush_get_option('down') ? drush_get_option('down') : 0;
  79. $derive_from_parent = drush_get_option('parent');
  80. $aggregate = drush_get_option('agg');
  81. $child = drush_get_option('child');
  82. $relationship = drush_get_option('relationship');
  83. $rel_part = drush_get_option('rel_part');
  84. $width = drush_get_option('width') ? drush_get_option('width') : 50;
  85. if ($relationship and !$rel_part) {
  86. print "Please specify both 'relationship' and a 'rel_part' arguments. Both must be used together\n";
  87. return;
  88. }
  89. $options = array(
  90. 'org_commonname' => $org_commonname,
  91. 'genus' => $genus,
  92. 'species' => $species,
  93. 'analysis_name' => $analysis_name,
  94. 'type' => $type,
  95. 'feature_name' => $feature_name,
  96. 'upstream' => $upstream,
  97. 'downstream' => $downstream,
  98. 'derive_from_parent' => $derive_from_parent,
  99. 'aggregate' => $aggregate,
  100. 'sub_feature_types' => explode(',', $child),
  101. 'relationship_type' => $relationship,
  102. 'relationship_part' => $rel_part,
  103. 'width' => $width
  104. );
  105. $seqs = tripal_get_bulk_feature_sequences($options);
  106. if (count($seqs) == 0) {
  107. print "No sequences found that match the criteria.";
  108. }
  109. foreach ($seqs as $seq) {
  110. print ">" . $seq['defline'] . "\r\n";
  111. print $seq['residues'] . "\r\n";
  112. }
  113. }
  114. /**
  115. * Sync Chado Features with Drupal (ie: create nodes)
  116. *
  117. * @ingroup tripal_drush
  118. */
  119. function drush_tripal_feature_sync() {
  120. $feature_id = drush_get_option('id');
  121. tripal_feature_sync_feature($feature_id);
  122. }