Giter Site home page Giter Site logo

Interval.__setitem__? about pybedtools HOT 9 CLOSED

daler avatar daler commented on July 28, 2024
Interval.__setitem__?

from pybedtools.

Comments (9)

brentp avatar brentp commented on July 28, 2024
self._bed.fields[key] = string(value)

then the key still has to be an integer. for the key as a string maybe (untested)

if isinstance(key, basestring):
    setattr(self, key)

from pybedtools.

daler avatar daler commented on July 28, 2024

OK, trying to setitem sort of works:

    def __setitem__(self, object key, object value):
        if isinstance(key, (int,long)):
            nfields = self._bed.fields.size()
            if key >= nfields:
                raise IndexError('field index out of range')
            elif key < 0: key = nfields + key
            self._bed.fields[key] = string(value)
        elif isinstance(key, (basestring)):
            setattr(self, key, value)

it looks like the chrom is getting changed (verified by printing the fields) but this is not recognized when i access Interval.chrom . . . see the test at:
https://github.com/daler/pybedtools/blob/exp/pybedtools/test/test_cbedtools.py#L117

the failed test shows this:

FAIL: testSetItem (pybedtools.test.test_cbedtools.IntervalTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ryan/proj/pybedtools/pybedtools/test/test_cbedtools.py", line 123, in testSetItem
    self.assertEqual(iv['chrom'], 'fake')
AssertionError: 'chr21' != 'fake'
-------------------- >> begin captured stdout << ---------------------
['fake', '9719768', '9721892', 'ALR/Alpha', '1004', '+']

--------------------- >> end captured stdout << ----------------------

my guess is that a similar issue causes testAppend to fail as well:
https://github.com/daler/pybedtools/blob/exp/pybedtools/test/test_cbedtools.py#L126

from pybedtools.

brentp avatar brentp commented on July 28, 2024

ah. it's because sometimes it's setting/getting the .chrom property in c++ (with the string) and others it's setting/getting the field (with the integer key).
i'll think about how to fix.

from pybedtools.

daler avatar daler commented on July 28, 2024

i ran into all sorts of issues trying to get this to work 1) with GFF files and 2) BED files that get something appended to them (and therefore getting nonempty otherFields vector).

i made some changes to getitem, which pays attention to the current length of fields and otherFields.

ba0ce3b

However, it looks like a GFF Interval, when created, gets 3 things put in its otherFields. I tried to account for this in the new getitem, but this seems like the wrong way to do it.

Can you explain how fields and otherFields should work for GFF files and for BED files of various lengths (say, BED3 vs BED9)?

from pybedtools.

daler avatar daler commented on July 28, 2024

OK, found the answer to my question in bedtool.h -- GFF parser puts "source", "fname", and "group" in the otherFields vector, while the rest of the GFF line goes into the standard BED6 fields. BED7+ has 7th and beyond placed into otherFields as expected.

from pybedtools.

brentp avatar brentp commented on July 28, 2024

i am also working on this a bit. trying to make it much simpler in the c and cython parts.

from pybedtools.

brentp avatar brentp commented on July 28, 2024

we'll have to check that all the set and normal property setters also update fields.
(note to self) make sure the field is in LOOKUPS and follow the set for chrom/ or start/end.

from pybedtools.

brentp avatar brentp commented on July 28, 2024

the .name setting is not working for GFF/GTF. needs something like:

self._bed.fields[8] = string(";".join("%s=%s" % (k, v) for k,v in attrs.iteritems()))

but also account for GTF

from pybedtools.

brentp avatar brentp commented on July 28, 2024

this is fixed as of your: d391fae yes?

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.