annotate cut_fr.py @ 2:d28ee835a561 draft default tip

Uploaded
author r-lannes
date Wed, 16 Dec 2015 08:46:37 -0500
parents 93f267c26057
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
1 #!usr/bin/pyhton3
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
2 '''<cut_fr.py is script allwing more convenient use of cut in galaxy environment>
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
3 Copyright (C) <2015> <Lannes Romain>
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
4
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
7 the Free Software Foundation, either version 3 of the License, or
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
8 (at your option) any later version.
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
9
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
13 GNU General Public License for more details.
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
14
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>.'''
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
17
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
18 #-------- import
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
19 import os
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
20 import argparse
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
21 import sys
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
22
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
23 #------- argument
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
24 parser = argparse.ArgumentParser(description = "renvoie le fichier inputs moins les collones sellectionner")
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
25 parser.add_argument('--c', help = "collumn to be removed" )
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
26 parser.add_argument('--i', help = "input datasets" )
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
27 parser.add_argument('--type_cut', help = "type of cut" )
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
28 parser.add_argument('--extend_print', help = "add sdtrout print" )
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
29 parser.add_argument('--o', help = "output datasets" )
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
30
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
31 args = parser.parse_args()
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
32
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
33
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
34 if(args.type_cut == "exclude"):
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
35 #------- First step count number of column
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
36 dataset_initial = open(args.i,'r')
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
37 firstline_dataset = dataset_initial.readline()
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
38
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
39 column_header = firstline_dataset.split('\t')
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
40 number_column = len(column_header)
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
41
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
42 # Collumn are in foramt c1,c2,c3
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
43 # need to get them
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
44 column_list = args.c
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
45 column_list = column_list.split(',')
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
46
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
47 # remove the letter c
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
48 # there is certainly a more convenient way to do it
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
49 for i in range(len(column_list)):
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
50 column_list[i] = int(column_list[i][-1])
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
51
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
52 # Second Step prepare the command to be printed
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
53 str_argument = "-f"
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
54 for i in range( 1,number_column +1 ,1 ):
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
55 if i not in column_list:
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
56 str_argument = str_argument + str(i) + ','
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
57 str_argument = str_argument.strip(',')
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
58
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
59 # Create the command to be launch
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
60 str_cut = "cut " + str_argument + " " + args.i +" >"+ args.o
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
61
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
62 if(args.type_cut == "include"):
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
63 # Collumn are in foramt c1,c2,c3
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
64 # need to get them
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
65 column_list = args.c
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
66 column_list = column_list.split(',')
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
67 # remove the letter c
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
68 # there is certainly a more convenient way to do it
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
69 for i in range(len(column_list)):
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
70 column_list[i] = int(column_list[i][-1])
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
71 # Second Step prepare the command to be printed
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
72 str_argument = "-f"
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
73 for indice in column_list :
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
74 str_argument = str_argument + str(indice) + ','
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
75 str_argument = str_argument.strip(',')
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
76 # Create the command to be launch
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
77 str_cut = "cut " + str_argument + " " + args.i +" >"+ args.o
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
78
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
79 # launch the command
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
80 result = os.system( str_cut )
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
81 if (args.extend_print == "True"):
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
82 sys.stdout.write("input dataset : " + args.i + '\n')
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
83 sys.stdout.write("column selected : " + args.c + '\n')
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
84 sys.stdout.write("cut_type : " + args.type_cut+'\n')
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
85 sys.stdout.write("output dataset : " + args.o+'\n')
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
86 sys.stdout.write("command launch : " + str_cut+'\n' )
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
87
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
88
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
89
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
90
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
91
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
92
93f267c26057 Uploaded
r-lannes
parents:
diff changeset
93