Question: Sort Sam file by chromosome and position in python
0
gravatar for hectorbaigessanchez
8 weeks ago by
hectorbaigessanchez0 wrote:

Hi, I'm trying to read a sam file and write another sam file sorted by chromosome and position.

The problem is that there are some sam files that have no alignment like

seq1 16 cr1 100 ....
seq1 16 cr2 100 ....
seq2 4  *   0   ....

So when I try to sort with this

df = pd.read_csv('file.sam', sep="\t", header=None).to_numpy()
list1 = sorted(df, key=operator.itemgetter(1, 2))

Returns this

 seq2 4  *   0  ....
seq1 16 cr1 100 ....
seq1 16 cr2 100 ....
sam alignment python genome • 136 views
ADD COMMENTlink written 8 weeks ago by hectorbaigessanchez0

Check pysam rather than coming up with costom solutions, it is the swiss-army knife for sequencing data manipulation in python.

ADD REPLYlink written 8 weeks ago by ATpoint44k

So how would you sort the sam file by chromosome and position using pysam?

ADD REPLYlink written 8 weeks ago by hectorbaigessanchez0

https://pysam.readthedocs.io/en/latest/api.html

ADD REPLYlink written 8 weeks ago by ATpoint44k
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: 1812 users visited in the last hour
_