Mercurial > repos > guerler > springsuite
comparison spring_package/Utilities.py @ 39:172398348efd draft
"planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
| author | guerler | 
|---|---|
| date | Fri, 22 Jan 2021 15:50:27 +0000 | 
| parents | |
| children | 
   comparison
  equal
  deleted
  inserted
  replaced
| 38:80a4b98121b6 | 39:172398348efd | 
|---|---|
| 1 from os.path import isfile | |
| 2 | |
| 3 | |
| 4 def validateIdentifier(identifier): | |
| 5 if len(identifier) < 6 or identifier[4:5] != "_": | |
| 6 raise Exception("Invalid list entry (`PDB_CHAIN`): %s." % identifier) | |
| 7 | |
| 8 | |
| 9 def getId(identifier): | |
| 10 identifier = identifier.strip() | |
| 11 validateIdentifier(identifier) | |
| 12 return identifier[:4].upper() + identifier[4:6] | |
| 13 | |
| 14 | |
| 15 def getChain(identifier): | |
| 16 validateIdentifier(identifier) | |
| 17 pdbChain = identifier[5:6] | |
| 18 return pdbChain | |
| 19 | |
| 20 | |
| 21 def getName(identifier): | |
| 22 pdb = identifier[:4].lower() | |
| 23 return pdb | |
| 24 | |
| 25 | |
| 26 def getCrossReference(crossReferenceFile, allPartners=False): | |
| 27 crossReference = dict() | |
| 28 crossCount = 0 | |
| 29 with open(crossReferenceFile) as file: | |
| 30 for line in file: | |
| 31 columns = line.split() | |
| 32 if len(columns) < 2: | |
| 33 raise Exception("Invalid Cross Reference Entry %s." % line) | |
| 34 core = columns[0] | |
| 35 partner = columns[1] | |
| 36 if len(columns) < 4: | |
| 37 templates = [core, partner] | |
| 38 else: | |
| 39 templates = [columns[2], columns[3]] | |
| 40 if core not in crossReference: | |
| 41 crossReference[core] = dict(partners=list(), templates=list()) | |
| 42 if allPartners or partner not in crossReference[core]["partners"]: | |
| 43 crossReference[core]["partners"].append(partner) | |
| 44 crossReference[core]["templates"].append(templates) | |
| 45 crossCount = crossCount + 1 | |
| 46 print("Identified %s reference interactions." % crossCount) | |
| 47 return crossReference | |
| 48 | |
| 49 | |
| 50 def getTemplates(hhrFile, minScore=10): | |
| 51 result = dict() | |
| 52 topTemplate = None | |
| 53 if isfile(hhrFile): | |
| 54 with open(hhrFile) as file: | |
| 55 for index, line in enumerate(file): | |
| 56 if index > 8: | |
| 57 if not line.strip(): | |
| 58 break | |
| 59 templateId = line[4:10] | |
| 60 templateScore = float(line[57:63]) | |
| 61 if templateScore > minScore: | |
| 62 if topTemplate is None: | |
| 63 topTemplate = templateId | |
| 64 result[templateId] = templateScore | |
| 65 return topTemplate, result | 
