Created
February 19, 2024 05:47
-
-
Save partrita/4da267fd2d0aaf87bd9ecb499ad529a4 to your computer and use it in GitHub Desktop.
이 코드는 주어진 WT 단백질 서열을 기반으로 뮤턴트 서열을 생성하고, 이를 FASTA 형식으로 변환하여 출력하는 작업을 수행합니다. 주요 단계는 다음과 같습니다: 주어진 WT 서열과 뮤턴트 리스트를 사용하여 각 단백질에 대한 뮤턴트 서열을 생성합니다. 생성된 뮤턴트 서열을 딕셔너리에 저장합니다. 딕셔너리에 저장된 뮤턴트 서열을 FASTA 형식으로 변환하여 출력합니다. 코드는 주로 뮤턴트 서열 생성 및 딕셔너리 조작, 그리고 FASTA 형식으로 변환하는 함수를 정의하고 호출하는 부분으로 구성되어 있습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| seq_Fc_wt = "ASTKGPSVFPLAPSSKSTSGGTAALGCLVKDYFPEPVTVSWNSGALTSGVHTFPAVLQSSGLYSLSSVVTVPSSSLGTQTYICNVNHKPSNTKVDKKVEPKSCDKTHTCPPCPAPELLGGPSVFLFPPKPKDTLMISRTPEVTCVVVDVSHEDPEVKFNWYVDGVEVHNAKTKPREEQYNSTYRVVSVLTVLHQDWLNGKEYKCKVSNKALPAPIEKTISKAKGQPREPQVYTLPPSREEMTKNQVSLTCLVKGFYPSDIAVEWESNGQPENNYKTTPPVLDSDGSFFLYSKLTVDKSRWQQGNVFSCSVMHEALHNHYTQKSLSLSPGK" | |
| start_num = 118 | |
| # 주어진 뮤턴트 리스트 | |
| mutant_list = { | |
| "DLE": ["S239D", "A330L", "I332E"], | |
| "AEFT": ["G236A", "I332E", "H268F", "S324T"], | |
| "GAALIE": ["G236A", "A330L", "I332E"], | |
| "GAALIELS": ["G236A", "A330L", "I332E", "M428L", "N434S"], | |
| "SDIEALGA": ["G236A", "S239D", "A330L", "I332E"], | |
| "SDIEALGALS": ["G236A", "S239D", "A330L", "I332E", "M428L", "N434S"], | |
| "VLPLL": ["L235V", "F243L", "R292P", "Y300L", "P396L"], | |
| "LPLL": ["F243L", "R292P", "Y300L", "P396L"], | |
| "SDIEGA": ["G236A", "S239D", "I332E"], | |
| "LET": ["F243L", "D270E", "K392T"], | |
| "LPL": ["F243L", "R292P", "Y300L"], | |
| "LLEK": ["F243L", "P247L", "D270E", "N421K"], | |
| "LPIL": ["F243L", "R292P", "V305I", "P396L"], | |
| "FALE": ["G237F", "S298A", "A330L", "I332E"], | |
| "EIYE": ["S239E", "V264I", "A330Y", "I332E"], | |
| "SDIESA": ["S239D", "S298A", "I332E"], | |
| "LALA": ["L234A", "L235A"], | |
| "G236A": ["G236A"], | |
| "Y300L": ["Y300L"], | |
| "D270E": ["D270E"], | |
| "KWES": ["K326W", "E333S"], | |
| "FT": ["H268F", "S324T"], | |
| "ID": ["L234I", "L235D"], | |
| "I332E": ["I332E"], | |
| "F243L": ["F243L"], | |
| "E258H": ["E258H"], | |
| "T223K": ["T223K"], | |
| "K246H": ["K246H"], | |
| "L328A": ["L328A"], | |
| "IQ": ["P247I", "A339Q"], | |
| "DE": ["S239D", "I332E"], | |
| } | |
| def generate_mutant(wt_sequence, mutation, start_num): | |
| """ | |
| 주어진 WT 서열에서 뮤턴트 서열을 생성하는 함수 | |
| :param wt_sequence: 원래 단백질 서열 (WT 서열) | |
| :param mutation: 뮤턴트 정보 (예: S239D) | |
| :return: 뮤턴트 서열 | |
| """ | |
| # 뮤턴트 정보에서 위치와 변경할 아미노산 추출 | |
| wild_type_aa = mutation[0] # WT 아미노산 | |
| position = int(mutation[1:-1]) # 위치 | |
| mutant_aa = mutation[-1] # 뮤턴트 아미노산 | |
| # 유효한 위치 범위 검증 | |
| if not (start_num <= position <= len(wt_sequence) + start_num - 1): | |
| raise ValueError("잘못된 위치입니다.") | |
| # 뮤턴트 서열 생성 | |
| mutant_sequence = list(wt_sequence) | |
| # 뮤턴트 아미노산 변경 | |
| index = position - start_num | |
| if mutant_sequence[index] != wild_type_aa: | |
| raise ValueError( | |
| "뮤턴트 위치의 아미노산이 원래의 아미노산과 일치하지 않습니다." | |
| ) | |
| mutant_sequence[index] = mutant_aa | |
| print(f"{mutation} 변경됨!") | |
| return "".join(mutant_sequence) | |
| # 새로운 뮤턴트 서열을 저장할 딕셔너리 | |
| mutant_sequences = {} | |
| def dict_to_fasta(dictionary): | |
| """ | |
| 딕셔너리를 FASTA 형식의 문자열로 변환하는 함수 | |
| :param dictionary: 서열이 저장된 딕셔너리 | |
| :return: FASTA 형식의 문자열 | |
| """ | |
| fasta_string = "" | |
| for header, sequence in dictionary.items(): | |
| my_string = "".join(sequence) | |
| fasta_string += f">{header}\n{my_string}\n" | |
| return fasta_string | |
| if __name__ == "__main__": | |
| # 각 단백질 서열에 대한 뮤턴트 생성 | |
| for protein, mutations in mutant_list.items(): | |
| # WT 서열 설정 | |
| seq = seq_Fc_wt | |
| # 해당 단백질의 뮤턴트 서열 생성 | |
| mutant_sequences[protein] = [] | |
| for mutation in mutations: | |
| seq = generate_mutant(seq, mutation, start_num) | |
| mutant_sequences[protein].append(seq) | |
| # FASTA 형식으로 변환된 뮤턴트 서열 출력 | |
| fasta_mutant_sequences = dict_to_fasta(mutant_sequences) | |
| print(fasta_mutant_sequences) | |
| # 새로운 데이터프레임 생성 | |
| # df = pd.DataFrame({str(i + start_num): list(seq_Fc_wt[i]) for i in range(len(seq_Fc_wt))}) | |
| # 인덱스를 start_num부터 시작하도록 설정 | |
| # df.index = range(start_num, len(df) + x) | |
| # df.to_csv("../output/240202_Fc_variant.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment