annotate blast_to_scaffold.py @ 0:7fb07a6ab968 draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
author drosofff
date Tue, 05 Jan 2016 09:25:59 -0500
parents
children 61731b911f4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
1 #!/usr/bin/env python
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
2 import sys
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
3 import argparse
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
4
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
5 def insert_newlines(string, every=60):
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
6 lines = []
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
7 for i in xrange(0, len(string), every):
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
8 lines.append(string[i:i+every])
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
9 return '\n'.join(lines)
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
10
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
11 def getseq (fastadict, transcript, up, down, orientation="direct"):
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
12 def reverse (seq):
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
13 revdict = {"A":"T","T":"A","G":"C","C":"G","N":"N"}
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
14 revseq = [revdict[i] for i in seq[::-1]]
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
15 return "".join(revseq)
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
16 pickseq = fastadict[transcript][up-1:down]
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
17 if orientation == "direct":
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
18 return pickseq
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
19 else:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
20 return reverse(pickseq)
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
21
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
22 def Parser():
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
23 the_parser = argparse.ArgumentParser(
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
24 description="Generate DNA scaffold from blastn or tblastx alignment of Contigs")
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
25 the_parser.add_argument(
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
26 '--sequences', action="store", type=str, help="input sequence file in fasta format")
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
27 the_parser.add_argument(
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
28 '--guideSequence', action="store", type=str, help="the reference sequence to guide the scaffold assembly in fasta format")
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
29 the_parser.add_argument(
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
30 '--blast-tab', dest="blast_tab", action="store", type=str, help="13-columns tabular blastn or tblastx output")
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
31 the_parser.add_argument(
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
32 '--output', action="store", type=str, help="output file path, fasta format")
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
33 args = the_parser.parse_args()
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
34 return args
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
35
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
36 def blatnInfo (file):
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
37 blastlist = []
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
38 with open(file, "r") as f:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
39 for line in f:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
40 minilist = []
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
41 fields = line.rstrip().split()
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
42 minilist.append(fields[0])
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
43 minilist.extend(fields[6:10])
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
44 blastlist.append(minilist)
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
45 blastlist.sort(key=lambda x: x[3], reverse=True)
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
46 return blastlist
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
47
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
48 def myContigs (file):
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
49 Contigs = {}
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
50 with open(file, "r") as f:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
51 for line in f:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
52 if line[0] == ">":
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
53 header = line[1:-1]
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
54 Contigs[header] = ""
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
55 else:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
56 Contigs[header] += line[:-1]
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
57 return Contigs
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
58
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
59 def myGuide (file):
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
60 Guide = {}
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
61 coordinate = 0
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
62 with open(file, "r") as f:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
63 for line in f:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
64 if line[0] == ">":
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
65 continue
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
66 else:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
67 for nucleotide in line[:-1]:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
68 coordinate += 1
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
69 Guide[coordinate] = nucleotide.lower()
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
70 return Guide
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
71
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
72 def updateGuide (blastlist, GuideDict, ContigsDict):
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
73 '''
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
74 the blastlist object is a list of list with
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
75 element [0] : name of the blasted Contig
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
76 element [1] : queryStart of the alignment to the reference
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
77 element [2] = queryStop of the alignment to the reference
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
78 element [3] : subjectStart of the alignment to the reference
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
79 element [4] = subjectStop of the alignment to the reference
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
80 '''
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
81 for fields in blastlist:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
82 seqHeader = fields[0]
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
83 queryStart = int(fields[1])
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
84 queryStop = int(fields[2])
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
85 subjectStart = int(fields[3])
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
86 subjectStop = int(fields[4])
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
87 if subjectStart > subjectStop:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
88 subjectStart, subjectStop = subjectStop, subjectStart
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
89 orientation = "reverse"
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
90 else:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
91 orientation = "direct"
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
92 sequence = getseq (ContigsDict, seqHeader, queryStart, queryStop, orientation)
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
93 for i in range(subjectStart, subjectStop+1):
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
94 try:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
95 del GuideDict[i]
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
96 except KeyError:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
97 continue
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
98 for i, nucleotide in enumerate(sequence):
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
99 GuideDict[i+subjectStart] = nucleotide
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
100
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
101 def finalAssembly (GuideDict, outputfile):
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
102 finalSeqList = []
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
103 for keys in sorted(GuideDict):
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
104 finalSeqList.append(GuideDict[keys])
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
105 finalSequence = insert_newlines("".join(finalSeqList) )
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
106 Out = open (outputfile, "w")
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
107 print >> Out, ">Scaffold"
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
108 print >> Out, finalSequence
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
109 Out.close()
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
110
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
111 def __main__():
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
112 args = Parser()
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
113 ContigsDict = myContigs (args.sequences)
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
114 GuideDict = myGuide (args.guideSequence)
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
115 blastlist = blatnInfo(args.blast_tab)
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
116 updateGuide(blastlist, GuideDict, ContigsDict)
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
117 finalAssembly(GuideDict, args.output)
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
118
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
119 if __name__ == "__main__":
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
120 __main__()