Python 和 Matplotlib:以字符为 x 轴
Python and Matplotlib: characters as the x axis
嗨 Stack Overflow 社区。我想我正在尝试用 matplotlib 编写不可能的代码,所以如果有不同的 python 库更适合我,请告诉我!
我有一个蛋白质(蛋白质 x)的完整氨基酸序列(在图像中用大写字母表示)。这将是我的 x 轴。
我有两个 excel 专栏:疾病和控制。这些柱子包含整个蛋白质 x 的氨基酸序列的一部分。有时会有多个命中,其中疾病或控制列将包含蛋白质 x 的两个相同氨基酸部分。我希望将它们堆叠在一起,以便可以看到疾病和控制对蛋白质 x 的影响。
令人困惑?抱歉,这是我使用 powerpoint 得出的示例。
氨基酸比较
黑色文字是参考序列。紫色是控制。粉红色是疾病。现在明白了吗?
我需要用一个巨大的数据集来做这件事,所以不,我不想 "just use powerpoint for hours"。我也想用我选择的任何参考序列来做。
我不是要别人为我做我的工作。我需要有人给我指出正确的方向。有专门的图书馆吗?我应该将所有内容都转换为数字然后重新标记为文本吗?
谢谢,我很感激任何建议。
我不完全确定你想做什么,所以我会重复我认为你在说什么。
你有一串字符 (A -> T?) 代表任意蛋白质(我们称之为 X),每个字母对应 20 种氨基酸中的一种。
您还有一个 table,它有两列控制和疾病,列中的每个元素都在顺序,但必须与 X 的序列 对齐。您没有询问执行对齐,对齐本身就是一个完全不同的问题,因此我将专注于数据的可视化。
您想获取对照和疾病的 X 比对序列,并在 X 之上直观地比较它们。
你真的有三个选择。
use matplotlib's text functionality 并在执行匹配后加载要显示的文本对象中的文本(可能是我提供的选项中最困难的)
use python QT interface and do the same but with text boxes (where you will get automatic scroll functionality) (you can use QT designer to do this easily) then use setHtml
and use html formatting around your text to get proper coloration. Additionally you could also use Tkinter 并做类似的事情。
最简单的解决方案,只用你想要的内容制作一个文本文件,你放弃了着色,但你可以更容易地创建一个与 X 的氨基酸长度相同大小的数组并单独设置那里的字符,然后将所有内容写在一个文件中,如果使用统一的文本大小字体,您可以看到氨基酸排列的位置。
如果您使用 HTML 来显示,您也可以在 HTML 页面中显示它,但是您必须做更多的工作来创建可滚动区域(但您可以为文本着色)这根本就不再是 python 了。
使用脚本创建一个 SVG 图像,它是 XML 文本。我会处理更简单的事情!
假设你的目标是这个。
首先在将有一列字符串片段的每个位置断开大字符串,在本例中为 'EF' 和 'IJKL'。您可以使用 SVG XML(最近)的功能定位大字符串的片段。由于您知道片段的起始位置和字符的高度,因此您可以在列中定位图层。
这是您必须构建的那种东西。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg8"
inkscape:version="0.92.0 r15299"
sodipodi:docname="genes.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.4"
inkscape:cx="170.60599"
inkscape:cy="341.08014"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1095"
inkscape:window-height="676"
inkscape:window-x="145"
inkscape:window-y="122"
inkscape:window-maximized="0" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Courier;-inkscape-font-specification:Courier;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332;"
x="24.588797"
y="179.4014"
id="text12"><tspan
sodipodi:role="line"
id="tspan10"
x="24.588797"
y="185.32886"
style="stroke-width:0.26458332;-inkscape-font-specification:Courier;font-family:Courier;font-weight:normal;font-style:normal;font-stretch:normal;font-variant:normal;" /></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="23.8125"
y="207.41963"
id="text24"><tspan
sodipodi:role="line"
id="tspan22"
x="23.8125"
y="207.41963"
style="stroke-width:0.26458332">ABCD</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="46.302082"
y="207.41965"
id="text28"><tspan
sodipodi:role="line"
id="tspan26"
x="46.302082"
y="207.41963"
style="stroke-width:0.26458332">EFGH</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="67.657738"
y="207.41963"
id="text32"><tspan
sodipodi:role="line"
id="tspan30"
x="67.657738"
y="207.41963"
style="stroke-width:0.26458332">IJKLMN</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="46.680061"
y="199.67113"
id="text36"><tspan
sodipodi:role="line"
id="tspan34"
x="46.302082"
y="199.67113"
style="stroke-width:0.26458332">EF</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="67.846725"
y="192.86755"
id="text40"><tspan
sodipodi:role="line"
id="tspan38"
x="67.657738"
y="192.86755"
style="stroke-width:0.26458332">IJKL</tspan></text>
</g>
</svg>
显然我已经在 Inkscape 中完成了,但你会明白的。 Python
无所不能
嗨 Stack Overflow 社区。我想我正在尝试用 matplotlib 编写不可能的代码,所以如果有不同的 python 库更适合我,请告诉我!
我有一个蛋白质(蛋白质 x)的完整氨基酸序列(在图像中用大写字母表示)。这将是我的 x 轴。
我有两个 excel 专栏:疾病和控制。这些柱子包含整个蛋白质 x 的氨基酸序列的一部分。有时会有多个命中,其中疾病或控制列将包含蛋白质 x 的两个相同氨基酸部分。我希望将它们堆叠在一起,以便可以看到疾病和控制对蛋白质 x 的影响。
令人困惑?抱歉,这是我使用 powerpoint 得出的示例。
氨基酸比较
黑色文字是参考序列。紫色是控制。粉红色是疾病。现在明白了吗?
我需要用一个巨大的数据集来做这件事,所以不,我不想 "just use powerpoint for hours"。我也想用我选择的任何参考序列来做。
我不是要别人为我做我的工作。我需要有人给我指出正确的方向。有专门的图书馆吗?我应该将所有内容都转换为数字然后重新标记为文本吗?
谢谢,我很感激任何建议。
我不完全确定你想做什么,所以我会重复我认为你在说什么。
你有一串字符 (A -> T?) 代表任意蛋白质(我们称之为 X),每个字母对应 20 种氨基酸中的一种。
您还有一个 table,它有两列控制和疾病,列中的每个元素都在顺序,但必须与 X 的序列 对齐。您没有询问执行对齐,对齐本身就是一个完全不同的问题,因此我将专注于数据的可视化。
您想获取对照和疾病的 X 比对序列,并在 X 之上直观地比较它们。
你真的有三个选择。
use matplotlib's text functionality 并在执行匹配后加载要显示的文本对象中的文本(可能是我提供的选项中最困难的)
use python QT interface and do the same but with text boxes (where you will get automatic scroll functionality) (you can use QT designer to do this easily) then use
setHtml
and use html formatting around your text to get proper coloration. Additionally you could also use Tkinter 并做类似的事情。最简单的解决方案,只用你想要的内容制作一个文本文件,你放弃了着色,但你可以更容易地创建一个与 X 的氨基酸长度相同大小的数组并单独设置那里的字符,然后将所有内容写在一个文件中,如果使用统一的文本大小字体,您可以看到氨基酸排列的位置。
如果您使用 HTML 来显示,您也可以在 HTML 页面中显示它,但是您必须做更多的工作来创建可滚动区域(但您可以为文本着色)这根本就不再是 python 了。
使用脚本创建一个 SVG 图像,它是 XML 文本。我会处理更简单的事情!
假设你的目标是这个。
首先在将有一列字符串片段的每个位置断开大字符串,在本例中为 'EF' 和 'IJKL'。您可以使用 SVG XML(最近)的功能定位大字符串的片段。由于您知道片段的起始位置和字符的高度,因此您可以在列中定位图层。
这是您必须构建的那种东西。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg8"
inkscape:version="0.92.0 r15299"
sodipodi:docname="genes.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.4"
inkscape:cx="170.60599"
inkscape:cy="341.08014"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1095"
inkscape:window-height="676"
inkscape:window-x="145"
inkscape:window-y="122"
inkscape:window-maximized="0" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Courier;-inkscape-font-specification:Courier;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332;"
x="24.588797"
y="179.4014"
id="text12"><tspan
sodipodi:role="line"
id="tspan10"
x="24.588797"
y="185.32886"
style="stroke-width:0.26458332;-inkscape-font-specification:Courier;font-family:Courier;font-weight:normal;font-style:normal;font-stretch:normal;font-variant:normal;" /></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="23.8125"
y="207.41963"
id="text24"><tspan
sodipodi:role="line"
id="tspan22"
x="23.8125"
y="207.41963"
style="stroke-width:0.26458332">ABCD</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="46.302082"
y="207.41965"
id="text28"><tspan
sodipodi:role="line"
id="tspan26"
x="46.302082"
y="207.41963"
style="stroke-width:0.26458332">EFGH</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="67.657738"
y="207.41963"
id="text32"><tspan
sodipodi:role="line"
id="tspan30"
x="67.657738"
y="207.41963"
style="stroke-width:0.26458332">IJKLMN</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="46.680061"
y="199.67113"
id="text36"><tspan
sodipodi:role="line"
id="tspan34"
x="46.302082"
y="199.67113"
style="stroke-width:0.26458332">EF</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="67.846725"
y="192.86755"
id="text40"><tspan
sodipodi:role="line"
id="tspan38"
x="67.657738"
y="192.86755"
style="stroke-width:0.26458332">IJKL</tspan></text>
</g>
</svg>
显然我已经在 Inkscape 中完成了,但你会明白的。 Python
无所不能