12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978 |
- <?php
- include('tripal_gbrowse.align_features.inc');
- function tripal_gbrowse_menu() {
-
- $items = array();
-
- $items[ 'admin/tripal/tripal_gbrowse' ]= array(
- 'title' => t('GBrowse Management'),
- 'description' => ('GBrowse management allows a user to create a database, register
- a GBrowse instance and to load/delete feature libraries'),
- 'page callback' => 'tripal_gbrowse_administration_description_page',
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
- $items['admin/tripal/tripal_gbrowse/configuration'] = array(
- 'title' => t('Configuration'),
- 'description' => t('Configuration for this module'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_gbrowse_administration_form'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
- $items['admin/tripal/tripal_gbrowse/register_gbrowse'] = array(
- 'title' => t('Register GBrowse Instance'),
- 'description' => t('Interface to enter gbrowse details and save to the database'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_gbrowse_register_gbrowse_form'),
- 'access arguments' => array('administer site configuration'),
- 'weight' => 20,
- 'type' => MENU_NORMAL_ITEM
- );
-
- $items['admin/tripal/tripal_gbrowse/unregister_gbrowse']=array(
- 'title' => t('Un-Register GBrowse Instance'),
- 'description' => t('Interface to remove gbrowse details from the database'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_gbrowse_unregister_gbrowse_instances_form'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- $items['admin/tripal/tripal_gbrowse/load_library_features'] = array(
- 'title' => t('Load Library Features'),
- 'description' => t('Load features associated with a specified library into a GBrowse instance.'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_gbrowse_load_library_features_form'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- $items['admin/tripal/tripal_gbrowse/load_analysis_features'] = array(
- 'title' => t('Load Analysis Features'),
- 'description' => t('Load features associated with a specified analyses into a GBrowse instance.'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_gbrowse_load_analyses_form'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- $items['admin/tripal/tripal_gbrowse/delete_library_features']=array(
- 'title' => t('Delete Library Features'),
- 'description' => t('Interface to delete features of a given library from a GBrowse Instance'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_gbrowse_delete_library_features_from_gbrowse_form'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- $items['admin/tripal/tripal_gbrowse/delete_analysis_features']=array(
- 'title' => t('Delete Analysis Features'),
- 'description' => t('Interface to delete features of a given analysis from a GBrowse Instance'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_gbrowse_delete_analysis_features_from_gbrowse_form'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- $items['admin/tripal/tripal_gbrowse/add_tracks']=array(
- 'title' => t('Add Tracks'),
- 'description' => t('Interface for Adding tracks to a GBrowse Instance'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_gbrowse_add_tracks_form'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- $items['admin/tripal/tripal_gbrowse/delete_tracks']=array(
- 'title' => t('Delete Tracks'),
- 'description' => t('Interface for Deleting tracks from a GBrowse Instance'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_gbrowse_delete_tracks_form'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- $items['admin/tripal/tripal_gbrowse/align_features']=array(
- 'title' => t('Align Features'),
- 'description' => t('Align a group of features (either library or analysis) against another grouping of features.'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_gbrowse_align_features_form'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM
- );
- return $items;
- }
- function tripal_gbrowse_theme() {
-
- return array(
-
- 'tripal_gbrowse_database_details' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_gbrowse_database_details',
- ),
- 'tripal_gbrowse_details' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_gbrowse_details',
- ),
- 'tripal_gbrowse_gbrowse_instance' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_gbrowse_gbrowse_instance',
- ),
- 'tripal_gbrowse_teaser' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_gbrowse_teaser',
- ),
- 'tripal_gbrowse_loaded_sources' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_gbrowse_loaded_sources',
- ),
- );
- }
- function tripal_gbrowse_block ($op = 'list', $delta = 0, $edit=array()) {
- switch($op) {
- case 'list':
- $blocks['database_details']['info'] = t('Tripal GBrowse Database Details');
- $blocks['database_details']['cache'] = BLOCK_NO_CACHE;
- $blocks['details']['info'] = t('Tripal GBrowse Details');
- $blocks['details']['cache'] = BLOCK_NO_CACHE;
-
- $blocks['gbrowse_instance']['info'] = t('Tripal GBrowse Instance');
- $blocks['gbrowse_instance']['cache'] = BLOCK_NO_CACHE;
-
- $blocks['teaser']['info'] = t('Tripal GBrowse Teaser');
- $blocks['teaser']['cache'] = BLOCK_NO_CACHE;
-
- $blocks['teaser']['info'] = t('Tripal GBrowse Sources');
- $blocks['teaser']['cache'] = BLOCK_NO_CACHE;
-
- return $blocks;
- case 'view':
- if(user_access('access tripal_gbrowse content') and arg(0) == 'node' and is_numeric(arg(1))) {
- $nid = arg(1);
- $node = node_load($nid);
-
- $block = array();
- switch($delta){
- case 'database_details':
- $block['subject'] = t('Tripal GBrowse Database Details');
- $block['content'] = theme('tripal_gbrowse_database_details',$node);
- break;
-
- case 'details':
- $block['subject'] = t('Tripal GBrowse Details');
- $block['content'] = theme('tripal_gbrowse_details',$node);
- break;
-
- case 'gbrowse_instance':
- $block['subject'] = t('Tripal GBrowse Instance');
- $block['content'] = theme('tripal_gbrowse_gbrowse_instance',$node);
- break;
-
- case 'teaser':
- $block['subject'] = t('Tripal GBrowse Teaser');
- $block['content'] = theme('tripal_gbrowse_teaser',$node);
- break;
-
- case 'teaser':
- $block['subject'] = t('Tripal GBrowse Sources');
- $block['content'] = theme('tripal_gbrowse_loaded_sources',$node);
- break;
-
- }
- return $block;
- }
- }
- }
-
- function tripal_gbrowse_views_api() {
- return array(
- 'api' => 2.0,
- );
- }
- function tripal_gbrowse_administration_description_page() {
- $text = ' ';
- $text .= '</p><h3>GBrowse Feature Administrative Tools Quick Links:</h3>';
-
- $text .= "<ul>";
-
- $text .= "<li>".l("Configuration", "admin/tripal/tripal_gbrowse/configuration"). "</li>";
- $text .= "<li>".l('Register GBrowse Instance', 'node/add/tripal-gbrowse')."</li>";
- $text .= "<li>".l("Load Library Features", "admin/tripal/tripal_gbrowse/load_library_features"). "</li>";
- $text .= "<li>".l("Delete Library Features", "admin/tripal/tripal_gbrowse/delete_library_features"). "</li>";
- $text .= "<li>".l("Load Analysis Features", "admin/tripal/tripal_gbrowse/load_analysis_features"). "</li>";
- $text .= "<li>".l("Delete Analysis Features", "admin/tripal/tripal_gbrowse/delete_analysis_features"). "</li>";
- $text .= "<li>".l("Add Tracks","admin/tripal/tripal_gbrowse/add_tracks"). "</li>";
- $text .= "<li>".l("Delete Tracks","admin/tripal/tripal_gbrowse/delete_tracks"). "</li>";
-
- $text .= "</ul>";
-
- $text .= '<h3>Module Description:</h3>';
- $text .= '<p>This module provides an interface to register already existing GBrowse instances with Drupal/Tripal and/or create new '
- .'GBrowse Instances. Furthermore, it allows basic management of these GBrowse instances including un-registering and/or '
- .'deleting and loading of features in Tripal/Chado into a MySQL GBrowse instance. As such, it provides interoperability '
- .'and syncronization between a Tripal/Chado installation and GBrowse</p>';
- $text .= '<h3>Setup Instructions:</h3>';
- $text .= '<ol>';
- $text .= '<li><b>Ensure the PHP-MySQL extension is installed:</b> Installation instructions are dependant upon your operating system.</li>';
- $text .= '<li><b>Move Template Configuration File:</b> Move the template.conf file included with this module into the GBrowse configuration file directory.</li>';
- $text .= '<li><b>Set GBrowse Instance Defaults :</b> Set default repository for Configuration files, also set the default GBrowse web link address.</li>'
- .'<a href="tripal_gbrowse/configuration">Administration -> Tripal Management -> GBrowse Management -> Configuration</a>.</li>';
-
- $text .= '<li><b>Register Existing GBrowse Instances</b>: Register any existing GBrowse instances through the form provided at '
- .'<a href="tripal_gbrowse/register_gbrowse">Administration -> Tripal Management -> GBrowse Management -> Register GBrowse Instance</a>.</li>';
- $text .= '<li><b>Load desired Feature Libraries into GBrowse Instances</b>: Additional feature libraries should be loaded through the form provided at '.l('Administration -> Tripal Management -> GBrowse Management -> Load Features','admin/tripal/tripal_gbrowse/load_features').'</li>';
- $text .= '<ol>';
-
- $text .= '<h3>Features of this Module:</h3>';
- $text .= '<ul>';
- $text .= '<li><b>Register GBrowse Instance:</b> In order to load features into a GBrowse instance you need to first register it with Tripal/Drupal. Any existing '
- .'GBrowse instance that utilizes a MySQL database can be registered with the module. Furthermore, you can create new GBrowse Instances '
- .'through this module by selecting that option in the register GBrowse Instance form. This'
- .'newly created GBrowse instance uses a MySQL database with is created and '
- .'a user name and password is setup and a default configuration file is created. Finally, the database is initialized and the first sequence '
- .'set is loaded into the GBrowse instance.</li>';
-
- $text .= '<li><b>Un-Register/Delete GBrowse Instance:</b> Un-registering a GBrowse instance alone will remove the GBrowse instance from the Drupal site.'
- .'When removing the entire instance, the database and the configuration file will be deleted. This cannot be undone!</li>';
-
- $text .='<li><b>Intergrated GBrowse Node/Page:</b> Allows users to easily access GBrowse instances that have been created.'
- .'This module provides details for a registered GBrowse Instance, including an I-Frame, providing instance access to the GBrowse display,'
- .'as well,the module provides a link to a GBrowse instance in a new window.</li>';
-
- $text .= '<li><b>Load Library Features:</b> Simply by selecting a Tripal Library and a GBrowse Instance, '
- .'the features associated with the selected Library are loaded into the selected GBrowse Instance. Libraries can also be updated by selecting that option. This removes all of the pre-existing'
- .'features associated with that library, then reloades them. Both loading and updating utilize the Perl script "bp_seqfeature_load.pl" which should be installed when you install GBrowse.</li>';
-
- $text .= '<li><b>Load Analysis Features:</b> Simply by selecting a Tripal Analysis and a GBrowse Instance, '
- .'the analyses associated with the selected Library are loaded into the selected GBrowse Instance. Analyses can also be updated by selecting that option. This removes all of the pre-existing'
- .'features associated with that analysis, then reloades them. Both loading and updating utilize the Perl script "bp_seqfeature_load.pl" which should be installed when you install GBrowse.</li>';
-
- $text .= '<li><b>Delete Feature (Libraries) Libraries:</b> A user can select a desired Tripal Library and a specific GBrowse instance and all of the features associated with that library in the selected isntance are removed.'
- .' This section uses the Perl "script bp_seqfeature_delete.pl" to delete the specified features.</li>';
- $text .= '<li><b>Delete (Libraries) Analysis :</b> A user can select a desired Tripal Analysis and a specific GBrowse instance and all of the features associated with that analysis in the selected isntance are removed.'
- .' This section uses the Perl "script bp_seqfeature_delete.pl" to delete the specified features.</li>';
-
- $text .= '<li><b>Add Tracks:</b> Allows a user to add tracks to a given GBrowse instance. This allows them to define exactly how they want their features to be displayed, as well as, to separate their features into their own GBrowse track.</li>';
-
- $text .= '<li><b>Delete Tracks:</b> Allows a user to delete default tracks or user created tracks for a given GBrowse instance.</li>';
-
- $text .= '</ul>';
-
- return $text;
- }
- function tripal_gbrowse_job_describe_args($call_back, $args){
- switch ($call_back){
-
- case 'tripal_gbrowse_delete_library_features_from_gbrowse':
-
- $new_args['GBrowse Database Name']=$args[0];
-
- $new_args['User Name']=$args[1];
-
- $new_args['Password']=$args[2];
- $result = db_fetch_object(db_query("SELECT nid FROM chado_library WHERE library_id=%d",$args[3]));
-
- $node = node_load($result->nid);
-
- $new_args['Library']= l($node->title, 'node/'.$result->nid);
-
- if(empty($args[4])){
- $new_args['Clear GBrowse Database']= 'No';
- }else{
- $new_args['Clear GBrowse Database']= 'Yes';
- }
-
- break;
-
- case 'tripal_gbrowse_load_library_features_into_gbrowse':
-
- $new_args['GBrowse Database Name']=$args[0];
-
- $new_args['User Name']=$args[1];
-
- $new_args['Password']=$args[2];
-
- $result = db_fetch_object(db_query("SELECT nid FROM chado_library WHERE library_id=%d",$args[3]));
-
- $node = node_load($result->nid);
-
- $new_args['Library']= l($node->title, 'node/'.$result->nid);
-
- if(empty($args[4])){
- $new_args['Clear GBrowse Database']= 'No';
- }else{
- $new_args['Clear GBrowse Database']= 'Yes';
- }
-
- break;
-
- case 'tripal_gbrowse_delete_analysis_features_from_gbrowse':
-
- $new_args['GBrowse Database Name']=$args[0];
-
- $new_args['User Name']=$args[1];
-
- $new_args['Password']=$args[2];
- $result = db_fetch_object(db_query("SELECT nid FROM chado_analysis WHERE analysis_id=%d",$args[3]));
-
- $node = node_load($result->nid);
-
- $new_args['Analysis']= l($node->title, 'node/'.$result->nid);
-
- if(empty($args[4])){
- $new_args['Clear GBrowse Database']= 'No';
- }else{
- $new_args['Clear GBrowse Database']= 'Yes';
- }
-
- break;
-
- case 'tripal_gbrowse_load_analysis_features_into_gbrowse':
-
- $new_args['GBrowse Database Name']=$args[0];
-
- $new_args['User Name']=$args[1];
-
- $new_args['Password']=$args[2];
-
- $result = db_fetch_object(db_query("SELECT nid FROM chado_analysis WHERE analysis_id=%d",$args[3]));
-
- $node = node_load($result->nid);
-
- $new_args['Analysis']= l($node->title, 'node/'.$result->nid);
-
- if(empty($args[4])){
- $new_args['Clear GBrowse Database']= 'No';
- }else{
- $new_args['Clear GBrowse Database']= 'Yes';
- }
-
- break;
-
- }
- return $new_args;
- }
- function tripal_gbrowse_getloaded_sources($gbrowse){
- $loaded_libraries = array();
-
- $link = mysql_connect('localhost', $gbrowse->database_user, $gbrowse->user_password);
-
- if (!$link) {
- drupal_set_message('Could not connect to database: ' . mysql_error(), 'error');
- }
-
-
- $resource = mysql_query('use ' .$gbrowse->database_name);
-
- if (empty($resource)) {
- drupal_set_message ('Database is empty or Non-existent','error');
- }
-
- $resource = mysql_query('select * from typelist');
-
- if (empty($resource)) {
- drupal_set_message ('Missing table typelist in database. Check sequence backbone has been loaded (Execute: tripal jobs) ','error');
- } else {
-
- $library_array = array();
-
- while($record = mysql_fetch_object($resource)){
- preg_match('/^[^:]+:(.+)/', $record->tag, $matches);
- $library_array[$matches[1]]= $matches[1];
- }
- }
- mysql_close($link);
- return $library_array;
- }
- function tripal_gbrowse_database_modification($node,$old_database){
-
- global $user;
-
- $user_name = $node->database_user;
-
- $user_password = $node->user_password;
-
-
- $back_upfile = '/tmp/' .$old_database .'_'.time().'.sql';
-
-
- $command = 'mysqldump -u' .$user_name .' -p' .$user_password .' ' .$old_database .' > ' .$back_upfile;
-
- exec($command);
-
-
- $link = mysql_connect('localhost', $user_name,$user_password);
-
-
- if (!$link) {
- drupal_set_message('Could not connect: ' . mysql_error(), 'error');
- return false;
- }
-
- $sql = 'DROP DATABASE ' . $old_database;
-
- if(mysql_query($sql, $link)){
- drupal_set_message( "Database Dropped Successfully\n");
- }else{
- drupal_set_message( 'Error Dropping Database: ' . mysql_error(), 'error');
- return false;
- }
- $sql = 'CREATE DATABASE ' . $node->database_name;
- if (mysql_query($sql, $link)) {
- drupal_set_message( "Database Created Successfully\n");
- }
- else {
- drupal_set_message( 'Error Creating Database: ' . mysql_error() . "\n");
- return false;
- }
- mysql_query( "GRANT SELECT ON " .$node->database_name.".* TO 'www-data'@'localhost'",$link);
-
- $command = 'mysql -u' .$user_name .' -p' .$user_password .' ' .$node->database_name .' < ' .$back_upfile;
-
- exec($command);
-
- mysql_close($link);
-
- }
- function tripal_gbrowse_node_info() {
- return array(
- 'tripal_gbrowse' => array(
- 'name' => t('GBrowse Instance'),
- 'module' => 'tripal_gbrowse',
- 'description' => t('A module for interfacing the GMOD database with Drupal, providing:
- Registration,Alteration and Deletion of GBrowse Instances,Configuration Files and Databases
- and the option to load/delete Sequence & Analysis Libraries'),
- 'has_title' => TRUE,
- 'title_label' =>t('gbrowse Name'),
- 'had_body' => FALSE,
- )
- );
- }
- function tripal_gbrowse_form(&$node, $form_state) {
-
- $type = node_get_types('type', $node);
-
- $form['register_gbrowse'] = array(
- '#type' => 'fieldset',
- '#title' => t('Data Base Specific Fields'),
- );
-
-
- $form['register_gbrowse']['database_name'] = array(
- '#type' => 'textfield',
- '#title' => t('GBrowse Database Name'),
- '#size' => 30,
- '#maxlength' => 64,
- '#description' => t('Desired Database Name Field'),
- '#default_value' => isset($node->gbrowse->database_name) ? $node->gbrowse->database_name : '',
- '#required' => TRUE,
- );
-
-
- $form['register_gbrowse']['database_user'] = array(
- '#type' => 'textfield',
- '#title' => t('GBrowse User'),
- '#size' => 30,
- '#maxlength' => 64,
- '#description' => t('GBrowse MySQL User Field'),
- '#default_value' => isset($node->gbrowse->database_user) ? $node->gbrowse->database_user : '',
- '#required' => TRUE,
- );
-
-
- $form['register_gbrowse']['user_password'] = array(
- '#type' => 'password',
- '#title' => t('Password'),
- '#size' => 30,
- '#maxlength' => 64,
- '#description' => t('User Password Field'),
- '#default_value' => isset($node->gbrowse->user_password) ? $node->gbrowse->user_password : '',
- '#required' => TRUE,
- );
-
-
- $form['gbrowse_details'] = array(
- '#type' => 'fieldset',
- '#title'=>'GBrowse Specifications' ,
- );
-
-
- $form['gbrowse_details']['title'] = array(
- '#type' => 'textfield',
- '#title' => t('GBrowse Name'),
- '#size' => 30,
- '#maxlength' => 256,
- '#description' => t('GBrowse Instance'),
- '#default_value' => isset($node->gbrowse->gbrowse_name) ? $node->gbrowse->gbrowse_name : '',
- '#required' => TRUE,
- );
-
-
- $default_value = variable_get('tripal_gbrowse_gbrowse_address_stub', '');
-
-
- $form['gbrowse_details']['gbrowse_link'] = array(
- '#type' => 'textfield',
- '#title' => t('GBrowse Link'),
- '#size' => 30,
- '#maxlength' => 256,
- '#description'=>t('Enter Full HTML address Including Host
- (ex:http://knowpulse2.usask.ca/) of the new GBrowse instance. By default this is '.$default_value.'[configuration file name] where the configuration file name is the same as that entered below except without .conf'),
- '#default_value' => isset($node->gbrowse->gbrowse_link) ? $node->gbrowse->gbrowse_link : $default_value,
- '#required' => TRUE,
- );
-
- $form['gbrowse_details']['config_file'] = array(
- '#type' => 'textfield',
- '#title' => t('Configuration File'),
- '#size' => 30,
- '#maxlength' => 256,
- '#description' => t('Enter Fully Qualified File Name including Path (ex: file.conf) '),
- '#default_value' => isset($node->gbrowse->config_file) ? $node->gbrowse->config_file : variable_get('tripal_gbrowse_configuration_file_path', ''),
- '#required' => TRUE,
- );
-
- $result = tripal_core_chado_select ( 'library', array('library_id','name'), array() );
- foreach ($result as $value) {
-
- $newArray[$value->library_id]=$value->name;
-
- }
-
- if (!$node->gbrowse->gbrowse_id) {
-
-
- $form['create_instance'] = array(
- '#type' => 'fieldset',
- '#title' => t('Create New GBrowse Instance'),
- );
-
- if(empty($newArray)){
-
- drupal_set_message('There are currently no libraries to load.','error');
-
- $form['create_instance']['check_box'] = array(
- '#type' => 'item',
- '#value'=>'A GBrowse instance can not be created without a valid loadable backbone.
- To make a valid loadable backbone available, please load features grouped in a library using
- any of the feature loaders available.'
- );
-
-
- }else {
-
-
- $form['create_instance']['check_box'] = array(
- '#type' => 'checkbox',
- '#title' => t('Create Instance'),
- '#description' => t('Create GBrowse Instane Unless Previous Existance'),
- );
-
-
- $form['create_instance']['library_id'] = array(
- '#type' => 'select',
- '#title' => t('Sequence BackBone'),
- '#options' => $newArray,
- '#description' => t('Sequence Features Locations'),
- );
- }
-
- }
-
- return $form;
-
- }
- function tripal_gbrowse_validate ($node, $form) {
- if (!preg_match('/\.conf$/',$node->config_file)) {
- form_set_error('config_file','Configuration file must end in .conf');
- }
-
- if (!preg_match('/^http:\/\//',$node->gbrowse_link)) {
- form_set_error('gbrowse_link','GBrowse Link must be an absolute path (include http://)');
- }
- }
- function tripal_gbrowse_help($path, $arg) {
- switch ($path) {
-
- case 'admin/help#tripal_gbrowse':
-
- return '<p>'. t('Module created by:Chad Krilow (e-mail:cnk046@mail.usask.ca)') .'</p>';
-
- break;
- }
- }
- function tripal_gbrowse_perm(){
- return array('create tripal_gbrowse', 'edit own tripal_gbrowse', 'access database-related details' ,'access tripal_gbrowse content');
- }
- function tripal_gbrowse_access($op, $node, $account) {
- if($op == 'create') {
-
- if(!user_access('create tripal_gbrowse', $account)){
- return FALSE;
- }
- }
-
-
- if($op == 'update' || $op == 'delete') {
- if(!user_access('edit own tripal_gbrowse',$account)){
- return FALSE;
- }
- if(user_access('edit own tripal_gbrowse',$account) &&
- $account->uid != $node->uid){
- return FALSE;
- }
- }
- return NULL;
- }
- function tripal_gbrowse_insert($node) {
-
- $values = array(
- 'database_name'=> $node->database_name,
- 'database_user'=> $node->database_user,
- 'user_password'=> $node->user_password,
- 'gbrowse_name'=> $node->title,
- 'gbrowse_link'=> $node->gbrowse_link,
- 'config_file'=> $node->config_file,
- 'library_id'=>$node->library_id,
- 'nid'=>$node->nid,
- 'vid'=>$node->vid,
- );
-
-
- drupal_write_record('tripal_gbrowse_instances', $values);
-
- if($node->check_box==1){
- tripal_gbrowse_create_gbrowse_instance($values);
- }else{
- drupal_set_message("Create instance check box not selected, unable initialize instance");
- }
-
- }
- function tripal_gbrowse_delete($node){
-
- if(variable_get('tripal_gbrowse_delete_all', '')){
- tripal_gbrowse_delete_gbrowse_instance($node->gbrowse);
- }
-
-
- db_query('DELETE FROM {tripal_gbrowse_instances} WHERE nid = %d', $node->nid);
-
- }
- function tripal_gbrowse_update($node){
-
-
- $old_data = db_fetch_object(
- db_query('SELECT database_name,config_file FROM {tripal_gbrowse_instances} WHERE nid=%d AND vid=%d',
- $node->nid, $node->vid));
-
- $old_config_file=$old_data->config_file;
-
- $old_database_name=$old_data->database_name;
-
- $match= array(
- 'nid',
- 'vid',
- );
-
- $values = array(
- 'database_name' => $node->database_name,
- 'database_user' => $node->database_user,
- 'user_password' => $node->user_password,
- 'gbrowse_name' => $node->gbrowse_name,
- 'gbrowse_link' => $node->gbrowse_link,
- 'config_file' => $node->config_file,
- 'library_id'=>$node->library_id,
- 'nid' => $node->nid,
- 'vid' => $node->vid,
- );
-
-
- $config_file = $node->config_file;
-
- if(strcmp($old_config_file, $config_file)!=0){
-
- $command = "mv " .$old_config_file ." ".$config_file;
- exec($command);
- }
- if($old_database_name != $node->database_name){
- tripal_gbrowse_database_modification($node,$old_database_name);
- }
- drupal_write_record('tripal_gbrowse_instances', $values, $match);
- }
- function tripal_gbrowse_load($node) {
-
- $result = db_fetch_object(db_query('SELECT gbrowse_id,database_name,database_user,user_password,
- gbrowse_name,gbrowse_link,config_file FROM {tripal_gbrowse_instances} WHERE nid=%d AND vid=%d',$node->nid, $node->vid));
-
- $node->gbrowse = $result;
-
- return $node;
- }
- function tripal_gbrowse_administration_form () {
-
-
- $form['configuration_features'] = array(
- '#type' => 'fieldset',
- '#title' => t('Module Configuration Fields'),
- );
-
-
- $form['configuration_features']['configuration_file'] = array(
- '#type' => 'textfield',
- '#title' => t('Set Default Configuration File Directory'),
- '#size' => 30,
- '#maxlength' => 64,
- '#description' => t('Specific Configuration File Directory'),
- '#default_value' => variable_get('tripal_gbrowse_configuration_file_path', ''),
- );
-
-
- $form['configuration_features']['gbrowse_address'] = array(
- '#type' => 'textfield',
- '#title' => t('Set Default GBrowse Web Address'),
- '#size' => 30,
- '#maxlength' => 64,
- '#description' => t('Desired GBrowse web address'),
- '#default_value' => variable_get('tripal_gbrowse_gbrowse_address_stub', ''),
- );
-
-
- $form['configuration_features']['delete_check_box'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete Instance'),
- '#description' => t('Delete GBrowse Configuration file and Database '),
- '#default_value'=>variable_get('tripal_gbrowse_delete_all', ''),
- );
- $form['configuration_features']['submit'] = array(
- '#type' => 'submit',
- '#weight' => 10,
- '#value' => t('Submit')
- );
-
- return $form;
- }
- function tripal_gbrowse_administration_form_validate ($form, $form_state) {
-
- if ( !valid_url($form_state['values']['gbrowse_address'])) {
- form_set_error('gbrowse_address', 'Invalid URL');
- }
- }
- function tripal_gbrowse_administration_form_submit ($form, $form_state) {
- if(!preg_match('/\/$/', $form_state['values']['configuration_file'])) {
- $form_state['values']['configuration_file'] = $form_state['values']['configuration_file'] . "/";
- }
- variable_set('tripal_gbrowse_configuration_file_path',$form_state['values']['configuration_file'] );
- drupal_set_message('Configuration File Path set to: '.variable_get('tripal_gbrowse_configuration_file_path', ''));
-
-
- variable_set('tripal_gbrowse_gbrowse_address_stub',$form_state['values']['gbrowse_address'] );
- drupal_set_message('GBrowse Default Address set to: '.variable_get('tripal_gbrowse_gbrowse_address_stub', ''));
-
- if($form_state['values']['delete_check_box']==1){
- variable_set('tripal_gbrowse_delete_all',$form_state['values']['delete_check_box'] );
- drupal_set_message('Selected GBrowse instance will be deleted: '.variable_get('tripal_gbrowse_delete_all', 'NOT SET'));
- }
- }
- function tripal_gbrowse_create_gbrowse_instance($values) {
-
- global $user;
-
-
- if ( file_exists($values['config_file']) ){
- drupal_set_message('Configuration File Already Exists', 'warning');
- }else{
-
- $config_path = variable_get('tripal_gbrowse_configuration_file_path', '');
-
- if(empty($config_path)){
- drupal_set_message( "Invalid or Non-Existent Configuration Path (Check Configuration Menu Defaults)", 'error');
- }
-
- $temp_file = '/tmp/temporary_gbrowse_'.time().'.conf';
-
-
-
- $command = "sed '2 s/<#gbrowse_name#>/".$values['gbrowse_name']."/' ".$config_path."template.conf > ".$temp_file;
- exec($command);
-
-
-
- $command = "sed '5 s/<#database_name#>/".$values['database_name']."/' ".$temp_file." > ".$values['config_file'];
- exec($command);
-
-
- if (file_exists($values['config_file'])) {
- drupal_set_message('Configuration File created successfully');
- } else {
- drupal_set_message('Unable to create configuration file','error');
- }
-
- $link = mysql_connect('localhost', $values['database_user'],$values['user_password']);
-
- if (!$link) {
- drupal_set_message('Could not connect: ' . mysql_error());
- return false;
- }
- $sql = 'CREATE DATABASE ' . $values['database_name'];
- if (mysql_query($sql, $link)) {
- drupal_set_message( "Database created successfully\n");
- } else {
- drupal_set_message( 'Error creating database: ' . mysql_error() . "\n");
- return false;
- }
-
- mysql_query( "GRANT SELECT ON " .$values['database_name'].".* TO 'www-data'@'localhost'",$link);
-
- mysql_close($link);
- $job_args=array($values['database_name'],$values['database_user'],$values['user_password'],$values['library_id'],TRUE);
-
-
- $job_id = tripal_add_job('Loading Features Into GBrowse', 'tripal_gbrowse','tripal_gbrowse_load_library_features_into_gbrowse', $job_args, $user->uid);
- drupal_set_message(' The Backbone needs to be loaded into GBrowse (done by executing Tripal Jobs Loading script),
- Before loaded libraries or GBrowse Instance will be displayed. ');
- }
-
- }
- function tripal_gbrowse_delete_gbrowse_instance($gbrowse) {
-
-
- $gbrowse_instance = db_fetch_object(
- db_query('SELECT * FROM {tripal_gbrowse_instances} WHERE gbrowse_id=%d', $gbrowse->gbrowse_id )
- );
-
-
- $config_file = $gbrowse->config_file;
-
-
- $command = "rm ".$config_file;
- exec($command);
-
- if (file_exists($config_file)) {
- drupal_set_message('Configuration File ('.$config_file.') not removed!', 'error');
- } else {
- drupal_set_message('Configuration File removed successfully');
- }
-
- $user_name = $gbrowse->database_user;
-
- $user_password = $gbrowse->user_password;
- $link = mysql_connect('localhost', $user_name,$user_password);
-
- if (!$link) {
- drupal_set_message('Could not connect: ' . mysql_error(), 'error');
- return false;
- }
- $sql = 'DROP DATABASE ' . $gbrowse->database_name;
-
- if(mysql_query($sql, $link)){
- drupal_set_message( "Database removed successfully\n");
- }else{
- drupal_set_message( 'Error removing database: ' . mysql_error(), 'error');
- return false;
- }
-
- mysql_close($link);
-
- }
- function tripal_gbrowse_load_library_features_form() {
-
- $new_array=array();
-
- $result = tripal_core_chado_select ( 'library', array('library_id','name'), array() );
-
- foreach ($result as $value) {
- $new_array[$value->library_id]=$value->name;
- }
-
-
- $form['load_features'] = array(
- '#type' => 'fieldset'
- );
-
-
- $form['load_features']['library_id'] = array(
- '#type' => 'select',
- '#title' => t('Libraries'),
- '#options' => $new_array,
- '#description' => t('Library of Genetic Sequences.'),
- );
-
-
- $resource = db_query('SELECT * FROM {tripal_gbrowse_instances}');
- $items = array();
-
- while($record = db_fetch_object($resource)){
- $items[$record->gbrowse_id]= $record->gbrowse_name;
- }
-
-
- $form['load_features']['gbrowse_id'] = array(
- '#type' => 'select',
- '#title' => t('GBrowse Instances'),
- '#options' => $items,
- '#description' => t('Selected GBrowse Instances to be Loaded.'),
- );
-
-
- $form['load_features']['check_box'] = array(
- '#type' => 'checkbox',
- '#title' => t('Update Features'),
- '#description' => t('Existing Same Name Features Updated Accordingly.'),
- );
- $form['load_features']['submit'] = array(
- '#type' => 'submit',
- '#weight' => 10,
- '#value' => t('Submit Job')
- );
-
- return $form;
- }
- function tripal_gbrowse_load_library_features_form_submit($form,$form_state) {
-
- global $user;
-
- $record = db_fetch_object(db_query('SELECT * FROM {tripal_gbrowse_instances} WHERE gbrowse_id=%d', $form_state['values']['gbrowse_id']));
-
- $name = $record->database_name;
- $user_name = $record->database_user;
- $password= $record->user_password;
- $job_args = array($name,$user_name,$password,$form_state['values']['library_id'], FALSE);
-
-
- if($form_state['values']['check_box']==1){
-
- $job_id = tripal_add_job('Deleting Features From GBrowse', 'tripal_gbrowse',
- 'tripal_gbrowse_delete_library_features_from_gbrowse', $job_args, $user->uid);
- }
-
-
- $job_id = tripal_add_job('Loading Features Into GBrowse', 'tripal_gbrowse',
- 'tripal_gbrowse_load_library_features_into_gbrowse', $job_args, $user->uid);
- }
- function tripal_gbrowse_load_library_features_into_gbrowse($database_name, $user_name, $password, $library_id,$clear_database){
-
- $myFile = "/tmp/temporaryGBrowse_".time().".gff3";
-
-
- $fh = fopen($myFile, 'w') or die("WARNING: Can not open file");
- print "Creating GFF3 file of features for library...\n";
-
- if (!preg_match('/^\d+$/', $library_id)) {
- print "ERROR: Invalid Library ID supplied (Library ID = ".$library_id.")\n";
- return false;
- }
-
-
- $values = array('library_id' => $library_id);
-
- $prime_result = tripal_core_chado_select ( 'library_feature', array('feature_id'), $values );
-
- $result = tripal_core_chado_select ( 'library', array('uniquename'), $values );
- $source = $result[0]->uniquename ;
-
-
-
- foreach ($prime_result as $value) {
- $feature_id = $value->feature_id;
-
- if (!preg_match('/^\d+$/', $feature_id)) {
- print "ERROR: Invalid feature ID (".$feature_id.") associated with Library (Library ID = ".$library_id.")\n";
- }
-
- $result = tripal_core_chado_select('feature', array('type_id'), array('feature_id'=>$feature_id));
-
- $type_id = $result[0]->type_id;
-
- if (empty($type_id)) {
- print "ERROR: No Type associated with Feature (Feature ID = ".$feature_id.")\n";
- }
-
-
- $result = tripal_core_chado_select('cvterm', array('name'), array('cvterm_id'=>$type_id));
-
- $type = $result[0]->name;
-
- if (empty($type)) {
- print "ERROR: Type associated with Feature (".$type_id.") doesn't exist in cvterm table (Feature ID = ".$feature_id.")\n";
- }
-
-
-
- $result = tripal_core_chado_select('featureloc', array('fmin','fmax', 'strand', 'phase', 'srcfeature_id'), array('feature_id'=>$feature_id));
-
- $start = $result[0]->fmin;
- if (!preg_match('/^\d+$/', $start)) {
- print "ERROR: Invalid Start (".$start.") of Feature (Feature ID= ".$feature_id.")\n";
- }
-
- $end = $result[0]->fmax;
- if (!preg_match('/^\d+$/', $end)) {
- print "ERROR: Invalid End (".$end.") of Feature (Feature ID= ".$feature_id.")\n";
- }
-
- $score = '.';
-
- if ($result[0]->strand < 0) {
-
- $strand= '-';
- } elseif ($result[0]->strand == 0) {
-
- $strand = '.';
- } elseif($result[0]->strand > 0) {
-
- $strand = '+';
- } else{
-
- $strand = '.';
- }
-
-
- $phase = $result[0]->phase;
- if(empty($phase)){
- $phase = '.';
- }
-
-
-
- $srcfeature_id = $result[0]->srcfeature_id;
- if (empty($srcfeature_id)) {
- print "ERROR: No Parent associated with Feature Location (Feature ID = ".$feature_id.")\n";
- }
-
- $result = tripal_core_chado_select('feature', array('name'), array('feature_id'=>$srcfeature_id));
-
- $seqid = $result[0]->name;
- if (empty($seqid)) {
- print "ERROR: Parent (Parent Feature ID = ".$seqid.") associated with Feature doesn't exist in feature table (Feature ID =".$feature_id."\n";
- }
-
-
- $result = tripal_core_chado_select('feature', array('uniquename', 'name'), array('feature_id'=>$feature_id));
-
- $id = $result[0]->uniquename;
-
- if (empty($id)) {
- print "ERROR: Missing Unique Name for Feature (Feature ID = ".$feature_id.")\n";
- }
- $name = $result[0]->name;
-
- if (empty($name)) {
- print "WARNING: Missing Name for Feature (Feature ID = ".$feature_id.")\n";
- }
-
-
- $result = tripal_core_chado_select('feature_synonym', array('synonym_id'), array('feature_id'=>$feature_id));
- $synonyms = array();
- foreach ($result as $obj){
-
- $synonym_id = $obj->synonym_id;
-
- $sub_result = tripal_core_chado_select('synonym', array('name'), array('synonym_id'=>$synonym_id));
-
- if (empty($sub_result[0]->name)) {
- print "ERROR: Synonym (".$synonym_id.") associated with feature not found in synonym table (Feature ID = ".$feature_id.")\n";
- } else {
- $synonyms[] = $sub_result[0]->name;
- }
- }
-
-
- $result = tripal_core_chado_select('feature_dbxref', array('dbxref_id'), array('feature_id'=>$feature_id));
- $dbxref = array();
-
- foreach ($result as $obj){
-
- $dbxref_id = $obj->dbxref_id;
-
- if (!empty($dbxref_id)) {
- $sub1_result = tripal_core_chado_select('dbxref', array('db_id', 'accession'), array('dbxref_id'=>$dbxref_id));
-
- $dbxref_accession = $sub1_result[0]->accession;
-
- $db_id = $sub1_result[0]->db_id;
-
- if (!empty($db_id)) {
- $sub_sub_result =tripal_core_chado_select('db', array('name'), array('db_id'=>$db_id));
-
- $db_name = $sub_sub_result[0]->name;
-
- if (empty($db_name)) {
- print "ERROR: Database (".$db_id.") associated with database reference not in db table (Database Reference ID = ".$dbxref_id.")\n";
- } elseif (empty($dbxref_accession)) {
- print "WARNING: Missing Accession for Database Reference (Database Reference ID = ".$dbxref_id.")\n";
- } else {
- $dbxref[] = $db_name . ':' . $dbxref_accession;
- }
- }
- }
- }
-
- $result = tripal_core_chado_select('feature', array('dbxref_id'), array('feature_id'=>$feature_id));
-
- $dbxref_id = $result[0]->dbxref_id;
-
- if (empty($dbxref_id)) {
- print "WARNING: No Database Reference associated directly with Feature (Feature ID = ".$feature_id.")\n";
- }
- $result = tripal_core_chado_select('dbxref', array('accession','db_id'), array('dbxref_id'=>$dbxref_id));
-
- $dbxref_accession = $result[0]->accession;
-
- if(!empty($dbxref_accession)){
- $db_id = $result[0]->db_id;
-
- $sub_sub_result =tripal_core_chado_select('db', array('name'), array('db_id'=>$db_id));
- $db_name = $sub_sub_result[0]->name;
-
- $dbxref[] = $db_name . ':' . $dbxref_accession;
- } else {
- print "WARNING: Missing Accession for Database Reference (Database Reference ID = ".$dbxref_id.")\n";
- }
-
- $attributes = array();
- $attributes[] = 'ID='.$id;
- if (!empty($name)) { $attributes[] = 'Name='.$name; }
- if (!empty($synonyms)) { $attributes[] = 'Alias='.implode(',',$synonyms); }
- if (!empty($dbxref)) { $attributes[] = 'Dbxref=' .implode(',', $dbxref); }
-
- $stringData = implode("\t", array($seqid,$source,$type,$start,$end,$score,$strand,$phase,
-
- implode(';',$attributes)))."\n";
-
-
- fwrite($fh, $stringData);
- }
-
- fclose($fh);
- if($clear_database){
-
- $command= "bp_seqfeature_load.pl -c -u '" .$user_name. "' -p '" .$password. "' -d " .$database_name. " " . $myFile;
- }else{
-
- $command= "bp_seqfeature_load.pl -u '" .$user_name. "' -p '" .$password. "' -d " .$database_name. " " . $myFile;
- }
-
- print 'Executing Command:'.$command."\n";
- exec($command, $out_put, $return_var);
- }
- function tripal_gbrowse_delete_library_features_from_gbrowse_form() {
- $form = array();
-
- $result = tripal_core_chado_select ( 'library', array('library_id','name'), array() );
- foreach ($result as $value){
- $newArray[$value->library_id]=$value->name;
- }
-
-
- $form['delete_gbrowse'] = array(
- '#type' => 'fieldset',
- '#title' => t(''),
- );
-
-
- $form['delete_gbrowse']['library_id'] = array(
- '#type' => 'select',
- '#title' => t('Libraries'),
- '#options' => $newArray,
- '#description' => t('Genetic Sequences.'),
- );
-
-
- $resource = db_query('SELECT * FROM {tripal_gbrowse_instances}');
- $items = array();
-
- while($record = db_fetch_object($resource)){
- $items[$record->gbrowse_id]= $record->gbrowse_name;
- }
- $form['delete_gbrowse']['gbrowse_id'] = array(
- '#type' => 'select',
- '#title' => t('GBrowse Instances'),
- '#options' => $items,
- '#description' => t('Selected Instances to be Removed.'),
- );
-
-
- $form['delete_gbrowse']['submit'] = array(
- '#type' => 'submit',
- '#weight' => 10,
- '#value' => t('Delete')
- );
-
- return $form;
- }
- function tripal_gbrowse_delete_library_features_from_gbrowse_form_submit($form, $form_state) {
-
- global $user;
-
- $record = db_fetch_object(db_query('SELECT * FROM {tripal_gbrowse_instances} WHERE gbrowse_id=%d', $form_state['values']['gbrowse_id']));
-
- $name = $record->database_name;
-
- $user_name = $record->database_user;
-
- $password= $record->user_password;
-
- $job_args = array($name,$user_name,$password,$form_state['values']['library_id']);
-
-
- if($form_state['values']['op'] == 'Delete'){
-
- $job_id = tripal_add_job('Deleting Library Features From GBrowse', 'tripal_gbrowse', 'tripal_gbrowse_delete_library_features_from_gbrowse', $job_args, $user->uid);
-
- }
-
- }
- function tripal_gbrowse_delete_library_features_from_gbrowse($database_name, $user_name, $password, $library_id){
- $result = tripal_core_chado_select ( 'library', array('name'), array('library_id' => $library_id)
-
- );
- $library_name = $result[0]->name;
-
- print "Removing Features of all types related to the ".$library_name." library...\n";
- $sql = 'SELECT cvterm.name FROM feature JOIN cvterm cvterm ON cvterm.cvterm_id=feature.type_id
-
- JOIN library_feature library_feature ON library_feature.feature_id=feature.feature_id JOIN library
-
- library ON library.library_id=library_feature.library_id WHERE library.library_id=%d GROUP BY
-
- cvterm.name';
- $previous_db = tripal_db_set_active('chado');
-
- $resource = db_query($sql, $library_id);
-
- tripal_db_set_active($previous_db);
-
- while($record = db_fetch_object($resource)){
-
- $type = $record->name;
-
-
- $command= "bp_seqfeature_delete.pl -u '".$user_name."' -p '".$password."' -d '" .$database_name. "' -t '" .$type. ":".$library_name."'";
-
- print "Executing Command: ".$command."\n";
-
-
- exec($command);
-
- }
- }
- function tripal_gbrowse_load_analyses_form(){
-
- $newArray=array();
-
- $result = tripal_core_chado_select ( 'analysis', array('analysis_id','name'), array() );
-
- foreach ($result as $value) {
- $newArray[$value->analysis_id]=$value->name;
- }
-
-
- $form['load_analyses'] = array(
- '#type' => 'fieldset',
- );
-
-
- $form['load_analyses']['analysis_id'] = array(
- '#type' => 'select',
- '#title' => t('Analyses'),
- '#options' => $newArray,
- '#description' => t('Analyses.'),
- );
-
-
- $resource = db_query('SELECT * FROM {tripal_gbrowse_instances}');
- $items = array();
-
- while($record = db_fetch_object($resource)){
- $items[$record->gbrowse_id]= $record->gbrowse_name;
- }
-
-
- $form['load_analyses']['gbrowse_id'] = array(
- '#type' => 'select',
- '#title' => t('GBrowse Instances'),
- '#options' => $items,
- '#description' => t('Selected GBrowse Instances to be Loaded.'),
- );
-
-
- $form['load_analyses']['check_box'] = array(
- '#type' => 'checkbox',
- '#title' => t('Update Analyses'),
- '#description' => t('Existing Same Name Analyses Updated Accordingly.'),
- );
- $form['load_analyses']['submit'] = array(
- '#type' => 'submit',
- '#weight' => 10,
- '#value' => t('Submit Job')
- );
-
- return $form;
- }
- function tripal_gbrowse_load_analyses_form_submit($form, $form_state) {
-
- global $user;
-
- $record = db_fetch_object(db_query('SELECT * FROM {tripal_gbrowse_instances} WHERE gbrowse_id=%d', $form_state['values']['gbrowse_id']));
-
- $name = $record->database_name;
-
- $user_name = $record->database_user;
-
- $password= $record->user_password;
-
- $job_args = array($name,$user_name,$password,$form_state['values']['analysis_id'], FALSE);
-
-
- if($form_state['values']['check_box']==1){
-
- $job_id = tripal_add_job('Deleting Features From GBrowse', 'tripal_gbrowse',
- 'tripal_gbrowse_delete_analysis_features_from_gbrowse', $job_args, $user->uid);
- }
-
-
- $job_id = tripal_add_job('Loading Features Into GBrowse', 'tripal_gbrowse',
- 'tripal_gbrowse_load_analysis_features_into_gbrowse', $job_args, $user->uid);
- }
- function tripal_gbrowse_load_analysis_features_into_gbrowse($database_name, $user_name, $password, $analysis_id,$clear_database){
-
-
- $myFile = "/tmp/temporaryGBrowse_".time().".gff3";
-
-
- $fh = fopen($myFile, 'w') or die("WARNING: Can not open file");
- print "Creating GFF3 file of features for Analysis...\n";
-
- if (!preg_match('/^\d+$/', $analysis_id)) {
- print "ERROR: Invalid Analysis ID supplied (Analysis ID= ".$analysis_id.")\n";
- return false;
- }
-
-
- $values = array('analysis_id' => $analysis_id);
-
- $prime_result = tripal_core_chado_select ( 'analysisfeature', array('feature_id'), $values);
-
- $result = tripal_core_chado_select ( 'analysis', array('name'), $values );
- $source = $result[0]->name ;
-
-
-
- foreach ($prime_result as $value) {
- $feature_id = $value->feature_id;
-
- if (!preg_match('/^\d+$/', $feature_id)) {
- print "ERROR: Invalid feature ID (".$feature_id.") associated with Library (Library ID = ".$analysis_id.")\n";
- }
-
- $result = tripal_core_chado_select('feature', array('type_id'), array('feature_id'=>$feature_id));
-
- $type_id = $result[0]->type_id;
-
- if (empty($type_id)) {
- print "ERROR: No Type associated with Feature ( Feature ID = ".$feature_id.")\n";
- }
-
-
- $result = tripal_core_chado_select('cvterm', array('name'), array('cvterm_id'=>$type_id));
-
- $type = $result[0]->name;
-
- if (empty($type)) {
- print "ERROR: Type associated with Feature (".$type_id.") doesn't exist in cvterm table (Feature ID = ".$feature_id.")\n";
- }
-
-
-
- $result = tripal_core_chado_select('featureloc', array('fmin','fmax', 'strand', 'phase', 'srcfeature_id'), array('feature_id'=>$feature_id));
-
- $start = $result[0]->fmin;
- if (!preg_match('/^\d+$/', $start)) {
- print "ERROR: Invalid Start (".$start.") of Feature (Feature ID= ".$feature_id.")\n";
- }
-
- $end = $result[0]->fmax;
- if (!preg_match('/^\d+$/', $end)) {
- print "ERROR: Invalid End (".$end.") of Feature (Feature ID= ".$feature_id.")\n";
- }
-
- $score = '.';
-
- if ($result[0]->strand < 0) {
- $strand= '-';
- } elseif ($result[0]->strand == 0) {
- $strand = '.';
- } elseif($result[0]->strand > 0) {
- $strand = '+';
- } else{
- $strand = '.';
- }
-
-
- $phase = $result[0]->phase;
- if(empty($phase)){
- $phase = '.';
- }
-
-
-
- $srcfeature_id = $result[0]->srcfeature_id;
- if (empty($srcfeature_id)) {
- print "ERROR: No Parent associated with Feature Location (Feature ID = ".$feature_id.")\n";
- }
-
- $result = tripal_core_chado_select('feature', array('name'), array('feature_id'=>$srcfeature_id));
-
- $seqid = $result[0]->name;
- if (empty($seqid)) {
- print "ERROR: Parent (Parent Feature ID = ".$seqid.") associated with Feature doesn't exist in feature table (Feature ID =".$feature_id."\n";
- }
-
- $result = tripal_core_chado_select('feature', array('uniquename', 'name'), array('feature_id'=>$feature_id));
-
- $id = $result[0]->uniquename;
-
- if (empty($id)) {
- print "ERROR: Missing Unique Name for Feature (Feature ID = ".$feature_id.")\n";
- }
- $name = $result[0]->name;
-
- if (empty($name)) {
- print "WARNING: Missing Name for Feature (Feature ID = ".$feature_id.")\n";
- }
-
-
- $result = tripal_core_chado_select('feature_synonym', array('synonym_id'), array('feature_id'=>$feature_id));
- $synonyms = array();
- foreach ($result as $obj){
-
- $synonym_id = $obj->synonym_id;
-
- $sub_result = tripal_core_chado_select('synonym', array('name'), array('synonym_id'=>$synonym_id));
-
- if (empty($sub_result[0]->name)) {
- print "ERROR: Synonym (".$synonym_id.") associated with feature not found in synonym table (Feature ID = ".$feature_id.")\n";
- } else {
- $synonyms[] = $sub_result[0]->name;
- }
- }
-
-
- $result = tripal_core_chado_select('feature_dbxref', array('dbxref_id'), array('feature_id'=>$feature_id));
- $dbxref = array();
-
- foreach ($result as $obj){
-
- $dbxref_id = $obj->dbxref_id;
-
- if (!empty($dbxref_id)) {
- $sub1_result = tripal_core_chado_select('dbxref', array('db_id', 'accession'), array('dbxref_id'=>$dbxref_id));
-
- $dbxref_accession = $sub1_result[0]->accession;
-
- $db_id = $sub1_result[0]->db_id;
-
- if (!empty($db_id)) {
- $sub_sub_result =tripal_core_chado_select('db', array('name'), array('db_id'=>$db_id));
-
- $db_name = $sub_sub_result[0]->name;
-
- if (empty($db_name)) {
- print "ERROR: Database (".$db_id.") associated with database reference not in db table (Database Reference ID = ".$dbxref_id.")\n";
- } elseif (empty($dbxref_accession)) {
- print "WARNING: Missing Accession for Database Reference (Database Reference ID = ".$dbxref_id.")\n";
- } else {
- $dbxref[] = $db_name . ':' . $dbxref_accession;
- }
- }
- }
- }
-
- $result = tripal_core_chado_select('feature', array('dbxref_id'), array('feature_id'=>$feature_id));
-
- $dbxref_id = $result[0]->dbxref_id;
-
- if (empty($dbxref_id)) {
- print "WARNING: No Database Reference associated directly with Feature (Feature ID = ".$feature_id.")\n";
- }
- $result = tripal_core_chado_select('dbxref', array('accession','db_id'), array('dbxref_id'=>$dbxref_id));
-
- $dbxref_accession = $result[0]->accession;
-
- if(!empty($dbxref_accession)){
- $db_id = $result[0]->db_id;
-
- $sub_sub_result =tripal_core_chado_select('db', array('name'), array('db_id'=>$db_id));
- $db_name = $sub_sub_result[0]->name;
-
- $dbxref[] = $db_name . ':' . $dbxref_accession;
- } else {
- print "WARNING: Missing Accession for Database Reference (Database Reference ID = ".$dbxref_id.")\n";
- }
-
- $attributes = array();
- $attributes[] = 'ID='.$id;
- if (!empty($name)) {
- $attributes[] = 'Name='.$name;
- }
- if (!empty($synonyms)) {
- $attributes[] = 'Alias='.implode(',',$synonyms);
- }
- if (!empty($dbxref)) {
- $attributes[] = 'Dbxref=' .implode(',', $dbxref);
- }
-
- $stringData = implode("\t", array($seqid,$source,$type,$start,$end,$score,$strand,$phase,
-
- implode(';',$attributes)))."\n";
-
-
- fwrite($fh, $stringData);
- }
-
- fclose($fh);
- if($clear_database){
-
- $command= "bp_seqfeature_load.pl -c -u '" .$user_name. "' -p '" .$password. "' -d " .$database_name. " " . $myFile;
- }else{
-
- $command= "bp_seqfeature_load.pl -u '" .$user_name. "' -p '" .$password. "' -d " .$database_name. " " . $myFile;
- }
-
- print 'Executing Command:'.$command."\n";
- exec($command, $out_put, $return_var);
- }
- function tripal_gbrowse_delete_analysis_features_from_gbrowse_form() {
- $form = array();
-
- $result = tripal_core_chado_select ( 'analysis', array('analysis_id','name'), array() );
- foreach ($result as $value){
- $newArray[$value->analysis_id]=$value->name;
- }
-
-
- $form['delete_analysis'] = array(
- '#type' => 'fieldset',
- '#title' => t(''),
- );
-
-
- $form['delete_analysis']['analysis_id'] = array(
- '#type' => 'select',
- '#title' => t('Analysis Features'),
- '#options' => $newArray,
- '#description' => t('Analysis.'),
- );
-
-
- $resource = db_query('SELECT * FROM {tripal_gbrowse_instances}');
- $items = array();
-
- while($record = db_fetch_object($resource)){
- $items[$record->gbrowse_id]= $record->gbrowse_name;
- }
-
- $form['delete_analysis']['gbrowse_id'] = array(
- '#type' => 'select',
- '#title' => t('GBrowse Instances'),
- '#options' => $items,
- '#description' => t('Selected Instances to be Removed.'),
- );
-
-
- $form['delete_analysis']['submit'] = array(
- '#type' => 'submit',
- '#weight' => 10,
- '#value' => t('Delete')
- );
-
- return $form;
- }
- function tripal_gbrowse_delete_analysis_features_from_gbrowse_form_submit($form, $form_state) {
-
- global $user;
-
- $record = db_fetch_object(db_query('SELECT * FROM {tripal_gbrowse_instances} WHERE gbrowse_id=%d', $form_state['values']['gbrowse_id']));
-
- $name = $record->database_name;
-
- $user_name = $record->database_user;
-
- $password= $record->user_password;
-
- $job_args = array($name,$user_name,$password,$form_state['values']['analysis_id']);
-
-
- if($form_state['values']['op'] == 'Delete'){
-
- $job_id = tripal_add_job('Deleting Analysis Features From GBrowse', 'tripal_gbrowse', 'tripal_gbrowse_delete_analysis_features_from_gbrowse', $job_args, $user->uid);
- }
-
- }
- function tripal_gbrowse_delete_analysis_features_from_gbrowse($database_name, $user_name, $password, $analysis_id){
- $result = tripal_core_chado_select ( 'analysis', array('name'), array('analysis_id' => $analysis_id)
-
- );
-
- $analysis_name = $result[0]->name;
-
- print "Removing Analysis Features of all types related to the ".$analysis_name." analysis...\n";
- $sql = 'SELECT cvterm.name FROM feature JOIN cvterm cvterm ON cvterm.cvterm_id=feature.type_id
-
- JOIN analysisfeature analysisfeature ON analysisfeature.feature_id=feature.feature_id JOIN analysis
-
- analysis ON analysis.analysis_id=analysisfeature.analysis_id WHERE analysis.analysis_id=%d GROUP BY
-
- cvterm.name';
- $previous_db = tripal_db_set_active('chado');
- $resource = db_query($sql, $analysis_id);
- tripal_db_set_active($previous_db);
-
- while($record = db_fetch_object($resource)){
-
- $type = $record->name;
-
-
- $command= "bp_seqfeature_delete.pl -u '".$user_name."' -p '".$password."' -d '" .$database_name. "' -t '" .$type. ":".$analysis_name."'";
-
- print "Executing Command: ".$command."\n";
-
-
- exec($command);
- }
- }
- function tripal_gbrowse_add_tracks_form() {
-
-
- $form['add_tracks_field_set'] = array(
- '#type' => 'fieldset',
- '#title' => t('Content-Related Fields'),
- );
-
- $resource = db_query('SELECT * FROM {tripal_gbrowse_instances}');
- $items = array();
-
- while($record = db_fetch_object($resource)){
-
- $items[$record->gbrowse_id]= $record->gbrowse_name;
-
- }
-
- $form['add_tracks_field_set']['gbrowse_instances'] = array(
- '#type' => 'select',
- '#title' => t('Registered GBrowse Instances'),
- '#options' => $items,
- '#description' => t('Selected GBrowse Instances to be Loaded.'),
- '#required' => TRUE,
- );
-
- $sql = 'SELECT name as type, cvterm_id '
- .'FROM cvterm '
- .'WHERE cvterm_id IN (SELECT type_id FROM feature)';
- $previous_db = tripal_db_set_active('chado');
- $resource = db_query($sql);
- tripal_db_set_active($previous_db);
-
- $items = array();
-
- while($record = db_fetch_object($resource)){
-
- $items[$record->type] = $record->type;
- }
- $form['add_tracks_field_set']['type_name'] = array(
- '#type' => 'select',
- '#title' => t('Feature Type'),
- '#options' => $items,
- '#description' => t('Selected GBrowse Instances to be Loaded.'),
- '#required' => TRUE,
- );
-
- $newArray['none'] = 'None';
- $result = tripal_core_chado_select ( 'library', array('library_id','name'), array() );
- foreach ($result as $value) {
- $newArray[$value->name]=$value->name;
- }
-
-
- $form['add_tracks_field_set']['library_id'] = array(
- '#type' => 'select',
- '#title' => t('Library'),
- '#options' => $newArray,
- '#description' => t('Selected GBrowse Instances to be Loaded.'),
- );
-
- $form['track_text'] = array(
- '#type' => 'fieldset',
- '#title' => 'Track-Specific Fields'
- );
-
- $form['track_text']['identifier'] = array(
- '#type' => 'textfield',
- '#title' => t('Track Identifier'),
- '#size' => 30,
- '#maxlength' => 64,
- '#description' => t('Specify Track Identifier (Must be Unique and Specific)'),
- '#required' => TRUE,
- );
-
- $form['track_text']['track_name'] = array(
- '#type' => 'textfield',
- '#title' => t('Track Name'),
- '#size' => 30,
- '#maxlength' => 64,
- '#description' => t('Specify Track Name (Must be Unique and Specific)'),
- '#required' => TRUE,
- );
-
-
- $item = array();
- $item[''] = 'Default Glyph';
- $item['generic'] = 'Generic';
- $item['allele_tower '] = 'Allele Tower';
- $item['anchored_arrow'] = 'Anchored Arrow';
- $item['arrow'] = 'Arrow';
- $item['box'] = 'Box';
- $item['cds'] = 'CDS';
- $item['crossbox'] = 'Cross Box';
- $item['diamond'] = 'Diamond';
- $item['dna'] = 'DNA';
- $item['dot'] = 'Dot';
- $item['ellipse'] = 'Ellipse';
- $item['extending_arrow'] = 'Extending Arrow';
- $item['generic'] = 'Generic';
- $item['graded_segments'] = 'Graded Segments';
- $item['heterogeneous_segments '] = 'Heterogeneous Segments';
- $item['image'] = 'Image';
- $item['line'] = 'Line';
- $item['primers'] = 'Primers';
- $item['processed_transcript'] = 'Processed Transcript';
- $item['rndrect'] = 'Rndrect';
- $item['ruler_arrow'] = 'Ruler Arrow';
- $item['segments'] = 'Segments';
- $item['span'] = 'Span';
- $item['toomany'] = 'Too Many';
- $item['transcript'] = 'Transcript';
- $item['transcript2'] = 'Transcript2';
- $item['translation'] = 'Translation';
- $item['triangle'] = 'Triangle';
- $item['wiggle_densit'] = 'Wiggle Densit';
- $item['wiggle_xyplot'] = 'Wiggle XYplot';
- $item['xyplot'] = 'XYplot';
-
-
-
- $form['track_text']['glyph'] = array(
- '#type' => 'select',
- '#title' => t('Glyph'),
- '#options' => $item,
- '#description' => t('Shape of Genomic Feature Track '),
- );
-
- $form['track_text']['foreground_colour'] = array(
- '#type' => 'textfield',
- '#title' => t('Foreground Colour'),
- '#size' => 30,
- '#maxlength' => 64,
- '#description' => t('Enter name/Hex-code for identifying foreground colour of glyph.
- List of available colours here:'.l("GBrowse Colour Palette.pdf",
- "http://gmod.org/mediawiki/images/a/ae/Gbrowse_Color_Palette.pdf")),
- );
-
- $form['track_text']['backround_colour'] = array(
- '#type' => 'textfield',
- '#title' => t('Background Colour'),
- '#size' => 30,
- '#maxlength' => 20,
- '#description' => t('Enter name/Hex-code for identifying background colour of glyph.
- List of available colours here:'.l("GBrowse Colour Palette.pdf",
- "http://gmod.org/mediawiki/images/a/ae/Gbrowse_Color_Palette.pdf")),
- );
-
- $form['track_text']['track_height'] = array(
- '#type' => 'textfield',
- '#title' => t('Height'),
- '#size' => 30,
- '#maxlength' => 20,
- '#description' => t('Modify Track Height'),
- );
-
- $form['track_text']['link'] = array(
- '#type' => 'textfield',
- '#title' => t('Link'),
- '#size' => 30,
- '#maxlength' => 64,
- '#description' => t('Specify to Further details (HTML address)'),
- );
-
- $form['create_instance']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Add Track')
- );
-
- return $form;
- }
- function tripal_gbrowse_add_tracks_form_validate ($form, $form_state) {
-
- if (!empty($form_state['values']['foreground_colour'])) {
-
- if ( !preg_match('/^[\w#]+$/', $form_state['values']['foreground_colour'])) {
-
- form_set_error('foreground_colour',
- 'The Foreground Colour should be either the name of a colour listed in the linked to pdf or a valid hex colour');
- }
- }
-
- if (!empty($form_state['values']['backround_colour'])) {
- if(!preg_match('/^[\w#]+$/', $form_state['values']['backround_colour'])){
- form_set_error('backround_colour','The Background Colour should be either the name of a colour listed in the linked to pdf or a valid hex colour');
- }
- }
-
- if (!empty($form_state['values']['track_height'])){
- if(!preg_match('/^\d*$/', $form_state['values']['track_height'])){
- form_set_error('track_height','The Track Height must be a positive integer');
- }
- }
-
- if(!preg_match('/^\w+$/', $form_state['values']['identifier'])){
- form_set_error('identifier','The Identifier must be composed of the following characters only: [A-Z][a-z][0-9] and _');
-
- }
-
- if (!empty($form_state['values']['link'])){
- if(!preg_match('/^http:/', $form_state['values']['link'])){
- form_set_error('link','The Link must be a conventional web site name, beginging with http: ');
- }
- }
- }
- function tripal_gbrowse_add_tracks_form_submit($form, $form_state) {
-
- $string = "\n[".$form_state['values']['identifier']."]\n"
- ."key = ".$form_state['values']['track_name']."\n";
-
- if($form_state['values']['library_id'] == 'none'){
- $string .= "feature = ".$form_state['values']['type_name']."\n";
- } else {
- $string .= "feature = ".$form_state['values']['type_name'].":" .$form_state['values']['library_id']."\n";
- }
-
- if (!empty($form_state['values']['glyph'])) {
- $string .= "glyph = ".$form_state['values']['glyph']."\n";
- }
-
- if (!empty($form_state['values']['track_height'])) {
- $string .= "height = ".$form_state['values']['track_height']."\n";
- }
-
- if (!empty($form_state['values']['foreground_colour'])) {
- $string .= "bgcolor = ".$form_state['values']['foreground_colour']."\n";
- }
-
- if (!empty($form_state['values']['backround_colour'])) {
- $string .= "fgcolor = ".$form_state['values']['backround_colour']."\n";
- }
-
- if (!empty($form_state['values']['link'])) {
- $string .= "link = ".$form_state['values']['link']."\n";
- }
-
- $string .= "\n";
-
- $record = db_fetch_object(db_query('SELECT * FROM {tripal_gbrowse_instances} WHERE gbrowse_id=%d', $form_state['values']['gbrowse_instances']));
-
- $config_file = $record->config_file;
-
- $command = "echo '".$string."' >> ".$config_file;
-
- exec($command);
- }
- function tripal_gbrowse_delete_tracks_form(&$form_state=NULL) {
-
- $form['delete_tracks_field_set'] = array(
- '#type' => ($form_state['storage']['gbrowse_id']) ? 'hidden' : 'fieldset',
- '#title' => t('GBrowse Specific Fields'),
- );
-
-
- $resource = db_query('SELECT * FROM {tripal_gbrowse_instances}');
- $items = array();
-
- while($record = db_fetch_object($resource)){
-
- $items[$record->gbrowse_id]= $record->gbrowse_name;
-
- }
-
- $form['delete_tracks_field_set']['gbrowse_instances'] = array(
- '#type' => 'select',
- '#title' => t('Registered GBrowse Instances'),
- '#options' => $items,
- '#description' => t('Selected GBrowse Instances to be Loaded.'),
- '#default_value' => $form_state['values']['gbrowse_instances'],
- );
-
-
- $form['delete_tracks_field_set']['submit_instance'] = array(
- '#type' => 'submit',
- '#value' => t('Set Instance')
- );
-
- $form['delete_tracks'] = array(
- '#type' => ($form_state['storage']['gbrowse_id']) ? 'fieldset' : 'hidden',
- '#title' => t('Track Specific Fields'),
- );
-
-
- $gbrowse_id = $form_state['storage']['gbrowse_id'];
-
- if ($gbrowse_id){
-
- $items = track_name_options($gbrowse_id);
-
- }else {
-
- $items = array();
-
- }
-
-
- $form['delete_tracks']['track_line_number'] = array(
- '#type' => 'select',
- '#title' => t('Track Name'),
- '#options' => $items,
- '#description' => t('Name of Track to Remove '),
- '#default_value' => $form_state['values']['gbrowse_id'],
- );
-
- $form['delete_tracks']['remove_track'] = array(
- '#type' => 'submit',
- '#value' => t('Remove Track')
- );
- return $form;
- }
- function tripal_gbrowse_delete_tracks_form_submit($form, &$form_state) {
- $form_state['storage']['gbrowse_id'] = $form_state['values']['gbrowse_instances'];
-
-
- if($form_state['clicked_button']['#value']=='Remove Track'){
-
-
- $resource= db_fetch_object(db_query('SELECT * FROM {tripal_gbrowse_instances} WHERE gbrowse_id=%d', $form_state['storage']['gbrowse_id']));
-
-
- $config_file = (string) $resource->config_file;
-
- $read_file_handle = fopen($config_file,'r') or drupal_set_message("WARNING: Can not open file:" .$config_file, 'error');
- $track_number = $form_state['values']['track_line_number'];
-
- $line_num = 0;
-
-
- $new_conf_file = '/tmp/temp_config_file.temp';
-
-
- $command = 'touch /tmp/temp_config_file.temp';
-
- exec($command);
-
-
- if (is_writable($new_conf_file)) {
-
-
- $write_file_handle = fopen($new_conf_file, 'w') or drupal_set_message("WARNING: Can not open file:" .$new_conf_file, 'error');
-
- }else{
-
- drupal_set_message("WARNING: Attempting to create a temporary file -insufficient permissions: ".$new_conf_file, 'error');
- }
- while(!feof($read_file_handle)){
-
- $file_line = fgets($read_file_handle);
-
- $line_num++;
-
- if($line_num == $track_number){
-
- $remove_track = TRUE;
-
- }
-
- if(preg_match('/^\s*$/',$file_line)){
-
- $remove_track=FALSE;
-
- }
-
- if($remove_track==FALSE){
-
- fwrite($write_file_handle, $file_line);
-
- }
-
- }
-
- $command = 'cp '.$new_conf_file.' '.$config_file ;
-
- exec($command);
-
- $command = 'rm '.$new_conf_file ;
-
- exec($command);
-
- }
-
- }
- function track_name_options($gbrowse_id) {
- $items = array();
-
- $record = db_fetch_object(db_query('SELECT * FROM {tripal_gbrowse_instances} WHERE gbrowse_id=%d', $gbrowse_id));
-
- $config_file = (string) $record->config_file;
- $config_array = array();
-
-
- $command = 'grep -n "^\[.*\]" ' .$config_file;
-
-
- exec($command , $config_array);
-
- $config_array_size = count($config_array);
-
-
- for($i = 0 ; $i < $config_array_size; $i++){
-
- $file_line = $config_array[$i];
-
- if ($is_track_definition){
-
- if(preg_match('/^(\d+):\[(.+)\]$/', $file_line, $matches)){
-
- $items[$matches[1]] = $matches[2];
-
- }
-
- }
-
- if(preg_match('/\[TRACK DEFAULTS\]/', $file_line)){
-
- $is_track_definition = TRUE;
- }
-
- }
-
- return $items;
- }
|