my ($R_chr, $A_chr, $match, $nomatch, $A_seg, $last_A_seg, $R_seg, $last_R_seg, $match_flag, $i, $j) = @_;
# last clone was a match
if ($match_flag) {
# adjust align block end
if ($match->{$R_chr}) {
my $c = scalar(@{ $match->{$R_chr} }) - 1;
# if the gaps between this clone and the last are different, start
# a new block
if (($A_seg->from_start - $match->{$R_chr}->[$c]->[1]) !=
($R_seg->from_start - $match->{$R_chr}->[$c]->[4])) {
$support->log("Gap size mismatch at A:$A_chr:".$match->{$R_chr}->[$c]->[1].'-'.$A_seg->from_start.", R:$R_chr:".$match->{$R_chr}->[$c]->[4].'-'.$R_seg->from_start."\n", 2);
# finish the last align block
$match->{$R_chr}->[$c]->[1] = $last_A_seg->from_end;
$match->{$R_chr}->[$c]->[2] = $j - $match->{$R_chr}->[$c]->[2];
$match->{$R_chr}->[$c]->[4] = $last_R_seg->from_end;
$match->{$R_chr}->[$c]->[5] = $i - $match->{$R_chr}->[$c]->[5];
# start a new align block
push @{ $match->{$R_chr} }, [
$A_seg->from_start,
$A_seg->from_end,
$j,
$R_seg->from_start,
$R_seg->from_end,
$i,
$A_chr,
];
# adjust align block end
} else {
$match->{$R_chr}->[$c]->[1] = $A_seg->from_end;
$match->{$R_chr}->[$c]->[4] = $R_seg->from_end;
}
}
# last clone was a non-match
} else {
# start a new align block
push @{ $match->{$R_chr} }, [
$A_seg->from_start,
$A_seg->from_end,
$j,
$R_seg->from_start,
$R_seg->from_end,
$i,
$A_chr,
];
# finish the last non-align block
if ($nomatch->{$R_chr} and $last_A_seg) {
my $c = scalar(@{ $nomatch->{$R_chr} }) - 1;
$nomatch->{$R_chr}->[$c]->[1] = $last_A_seg->from_end;
$nomatch->{$R_chr}->[$c]->[2] = $j - $nomatch->{$R_chr}->[$c]->[2];
$nomatch->{$R_chr}->[$c]->[4] = $last_R_seg->from_end;
$nomatch->{$R_chr}->[$c]->[5] = $i - $nomatch->{$R_chr}->[$c]->[5];
}
}
}