comparison Contra/scripts/get_chr_length.py @ 0:7564f3b1e675

Uploaded
author fcaramia
date Thu, 13 Sep 2012 02:31:43 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:7564f3b1e675
1 # ----------------------------------------------------------------------#
2 # Copyright (c) 2011, Richard Lupat & Jason Li.
3 #
4 # > Source License <
5 # This file is part of CONTRA.
6 #
7 # CONTRA is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # CONTRA is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with CONTRA. If not, see <http://www.gnu.org/licenses/>.
19 #
20 #
21 #-----------------------------------------------------------------------#
22 # Last Updated : 05 October 2011 16:43PM
23
24
25 import subprocess, shlex
26
27 def get_genome(srcFile, genomeOut):
28 genome = open(genomeOut, "w")
29
30 args = shlex.split("samtools view -H %s" %(srcFile))
31 raw_header = subprocess.Popen(args, stdout = subprocess.PIPE).communicate()[0]
32 headers = raw_header.split("\n")
33
34 for header in headers:
35 header = header.split("\t")
36 if header[0][1:] != "SQ":
37 continue
38
39 genome.write(header[1].strip("SN:") + "\t" + header[2].strip("LN:") + "\n")
40
41 genome.close()
42
43