Question: Secuence length in bed file
0
gravatar for sudupelaura
10 weeks ago by
sudupelaura0 wrote:

Hi!

I´m trying to graph the length of the sequences from a bed file. I know how to get the length with awk, but I want to do it with python, using pybedtools. How do I do it? I

Thank you!

bed file sequence python • 218 views
ADD COMMENTlink modified 9 weeks ago by Alex Reynolds31k • written 10 weeks ago by sudupelaura0

What have you tried? Why do you want to do it in python?

ADD REPLYlink written 10 weeks ago by _r_am32k

I tried to iterate from components and got the following error "OverflowError: Cannot convert negative value to CHRPOS". I am new to bioinformatics and I am not sure if it is the correct way. I know is related to starting coordinates, but I don't know how to fix it. I want to do it in Python to reuse the program from all the bed files that I have to analyze.

Thanks!

ADD REPLYlink written 10 weeks ago by sudupelaura0

It seems that a position is exceeding the maximum value that the variable being used for it can handle. You might need to search on how to get pybedtools to handle large integer values.

ADD REPLYlink written 10 weeks ago by _r_am32k

You're right.Thanks for your advice!

ADD REPLYlink written 8 weeks ago by sudupelaura0
1
gravatar for Alex Reynolds
9 weeks ago by
Alex Reynolds31k
Seattle, WA USA
Alex Reynolds31k wrote:

Why would you need pybedtools? Just subtract the stop and start coordinates to get the sequence length. Put the lengths into an array and plot a histogram (or do whatever else you want with the lengths):

#!/usr/bin/env python

import numpy as np
import matplotlib.pyplot as plt
import sys

lengths = []
for line in sys.stdin:
    elems = line.rstrip().split('\t')
    lengths.append(int(elems[2]) - int(elems[1]))

plt.hist(np.array(lengths), bins='auto')  # arguments are passed to np.histogram
plt.title("Sequence lengths histogram")
plt.show()

To use, e.g.:

$ python ./so471158.py < in.bed
ADD COMMENTlink modified 9 weeks ago • written 9 weeks ago by Alex Reynolds31k

Thank for the example! Help me a lot. I want to use pybedtools because mi supervisor told me, but it isn´t required

ADD REPLYlink written 6 weeks ago by sudupelaura0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1174 users visited in the last hour