-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCurrito3.1_bars_statistics.py
138 lines (95 loc) · 5.29 KB
/
Currito3.1_bars_statistics.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import sys, getopt
def main(argv):
Input_Split_cluster_unclustered = ""
Input_Genome_8_Pre_statistics_output = ""
Input_Plasmid_2_First_filt_per_target = ""
Output_statistics_for_bars = ""
SeqID_index = 0
RowNumberWhereDataStarts = ""
TargetID_candidate = ""
try:
opts, args = getopt.getopt(argv,"i:j:k:l:m:o:",["Input_Split_cluster_unclustered=","Input_Genome_8_Pre_statistics_output=","Input_Plasmid_2_First_filt_per_target=", "RowNumberWhereDataStarts=", "TargetID_candidate=","Output_statistics_for_bars="])
except getopt.GetoptError:
print ('bars_statistics.py -i <Input_Split_cluster_unclustered> -j <Input_Genome_8_Pre_statistics_output> -k <Input_Plasmid_2_First_filt_per_target> -l <RowNumberWhereDataStarts> -m <TargetID_candidate> -o <Output_statistics_for_bars>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print ('bars_statistics.py -i <Input_Split_cluster_unclustered> -j <Input_Genome_8_Pre_statistics_output> -k <Input_Plasmid_2_First_filt_per_target> -l<RowNumberWhereDataStarts> -m <TargetID_candidate> -o <Output_statistics_for_bars>')
sys.exit()
elif opt in ("-i", "--Input_Split_cluster_unclustered"):
Input_Split_cluster_unclustered = arg
elif opt in ("-j", "--Input_Genome_8_Pre_statistics_output"):
Input_Genome_8_Pre_statistics_output = arg
elif opt in ("-k", "--Input_Plasmid_2_First_filt_per_target"):
Input_Plasmid_2_First_filt_per_target = arg
elif opt in ("-l", "--RowNumberWhereDataStarts"):
RowNumberWhereDataStarts = arg
elif opt in ("-m", "--TargetID_candidate"):
TargetID_candidate = arg
elif opt in ("-o", "--Output_statistics_for_bars"):
Output_statistics_for_bars = arg
print ('Input file is :"', Input_Split_cluster_unclustered)
print ('Input file is : "', Input_Genome_8_Pre_statistics_output)
print ('Input file is : "', Input_Plasmid_2_First_filt_per_target)
print ('Output file is :"', Output_statistics_for_bars)
InputTotalSequences = open(Input_Split_cluster_unclustered)
InputSeqsWITH_hits = open(Input_Genome_8_Pre_statistics_output)
InputPLASMID_hits = open(Input_Plasmid_2_First_filt_per_target)
OutputFile = open(Output_statistics_for_bars, 'w')
BLAST_INDEXES_FROM_Split_cluster_unclustered = set()
BLAST_INDEXES_FROM_Genome_8_Pre_statistics_output = set()
BLAST_INDEXES_FROM_Plasmid_2_First_filt_per_target = set()
Total_number_of_sequences = 0
Number_of_sequences_hiting_Genome = 0
Number_of_sequences_hiting_PLASMID_not_GENOME = 0
Number_of_sequencesWithoutHits = 0
for i in range(0, int(RowNumberWhereDataStarts)):
HeaderTemp = InputTotalSequences.readline()
tempstring = "temp"
while tempstring:
tempstring = InputTotalSequences.readline()
if tempstring == "":
break
templine = tempstring.splitlines()
x = templine[0]
rowlist = x.split(",")
SeqID = rowlist[SeqID_index]
BLAST_INDEXES_FROM_Split_cluster_unclustered.add(SeqID)
Total_number_of_sequences = len(BLAST_INDEXES_FROM_Split_cluster_unclustered)
tempstring = InputSeqsWITH_hits.readline()
tempstring = "temp"
while tempstring:
tempstring = InputSeqsWITH_hits.readline()
if tempstring == "":
break
templine = tempstring.splitlines()
x = templine[0]
rowlist = x.split("\t")
SeqID = rowlist[SeqID_index]
BLAST_INDEXES_FROM_Genome_8_Pre_statistics_output.add(SeqID)
Number_of_sequences_hiting_Genome = len(BLAST_INDEXES_FROM_Genome_8_Pre_statistics_output)
tempstring = InputPLASMID_hits.readline()
tempstring = "temp"
while tempstring:
tempstring = InputPLASMID_hits.readline()
if tempstring == "":
break
templine = tempstring.splitlines()
x = templine[0]
rowlist = x.split("\t")
SeqID = rowlist[SeqID_index]
BLAST_INDEXES_FROM_Plasmid_2_First_filt_per_target.add(SeqID)
BLAST_INDEXES_Plasmid_WITHOUT_BLAST_INDEXES_Genome = BLAST_INDEXES_FROM_Plasmid_2_First_filt_per_target.difference(BLAST_INDEXES_FROM_Genome_8_Pre_statistics_output)
Number_of_sequences_hiting_PLASMID_not_GENOME = len(BLAST_INDEXES_Plasmid_WITHOUT_BLAST_INDEXES_Genome)
Number_of_sequencesWithoutHits = Total_number_of_sequences - (Number_of_sequences_hiting_Genome + Number_of_sequences_hiting_PLASMID_not_GENOME)
AllHeaders = "TargetID" + "\t" + "TotalSequences" + "\t" + "SequencesWithHitsToAReference" + "\t" + "SequencesWithHitsToAPlasmid" + "\t" + "SequencesWithoutHitsToAReference" + "\n"
OutputFile.write(AllHeaders)
Data = (TargetID_candidate + "\t" + str(Total_number_of_sequences) + "\t" + str(Number_of_sequences_hiting_Genome) + "\t" +
str(Number_of_sequences_hiting_PLASMID_not_GENOME) + "\t" + str(Number_of_sequencesWithoutHits) + "\n")
OutputFile.write(Data)
InputTotalSequences.close()
InputSeqsWITH_hits.close()
InputPLASMID_hits.close()
OutputFile.close()
if __name__ == "__main__":
main(sys.argv[1:])