Tripal v1.0 (6.x-1.0)
|
00001 <?php 00002 00014 function tripal_feature_drush_help($command) { 00015 switch ($command) { 00016 case 'drush:tripal-get_sequence': 00017 return dt('Prints sequences that match specified categories.'); 00018 } 00019 } 00020 00027 function tripal_feature_drush_command() { 00028 $items = array(); 00029 $items['tripal-get-sequence'] = array( 00030 'description' => dt('Prints sequences that match specified categories.'), 00031 'options' => array( 00032 'org' => dt('The organism\'s common name. If specified, features for this organism will be retrieved.'), 00033 'genus' => dt('The organism\'s genus. If specified, features for all organism with this genus will be retrieved.'), 00034 'species' => dt('The organism\'s species name. If specified, features for this all organism with this species will be retrieved.'), 00035 'analysis' => dt('The analysis name. If specified, features for this analysis will be retrieved.'), 00036 'type' => dt('The type of feature to retrieve (e.g. mRNA). All features that match this type will be retrieved.'), 00037 'name' => dt('The name of the feature to retrieve.'), 00038 'up' => dt('An integer value specifying the number of upstream bases to include.'), 00039 'down' => dt('An integer value specifying the number of downstream bases to incldue.'), 00040 'out' => dt('The output format. Valid options are "fasta_html", "fasta_txt" and raw.'), 00041 '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.'), 00042 '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'), 00043 '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).'), 00044 ), 00045 'examples' => array( 00046 'Standard example' => 'drush tripal-current-job', 00047 ), 00048 'aliases' => array('trp-get-seq'), 00049 ); 00050 $items['tripal-feature-sync'] = array( 00051 'description' => dt('Syncs an individual feature.'), 00052 'options' => array( 00053 'id' => dt('The feature ID of the feature to sync'), 00054 ), 00055 'examples' => array( 00056 'Standard example' => 'drush tripal-feature-sync --id=48273', 00057 ), 00058 'aliases' => array('trp-fsync'), 00059 ); 00060 return $items; 00061 } 00062 00068 function drush_tripal_feature_tripal_get_sequence() { 00069 00070 $org_commonname = drush_get_option('org'); 00071 $genus = drush_get_option('genus'); 00072 $species = drush_get_option('species'); 00073 $analysis_name = drush_get_option('analysis'); 00074 $type = drush_get_option('type'); 00075 $feature_name = drush_get_option('name'); 00076 $upstream = drush_get_option('up'); 00077 $downstream = drush_get_option('down'); 00078 $output_format = drush_get_option('out'); 00079 $derive_from_parent = drush_get_option('parent'); 00080 $aggregate = drush_get_option('agg'); 00081 $child = drush_get_option('child'); 00082 00083 $sub_features = explode(',', $child); 00084 00085 if (!$output_format) { 00086 $output_format = 'fasta_txt'; 00087 } 00088 00089 if (!$type and !$feature_name and !$org_commonname) { 00090 print "Please provide a type, feature name or organism common name\n"; 00091 return; 00092 } 00093 00094 // get the list of features 00095 $vars = array(); 00096 $sql = "SELECT DISTINCT F.feature_id, F.name, F.uniquename, O.genus, O.species, CVT.name as feature_type ". 00097 "FROM feature F ". 00098 " INNER JOIN organism O on O.organism_id = F.organism_id ". 00099 " INNER JOIN cvterm CVT on CVT.cvterm_id = F.type_id "; 00100 if ($analysis_name) { 00101 $sql .= " INNER JOIN analysisfeature AF on AF.feature_id = F.feature_id ". 00102 " INNER JOIN analysis A on AF.analysis_id = A.analysis_id "; 00103 } 00104 $sql .= "WHERE (1=1) "; 00105 if ($org_commonname) { 00106 $sql .= "AND O.common_name = '%s' "; 00107 $vars[] = $org_commonname; 00108 } 00109 if ($genus) { 00110 $sql .= "AND O.genus = '%s' "; 00111 $vars[] = $genus; 00112 } 00113 if ($species) { 00114 $sql .= "AND O.species = '%s' "; 00115 $vars[] = $species; 00116 } 00117 if ($type) { 00118 $sql .= "AND CVT.name = '%s' "; 00119 $vars[] = $type; 00120 } 00121 if ($feature_name) { 00122 $sql .= "AND F.name = '%s'"; 00123 $vars[] = $feature_name; 00124 } 00125 if ($analysis_name) { 00126 $sql .= "AND A.name = '%s'"; 00127 $vars[] = $analysis_name; 00128 } 00129 $num_bases_per_line = 50; 00130 $q = chado_query($sql, $vars); 00131 while ($feature = db_fetch_object($q)) { 00132 $feature_id = $feature->feature_id; 00133 $feature_name = "$feature->uniquename $feature->name $feature->feature_type ($feature->genus $feature->species)"; 00134 00135 $sequence = tripal_feature_get_formatted_sequence($feature_id, $feature_name, 00136 $num_bases_per_line, $derive_from_parent, $aggregate, $output_format, 00137 $upstream, $downstream, $sub_features); 00138 print $sequence; 00139 } 00140 } 00141 /* 00142 * 00143 */ 00144 function drush_tripal_feature_sync() { 00145 $feature_id = drush_get_option('id'); 00146 tripal_feature_sync_feature($feature_id); 00147 }