PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Prohits/analyst/classes/plateWell_class.php

http://prohits.googlecode.com/
PHP | 277 lines | 214 code | 8 blank | 55 comment | 16 complexity | cb3f1683b26aadddd43e4a72d506ae08 MD5 | raw file
  1. <?php
  2. /***********************************************************************
  3. Copyright 2010 Gingras and Tyers labs,
  4. Samuel Lunenfeld Research Institute, Mount Sinai Hospital.
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. *************************************************************************/
  15. class PlateWell{
  16. var $ID;
  17. var $PlateID;
  18. var $BandID;
  19. var $WellCode;
  20. var $OwnerID;
  21. var $ProjectID;
  22. var $DateTime;
  23. var $HitBaitID; //for get_plate_hits()
  24. var $HitGeneID;
  25. var $HitLocusTag;
  26. var $HitORFName; //for get_plate_hits()
  27. var $HitID; //for get_plate_hits()
  28. var $HitBandID; //for get_plate_hits()
  29. var $HitMW; //for get_plate_hits()
  30. var $count;
  31. //----------------------------------------------
  32. // default function
  33. //----------------------------------------------
  34. function PlateWell( $ID="") {
  35. if($ID) {
  36. $this->fetch($ID);
  37. }
  38. }//function end
  39. //----------------------------------------------
  40. // fetch function
  41. //----------------------------------------------
  42. function fetch($ID="") {
  43. if($ID){
  44. $this->ID = $ID;
  45. $SQL = "SELECT
  46. ID,
  47. PlateID,
  48. BandID,
  49. WellCode,
  50. OwnerID,
  51. ProjectID,
  52. DateTime
  53. FROM PlateWell where ID='$this->ID'";
  54. list(
  55. $this->ID,
  56. $this->PlateID,
  57. $this->BandID,
  58. $this->WellCode,
  59. $this->OwnerID,
  60. $this->ProjectID,
  61. $this->DateTime) = mysql_fetch_array(mysql_query($SQL));
  62. $this->count = 1;
  63. }
  64. } //end of function fetch
  65. //----------------------------------------------
  66. // fetchall function
  67. //----------------------------------------------
  68. function fetchall_this_plate($Plate_ID) {
  69. if(!$Plate_ID) {
  70. echo "Error: Missing info to get palte";
  71. exit;
  72. }
  73. $SQL = "SELECT
  74. ID,
  75. PlateID,
  76. BandID,
  77. WellCode,
  78. OwnerID,
  79. ProjectID,
  80. DateTime
  81. FROM PlateWell";
  82. $SQL .= " WHERE PlateID='$Plate_ID'";
  83. $SQL .= " ORDER BY WellCode";
  84. $i = 0;
  85. //echo $SQL;
  86. $sqlResult = mysql_query($SQL);
  87. $this->count = mysql_num_rows($sqlResult);
  88. while (list(
  89. $this->ID[$i],
  90. $this->PlateID[$i],
  91. $this->BandID[$i],
  92. $this->WellCode[$i],
  93. $this->OwnerID[$i],
  94. $this->ProjectID[$i],
  95. $this->DateTime[$i])= mysql_fetch_row($sqlResult) ) {
  96. $i++;
  97. }
  98. }//end of function fetchall
  99. //------------------------------------------------
  100. // used by band.php
  101. //------------------------------------------------
  102. function fetch_wells_in_lane_or_exp($Lane_ID=0, $Exp_ID=0){
  103. if(!$Lane_ID and !$Exp_ID) {
  104. return;
  105. }
  106. $SQL = "SELECT
  107. W.ID,
  108. W.PlateID,
  109. W.BandID,
  110. W.WellCode,
  111. W.OwnerID,
  112. W.ProjectID,
  113. W.DateTime
  114. FROM PlateWell W, Band B WHERE W.BandID=B.ID";
  115. if($Lane_ID){
  116. $SQL .= " and B.LaneID='$Lane_ID'";
  117. }else{
  118. $SQL .= " and B.ExpID='$Exp_ID'";
  119. }
  120. $SQL .= " ORDER BY W.PlateID,WellCode";
  121. $i = 0;
  122. //echo $SQL;
  123. $sqlResult = mysql_query($SQL);
  124. $this->count = mysql_num_rows($sqlResult);
  125. while (list(
  126. $this->ID[$i],
  127. $this->PlateID[$i],
  128. $this->BandID[$i],
  129. $this->WellCode[$i],
  130. $this->OwnerID[$i],
  131. $this->ProjectID[$i],
  132. $this->DateTime[$i])= mysql_fetch_row($sqlResult) ) {
  133. $i++;
  134. }
  135. }
  136. //----------------------------------------------
  137. // insert function
  138. //----------------------------------------------
  139. function insert($frm_PlateID, $frm_BandID, $frm_WellCode, $frm_OwnerID=0, $frm_ProjectID=0){
  140. if(
  141. !$frm_PlateID or
  142. !$frm_WellCode or
  143. !$frm_OwnerID
  144. ){
  145. echo "missing info: ... insert aborted.";
  146. echo "$frm_PlateID, $frm_BandID, $frm_WellCode, $frm_OwnerID=0, $frm_ProjectID=0";
  147. exit;
  148. }else{
  149. //check if the well is used in the plate
  150. $SQL = "select ID from PlateWell where PlateID = '$frm_PlateID' and WellCode = '$frm_WellCode'";
  151. if(!mysql_num_rows(mysql_query($SQL))){
  152. $SQL ="INSERT INTO PlateWell SET
  153. PlateID='$frm_PlateID',
  154. BandID='$frm_BandID',
  155. WellCode='$frm_WellCode',
  156. OwnerID='$frm_OwnerID',
  157. ProjectID='$frm_ProjectID',
  158. DateTime=now()";
  159. mysql_query($SQL);
  160. $this->ID = mysql_insert_id();
  161. //set PlateID into Band
  162. $SQL = "UPDATE Band SET inPlate=$frm_PlateID WHERE ID = $frm_BandID";
  163. mysql_query($SQL);
  164. }
  165. }
  166. }//end insert
  167. //----------------------------------------------
  168. // remove function
  169. //----------------------------------------------
  170. function remove($Band_ID) {
  171. //check if this Band link to Hits. It shouldn't be deleted
  172. $SQL = "Select ID from Hits where BandID='$Band_ID'";
  173. if(mysql_num_rows(mysql_query($SQL))){
  174. return "The Well can not be deleted since it links to hits.";
  175. }
  176. $SQL = "DELETE FROM PlateWell WHERE BandID = '$Band_ID'";
  177. mysql_query($SQL);
  178. //set 0 inPlate for Band record
  179. mysql_query("UPDATE Band SET inPlate=0 WHERE ID = $Band_ID");
  180. return '';
  181. }
  182. //----------------------------------------------
  183. // update function
  184. //----------------------------------------------
  185. function update(
  186. $frm_ID=0,
  187. $frm_PlateID=0,
  188. $frm_BandID=0,
  189. $frm_WellCode='',
  190. $frm_OwnerID=0,
  191. $frm_ProjectID=0,
  192. $frm_DateTime=''){
  193. $SQL ="UPDATE PlateWell SET
  194. PlateID='$frm_PlateID',
  195. BandID='$frm_BandID',
  196. WellCode='$frm_WellCode',
  197. OwnerID='$frm_OwnerID',
  198. ProjectID='$frm_ProjectID',
  199. DateTime='$frm_DateTime'
  200. WHERE ID =$frm_ID ";
  201. mysql_query($SQL);
  202. }//end of function update
  203. function get_plate_id($Band_ID){
  204. $SQL = "select PlateID from PlateWell where BandID = $Band_ID group by PlateID";
  205. $sqlResult = mysql_query($SQL);
  206. if($row = mysql_fetch_row($sqlResult)){
  207. return $row[0];
  208. }else{
  209. return 0;
  210. }
  211. }
  212. //------------------------------------
  213. //for checkCarryOver.inc.php
  214. //fetch all hits in the specified plate
  215. //------------------------------------
  216. function get_plate_hits($Plate_ID){
  217. if(!$Plate_ID) exit;
  218. $SQL = "select W.ID, W.WellCode, H.BaitID, H.GeneID, H.LocusTag, H.ID, H.BandID, H.MW
  219. from PlateWell W, Hits H where W.ID=H.WellID and W.PlateID='$Plate_ID'";
  220. //echo $SQL;
  221. $sqlResult = mysql_query($SQL);
  222. $this->count = mysql_num_rows($sqlResult);
  223. $i = 0;
  224. while (list(
  225. $this->ID[$i],
  226. $this->WellCode[$i],
  227. $this->HitBaitID[$i],
  228. $this->HitGeneID[$i],
  229. $this->HitLocusTag[$i],
  230. $this->HitID[$i],
  231. $this->HitBandID[$i],
  232. $this->HitMW[$i] )= mysql_fetch_row($sqlResult) ) {
  233. $i++;
  234. }
  235. }//end function
  236. //---------------------------------
  237. // used by UploadMDS.php
  238. //---------------------------------
  239. function is_exsist($plateName,$wellCode, $Plate_ID = 0){
  240. if($Plate_ID){
  241. $SQL = "select ID from PlateWell where PlateID='$Plate_ID' and WellCode='$wellCode'";
  242. }else{
  243. $SQL = "select W.ID from PlateWell W, Plate P where W.PlateID=P.ID and P.Name='$plateName' and W.WellCode='$wellCode'";
  244. }
  245. if($row = mysql_fetch_row(mysql_query($SQL))){
  246. return 1;
  247. }else{
  248. return 0;
  249. }
  250. }
  251. //----------------------------------
  252. // used by plate_show.php
  253. //----------------------------------
  254. function band_in_plate($Band_ID){
  255. $Plate_ID_arr = array();
  256. if(!$Band_ID)return $Plate_ID_arr;
  257. $SQL = "select PlateID from PlateWell where BandID='$Band_ID'";
  258. //echo $SQL;
  259. $results = mysql_query($SQL);
  260. while($row = mysql_fetch_row($results) ){
  261. array_push($Plate_ID_arr,$row[0]);
  262. }
  263. return array_unique($Plate_ID_arr);
  264. }
  265. }//end of class
  266. ?>