INNER CODE UNIT · Python

all_refs_ordered

MariaNattestad/assemblytics · assemblytics/dotplot.py:34

    all_refs_ordered = [r for r in ordered_common_names if r in unique_refs] + \
                       [r for r in unique_refs if r not in ordered_common_names]
    
    coords['ref'] = pd.Categorical(coords['ref'], categories=all_refs_ordered, ordered=True)
    coords = coords.sort_values('ref')

    # Get chromosome lengths and calculate offsets
    chr_lengths = coords.groupby('ref', observed=False)['ref_length'].max().reindex(all_refs_ordered).fillna(0)
    chr_offsets = chr_lengths.cumsum().shift(1).fillna(0)

    def get_ref_loc(chrom, pos):
        return chr_offsets[chrom] + pos

    coords['ref_loc_start'] = coords.apply(lambda row: get_ref_loc(row['ref'], row['ref_start']), axis=1)
    coords['ref_loc_stop'] = coords.apply(lambda row: get_ref_loc(row['ref'], row['ref_end']), axis=1)

    # Calculate alignment length for query ordering
    coords['alignment_length'] = abs(coords['query_start'] - coords['query_end'])

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…