def test_expr_errors(self, obj): with pytest.raises(TypeError): exprl2alignment(obj) with pytest.raises(TypeError): PairwiseAlignment(obj, Dw, Gw) with pytest.raises(TypeError): Alignment(obj)
def test_Alignment(filtered_peak_list): #Alignment(Experiment("ELEY_1_SUBTRACT", filtered_peak_list)) #Alignment(None) for obj in [test_string, *test_numbers, *test_lists, test_dict]: with pytest.raises(TypeError): Alignment(obj)
def merge_alignments(A1: Alignment, A2: Alignment, traces) -> Alignment: """ Merges two alignments with gaps added in from DP traceback. :param A1: First alignment. :param A2: Second alignment. :param traces: DP traceback. :return: A single alignment from ``A1`` and ``A2``. :authors: Woon Wai Keen, Vladimir Likic, Qiao Wang """ # Create object to hold new merged alignment and fill in its expr_codes ma = Alignment(None) ma.expr_code = A1.expr_code + A2.expr_code # create empty lists of dimension |A1| + |A2| dimension = len(A1.peakpos) + len(A2.peakpos) merged: List[List[Peak]] = [[] for _ in range(dimension)] idx1 = idx2 = 0 # trace can either be 0, 1, or 2 # if it is 0, there are no gaps. otherwise, if it is 1 or 2, # there is a gap in A2 or A1 respectively. for trace in traces: if trace in {0, 1}: for i, _ in enumerate(A1.peakpos): merged[i].append(A1.peakpos[i][idx1]) idx1 = idx1 + 1 elif trace == 2: for i, _ in enumerate(A1.peakpos): merged[i].append(None) # type: ignore # --- if trace in {0, 2}: for j, peak in enumerate(A2.peakpos): merged[1 + i + j].append(peak[idx2]) idx2 = idx2 + 1 elif trace == 1: for j, _ in enumerate(A2.peakpos): merged[1 + i + j].append(None) # type: ignore ma.peakalgt = numpy.transpose(merged) # sort according to average peak ma.peakalgt = list(ma.peakalgt) ma.peakalgt.sort(key=functools.cmp_to_key(alignment_compare)) ma.peakpos = numpy.transpose(ma.peakalgt) return ma