annotate Contra/scripts/get_chr_length.py @ 11:b6ce842a633d

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