mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Merge pull request #11365 from bernt-matthias/ccedmendoza_patch-1
Make filter work with file containing header
This commit is contained in:
@@ -53,13 +53,15 @@ def gff_filter(gff_file, attribute_name, ids_file, output_file):
|
||||
ids_dict[line.split('\t')[0].strip()] = True
|
||||
|
||||
# Filter GFF file using ids.
|
||||
output = open(output_file, 'w')
|
||||
for line in open(gff_file):
|
||||
fields = line.split('\t')
|
||||
attributes = parse_gff_attributes(fields[8])
|
||||
if (attribute_name in attributes) and (attributes[attribute_name] in ids_dict):
|
||||
output.write(line)
|
||||
output.close()
|
||||
with open(output_file, 'w') as output, open(gff_file) as ingff:
|
||||
for line in ingff:
|
||||
if not line or line.startswith('#'):
|
||||
output.write(line)
|
||||
continue
|
||||
fields = line.split('\t')
|
||||
attributes = parse_gff_attributes(fields[8])
|
||||
if attribute_name in attributes and attributes[attribute_name] in ids_dict:
|
||||
output.write(line)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
<tool id="gtf_filter_by_attribute_values_list" name="Filter GTF data by attribute values_list" version="0.1">
|
||||
<tool id="gtf_filter_by_attribute_values_list" name="Filter GTF data by attribute values_list" version="0.2">
|
||||
<description></description>
|
||||
<command interpreter="python">
|
||||
gtf_filter_by_attribute_values_list.py $input $attribute_name $ids $output
|
||||
</command>
|
||||
<requirements>
|
||||
<requirement type="package" version="3.6">python</requirement>
|
||||
</requirements>
|
||||
<command><![CDATA[
|
||||
python '$__tool_directory__/gtf_filter_by_attribute_values_list.py' '$input' $attribute_name '$ids' '$output'
|
||||
]]></command>
|
||||
<inputs>
|
||||
<param format="gtf" name="input" type="data" label="Filter"/>
|
||||
<param name="attribute_name" type="select" label="Using attribute name">
|
||||
@@ -19,10 +22,10 @@
|
||||
<tests>
|
||||
<!-- Test filtering with a simple list of values. -->
|
||||
<test>
|
||||
<param name="input" value="gops_subtract_in1.gff"/>
|
||||
<param name="input" value="gops_subtract_in1_wcomment.gff"/>
|
||||
<param name="attribute_name" value="gene_id"/>
|
||||
<param name="ids" value="gtf_filter_by_attribute_values_list_in1.txt"/>
|
||||
<output name="output" file="gtf_filter_by_attribute_values_list_out1.gtf"/>
|
||||
<output name="output" file="gtf_filter_by_attribute_values_list_out1_wcomment.gtf"/>
|
||||
</test>
|
||||
<!-- Test filtering with a more complex tabular file. -->
|
||||
<test>
|
||||
|
||||
Reference in New Issue
Block a user