فهرست منبع

Fixed merge conflict

Ficklin 10 سال پیش
والد
کامیت
f3f17b6ec1

+ 339 - 0
LICENSE.txt

@@ -0,0 +1,339 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                            NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.

+ 2 - 2
tripal_analysis/tripal_analysis.install

@@ -56,7 +56,7 @@ function tripal_analysis_add_cvterms(){
   // change change this property
   $term = array(
     'name' => 'analysis_type', 
-    'def' => 'The type of analysis was performed. This value is automatically set by '.
+    'def' => 'The type of analysis that was performed. This value is automatically set by '.
              'each Tripal Analysis module and should be equal to the module name '.
              '(e.g. tripal_analysis_blast, tripal_analysis_go).'
   );
@@ -83,7 +83,7 @@ function tripal_analysis_add_cvterms(){
   // an analysis_type term in the 'tripal_analysis' vocabular we duplicate it here because the 
   // tripal_analysis vocabulary is intended for use by the extension modules.  user's should not be able
   // to directly modify properties set by extension modules for an analysis.
-  tripal_cv_add_cvterm(array('name' => 'Analysis Type','def' => 'The type of analysis was performed.'), 
+  tripal_cv_add_cvterm(array('name' => 'Analysis Type','def' => 'The type of analysis that was performed.'), 
      'analysis_property', 0, 1, 'tripal');
 }
 /**

+ 4 - 4
tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc

@@ -17,9 +17,9 @@
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_modify_template_base_form($form_state = NULL, $mode) {
+function tripal_bulk_loader_modify_template_base_form(&$form_state = NULL, $mode) {
   $form = array();
-
+  
    // get template id from path and rebuild form
   if ($_GET['template_id']) {
     if (preg_match('/^\d+$/', $_GET['template_id'])) {
@@ -570,7 +570,7 @@ function tripal_bulk_loader_delete_template_base_form_submit($form, &$form_state
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_import_export_template_form($form_state = NULL, $mode) {
+function tripal_bulk_loader_import_export_template_form(&$form_state = NULL, $mode) {
   $form = array();
 
   $form['mode'] = array(
@@ -687,6 +687,7 @@ function tripal_bulk_loader_import_export_template_form_submit($form, &$form_sta
 function tripal_bulk_loader_edit_template_record_form(&$form_state = NULL) {
   $form['#cache'] = TRUE; // Make sure the form is cached.
 
+
    // get template id from path
   $template_id = ($_GET['template_id'] !== NULL) ? $_GET['template_id'] : $form_state['values']['template_id'];
 
@@ -1595,7 +1596,6 @@ function tripal_bulk_loader_add_template_field_form_validate($form, $form_state)
       form_set_error('record_name', "New Record Name must be unique. '" . $form_state['values']['record_name'] . "' is not unique.");
     }
   }
-
 }
 
 /**

+ 3 - 3
tripal_contact/tripal_contact.module

@@ -547,12 +547,12 @@ function tripal_contact_preprocess_tripal_contact_relationships(&$variables) {
   $contact = $variables['node']->contact;
 
   // normally we would use tripal_core_expand_chado_vars to expand our
-  // organism object and add in the relationships, however whan a large
+  // contact object and add in the relationships, however whan a large
   // number of relationships are present this significantly slows the
   // query, therefore we will manually perform the query
   $sql = "
     SELECT C.name, C.contact_id, CP.nid, CVT.name as rel_type
-    FROM contact_relationship PR
+    FROM {contact_relationship} PR
       INNER JOIN {contact} C              ON PR.object_id  = C.contact_id
       INNER JOIN {cvterm} CVT             ON PR.type_id    = CVT.cvterm_id
       LEFT  JOIN public.chado_contact CP  ON C.contact_id  = CP.contact_id
@@ -561,7 +561,7 @@ function tripal_contact_preprocess_tripal_contact_relationships(&$variables) {
   $as_subject = chado_query($sql, $contact->contact_id);
   $sql = "
     SELECT C.name, C.contact_id, CP.nid, CVT.name as rel_type
-    FROM contact_relationship PR
+    FROM {contact_relationship} PR
       INNER JOIN {contact} C              ON PR.subject_id = C.contact_id
       INNER JOIN {cvterm} CVT             ON PR.type_id    = CVT.cvterm_id
       LEFT  JOIN public.chado_contact CP  ON C.contact_id  = CP.contact_id

+ 37 - 8
tripal_cv/includes/obo_loader.inc

@@ -313,13 +313,37 @@ function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
   // parse the obo file
   $default_db = tripal_cv_obo_parse($file, $header, $jobid);
 
-  // add the CV for this ontology to the database
-  $defaultcv = tripal_cv_add_cv($header['default-namespace'][0], '');
-  if (!$defaultcv) {
-    tripal_cv_obo_quiterror('Cannot add namespace ' . $header['default-namespace'][0]);
+  // add the CV for this ontology to the database.  The v1.2 definition
+  // specifies a 'default-namespace' to be used if a 'namespace' is not
+  // present for each stanza.  Some ontologies have adopted the v1.4 method
+  // in their v1.2 files and not including it.
+  if (array_key_exists('default-namespace', $header)) {
+    $defaultcv = tripal_cv_add_cv($header['default-namespace'][0], '');
+    if (!$defaultcv) {
+      tripal_cv_obo_quiterror('Cannot add namespace ' . $header['default-namespace'][0]);
+    }
+    $newcvs[$header['default-namespace'][0]] = $defaultcv->cv_id;
   }
-  $newcvs[$header['default-namespace'][0]] = $defaultcv->cv_id;
-
+  // if the 'default-namespace' is missing
+  else {
+    
+    // look to see if an 'ontology' key is present.  It is part of the v1.4 
+    // specification so it shouldn't be in the file, but just in case
+    if (array_key_exists('ontology', $header)) {
+      $defaultcv = tripal_cv_add_cv(strtoupper($header['ontology'][0]), '');
+      if (!$defaultcv) {
+        tripal_cv_obo_quiterror('Cannot add namespace ' . strtoupper($header['ontology'][0]));
+      }
+      $newcvs[strtoupper(strtoupper($header['ontology'][0]))] = $defaultcv->cv_id;
+    }
+    else {
+      $defaultcv = tripal_cv_add_cv('_global', '');
+      $newcvs['_global'] = $defaultcv->cv_id;
+    }
+    watchdog('t_obo_loader', "This OBO is missing the 'default-namespace' header. It is not possible to determine which vocabulary terms without a 'namespace' key should go.  Instead, those terms will be placed in the '%vocab' vocabulary.", 
+      array('%vocab' => $defaultcv->name), WATCHDOG_WARNING);
+  }
+  
   // add any typedefs to the vocabulary first
   print "\nStep 2: Loading type defs...\n"; 
   tripal_cv_obo_load_typedefs($defaultcv, $newcvs, $default_db, $jobid);
@@ -465,7 +489,12 @@ function tripal_cv_obo_process_terms($defaultcv, $jobid = NULL, &$newcvs, $defau
  * @ingroup tripal_obo_loader
  */
 function tripal_cv_obo_process_term($term, $defaultcv, $is_relationship = 0, &$newcvs, $default_db) {
- 
+
+  // make sure we have a namespace for this term
+  if (!array_key_exists('namespace', $term) and !($defaultcv or $defaultcv == '')) {
+    tripal_cv_obo_quiterror("Cannot add the term: no namespace defined. " . $term['id'][0]);
+  }
+  
   // construct the term array for sending to the tripal_cv_add_cvterm function
   // for adding a new cvterm
   $t = array(); 
@@ -482,7 +511,7 @@ function tripal_cv_obo_process_term($term, $defaultcv, $is_relationship = 0, &$n
   }
   if (array_key_exists('is_obsolete', $term)) {
     $t['is_obsolete'] = $term['is_obsolete'][0];
-  } 
+  }
   
   // add the cvterm
   $cvterm = tripal_cv_add_cvterm($t, $defaultcv, $is_relationship, 1, $default_db); 

+ 1 - 0
tripal_feature/api/tripal_feature.api.inc

@@ -702,6 +702,7 @@ function tripal_feature_get_formatted_sequence($feature_id, $feature_name,
           // included then continue if this child is not one of those allowed
           // subfeatures
           if (count($sub_features) > 0 and !in_array($child->type_name, $sub_features)) {
+             $i++;
              continue;
           }
         

+ 33 - 13
tripal_feature/includes/gff_loader.inc

@@ -306,7 +306,7 @@ function tripal_feature_gff3_load_form_submit($form, &$form_state) {
  * @ingroup gff3_loader
  */
 function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, 
-  $add_only = 0, $update = 0, $refresh = 0, $remove = 0, $use_transaction = 1, 
+  $add_only = 0, $update = 1, $refresh = 0, $remove = 0, $use_transaction = 1, 
   $target_organism_id = NULL, $target_type = NULL,  $create_target = 0, 
   $start_line = 1, $landmark_type = '', $alt_id_attr = '', $create_organism = FALSE, 
   $job = NULL) {     
@@ -930,29 +930,49 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
  */
 function tripal_feature_load_gff3_derives_from($feature, $subject, $organism) {
 
-  // get the subject type
+  // get the subject. If the subject is not in the tripal_gff_temp table
+  // then look for the subject in the feature table using the unique name.
+  // if it is not unique then we can provide an error
   $values = array(
     'organism_id' => $organism->organism_id,
     'uniquename' => $subject,
   );
   $options = array('statement_name' => 'sel_tripalgfftemp_orun');
-  $result = tripal_core_chado_select('tripal_gff_temp', array('type_name'), $values, $options);   
-  if (count($result) == 0) {
-    watchdog("T_gff3_loader", "Cannot find subject type for feature in 'derives_from' relationship: %subject", array('%subject' => $subject), WATCHDOG_WARNING);
-     return ''; 
+  $result = tripal_core_chado_select('tripal_gff_temp', array('type_name'), $values, $options);
+  $type_id = array();
+  if (count($result) > 0) {
+    $type_id = array(
+      'name' => $result[0]->type_name,
+      'cv_id' => array(
+        'name' => 'sequence'
+      ),
+    );
+  }
+  
+  // if we don't have a subject type then look for the feature in the feature table
+  if (empty($type_id)) {
+    $options = array('statement_name' => 'sel_feature_orun');
+    $result = tripal_core_chado_select('feature', array('type_id'), $values, $options);
+    if (count($result) > 1) {
+      watchdog("T_gff3_loader", "Cannot find subject type for feature,'%subject' , in 'derives_from' relationship. Multiple matching features exist with this uniquename.", 
+        array('%subject' => $subject), WATCHDOG_WARNING);
+      return '';
+    }
+    else if (count($result) == 0) {
+      watchdog("T_gff3_loader", "Cannot find subject type for feature,'%subject' , in 'derives_from' relationship.",
+        array('%subject' => $subject), WATCHDOG_WARNING);
+      return '';
+    }
+    else {
+      $type_id = $result->type_id;
+    }
   }
-  $subject_type = $result[0]->type_name;
   
   // get the subject feature
   $match = array(
     'organism_id' => $organism->organism_id,
     'uniquename' => $subject,
-    'type_id' => array(
-      'name' => $subject_type,
-      'cv_id' => array(
-        'name' => 'sequence'
-      ),
-    ),      
+    'type_id' => $type_id,
   );
   $options = array('statement_name' => 'sel_feature_orunty');
   $sfeature = tripal_core_chado_select('feature', array('feature_id'), $match, $options);

+ 34 - 34
tripal_feature/tripal_feature.module

@@ -133,9 +133,9 @@ function tripal_feature_perm() {
  *  @return
  *  If the permission for the specified operation is not set then return FALSE. If the
  *  permission is set then return NULL as this allows other modules to disable
- *  access.  The only exception is when the $op == 'create'.  We will always
+ *  access.  The only exception is when the $op == 'create'.  We will always 
  *  return TRUE if the permission is set.
- *
+ *  
  * @ingroup tripal_feature
  */
 function chado_feature_access($op, $node, $account) {
@@ -181,14 +181,14 @@ function tripal_feature_menu() {
     'access arguments' => array('access chado_feature content'),
     'type' => MENU_CALLBACK,
   );
-
+  
   $items['find/sequences/ajax'] = array(
     'title' => 'Sequence Retrieval',
     'page callback' => 'tripal_feature_seq_extract_form_ahah_update',
     'access arguments' => array('access chado_feature content'),
     'type' => MENU_CALLBACK,
   );
-
+  
   // the administative settings menu
   $items['admin/tripal/tripal_feature'] = array(
     'title' => 'Features',
@@ -331,7 +331,7 @@ function tripal_feature_theme() {
       'arguments' =>  array(NULL),
       'path' => drupal_get_path('module', 'tripal_feature') . '/theme'
     ),
-
+    
     // themed forms
     'tripal_feature_seq_extract_form' => array(
        'arguments' => array('form'),
@@ -500,7 +500,7 @@ function chado_feature_insert($node) {
     'type_id' => $type[0]->cvterm_id,
   );
   $feature = tripal_core_chado_select('feature', array('feature_id'), $values);
-
+    
   // add the genbank accession and synonyms
   chado_feature_add_synonyms($node->synonyms, $feature[0]->feature_id);
 
@@ -561,7 +561,7 @@ function chado_feature_update($node) {
     );
     $options = array('return_record' => TRUE);
     $status = tripal_core_chado_update('feature', $match, $values, $options);
-
+    
     // add the genbank synonyms
     chado_feature_add_synonyms($node->synonyms, $feature_id);
   }
@@ -573,7 +573,7 @@ function chado_feature_update($node) {
     WATCHDOG_WARNING
     );
   }
-
+  
 
 }
 /**
@@ -830,8 +830,8 @@ function chado_feature_form($node, $param) {
 
   // get the sequence ontology CV ID
   $values = array('name' => 'sequence');
-  $cv = tripal_core_chado_select('cv', array('cv_id'), $values);
-  $cv_id = $cv[0]->cv_id;
+  $cv = tripal_core_chado_select('cv', array('cv_id'), $values); 
+  $cv_id = $cv[0]->cv_id; 
 
   $form['feature_type'] = array(
    '#title'       => t('Feature Type'),
@@ -906,11 +906,11 @@ function chado_feature_form($node, $param) {
  */
 function chado_feature_validate($node) {
   $result = 0;
-
+  
   // make sure the feature type is a real sequence ontology term
   $type = tripal_cv_get_cvterm_by_name($node->feature_type, NULL, 'sequence');
   if (!$type) {
-     form_set_error('feature_type', t("The feature type is not a valid name from the Sequence Ontology."));
+     form_set_error('feature_type', t("The feature type is not a valid name from the Sequence Ontology."));	
   }
 
   // if this is an update, we want to make sure that a different feature for
@@ -969,10 +969,10 @@ function chado_feature_load($node) {
     if (strcmp($feature->name, $feature->uniquename)==0) {
       $node->title = $feature->name . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
     }
-    // in previous version of Tripal, the feature title was simply the unique name.
+    // in previous version of Tripal, the feature title was simply the unique name. 
     // so, we recreate the title just to be sure all of our feature pages are consistent
     else {
-      $node->title = $feature->name . ", " . $feature->uniquename . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
+      $node->title = $feature->name . ", " . $feature->uniquename . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;  
     }
   }
   // set the title to be the feature name or uniquename as configured
@@ -980,7 +980,7 @@ function chado_feature_load($node) {
     $node->title = $feature->name;
   }
   if($title_type == 'feature_unique_name') {
-    $node->title = $feature->uniquename;
+    $node->title = $feature->uniquename;  
   }
 
   $additions = new stdClass();
@@ -1839,23 +1839,23 @@ function chado_feature_view($node, $teaser = FALSE, $page = FALSE) {
  * @ingroup tripal_feature
  */
 function tripal_feature_nodeapi(&$node, $op, $teaser, $page) {
-
+  
   switch ($op) {
-
+    
      // set the title to ensure it is always unique
     case 'presave':
       switch ($node->type) {
         case 'chado_feature':
-
+          
           $values = array('organism_id' => $node->organism_id);
           $organism = tripal_core_chado_select('organism', array('genus','species'), $values);
           $node->title = $node->fname . ', ' . $node->uniquename . ' (' . $node->feature_type . ') ' . $organism[0]->genus . ' ' . $organism[0]->species;
           break;
       }
       break;
-
-    // set the URL path after inserting.  We do it here because we do not
-    // know the feature_id in the presave
+      
+    // set the URL path after inserting.  We do it here because we do not 
+    // know the feature_id in the presave  
     case 'insert':
       switch ($node->type) {
         case 'chado_feature':
@@ -1865,34 +1865,34 @@ function tripal_feature_nodeapi(&$node, $op, $teaser, $page) {
             $node->feature_id = $chado_feature->feature_id;
           }
 
-
+          
           // remove any previous alias
           db_query("DELETE FROM {url_alias} WHERE src = '%s'", "node/$node->nid");
-
+          
           // set the URL for this feature page
           $url_alias = tripal_feature_get_feature_url($node);
           path_set_alias("node/$node->nid", $url_alias);
           break;
       }
       break;
-
-    // set the URL path after inserting.  We do it here because we do not
-    // know the feature_id in the presave
+      
+    // set the URL path after inserting.  We do it here because we do not 
+    // know the feature_id in the presave  
     case 'update':
       switch ($node->type) {
         case 'chado_feature':
-
+          
           // remove any previous alias
           db_query("DELETE FROM {url_alias} WHERE src = '%s'", "node/$node->nid");
-
+          
           // set the URL for this feature page
           $url_alias = tripal_feature_get_feature_url($node);
           path_set_alias("node/$node->nid", $url_alias);
           break;
       }
       break;
-
-
+      
+      
     // add items to other nodes, build index and search results
     case 'view':
       switch ($node->type) {
@@ -2303,7 +2303,7 @@ function tripal_feature_coder_ignore() {
  * features is shown.
  */
 function tripal_feature_match_features_page($id) {
-
+  
   // if the URL alias configuration is set such that the URL
   // always begins with 'feature' then we want to use the ID as it is and
   // forward it on. Otherwise, try to find the matching feature.
@@ -2376,16 +2376,16 @@ function tripal_feature_match_features_page($id) {
 }
 
 /**
- *
+ * 
  * @param unknown_type $form
  * @param unknown_type $form_state
  * @param unknown_type $form_id
  */
 function tripal_feature_form_alter(&$form, &$form_state, $form_id) {
-  if ($form_id == "tripal_feature_seq_extract_form") {
+  if ($form_id == "tripal_feature_seq_extract_form") {    
     // updating the form through the ahah callback sets the action of
     // the form to the ahah callback URL. We need to set it back
     // to the normal form URL
     $form['#action'] = url("find/sequences");
   }
-}
+} 

+ 254 - 0
tripal_natural_diversity/includes/tripal_natural_diversity.admin.inc

@@ -0,0 +1,254 @@
+<?php
+/**
+ * @file
+ * @todo Add file header description
+ */
+
+function tripal_natural_diversity_admin($form_state = NULL) {
+  $form = array();
+
+  // before proceeding check to see if we have any
+  // currently processing jobs. If so, we don't want
+  // to give the opportunity to sync nd_geolocation
+  $active_jobs = FALSE;
+  if (tripal_get_module_active_jobs('tripal_nd_geolocation')) {
+    $active_jobs = TRUE;
+  }
+
+  // add the field set for syncing libraries
+  if (!$active_jobs) {
+    get_tripal_natural_diversity_admin_form_sync_set($form);
+    get_tripal_natural_diversity_admin_form_cleanup_set($form);
+  }
+  else {
+    $form['notice'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Natural Diversity Management Temporarily Unavailable')
+    );
+    $form['notice']['message'] = array(
+      '#value' => t('Currently, natural_diversity management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete.  Please check back later once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.'),
+    );
+  }
+
+  return system_settings_form($form);
+}
+/**
+ *
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function get_tripal_natural_diversity_admin_form_cleanup_set(&$form) {
+  $form['cleanup'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Clean Up')
+  );
+  $form['cleanup']['description'] = array(
+    '#type' => 'item',
+    '#value' => t("With Drupal and chado residing in different databases ".
+    "it is possible that nodes in Drupal and nd_geolocation in Chado become ".
+    "\"orphaned\".  This can occur if a nd_geolocation node in Drupal is ".
+    "deleted but the corresponding chado natural_diversity is not and/or vice ".
+    "versa. Click the button below to resolve these discrepancies."),
+    '#weight' => 1,
+  );
+  $form['cleanup']['button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Clean up orphaned nd_geolocation'),
+    '#weight' => 2,
+  );
+}
+/**
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function get_tripal_natural_diversity_admin_form_sync_set(&$form) {
+  // define the fieldsets
+  $form['sync'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Sync ND Geolocation')
+  );
+
+  // before proceeding check to see if we have any
+  // currently processing jobs. If so, we don't want
+  // to give the opportunity to sync libraries
+  $active_jobs = FALSE;
+  if (tripal_get_module_active_jobs('tripal_nd_geolocation')) {
+    $active_jobs = TRUE;
+  }
+
+  if (!$active_jobs) {
+
+    // get the list of nd_geolocation
+    $sql = "SELECT * FROM {nd_geolocation} ORDER BY description";
+    $org_rset = chado_query($sql);
+
+    // if we've added any nd_geolocation to the list that can be synced
+    // then we want to build the form components to allow the user
+    // to select one or all of them.  Otherwise, just present
+    // a message stating that all nd_geolocation are currently synced.
+    $nd_geo_boxes = array();
+    $added = 0;
+    while ($nd_geolocation = db_fetch_object($org_rset)) {
+      // check to see if the nd_geolocation is already present as a node in drupal.
+      // if so, then skip it.
+      $sql = "SELECT * FROM {chado_nd_geolocation} WHERE nd_geolocation_id = %d";
+      if (!db_fetch_object(db_query($sql, $nd_geolocation->nd_geolocation_id))) {
+        $nd_geo_boxes[$nd_geolocation->nd_geolocation_id] = $nd_geolocation->description;
+        $added++;
+      }
+    }
+
+    // if we have nd_geolocation we need to add to the checkbox then
+    // build that form element
+    if ($added > 0) {
+      $nd_geo_boxes['all'] = "All ND Geolocation";
+
+      $form['sync']['nd_geolocation'] = array(
+        '#title'       => t('Available ND Geolocation'),
+        '#type'        => t('checkboxes'),
+        '#description' => t("Check the nd_geolocation you want to sync.  Drupal content will be created for each of the nd_geolocation listed above.  Select 'All Natural Diversity' to sync all of them."),
+        '#required'    => FALSE,
+        '#prefix'      => '<div id="org_boxes">',
+        '#suffix'      => '</div>',
+        '#options'     => $nd_geo_boxes,
+      );
+      $form['sync']['button'] = array(
+        '#type' => 'submit',
+        '#value' => t('Submit Sync Job')
+      );
+    }
+    // we don't have any nd_geolocation to select from
+    else {
+    $form['sync']['value'] = array(
+        '#value' => t('All nd_geolocation in Chado are currently synced with Drupal.')
+    );
+    }
+  }
+  // we don't want to present a form since we have an active job running
+  else {
+    $form['sync']['value'] = array(
+        '#value' => t('Currently, jobs exist related to chado nd_geolocation. Please check back later for nd_geolocation that can by synced once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.')
+    );
+  }
+}
+/**
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function tripal_natural_diversity_admin_validate($form, &$form_state) {
+  global $user;  // we need access to the user info
+  $job_args = array();
+
+  if ($form_state['values']['op'] == t('Submit Sync Job')) {
+
+    // check to see if the user wants to sync chado and drupal.  If
+    // so then we need to register a job to do so with tripal
+    $nd_geolocation = $form_state['values']['nd_geolocation'];
+    $do_all = FALSE;
+    $to_sync = array();
+
+    foreach ($nd_geolocation as $nd_geolocation_id) {
+      if (preg_match("/^all$/i" , $nd_geolocation_id)) {
+        $do_all = TRUE;
+      }
+      if ($nd_geolocation_id and preg_match("/^\d+$/i" , $nd_geolocation_id)) {
+        // get the list of nd_geolocation
+        $sql = "SELECT * FROM {nd_geolocation} WHERE nd_geolocation_id = %d";
+        $nd_geolocation = db_fetch_object(chado_query($sql, $nd_geolocation_id));
+        $to_sync[$nd_geolocation_id] = "$nd_geolocation->description";
+      }
+    }
+
+    // submit the job the tripal job manager
+    if ($do_all) {
+      tripal_add_job('Sync all nd_geolocation' , 'tripal_natural_diversity',
+      'tripal_natural_diversity_sync_nd_geolocation' , $job_args , $user->uid);
+    }
+    else{
+      foreach ($to_sync as $nd_geolocation_id => $name) {
+        $job_args[0] = $nd_geolocation_id;
+        tripal_add_job("Sync nd_geolocation: $name" , 'tripal_natural_diversity',
+          'tripal_natural_diversity_sync_nd_geolocation' , $job_args , $user->uid);
+      }
+    }
+  }
+
+  // -------------------------------------
+  // Submit the Cleanup Job if selected
+  if ($form_state['values']['op'] == t('Clean up orphaned nd_geolocation')) {
+    tripal_add_job('Cleanup orphaned nd_geolocation', 'tripal_natural_diversity',
+      'tripal_natural_diversity_cleanup', $job_args, $user->uid);
+  }
+}
+/**
+ * Synchronize natural_diversity from chado to drupal
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function tripal_natural_diversity_sync_nd_geolocation($nd_geolocation_id = NULL, $job_id = NULL) {
+  global $user;
+  $page_content = '';
+
+  if (!$nd_geolocation_id) {
+    $sql = "SELECT * FROM {nd_geolocation} P";
+    $results = chado_query($sql);
+  }
+  else {
+    $sql = "SELECT * FROM {nd_geolocation} P WHERE nd_geolocation_id = %d";
+    $results = chado_query($sql, $nd_geolocation_id);
+  }
+
+  // We'll use the following SQL statement for checking if the nd_geolocation
+  // already exists as a drupal node.
+  $sql = "SELECT * FROM {chado_nd_geolocation} ".
+         "WHERE nd_geolocation_id = %d";
+
+  while ($nd_geolocation = db_fetch_object($results)) {
+
+    // check if this nd_geolocation already exists in the drupal database. if it
+    // does then skip this nd_geolocation and go to the next one.
+    if (!db_fetch_object(db_query($sql, $nd_geolocation->nd_geolocation_id))) {
+
+      $new_node = new stdClass();
+      $new_node->type = 'chado_nd_geolocation';
+      $new_node->uid = $user->uid;
+      $new_node->nd_geolocation_id = $nd_geolocation->nd_geolocation_id;
+      $new_node->title = $nd_geolocation->description;
+      $new_node->latitude = $nd_geolocation->latitude;
+      $new_node->longitude = $nd_geolocation->longitude;
+      $new_node->altitude = $nd_geolocation->altitude;
+      $new_node->geodetic_datum = $nd_geolocation->geodetic_datum;
+      node_validate($new_node);
+      if (!form_get_errors()) {
+        $node = node_submit($new_node);
+        node_save($node);
+        db_query("UPDATE node SET title = '%s' WHERE nid = %d", $nd_geolocation->description, $node->nid); // Use description as node title
+        if ($node->nid) {
+          print "Added $nd_geolocation->description\n";
+        }
+      }
+      else {
+        print "Failed to insert nd_geolocation $nd_geolocation->description\n";
+      }
+    }
+    else {
+      print "Skipped $nd_geolocation->description\n";
+    }
+  }
+  return $page_content;
+}
+
+/**
+ * Remove orphaned drupal nodes
+ *
+ * @param $dummy
+ *   Not Used -kept for backwards compatibility
+ * @param $job_id
+ *   The id of the tripal job executing this function
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function tripal_natural_diversity_cleanup($dummy = NULL, $job_id = NULL) {
+
+  return tripal_core_clean_orphaned_nodes('nd_geolocation', $job_id);
+}

+ 255 - 0
tripal_natural_diversity/includes/tripal_natural_diversity.nd_geolocation.inc

@@ -0,0 +1,255 @@
+<?php
+/**
+ * Implementation of hook_form().
+ *
+ *  This form takes the ND Geolocation Title information and description from the user.
+ *
+ *  @parm $node
+ *    The initialized node
+ *
+ *  @parm $form_state
+ *    The state of the form, that has the user entered information that is neccessary for adding
+ *    information to the nd_geolocation
+ *
+ *  @return $form
+ *    An array as described by the Drupal Form API
+ *
+ *
+ * @ingroup tripal_nd_geolocation
+ */
+function chado_nd_geolocation_form(&$node, $form_state) {
+  $form = array();
+  $nd_geolocation = $node->nd_geolocation;
+  $nd_geolocation_latitude = $nd_geolocation->latitude;
+  $nd_geolocation_longitude = $nd_geolocation->longitude;
+  $nd_geolocation_altitude = $nd_geolocation->altitude;
+  $nd_geolocation_geodetic_datum = $nd_geolocation->geodetic_datum;
+
+  // keep track of the nd_geolocation id if we have.  If we do have one then
+  // this is an update as opposed to an insert.
+  $form['nd_geolocation_id'] = array(
+      '#type' => 'value',
+      '#value' => $nd_geolocation->nd_geolocation_id,
+  );
+  
+  // use nd_geolocation.description as the node title
+  $form['title']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('ND Geolocation Description'),
+    '#description'   => t('A brief description of the nd_geolocation.'),
+    '#required'      => TRUE,
+    '#default_value' => $node->title,
+    '#weight'        => 1
+  );
+
+  $form['nd_geolocation_latitude']= array(
+      '#type'          => 'textfield',
+      '#title'         => t('ND Geolocation Latitude'),
+      '#description'   => t('Latitude of the nd_geolocation'),
+      '#required'      => FALSE,
+      '#default_value' => $nd_geolocation_latitude,
+      '#weight'        => 2
+  );
+  
+  $form['nd_geolocation_longitude']= array(
+      '#type'          => 'textfield',
+      '#title'         => t('ND Geolocation Longitude'),
+      '#description'   => t('Longitude of the nd_geolocation'),
+      '#required'      => FALSE,
+      '#default_value' => $nd_geolocation_longitude,
+      '#weight'        => 3
+  );
+  
+  $form['nd_geolocation_altitude']= array(
+      '#type'          => 'textfield',
+      '#title'         => t('ND Geolocation Altitude'),
+      '#description'   => t('Altitude of the nd_geolocation'),
+      '#required'      => FALSE,
+      '#default_value' => $nd_geolocation_altitude,
+      '#weight'        => 4
+  );
+  
+  $form['nd_geolocation_geodetic_datum']= array(
+      '#type'          => 'textfield',
+      '#title'         => t('ND Geolocation Geodetic Datum'),
+      '#description'   => t('Geodetic_datum of the nd_geolocation'),
+      '#required'      => FALSE,
+      '#default_value' => $nd_geolocation_geodetic_datum,
+      '#weight'        => 5
+  );
+  return $form;
+
+}
+
+/**
+ *  validates submission of form when adding or updating a nd_geolocation node
+ *
+ * @ingroup tripal_nd_geolocation
+ */
+function chado_nd_geolocation_validate($node) {
+  // check to make sure latitude, longitude, and altitude are numbers or null
+  $latitude = trim($node->nd_geolocation_latitude);
+  $longitude = trim($node->nd_geolocation_longitude);
+  $altitude = trim($node->nd_geolocation_altitude);
+  if ($latitude && !is_numeric($latitude)) {
+    form_set_error('nd_geolocation_latitude', t('Latitude shoulbe a number'));
+  } 
+  if ($longitude && !is_numeric($longitude)) {
+    form_set_error('nd_geolocation_longitude', t('Longitude shoulbe a number'));
+  }
+  if ($altitude && !is_numeric($altitude)) {
+    form_set_error('nd_geolocation_altitude', t('Altitude shoulbe a number'));
+  }
+
+}
+/**
+ * Implementation of hook_insert().
+ *
+ *  @parm $node
+ *    Then node that has the information stored within, accessed given the nid
+ *
+ *
+ * @ingroup tripal_nd_geolocation
+ */
+function chado_nd_geolocation_insert($node) {
+  if ($node->nd_geolocation_id) {
+    $nd_geolocation['nd_geolocation_id'] = $node->nd_geolocation_id;
+  }
+  else {
+    $description = trim($node->title);
+    $latitude = trim($node->nd_geolocation_latitude);
+    $longitude = trim($node->nd_geolocation_longitude);
+    $altitude = trim($node->nd_geolocation_altitude);
+    $geodetic_datum = trim($node->nd_geolocation_geodetic_datum);
+    $values = array(
+        'description' => $description,
+        'latitude' => $latitude ? $latitude : 'NULL',
+        'longitude' => $longitude ? $longitude : 'NULL',
+        'altitude' => $altitude ? $altitude : 'NULL',
+        'geodetic_datum' => $geodetic_datum ? $geodetic_datum : '',
+    );
+    $nd_geolocation = tripal_core_chado_insert('nd_geolocation', $values);
+  }
+
+  if ($nd_geolocation) {
+    // make sure the entry for this feature doesn't already exist in the chado_nd_geolocation table
+    // if it doesn't exist then we want to add it.
+    $nd_geolocation_id = chado_get_id_for_node('nd_geolocation', $node) ;
+    if (!$nd_geolocation_id) {
+      // next add the item to the drupal table
+      $sql = "INSERT INTO {chado_nd_geolocation} (nid, vid, nd_geolocation_id) ".
+          "VALUES (%d, %d, %d)";
+      db_query($sql, $node->nid, $node->vid, $nd_geolocation['nd_geolocation_id']);
+    }
+  }
+  else {
+    drupal_set_message(t('Unable to add nd_geolocation.', 'warning'));
+    watchdog('tripal_nd_geolocation', 'Insert nd_geolocation: Unable to create nd_geolocation where values: %values',
+    array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
+  }
+}
+
+/**
+ *
+ * Implementation of hook_delete().
+ *
+ * @param $node
+ * The node which is to be deleted, only chado nd_geolocation and chado_nd_geolocation need to be dealt with
+ * since the drupal node is deleted automagically
+ *
+ *
+ * @ingroup tripal_nd_geolocation
+ */
+function chado_nd_geolocation_delete($node) {
+
+  $nd_geolocation_id = chado_get_id_for_node('nd_geolocation', $node);
+
+  // if we don't have a nd_geolocation id for this node then this isn't a node of
+  // type chado_nd_geolocation or the entry in the chado_nd_geolocation table was lost.
+  if (!$nd_geolocation_id) {
+    return;
+  }
+
+  // Remove data from {chado_nd_geolocation}, {node} and {node_revisions} tables of
+  // drupal database
+  $sql_del = "DELETE FROM {chado_nd_geolocation} ".
+      "WHERE nid = %d ".
+      "AND vid = %d";
+  db_query($sql_del, $node->nid, $node->vid);
+  $sql_del = "DELETE FROM {node_revisions} ".
+      "WHERE nid = %d ".
+      "AND vid = %d";
+  db_query($sql_del, $node->nid, $node->vid);
+  $sql_del = "DELETE FROM {node} ".
+      "WHERE nid = %d ".
+      "AND vid = %d";
+  db_query($sql_del, $node->nid, $node->vid);
+
+
+  // Remove data from nd_geolocation and nd_geolocationprop tables of chado database as well
+  chado_query("DELETE FROM {nd_geolocationprop} WHERE nd_geolocation_id = %d", $eimage_id);
+  chado_query("DELETE FROM {nd_geolocation} WHERE nd_geolocation_id = %d", $nd_geolocation_id);
+}
+
+/**
+ * Implements hook_update().
+ *
+ * @param $node
+ *  The node which is to have its containing information updated when the user modifies information
+ *  pertaining to the specific nd_geolocation
+ *
+ *
+ * @ingroup tripal_nd_geolocation
+ */
+function chado_nd_geolocation_update($node) {
+  if ($node->revision) {
+    // there is no way to handle revisions in Chado but leave
+    // this here just to make not we've addressed it.
+  }
+
+  // update the nd_geolocation and the description
+  $nd_geolocation_id = chado_get_id_for_node('nd_geolocation', $node) ;
+  $match = array(
+      'nd_geolocation_id' => $nd_geolocation_id,
+  );
+  $description = trim($node->title);
+  $latitude = trim($node->nd_geolocation_latitude);
+  $longitude = trim($node->nd_geolocation_longitude);
+  $altitude = trim($node->nd_geolocation_altitude);
+  $geodetic_datum = trim($node->nd_geolocation_geodetic_datum);
+  $values = array(
+      'description' => $description,
+      'latitude' => $latitude ? $latitude : 'NULL',
+      'longitude' => $longitude ? $longitude : 'NULL',
+      'altitude' => $altitude ? $altitude : 'NULL',
+      'geodetic_datum' => $geodetic_datum ? $geodetic_datum : '',
+  );
+  $status = tripal_core_chado_update('nd_geolocation', $match, $values);
+
+}
+
+/**
+ * Implementation of node_load().
+ *
+ * @param $node
+ *   The node that is to have its containing information loaded
+ *
+ * @return $node
+ *   The node, containing the loaded nd_geolocation with the current nid
+ *
+ *
+ * @ingroup tripal_nd_geolocation
+ */
+function chado_nd_geolocation_load($node) {
+
+  // get the feature details from chado
+  $nd_geolocation_id = chado_get_id_for_node('nd_geolocation', $node);
+
+  $values = array('nd_geolocation_id' => $nd_geolocation_id);
+  $nd_geolocation = tripal_core_generate_chado_var('nd_geolocation', $values);
+
+  $additions = new stdClass();
+  $additions->nd_geolocation = $nd_geolocation;
+  return $additions;
+
+}

+ 31 - 0
tripal_natural_diversity/theme/tripal_natural_diversity_admin.tpl.php

@@ -0,0 +1,31 @@
+<h3>Tripal Natural Diversity Administrative Tools Quick Links:</h3>
+<ul>
+ <li><a href="<?php print url("admin/tripal/tripal_natural_diversity/configuration") ?>">Natural Diversity Configuration</a></li>
+</ul>
+<h3>Module Description:</h3>
+<p>The Tripal Natural Diversity module provides support for visualization of "natural_diversity" pages, editing and updating.</p>
+
+<h3>Setup Instructions:</h3>
+<ol>
+   <li><p><b>Set Permissions</b>: By default only the site administrator account has access to create, edit, delete
+   or administer features. Navigate to the <?php print l('permissions page', 'admin/user/permissions')?> and set the
+   permissions under the 'tripal_natural_diversity' section as appropriate for your site. For a simple setup, allow anonymous 
+   users access to view content and create a special role for creating, editing and other administrative tasks.</p></li>
+
+<li><p><b>Sync any Existing Natural Diversity Geolocations</b>: Near the top of the <?php print l('Natural Diversity Configuration page', 'admin/tripal/tripal_natural_diversity/configuration') ?> there is
+  a Sync Natural Diversity Geolocation section which provides list of nd_geolocation currently in chado which can be sync\'d.
+  Simply select the nd_geolocation you would like to create Drupal/Tripal pages for and click Submit Sync Job.</p></li>
+</ol>
+
+
+<h3>Features of this Module:</h3>
+<ul>
+  <li><b>Add/Edit/Delete Natural Diversity Geolocation</b>: Natural Diversity Geolocation can be created <?php print l('here', 'node/add/chado-nd-geolocation') ?>. 
+  After creation, nd_geolocation (regardless of the method used to create them) can be
+  edited or deleted by clicking the Edit tab at the top of the Natural Diversity Geolocation Page.</li>
+    <li><p><b>Simple Search Tool</b>: A <?php print l('simple search tool','chado/nd_geolocation') ?> is provided for 
+    finding nd_geolocation. This tool relies on Drupal Views.  <a href="http://drupal.org/natural_diversity/views">Drupal Views</a>
+    which must be installed to see the search tool.  Look for it in the navigation menu under the item 
+    "Search Biological Data". </p></li>
+
+</ul>

+ 47 - 0
tripal_natural_diversity/tripal_natural_diversity.install

@@ -15,6 +15,10 @@ function tripal_natural_diversity_install() {
   // add cvterms
   tripal_natural_diversity_add_cvterms();
   
+  // add chado_nd_geolocation table
+  if (!db_table_exists('chado_nd_geolocation')) {
+    drupal_install_schema('tripal_natural_diversity_nd_geolocation');
+  }
 }
 
 /**
@@ -72,4 +76,47 @@ function tripal_natural_diversity_requirements($phase) {
     }
   }
   return $requirements;
+}
+
+/**
+ *  Update for Drupal 6.x, Tripal 1.1, Natural Diversity Module 1.1
+ *  This update adds new chado_nd_geolocation table
+ *
+ */
+function tripal_natural_diversity_update_6101() {
+   
+  // add chado_nd_geolocation table
+  drupal_install_schema('tripal_natural_diversity_nd_geolocation');
+
+  $ret = array(
+      '#finished' => 1,
+  );
+
+  return $ret;
+}
+
+/**
+ * Implementation of hook_schema().
+ */
+function tripal_natural_diversity_nd_geolocation_schema() {
+  $schema['chado_nd_geolocation'] = array(
+      'fields' => array(
+          'nid' => array(
+              'type' => 'int',
+              'unsigned' => TRUE,
+              'not null' => TRUE,
+          ),
+          'vid' => array(
+              'type' => 'int',
+              'not null' => TRUE,
+          ),
+          'nd_geolocation_id' => array(
+              'type' => 'int',
+              'unsigned' => TRUE,
+              'not null' => TRUE,
+          ),
+      ),
+      'primary key' => array('nid', 'vid', 'nd_geolocation_id'),
+  );
+  return $schema;
 }

+ 134 - 1
tripal_natural_diversity/tripal_natural_diversity.module

@@ -2,6 +2,8 @@
 
 require_once('api/tripal_natural_diversity.api.inc');
 require_once('includes/tripal_natural_diversity.schema.inc');
+require_once('includes/tripal_natural_diversity.nd_geolocation.inc');
+require_once('includes/tripal_natural_diversity.admin.inc');
 
 /**
  *  @file
@@ -48,6 +50,19 @@ function tripal_natural_diversity_theme() {
       'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_nd_phenotypes',
     ),
+    'tripal_nd_geolocation_base' => array(
+        'arguments' => array('node' => NULL),
+        'template' => 'tripal_nd_geolocation_base',
+    ),
+    'tripal_nd_geolocation_properties' => array(
+        'arguments' => array('node' => NULL),
+        'template' => 'tripal_nd_geolocation_properties',
+    ),
+    'tripal_natural_diversity_admin' => array(
+        'template' => 'tripal_natural_diversity_admin',
+        'arguments' =>  array(NULL),
+        'path' => drupal_get_path('module', 'tripal_natural_diversity') . '/theme'
+    ),
   );
 }
 
@@ -62,7 +77,7 @@ function tripal_natural_diversity_nodeapi(&$node, $op, $teaser, $page){
       if ($node->type == 'chado_feature') {
         // the tripal_genetic module provides a tripal_feature_genotype
         // template.  The only difference between them is the addition of
-        // project information by this module's template.  Therefore,
+        // natural_diversity information by this module's template.  Therefore,
         // if the tripal_genetic content is present get rid of as this
         // module superceeds it.
         if (array_key_exists('tripal_feature_genotypes', $node->content)) {
@@ -92,3 +107,121 @@ function tripal_natural_diversity_nodeapi(&$node, $op, $teaser, $page){
 function tripal_natural_diversity_preprocess_tripal_stock_nd_genotypes(&$variables){
 
 }
+
+/**
+ * Implements hook_menu
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function tripal_natural_diversity_menu() {
+  $items[ 'admin/tripal/tripal_natural_diversity' ]= array(
+    'title' => 'Natural Diversity',
+    'description' => ('A module for interfacing the GMOD chado database with Drupal, providing viewing of natural_diversity data'),
+    'page callback' => 'theme',
+    'page arguments' => array('tripal_natural_diversity_admin'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM
+  );
+
+  $items[ 'admin/tripal/tripal_natural_diversity/configuration' ]= array(
+    'title' => 'Configuration',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_natural_diversity_admin'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM
+  );
+
+  return $items;
+}
+
+/**
+ * Implements hook_perm()
+ *
+ *  This function sets the permission for the user to access the information in the database.
+ *  This includes creating, inserting, deleting and updating of information in the database
+ *
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function tripal_natural_diversity_perm() {
+  return array(
+      'access chado_nd_geolocation content',
+      'create chado_nd_geolocation content',
+      'delete chado_nd_geolocation content',
+      'edit chado_nd_geolocation content',
+      'adminster tripal natural_diversity',
+  );
+}
+
+/**
+ * Implement hook_access().
+ *
+ * This hook allows node modules to limit access to the node types they define.
+ *
+ *  @param $op
+ *  The operation to be performed
+ *
+ *  @param $node
+ *  The node on which the operation is to be performed, or, if it does not yet exist, the
+ *  type of node to be created
+ *
+ *  @param $account
+ *  A user object representing the user for whom the operation is to be performed
+ *
+ *  @return
+ *  If the permission for the specified operation is not set then return FALSE. If the
+ *  permission is set then return NULL as this allows other modules to disable
+ *  access.  The only exception is when the $op == 'create'.  We will always
+ *  return TRUE if the permission is set.
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function chado_natural_diversity_access($op, $node, $account) {
+
+  if ($op == 'create') {
+    if (!user_access('create chado_nd_geolocation content', $account)) {
+      return FALSE;
+    }
+    return TRUE;
+  }
+  if ($op == 'update') {
+    if (!user_access('edit chado_nd_geolocation content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'delete') {
+    if (!user_access('delete chado_nd_geolocation content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'view') {
+    if (!user_access('access chado_nd_geolocation content', $account)) {
+      return FALSE;
+    }
+  }
+  return NULL;
+}
+
+/**
+ * Implementation of hook_node_info().
+ *
+ * This node_info, is a simple node that describes the functionallity of the module. It specifies
+ * that the title(Project Name) and body(Description) set to true so that they information can be
+ * entered
+ *
+ *
+ * @ingroup tripal_natural_diversity
+ */
+function tripal_natural_diversity_node_info() {
+  return array(
+      'chado_nd_geolocation' => array(
+          'name' => t('ND Geolocation'),
+          'module' => 'chado_nd_geolocation',
+          'description' => t('A module for interfacing the GMOD chado database with Drupal, providing viewing of nd_geolocation'),
+          'has_title' => TRUE,
+          'title_label' => t('ND Geolocation'),
+          'had_body' => FALSE,
+          'body_label' => t('Full Description'),
+      )
+  );
+}

+ 4 - 0
tripal_organism/tripal_organism.module

@@ -149,6 +149,10 @@ function tripal_organism_theme() {
       'arguments' =>  array(NULL),
       'path' => drupal_get_path('module', 'tripal_organism') . '/theme'
     ),
+    'tripal_organism_references' => array(
+      'arguments' => array('node' => NULL),
+      'template' => 'tripal_organism_references',
+    ),
   );
 }
 /**

+ 1 - 1
tripal_project/includes/tripal_project.admin.inc

@@ -250,7 +250,7 @@ function tripal_project_sync_projects($project_id = NULL, $job_id = NULL) {
       $new_node->uid = $user->uid;
       $new_node->title = "$project->name";
       $new_node->project_id = $project->project_id;
-      $new_node->name = $project->name;
+      //$new_node->name = $project->name;
       $new_node->description = $project->description;
       node_validate($new_node);
       if (!form_get_errors()) {

+ 38 - 7
tripal_pub/api/tripal_pub.api.inc

@@ -227,6 +227,8 @@ function tripal_pub_import_publications($report_email = FALSE, $do_update = FALS
   $do_contact = FALSE;
   $reports = array();
   while ($import = db_fetch_object($results)) {
+    $page = 0;
+    
     print "Importing: " . $import->name . "\n";
     // keep track if any of the importers want to create contacts from authors
     if ($import->do_contact == 1) {
@@ -649,6 +651,12 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
     $results = tripal_pub_get_pubs_by_dbxref($pub_details['Publication Dbxref']);
     if(count($results) == 1) {
       $pub_id = $results[0];
+      if ($pub_id and !$update_if_exists) {
+        watchdog('tripal_pub', "A publication with this Dbxref already exists... Skipping: %dbxref", 
+          array('%dbxref' => $pub_details['Publication Dbxref']), WATCHDOG_WARNING);
+        $action = 'skipped';
+        return $pub_id;
+      }
     }
     elseif (count($results) > 1) {
       watchdog('tripal_pub', "There are two publications with this accession: %db:%accession. Cannot determine which to update.",
@@ -666,6 +674,13 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
     $results = tripal_pub_get_pubs_by_title_type_pyear_series($pub_details['Title'], NULL, $pub_details['Year']);
     if (count($results) == 1) {
       $pub_id = $results[0];
+      if ($pub_id and !$update_if_exists) {
+        watchdog('tripal_pub', "The publication with the same title, type and year already exists. Skipping. ".
+          " Title: '%title'. Type: '%type'. Year: '%year'", 
+          array('%title' => $pub_details['Title'], '%type' => $pub_details['Publication Type'], '%year' => $pub_details['Year']), WATCHDOG_WARNING);
+        $action = 'skipped';
+        return $pub_id;
+      }
     }
     elseif (count($results) > 1) {
       watchdog('tripal_pub', "The publication with the same title, type and year is present multiple times. Cannot ".
@@ -675,12 +690,6 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
       return FALSE;
     }
   }
-  //print "PUB ID: $pub_id\n";
-  // if there is a pub id and we've been told not to update then return
-  if ($pub_id and !$update_if_exists) {
-    $action = 'skipped';
-    return $pub_id;
-  }
 
   // get the publication type (use the first publication type, any others will get stored as properties)
   if (is_array($pub_details['Publication Type'])) {
@@ -705,7 +714,7 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
   $values = array(
     'title'       => $pub_details['Title'],
     'volume'      => $pub_details['Volume'],
-    'series_name' => $pub_details['Journal Name'],
+    'series_name' => substr($pub_details['Journal Name'], 0, 255),
     'issue'       => $pub_details['Issue'],
     'pyear'       => $pub_details['Year'],
     'pages'       => $pub_details['Pages'],
@@ -1197,6 +1206,11 @@ function tripal_pub_create_citation($pub) {
         $pub_type = $ptype;
         break;
       }
+      else if ($ptype == "Research Support, Non-U.S. Gov't") {
+        $pub_type = $ptype; 
+        // we don't break because if the article is also a Journal Article
+        // we prefer that type
+      }
     }
     if (!$pub_type) {
       watchdog('tripal_pub', "Cannot generate citation for publication type: %types", 
@@ -1249,6 +1263,23 @@ function tripal_pub_create_citation($pub) {
     $citation .= '.';
   }
   //----------------------
+  // Research Support, Non-U.S. Gov't
+  //----------------------
+  elseif ($pub_type == "Research Support, Non-U.S. Gov't") {
+    $citation = $pub['Authors'] . '. ' . $pub['Title'] .  '. ';
+  
+    if ($pub['Journal Name']) {
+      $citation .= $pub['Journal Name'] . '. ';
+    }
+    if ($pub['Publication Date']) {
+      $citation .= $pub['Publication Date'];
+    }
+    elseif ($pub['Year']) {
+      $citation .= $pub['Year'];
+    }    
+    $citation .= '.';
+  }
+  //----------------------
   // Letter
   //----------------------
   elseif ($pub_type == 'Letter') {

+ 14 - 0
tripal_pub/includes/importers/AGL.inc

@@ -813,6 +813,20 @@ function tripal_pub_AGL_parse_pubxml($pub_xml) {
     $pub['Authors'] = $pub['Author List'];	
   }
 
+  // for Title, Abstract, Authors, convert the html entity and remove special unicode chars that are not meant for display
+  $pub['Title'] = preg_replace( '/[\p{So}]/u', '', mb_convert_encoding($pub['Title'], 'UTF-8', 'HTML-ENTITIES'));
+  if (key_exists('Abstract', $pub)) {
+    $pub['Abstract'] =preg_replace( '/[\p{So}]/u', '',mb_convert_encoding($pub['Abstract'], 'UTF-8', 'HTML-ENTITIES'));
+  }
+  $newauths = array();
+  foreach ($pub['Author List'] AS $auth) {
+    foreach($auth AS $k => $v) {
+      $auth[$k] = preg_replace( '/[\p{So}]/u', '',mb_convert_encoding($v, 'UTF-8', 'HTML-ENTITIES'));
+    }
+    array_push($newauths, $auth);
+  }
+  $pub['Author List'] = $newauths;
+
   // build the citation
   $pub['Citation'] = tripal_pub_create_citation($pub);
 

+ 1 - 1
tripal_pub/includes/pub_search.inc

@@ -410,7 +410,7 @@ function tripal_pub_get_search_results($search_array, $limit, $pager_id) {
   $select = "SELECT DISTINCT P.*, CP.nid ";
   $from   = "FROM {pub} P
                LEFT JOIN public.chado_pub CP on P.pub_id = CP.pub_id 
-               INNER JOIN cvterm CVT on CVT.cvterm_id = P.type_id
+               INNER JOIN {cvterm} CVT on CVT.cvterm_id = P.type_id
             ";
   $where  = "WHERE (NOT P.title = 'null') "; // always exclude the dummy pub
   $order  = "ORDER BY P.pyear DESC, P.title ASC";

+ 1 - 1
tripal_pub/tripal_pub.drush.inc

@@ -68,7 +68,7 @@ function drush_tripal_pub_tripal_pubs_import() {
   $create_contacts = drush_get_option('create_contacts');
   $dbxref = drush_get_option('dbxref');
   $do_report = drush_get_option('report');
-  $update = drush_get_option('$update');
+  $update = drush_get_option('update');
 
   if($update == 'Y') {
     $update = TRUE;

+ 6 - 6
tripal_pub/tripal_pub.module

@@ -444,7 +444,7 @@ function chado_pub_insert($node) {
     // insert the pub record
     $values = array(
       'title'       => trim($node->pubtitle),
-      'series_name' => trim($node->series_name),
+      'series_name' => substr(trim($node->series_name), 0, 255),
       'type_id'     => trim($node->type_id),
       'pyear'       => trim($node->pyear),
       'is_obsolete' => $node->is_obsolete ? 'true' : 'false', 
@@ -453,9 +453,9 @@ function chado_pub_insert($node) {
       'volume'      => $volume,    
       'issue'       => $issue,    
       'pages'       => $pages,
-      'miniref'     => $miniref,        
-      'publisher'   => $publisher,
-      'pubplace'    => $pubplace,
+      'miniref'     => substr($miniref, 0, 255),        
+      'publisher'   => substr($publisher, 0, 255),
+      'pubplace'    => substr($pubplace, 0, 255),
     );
     $pub = tripal_core_chado_insert('pub', $values);
     if (!$pub) {
@@ -822,7 +822,7 @@ function tripal_pub_preprocess_tripal_pub_relationships(&$variables) {
   // query, therefore we will manually perform the query
   $sql = "
     SELECT P.title, P.pub_id, CP.nid, CVT.name as rel_type
-    FROM pub_relationship PR
+    FROM {pub_relationship} PR
       INNER JOIN {pub} P            ON PR.object_id = P.pub_id
       INNER JOIN {cvterm} CVT       ON PR.type_id   = CVT.cvterm_id
       LEFT JOIN public.chado_pub CP ON P.pub_id     = CP.pub_id
@@ -831,7 +831,7 @@ function tripal_pub_preprocess_tripal_pub_relationships(&$variables) {
   $as_subject = chado_query($sql, $pub->pub_id);
   $sql = "
     SELECT P.title, P.pub_id, CP.nid, CVT.name as rel_type
-    FROM pub_relationship PR
+    FROM {pub_relationship} PR
       INNER JOIN {pub} P            ON PR.subject_id = P.pub_id
       INNER JOIN {cvterm} CVT       ON PR.type_id    = CVT.cvterm_id
       LEFT JOIN public.chado_pub CP ON P.pub_id      = CP.pub_id

+ 1 - 1
tripal_views/views/handlers/chado_views_handler_field.inc

@@ -92,7 +92,7 @@ class chado_views_handler_field extends views_handler_field {
   /**
    * Splits the aggregated values up for use in rendering
    */
-  function pre_render(&$values) {
+  function pre_render($values) {
 
     // further check the results to see if this field is a postgresql array
     $this->aggregated = chado_wrapper_is_aggregated_by_result($this, $values);