728x90
반응형
def running_mixMHCpred(x,path,mixmhcpred):
'''
# parameters
x : dataframe ['peptide','mhc','other columns'] # input dataframe
path : /path/to/workdir # 작업경로
mixmhcpred : /path/to/mixmhcpred/MixMHCpred # 실행 파일경로
# return
dataframe with mixmhcpred result
# saved file
/path/to/workdir/mixMHCpred_peptide_input.txt
/path/to/mixMHCpred-result.txt
'''
import subprocess as sbp
import pandas as pd
# Exporting the peptide file
peptides='\n'.join(x['peptide'].unique())
with open(path+'/mixMHCpred_peptide_input.txt','w') as f:
f.write(peptides)
# Get MHCs
mhcs=x['mhc'].unique()
mhcs=[i.split('-')[1].replace('*','').replace(':','') for i in mhcs]
mhcs=','.join(mhcs)
# Make command line and run it.
cmd=f'{mixmhcpred} -i {path}/mixMHCpred_peptide_input.txt -o {path}/mixMHCpred-result.txt -a {mhcs}'
sbp.call(cmd,shell=True)
# Loading the result
mm=pd.read_csv(f'{path}/mixMHCpred-result.txt',sep='\t',comment='#')
# Attach the prediction result to original data
mm=mm.drop(['Score_bestAllele','BestAllele','%Rank_bestAllele'],axis=1)
x1=x.copy()
x1['mixMHCkey']=x1['mhc'].apply(lambda x: x.split('-')[1].replace('*','').replace(':',''))
mm1=mm.melt('Peptide')
mm1[['category','mixMHCkey']]=mm1['variable'].str.split('_').tolist()
mm2=mm1.pivot(index=['Peptide','mixMHCkey'],columns='category').reset_index().loc[:,['Peptide','mixMHCkey','value']]
mm2.columns=['peptide','mixMHCkey','%Rank','Score']
x2=pd.merge(x1,mm2,on=['peptide','mixMHCkey']).drop('mixMHCkey',axis=1)
gc.collect()
return x2
728x90
반응형
'Bioinformatics(생정보학)' 카테고리의 다른 글
mhcnuggets 도커파일 (0) | 2024.03.18 |
---|---|
mhcflurry 설치, 실행 및 결과 불러오기 (1) | 2024.03.15 |
SOPRANO immunoediting dN/dS docker (0) | 2024.01.09 |
원하는 위치를 포함하는 K-mer 펩타이드 서열 생성하기 (1) | 2023.11.20 |
[python] di-peptide encoding (0) | 2023.10.10 |