Giter Site home page Giter Site logo

Comments (4)

daler avatar daler commented on July 28, 2024

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.

jorgsk avatar jorgsk commented on July 28, 2024

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.

daler avatar daler commented on July 28, 2024

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.

jorgsk avatar jorgsk commented on July 28, 2024

Wonderful! Thanks. I'm closing the issue with this.

from pybedtools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.