源代码:

import numpy as np

import pandas as pd

from pandas import DataFrame

T=5

#return_minimun_value

def minimun(one ,two ,three):

min=((one if one

return min

#calculate_similarity

def similarity(str_1,str_2):

d=np.zeros((len(str_1)+1,len(str_2)+1))

for i in range(len(str_1)+1):

d[i][0]=i

for j in range(len(str_2)+1):

d[0][j]=j

for i in range(1,len(str_1)+1):

for j in range(1,len(str_2)+1):

score=1

if str_1[i-1]==str_2[j-1]:

score=0

d[i][j]=minimun(d[i-1][j]+1,d[i][j-1]+1,d[i-1][j-1]+score) if minimun(d[i-1][j]+1,d[i][j-1]+1,d[i-1][j-1]+score)

return d[len(str_1)][len(str_2)]

#indentify_how_similar

def identify(s1,s2):

s1=s1.strip()

s2=s2.strip()

s1=s1.split(' ')

s2=s2.split(' ')

t=len(s1) if len(s1)

score=0

for i in range(t):

if s1[i]!=s2[i]:

score=100

break

score=score+similarity(s1[i],s2[i])

return score

path1='C:\\Users\\jyjh\\Desktop\\chromosome_data.csv'

path2='C:\\Users\\jyjh\\Desktop\\xishaislands.csv'

cd=pd.read_csv(path1,index_col=0)

xs=pd.read_csv(path2)

cd=DataFrame(cd)

xs=DataFrame(xs)

cdlt=[]

xslt=[]

for i in cd['Latin_name']:

cdlt.append(i)

for i in xs['latin_name']:

xslt.append(i)

dic={}

for j in range(len(xs.index)):

locc=0

loc=0

sms=[]

for i in cdlt:

sms.append(identify(i,xs['latin_name'].ix[j]))

min=sms[0]

for i in sms:

if i

min=i

locc=loc

loc=loc+1

dic.setdefault(xs['latin_name'].ix[j],locc)

col=['Gametophytic','Sporophytic','Paresd_n']

data=DataFrame(index=dic.keys(),columns=col)

all=[]

for i in dic.values():

if i!=0:

all.append(cd['Gametophytic'].ix[i])

else:

all.append(' ')

for i in arange(len(dic.keys())):

data['Gametophytic'].ix[i]=all[i]

all=[]

for i in dic.values():

if i!=0:

all.append(cd['Sporophytic'].ix[i])

else:

all.append(' ')

for i in arange(len(dic.keys())):

data['Sporophytic'].ix[i]=all[i]

all=[]

for i in dic.values():

if i!=0:

all.append(cd['Paresd_n'].ix[i])

else:

all.append(' ')

for i in arange(len(dic.keys())):

data['Paresd_n'].ix[i]=all[i]

data.to_csv('data.csv')

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐