Skip to content

Commit

Permalink
TNRS db scripts version 3.6.3
Browse files Browse the repository at this point in the history
Added fixes for specific issues with Tropicos taxonomy
  • Loading branch information
ojalaquellueva committed Mar 28, 2014
1 parent 663d418 commit 3f6595b
Show file tree
Hide file tree
Showing 54 changed files with 2,117 additions and 287 deletions.
2 changes: 1 addition & 1 deletion tnrs3_db_scripts/create_staging_table.inc
Expand Up @@ -34,7 +34,7 @@ CREATE TABLE `$tbl_staging` (
`$parent_fk_fld` INTEGER UNSIGNED DEFAULT NULL,
`$left_index_fld` INTEGER(11) UNSIGNED DEFAULT NULL,
`$right_index_fld` INTEGER(11) UNSIGNED DEFAULT NULL,
`$acceptance_fld` VARCHAR(25) DEFAULT NULL,
`$acceptance_fld` VARCHAR(50) DEFAULT NULL,
`$accepted_id_fld` INTEGER(11) UNSIGNED DEFAULT NULL,
`nomenclaturalStatusRemarks` VARCHAR(100) DEFAULT NULL,
`parent` VARCHAR(250) NOT NULL,
Expand Down
131 changes: 131 additions & 0 deletions tnrs3_db_scripts/functions/geo_functions.inc
@@ -0,0 +1,131 @@
<?php
// functions related to parsing and converting coordinates

function decimal_coordinate($deg,$min,$sec,$lat_or_long) {
// Converts coordinates from
// degrees, minutes, seconds
// to decimal format.
// Will convert either latitude or longitude, depending on
// value of parameter $lat_or_long.
// Can handle character format input; will convert if numeric.
// Can return either the converted value, false (check with ===) or null

$lat_or_long = strtolower($lat_or_long);

if ($lat_or_long=='lat' || $lat_or_long=='latitude') {
$lat = true;
$long = false;
} else if ($lat_or_long=='long' || $lat_or_long=='lon' || $lat_or_long=='longitude') {
$lat = false;
$long = true;
} else {
return null;
}


// check degrees numeric and in range
if ( is_null($deg) || (!(is_numeric($deg))) ) {
return null;
} else {
// check degrees in range
if ( ($lat && ($deg>90 || $deg<-90)) || ($long && ($deg>180 || $deg<-180)) ) return null;
}

// check minutes numeric and in range
if ( is_null($min) || (!(is_numeric($min))) ) {
// assume zero if degrees null
$min=0;
} elseif ( ($min>=60 || $min<-0) ) {
return null;
}

// check seconds numeric and in range
if ( is_null($sec) || (!(is_numeric($sec))) ) {
// assume zero if degrees null
$sec=0;
} elseif ( ($sec>=60 || $sec<-0) ) {
return null;
}

// finally, check that minutes + seconds do not total >60
if ($min + $sec > 60) return null;

// Good to go; calculate decimal coordinate
$coord = $deg + $min/60 + $sec/3600;
return $coord;

}

function state_name_US($state_code) {
// Translates US two-letter state codes to full state names
// Returns NULL if no match; be sure to add handler if
// need to use some other vaue for nomatch

$state_name=array(
'AL'=>'Alabama',
'AK'=>'Alaska',
'AZ'=>'Arizona',
'AR'=>'Arkansas',
'CA'=>'California',
'CO'=>'Colorado',
'CT'=>'Connecticut',
'DE'=>'Delaware',
'DC'=>'District of Columbia',
'FL'=>'Florida',
'GA'=>'Georgia',
'HI'=>'Hawaii',
'ID'=>'Idaho',
'IL'=>'Illinois',
'IN'=>'Indiana',
'IA'=>'Iowa',
'KS'=>'Kansas',
'KY'=>'Kentucky',
'LA'=>'Louisiana',
'ME'=>'Maine',
'MD'=>'Maryland',
'MA'=>'Massachusetts',
'MI'=>'Michigan',
'MN'=>'Minnesota',
'MS'=>'Mississippi',
'MO'=>'Missouri',
'MT'=>'Montana',
'NE'=>'Nebraska',
'NV'=>'Nevada',
'NH'=>'New Hampshire',
'NJ'=>'New Jersey',
'NM'=>'New Mexico',
'NY'=>'New York',
'NC'=>'North Carolina',
'ND'=>'North Dakota',
'OH'=>'Ohio',
'OK'=>'Oklahoma',
'OR'=>'Oregon',
'PA'=>'Pennsylvania',
'RI'=>'Rhode Island',
'SC'=>'South Carolina',
'SD'=>'South Dakota',
'TN'=>'Tennessee',
'TX'=>'Texas',
'UT'=>'Utah',
'VT'=>'Vermont',
'VA'=>'Virginia',
'WA'=>'Washington',
'WV'=>'West Virginia',
'WI'=>'Wisconsin',
'WY'=>'Wyoming',
'AS'=>'American Samoa',
'GU'=>'Guam',
'FM'=>'Federated States of Micronesia',
'MH'=>'Marshall Islands',
'MP'=>'Northern Mariana Islands',
'PW'=>'Palau',
'PR'=>'Puerto Rico',
'VI'=>'Virgin Islands',
'AE'=>'Armed Forces Africa \ Canada \ Europe \ Middle East',
'AA'=>'Armed Forces America (except Canada)',
'AP'=>'Armed Forces Pacific'
);
return strtr($state_code,$state_name);
}

?>
18 changes: 18 additions & 0 deletions tnrs3_db_scripts/functions/get_time.inc
@@ -0,0 +1,18 @@
<?php

//////////////////////////////////////
// Gets time in seconds
// Timer must have been started previously
//////////////////////////////////////

// Stop timer and get time
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);

// Calculate time elapsed in seconds
$tsecs = round($totaltime,2);

?>
4 changes: 3 additions & 1 deletion tnrs3_db_scripts/functions/sql_functions.inc
Expand Up @@ -1008,7 +1008,7 @@ function create_tables($create_sql,$drop_sql,$USER,$PWD,$DB){
}

/* Next version is better, but keep for now
function sql_execute_multiple($sqlmultiple) {
function sql_execute_multiple_bak($sqlmultiple) {
// executes one or more sql queries by exploding on ";"
$queries = explode(';', $sqlmultiple);
foreach($queries as $sql){
Expand All @@ -1021,6 +1021,8 @@ function sql_execute_multiple($sqlmultiple) {
function sql_execute_multiple($sqlmultiple) {
// executes one or more sql queries by exploding on ";"
// if any query fails, dies and reports error
// Note that there no need to wrap this in an error handler; it
// automatically dies and report error when any query fails
$queries = explode(';', $sqlmultiple);
foreach($queries as $sql){
$sql=trim($sql).";";
Expand Down
86 changes: 84 additions & 2 deletions tnrs3_db_scripts/functions/taxon_functions.inc
Expand Up @@ -503,8 +503,6 @@ function is_hybrid($taxon) {
}
}



function stdRankIndicator($str) {
// Transforms rank indicator in taxon names
// to standarized abbreviated form
Expand Down Expand Up @@ -585,4 +583,88 @@ function stdRankIndicator($str) {
return strtr($str,$arr);
}

function isRankIndicator($str) {
// Returns true if $str is a taxonomic rank indicator
$arr=array(
'agsp',
'agsp.',
'convar.',
'convar',
'cult.',
'cult',
'cultivar',
'cv',
'cv..',
'cv',
'fo.',
'fo',
'f.',
'forma',
'grex',
'lusus',
'monstr',
'nohtosubsp',
'nothogen',
'nothomorph',
'nothosect.',
'nothosect',
'nothoser.',
'nothoser',
'nothosubgen.',
'nothosubgen',
'nothosbgen',
'nothosbgen',
'nothosubsp.',
'nothosubsp.',
'nothosbsp.',
'nothosbsp.',
'nothossp.',
'nothossp',
'nothovar.',
'nothovar',
'proles',
'race',
'rasse',
'sect.',
'sect',
'ser',
'ser.',
'sport',
'stirps',
'subfo.',
'subfo',
'subf.',
'subf',
'subforma.',
'sbfo.',
'sbforma',
'subgen.',
'subgen',
'subsect',
'subsect.',
'subser.',
'subser',
'subsp',
'subsp.',
'sbsp.',
'sbsp',
'ssp.',
'ssp',
'subspecies',
'substirps',
'subvar.',
'subvar',
'supersect.',
'var',
'var.',
'variety'
);
if (in_array($str,$arr)) {
return true;
} else {
return false;
}
}


?>
29 changes: 11 additions & 18 deletions tnrs3_db_scripts/global_params.inc
Expand Up @@ -4,15 +4,14 @@
//////////////////////////////////////////////////
// Loading scripts for TNRS core database
//
// DB version: 3.5.2
// Last DB revision date: 23 May 2012
// DB version: 3.6.3
// Last DB revision date: 27 March 2014
// By: Brad Boyle
// Contact: bboyle@email.arizona.edu
// TNRS website: http://tnrs.iplantcollaborative.org/
//
// Key changes:
// - support for multiple sources of names,
// synonymy and classifications
// - Added tropicos_fixes/ (fixes problems with tropicos taxonomy)
//
// Everything you need to set is here and in local
// params.inc file in each import directory
Expand All @@ -36,13 +35,11 @@
// for that source.
//////////////////////////////////////////////////

// The follow configuration is for a test build using three example taxonomic
// sources provided:
// This will load all four sources
$src_array=array(
"usda_example",
"dwc_example",
"tropicos_example",
"gcc_example"
'tropicosExample',
'tropicosExample2',
'usdaExample'
);

//////////////////////////////////////////////////
Expand Down Expand Up @@ -88,16 +85,12 @@ require_once $local_utilities_path."class.normalize.php";
// Db connection info
//////////////////////////////////////////////////

// enter host here
// I recommend running as localhost
$HOST = "localhost";
// Explicit host name for display at runtime
$HOST=="localhost"?$HOSTNAME=exec('hostname -f'):$HOSTNAME=$HOST;
$USER = "tnrs_root";
$PWD = "rooter";
// Enter whatever your database will be called below.
// Database will be created if it doesn't exist (assuming you have full permissions)
$DB = "tnrs_test";
$USER = "";
$PWD = "";
$DB = "tnrs_test";

//////////////////////////////////////////////////
// Backup options
Expand All @@ -115,7 +108,7 @@ $use_db_backup=true;
// exist, it will be created; if it does exist, it will
// be replaced. Therefore, be VERY careful how you name
// this database!
$DB_BACKUP = "tnrs_test_backup"; // for testing
$DB_BACKUP = "tnrs_test_backup";

// Save a backup copy of staging table? This
// prevents staging table for current source
Expand Down
Expand Up @@ -16,7 +16,7 @@
// MUST BE UNIQUE
// NO SPACES
// MAX 50 characters
$sourceName="dwc_example";
$sourceName="dwcExample";

// Longer, more descriptive name for source
// Can have spaces; not used in any scripts
Expand Down Expand Up @@ -65,10 +65,10 @@ $fix_chars=true;
/////////////////////////////////////////////////////////////////////////////

// Path to data file
$filepath="import_dwc_example/data/";
$filepath="import_dwcExample/data/";

// Name of data file you will be importing
$namesfile = "dwc_example.csv";
$namesfile = "tnrs_dwc_example.txt";

// path + file
$namesfileandpath = $filepath.$namesfile;
Expand Down
Expand Up @@ -57,17 +57,18 @@ infraspecificRank *Required if name is an infraspecific trinomial (e.g.,
library of infraspecific rank indicators and their variants and will
attempt to standardize any variant abbreviations. Leave blank if taxon
is at rank of species or higher.
infraspecificEpithet Required if taxon is subspecies, variety, forma, etc. Subgeneric
taxa such as section and series (e.g., Psychotria sect. Notopleura)
can be entered by leaving specificEpithet NULL, entering the rank
indicator in infraspecificRank and epithet infraspecificEpithet.
infraspecificEpithet Required if taxon is subspecies, variety, forma, etc. Tribes and
subgeneric taxa such as section and series
(e.g., Psychotria sect. Notopleura) can be entered by leaving
specificEpithet NULL, entering the rank indicator in infraspecificRank
and epithet infraspecificEpithet.
infraspecificRank2 *Required if name is an infraspecific quadrinomial (e.g.,
"Silene laciniata ssp. major var. angustifolia"). Will be taxa of
"Silene laciniata ssp. major var. angustifolia"). These will be taxa of
ranks variety, forma, subforma, etc. Not directly
equivalent to any Darwin Core term. Controlled vocabulary as per
abbreviations as used in the ICBN Vienna code
(http://ibot.sav.sk/icbn/main.htm; see esp. Section 5):
"var.", "subvar.", "fo.", "subfo.".
"var.", "subvar.", "fo.", "subfo.", "cv.".
infraspecificEpithet2 *Required if taxon is an infraspecific quadrinomial (see
infraspecificRank2, above). Not directly equivalent to any Darwin Core
term. If used, infraspecificRank2 as well as all higher taxonomic name
Expand Down

0 comments on commit 3f6595b

Please sign in to comment.