def make_msa_kalign(family, mate): logging.info('Aligning with kalign.') try: # Import in the child process in case there's any issue in the .so with shared state between # processes (maybe not possible, but just in case). from kalign import kalign except ImportError: logging.critical('Error importing kalign module. Check that the submodule is installed properly.') raise seqs = [pair['seq'+mate] for pair in family] aligned_seqs = kalign.align(seqs) return aligned_seqs
def make_msa_kalign(family, mate): logging.info('Aligning with kalign.') try: # Import in the child process in case there's any issue in the .so with shared state between # processes (maybe not possible, but just in case). from kalign import kalign except ImportError: logging.critical('Error importing kalign module. Check that the submodule is installed properly.') raise seqs = [pair['seq'+mate] for pair in family] aln_struct = kalign.align(seqs) return [aln_struct.seqs[i] for i in range(aln_struct.nseqs)]
def realign_family_to_consensus(consensus, family, quals, validate=False): unaligned_seqs = [consensus] unaligned_seqs.extend([seq.replace('-', '') for seq in family]) aligned_seqs = kalign.align(unaligned_seqs) if validate: for input, output in zip(unaligned_seqs, aligned_seqs): assert input == output.replace('-', ''), ( "Kalign may have returned sequences in a different order than they were given. Failed on " "sequence: {}".format(input) ) aligned_consensus = aligned_seqs[0] aligned_family = aligned_seqs[1:] aligned_quals = seqtools.transfer_gaps_multi(quals, aligned_family, gap_char_out=' ') return aligned_consensus, aligned_family, aligned_quals