mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-01 15:37:32 +08:00
Adding new tool "Extract features from GFF file" under Fetch Sequences and Alignments section.
Have not been able to get this tool to pass functional test as test support with the new conditional constructs is yet to be worked out.
This commit is contained in:
@@ -81,7 +81,9 @@
|
||||
<tool file="filters/maf/maf_limit_to_species.xml"/>
|
||||
<tool file="filters/maf/maf_limit_size.xml"/>
|
||||
<tool file="filters/maf/maf_by_block_number.xml"/>
|
||||
<tool file="extract/extract_GFF_Features.xml" />
|
||||
</section>
|
||||
|
||||
<section name="Get Genomic Scores" id="scores">
|
||||
<tool file="stats/wiggle_to_simple.xml" />
|
||||
<tool file="stats/aggregate_binned_scores_in_intervals.xml" />
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python2.4
|
||||
|
||||
"""
|
||||
Extract features from GFF file.
|
||||
|
||||
usage: %prog input1 out_file1 column features out_format
|
||||
"""
|
||||
|
||||
import sys, os
|
||||
import cookbook.doc_optparse
|
||||
|
||||
def main():
|
||||
# Parsing Command Line here
|
||||
options, args = cookbook.doc_optparse.parse( __doc__ )
|
||||
|
||||
try:
|
||||
inp_file, out_file, column, features = args
|
||||
column = int(column)
|
||||
except:
|
||||
cookbook.doc_optparse.exception()
|
||||
|
||||
if features == None:
|
||||
print "Column %d has no features to display. Please select another column." %(column+1)
|
||||
sys.exit()
|
||||
|
||||
try:
|
||||
fo=open(out_file,'w')
|
||||
for line in open(inp_file):
|
||||
if line[0] == '#' or not(line) or line == "":
|
||||
print >>fo, line.strip()
|
||||
continue
|
||||
try:
|
||||
if line.split('\t')[column] in features.split(','):
|
||||
print >>fo, line.strip()
|
||||
except:
|
||||
pass
|
||||
fo.close()
|
||||
except Exception, exc:
|
||||
print >> sys.stderr, exc
|
||||
|
||||
print 'Field = Column %d and Features = %s' %(column+1, features)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,96 @@
|
||||
<tool id="Extract_features1" name="Extract features">
|
||||
<description> from GFF file</description>
|
||||
<command interpreter="python2.4">
|
||||
extract_GFF_Features.py $input1 $out_file1 ${column_choice.col} ${column_choice.feature}
|
||||
</command>
|
||||
<inputs>
|
||||
<page>
|
||||
<param format="gff" name="input1" type="data" label="Select a GFF file"/>
|
||||
</page>
|
||||
<page>
|
||||
<conditional name="column_choice">
|
||||
<param name="col" type="select" label="Select a field">
|
||||
<option value="0" selected="true">Column 1 / Sequence name</option>
|
||||
<option value="1">Column 2 / Source</option>
|
||||
<option value="2">Column 3 / Feature</option>
|
||||
<option value="6">Column 7 / Strand</option>
|
||||
<option value="7">Column 8 / Frame</option>
|
||||
</param>
|
||||
<when value="0">
|
||||
<param name="feature" label="Select Features" type="select" multiple="true" dynamic_options="get_features( input1, 0 )"/>
|
||||
</when>
|
||||
<when value="1">
|
||||
<param name="feature" label="Select Features" type="select" multiple="true" dynamic_options="get_features( input1, 1 )"/>
|
||||
</when>
|
||||
<when value="2">
|
||||
<param name="feature" label="Select Features" type="select" multiple="true" dynamic_options="get_features( input1, 2 )"/>
|
||||
</when>
|
||||
<when value="6">
|
||||
<param name="feature" label="Select Features" type="select" multiple="true" dynamic_options="get_features( input1, 6 )"/>
|
||||
</when>
|
||||
<when value="7">
|
||||
<param name="feature" label="Select Features" type="select" multiple="true" dynamic_options="get_features( input1, 7 )"/>
|
||||
</when>
|
||||
</conditional>
|
||||
<!--
|
||||
<param name="out_format" type="select" label="Output format">
|
||||
<option value="GFF" selected="true">GFF</option>
|
||||
<option value="BED">BED</option>
|
||||
</param>
|
||||
-->
|
||||
</page>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<data format="gff" name="out_file1" />
|
||||
</outputs>
|
||||
<!--
|
||||
<tests>
|
||||
<test>
|
||||
<param name="input1" value="5.gff"/>
|
||||
<param name="column_choice|col" value="0" />
|
||||
<param name="column_choice|feature" value="chr5,chr6,chr7,chr8" />
|
||||
<output name="out_file1" file="gff_features.gff"/>
|
||||
</test>
|
||||
</tests>
|
||||
-->
|
||||
<help>
|
||||
|
||||
.. class:: infomark
|
||||
|
||||
**Info:** This tool extracts selected features from the input GFF file into an output GFF file. To convert the output GFF file to BED format, please use *GFF-to-BED converter* under *Convert Formats* section.
|
||||
|
||||
----
|
||||
|
||||
**Syntax**
|
||||
|
||||
- **GFF format** General Feature Format is a format for describing genes and other features associated with DNA, RNA and Protein sequences. GFF lines have nine tab-separated fields::
|
||||
|
||||
1. seqname - Must be a chromosome or scaffold.
|
||||
2. source - The program that generated this feature.
|
||||
3. feature - The name of this type of feature. Some examples of standard feature types are "CDS", "start_codon", "stop_codon", and "exon".
|
||||
4. start - The starting position of the feature in the sequence. The first base is numbered 1.
|
||||
5. end - The ending position of the feature (inclusive).
|
||||
6. score - A score between 0 and 1000. If there is no score value, enter ".".
|
||||
7. strand - Valid entries include '+', '-', or '.' (for don't know/care).
|
||||
8. frame - If the feature is a coding exon, frame should be a number between 0-2 that represents the reading frame of the first base. If the feature is not a coding exon, the value should be '.'.
|
||||
9. group - All lines with the same group are linked together into a single item.
|
||||
|
||||
-----
|
||||
|
||||
**Example**
|
||||
|
||||
- Input GFF file::
|
||||
|
||||
chr22 TeleGene enhancer 10000000 10001000 500 + . TG1
|
||||
chr22 TeleGene promoter 10010000 10010100 900 + . TG1
|
||||
chr22 TeleGene promoter 10020000 10025000 400 - . TG2
|
||||
chr22 TeleGene CCDS2220 10030000 10065000 800 - . TG2
|
||||
|
||||
- Running this tool on the above input by choosing field as *Column 3 / Feature* and feature as *promoter* will produce the following output::
|
||||
|
||||
chr22 TeleGene promoter 10010000 10010100 900 + . TG1
|
||||
chr22 TeleGene promoter 10020000 10025000 400 - . TG2
|
||||
|
||||
</help>
|
||||
<code file="extract_GFF_Features_code.py"/>
|
||||
</tool>
|
||||
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python2.4
|
||||
|
||||
import os, sys, tempfile
|
||||
|
||||
def get_unique_elems(elems):
|
||||
#return list(set(elems))
|
||||
seen = set()
|
||||
return [x for x in elems if x not in seen and not seen.add(x)]
|
||||
|
||||
#return available unique entries from the specified column of the input data
|
||||
def get_features( data, index ):
|
||||
elem_list = []
|
||||
unique_list = []
|
||||
datafile = "./database/files/dataset_" + str(data.id) + ".dat"
|
||||
try:
|
||||
finp = open(datafile, "r")
|
||||
except:
|
||||
return [("Input datafile doesn't exist",'None',True)]
|
||||
try:
|
||||
for line in finp:
|
||||
line = line.rstrip("\r\n")
|
||||
if not(line) or line == "" or line[0:1] == '#':
|
||||
continue
|
||||
elems = line.split('\t')
|
||||
elem_list.append(elems[index])
|
||||
except:
|
||||
pass
|
||||
finp.close()
|
||||
if not(elem_list):
|
||||
return[('No elements to display. Please choose another column','None',True)]
|
||||
try:
|
||||
for ind, elem in enumerate(get_unique_elems(elem_list)):
|
||||
if ind == 0:
|
||||
unique_list.append((elem,elem,True))
|
||||
else:
|
||||
unique_list.append((elem,elem,False))
|
||||
return unique_list
|
||||
except:
|
||||
pass
|
||||
"""
|
||||
if len(unique_list) == 1:
|
||||
return[('Column has only one feature. Please choose another column','None',True)]
|
||||
|
||||
if len(unique_list) > 10:
|
||||
return [('Too many elements to display.Choose another column with at most 10 entries','None',True)]
|
||||
"""
|
||||
|
||||
|
||||
def get_length( feature ):
|
||||
return len(feature)
|
||||
Reference in New Issue
Block a user