def sequence_to_alignment_coords(self, seq_name, start, end, trim=False):
<EOL>if end <= start:<EOL><INDENT>raise InvalidSequenceCoordinatesError("<STR_LIT>" + str(start) +<EOL>"<STR_LIT:U+002CU+0020>" + str(end))<EOL><DEDENT>seq = self[seq_name]<EOL>s_start = seq.start<EOL>s_end = seq.end<EOL>pos_strand = seq.is_positive_strand()<EOL>if start > s_end or end < s_start:<EOL><INDENT>msg = "<STR_LIT>" + str(start) + "<STR_LIT:U+002CU+0020>" + str(end) + "<STR_LIT>" +"<STR_LIT>" +str(s_start) + "<STR_LIT:U+002CU+0020>" + str(s_end)<EOL>raise InvalidSequenceCoordinatesError(msg)<EOL><DEDENT>if trim:<EOL><INDENT>start = s_start if start < s_start else start<EOL>end = s_end if end > s_end else end<EOL><DEDENT>elif start < s_start or end > s_end:<EOL><INDENT>msg = "<STR_LIT>" + str(start) + "<STR_LIT:U+002CU+0020>" + str(end) + "<STR_LIT>" +"<STR_LIT>" +str(s_start) + "<STR_LIT:U+002CU+0020>" + str(s_end)<EOL>raise InvalidSequenceCoordinatesError(msg)<EOL><DEDENT>num_gaps = <NUM_LIT:0><EOL>num_non_gaps = <NUM_LIT:0><EOL>res = []<EOL>current_start = None<EOL>current_end = None<EOL>l_start = <NUM_LIT:0> if pos_strand else self.size() - <NUM_LIT:1><EOL>l_end = self.size() if pos_strand else <NUM_LIT:0><EOL>l_step = <NUM_LIT:1> if pos_strand else -<NUM_LIT:1><EOL>for i in range(l_start, l_end, l_step):<EOL><INDENT>if seq[i] == GAP_CHAR:<EOL><INDENT>num_gaps += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>num_non_gaps += <NUM_LIT:1><EOL><DEDENT>if num_non_gaps > end - s_start:    <EOL><INDENT>break<EOL><DEDENT>if num_non_gaps > start - s_start:  <EOL><INDENT>if seq[i] != GAP_CHAR:<EOL><INDENT>if current_start is None and current_end is None:<EOL><INDENT>current_start = i<EOL>current_end = i + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>if ((pos_strand and seq[i - <NUM_LIT:1>] == GAP_CHAR) or<EOL>(not pos_strand and seq[i + <NUM_LIT:1>] == GAP_CHAR)):<EOL><INDENT>res.append((current_start + <NUM_LIT:1>, current_end + <NUM_LIT:1>))<EOL>current_start = i<EOL>current_end = i + <NUM_LIT:1><EOL><DEDENT>if pos_strand and seq[i - <NUM_LIT:1>] != GAP_CHAR:<EOL><INDENT>current_end += <NUM_LIT:1><EOL><DEDENT>if not pos_strand and seq[i + <NUM_LIT:1>] != GAP_CHAR:<EOL><INDENT>current_start -= <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>res.append((current_start + <NUM_LIT:1>, current_end + <NUM_LIT:1>))<EOL>return res<EOL>
convert an interval in one of the sequences into an interval in the
alignment. Alignment intervals are inclusive of start, but not end. They
are one-based. Hence the full alignment has coords [1, N+1), where N is the
length of the alignment (number of columns). Sequence coords follow the
same conventions: one-based, inclusive of start but not end.

:param seq_name: which sequence are the start and end coords for?
:param start:    start of the interval in sequence co-ordinates
:param end:      end of the interval in sequence co-ordinates
:param trim:     if true, trim coordinates that fall partially outside
                 the sequence
:raises AlignmentError: if coordinates fall entirely outside the
                        sequence, or partially outside and trim == false