Skip to content

Commit

Permalink
streamline fimo output
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonHafner committed Dec 18, 2024
1 parent 18d0cfe commit 45ba08d
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions modules/local/fimo/combine_results/templates/combine_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,24 @@ def format_yaml_like(data: dict, indent: int = 0) -> str:

output_dirs = [os.path.join('fimo', d) for d in os.listdir('fimo') if os.path.isdir(os.path.join('fimo', d))]

tsvs = []
gffs = []
for output in output_dirs:
with open(f'{output}/fimo.tsv', 'r') as f:
tsv = f.read().split('\\n')
with open(f'{output}/fimo.gff', 'r') as f:
gff = f.read().split('\\n')

tsvs.extend(tsv)
gffs.extend(gff)

tsvs = [line for line in tsvs if not line.startswith('#') and not line.startswith('motif_id') and not line == '']
gffs = [line for line in gffs if not line.startswith('#') and not line == '']

tsvs = ['motif_id\\tmotif_alt_id\\tsequence_name\\tstart\\tstop\\tstrand\\tscore\\tp-value\\tq-value\\tmatched_sequence'] + tsvs

with open('${meta.id}.tsv', 'w') as f:
f.write('\\n'.join(tsvs))

with open('${meta.id}.gff', 'w') as f:
f.write('\\n'.join(gffs))

output_tsv = "${meta.id}.tsv"
output_gff = "${meta.id}.gff"

with open(output_tsv, 'w') as tsv_out, open(output_gff, 'w') as gff_out:
tsv_out.write('motif_id\\tmotif_alt_id\\tsequence_name\\tstart\\tstop\\tstrand\\tscore\\tp-value\\tq-value\\tmatched_sequence\\n')

for output in output_dirs:
with open(f"{output}/fimo.tsv", "r") as f:
for line in f:
line = line.strip()
if line and not line.startswith('#') and not line.startswith('motif_id'):
tsv_out.write(line + "\\n")

with open(f"{output}/fimo.gff", "r") as f:
for line in f:
line = line.strip()
if line and not line.startswith('#'):
gff_out.write(line + "\\n")

# Create version file
versions = {
Expand Down

0 comments on commit 45ba08d

Please sign in to comment.