Question: Is there a simple way to get the max coverage of a bedgraph file in python?
0
gravatar for rioualen
3.3 years ago by
rioualen380
France
rioualen380 wrote:

Everything is in the question! Basically I guess I should load the bedgraph file and get the maximum value from the coverage column, however I can't seem to get this done.

I've tried using numpy:

>>> np.loadtxt('GSM1470159_sickle-se-q20_bwa.bedgraph', usecols=3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/numpy/lib/npyio.py", line 722, in loadtxt
    usecols = list(usecols)
TypeError: 'int' object is not iterable

This kind of stuff is a lot easier to deal with in R, however it looks super complicated to use R in python for such a simple task: https://sites.google.com/site/aslugsguidetopython/data-analysis/pandas/calling-r-from-python.

I must be missing something here, if you can help me thanks in advance!

bedgraph python • 926 views
ADD COMMENTlink modified 3.3 years ago by Alex Reynolds28k • written 3.3 years ago by rioualen380
1

Seems answered here: http://stackoverflow.com/questions/10758668/numpy-loadtxt-gives-not-iterable-error

ADD REPLYlink written 3.3 years ago by fanli.gcb660

Oh thanks, indeed! In the meantime I found another solution with pandas (see under).

ADD REPLYlink written 3.3 years ago by rioualen380
0
gravatar for rioualen
3.3 years ago by
rioualen380
France
rioualen380 wrote:

Seems I found an easier way of doing it with pandas library:

import pandas as pd
tab = pd.read_table("file.bedgraph")
cov = tab.iloc[:,3]
max = int(cov.max())
ADD COMMENTlink modified 3.3 years ago • written 3.3 years ago by rioualen380
0
gravatar for Alex Reynolds
3.3 years ago by
Alex Reynolds28k
Seattle, WA USA
Alex Reynolds28k wrote:

You could do a reverse-numerical sort on the fourth column and pull off the first value:

$ cut -f4 foo.bedgraph | sort -nr | head -1 > answer.txt
ADD COMMENTlink written 3.3 years ago by Alex Reynolds28k
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: 917 users visited in the last hour