/alignSeqs/updateMismatchAndMiddleFlatOLD.py

https://github.com/JasonAng/ResearchScripts
Python | 91 lines | 63 code | 26 blank | 2 comment | 16 complexity | f8087547d7ffdf7ee6886aea2966422a MD5 | raw file
  1. import bioLibCG
  2. import cgNexusFlat
  3. import cgPeaks
  4. import cgAlignmentFlat
  5. def markCenterExpression(aFN, cName, rn = None, tn = None):
  6. aNX = cgNexusFlat.Nexus(aFN, cgAlignmentFlat.cgAlignment)
  7. aNX.load(['centerExpression', 'tTcc', 'tStart', 'sLength'], [rn, tn])
  8. for aID in aNX.centerExpression:
  9. aNX.centerExpression[aID] = [0.0, 0.0, 0.0]
  10. chrom, strand, start, end = bioLibCG.tccSplit(aNX.tTcc[aID])
  11. offset = aNX.tStart[aID]
  12. sLen = aNX.sLength[aID]
  13. if strand == '1':
  14. start = start - 19 + offset
  15. end = start + sLen
  16. else:
  17. end = end + 19 - offset
  18. start = end - sLen
  19. scanRange = bioLibCG.makeTcc(chrom, strand, start, end)
  20. stretch = cgPeaks.stretch(scanRange, cName)
  21. expressionSum = stretch.getSumOfLevels()
  22. sortedKeys = stretch.profile.keys()
  23. sortedKeys.sort()
  24. if strand == '-1':
  25. sortedKeys.reverse()
  26. if expressionSum != 0:
  27. sum = 0.0
  28. for key in sortedKeys[8:12]:
  29. sum += stretch.profile[key]
  30. aNX.centerExpression[aID][0] = sum/expressionSum
  31. sum = 0.0
  32. for key in sortedKeys[7:13]:
  33. sum += stretch.profile[key]
  34. aNX.centerExpression[aID][1] = sum/expressionSum
  35. sum = 0.0
  36. for key in sortedKeys[6:14]:
  37. sum += stretch.profile[key]
  38. aNX.centerExpression[aID][2] = sum/expressionSum
  39. aNX.save()
  40. def markMismatchedPairs(aFN, rn = None, tn = None):
  41. #make mismatchDict
  42. aNX = cgNexusFlat.Nexus(aFN, cgAlignmentFlat.cgAlignment)
  43. aNX.load(['mismatchStatus', 'mismatchPositions'], [rn, tn])
  44. for aID in aNX.mismatchStatus:
  45. aNX.mismatchStatus[aID] = [False, False, False]
  46. lowRange = range(9,13)
  47. midRange = range(8,14)
  48. highRange = range(7,15)
  49. #check mismatches
  50. for i in lowRange:
  51. if i in aNX.mismatchPositions[aID]:
  52. aNX.mismatchStatus[aID][0] = True
  53. break
  54. for i in midRange:
  55. if i in aNX.mismatchPositions[aID]:
  56. aNX.mismatchStatus[aID][1] = True
  57. break
  58. for i in highRange:
  59. if i in aNX.mismatchPositions:
  60. aNX.mismatchStatus[aID][2] = True
  61. break
  62. aNX.save()
  63. if __name__ == "__main__":
  64. import sys
  65. bioLibCG.submitArgs(globals()[sys.argv[1]], sys.argv[1:])