Comments (4)
This error is because merge()
only operates on a single file (e.g., mergeBed -i infile
from the command line). Currently the decorator that performs the wrapping does not have a useful error message. I'll have to think about how best to improve this. Also, for convenience you can pass an assembly name as the "genome" kwarg to save a step:
import pybedtools
annotated = pybedtools.BedTool('file1.bed')
discovered = pybedtools.BedTool('file2.bed')
ann_slop = annotated.slop(genome='hg19', b=10)
disc_slop = discovered.slop(genome='hg19', b=10)
# gives an error, because merge only operates on a single file.
# By default it's the file the BedTool points to (here, file1.bed)
#
# mergd = ann_slop.merge(disc_slop, s=True, nms=True)
# "merge" only merges one file
ann_merged = ann_slop.merge(s=True, nms=True)
# perhaps this is what you want?
in_common = ann_slop.intersect(disc_slop, s=True)
What is the output you'd like to get? You may need to use args like wo=True
for the intersection depending on your needs.
from pybedtools.
I see now that I used mergeBed in an unintended way, thanks for the good explanation and the tip about 'hg19'. The output I was after was actually to first concatenate the two files and then merge them:
cat annotated merged | slopBed -i stdin -b 10 -g hg19 | mergeBed -i stdin | sortBed -i stdin > my_output.bed
The solution I ended up with was what you outlined. But since I wanted the entries unique to ann_slop and disc_slop too I added them manually with an intersectBed -v against the in_common file.
What would you would suggest for the pipeline above with only pybedtools? (avoiding the cat method since it truncates at BED3)
from pybedtools.
I just committed a change b64ceb8 that checks to see if the input filenames are 1) the same type and 2) have the same number of fields. If so, then no truncation will happen.
In my use-cases, I typically would cat and then merge, so the BedTool.cat() method does a post-merge unless you tell it not to; additional kwargs are sent to the merge command after cat-ing. Also keep in mind that the latest BEDTools version requires that a file be sorted before merging, but the command in BedTool.cat takes care of that.
However, you're doing a slop call before merging. So something like this should do the same as the command you showed:
import pybedtools
results = pybedtools.BedTool('file1.bed')\
.cat('file2.bed', post_merge=False)\
.slop(genome='hg19', b=10)\
.sort()\
.merge()
from pybedtools.
Wonderful! Thanks. I'm closing the issue with this.
from pybedtools.
Related Issues (20)
- pybedtools.bedtool.BedTool.save_seqs leaves open .tmp files
- Support Python 3.10 and 3.11 HOT 1
- "python setup.py bdist_wheel did not run successfully" when pip installing with python v3.11 HOT 8
- to_dataframe() creates 0th row with generic names in nucleotide_content HOT 2
- build failure under python 3.11 HOT 6
- pybedtools intersect error HOT 2
- Cannot create a BedTool object from list of regions that uses np.int64 coordinates
- remove historical py27 support HOT 1
- bedtools intersect reported incorrect interval intersection HOT 3
- Cythonizing files requires `language_level=2` to be set in cythonize() HOT 4
- pybedtools multi_bam_coverage assistance HOT 2
- "fastaFromBed" error HOT 2
- intersect with multiple -b arguments not working with -sorted HOT 1
- Unable to install pybedtools==0.9.1 in Python3.10 HOT 4
- Len modifying the Bedtools after a filter HOT 2
- Has pybedtools considered packaging bedtools? HOT 3
- how to mask gap regions for randomization? HOT 1
- Issue while doing pip install pybedtools HOT 3
- Inconsistent behaviour when using files from `pathlib.PosixPath` with BedTool functions...
- pybedtools.bedtool.Bedtool.sort()
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pybedtools.