Question: Is there a simple way to get the max coverage of a bedgraph file in python?
0
gravatar for rioualen
2.9 years ago by
rioualen320
France
rioualen320 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 • 848 views
ADD COMMENTlink modified 2.9 years ago by Alex Reynolds27k • written 2.9 years ago by rioualen320
1

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

ADD REPLYlink written 2.9 years ago by fanli.gcb650

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

ADD REPLYlink written 2.9 years ago by rioualen320
0
gravatar for rioualen
2.9 years ago by
rioualen320
France
rioualen320 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 2.9 years ago • written 2.9 years ago by rioualen320
0
gravatar for Alex Reynolds
2.9 years ago by
Alex Reynolds27k
Seattle, WA USA
Alex Reynolds27k 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 2.9 years ago by Alex Reynolds27k
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: 735 users visited in the last hour