1// 2// BCAminoAcid.m 3// BioCocoa 4// 5// Created by Koen van der Drift on Sat May 10 2003. 6// Copyright (c) 2003-2009 The BioCocoa Project. 7// All rights reserved. 8// 9// Redistribution and use in source and binary forms, with or without 10// modification, are permitted provided that the following conditions 11// are met: 12// 1. Redistributions of source code must retain the above copyright 13// notice, this list of conditions and the following disclaimer. 14// 2. Redistributions in binary form must reproduce the above copyright 15// notice, this list of conditions and the following disclaimer in the 16// documentation and/or other materials provided with the distribution. 17// 3. The name of the author may not be used to endorse or promote products 18// derived from this software without specific prior written permission. 19// 20// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31#import "BCAminoAcid.h" 32#import "BCStringDefinitions.h" 33 34static BCAminoAcid *alanineRepresentation = nil; 35static BCAminoAcid *arginineRepresentation = nil; 36static BCAminoAcid *asparagineRepresentation = nil; 37static BCAminoAcid *asparticacidRepresentation = nil; 38static BCAminoAcid *cysteineRepresentation = nil; 39static BCAminoAcid *glutamicacidRepresentation = nil; 40static BCAminoAcid *glutamineRepresentation = nil; 41static BCAminoAcid *glycineRepresentation = nil; 42static BCAminoAcid *histidineRepresentation = nil; 43static BCAminoAcid *isoleucineRepresentation = nil; 44static BCAminoAcid *leucineRepresentation = nil; 45static BCAminoAcid *lysineRepresentation = nil; 46static BCAminoAcid *methionineRepresentation = nil; 47static BCAminoAcid *phenylalanineRepresentation = nil; 48static BCAminoAcid *prolineRepresentation = nil; 49static BCAminoAcid *serineRepresentation = nil; 50static BCAminoAcid *threonineRepresentation = nil; 51static BCAminoAcid *tryptophanRepresentation = nil; 52static BCAminoAcid *tyrosineRepresentation = nil; 53static BCAminoAcid *valineRepresentation = nil; 54static BCAminoAcid *glxRepresentation = nil; 55static BCAminoAcid *asxRepresentation = nil; 56static BCAminoAcid *gapRepresentation = nil; 57static BCAminoAcid *undefinedRepresentation = nil; 58 59static NSMutableDictionary *aminoAcidPropertiesDict = nil; 60 61 62@implementation BCAminoAcid 63 64- (id)initWithSymbolChar:(unsigned char)aChar 65{ 66 if ([super initWithSymbolChar:aChar]) 67 { 68 symbolInfo = [[[BCAminoAcid aaPropertiesDict] objectForKey:[self symbolString]] copy]; 69 70 if ( nil == symbolInfo ) 71 { 72 return nil; 73 } 74 75 name = [[symbolInfo objectForKey: BCSymbolNameProperty] copy]; 76 threeLetterCode = [[symbolInfo objectForKey: BCSymbolThreeLetterCodeProperty] copy]; 77 78 [self setKyteDoolittleValue: [[symbolInfo objectForKey: BCSymbolKyteDoolittleProperty] floatValue]]; 79 [self setHoppWoodsValue: [[symbolInfo objectForKey: BCSymbolHoppWoodsProperty] floatValue]]; 80 [self setpKaValue: [[symbolInfo objectForKey: BCSymbolpKaProperty] floatValue]]; 81 82 [self setMonoisotopicMass: [[symbolInfo objectForKey: BCSymbolMonoisotopicMassProperty] floatValue]]; 83 [self setAverageMass: [[symbolInfo objectForKey: BCSymbolAverageMassProperty] floatValue]]; 84 } 85 86 return self; 87} 88 89- (void)dealloc 90{ 91 [symbolInfo release]; 92 [name release]; 93 [threeLetterCode release]; 94 95 [super dealloc]; 96} 97 98 99+ (NSMutableDictionary *) aaPropertiesDict 100{ 101 if ( aminoAcidPropertiesDict == nil ) 102 { 103 NSString *filePath = [[NSBundle bundleForClass: [BCAminoAcid class]] 104 pathForResource: @"aminoacids" ofType: @"plist"]; 105 aminoAcidPropertiesDict = [NSMutableDictionary dictionaryWithContentsOfFile: filePath]; 106 } 107 108 return aminoAcidPropertiesDict; 109} 110 111+ (id) symbolForChar: (unsigned char)aSymbol 112{ 113 switch ( aSymbol ) { 114 115 case 'A' : 116 case 'a' : { 117 return [BCAminoAcid alanine]; 118 break; 119 } 120 121 case 'R' : 122 case 'r' : { 123 return [BCAminoAcid arginine]; 124 break; 125 } 126 127 case 'N' : 128 case 'n' : { 129 return [BCAminoAcid asparagine]; 130 break; 131 } 132 133 case 'D' : 134 case 'd' : { 135 return [BCAminoAcid asparticacid]; 136 break; 137 } 138 139 case 'C' : 140 case 'c' : { 141 return [BCAminoAcid cysteine]; 142 break; 143 } 144 145 case 'E' : 146 case 'e' : { 147 return [BCAminoAcid glutamicacid]; 148 break; 149 } 150 151 case 'Q' : 152 case 'q' : { 153 return [BCAminoAcid glutamine]; 154 break; 155 } 156 157 case 'G' : 158 case 'g' : { 159 return [BCAminoAcid glycine]; 160 break; 161 } 162 163 case 'H' : 164 case 'h' : { 165 return [BCAminoAcid histidine]; 166 break; 167 } 168 169 case 'I' : 170 case 'i' : { 171 return [BCAminoAcid isoleucine]; 172 break; 173 } 174 175 case 'L' : 176 case 'l' : { 177 return [BCAminoAcid leucine]; 178 break; 179 } 180 181 case 'K' : 182 case 'k' : { 183 return [BCAminoAcid lysine]; 184 break; 185 } 186 187 case 'M' : 188 case 'm' : { 189 return [BCAminoAcid methionine]; 190 break; 191 } 192 193 case 'F' : 194 case 'f' : { 195 return [BCAminoAcid phenylalanine]; 196 break; 197 } 198 199 case 'P' : 200 case 'p' : { 201 return [BCAminoAcid proline]; 202 break; 203 } 204 205 case 'S' : 206 case 's' : { 207 return [BCAminoAcid serine]; 208 break; 209 } 210 211 case 'T' : 212 case 't' : { 213 return [BCAminoAcid threonine]; 214 break; 215 } 216 217 218 case 'W' : 219 case 'w' : { 220 return [BCAminoAcid tryptophan]; 221 break; 222 } 223 224 case 'Y' : 225 case 'y' : { 226 return [BCAminoAcid tyrosine]; 227 break; 228 } 229 230 case 'V' : 231 case 'v' : { 232 return [BCAminoAcid valine]; 233 break; 234 } 235 236 case 'B' : 237 case 'b' : { 238 return [BCAminoAcid asx]; 239 break; 240 } 241 242 case 'Z' : 243 case 'z' : { 244 return [BCAminoAcid glx]; 245 break; 246 } 247 248 case '-' : { 249 return [BCAminoAcid gap]; 250 break; 251 } 252 253 case '*' : { 254 return nil; // stop amino acid 255 break; 256 } 257 258 default : 259 return [BCAminoAcid undefined]; 260 } 261} 262 263 264 265+ (id) objectForSavedRepresentation: (NSString *)aSymbol { 266 return [BCAminoAcid symbolForChar: [aSymbol characterAtIndex: 0]]; 267} 268 269 270+ (void) initAminoAcids 271{ 272 NSDictionary *aaDefinitions = [BCAminoAcid aaPropertiesDict]; 273 274 NSDictionary *tempDict = [aaDefinitions objectForKey: @"A"]; 275 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 276 alanineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'A']; 277 } 278 279 tempDict = [aaDefinitions objectForKey: @"R"]; 280 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 281 arginineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'R']; 282 } 283 284 tempDict = [aaDefinitions objectForKey: @"N"]; 285 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 286 asparagineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'N']; 287 } 288 289 tempDict = [aaDefinitions objectForKey: @"D"]; 290 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 291 asparticacidRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'D']; 292 } 293 294 tempDict = [aaDefinitions objectForKey: @"C"]; 295 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 296 cysteineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'C']; 297 } 298 299 tempDict = [aaDefinitions objectForKey: @"E"]; 300 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 301 glutamicacidRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'E']; 302 } 303 304 tempDict = [aaDefinitions objectForKey: @"Q"]; 305 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 306 glutamineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'Q']; 307 } 308 309 tempDict = [aaDefinitions objectForKey: @"G"]; 310 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 311 glycineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'G']; 312 } 313 314 tempDict = [aaDefinitions objectForKey: @"H"]; 315 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 316 histidineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'H']; 317 } 318 319 tempDict = [aaDefinitions objectForKey: @"I"]; 320 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 321 isoleucineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'I']; 322 } 323 324 tempDict = [aaDefinitions objectForKey: @"L"]; 325 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 326 leucineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'L']; 327 } 328 329 tempDict = [aaDefinitions objectForKey: @"K"]; 330 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 331 lysineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'K']; 332 } 333 334 tempDict = [aaDefinitions objectForKey: @"M"]; 335 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 336 methionineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'M']; 337 } 338 339 tempDict = [aaDefinitions objectForKey: @"F"]; 340 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 341 phenylalanineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'F']; 342 } 343 344 tempDict = [aaDefinitions objectForKey: @"P"]; 345 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 346 prolineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'P']; 347 } 348 349 tempDict = [aaDefinitions objectForKey: @"S"]; 350 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 351 serineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'S']; 352 } 353 354 tempDict = [aaDefinitions objectForKey: @"T"]; 355 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 356 threonineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'T']; 357 } 358 359 tempDict = [aaDefinitions objectForKey: @"W"]; 360 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 361 tryptophanRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'W']; 362 } 363 364 tempDict = [aaDefinitions objectForKey: @"Y"]; 365 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 366 tyrosineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'Y']; 367 } 368 369 tempDict = [aaDefinitions objectForKey: @"V"]; 370 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 371 valineRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'V']; 372 } 373 374 tempDict = [aaDefinitions objectForKey: @"B"]; 375 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 376 asxRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'B']; 377 } 378 379 tempDict = [aaDefinitions objectForKey: @"Z"]; 380 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 381 glxRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: 'Z']; 382 } 383 384 tempDict = [aaDefinitions objectForKey: @"-"]; 385 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 386 gapRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: '-']; 387 } 388 389 tempDict = [aaDefinitions objectForKey: @"?"]; 390 if ( tempDict != nil && [tempDict isKindOfClass: [NSDictionary class]] ) { 391 undefinedRepresentation = [[BCAminoAcid alloc] initWithSymbolChar: '?']; 392 } 393} 394 395+ (BCAminoAcid *) alanine { 396 if ( alanineRepresentation == nil ) 397 [BCAminoAcid initAminoAcids]; 398 return alanineRepresentation; 399} 400 401+ (BCAminoAcid *) arginine { 402 if ( arginineRepresentation == nil ) 403 [BCAminoAcid initAminoAcids]; 404 return arginineRepresentation; 405} 406 407+ (BCAminoAcid *) asparagine { 408 if ( asparagineRepresentation == nil ) 409 [BCAminoAcid initAminoAcids]; 410 return asparagineRepresentation; 411} 412 413+ (BCAminoAcid *) asparticacid { 414 if ( asparticacidRepresentation == nil ) 415 [BCAminoAcid initAminoAcids]; 416 return asparticacidRepresentation; 417} 418 419+ (BCAminoAcid *) cysteine { 420 if ( cysteineRepresentation == nil ) 421 [BCAminoAcid initAminoAcids]; 422 return cysteineRepresentation; 423} 424 425+ (BCAminoAcid *) glutamicacid { 426 if ( glutamicacidRepresentation == nil ) 427 [BCAminoAcid initAminoAcids]; 428 return glutamicacidRepresentation; 429} 430 431 432+ (BCAminoAcid *) glutamine { 433 if ( glutamineRepresentation == nil ) 434 [BCAminoAcid initAminoAcids]; 435 return glutamineRepresentation; 436} 437 438 439+ (BCAminoAcid *) glycine { 440 if ( glycineRepresentation == nil ) 441 [BCAminoAcid initAminoAcids]; 442 return glycineRepresentation; 443} 444 445 446+ (BCAminoAcid *) histidine { 447 if ( histidineRepresentation == nil ) 448 [BCAminoAcid initAminoAcids]; 449 return histidineRepresentation; 450} 451 452 453+ (BCAminoAcid *) isoleucine { 454 if ( isoleucineRepresentation == nil ) 455 [BCAminoAcid initAminoAcids]; 456 return isoleucineRepresentation; 457} 458 459 460+ (BCAminoAcid *) leucine { 461 if ( leucineRepresentation == nil ) 462 [BCAminoAcid initAminoAcids]; 463 return leucineRepresentation; 464} 465 466 467+ (BCAminoAcid *) lysine { 468 if ( lysineRepresentation == nil ) 469 [BCAminoAcid initAminoAcids]; 470 return lysineRepresentation; 471} 472 473+ (BCAminoAcid *) methionine { 474 if ( methionineRepresentation == nil ) 475 [BCAminoAcid initAminoAcids]; 476 return methionineRepresentation; 477} 478 479+ (BCAminoAcid *) phenylalanine { 480 if ( phenylalanineRepresentation == nil ) 481 [BCAminoAcid initAminoAcids]; 482 return phenylalanineRepresentation; 483} 484 485+ (BCAminoAcid *) proline { 486 if ( prolineRepresentation == nil ) 487 [BCAminoAcid initAminoAcids]; 488 return prolineRepresentation; 489} 490 491+ (BCAminoAcid *) serine { 492 if ( serineRepresentation == nil ) 493 [BCAminoAcid initAminoAcids]; 494 return serineRepresentation; 495} 496 497+ (BCAminoAcid *) threonine { 498 if ( threonineRepresentation == nil ) 499 [BCAminoAcid initAminoAcids]; 500 return threonineRepresentation; 501} 502 503+ (BCAminoAcid *) tryptophan { 504 if ( tryptophanRepresentation == nil ) 505 [BCAminoAcid initAminoAcids]; 506 return tryptophanRepresentation; 507} 508 509+ (BCAminoAcid *) tyrosine { 510 if ( tyrosineRepresentation == nil ) 511 [BCAminoAcid initAminoAcids]; 512 return tyrosineRepresentation; 513} 514 515+ (BCAminoAcid *) valine { 516 if ( valineRepresentation == nil ) 517 [BCAminoAcid initAminoAcids]; 518 return valineRepresentation; 519} 520 521+ (BCAminoAcid *) asx { 522 if ( asxRepresentation == nil ) 523 [BCAminoAcid initAminoAcids]; 524 return asxRepresentation; 525} 526 527+ (BCAminoAcid *) glx { 528 if ( glxRepresentation == nil ) 529 [BCAminoAcid initAminoAcids]; 530 return glxRepresentation; 531} 532 533+ (BCAminoAcid *) gap { 534 if ( gapRepresentation == nil ) 535 [BCAminoAcid initAminoAcids]; 536 return gapRepresentation; 537} 538 539+ (BCAminoAcid *) undefined { 540 if ( undefinedRepresentation == nil ) 541 [BCAminoAcid initAminoAcids]; 542 return undefinedRepresentation; 543} 544 545 546- (NSString *)threeLetterCode 547{ 548 return threeLetterCode; 549} 550 551- (float)kyteDoolittleValue 552{ 553 return kyteDoolittleValue; 554} 555 556- (void)setKyteDoolittleValue:(float)value 557{ 558 kyteDoolittleValue = value; 559} 560 561- (float)hoppWoodsValue 562{ 563 return hoppWoodsValue; 564} 565 566- (void)setHoppWoodsValue:(float)value 567{ 568 hoppWoodsValue = value; 569} 570 571- (float)pKaValue 572{ 573 return pKaValue; 574} 575 576- (void)setpKaValue:(float)value 577{ 578 pKaValue = value; 579} 580 581 582@end 583