tripal_feature.drush.inc 4.3 KB

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