4

Answer to main question: import pyranges as pr assert int(pr.__version__.split(".")[2]) >= 93, "pip install pyranges==0.0.93" import numpy as np np.random.seed(42 * 10) # create large df to test on gr = pr.random(int(1e5), length=1, chromsizes={"chr1": 249250621}) gr.Score = np.random.randint(250, size=len(gr)) result = gr....


3

Following up on zorbax's answer, you could read in and filter the GTF file in this way, among others: #!/usr/bin/env python import gtfparse as gp gtf_file = "test.gtf" test_list = ["PCNA", "USP21", "USP1"] df = gp.read_gtf(gtf_file) subset = df[df['gene_name'].str.contains('|'.join(test_list))] print(subset) You ...


2

If you have your gtf file like a DataFrame you can use: df[df['gene_name'].str.contains('|'.join(test_list))]


2

Setup: import pandas as pd import pyranges as pr from pyranges import PyRanges from scipy.stats import fisher_exact import numpy as np # ! zcat dataset1.tsv.gz | head -2 # chromosome start end num_motifs_in_group called_sites called_sites_methylated methylated_frequency group_sequence # chr21 5010053 5010053 1 3 0 0.000 CACCACGTCCA # ...


1

Unless you need to use Python and can't use subprocess, here's a quick CLI one-liner which sums signal from sorted BED5 files, over the genomic space where they overlap: $ bedmap --echo --sum --delim '\t' <(bedops --merge A.bed B.bed ... N.bed) <(bedops --everything A.bed B.bed ... N.bed) > answer.bed (Requires bash for process substitutions.)


1

It turned out to be a lot easier if I used grep to do this: grep -w -f genes.txt gencode.v19.annotation.gtf > sub_set.gtf genes.txt contains gene symbols on new lines.


1

Quick and dirty (not to mention atrociously bad O(n)) solution: import pyranges as pr import numpy as np np.random.seed(42 * 10) # create large df to test on gr = pr.random(int(1e5), length=10000, chromsizes={"chr1": 249250621}) gr.Score = np.random.randint(250, size=len(gr)) def remove_worst_scores_until_no_overlap(gr): df = gr.df ...


Only top voted, non community-wiki answers of a minimum length are eligible