File: paired_crop.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 (99 lines) | stat: -rw-r--r-- 2,341 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/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.
############################################################################


import sys
import os

genome = sys.argv[1]

if (bowtie == '-h'):
	print("Usage: <bowtie_path/> <genome_reference> <file with list of files> <ouput_dir/> [crop_len = 100000] [offset = 0] [minins = 0] [maxins = 10000] [orientation --(fr|rf|ff) = --fr] [format(-f/-q) = -q]\n")
	sys.exit(0)

bowtie = sys.argv[1]
genome = sys.argv[2]
flist = open(sys.argv[3])
outdir = sys.argv[4]

crop_len = 100000
if len(sys.argv) > 5:
	crop_len = int(sys.argv[5])

offset = 0
if len(sys.argv) > 6:
	offset = int(sys.argv[6])


minins = 0
if len(sys.argv) > 7:
	minins = int(sys.argv[7])

maxins = 10000
if len(sys.argv) > 8:
	maxins = (sys.argv[8])

orient = '--fr'
if len(sys.argv) > 9:
	orient = sys.argv[9]

format = "-q"
if len(sys.argv) > 10:
	format = sys.argv[10]


output_genome = outdir + genome + "_" + str(crop_len) + "_" + str(offset) + ".fa"

# crop genome to first 'crop_len' basepairs
gf = open(genome)
ogf = open(output_genome, 'w')

for line in gf:
	ogf.write(line)
	break

cnt = -offset
if offset > 0:
	for line in gf:
		if cnt >= 0:
			break
		cnt+=70

cnt = 0
for line in gf:
	if (crop_len - cnt < 70):
		line = line[0:crop_len-cnt]
	ogf.write(line);
	cnt += 70
	if cnt >= max:
		break

gf.close()
ogf.close()

print('Cropped\n')

file_suff = str(crop_len) + '_' + str(offset) + '_' + str(minins) + '_' + str(maxins) 

# build bowtie index
os.system('mkdir -p index')
os.system(bowtie +'bowtie-build ' + output_genome + ' ' + outdir + 'index/ref' + file_suff +  ' > /dev/null')
print('Index built\n')

# align reads using bowtie
for line in flist:
	l = line.split()
	f1 = l[0]
	f2 = l[1]
	fName, ext = os.path.splitext(f1)
	os.system(bowtie + 'bowtie -p 8 -c ' + format + ' --minins ' + str(minins) + ' --maxins ' + str(maxins) + ' ' + orient + ' ' + outdir + 'index/ref' + file_suff + ' -1 ' + f1.strip() + ' -2 ' + f2.strip() + ' --al ' + outdir + fName + file_suff + ext.strip() + ' > /dev/null 2> ' +  outdir + 'errlog' + file_suff)

print('Alligned\n')
# use -X for maxins length