find_cnv_DE.py 1.08 KB
Newer Older
Marine Bergot's avatar
Marine Bergot committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#! /usr/bin/env python3
# -*- coding: utf-8 -*-


#Attention : pour que ça fonctionne, il faut : sed -i 's/"//g' outrider.tsv
import sys 
import csv


lines = [line.rstrip() for line in open(sys.argv[1])]
header = lines[0].split()
print(header)
liste_dijarn = lines[0].split()[1:]
matrice_count = {l.split()[0]: l.split()[1:] for l in lines[1:]}
outrider_file = [line.rstrip() for line in open(sys.argv[2])]
outrider_file = outrider_file[1:]

#comparaison des listes de gènes outrider vs matrix.all.counts

key_matrix = matrice_count.keys()
keys_outrider = set()
for line in outrider_file:
	gene = line.split()[1]
	keys_outrider.add(gene)
	dijarn = line.split()[2]
	position = liste_dijarn.index(dijarn)
	count_norm = line.split()[8]
	matrice_count[gene][position] = count_norm

to_remove = list(set(key_matrix) - set(keys_outrider))

for key in to_remove:
	del matrice_count[key]

		
with open(sys.argv[3], "w" , newline='') as output_file:
	writer = csv.writer(output_file, delimiter='\t')
	writer.writerow(header)
	for i in matrice_count:
		to_write =[i]+ matrice_count[i]
		writer.writerow(to_write)