File: guide-recipes.md

package info (click to toggle)
python-bioframe 0.4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,000 kB
  • sloc: python: 5,860; makefile: 38; sh: 13
file content (69 lines) | stat: -rw-r--r-- 1,688 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
jupytext:
  formats: md:myst
  text_representation:
    extension: .md
    format_name: myst
    format_version: 0.13
    jupytext_version: 1.11.3
kernelspec:
  display_name: Python 3
  language: python
  name: python3
---

# How do I

## Obtain overlapping intervals with matching strandedness? 
Use overlap with the ``on`` argument:
```
df = bf.overlap(df1, df2, on=[‘strand’])
```

## Obtain overlapping intervals with opposite strandedness? 
Overlap then filter pairs of opposite strandedness:
```
df = bf.overlap(df1, df2)
df = df.loc[df["strand"]!=df["strand_"]]
```
## Obtain intervals that exceed 50% coverage by another set of intervals?
Coverage, then filter pairs by fractional coverage:
```
df = bf.coverage(df1, df2)
df = df[ ( df["coverage"] / (df["end"]-df["start"]) ) >=0.50]
```

## Shift all intervals on the positive strand by 10bp?
Use pandas indexing: 
```
df.loc[df.strand=="+",["start", "end"]] += 10
```

## Obtain intervals overlapped by at least 2 intervals from another set?
Count overlaps, then filter:
```
df = bf.count_overlaps(df1, df2)
df = df[ df["count"] >= 2]
```

## Find strand-specific downstream genomic features?
Use closest after filtering by strand, and passing the `ignore_upsream=True` argument.
```
bioframe.closest(df1.loc[df1['strand']=='+'], df2, ignore_upstream=True)
```

For gener, the upstream/downstream direction might be defined by the direction of transcription. 
Use `direction_col='strand'` to set up the direction: 
```
bioframe.closest(df1, df2, ignore_upstream=True, direction_col='strand')
```

## Drop non-autosomes from a bedframe?
Use pandas DataFrame.isin(values):
```
df[ ~df.chrom.isin(['chrX','chrY'])]
```