Returns two dictionaries:
           1) name=>contig length.
           2) Second is dictionary of nucmer hits (ignoring self matches).
              contig name => list of hits
8478
def _load_nucmer_hits(self, infile):
        ''''''
        hits = {}
        lengths = {}
        file_reader = pymummer.coords_file.reader(infile)
        for al in file_reader:
            if al.qry_name == al.ref_name:
                continue
            elif al.qry_name not in hits:
                hits[al.qry_name] = []
            hits[al.qry_name].append(al)
            lengths[al.qry_name] = al.qry_length
            lengths[al.ref_name] = al.ref_length
        return lengths, hits
1222516
def _nucmer_hits_to_percent_identity(nucmer_hits):
        ''''''
        percent_identities = {}
        max_lengths = {}

        for contig in nucmer_hits:
            max_length = -1
            percent_identity = 0
            for hit in nucmer_hits[contig]:
                if hit.hit_length_qry > max_length:
                    max_length = hit.hit_length_qry
                    percent_identity = hit.percent_identity
            percent_identities[contig] = percent_identity

        return percent_identities
214218
def get_name_type_dict(self):
        
        attrs = self.get_attributes()
        types = self.get_types()
        d = dict()
        for i,a in enumerate(attrs):
            d[a] = types[i]

        return d
266543
def cmp_like_py2(dict1, dict2):  # type: (Dict[Text, Any], Dict[Text, Any]) -> int
    
    # extract lists from both dicts
    first, second = dict1["position"], dict2["position"]
    # iterate through both list till max of their size
    for i, j in zip_longest(first, second):
        if i == j:
            continue
        # in case 1st list is smaller
        # should come first in sorting
        if i is None:
            return -1
        # if 1st list is longer,
        # it should come later in sort
        elif j is None:
            return 1

        # if either of the list contains str element
        # at any index, both should be str before comparing
        if isinstance(i, str) or isinstance(j, str):
            return 1 if str(i) > str(j) else -1
        # int comparison otherwise
        return 1 if i > j else -1
    # if both lists are equal
    return 0
1084604
def metrics(self):
        
        return dict(
            (name, getattr(Metrics, config['type']))
            for name, config in six.iteritems(self._metrics)
        )
1208101
def _nucmer_hits_to_assembly_coords(nucmer_hits):
        ''''''
        coords = {}
        for l in nucmer_hits.values():
            for hit in l:
                if hit.qry_name not in coords:
                    coords[hit.qry_name] = []
                coords[hit.qry_name].append(hit.qry_coords())

        for scaff in coords:
            pyfastaq.intervals.merge_overlapping_in_list(coords[scaff])

        return coords
714993
def to_dict(self):
        '''
        '''
        try:
            name = self.file.name
        except AttributeError:
            name = None

        try:
            size = self.size()
        except OSError:
            size = None

        return {
            'filename': name,
            'length': size,
            'content_size': size,
        }
1241333
def find_contig_distribution(contig_lengths_dict):
    
    # Initialise the dictionary
    contig_len_dist_dict = dict()
    for file_name, contig_lengths in contig_lengths_dict.items():
        # Initialise integers to store the number of contigs that fall into the different bin sizes
        over_1000000 = 0
        over_500000 = 0
        over_100000 = 0
        over_50000 = 0
        over_10000 = 0
        over_5000 = 0
        other = 0
        for contig_length in contig_lengths:
            # Depending on the size of the contig, increment the appropriate integer
            if contig_length > 1000000:
                over_1000000 += 1
            elif contig_length > 500000:
                over_500000 += 1
            elif contig_length > 100000:
                over_100000 += 1
            elif contig_length > 50000:
                over_50000 += 1
            elif contig_length > 10000:
                over_10000 += 1
            elif contig_length > 5000:
                over_5000 += 1
            else:
                other += 1
        # Populate the dictionary with a tuple of each of the size range frequencies
        contig_len_dist_dict[file_name] = (over_1000000,
                                           over_500000,
                                           over_100000,
                                           over_50000,
                                           over_10000,
                                           over_5000,
                                           other)
    return contig_len_dist_dict
256365
def name_targets(func):
    
    def wrap(*a, **kw):
        ret = func(*a, **kw)
        return dict(zip(ret[:-1], ret[-1]))
    return wrap
1219609
def _get_dict(names, ndarrays):
        """"""
        nset = set()
        for nm in names:
            if nm in nset:
                raise ValueError('Duplicate names detected, %s' % str(names))
            nset.add(nm)
        return dict(zip(names, ndarrays))
1078681
def attrib(self):
        
        return dict([
            ('aValue', str(self.a_val)),
            ('bValue', str(self.b_val)),
            ('minMag', str(self.min_mag)),
            ('maxMag', str(self.max_mag)),
        ])
718179
def names_dict(self):
        """"""
        INCLUDE_KEYS = ['name', 'vname', 'vid']

        d = {k: v for k, v in iteritems(self.dict) if k in INCLUDE_KEYS}

        d['fqname'] = self.fqname

        return d
1120578
def _get_sg_name_dict(self, data, page_size, no_nameconv):
        
        if no_nameconv:
            return {}
        neutron_client = self.get_client()
        search_opts = {'fields': ['id', 'name']}
        if self.pagination_support:
            if page_size:
                search_opts.update({'limit': page_size})
        sec_group_ids = set()
        for rule in data:
            for key in self.replace_rules:
                if rule.get(key):
                    sec_group_ids.add(rule[key])
        sec_group_ids = list(sec_group_ids)

        def _get_sec_group_list(sec_group_ids):
            search_opts['id'] = sec_group_ids
            return neutron_client.list_security_groups(
                **search_opts).get('security_groups', [])

        try:
            secgroups = _get_sec_group_list(sec_group_ids)
        except exceptions.RequestURITooLong as uri_len_exc:
            # Length of a query filter on security group rule id
            # id=<uuid>& (with len(uuid)=36)
            sec_group_id_filter_len = 40
            # The URI is too long because of too many sec_group_id filters
            # Use the excess attribute of the exception to know how many
            # sec_group_id filters can be inserted into a single request
            sec_group_count = len(sec_group_ids)
            max_size = ((sec_group_id_filter_len * sec_group_count) -
                        uri_len_exc.excess)
            chunk_size = max_size // sec_group_id_filter_len
            secgroups = []
            for i in range(0, sec_group_count, chunk_size):
                secgroups.extend(
                    _get_sec_group_list(sec_group_ids[i: i + chunk_size]))

        return dict([(sg['id'], sg['name'])
                     for sg in secgroups if sg['name']])
1139756
def _get_possible_query_bridging_contigs(self, nucmer_hits, log_fh=None, log_outprefix=None):
        ''''''
        bridges = {}
        writing_log_file = None not in [log_fh, log_outprefix]

        for qry_name, hits_to_qry in nucmer_hits.items():
            if len(hits_to_qry) < 2:
                continue

            if writing_log_file:
                print(log_outprefix, '\t', qry_name, ': checking nucmer matches', sep='', file=log_fh)

            longest_start_hit = self._get_longest_hit_at_qry_start(hits_to_qry)
            longest_end_hit = self._get_longest_hit_at_qry_end(hits_to_qry)

            if (
                None in (longest_start_hit, longest_end_hit)
              or longest_start_hit.ref_name == longest_end_hit.ref_name
              or self._hits_have_same_reference(longest_start_hit, longest_end_hit)
            ):
                if writing_log_file:
                    print(log_outprefix, '\t', qry_name, ': no potential pairs of hits to merge contigs', sep='', file=log_fh)
                continue

            if writing_log_file:
                print(log_outprefix, '\t', qry_name, ': potential pair of hits to merge contigs...', sep='', file=log_fh)
                print(log_outprefix, '\t', qry_name, ':    ', longest_start_hit, sep='', file=log_fh)
                print(log_outprefix, '\t', qry_name, ':    ', longest_end_hit, sep='', file=log_fh)

            shortest_hit_length = self._min_qry_hit_length([longest_start_hit, longest_end_hit])
            has_longer_hit = self._has_qry_hit_longer_than(
                hits_to_qry,
                shortest_hit_length,
                hits_to_exclude={longest_start_hit, longest_end_hit}
            )

            if has_longer_hit and writing_log_file:
                print(log_outprefix, '\t', qry_name, ':    rejected - there is a longer hit to elsewhere', sep='', file=log_fh)

            orientation_ok = self._orientation_ok_to_bridge_contigs(longest_start_hit, longest_end_hit)

            if writing_log_file and not orientation_ok:
                print(log_outprefix, '\t', qry_name, ':    rejected - orientation/distance from ends not correct to make a merge', sep='', file=log_fh)

            if orientation_ok and not has_longer_hit:
                if writing_log_file:
                    print(log_outprefix, '\t', qry_name, ':    might be used - no longer hits elsewhere and orientation/distance to ends OK', sep='', file=log_fh)
                bridges[qry_name] = (longest_start_hit, longest_end_hit)

        return bridges
73695
def as_dict(self):
        
        #TODO/FIXME: add selected information
        if self.hidden:
            rdict = {}
        else:
            def_selected = self.selected()
            comps = [
                {
                    'name': comp.name,
                    'default': comp.name in self.defaults,
                    'options': comp.get_ordered_options() if isinstance(comp, Optionable) else None
                }
                for comp in self
            ]
            rdict = {
                'name': self.name,
                'required': self.required,
                'multiple': self.multiple,
                'args': self.in_name,
                'returns': self.out_name,
                'components': comps
            }
        return rdict
34798
def prior_model_name_constant_tuples_dict(self):
        
        return {name: list(prior_model.constant_tuples) for name, prior_model in self.prior_model_tuples}
59781
def attrib(self):
        
        return dict([
            ('probability', str(self.probability)),
            ('strike', str(self.strike)),
            ('dip', str(self.dip)),
            ('rake', str(self.rake)),
        ])