SEQanswers

Go Back   SEQanswers > General



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting SAM files ronaldrcutler RNA Sequencing 6 07-01-2016 09:08 AM
Cufflinks refuses to operate on Tophat2 created bam or sam files due to sorting error amrezans Bioinformatics 1 06-24-2013 12:54 PM
sorting sam file crh Bioinformatics 2 06-16-2011 06:45 AM
Sorting SAM output from Bowtie DrD2009 Bioinformatics 9 11-10-2010 11:52 AM
Sorting large files scami Bioinformatics 3 09-20-2010 11:45 PM

Reply
 
Thread Tools
Old 12-07-2016, 08:19 AM   #1
mavadhani
Junior Member
 
Location: baltimore

Join Date: Jul 2016
Posts: 9
Default Help with sorting sam files in python!

Hello All!

I am new to coding. I have written a python script to analyze a bunch of fastq files from RNASeq analysis. I am using the subprocess module to call bowtie2 in order to index the genome and align the unpaired short reads to the genome.My script generates a sam file which needs to be sorted before running the cuffdiff module. The linux sort command works perfectly on my mac, however, in spite of installing the Unxupdates on my windows at work, I am unable to make my script work. I am hoping for some help/advice here to sort my sam file in python. Here is the script I tried.

#!/usr/bin/env python2.7

import os, sys

inputFile = open(‘Outputfile1.txt’, 'r')

lineList = inputFile.readlines()

for line in sorted(lineList):

print(line.rstrip());

With this script, the stdout is written to the screen. But this recognizes only the text file. Sam files are not recognized.

Any help is much appreciated.

Thanks in advance.
-M
mavadhani is offline   Reply With Quote
Old 12-07-2016, 01:42 PM   #2
wdecoster
Member
 
Location: Antwerp, Belgium

Join Date: Oct 2015
Posts: 89
Default

No, that's really not how you should sort a sam file. You should either have a look at samtools sort or pysam (python module).

I don't think doing this in plain python is a good idea, there are better alternatives such as bash loops, gnu-parallel, snakemake.
wdecoster is offline   Reply With Quote
Old 12-08-2016, 07:03 AM   #3
mavadhani
Junior Member
 
Location: baltimore

Join Date: Jul 2016
Posts: 9
Default

Hi wdecoster,

Thanks for your response. Samtools sort function does not work on the windows terminal with either sam or bam files. But the samtools view function converts sam to bam format successfully. Also, the latest version of pysam for windows is not running on my machine. I will try snakemake.

Thanks again,
-M
mavadhani is offline   Reply With Quote
Old 12-08-2016, 09:10 AM   #4
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,301
Default

Quote:
Originally Posted by mavadhani View Post
Samtools sort function does not work on the windows terminal with either sam or bam files.
Is that reference to "ubuntu bash on windows 10" or something else?
GenoMax is offline   Reply With Quote
Old 12-08-2016, 09:20 AM   #5
mavadhani
Junior Member
 
Location: baltimore

Join Date: Jul 2016
Posts: 9
Default

Thanks GenoMax. Samtools sort sorts only bam files on the windows 10 terminal. With the sam file input, it gives the following error: samtools.exe has stopped working.

Also, does pysam work on windows? From what I saw, there is no pysam version for windows yet.

Thanks again,
-M
mavadhani is offline   Reply With Quote
Old 12-08-2016, 10:00 AM   #6
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,301
Default

AFAIK the linux version of samtools works with ubuntu bash terminal in windows 10. Are you not using that (I see a reference to samtools.exe)?
GenoMax is offline   Reply With Quote
Old 12-08-2016, 10:14 AM   #7
mavadhani
Junior Member
 
Location: baltimore

Join Date: Jul 2016
Posts: 9
Default

That is what I am using. samtools view works fine. The sort function works only on bam input, not on the sam input.

I downloaded unix utilities from
http://gnuwin32.sourceforge.net/packages/coreutils.htm.

Now the linux sort works on windows.

Thanks again.
-M
mavadhani is offline   Reply With Quote
Reply

Tags
cuffdiff, python, sam file, sort, sorted

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 03:33 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO