blob: 57c0ed93427de5c8a6693a913257f95f9f56c63a (
plain)
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
|
#!/usr/bin/python
# coding=utf-8
#
# clean-stream.py
#
# Remove non-indexed frames from a stream
#
# Copyright © 2013 Fedor Chervinskii
#
# Authors:
# 2013 Fedor Chervinskii <fedor.chervinskii@gmail.com>
#
# This file is part of CrystFEL.
#
# CrystFEL is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# CrystFEL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CrystFEL. If not, see <http://www.gnu.org/licenses/>.
from __future__ import division
from itertools import islice
import sys
import re
infile_1 = open (sys.argv[1],'r')
infile_2 = open (sys.argv[1],'r')
outfile = open (sys.argv[2],'w')
Nfile = open ('N.dat','w')
suited = False
counter1 = -1
counter2 = 0
start_index = 0
n_patt = 0
num_peaks = 0
indexed = False
num_suited = 0
line = infile_1.readline()
reg0 = re.compile('----- Begin chunk')
reg1 = re.compile('----- End chunk')
reg6 = re.compile('^indexed_by')
reg7 = re.compile('none')
while (line != ''):
counter1 += 1
if (reg6.match(line)):
if reg7.search(line) :
indexed = False
else:
indexed = True
if (reg0.match(line)):
if (start_index == 0) :
while (counter2 < counter1) :
outline = infile_2.readline()
outfile.write(outline)
counter2 += 1
start_index = counter1
if (reg1.match(line)):
n_patt += 1
if indexed :
suited = True
if suited :
num_suited += 1
while (counter2 <= counter1) :
outline = infile_2.readline()
if suited :
outfile.write(outline)
counter2 += 1
suited = False
line = infile_1.readline()
print('%d suited of %d patterns have been extracted and saved as %s' % (num_suited, n_patt, sys.argv[2]))
Nfile.write('%d' % num_suited)
|