Sort Sam file by chromosome and position in python
0
0
Entering edit mode
3.4 years ago

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 python genome alignment • 1.0k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
ADD REPLY

Login before adding your answer.

Traffic: 1468 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6