File: test_change_chromosome_custom.py

package info (click to toggle)
pyranges 0.0.111%2Bds-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,996 kB
  • sloc: python: 5,546; makefile: 37; sh: 6
file content (24 lines) | stat: -rw-r--r-- 657 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pandas as pd
import pyranges as pr

def test_change_chromosomes():

    df1 = pd.DataFrame({"Chromosome": ["chr1", "chr2"], "Start": [100, 200],
                    "End": [150, 201]})
    py1 = pr.PyRanges(df1)
    df2 = pd.DataFrame({"Chromosome": ["1", "2"], "Start": [1000, 2000],
                    "End": [1500, 20010]})
    py2 = pr.PyRanges(df2)

    def modify_chrom_series(df):
        df.Chromosome = df.Chromosome.apply(lambda val: val.replace("chr", ""))
        return df
    def fix_chrom(regions):
        return regions.apply(modify_chrom_series)

    print(py1)

    py1 = fix_chrom(py1)


    assert py1.chromosomes == ["1", "2"]