annotate blast_to_scaffold.py @ 5:81ffa74cf96e draft default tip

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit b6de14061c479f0418cd89e26d6f5ac26e565a07
author drosofff
date Wed, 09 Nov 2016 11:38:39 -0500
parents 3288cc5a57e5
children
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")
4
3288cc5a57e5 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit fb47b9859a0703f1fa4a1e76b75b9dae29ca8329
drosofff
parents: 3
diff changeset
33 the_parser.add_argument(
3288cc5a57e5 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit fb47b9859a0703f1fa4a1e76b75b9dae29ca8329
drosofff
parents: 3
diff changeset
34 '--scaffold_prefix', action="store", type=str, help="the prefix that will be used for the header of the fasta scaffold")
3288cc5a57e5 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit fb47b9859a0703f1fa4a1e76b75b9dae29ca8329
drosofff
parents: 3
diff changeset
35 the_parser.add_argument(
3288cc5a57e5 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit fb47b9859a0703f1fa4a1e76b75b9dae29ca8329
drosofff
parents: 3
diff changeset
36 '--scaffold_suffix', action="store", type=str, help="the sufix that will be used for the header of the fasta scaffold")
0
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
37 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
38 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
39
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
40 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
41 blastlist = []
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
42 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
43 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
44 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 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
46 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
47 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
48 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
49 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
50 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
51
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
52 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
53 Contigs = {}
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
54 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
55 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
56 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
57 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
58 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
59 else:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
60 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
61 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
62
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
63 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
64 Guide = {}
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
65 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
66 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
67 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
68 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
69 continue
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
70 else:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
71 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
72 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
73 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
74 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
75
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
76 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
77 '''
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
78 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
79 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
80 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
81 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
82 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
83 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
84 '''
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
85 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
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93 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
94 else:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
95 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
96 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
97 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
98 try:
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
99 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
100 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
101 continue
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
102 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
103 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
104
4
3288cc5a57e5 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit fb47b9859a0703f1fa4a1e76b75b9dae29ca8329
drosofff
parents: 3
diff changeset
105 def finalAssembly (GuideDict, outputfile, prefix, suffix):
0
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
106 finalSeqList = []
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
107 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
108 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
109 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
110 Out = open (outputfile, "w")
4
3288cc5a57e5 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit fb47b9859a0703f1fa4a1e76b75b9dae29ca8329
drosofff
parents: 3
diff changeset
111 print >> Out, ">Scaffold_from_%s_guided_by_%s" % (prefix, suffix)
0
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
112 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
113 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
114
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
115 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
116 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
117 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
118 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
119 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
120 updateGuide(blastlist, GuideDict, ContigsDict)
4
3288cc5a57e5 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit fb47b9859a0703f1fa4a1e76b75b9dae29ca8329
drosofff
parents: 3
diff changeset
121 finalAssembly(GuideDict, args.output, args.scaffold_prefix, args.scaffold_suffix)
0
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
122
7fb07a6ab968 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/blast_to_scaffold commit 8dbdc4db56dc4a00eb480fc191027a54ffd6ab45
drosofff
parents:
diff changeset
123 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
124 __main__()