mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Add python requirement to CONVERTER_bed_to_gff_0
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
<tool id="CONVERTER_bed_to_gff_0" name="Convert BED to GFF" version="2.0.0">
|
||||
<tool id="CONVERTER_bed_to_gff_0" name="Convert BED to GFF" version="2.0.1" profile="16.04">
|
||||
<!-- <description>__NOT_USED_CURRENTLY_FOR_CONVERTERS__</description> -->
|
||||
<!-- Used on the metadata edit page. -->
|
||||
<requirements>
|
||||
<requirement type="package" version="3.7">python</requirement>
|
||||
</requirements>
|
||||
<command>python '$__tool_directory__/bed_to_gff_converter.py' '$input1' '$output1'</command>
|
||||
<inputs>
|
||||
<param format="bed" name="input1" type="data" label="Choose BED file"/>
|
||||
|
||||
@@ -12,60 +12,59 @@ def __main__():
|
||||
output_name = sys.argv[2]
|
||||
skipped_lines = 0
|
||||
first_skipped_line = 0
|
||||
out = open(output_name, 'w')
|
||||
i = 0
|
||||
for i, line in enumerate(open(input_name)):
|
||||
complete_bed = False
|
||||
line = line.rstrip('\r\n')
|
||||
if line and not line.startswith('#') and not line.startswith('track') and not line.startswith('browser'):
|
||||
try:
|
||||
elems = line.split('\t')
|
||||
if len(elems) == 12:
|
||||
complete_bed = True
|
||||
chrom = elems[0]
|
||||
if complete_bed:
|
||||
feature = "mRNA"
|
||||
else:
|
||||
with open(output_name, 'w') as out, open(input_name) as fh_in:
|
||||
for i, line in enumerate(fh_in):
|
||||
complete_bed = False
|
||||
line = line.rstrip('\r\n')
|
||||
if line and not line.startswith('#') and not line.startswith('track') and not line.startswith('browser'):
|
||||
try:
|
||||
elems = line.split('\t')
|
||||
if len(elems) == 12:
|
||||
complete_bed = True
|
||||
chrom = elems[0]
|
||||
if complete_bed:
|
||||
feature = "mRNA"
|
||||
else:
|
||||
try:
|
||||
feature = elems[3]
|
||||
except Exception:
|
||||
feature = 'feature%d' % (i + 1)
|
||||
start = int(elems[1]) + 1
|
||||
end = int(elems[2])
|
||||
try:
|
||||
feature = elems[3]
|
||||
score = elems[4]
|
||||
except Exception:
|
||||
feature = 'feature%d' % (i + 1)
|
||||
start = int(elems[1]) + 1
|
||||
end = int(elems[2])
|
||||
try:
|
||||
score = elems[4]
|
||||
score = '0'
|
||||
try:
|
||||
strand = elems[5]
|
||||
except Exception:
|
||||
strand = '+'
|
||||
try:
|
||||
group = elems[3]
|
||||
except Exception:
|
||||
group = 'group%d' % (i + 1)
|
||||
if complete_bed:
|
||||
out.write('%s\tbed2gff\t%s\t%d\t%d\t%s\t%s\t.\t%s %s;\n' % (chrom, feature, start, end, score, strand, feature, group))
|
||||
else:
|
||||
out.write('%s\tbed2gff\t%s\t%d\t%d\t%s\t%s\t.\t%s;\n' % (chrom, feature, start, end, score, strand, group))
|
||||
if complete_bed:
|
||||
# We have all the info necessary to annotate exons for genes and mRNAs
|
||||
block_count = int(elems[9])
|
||||
block_sizes = elems[10].split(',')
|
||||
block_starts = elems[11].split(',')
|
||||
for j in range(block_count):
|
||||
exon_start = int(start) + int(block_starts[j])
|
||||
exon_end = exon_start + int(block_sizes[j]) - 1
|
||||
out.write('%s\tbed2gff\texon\t%d\t%d\t%s\t%s\t.\texon %s;\n' % (chrom, exon_start, exon_end, score, strand, group))
|
||||
except Exception:
|
||||
score = '0'
|
||||
try:
|
||||
strand = elems[5]
|
||||
except Exception:
|
||||
strand = '+'
|
||||
try:
|
||||
group = elems[3]
|
||||
except Exception:
|
||||
group = 'group%d' % (i + 1)
|
||||
if complete_bed:
|
||||
out.write('%s\tbed2gff\t%s\t%d\t%d\t%s\t%s\t.\t%s %s;\n' % (chrom, feature, start, end, score, strand, feature, group))
|
||||
else:
|
||||
out.write('%s\tbed2gff\t%s\t%d\t%d\t%s\t%s\t.\t%s;\n' % (chrom, feature, start, end, score, strand, group))
|
||||
if complete_bed:
|
||||
# We have all the info necessary to annotate exons for genes and mRNAs
|
||||
block_count = int(elems[9])
|
||||
block_sizes = elems[10].split(',')
|
||||
block_starts = elems[11].split(',')
|
||||
for j in range(block_count):
|
||||
exon_start = int(start) + int(block_starts[j])
|
||||
exon_end = exon_start + int(block_sizes[j]) - 1
|
||||
out.write('%s\tbed2gff\texon\t%d\t%d\t%s\t%s\t.\texon %s;\n' % (chrom, exon_start, exon_end, score, strand, group))
|
||||
except Exception:
|
||||
skipped_lines += 1
|
||||
if not first_skipped_line:
|
||||
first_skipped_line = i + 1
|
||||
else:
|
||||
skipped_lines += 1
|
||||
if not first_skipped_line:
|
||||
first_skipped_line = i + 1
|
||||
else:
|
||||
skipped_lines += 1
|
||||
if not first_skipped_line:
|
||||
first_skipped_line = i + 1
|
||||
out.close()
|
||||
info_msg = "%i lines converted to GFF version 2. " % (i + 1 - skipped_lines)
|
||||
if skipped_lines > 0:
|
||||
info_msg += "Skipped %d blank/comment/invalid lines starting with line #%d." % (skipped_lines, first_skipped_line)
|
||||
|
||||
Reference in New Issue
Block a user