original_docstring: Parse the next alignment from the stream.
docstring: Parse the next alignment from the stream.
docstring_tokens: Parse the next alignment from the stream .
code: def parse(self, stream):
          """Parse the next alignment from the stream."""
          if stream is None:
              raise StopIteration
  
          line = self.line
          self.line = None
          if line is not None:
              lines = chain([line], stream)
          else:
              lines = stream
          records = None
          for line in lines:
              if line.startswith("a"):
                  strands = []
                  annotations = {}
                  column_annotations = {}
                  records = []
                  aligned_sequences = []
                  score = None
                  words = line[1:].split()
                  for word in words:
                      key, value = word.split("=")
                      if key == "score":
                          score = float(value)
                      elif key == "pass":
                          value = int(value)
                          if value <= 0:
                              raise ValueError(
                                  "pass value must be positive (found %d)" % value
                              )
                          annotations["pass"] = value
                      else:
                          raise ValueError("Unknown annotation variable '%s'" % key)
              elif line.startswith("s "):
                  words = line.strip().split()
                  if len(words) != 7:
                      raise ValueError(
                          "Error parsing alignment - 's' line must have 7 fields"
                      )
                  src = words[1]
                  start = int(words[2])
                  size = int(words[3])
                  strand = words[4]
                  srcSize = int(words[5])
                  text = words[6]
                  for gap_char in ".=_":
                      text = text.replace(gap_char, "-")
                  aligned_sequences.append(text)
                  sequence = text.replace("-", "")
                  if len(sequence) != size:
                      raise ValueError(
                          "sequence size is incorrect (found %d, expected %d)"
                          % (len(sequence), size)
                      )
                  if strand == "-":
                      sequence = reverse_complement(sequence)
                      start = srcSize - start - size
                  seq = Seq({start: sequence}, length=srcSize)
                  record = SeqRecord(seq, id=src)
                  records.append(record)
                  strands.append(strand)
              elif line.startswith("i "):
                  words = line.strip().split()
                  assert len(words) == 6
                  assert words[1] == src  # from the previous "s" line
                  leftStatus = words[2]
                  leftCount = int(words[3])
                  rightStatus = words[4]
                  rightCount = int(words[5])
                  assert leftStatus in AlignmentIterator.status_characters
                  assert rightStatus in AlignmentIterator.status_characters
                  record.annotations["leftStatus"] = leftStatus
                  record.annotations["leftCount"] = leftCount
                  record.annotations["rightStatus"] = rightStatus
                  record.annotations["rightCount"] = rightCount
              elif line.startswith("e"):
                  words = line[1:].split()
                  assert len(words) == 6
                  src = words[0]
                  start = int(words[1])
                  size = int(words[2])
                  strand = words[3]
                  srcSize = int(words[4])
                  status = words[5]
                  assert status in AlignmentIterator.empty_status_characters
                  sequence = Seq(None, length=srcSize)
                  record = SeqRecord(sequence, id=src)
                  end = start + size
                  if strand == "+":
                      segment = (start, end)
                  else:
                      segment = (srcSize - start, srcSize - end)
                  empty = (record, segment, status)
                  annotation = annotations.get("empty")
                  if annotation is None:
                      annotation = []
                      annotations["empty"] = annotation
                  annotation.append(empty)
              elif line.startswith("q "):
                  words = line.strip().split()
                  assert len(words) == 3
                  assert words[1] == src  # from the previous "s" line
                  value = words[2].replace("-", "")
                  record.annotations["quality"] = value
              elif not line.strip():
                  # reached the end of this alignment
                  yield AlignmentIterator.create_alignment(
                      records,
                      aligned_sequences,
                      strands,
                      annotations,
                      column_annotations,
                      score,
                  )
                  records = None
              else:
                  raise ValueError(f"Error parsing alignment - unexpected line:\n{line}")
          if records is None:
              return
          yield AlignmentIterator.create_alignment(
              records,
              aligned_sequences,
              strands,
              annotations,
              column_annotations,
              score,
          )
code_tokens: def parse ( self , stream ) : if stream is None : raise StopIteration line = self . line self . line = None if line is not None : lines = chain ( [ line ] , stream ) else : lines = stream records = None for line in lines : if line . startswith ( "a" ) : strands = [ ] annotations = { } column_annotations = { } records = [ ] aligned_sequences = [ ] score = None words = line [ 1 : ] . split ( ) for word in words : key , value = word . split ( "=" ) if key == "score" : score = float ( value ) elif key == "pass" : value = int ( value ) if value <= 0 : raise ValueError ( "pass value must be positive (found %d)" % value ) annotations [ "pass" ] = value else : raise ValueError ( "Unknown annotation variable '%s'" % key ) elif line . startswith ( "s " ) : words = line . strip ( ) . split ( ) if len ( words ) != 7 : raise ValueError ( "Error parsing alignment - 's' line must have 7 fields" ) src = words [ 1 ] start = int ( words [ 2 ] ) size = int ( words [ 3 ] ) strand = words [ 4 ] srcSize = int ( words [ 5 ] ) text = words [ 6 ] for gap_char in ".=_" : text = text . replace ( gap_char , "-" ) aligned_sequences . append ( text ) sequence = text . replace ( "-" , "" ) if len ( sequence ) != size : raise ValueError ( "sequence size is incorrect (found %d, expected %d)" % ( len ( sequence ) , size ) ) if strand == "-" : sequence = reverse_complement ( sequence ) start = srcSize - start - size seq = Seq ( { start : sequence } , length = srcSize ) record = SeqRecord ( seq , id = src ) records . append ( record ) strands . append ( strand ) elif line . startswith ( "i " ) : words = line . strip ( ) . split ( ) assert len ( words ) == 6 assert words [ 1 ] == src leftStatus = words [ 2 ] leftCount = int ( words [ 3 ] ) rightStatus = words [ 4 ] rightCount = int ( words [ 5 ] ) assert leftStatus in AlignmentIterator . status_characters assert rightStatus in AlignmentIterator . status_characters record . annotations [ "leftStatus" ] = leftStatus record . annotations [ "leftCount" ] = leftCount record . annotations [ "rightStatus" ] = rightStatus record . annotations [ "rightCount" ] = rightCount elif line . startswith ( "e" ) : words = line [ 1 : ] . split ( ) assert len ( words ) == 6 src = words [ 0 ] start = int ( words [ 1 ] ) size = int ( words [ 2 ] ) strand = words [ 3 ] srcSize = int ( words [ 4 ] ) status = words [ 5 ] assert status in AlignmentIterator . empty_status_characters sequence = Seq ( None , length = srcSize ) record = SeqRecord ( sequence , id = src ) end = start + size if strand == "+" : segment = ( start , end ) else : segment = ( srcSize - start , srcSize - end ) empty = ( record , segment , status ) annotation = annotations . get ( "empty" ) if annotation is None : annotation = [ ] annotations [ "empty" ] = annotation annotation . append ( empty ) elif line . startswith ( "q " ) : words = line . strip ( ) . split ( ) assert len ( words ) == 3 assert words [ 1 ] == src value = words [ 2 ] . replace ( "-" , "" ) record . annotations [ "quality" ] = value elif not line . strip ( ) : yield AlignmentIterator . create_alignment ( records , aligned_sequences , strands , annotations , column_annotations , score , ) records = None else : raise ValueError ( f"Error parsing alignment - unexpected line:\n{line}" ) if records is None : return yield AlignmentIterator . create_alignment ( records , aligned_sequences , strands , annotations , column_annotations , score , )
short_docstring: Parse the next alignment from the stream.
short_docstring_tokens: Parse the next alignment from the stream .
comment: """Parse the next alignment from the stream."""$SEP$# from the previous "s" line$SEP$# from the previous "s" line$SEP$# reached the end of this alignment