Mercurial > repos > yating-l > rename_scaffolds
changeset 1:0d13e4410c3d draft
planemo upload commit 68b7e251486853b77396932b588c20f389c366d2
| author | yating-l |
|---|---|
| date | Mon, 18 Jun 2018 18:36:00 -0400 |
| parents | 65c9ce351343 |
| children | 8fdd3e06e1ec |
| files | rename.py rename_scaffold.iml rename_scaffold.xml test-data/Dbia3_index.csv test-data/Dbia3_index.fa |
| diffstat | 5 files changed, 91 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/rename.py Fri Jan 20 17:06:52 2017 -0500 +++ b/rename.py Mon Jun 18 18:36:00 2018 -0400 @@ -2,9 +2,10 @@ Call rename to rename scaffolds in reference genome so that the sequence names are less than 31 characters. Rename all scaffolds to scaffold_1, scaffold_2, ..., scaffold_N and provide a name mapping file """ import sys +import csv from collections import OrderedDict -def rename(inputfile, outputfile, indexfile): +def rename(inputfile, outputfile, writer): namemap = OrderedDict() with open(outputfile, 'w') as out: with open(inputfile, 'r') as rf: @@ -16,21 +17,19 @@ newname = "scaffold_" + str(i) line = ">" + newname i = i+1 - namemap[oldname] = newname + writer.writerow([oldname, newname]) #TODO: Add line breaks to chromosome sequences that are in a single line - #else: - #if (len(line) > 50): - #for out.write(line.rstrip() + "\n") - with open(indexfile, 'w') as index: - for k in namemap: - index.write(k + "\t" + namemap[k] + "\n") def main(): inputfile = str(sys.argv[1]) outputfile = str(sys.argv[2]) indexfile = str(sys.argv[3]) - rename(inputfile, outputfile, indexfile) + csvfile = open(indexfile, 'w') + fieldnames = ['Original sequence name', 'Renamed sequence name'] + writer = csv.writer(csvfile) + writer.writerow(fieldnames) + rename(inputfile, outputfile, writer) if __name__ == "__main__": main()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rename_scaffold.iml Mon Jun 18 18:36:00 2018 -0400 @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="PYTHON_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$" /> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> \ No newline at end of file
--- a/rename_scaffold.xml Fri Jan 20 17:06:52 2017 -0500 +++ b/rename_scaffold.xml Mon Jun 18 18:36:00 2018 -0400 @@ -1,4 +1,4 @@ -<tool id="rename_scaffold" name="rename the scaffolds" version="0.1.0"> +<tool id="rename_scaffold" name="rename the scaffolds" version="1.1"> <description>Rename the scaffolds so that they won't exceed 31 characters</description> <stdio> <exit_code range="1:" /> @@ -11,14 +11,14 @@ </inputs> <outputs> <data name="output" format="fasta" label="${tool.name} on ${on_string}: renamed_reference" /> - <data name="index" format="fasta" label="${tool.name} on ${on_string}: name mapping"/> + <data name="index" format="csv" label="${tool.name} on ${on_string}: name mapping"/> </outputs> <tests> <test> <!-- Test with Dbia3.fa --> <param name="input" value="Dbia3.fa" /> <output name="output" file="Dbia3_renamed.fa"/> - <output name="index" file="Dbia3_index.fa"/> + <output name="index" file="Dbia3_index.csv"/> </test> </tests> <help><