nodes: 0, module; 1, function_definition; 2, function_name:filter; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, expression_statement; 14, comment:# Use a ReadSetFilter only if we're checking that read sets are; 15, comment:# sufficiently new.; 16, if_statement; 17, expression_statement; 18, if_statement; 19, for_statement; 20, return_statement; 21, identifier:minMatchingReads; 22, None; 23, identifier:minMedianScore; 24, None; 25, identifier:withScoreBetterThan; 26, None; 27, identifier:minNewReads; 28, None; 29, identifier:minCoverage; 30, None; 31, identifier:maxTitles; 32, None; 33, identifier:sortOn; 34, string; 35, comment:"""
          Filter the titles in self to create another TitlesAlignments.
  
          @param minMatchingReads: titles that are matched by fewer reads
              are unacceptable.
          @param minMedianScore: sequences that are matched with a median
              bit score that is less are unacceptable.
          @param withScoreBetterThan: if the best score for a title is not
              as good as this value, the title is not acceptable.
          @param minNewReads: The C{float} fraction of its reads by which a new
              title's read set must differ from the read sets of all previously
              seen titles in order for this title to be considered acceptably
              different (and therefore interesting).
          @param minCoverage: The C{float} minimum fraction of the title sequence
              that must be matched by at least one read.
          @param maxTitles: A non-negative C{int} maximum number of titles to
              keep. If more titles than this are present, titles will be sorted
              (according to C{sortOn}) and only the best will be retained.
          @param sortOn: A C{str} attribute to sort on, used only if C{maxTitles}
              is not C{None}. See the C{sortTitles} method below for the legal
              values.
          @raise: C{ValueError} if C{maxTitles} is less than zero or the value of
              C{sortOn} is unknown.
          @return: A new L{TitlesAlignments} instance containing only the
              matching titles.
          """; 36, comparison_operator:minNewReads is None; 37, block; 38, else_clause; 39, assignment; 40, boolean_operator; 41, block; 42, else_clause; 43, identifier:title; 44, identifier:titles; 45, comment:# Test max titles up front, as it may be zero.; 46, block; 47, identifier:result; 48, string_content:maxScore; 49, identifier:minNewReads; 50, None; 51, expression_statement; 52, block; 53, identifier:result; 54, call; 55, comparison_operator:maxTitles is not None; 56, comparison_operator:len(self) > maxTitles; 57, if_statement; 58, block; 59, if_statement; 60, expression_statement; 61, if_statement; 62, comment:# To compare the median score with another score, we must; 63, comment:# convert both values to instances of the score class used in; 64, comment:# this data set so they can be compared without us needing to; 65, comment:# know if numerically greater scores are considered better or; 66, comment:# not.; 67, if_statement; 68, if_statement; 69, if_statement; 70, if_statement; 71, expression_statement; 72, assignment; 73, if_statement; 74, expression_statement; 75, identifier:TitlesAlignments; 76, argument_list; 77, identifier:maxTitles; 78, None; 79, call; 80, identifier:maxTitles; 81, comparison_operator:maxTitles < 0; 82, block; 83, else_clause; 84, expression_statement; 85, boolean_operator; 86, block; 87, assignment; 88, parenthesized_expression; 89, block; 90, parenthesized_expression; 91, block; 92, parenthesized_expression; 93, block; 94, parenthesized_expression; 95, block; 96, parenthesized_expression; 97, block; 98, call; 99, identifier:readSetFilter; 100, None; 101, comparison_operator:self.readSetFilter is None; 102, block; 103, assignment; 104, attribute; 105, attribute; 106, attribute; 107, keyword_argument; 108, identifier:len; 109, argument_list; 110, identifier:maxTitles; 111, integer:0; 112, raise_statement; 113, comment:# There are too many titles. Make a sorted list of them so; 114, comment:# we loop through them (below) in the desired order and can; 115, comment:# break when/if we've reached the maximum. We can't just; 116, comment:# take the first maxTitles titles from the sorted list now,; 117, comment:# as some of those titles might later be discarded by the; 118, comment:# filter and then we'd return a result with fewer titles; 119, comment:# than we should.; 120, block; 121, assignment; 122, comparison_operator:maxTitles is not None; 123, comparison_operator:len(result) == maxTitles; 124, break_statement; 125, identifier:titleAlignments; 126, subscript; 127, boolean_operator; 128, continue_statement; 129, boolean_operator; 130, continue_statement; 131, boolean_operator; 132, continue_statement; 133, boolean_operator; 134, continue_statement; 135, boolean_operator; 136, continue_statement; 137, attribute; 138, argument_list; 139, attribute; 140, None; 141, expression_statement; 142, identifier:readSetFilter; 143, attribute; 144, identifier:self; 145, identifier:readsAlignments; 146, identifier:self; 147, identifier:scoreClass; 148, identifier:self; 149, identifier:readSetFilter; 150, identifier:importReadsAlignmentsTitles; 151, False; 152, identifier:self; 153, call; 154, expression_statement; 155, identifier:titles; 156, call; 157, identifier:maxTitles; 158, None; 159, call; 160, identifier:maxTitles; 161, identifier:self; 162, identifier:title; 163, comparison_operator:minMatchingReads is not None; 164, comparison_operator:titleAlignments.readCount() < minMatchingReads; 165, comparison_operator:minMedianScore is not None; 166, comparison_operator:self.scoreClass(titleAlignments.medianScore()) <
                      self.scoreClass(minMedianScore); 167, comparison_operator:withScoreBetterThan is not None; 168, not_operator; 169, comparison_operator:minCoverage is not None; 170, comparison_operator:titleAlignments.coverage() < minCoverage; 171, identifier:readSetFilter; 172, not_operator; 173, identifier:result; 174, identifier:addTitle; 175, identifier:title; 176, identifier:titleAlignments; 177, identifier:self; 178, identifier:readSetFilter; 179, assignment; 180, identifier:self; 181, identifier:readSetFilter; 182, identifier:ValueError; 183, argument_list; 184, assignment; 185, attribute; 186, argument_list; 187, identifier:len; 188, argument_list; 189, identifier:minMatchingReads; 190, None; 191, call; 192, identifier:minMatchingReads; 193, identifier:minMedianScore; 194, None; 195, call; 196, call; 197, identifier:withScoreBetterThan; 198, None; 199, call; 200, identifier:minCoverage; 201, None; 202, call; 203, identifier:minCoverage; 204, call; 205, attribute; 206, call; 207, binary_operator:'maxTitles (%r) cannot be negative.' %
                                   maxTitles; 208, identifier:titles; 209, call; 210, identifier:self; 211, identifier:keys; 212, identifier:result; 213, attribute; 214, argument_list; 215, attribute; 216, argument_list; 217, attribute; 218, argument_list; 219, attribute; 220, argument_list; 221, attribute; 222, argument_list; 223, attribute; 224, argument_list; 225, identifier:self; 226, identifier:readSetFilter; 227, identifier:ReadSetFilter; 228, argument_list; 229, string; 230, identifier:maxTitles; 231, attribute; 232, argument_list; 233, identifier:titleAlignments; 234, identifier:readCount; 235, identifier:self; 236, identifier:scoreClass; 237, call; 238, identifier:self; 239, identifier:scoreClass; 240, identifier:minMedianScore; 241, identifier:titleAlignments; 242, identifier:hasScoreBetterThan; 243, identifier:withScoreBetterThan; 244, identifier:titleAlignments; 245, identifier:coverage; 246, identifier:readSetFilter; 247, identifier:accept; 248, identifier:title; 249, identifier:titleAlignments; 250, identifier:minNewReads; 251, string_content:maxTitles (%r) cannot be negative.; 252, identifier:self; 253, identifier:sortTitles; 254, identifier:sortOn; 255, attribute; 256, argument_list; 257, identifier:titleAlignments; 258, identifier:medianScore
code: def filter(self, minMatchingReads=None, minMedianScore=None,
                 withScoreBetterThan=None, minNewReads=None, minCoverage=None,
                 maxTitles=None, sortOn='maxScore'):
          """
          Filter the titles in self to create another TitlesAlignments.
  
          @param minMatchingReads: titles that are matched by fewer reads
              are unacceptable.
          @param minMedianScore: sequences that are matched with a median
              bit score that is less are unacceptable.
          @param withScoreBetterThan: if the best score for a title is not
              as good as this value, the title is not acceptable.
          @param minNewReads: The C{float} fraction of its reads by which a new
              title's read set must differ from the read sets of all previously
              seen titles in order for this title to be considered acceptably
              different (and therefore interesting).
          @param minCoverage: The C{float} minimum fraction of the title sequence
              that must be matched by at least one read.
          @param maxTitles: A non-negative C{int} maximum number of titles to
              keep. If more titles than this are present, titles will be sorted
              (according to C{sortOn}) and only the best will be retained.
          @param sortOn: A C{str} attribute to sort on, used only if C{maxTitles}
              is not C{None}. See the C{sortTitles} method below for the legal
              values.
          @raise: C{ValueError} if C{maxTitles} is less than zero or the value of
              C{sortOn} is unknown.
          @return: A new L{TitlesAlignments} instance containing only the
              matching titles.
          """
          # Use a ReadSetFilter only if we're checking that read sets are
          # sufficiently new.
          if minNewReads is None:
              readSetFilter = None
          else:
              if self.readSetFilter is None:
                  self.readSetFilter = ReadSetFilter(minNewReads)
              readSetFilter = self.readSetFilter
  
          result = TitlesAlignments(
              self.readsAlignments, self.scoreClass, self.readSetFilter,
              importReadsAlignmentsTitles=False)
  
          if maxTitles is not None and len(self) > maxTitles:
              if maxTitles < 0:
                  raise ValueError('maxTitles (%r) cannot be negative.' %
                                   maxTitles)
              else:
                  # There are too many titles. Make a sorted list of them so
                  # we loop through them (below) in the desired order and can
                  # break when/if we've reached the maximum. We can't just
                  # take the first maxTitles titles from the sorted list now,
                  # as some of those titles might later be discarded by the
                  # filter and then we'd return a result with fewer titles
                  # than we should.
                  titles = self.sortTitles(sortOn)
          else:
              titles = self.keys()
  
          for title in titles:
              # Test max titles up front, as it may be zero.
              if maxTitles is not None and len(result) == maxTitles:
                  break
  
              titleAlignments = self[title]
              if (minMatchingReads is not None and
                      titleAlignments.readCount() < minMatchingReads):
                  continue
  
              # To compare the median score with another score, we must
              # convert both values to instances of the score class used in
              # this data set so they can be compared without us needing to
              # know if numerically greater scores are considered better or
              # not.
              if (minMedianScore is not None and
                      self.scoreClass(titleAlignments.medianScore()) <
                      self.scoreClass(minMedianScore)):
                  continue
  
              if (withScoreBetterThan is not None and not
                      titleAlignments.hasScoreBetterThan(withScoreBetterThan)):
                  continue
  
              if (minCoverage is not None and
                      titleAlignments.coverage() < minCoverage):
                  continue
  
              if (readSetFilter and not
                      readSetFilter.accept(title, titleAlignments)):
                  continue
  
              result.addTitle(title, titleAlignments)
  
          return result