blast_ui.services.inc 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. <?php
  2. /**
  3. * Implements hook_services_resources().
  4. * Hooks provided by Services for the definition of new services,
  5. */
  6. function blast_ui_services_resources()
  7. {
  8. return array(
  9. 'blast' => array(
  10. 'retrieve' => array(
  11. 'help' => 'Retrieves a blastResult',
  12. 'callback' => 'getBlastData',
  13. 'access callback' => 'user_access',
  14. 'access arguments' => array(
  15. 'access content'
  16. ),
  17. 'access arguments append' => FALSE,
  18. 'args' => array(
  19. array(
  20. 'name' => 'job_id',
  21. 'type' => 'int',
  22. 'description' => 'The information needed',
  23. 'source' => array(
  24. 'path' => '0'
  25. ),
  26. 'optional' => FALSE
  27. )
  28. )
  29. ),
  30. 'index' => array(
  31. 'help' => 'Retrieves a listing of blast_ui',
  32. 'callback' => '_blast_ui_index',
  33. 'access callback' => 'user_access',
  34. 'access arguments' => array(
  35. 'access content'
  36. ),
  37. 'access arguments append' => FALSE,
  38. 'args' => array ()
  39. ),
  40. 'actions' => array(
  41. 'getJobId' => array(
  42. 'help' => 'Retrieves a listing of database',
  43. 'callback' => '_blast_ui_getJobId',
  44. 'access callback' => 'user_access',
  45. 'access arguments' => array(
  46. 'access content'
  47. ),
  48. 'args' => array(
  49. array(
  50. 'name' => 'data',
  51. 'type' => 'array',
  52. 'description' => 'Retrieve blast job id',
  53. 'source' => 'data',
  54. 'optional' => FALSE
  55. )
  56. ),
  57. 'access arguments append' => FALSE
  58. ),
  59. 'getDatabaseOptions' => array(
  60. 'help' => 'Retrieves a listing of database',
  61. 'callback' => '_blast_ui_getDatabaseOption',
  62. 'access callback' => 'user_access',
  63. 'access arguments' => array(
  64. 'access content'
  65. ),
  66. 'args' => array(
  67. array(
  68. 'name' => 'data',
  69. 'type' => 'array',
  70. 'description' => 'The set database_type information',
  71. 'source' => 'data',
  72. 'optional' => FALSE
  73. )
  74. ),
  75. 'access arguments append' => false
  76. )
  77. )
  78. )
  79. );
  80. }
  81. /**
  82. * Callback for retrieving blast services.
  83. *
  84. * @param int $id
  85. * @return object
  86. */
  87. function _blast_ui_retrieve( $id )
  88. {
  89. return getBlastData( $id );
  90. }
  91. /**
  92. * Callback for Index blast services.
  93. * @return object
  94. */
  95. function _blast_ui_index()
  96. {
  97. return array(
  98. 'query_type' => array(
  99. '1' => 'nucleotide',
  100. '2' => 'protein'
  101. ),
  102. 'db_type' => array(
  103. '1' => 'nucleotide',
  104. '2' => 'protein'
  105. ),
  106. 'blast_program' => array(
  107. '1' => 'blastn',
  108. '2' => 'blastx',
  109. '3' => 'tblastn',
  110. '4' => 'blastp'
  111. )
  112. );
  113. }
  114. /*
  115. ** Method returns Advanced options and Database Type
  116. ** @param Object $data
  117. ** web service url : http://localhost:8080/restapi/blast/getDatabaseOptions.json
  118. */
  119. function _blast_ui_getDatabaseOption( $data )
  120. {
  121. if ( !isset( $data[ query_type ] ) )
  122. {
  123. return services_error( 'Missing blast attribute $query_type [ set necleotide or protein in post request of query_type ]', 406 );
  124. }
  125. if ( !isset( $data[ db_type ] ) )
  126. {
  127. return services_error( 'Missing blast attribute $db_type [ set necleotide or protein in post request of db_type ]', 406 );
  128. }
  129. if ( !isset( $data[ blast_program ] ) )
  130. {
  131. return services_error( 'Missing blast attribute $blast_program [ set blastn, blastx, tblastn, blastp in post request of blast_program ]', 406 );
  132. }
  133. $query_type = $data[ db_type ];
  134. $db_type = $data[ db_type ];
  135. $blast_program = $data[ blast_program ];
  136. $options_database = get_blast_database_options( $db_type );
  137. // Data Set send to user for selection of Blastn
  138. if ( $blast_program == 'blastn' )
  139. {
  140. return array(
  141. 'Select_Database' => $options_database,
  142. 'Max_target_sequences' => _get_max_target( $blast_program ),
  143. 'Word_size' => _get_word_size( $blast_program ),
  144. 'Match_Mismatch_Scores' => _get_match_mismatch( $blast_program ),
  145. 'Gap_Costs' => _get_gap( $blast_program )
  146. );
  147. }
  148. // Data Set send to user for selection of Blastx
  149. elseif ( $blast_program == 'blastx' )
  150. {
  151. return array(
  152. 'Select_Database' => $options_database,
  153. 'Max_target_sequences' => _get_max_target( $blast_program ),
  154. 'Word_size' => _get_word_size( $blast_program ),
  155. 'Matrix_options' => _get_matrix_options()
  156. );
  157. }
  158. //Data Set send to user for selection of tblastn
  159. elseif ( $blast_program == 'tblastn' )
  160. {
  161. return array(
  162. 'Select_Database' => $options_database,
  163. 'Max_target_sequences' => _get_max_target( $blast_program ),
  164. 'Word_size' => _get_word_size( $blast_program ),
  165. 'Matrix_options' => _get_matrix_options(),
  166. 'Gap_Costs' => getGap_cost()
  167. );
  168. }
  169. //Data Set send to user for selection of blastp
  170. elseif ( $blast_program == 'blastp' )
  171. {
  172. return array(
  173. 'Select_Database' => $options_database,
  174. 'Max_target_sequences' => _get_max_target( $blast_program ),
  175. 'Word_size' => _get_word_size( $blast_program ),
  176. 'Matrix_options' => _get_matrix_options(),
  177. 'Gap_Costs' => getGap_cost()
  178. );
  179. }
  180. }
  181. /*
  182. ** validate the data
  183. */
  184. function blast_validation( $query_type, $db_type, $data )
  185. {
  186. if ( $query_type == 'nucleotide' )
  187. {
  188. if ( $db_type == 'nucleotide' )
  189. {
  190. if ( !isset( $data[ Select_Database ] ) )
  191. {
  192. return services_error( 'Missing blast attribute $Select_Database [ query blast/getDatabaseOptions for options :- Add database you need to use]', 406 );
  193. }
  194. if ( !isset( $data[ Max_target_sequences ] ) )
  195. {
  196. return services_error( 'Missing blast attribute $Max_target_sequences [ query blast/getDatabaseOptions for options ]', 406 );
  197. }
  198. if ( !isset( $data[ Word_size ] ) )
  199. {
  200. return services_error( 'Missing blast attribute $Word_size [ query blast/getDatabaseOptions for options ]', 406 );
  201. }
  202. if ( !isset( $data[ Match_Mismatch_Scores ] ) )
  203. {
  204. return services_error( 'Missing blast attribute $Match_Mismatch_Scores [ query blast/getDatabaseOptions for options]', 406 );
  205. }
  206. if ( !isset( $data[ Gap_costs ] ) )
  207. {
  208. return services_error( 'Missing blast attribute $Gap_Costs [ query blast/getDatabaseOptions for options ]', 406 );
  209. }
  210. if ( isset( $data[ seqQuery ] ) )
  211. {
  212. if ( validate_fasta_sequence( $query_type, $data[ seqQuery ] ) == 1 )
  213. {
  214. return services_error( 'Please enter validate_fasta_sequence', 406 );
  215. }
  216. }
  217. else
  218. {
  219. return services_error( 'Missing blast attribute data[seqQuery]', 406 );
  220. }
  221. }
  222. else
  223. {
  224. if ( !isset( $data[ Select_Database ] ) )
  225. {
  226. return services_error( 'Missing blast attribute $Select_Database [ query blast/getDatabaseOptions for options :- Add database used by you]', 406 );
  227. }
  228. if ( !isset( $data[ Max_target_sequences ] ) )
  229. {
  230. return services_error( 'Missing blast attribute $Max_target_sequences [ query blast/getDatabaseOptions for options ]', 406 );
  231. }
  232. if ( !isset( $data[ Word_size ] ) )
  233. {
  234. return services_error( 'Missing blast attribute $Word_size [ query blast/getDatabaseOptions for options ]', 406 );
  235. }
  236. if ( !isset( $data[ Matrix_options ] ) )
  237. {
  238. return services_error( 'Missing blast attribute $Matrix_options [ query blast/getDatabaseOptions for options ]', 406 );
  239. }
  240. if ( isset( $data[ seqQuery ] ) )
  241. {
  242. if ( validate_fasta_sequence( $query_type, $data[ seqQuery ] ) == 1 )
  243. {
  244. return services_error( 'Please enter validate_fasta_sequence', 406 );
  245. }
  246. }
  247. else
  248. {
  249. return services_error( 'Missing blast attribute data[seqQuery]', 406 );
  250. }
  251. }
  252. }
  253. else
  254. {
  255. if ( $db_type == 'nucleotide' )
  256. {
  257. if ( !isset( $data[ Select_Database ] ) )
  258. {
  259. return services_error( 'Missing blast attribute $Select_Database [ query blast/getDatabaseOptions for options :- Add database you need to use]', 406 );
  260. }
  261. if ( !isset( $data[ Max_target_sequences ] ) )
  262. {
  263. return services_error( 'Missing blast attribute $Max_target_sequences [ query blast/getDatabaseOptions for options ]', 406 );
  264. }
  265. if ( !isset( $data[ Word_size ] ) )
  266. {
  267. return services_error( 'Missing blast attribute $Word_size [ query blast/getDatabaseOptions for options ]', 406 );
  268. }
  269. if ( !isset( $data[ Matrix_options ] ) )
  270. {
  271. return services_error( 'Missing blast attribute $Matrix_options [ query blast/getDatabaseOptions for options ]', 406 );
  272. }
  273. if ( !isset( $data[ Gap_costs ] ) )
  274. {
  275. return services_error( 'Missing blast attribute [ query blast/getDatabaseOptions for options ]', 406 );
  276. }
  277. if ( isset( $data[ seqQuery ] ) )
  278. {
  279. if ( validate_fasta_sequence( $query_type, $data[ seqQuery ] ) == 1 )
  280. {
  281. return services_error( 'Please enter validate_fasta_sequence', 406 );
  282. }
  283. }
  284. else
  285. {
  286. return services_error( 'Missing blast attribute data[seqQuery]', 406 );
  287. }
  288. }
  289. else
  290. {
  291. //return $data;
  292. if ( !isset( $data[ Select_Database ] ) )
  293. {
  294. return services_error( 'Missing blast attribute $Select_Database [ query blast/getDatabaseOptions for options :- Add database used by you]', 406 );
  295. }
  296. if ( !isset( $data[ Max_target_sequences ] ) )
  297. {
  298. return services_error( 'Missing blast attribute $Max_target_sequences [ query blast/getDatabaseOptions for options ]', 406 );
  299. }
  300. if ( !isset( $data[ Word_size ] ) )
  301. {
  302. return services_error( 'Missing blast attribute $Word_size [ query blast/getDatabaseOptions for options ]', 406 );
  303. }
  304. if ( !isset( $data[ Matrix_options ] ) )
  305. {
  306. return services_error( 'Missing blast attribute $Matrix_options [ query blast/getDatabaseOptions for options ]', 406 );
  307. }
  308. if ( isset( $data[ seqQuery ] ) )
  309. {
  310. if ( validate_fasta_sequence( $query_type, $data[ seqQuery ] ) == 1 )
  311. {
  312. return services_error( 'Please enter validate_fasta_sequence', 406 );
  313. }
  314. }
  315. else
  316. {
  317. return services_error( 'Missing blast attribute data[seqQuery]', 406 );
  318. }
  319. }
  320. }
  321. }
  322. /*
  323. ** Method call the blast_ui_getblastJobId by setting all the needed
  324. ** parameters
  325. ** web service url : http://localhost:8080/restapi/blast/getJobId.json
  326. */
  327. function _blast_ui_getJobId( $data )
  328. {
  329. $query_type;
  330. $db_type;
  331. // Setting the default value of qRange and eValue from blast_ui.admin
  332. $eVal = variable_get( 'eVal', '' );
  333. $qRange = variable_get( 'qRange', '' );
  334. /* check values in post query */
  335. if ( !isset( $data[ query_type ] ) )
  336. {
  337. return services_error( 'Missing blast attribute $query_type [ set necleotide or protein in post request of query_type ]', 406 );
  338. }
  339. if ( !isset( $data[ db_type ] ) )
  340. {
  341. return services_error( 'Missing blast attribute $db_type [ set necleotide or protein in post request of db_type ]', 406 );
  342. }
  343. $query_type = $data[ query_type ];
  344. $db_type = $data[ db_type ];
  345. // check the user input in $data
  346. blast_validation( $query_type, $db_type, $data );
  347. if ( isset( $data[ $eVal ] ) )
  348. {
  349. $eVal = $data[ $eVal ];
  350. }
  351. if ( isset( $data[ $culling_limit ] ) )
  352. {
  353. $qRange = $data[ $culling_limit ];
  354. }
  355. if ( $query_type == 'nucleotide' )
  356. {
  357. if ( $db_type == 'nucleotide' )
  358. {
  359. $blast_program = 'blastn';
  360. // code not working for wordvalue = 7 ?
  361. $options_database = get_blast_database_options( $data[ db_type ] );
  362. $Databasekey = array_search( $data[ Select_Database ], $options_database );
  363. $advanced_options = advanced_options( $blast_program, $eVal, $qRange, $data );
  364. }
  365. elseif ( $db_type == 'protein' )
  366. {
  367. $blast_program = 'blastx';
  368. // how to get gap cost - question
  369. $options_database = get_blast_database_options( $data[ db_type ] );
  370. $Databasekey = array_search( $data[ Select_Database ], $options_database );
  371. $advanced_options = advanced_options( $blast_program, $eVal, $qRange, $data );
  372. }
  373. }
  374. elseif ( $query_type == 'protein' )
  375. {
  376. if ( $db_type == 'nucleotide' )
  377. {
  378. $blast_program = 'tblastn';
  379. $options_database = get_blast_database_options( $data[ db_type ] );
  380. $Databasekey = array_search( $data[ Select_Database ], $options_database );
  381. $advanced_options = advanced_options( $blast_program, $eVal, $qRange, $data );
  382. }
  383. elseif ( $db_type == 'protein' )
  384. {
  385. $blast_program = 'blastp';
  386. $options_database = get_blast_database_options( $data[ db_type ] );
  387. $Databasekey = array_search( $data[ Select_Database ], $options_database );
  388. $advanced_options = advanced_options( $blast_program, $eVal, $qRange, $data );
  389. }
  390. }
  391. return blast_ui_getblastJobId( $data[ query_type ], $data[ db_type ], $data[ seqQuery ], $Databasekey, $advanced_options );
  392. }
  393. /*
  394. ** Define the advanced Options for Blast
  395. ** @return : advanced_options according to blast_program
  396. */
  397. function advanced_options( $blast_program, $eVal, $qRange, $data )
  398. {
  399. if ( $blast_program == 'blastn' )
  400. {
  401. $wordvalue = intval( $data[ Word_size ] );
  402. $numAlign = intval( $data[ Max_target_sequences ] );
  403. $Data_GapCost = _get_gap( $blast_program );
  404. $gapkey = array_search( $data[ Gap_Costs ], $Data_GapCost );
  405. $gap = _set_gap( $gapkey );
  406. $Data_Mismatch_Scores = _get_match_mismatch( $blast_program );
  407. $Mismatch_Scores_key = array_search( $data[ Match_Mismatch_Scores ], $Data_Mismatch_Scores );
  408. $m_m = _set_match_mismatch( $Mismatch_Scores_key );
  409. return array(
  410. 'max_target_seqs' => $numAlign,
  411. 'evalue' => $eVal,
  412. 'word_size' => $wordvalue,
  413. 'gapopen' => $gap[ 'gapOpen' ],
  414. 'gapextend' => $gap[ 'gapExtend' ],
  415. 'penalty' => $m_m[ 'penalty' ],
  416. 'reward' => $m_m[ 'reward' ],
  417. 'culling_limit' => $qRange
  418. );
  419. }
  420. elseif ( $blast_program == 'blastx' )
  421. {
  422. $wordSize = intval( $data[ Word_size ] );
  423. $numAlign = intval( $data[ Max_target_sequences ] );
  424. $matrix = $data[ Matrix_options ];
  425. $gap = getGap( $matrix, 1 );
  426. return array(
  427. 'max_target_seqs' => $numAlign,
  428. 'evalue' => $eVal,
  429. 'word_size' => $wordSize,
  430. 'gapopen' => $gap[ 'gapOpen' ],
  431. 'gapextend' => $gap[ 'gapExtend' ],
  432. 'culling_limit' => $qRange,
  433. 'matrix' => $matrix
  434. );
  435. }
  436. elseif ( $blast_program == 'tblastn' )
  437. {
  438. $wordSize = intval( $data[ Word_size ] );
  439. $numAlign = intval( $data[ Max_target_sequences ] );
  440. $matrix = $data[ Matrix_options ];
  441. $gap = getGap( $matrix, 1 );
  442. return array(
  443. 'max_target_seqs' => $numAlign,
  444. 'evalue' => $eVal,
  445. 'word_size' => $wordSize,
  446. 'gapopen' => $gap[ 'gapOpen' ],
  447. 'gapextend' => $gap[ 'gapExtend' ],
  448. 'culling_limit' => $qRange,
  449. 'matrix' => $matrix
  450. );
  451. }
  452. elseif ( $blast_program == 'blastp' )
  453. {
  454. $wordSize = intval( $data[ Word_size ] );
  455. $numAlign = intval( $data[ Max_target_sequences ] );
  456. $matrix = $data[ Matrix_options ];
  457. $gap = getGap( $matrix, 1 );
  458. return array(
  459. 'max_target_seqs' => $numAlign,
  460. 'evalue' => $eVal,
  461. 'word_size' => $wordSize,
  462. 'gapopen' => $gap[ 'gapOpen' ],
  463. 'gapextend' => $gap[ 'gapExtend' ],
  464. 'culling_limit' => $qRange,
  465. 'matrix' => $matrix
  466. );
  467. }
  468. }
  469. /*
  470. ** Call the core API of Triple
  471. ** @return : Job_ID
  472. */
  473. function blast_ui_getblastJobId( $query_type, $db_type, $seqQuery, $Databasekey, $adv_options )
  474. {
  475. if ( $query_type == 'nucleotide' )
  476. {
  477. if ( $db_type == 'nucleotide' )
  478. {
  479. $blast_program = 'blastn';
  480. }
  481. elseif ( $db_type == 'protein' )
  482. {
  483. $blast_program = 'blastx';
  484. }
  485. }
  486. elseif ( $query_type == 'protein' )
  487. {
  488. if ( $db_type == 'nucleotide' )
  489. {
  490. $blast_program = 'tblastn';
  491. }
  492. elseif ( $db_type == 'protein' )
  493. {
  494. $blast_program = 'blastp';
  495. }
  496. }
  497. $query = variable_get('file_temporary_path', file_directory_temp()) . '/' . date( 'YMd_His' ) . '_query.fasta';
  498. file_put_contents( $query, $seqQuery );
  499. $blastdb_node = node_load( $Databasekey );
  500. $blastdb_name = $blastdb_node->db_name;
  501. $blastdb_with_path = $blastdb_node->db_path;
  502. // Now let each program process its own advanced options.
  503. $advanced_options = $adv_options;
  504. global $user;
  505. $output_filestub = date( 'YMd_His' );
  506. $job_args = array(
  507. 'program' => $blast_program,
  508. 'query' => $query,
  509. 'database' => $blastdb_with_path,
  510. 'output_filename' => $output_filestub,
  511. 'options' => $advanced_options
  512. );
  513. $job_id = tripal_add_job( t( 'BLAST (@program): @query', array(
  514. '@program' => $blast_program,
  515. '@query' => $query
  516. ) ), 'blast_job', 'run_BLAST_tripal_job', $job_args, $user->uid );
  517. ob_start();
  518. tripal_launch_job( 1, $job_id );
  519. ob_end_clean();
  520. return $job_id;
  521. // return getBlastData($job_id);
  522. }
  523. function getBlaststatus( $job_id )
  524. {
  525. /* $sql = "SELECT status FROM tripal_jobs WHERE job_id = :job_id ";
  526. $job_res = db_query($sql, array(':job_id' => $job_id))->fetchField();
  527. return $job_res; */
  528. }
  529. /*
  530. **Method returns file output data
  531. ** @param int $job_id
  532. ** web service url : http://localhost:8080/restapi/blast/job_id
  533. */
  534. function getBlastData( $job_id )
  535. {
  536. $result;
  537. $sql = "SELECT job_name FROM tripal_jobs WHERE job_id = :job_id ";
  538. $job_res = db_query( $sql, array(
  539. ':job_id' => $job_id
  540. ) )->fetchField();
  541. $file_path = str_replace( '_query.fasta', '.blast.asn', $job_res );
  542. if ( stristr( $file_path, "tblastn" ) )
  543. {
  544. $file_path = str_replace( 'BLAST (tblastn): /', '/', $file_path );
  545. }
  546. elseif ( stristr( $file_path, "blastx" ) )
  547. {
  548. $file_path = str_replace( 'BLAST (blastx): /', '/', $file_path );
  549. }
  550. elseif ( stristr( $file_path, "blastn" ) )
  551. {
  552. $file_path = str_replace( 'BLAST (blastn): /', '/', $file_path );
  553. }
  554. elseif ( stristr( $file_path, "blastp" ) )
  555. {
  556. $file_path = str_replace( 'BLAST (blastp): /', '/', $file_path );
  557. }
  558. if ( file_exists( $file_path ) )
  559. {
  560. $result = file_get_contents( $file_path );
  561. }
  562. else
  563. {
  564. $result = "The file $file_path does not exist";
  565. }
  566. return $result;
  567. }
  568. /*
  569. **Method Used for tblastn and blastx
  570. ** @return int $gapOpen and $gapExtend
  571. */
  572. function getGap( $matrix, $gapkey )
  573. {
  574. switch ( $matrix )
  575. {
  576. case 'PAM30':
  577. switch ( $gapKey )
  578. {
  579. case 0:
  580. $gapOpen = 7;
  581. $gapExtend = 2;
  582. break;
  583. case 1:
  584. $gapOpen = 6;
  585. $gapExtend = 2;
  586. break;
  587. case 2:
  588. $gapOpen = 5;
  589. $gapExtend = 2;
  590. break;
  591. case 3:
  592. $gapOpen = 10;
  593. $gapExtend = 1;
  594. break;
  595. case 4:
  596. $gapOpen = 9;
  597. $gapExtend = 1;
  598. break;
  599. case 5:
  600. $gapOpen = 8;
  601. $gapExtend = 1;
  602. break;
  603. }
  604. break;
  605. case 'PAM70':
  606. switch ( $gapKey )
  607. {
  608. case 0:
  609. $gapOpen = 8;
  610. $gapExtend = 2;
  611. break;
  612. case 1:
  613. $gapOpen = 7;
  614. $gapExtend = 2;
  615. break;
  616. case 2:
  617. $gapOpen = 6;
  618. $gapExtend = 2;
  619. break;
  620. case 3:
  621. $gapOpen = 11;
  622. $gapExtend = 1;
  623. break;
  624. case 4:
  625. $gapOpen = 10;
  626. $gapExtend = 1;
  627. break;
  628. case 5:
  629. $gapOpen = 9;
  630. $gapExtend = 1;
  631. break;
  632. }
  633. break;
  634. case 'PAM250':
  635. switch ( $gapKey )
  636. {
  637. case 0:
  638. $gapOpen = 15;
  639. $gapExtend = 3;
  640. break;
  641. case 1:
  642. $gapOpen = 14;
  643. $gapExtend = 3;
  644. break;
  645. case 2:
  646. $gapOpen = 13;
  647. $gapExtend = 3;
  648. break;
  649. case 3:
  650. $gapOpen = 12;
  651. $gapExtend = 3;
  652. break;
  653. case 4:
  654. $gapOpen = 11;
  655. $gapExtend = 3;
  656. break;
  657. case 5:
  658. $gapOpen = 17;
  659. $gapExtend = 2;
  660. break;
  661. case 6:
  662. $gapOpen = 16;
  663. $gapExtend = 2;
  664. break;
  665. case 7:
  666. $gapOpen = 15;
  667. $gapExtend = 2;
  668. break;
  669. case 8:
  670. $gapOpen = 14;
  671. $gapExtend = 2;
  672. break;
  673. case 9:
  674. $gapOpen = 13;
  675. $gapExtend = 2;
  676. break;
  677. case 10:
  678. $gapOpen = 21;
  679. $gapExtend = 1;
  680. break;
  681. case 11:
  682. $gapOpen = 20;
  683. $gapExtend = 1;
  684. break;
  685. case 12:
  686. $gapOpen = 19;
  687. $gapExtend = 1;
  688. break;
  689. case 13:
  690. $gapOpen = 18;
  691. $gapExtend = 1;
  692. break;
  693. case 14:
  694. $gapOpen = 17;
  695. $gapExtend = 1;
  696. break;
  697. }
  698. break;
  699. case 'BLOSUM80':
  700. switch ( $gapKey )
  701. {
  702. case 0:
  703. $gapOpen = 8;
  704. $gapExtend = 2;
  705. break;
  706. case 1:
  707. $gapOpen = 7;
  708. $gapExtend = 2;
  709. break;
  710. case 2:
  711. $gapOpen = 6;
  712. $gapExtend = 2;
  713. break;
  714. case 3:
  715. $gapOpen = 11;
  716. $gapExtend = 1;
  717. break;
  718. case 4:
  719. $gapOpen = 10;
  720. $gapExtend = 1;
  721. break;
  722. case 5:
  723. $gapOpen = 9;
  724. $gapExtend = 1;
  725. break;
  726. }
  727. break;
  728. case 'BLOSUM62':
  729. switch ( $gapKey )
  730. {
  731. case 0:
  732. $gapOpen = 11;
  733. $gapExtend = 2;
  734. break;
  735. case 1:
  736. $gapOpen = 10;
  737. $gapExtend = 2;
  738. break;
  739. case 2:
  740. $gapOpen = 9;
  741. $gapExtend = 2;
  742. break;
  743. case 3:
  744. $gapOpen = 8;
  745. $gapExtend = 2;
  746. break;
  747. case 4:
  748. $gapOpen = 7;
  749. $gapExtend = 2;
  750. break;
  751. case 5:
  752. $gapOpen = 6;
  753. $gapExtend = 2;
  754. break;
  755. case 6:
  756. $gapOpen = 13;
  757. $gapExtend = 1;
  758. break;
  759. case 7:
  760. $gapOpen = 12;
  761. $gapExtend = 1;
  762. break;
  763. case 8:
  764. $gapOpen = 11;
  765. $gapExtend = 1;
  766. break;
  767. case 9:
  768. $gapOpen = 10;
  769. $gapExtend = 1;
  770. break;
  771. case 10:
  772. $gapOpen = 9;
  773. $gapExtend = 1;
  774. break;
  775. }
  776. break;
  777. case 'BLOSUM45':
  778. switch ( $gapKey )
  779. {
  780. case 0:
  781. $gapOpen = 13;
  782. $gapExtend = 3;
  783. break;
  784. case 1:
  785. $gapOpen = 12;
  786. $gapExtend = 3;
  787. break;
  788. case 2:
  789. $gapOpen = 11;
  790. $gapExtend = 3;
  791. break;
  792. case 3:
  793. $gapOpen = 10;
  794. $gapExtend = 3;
  795. break;
  796. case 4:
  797. $gapOpen = 15;
  798. $gapExtend = 2;
  799. break;
  800. case 5:
  801. $gapOpen = 14;
  802. $gapExtend = 2;
  803. break;
  804. case 6:
  805. $gapOpen = 13;
  806. $gapExtend = 2;
  807. break;
  808. case 7:
  809. $gapOpen = 12;
  810. $gapExtend = 2;
  811. break;
  812. case 8:
  813. $gapOpen = 19;
  814. $gapExtend = 1;
  815. break;
  816. case 9:
  817. $gapOpen = 18;
  818. $gapExtend = 1;
  819. break;
  820. case 10:
  821. $gapOpen = 17;
  822. $gapExtend = 1;
  823. break;
  824. case 11:
  825. $gapOpen = 16;
  826. $gapExtend = 1;
  827. break;
  828. }
  829. break;
  830. case 'BLOSUM50':
  831. switch ( $gapKey )
  832. {
  833. case 0:
  834. $gapOpen = 13;
  835. $gapExtend = 3;
  836. break;
  837. case 1:
  838. $gapOpen = 12;
  839. $gapExtend = 3;
  840. break;
  841. case 2:
  842. $gapOpen = 11;
  843. $gapExtend = 3;
  844. break;
  845. case 3:
  846. $gapOpen = 10;
  847. $gapExtend = 3;
  848. break;
  849. case 4:
  850. $gapOpen = 9;
  851. $gapExtend = 3;
  852. break;
  853. case 5:
  854. $gapOpen = 16;
  855. $gapExtend = 2;
  856. break;
  857. case 6:
  858. $gapOpen = 15;
  859. $gapExtend = 2;
  860. break;
  861. case 7:
  862. $gapOpen = 14;
  863. $gapExtend = 2;
  864. break;
  865. case 8:
  866. $gapOpen = 13;
  867. $gapExtend = 2;
  868. break;
  869. case 9:
  870. $gapOpen = 12;
  871. $gapExtend = 2;
  872. break;
  873. case 10:
  874. $gapOpen = 19;
  875. $gapExtend = 1;
  876. break;
  877. case 11:
  878. $gapOpen = 18;
  879. $gapExtend = 1;
  880. break;
  881. case 12:
  882. $gapOpen = 17;
  883. $gapExtend = 1;
  884. break;
  885. case 13:
  886. $gapOpen = 16;
  887. $gapExtend = 1;
  888. break;
  889. case 14:
  890. $gapOpen = 15;
  891. $gapExtend = 1;
  892. break;
  893. }
  894. break;
  895. case 'BLOSUM90':
  896. switch ( $gapKey )
  897. {
  898. case 0:
  899. $gapOpen = 9;
  900. $gapExtend = 2;
  901. break;
  902. case 1:
  903. $gapOpen = 8;
  904. $gapExtend = 2;
  905. break;
  906. case 2:
  907. $gapOpen = 7;
  908. $gapExtend = 2;
  909. break;
  910. case 3:
  911. $gapOpen = 6;
  912. $gapExtend = 2;
  913. break;
  914. case 4:
  915. $gapOpen = 11;
  916. $gapExtend = 1;
  917. break;
  918. case 5:
  919. $gapOpen = 10;
  920. $gapExtend = 1;
  921. break;
  922. case 6:
  923. $gapOpen = 9;
  924. $gapExtend = 1;
  925. break;
  926. }
  927. break;
  928. }
  929. return array(
  930. 'gapOpen' => $gapOpen,
  931. 'gapExtend' => $gapExtend
  932. );
  933. }
  934. /*
  935. ** Used for tblastn
  936. */
  937. function getGap_cost()
  938. {
  939. return array(
  940. 'PAM30' => _get_gap_for_matrix( 'PAM30' ),
  941. 'PAM70' => _get_gap_for_matrix( 'PAM70' ),
  942. 'PAM250' => _get_gap_for_matrix( 'PAM250' ),
  943. 'BLOSUM80' => _get_gap_for_matrix( 'BLOSUM80' ),
  944. 'BLOSUM62' => _get_gap_for_matrix( 'BLOSUM62' ),
  945. 'BLOSUM45' => _get_gap_for_matrix( 'BLOSUM45' ),
  946. 'BLOSUM50' => _get_gap_for_matrix( 'BLOSUM50' ),
  947. 'BLOSUM90' => _get_gap_for_matrix( 'BLOSUM90' )
  948. );
  949. }