Tripal v1.0 (6.x-1.0)
tripal_feature-delete.inc
Go to the documentation of this file.
00001 <?php
00007 function tripal_feature_delete_form() {
00008   // get the list of organisms
00009   $sql = "SELECT * FROM {organism} ORDER BY genus, species";
00010   $org_rset = chado_query($sql);
00011   $organisms = array();
00012   $organisms[''] = '';
00013   while ($organism = db_fetch_object($org_rset)) {
00014     $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
00015   }
00016   $form['desc'] = array(
00017     '#type' => 'markup',
00018     '#value' => t("Use one or more of the following fields to identify sets of features to be deleted."),
00019   );
00020 
00021   $form['feature_names']= array(
00022     '#type' => 'textarea',
00023     '#title' => t('Feature Names'),
00024     '#description' => t('Please provide a list of feature names or unique names,
00025        separated by spaces or by new lines to be delete. If you specify feature names then
00026        all other options below will be ignored (except the unique checkbox).'),
00027   );
00028   $form['is_unique'] = array(
00029     '#title' => t('Names are Unique Names'),
00030     '#type' => 'checkbox',
00031     '#description' => t('Select this checbox if the names listed in the feature
00032       names box above are the unique name of the feature rather than the human readable names.'),
00033   );
00034   $form['seq_type']= array(
00035     '#type' => 'textfield',
00036     '#title' => t('Sequence Type'),
00037     '#description' => t('Please enter the Sequence Ontology term that describes the features to be deleted. Use in conjunction with an organism or anaylysis.'),
00038   );
00039 
00040   $form['organism_id'] = array(
00041    '#title'       => t('Organism'),
00042    '#type'        => t('select'),
00043    '#description' => t("Choose the organism for which features will be deleted."),
00044    '#options'     => $organisms,
00045   );
00046 
00047 
00048   // get the list of analyses
00049   $sql = "SELECT * FROM {analysis} ORDER BY name";
00050   $org_rset = chado_query($sql);
00051   $analyses = array();
00052   $analyses[''] = '';
00053   while ($analysis = db_fetch_object($org_rset)) {
00054     $analyses[$analysis->analysis_id] = "$analysis->name ($analysis->program $analysis->programversion, $analysis->sourcename)";
00055   }
00056   //  TODO: ADD THIS BACK IN LATER
00057   //
00058   //   $form['analysis']['analysis_id'] = array (
00059   //     '#title'       => t('Analysis'),
00060   //     '#type'        => t('select'),
00061   //     '#description' => t("Choose the analysis for which associated features will be deleted."),
00062   //     '#options'     => $analyses,
00063   //   );
00064 
00065   $form['button'] = array(
00066     '#type' => 'submit',
00067     '#value' => t('Delete Features'),
00068   );
00069   return $form;
00070 }
00071 
00072 function tripal_feature_delete_form_validate($form, &$form_state) {
00073   $organism_id   = $form_state['values']['organism_id'];
00074   $seq_type      = trim($form_state['values']['seq_type']);
00075   $analysis_id   = $form_state['values']['analysis_id'];
00076   $is_unique     = $form_state['values']['is_unique'];
00077   $feature_names = $form_state['values']['feature_names'];
00078 
00079   if (!$organism_id and !$anaysis_id and !$seq_type and !$feature_names) {
00080     form_set_error('feature_names', t("Please select at least one option"));
00081   }
00082 
00083   // check to make sure the types exists
00084   if ($seq_type) {
00085     $cvtermsql = "SELECT CVT.cvterm_id
00086                   FROM {cvterm} CVT
00087                      INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
00088                      LEFT JOIN {cvtermsynonym} CVTS on CVTS.cvterm_id = CVT.cvterm_id
00089                   WHERE cv.name = '%s' and (CVT.name = '%s' or CVTS.synonym = '%s')";
00090     $cvterm = db_fetch_object(db_query($cvtermsql, 'sequence', $seq_type, $seq_type));
00091     if (!$cvterm) {
00092       form_set_error('seq_type', t("The Sequence Ontology (SO) term selected for the sequence type is not available in the database. Please check spelling or select another."));
00093     }
00094   }
00095 }
00096 
00097 function tripal_feature_delete_form_submit($form, &$form_state) {
00098   global $user;
00099 
00100   $organism_id   = $form_state['values']['organism_id'];
00101   $seq_type      = trim($form_state['values']['seq_type']);
00102   $analysis_id   = $form_state['values']['analysis_id'];
00103   $is_unique     = $form_state['values']['is_unique'];
00104   $feature_names = $form_state['values']['feature_names'];
00105 
00106   $args = array($organism_id, $analysis_id, $seq_type, $is_unique, $feature_names);
00107 
00108   tripal_add_job("Delete features", 'tripal_feature',
00109     'tripal_feature_delete_features', $args, $user->uid);
00110 }
00111 
00112 
00113 function tripal_feature_delete_features($organism_id, $analysis_id, $seq_type,
00114   $is_unique, $feature_names, $job = NULL) {
00115 
00116   global $user;
00117   $match = array();
00118 
00119   // if feature names have been provided then handle that separately
00120   if ($feature_names) {
00121     $names = preg_split('/\s+/', $feature_names);
00122     if (sizeof($names) == 1) {
00123       $names = $names[0];
00124     }
00125     if ($is_unique) {
00126       $match['uniquename'] = $names;
00127     }
00128     else {
00129       $match['name'] = $names;
00130     }
00131     $num_deletes = tripal_core_chado_select('feature', array('count(*) as cnt'), $match);
00132     print "Deleting " . $num_deletes[0]->cnt . " features\n";
00133     tripal_core_chado_delete('feature', $match);
00134   }
00135 
00136   // if the user has provided an analysis_id then handle that separately
00137   elseif ($analysis_id) {
00138     tripal_feature_delete_by_analysis();
00139   }
00140   else {
00141 
00142     if ($organism_id) {
00143       $match['organism_id'] = $organism_id;
00144     }
00145     if ($seq_type) {
00146       $match['type_id'] = array(
00147         'name' => $seq_type,
00148         'cv_id' => array(
00149           'name' => 'sequence'
00150         ),
00151       );
00152     }
00153     $num_deletes = tripal_core_chado_select('feature', array('count(*) as cnt'), $match);
00154     print "Deleting " . $num_deletes[0]->cnt . " features\n";
00155     tripal_core_chado_delete('feature', $match);
00156   }
00157 
00158   print "Removing orphaned feature pages\n";
00159   tripal_features_cleanup(array(), $user->uid);
00160 }
00161 
00162 function tripal_feature_delete_by_analysis($organism_id, $analysis_id, $seq_type,
00163   $is_unique, $feature_names, $job = NULL) {
00164 
00165 }
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00175 
 All Classes Files Functions Variables