Commit ae37a2b8 authored by Celine Noirot's avatar Celine Noirot
Browse files

Debug _main_

parent 87d89442
......@@ -15,6 +15,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from optparse import *
import sys,re,datetime
from os.path import join, splitext, basename, exists, split
__author__ = 'Plateforme bioinformatique Midi Pyrenees'
__copyright__ = 'Copyright (C) 2009 INRA'
__license__ = 'GNU General Public License'
......@@ -28,10 +32,6 @@ __authors__ = "Celine Noirot"
__keywords__ = "Count matrix, join columns, merge files"
__description__ = "Merge (join) files columns on first column, skip lines starting with #"
from optparse import *
import sys,re,datetime
from os.path import join, splitext, basename, exists, split
def read_file (file,libname,dict_col, col_number=1):
"""
Extract count from the count file
......@@ -64,72 +64,72 @@ def version_string ():
return "merge_count.py " + __version__
if __name__ == '__main__':
parser = OptionParser(usage="Usage: %prog", description = "Merge files columns on first column, skip lines starting with #")
igroup = OptionGroup(parser, "Input options","")
igroup.add_option("-f", "--files", dest="files", help="tabulated files separated by ',' ")
igroup.add_option("-n", "--names", dest="names", help="matrix columns names in the same order as files ',' ")
igroup.add_option("-c", "--column", dest="col_number", help="column of each files to extract, first column is 0, default 1", default=1, metavar="INT")
parser.add_option_group(igroup)
ogroup = OptionGroup(parser, "Output files options","")
ogroup.add_option("-o", "--output", dest="output", help="the output count file")
parser.add_option_group(ogroup)
parser = OptionParser(usage="Usage: %prog", description = "Merge files columns on first column, skip lines starting with #")
igroup = OptionGroup(parser, "Input options","")
igroup.add_option("-f", "--files", dest="files", help="tabulated files separated by ',' ")
igroup.add_option("-n", "--names", dest="names", help="matrix columns names in the same order as files ',' ")
igroup.add_option("-c", "--column", dest="col_number", help="column of each files to extract, first column is 0, default 1", default=1, metavar="INT")
parser.add_option_group(igroup)
ogroup = OptionGroup(parser, "Output files options","")
ogroup.add_option("-o", "--output", dest="output", help="the output count file")
parser.add_option_group(ogroup)
(options, args) = parser.parse_args()
if options.files == None :
sys.stderr.write("Need files to merge\n")
parser.print_help()
sys.exit(1)
if options.col_number < 1 :
sys.stderr.write("Column must be greater than 0 \n")
parser.print_help()
sys.exit(1)
(options, args) = parser.parse_args()
if options.output == None:
sys.stderr.write("Output file is missing\n")
parser.print_help()
sys.exit(1)
if options.files == None :
sys.stderr.write("Need files to merge\n")
parser.print_help()
sys.exit(1)
dict_col={}
files = options.files.split(",")
libs_name = []
get_lib_name = True
if options.names :
libs_name=options.names.split(",")
get_lib_name = False
if len(libs_name) != len(files):
sys.stderr.write("You must provide same number of files and names\n")
parser.print_help()
sys.exit(1)
if options.col_number < 1 :
sys.stderr.write("Column must be greater than 0 \n")
parser.print_help()
current_libname=""
for idx, line in enumerate(files):
file = line.rstrip()
if exists(file) :
if get_lib_name :
current_libname = splitext(basename(file))[0]
libs_name.append(current_libname)
else :
current_libname = libs_name[idx]
read_file(file,current_libname,dict_col,options.col_number)
else :
sys.stderr.write("File : " + file + " doesn't exist")
sys.exit(1)
if options.output == None:
sys.stderr.write("Output file is missing\n")
parser.print_help()
sys.exit(1)
dict_col={}
files = options.files.split(",")
libs_name = []
get_lib_name = True
if options.names :
libs_name=options.names.split(",")
get_lib_name = False
if len(libs_name) != len(files):
sys.stderr.write("You must provide same number of files and names\n")
parser.print_help()
sys.exit(1)
current_libname=""
for idx, line in enumerate(files):
file = line.rstrip()
if exists(file) :
if get_lib_name :
current_libname = splitext(basename(file))[0]
libs_name.append(current_libname)
else :
current_libname = libs_name[idx]
read_file(file,current_libname,dict_col,options.col_number)
else :
sys.stderr.write("File : " + file + " doesn't exist")
sys.exit(1)
fout = open (options.output,"w")
fout.write ( '#contig_name\t' + '\t'.join(libs_name) +"\n")
# Pour tous les contigs : contruction de la ligne
for contig_name in sorted(dict_col.keys()) :
line = []
line.append( contig_name )
# Pour toutes les contigs
for lib in libs_name :
line.append( str(dict_col[contig_name][lib]) )
fout.write ( '\t'.join(line) +"\n")
fout.close
sys.exit(0)
fout = open (options.output,"w")
fout.write ( '#contig_name\t' + '\t'.join(libs_name) +"\n")
# Pour tous les contigs : contruction de la ligne
for contig_name in sorted(dict_col.keys()) :
line = []
line.append( contig_name )
# Pour toutes les contigs
for lib in libs_name :
line.append( str(dict_col[contig_name][lib]) )
fout.write ( '\t'.join(line) +"\n")
fout.close
sys.exit(0)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment