Skip to content

Track manipulations assume features have names #4

Description

@Phlya

Hi!
I know you said you don't really maintain the package anymore, but still, I found a weird thing and thought, you might improve it... For now I did a dirty hack in my installation where necessary, but without understanding the architecture of the package it is hard to do it properly.

So, the thing is, it seems, that all the manipulations with tracks, such as overlapping, assume that features of tracks have names and 2 other fields after it.
You can see it in, for example, overlap.py file.
make_feature function from git:

def make_feature(a, b):
    return (max(a[0],b[0]),
            min(a[1],b[1]),
            make_name(a[2], b[2]),
            (a[3]+b[3])/2.0,
            a[4]==b[4] and b[4] or 0) + b[5:]

It caused error on the line with a call of make_name, because there was no a[2] or b[2] in my track - the features didn't have names.

This is how my dirty function looks and causes no trouble:

def make_feature(a, b):
    try:
    name = make_name(a[2], b[2])
    except:
        try:
            return (max(a[0],b[0]),
                    min(a[1],b[1]))
        except:
            raise ValueError
    return (max(a[0],b[0]),
            min(a[1],b[1]),
            name,
            (a[3]+b[3])/2.0,
            a[4]==b[4] and b[4] or 0) + b[5:]

The change is quite obvious, and it solved the problem, but it is not really a good way to solve it.

Another thing, concerning fields, is that such thing doesn't work:

two_not_one = overlap(complement(track1), track2)

It causes this:

Traceback (most recent call last):
  File "my_script.py", line 17, in <module>
    two_not_one = overlap(complement(track1), track2)
  File "/usr/local/lib/python2.7/dist-packages/track-1.2.0-py2.7-linux-x86_64.egg/track/manipulate.py", line 206, in __call__
    rest_of_fields = [f for f in value.fields if f not in first_fields]
AttributeError: 'VirtualTrack' object has no attribute 'fields'

I had to comment a few line in the manipulate.py to make it work, though It probably now loses the field information from tracks (I don't have any fields except for start and end, so it is not a problem for now).

It would be really nice, if you looked into these issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions