annotate DiffExpAnal/loadMultiFastqFiles.py @ 3:a07e588f245a draft

Uploaded
author yufei-luo
date Tue, 22 Jan 2013 10:37:04 -0500
parents 63799b789162
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
1 #!/usr/bin/env python
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
2
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
3 """
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
4 Yufei LUO
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
5 """
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
6
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
7
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
8
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
9 import optparse, sys
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
10
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
11
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
12 def __main__():
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
13 #Parse Command Line
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
14 parser = optparse.OptionParser()
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
15 parser.add_option('-i', '--inputs', dest='inputFiles', default=None, help='several input files. (seperated by @ or @@' )
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
16 parser.add_option( '-o', '--output', dest='outputSingleFile', default=None, help='The output list of fastq files on txt format.' )
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
17 parser.add_option( '', '--pairedEnd', dest='outputPaireFile', default=None, help='paired end option help to upload the corresponding paired end complementary fastq files' )
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
18 ( options, args ) = parser.parse_args()
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
19
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
20
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
21
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
22 if options.outputSingleFile == None:
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
23 raise Exception, 'OutSingleFile txt file name is not defined!'
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
24 else:
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
25 outSingle = open(options.outputSingleFile, 'w')
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
26
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
27 if options.inputFiles == None:
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
28 raise Exception, 'input file name is not defined!'
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
29
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
30 groupCount = 1
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
31 fileCount = 0
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
32
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
33 if options.outputPaireFile == None:
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
34 inputFiles = sys.argv[4:]
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
35 i = 0
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
36 while i < (len(inputFiles)-1):
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
37 if inputFiles[i] == "@":
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
38 i += 1
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
39 fileCount = 1
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
40 groupCount += 1
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
41 outSingle.write("Group%s_%s\t%s\n" % (groupCount, fileCount, inputFiles[i]))
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
42
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
43 else:
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
44 fileCount += 1
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
45 outSingle.write("Group%s_%s\t%s\n" % (groupCount, fileCount, inputFiles[i]))
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
46
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
47 i += 1
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
48 else:
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
49 inputFiles = sys.argv[6:]
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
50 print '\n\nthe length of inputfiles is : %s \n' % len(inputFiles)
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
51 outPaire = open(options.outputPaireFile, 'w')
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
52 i = 0
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
53 while i < (len(inputFiles)-1):
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
54 if inputFiles[i] == "@@":
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
55 i += 1
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
56 outPaire.write("Group%s_%s\t%s\n" % (groupCount, fileCount, inputFiles[i]))
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
57 elif inputFiles[i] == "@":
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
58 i += 1
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
59 fileCount = 1
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
60 groupCount += 1
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
61 outSingle.write("Group%s_%s\t%s\n" % (groupCount, fileCount, inputFiles[i]))
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
62 else:
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
63 fileCount += 1
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
64 outSingle.write("Group%s_%s\t%s\n" % (groupCount, fileCount, inputFiles[i]))
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
65
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
66 i += 1
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
67
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
68
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
69
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
70 outPaire.close()
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
71
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
72 outSingle.close()
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
73
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
74
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
75
63799b789162 Uploaded
yufei-luo
parents:
diff changeset
76 if __name__=="__main__": __main__()