|
@@ -3,6 +3,33 @@
|
|
|
*
|
|
|
*/
|
|
|
function tripal_feature_seq_extract_page() {
|
|
|
+ if ($_SESSION['tripal_feature_seq_extract']){
|
|
|
+ $genus = $_SESSION['tripal_feature_seq_extract']['genus'];
|
|
|
+ $species = $_SESSION['tripal_feature_seq_extract']['species'];
|
|
|
+ $analysis = $_SESSION['tripal_feature_seq_extract']['analysis'];
|
|
|
+ $ftypes = $_SESSION['tripal_feature_seq_extract']['ftypes'];
|
|
|
+ $fname = $_SESSION['tripal_feature_seq_extract']['fname'];
|
|
|
+ $upstream = $_SESSION['tripal_feature_seq_extract']['upstream'];
|
|
|
+ $downstream = $_SESSION['tripal_feature_seq_extract']['downstream'];
|
|
|
+ $format = $_SESSION['tripal_feature_seq_extract']['format'];
|
|
|
+ $use_parent = $_SESSION['tripal_feature_seq_extract']['use_parent'];
|
|
|
+ $aggregate = $_SESSION['tripal_feature_seq_extract']['aggregate'];
|
|
|
+ $agg_types = $_SESSION['tripal_feature_seq_extract']['agg_types'];
|
|
|
+
|
|
|
+ if ($format == 'fasta_html') {
|
|
|
+ drupal_set_header('Content-Type: text/html');
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ drupal_set_header('Content-Type: text/plain');
|
|
|
+ }
|
|
|
+ tripal_feature_seq_extract_get_features(NULL, $genus, $species, $analysis,
|
|
|
+ $ftypes, $fname, $upstream, $downstream, $format, $use_parent, $aggregate, $agg_types);
|
|
|
+
|
|
|
+ unset($_SESSION['tripal_feature_seq_extract']);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// generate the search form
|
|
|
$output .= '';
|
|
|
if (user_access('access administration pages')) {
|
|
@@ -77,7 +104,7 @@ function tripal_feature_seq_extract_form(&$form_state = NULL) {
|
|
|
$ddownstream = $form_state['values']['downstream'];
|
|
|
$dformat = $form_state['values']['format'] ? $form_state['values']['format'] : 'fasta_txt';
|
|
|
$duse_parent = $form_state['values']['use_parent'];
|
|
|
- $aggregate = $form_state['values']['aggregate'];
|
|
|
+ $daggregate = $form_state['values']['aggregate'];
|
|
|
$dagg_types = $form_state['values']['agg_types'];
|
|
|
|
|
|
$sql = "
|
|
@@ -331,3 +358,121 @@ function tripal_feature_seq_extract_set_source() {
|
|
|
)
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+function tripal_feature_seq_extract_form_validate($form, &$form_state) {
|
|
|
+ $genus = $form_state['values']['genus'];
|
|
|
+ $species = $form_state['values']['species'];
|
|
|
+ $analysis = $form_state['values']['analysis'];
|
|
|
+ $ftypes = $form_state['values']['ftypes'];
|
|
|
+ $fname = $form_state['values']['fname'];
|
|
|
+ $upstream = $form_state['values']['upstream'];
|
|
|
+ $downstream = $form_state['values']['downstream'];
|
|
|
+ $format = $form_state['values']['format'];
|
|
|
+ $use_parent = $form_state['values']['use_parent'];
|
|
|
+ $aggregate = $form_state['values']['aggregate'];
|
|
|
+ $agg_types = $form_state['values']['agg_types'];
|
|
|
+
|
|
|
+ if ($upstream and !preg_match('/^\d+$/', $upstream)) {
|
|
|
+ form_set_error('upstream', 'Please enter a positive numeric value for the upstream bases');
|
|
|
+ }
|
|
|
+ if ($downstream and !preg_match('/^\d+$/', $downstream)) {
|
|
|
+ form_set_error('downstream', 'Please enter a positive numeric value for the downstream bases');
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+function tripal_feature_seq_extract_form_submit($form, &$form_state) {
|
|
|
+ $genus = $form_state['values']['genus'];
|
|
|
+ $species = $form_state['values']['species'];
|
|
|
+ $analysis = $form_state['values']['analysis'];
|
|
|
+ $ftypes = $form_state['values']['ftypes'];
|
|
|
+ $fname = $form_state['values']['fname'];
|
|
|
+ $upstream = $form_state['values']['upstream'];
|
|
|
+ $downstream = $form_state['values']['downstream'];
|
|
|
+ $format = $form_state['values']['format'];
|
|
|
+ $use_parent = $form_state['values']['use_parent'];
|
|
|
+ $aggregate = $form_state['values']['aggregate'];
|
|
|
+ $agg_types = $form_state['values']['agg_types'];
|
|
|
+
|
|
|
+ $_SESSION['tripal_feature_seq_extract']['genus'] = $genus;
|
|
|
+ $_SESSION['tripal_feature_seq_extract']['species'] = $species;
|
|
|
+ $_SESSION['tripal_feature_seq_extract']['analysis'] = $analysis;
|
|
|
+ $_SESSION['tripal_feature_seq_extract']['ftypes'] = $ftypes;
|
|
|
+ $_SESSION['tripal_feature_seq_extract']['fname'] = $fname;
|
|
|
+ $_SESSION['tripal_feature_seq_extract']['upstream'] = $upstream;
|
|
|
+ $_SESSION['tripal_feature_seq_extract']['downstream'] = $downstream;
|
|
|
+ $_SESSION['tripal_feature_seq_extract']['format'] = $format;
|
|
|
+ $_SESSION['tripal_feature_seq_extract']['use_parent'] = $use_parent;
|
|
|
+ $_SESSION['tripal_feature_seq_extract']['aggregate'] = $aggregate;
|
|
|
+ $_SESSION['tripal_feature_seq_extract']['agg_types'] = $agg_types;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ *
|
|
|
+ */
|
|
|
+function tripal_feature_seq_extract_get_features($org_commonname, $genus, $species, $analysis_name,
|
|
|
+ $type, $feature_name, $upstream, $downstream, $output_format, $derive_from_parent, $aggregate, $child) {
|
|
|
+
|
|
|
+ $sub_features = explode(',', $child);
|
|
|
+
|
|
|
+ if (!$output_format) {
|
|
|
+ $output_format = 'fasta_txt';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$type and !$feature_name and !$org_commonname) {
|
|
|
+ print "Please provide a type, feature name or organism common name\n";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // get the list of features
|
|
|
+ $vars = array();
|
|
|
+ $sql = "SELECT DISTINCT F.feature_id, F.name, F.uniquename, O.genus, O.species, CVT.name as feature_type ".
|
|
|
+ "FROM {feature} F ".
|
|
|
+ " INNER JOIN {organism} O on O.organism_id = F.organism_id ".
|
|
|
+ " INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id ";
|
|
|
+ if ($analysis_name) {
|
|
|
+ $sql .= " INNER JOIN {analysisfeature} AF on AF.feature_id = F.feature_id ".
|
|
|
+ " INNER JOIN {analysis} A on AF.analysis_id = A.analysis_id ";
|
|
|
+ }
|
|
|
+ $sql .= "WHERE (1=1) ";
|
|
|
+ if ($org_commonname) {
|
|
|
+ $sql .= "AND O.common_name = '%s' ";
|
|
|
+ $vars[] = $org_commonname;
|
|
|
+ }
|
|
|
+ if ($genus) {
|
|
|
+ $sql .= "AND O.genus = '%s' ";
|
|
|
+ $vars[] = $genus;
|
|
|
+ }
|
|
|
+ if ($species) {
|
|
|
+ $sql .= "AND O.species = '%s' ";
|
|
|
+ $vars[] = $species;
|
|
|
+ }
|
|
|
+ if ($type) {
|
|
|
+ $sql .= "AND CVT.name = '%s' ";
|
|
|
+ $vars[] = $type;
|
|
|
+ }
|
|
|
+ if ($feature_name) {
|
|
|
+ $sql .= "AND F.name = '%s'";
|
|
|
+ $vars[] = $feature_name;
|
|
|
+ }
|
|
|
+ if ($analysis_name) {
|
|
|
+ $sql .= "AND A.name = '%s'";
|
|
|
+ $vars[] = $analysis_name;
|
|
|
+ }
|
|
|
+ $num_bases_per_line = 50;
|
|
|
+ $q = chado_query($sql, $vars);
|
|
|
+ while ($feature = db_fetch_object($q)) {
|
|
|
+ $feature_id = $feature->feature_id;
|
|
|
+ $feature_name = "$feature->uniquename $feature->name $feature->feature_type ($feature->genus $feature->species)";
|
|
|
+
|
|
|
+ $sequence = tripal_feature_get_formatted_sequence($feature_id, $feature_name,
|
|
|
+ $num_bases_per_line, $derive_from_parent, $aggregate, $output_format,
|
|
|
+ $upstream, $downstream, $sub_features);
|
|
|
+ print $sequence;
|
|
|
+ }
|
|
|
+}
|