"""
Function of this code: one method of transforming DNA sequences to numerical values.
Contact for help: gch_liu@163.com 
"""

import numpy as np
def dna2numDVcurve(seq):
#    seq='0'+seq
    N=len(seq);
    x=np.zeros((N,));
    y=np.zeros((N,));
    indx=1;
    x[2*indx-2]=2*indx-1;
    x[2*indx-1]=2*indx;
    if seq[2*indx-2]=='A' or seq[2*indx-2]=='T':
        y[2*indx-2]=0+1;
    elif seq[2*indx-2]=='C' or seq[2*indx-2]=='G':  
        y[2*indx-2]=0-1;

    if seq[2*indx-1]=='A' or seq[2*indx-1]=='C':  
        y[2*indx-1]=y[2*indx-2]+1;
    elif seq[2*indx-1]=='T' or seq[2*indx-1]=='G':  
        y[2*indx-1]=y[2*indx-2]-1; 
     
    indx=2;
    while 2*indx<=N:
        x[2*indx-2]=2*indx-1;
        x[2*indx-1]=2*indx;
        if seq[2*indx-2]=='A'or seq[2*indx-2]=='T':  
            y[2*indx-2]=y[2*indx-3]+1;
        elif seq[2*indx-2]=='C'or seq[2*indx-2]=='G':  
            y[2*indx-2]=y[2*indx-3]-1;
            
        if seq[2*indx-1]=='A'or seq[2*indx-1]=='C':  
            y[2*indx-1]=y[2*indx-2]+1;
        elif seq[2*indx-1]=='T'or seq[2*indx-1]=='G': 
            y[2*indx-1]=y[2*indx-2]-1;
            
        indx=indx+1;
    
    return [x.tolist(),y.tolist()];
if __name__=='__main__':
    print(dna2numDVcurve("ACGTACGTACGTAGCTACGTCACTCTCATTACTCTACACGACGCATAC"))
