From 4c6d8476289db24e9b9458f4e0534d7315b172a7 Mon Sep 17 00:00:00 2001
From: Blaise Li <blaise.li__git@nsup.org>
Date: Tue, 19 Dec 2017 15:48:19 +0100
Subject: [PATCH] Added dependency of RNA-seq pipeline.

This is a python3 version of a script converting wormbase identifiers to
names.
---
 RNA_Seq_Cecere/id2name.py | 42 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100755 RNA_Seq_Cecere/id2name.py

diff --git a/RNA_Seq_Cecere/id2name.py b/RNA_Seq_Cecere/id2name.py
new file mode 100755
index 0000000..24a301a
--- /dev/null
+++ b/RNA_Seq_Cecere/id2name.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+# vim: set fileencoding=<utf-8> :
+"""This script parses tab-separated input and converts the fields using the
+dictionary contained in the pickle file provided as first argument.
+Input is taken in the file given as second argument or in stdin."""
+
+from sys import argv, stdin, stdout
+# To store dictionaries
+from pickle import load
+
+
+def strip_split(text):
+    return text.strip().split("\t")
+
+
+input_filename = None
+if len(argv) == 2:
+    pickle_filename = argv[1]
+elif len(argv) == 3:
+    pickle_filename = argv[1]
+    input_filename = argv[2]
+elif len(argv) == 1:
+    pickle_filename = "/pasteur/entites/Mhe/Genomes/C_elegans/Caenorhabditis_elegans/Ensembl/WBcel235/Annotation/Genes/genes_id2name.pickle"
+else:
+    exit(__doc__)
+
+with open(pickle_filename, "rb") as pickle_file:
+    id2name = load(pickle_file)
+
+if input_filename is None or input_filename == "-":
+    input_source = stdin
+else:
+    input_source = open(input_filename, "r")
+
+for fields in map(strip_split, input_source):
+    print(*[id2name.get(field, field) for field in fields], sep="\t", file=stdout)
+
+if input_filename is not None:
+    input_source.close()
+
+
+exit(0)
-- 
GitLab