forked from holtzy/Bioinformatics-Tool-Box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_some_sequences_in_fasta.py
executable file
·82 lines (50 loc) · 1.85 KB
/
delete_some_sequences_in_fasta.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/python
# -*- coding: utf-8 -*-
#-------------------------------------
#
# SCRIPT PYTHON Delete_Some_sequences_in_fasta
# Take a Fasta OR ALR file and delete chosen sequences that are present in a given list
# Yan Holtz, [email protected]
#-------------------------------------
import os
import sys
import re
try:
import argparse
except ImportError:
print"oops, the import /argparse/ didn't work"
parser = argparse.ArgumentParser(description= '\n\nTake a Fasta OR ALR file and delete sequences that are present several times\n\n')
parser.add_argument('-fic', required=True, help=' Input : ALR or FASTA file ')
parser.add_argument('-list', required=True, help=' list of sequence to delete')
parser.add_argument('-out', required=True, help=' Output')
args = parser.parse_args()
fic=args.fic
list=args.list
output=args.out
#------------------------------------------------------------------------------------------------------
# DICTIONNAIRY OF SEQUENCES TO DELETE
dico_to_del=dict()
for line in open(list):
line=line.strip()
line=line.replace(">","")
dico_to_del[line]="deleteme"
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
#LECTURE DU FASTA
tmp=open(output,"w")
toprint="no"
for line in open(fic):
line=line.strip()
if line.startswith(">"):
line=line.replace(">","")
if line not in dico_to_del :
toprint="yes"
tmp.write(">"+line+"\n")
else:
toprint="no"
else:
if toprint=="yes" :
tmp.write(line+"\n")
tmp.close
print "\n\nOk, c'est gagné, les contigs ont été récupérés et les contigs indiqués ont été supprimés !! \n\n"
#------------------------------------------------------------------------------------------------------