annotate Iterative_mapping/truncate.py @ 30:4d81d174dece draft

Uploaded
author tyty
date Mon, 20 Oct 2014 14:44:01 -0400
parents d56631911cc1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d56631911cc1 Uploaded
tyty
parents:
diff changeset
1 #!/usr/bin/env python
d56631911cc1 Uploaded
tyty
parents:
diff changeset
2 # -*- coding: utf-8 -*-
d56631911cc1 Uploaded
tyty
parents:
diff changeset
3
d56631911cc1 Uploaded
tyty
parents:
diff changeset
4 import sys
d56631911cc1 Uploaded
tyty
parents:
diff changeset
5 from Bio import SeqIO
d56631911cc1 Uploaded
tyty
parents:
diff changeset
6
d56631911cc1 Uploaded
tyty
parents:
diff changeset
7 fasta_file = sys.argv[1]
d56631911cc1 Uploaded
tyty
parents:
diff changeset
8 shift_in = sys.argv[2]
d56631911cc1 Uploaded
tyty
parents:
diff changeset
9 result_file = sys.argv[3]
d56631911cc1 Uploaded
tyty
parents:
diff changeset
10 length = sys.argv[4]
d56631911cc1 Uploaded
tyty
parents:
diff changeset
11
d56631911cc1 Uploaded
tyty
parents:
diff changeset
12 shift = int(shift_in)
d56631911cc1 Uploaded
tyty
parents:
diff changeset
13
d56631911cc1 Uploaded
tyty
parents:
diff changeset
14 fasta_sequences = SeqIO.parse(open(fasta_file),'fasta');
d56631911cc1 Uploaded
tyty
parents:
diff changeset
15 h = file(result_file,'w')
d56631911cc1 Uploaded
tyty
parents:
diff changeset
16 for seq in fasta_sequences:
d56631911cc1 Uploaded
tyty
parents:
diff changeset
17 nuc = seq.id;
d56631911cc1 Uploaded
tyty
parents:
diff changeset
18 sequence = seq.seq.tostring();
d56631911cc1 Uploaded
tyty
parents:
diff changeset
19 if (len(sequence)-shift)>=int(length):
d56631911cc1 Uploaded
tyty
parents:
diff changeset
20 h.write('>'+nuc)
d56631911cc1 Uploaded
tyty
parents:
diff changeset
21 h.write('\n')
d56631911cc1 Uploaded
tyty
parents:
diff changeset
22 h.write(sequence[0:(len(sequence)-shift)])
d56631911cc1 Uploaded
tyty
parents:
diff changeset
23 h.write('\n')
d56631911cc1 Uploaded
tyty
parents:
diff changeset
24
d56631911cc1 Uploaded
tyty
parents:
diff changeset
25
d56631911cc1 Uploaded
tyty
parents:
diff changeset
26
d56631911cc1 Uploaded
tyty
parents:
diff changeset
27
d56631911cc1 Uploaded
tyty
parents:
diff changeset
28 h.close()
d56631911cc1 Uploaded
tyty
parents:
diff changeset
29
d56631911cc1 Uploaded
tyty
parents:
diff changeset
30
d56631911cc1 Uploaded
tyty
parents:
diff changeset
31
d56631911cc1 Uploaded
tyty
parents:
diff changeset
32