LoginSignup
1
0

More than 3 years have passed since last update.

plotHeatmapのカラーバランスを自動で全通り作成する方法。

Last updated at Posted at 2019-10-12

ChIP-seq のヒートマップの色バリエーションを全パターン作成する方法

各ターゲットとする領域におけるChIP-seq シグナルを可視化する方法にHeatmapが一覧的に見やすく便利です。

bamfile から,deeptools のbamCoverageもしくはbamCompare, bigwigCompareなどを用いて,bigwigファイルを作成し,computeMatrixやplotProfile, plotHeatmapの機能を用いて,ヒートマップを作成しています。

データ解析を頼まれるときに,時に元々のChIP-seqのシグナルがあまり出ていないのに,カラーバランスを調整して見やすくするよう求められることがあります。

どうやっても無理な場合は,想定しうるカラーコントラストを全通り作成して,当人に選んでもらうことで納得される場合があります。

このようなときに役立つplotHeatmapの色のグラデーションのパターンをすべて網羅する方法を作成しました。
用途としては,やや後ろ向きですが,納得しない方に無限に時間を吸い取られることを考えると,役に立つときもあります。
現在は、SLURMシステムを用いているのですが,Deeptoolsをインストール済みの通常のLinuxでも実行可能と思います。
pythonを用いてコードを複数作成してそれを実行するイメージです。

all-color-variation.ipynb
import numpy as np
import itertools

# provide the color-code information to decide the color for the lowest signal and for the highest signal
print("color example : white >> ffffff, black >> 000000, blue >> 0000ff, red >> ff0000, green >> 00ff00")
print("You can also check color-code in https://www.color-hex.com/")
print("")
LowColor  = input("Input the color for the lowest signal. (eg: ffffff) : ")
HighColor = input("Input the color for the highest signal. (eg: 0000ff) : ")
Color_div = int(input("How many color point do you need for color contrast ? (2~8) : ")) - 1

# convert the color-code (hex) to the int
int_lowCol = [int(LowColor[0:2], 16), int(LowColor[2:4], 16), int(LowColor[4:6], 16)]
int_highCol = [int(HighColor[0:2], 16), int(HighColor[2:4], 16), int(HighColor[4:6], 16)]

loColarr = np.array(int_lowCol)
hiColarr = np.array(int_highCol)

lo2high = hiColarr - loColarr
div_lo2high = lo2high / Color_div

color_dict = {}
color_dict[0] = "#" + LowColor
color_dict[Color_div] = "#" + HighColor

for i in range(1, Color_div):
    div_color_arr = loColarr + div_lo2high * i
    div_color_arr = div_color_arr.astype(int)
    div_color = "#" + '{:02x}'.format(div_color_arr[0]) + \
                      '{:02x}'.format(div_color_arr[1]) + \
                      '{:02x}'.format(div_color_arr[2])
    color_dict[i] = div_color

# For confirmation of color list
print(color_dict)

# make the list of the combinations with the replacement for the color_dict.keys()
ColIntList = list(itertools.combinations_with_replacement(np.arange(Color_div + 1), Color_div + 1))

# convert the number to the colors with color_dict
for ind, arr in enumerate(ColIntList):
    ColorList[ind] = [color_dict[elm] for elm in arr]

    Color_choice = ",".join(ColorList[ind])

    COLOR_CODE = "'" + Color_choice  + "' '" + Color_choice + "' '" + \
                 Color_choice + "' '" + Color_choice + "'"

    code = "plotHeatmap -m ComputedMatrix.gz -out ChIPsignalTopltHeatmap_KClust5_ver" + str(ind + 1) + ".pdf --plotFileFormat 'pdf' --colorList " + COLOR_CODE + " --plotTitle ChIPsignalTopltHeatmap --refPointLabel Center --kmeans 5"
    print(code, file = open("codes_plotHeatmap_colorVariationsWithHEXcode_KmeansClust5", "a"))

こうすることでcodes_plotHeatmap_colorVariationsWithHEXcode_KmeansClust5というファイルに,今回はkmeans clusterで5分割されたheatmapに色のグラデーションパターンを組み合わせたコードを作成することができます
color pointが7の場合, 約1716通りの色のグラデーションパターンを作成することができます。

これで,微妙なコントラストの調整も可能です.

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0