Author: bugman Date: Sat Jan 31 13:13:38 2015 New Revision: 27426 URL: http://svn.gna.org/viewcvs/relax?rev=27426&view=rev Log: Shifted the residue skipping data structure construction into the relax library. The code was originally in pipe_control.structure.main.assemble_structural_coordinates() but has been shifted into the new lib.sequence_alignment.msa.msa_residue_skipping() function. This will also for greater code reuse. The lib.sequence_alignment.msa module is also a better location for such functionality. Modified: trunk/lib/sequence_alignment/msa.py trunk/pipe_control/structure/main.py Modified: trunk/lib/sequence_alignment/msa.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/sequence_alignment/msa.py?rev=27426&r1=27425&r2=27426&view=diff ============================================================================== --- trunk/lib/sequence_alignment/msa.py (original) +++ trunk/lib/sequence_alignment/msa.py Sat Jan 31 13:13:38 2015 @@ -228,3 +228,50 @@ # Return the results. return strings, gaps + + +def msa_residue_skipping(sequences=None, strings=None, gaps=None): + """Create the residue skipping data structure. + + @keyword sequences: The list of residue sequences as one letter codes. + @type sequences: list of str + @keyword strings: The list of alignment strings. + @type strings: list of str + @keyword gaps: The gap matrix. + @type gaps: numpy rank-2 int array + @return: The residue skipping data structure. The first dimension is the molecule and the second is the residue. As opposed to zero, a value of one means the residue should skipped. + @rtype: list of lists of int + # + """ + + # initialise. + skip = [] + num_mols = len(sequences) + + # Loop over each molecule. + for mol_index in range(num_mols): + skip.append([]) + for i in range(len(sequences[0])): + # Create the empty residue skipping data structure. + if strings == None: + skip[mol_index].append(0) + continue + + # No residue in the current sequence. + if gaps[mol_index][i]: + continue + + # A gap in one of the other sequences. + gap = False + for mol_index2 in range(num_mols): + if gaps[mol_index2][i]: + gap = True + + # Skip the residue. + if gap: + skip[mol_index].append(1) + else: + skip[mol_index].append(0) + + # Return the data structure. + return skip Modified: trunk/pipe_control/structure/main.py URL: http://svn.gna.org/viewcvs/relax/trunk/pipe_control/structure/main.py?rev=27426&r1=27425&r2=27426&view=diff ============================================================================== --- trunk/pipe_control/structure/main.py (original) +++ trunk/pipe_control/structure/main.py Sat Jan 31 13:13:38 2015 @@ -38,7 +38,7 @@ from lib.plotting.api import correlation_matrix from lib.selection import tokenise from lib.sequence import write_spin_data -from lib.sequence_alignment.msa import central_star, msa_residue_numbers +from lib.sequence_alignment.msa import central_star, msa_residue_numbers, msa_residue_skipping from lib.structure.internal.coordinates import assemble_atomic_coordinates, assemble_coord_array, loop_coord_structures from lib.structure.internal.displacements import Displacements from lib.structure.internal.object import Internal @@ -178,30 +178,7 @@ strings, gaps = msa_residue_numbers(one_letter_codes, residue_numbers=res_num_list) # Create the residue skipping data structure. - skip = [] - for mol_index in range(num_mols): - skip.append([]) - for i in range(len(one_letter_codes[0])): - # Create the empty residue skipping data structure. - if strings == None: - skip[mol_index].append(0) - continue - - # No residue in the current sequence. - if gaps[mol_index][i]: - continue - - # A gap in one of the other sequences. - gap = False - for mol_index2 in range(num_mols): - if gaps[mol_index2][i]: - gap = True - - # Skip the residue. - if gap: - skip[mol_index].append(1) - else: - skip[mol_index].append(0) + skip = msa_residue_skipping(sequences=one_letter_codes, strings=strings, gaps=gaps) # Assemble and return the atomic coordinates and common atom information. coord, mol_name_common, res_name_common, res_num_common, atom_name_common, element_common = assemble_coord_array(atom_pos=atom_pos, mol_names=mol_names, res_names=res_names, res_nums=res_nums, atom_names=atom_names, elements=elements, sequences=one_letter_codes, skip=skip)