File: raw.py

package info (click to toggle)
spades 3.13.1+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 22,172 kB
  • sloc: cpp: 136,213; ansic: 48,218; python: 16,809; perl: 4,252; sh: 2,115; java: 890; makefile: 507; pascal: 348; xml: 303
file content (70 lines) | stat: -rwxr-xr-x 1,724 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python3 -O

############################################################################
# Copyright (c) 2015 Saint Petersburg State University
# Copyright (c) 2011-2014 Saint Petersburg Academic University
# All Rights Reserved
# See file LICENSE for details.
############################################################################


#Create raw file for paired reads using chromosome map file (optional)
#Chromosome map file should contain choromosome name (as used in bowtie) and its start position in genome, one chromosome per line

import sys

if len(sys.argv) != 4 and len(sys.argv) != 3:
        print("Usage: <bowtie log file> <output> [chromosomes file]");
        exit(0)

inFile = open(sys.argv[1])
outFile = open(sys.argv[2], 'w')

wChrs = (len(sys.argv) == 4)

chrs = {" ":0}
if wChrs:	 
	chrsF = open(sys.argv[3])
	for line in chrsF:
		chrs[line.split()[0]] =	int(line.split()[1])
	chrsF.close()


delim = '/'

prevLine = ""
for line in inFile:
	if (prevLine == ""):
		prevLine = line
		continue

	if (line.split(delim, 1)[0] == prevLine.split(delim, 1)[0]):
		l1 = line.split('\t', 5)
		l2 = prevLine.split('\t', 5)

		chr2 = l1[2]
		chr1 = l2[2]
		pos2 = int(l1[3])
		pos1 = int(l2[3])
               	len2 = len(l1[4].strip())
               	len1 = len(l2[4].strip())

		if not wChrs or chr1 == chr2:
			addPos = 0
			if wChrs:
				addPos = chrs[chr1] 	

			outFile.write(str(pos1 + addPos) + ' ' + str(len1))
			outFile.write('\n')
		        outFile.write(str(pos2 + addPos) + ' ' + str(len2))
		        outFile.write('\n')
	else:
		print("Non-equal pairs\n")
		print(prevLine.split(delim, 1)[0])
		print(line.split(delim, 1)[0])
		exit(0)

	prevLine = ""

inFile.close()
outFile.close()