We changed our privacy policy. Read more.
6

Your setup: import pandas as pd dict1 = {0:['chr1','chr1','chr1','chr1','chr2'], 1:[1, 100, 150, 900, 1], 2:[100, 200, 500, 950, 100], 3:['feature1', 'feature2', 'feature3', 'feature4', 'feature4'], 4:[0, 0, 0, 0, 0], 5:['+','+','-','+','+']} df1 = pd.DataFrame(dict1) print(df1) ## 0 1 2 3 4 5 ## 0 chr1 1 100 ...


4

I don't think Pandas has this implemented functionality out-of-the-box. Even if it did, solutions not designed specifically for bioinformatics probably rarely handle intervals on different chromosomes correctly unless you split the intervals by chromosome first. Pandas does handle intervals (see docs for the Interval and IntervalIndex classes), but I've ...


4

pybedtools assumes that bedtools is in your path and bedtools itself will return the version with bedtools --version. So: import subprocess subprocess.check_output(['bedtools', '--version'], text=True).strip().split()[1] For me that returns 'v2.30.0'.


3

To make disjoint intervals, you could use BEDOPS bedops --partition, piping to bedmap --mean to get the mean signal over disjoint regions. Starting with the input bedgraph file, convert it to five-column BED with GNU awk, putting the signal in the fifth column per UCSC convention: $ awk -vOFS="\t" '{ print $1, $2, $3, ".", $4 }' /tmp/in.bedgraph | sort-bed ...


2

As mentioned by OP, another option is to use pybedtools, which in my opinion is pretty convenient for people already familiar with BedTools. Let's even say df1's format is slightly different than df2: import pandas as pd dict1 = {0: ['chr1', 'chr1', 'chr1', 'chr1', 'chr2'], 1: [1, 100, 150, 900, 1], 2: [100, 200, 500, 950, 100], 3: ['...


2

I implemented pandas "Intervals" and ... it should be a few lines, clearly there are limitations. For non-overlapping data it is very cool however. It will work for overlapping data, BUT if the data you are using as the interval data is overlapping, it falls over. It could work if an independent (non-overlapping) interval was constructed. Anyway, the point ...


2

The reason why unpacking an Interval results in strings instead of ints might be related to how indexing by position works. Even without considering the string/int issue, it seems slightly more efficient to access the interval's attributes rather than unpacking them directly: In [311]: %timeit [(chrom, start, end, strand) for (chrom, start, end, _, _, ...


2

You have to take your variables and make them into a single string variable. for example: chr_ = "chr1" start = 3000 end = 3402 as_str = ' '.join([chr_, str(start), str(end)]) # or as_str2 = "{} {} {}".format(chr_, start, end) Once you have the string built you can use the example in the bedTool docs. a = BedTool(as_str, from_string=True)


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