|
12 | 12 | import os |
13 | 13 |
|
14 | 14 | from modeller import * |
| 15 | +def msa_with_modeller(alignment_file, combined_fasta): |
| 16 | + """ |
| 17 | + Perform Multiple Sequence Alignment (MSA) using Modeller. |
| 18 | +
|
| 19 | + Note |
| 20 | + ---- |
| 21 | + If the proteins are not closely related, it may be better to use a more sophisticated alignment method. |
15 | 22 |
|
| 23 | + Parameters |
| 24 | + ---------- |
| 25 | + alignment_file : str |
| 26 | + Name of the file to write the alignment results to. |
| 27 | + combined_fasta : str |
| 28 | + Path to a FASTA file containing sequences of all proteins. |
| 29 | +
|
| 30 | + Returns |
| 31 | + ------- |
| 32 | + None |
| 33 | + """ |
| 34 | + |
| 35 | + log.verbose() |
| 36 | + |
| 37 | + #Initialize environment |
| 38 | + env = environ() |
| 39 | + env.io.atom_files_directory='./' |
| 40 | + |
| 41 | + #Perform alignment, using default modeller parameters |
| 42 | + aln = alignment(env, file=combined_fasta, alignment_format='FASTA') |
| 43 | + aln.salign(rr_file='$(LIB)/as1.sim.mat', # Substitution matrix used |
| 44 | + output='', |
| 45 | + max_gap_length=20, |
| 46 | + gap_function=False, # If False then align2d not done |
| 47 | + feature_weights=(1., 0., 0., 0., 0., 0.), |
| 48 | + gap_penalties_1d=(-100, 0), |
| 49 | + output_weights_file='saligni1d.mtx', |
| 50 | + similarity_flag=True) # Ensuring that the dynamic programming |
| 51 | + # matrix is not scaled to a |
| 52 | + # difference matrix |
| 53 | + |
| 54 | + #Write final alignment |
| 55 | + aln.write(file=alignment_file, alignment_format='PIR') |
| 56 | + |
16 | 57 | def perform_structure_alignment(pdb_dir, same_chain='A',out_dir='aligned_pdbs', sort_pdbs=True): |
17 | 58 | """ |
18 | 59 | Perform a built-in structural alignment. |
@@ -67,7 +108,20 @@ def perform_structure_alignment(pdb_dir, same_chain='A',out_dir='aligned_pdbs', |
67 | 108 | chain = same_chain[i] |
68 | 109 | pdb_file = os.path.join(pdb_dir, ref_pdb) |
69 | 110 |
|
70 | | - m = Model(env, file=pdb_file, model_segment=('FIRST:'+chain, 'LAST:'+chain)) |
| 111 | + if isinstance(chain, str): |
| 112 | + try: |
| 113 | + m = Model(env, file=pdb_file, model_segment=('FIRST:'+chain, 'LAST:'+chain)) |
| 114 | + except: |
| 115 | + #If chain of interest is not found, use chain 'X' |
| 116 | + m = Model(env, file=pdb_file, model_segment=('FIRST:'+'X', 'LAST:'+'X')) |
| 117 | + else: |
| 118 | + #If tuple, assume user wants Chain [0] - Chain [1]x |
| 119 | + try: |
| 120 | + m = Model(env, file=pdb_file, model_segment=('FIRST:'+chain[0], 'LAST:'+chain[1])) |
| 121 | + except: |
| 122 | + #If chain of interest is not found, use chain 'X' |
| 123 | + m = Model(env, file=pdb_file, model_segment=('FIRST:'+'X', 'LAST:'+'X')) |
| 124 | + |
71 | 125 | aln.append_model(m, atom_files=os.path.join(pdb_dir, ref_pdb), align_codes=ref_pdb) |
72 | 126 |
|
73 | 127 | aln.malign() |
@@ -151,6 +205,7 @@ def apply_transformation(coordinates, rotation_matrix, translation_vector): |
151 | 205 | transformed_coords = np.dot(coordinates, rotation_matrix.T) + translation_vector |
152 | 206 | return transformed_coords |
153 | 207 |
|
| 208 | + os.makedirs(out_dir, exist_ok=True) |
154 | 209 | parser = PDBParser() |
155 | 210 | pdbs = os.listdir(pdb_dir) |
156 | 211 | pdbs.sort() |
@@ -438,7 +493,8 @@ def pick_pair(u, options, num_options=1, dist_cutoff=20): |
438 | 493 | """ |
439 | 494 | pairs = [] |
440 | 495 | cur_option = 0 |
441 | | - while cur_option < no_options: |
| 496 | + dist = lambda x1, y1, z1, x2, y2, z2: np.sqrt((x1-x2)**2 + (y1-y2)**2 + (z1-z2)**2) |
| 497 | + while cur_option < num_options: |
442 | 498 | for option1 in options: |
443 | 499 | coords1 = u.select_atoms(f"resid {option1} and name CA").positions |
444 | 500 | for option2 in options[::-1]: |
|
0 commit comments