我如何 'lower' 在 python 中按特定角度绘制图表

How do I 'lower' graph by a certain angle in python

我目前正在编写 'doing' 程序并绘制 DNA 样本的相位分析,但有些问题:Output plot HERE! 右侧的图像来自 MATLAB,是它如何进行的示例应该看起来像。左边的图像是我程序的输出。正如您所看到的,蓝色图表看起来是正确的,但它处于不同的角度。我检查了代码,它与我程序的 MATLAB 版本中的代码基本相同。无论如何我都会把它放在这里也许有一个我不知道的错误。但如果不是,有没有办法 'turning/lowering' 将该图移到正确的位置?

Python 代码在这里:

def listIni(size, const=0):
    return [const] * size

seq = SeqIO.read("C:/ec.fasta", "fasta")
seqString = seq.format("fasta")
seq = seqString[72:]
seqLen = len(seq)

phase = listIni(seqLen)
A = complex(1, 1)
T = complex(1, -1)
C = complex(-1, -1)
G = complex(-1, 1)

RNL = range(0, seqLen)
ntLoc = np.asarray(RNL)


for i in RNL:
    if seq[i] == "A":
        phase[i] = np.angle(A)
    elif seq[i] == "T":
        phase[i] = np.angle(T)
    elif seq[i] == "C":
        phase[i] = np.angle(C)
    else:
        phase[i] = np.angle(G)

arrPh = np.asarray(phase)
unwrapedPh = np.unwrap(arrPh)
cumulatedPh = np.cumsum(arrPh)


plt.plot(ntLoc, unwrapedPh, label='uPhase', color='red')
plt.plot(ntLoc, cumulatedPh, label='cPhase', color='blue')
plt.xlabel("Relative nt location")
plt.ylabel("Angle")
plt.show()

我觉得问题出在np.angle的定义上。

在您的代码中,我们有

angle('A') -> pi/4
angle('T') -> -pi/4
angle('G') -> 3pi/4
angle('C') -> -3pi/4

很明显,负角的累积和会减少。我想您更想要以下映射:

angle('A') -> pi/4
angle('T') -> 7pi/4
angle('G') -> 3pi/4
angle('C') -> 5pi/4

一个快速的'n'dirty walkaround

for i in RNL:
    if seq[i] == "A":
        phase[i] = np.angle(A)
    elif seq[i] == "T":
        phase[i] = np.pi-np.angle(T)
    elif seq[i] == "C":
        phase[i] = np.pi-np.angle(C)
    else:
        phase[i] = np.angle(G)

但这实际上取决于您希望与要指向的碱基相对应的向量的位置。

我刚刚弄明白了。而不是像我在这部分代码中那样使用 'manual sequence loading':

seq = SeqIO.read("C:/ec.fasta", "fasta")
seqString = seq.format("fasta")
seq = seqString[72:]
seqLen = len(seq)

我只是像这样在 Biopython 中使用内置的 'function':

record = SeqIO.read("C:/ec.fasta", "fasta")
sequence = record.seq

一切正常。为什么会这样仍然是个谜。 无论如何感谢另一个想法和回应 alexblae!