Functions | Variables
python.stream Namespace Reference

Functions

def get_stream (inputfile)
 

Variables

 stream = get_stream(str(sys.argv[1]))
 

Function Documentation

def python.stream.get_stream (   inputfile)

Definition at line 27 of file stream.py.

27 def get_stream(inputfile):
28 
29  result = ''
30 
31  # Extract sam metadata in form of json string.
32 
33  jobinfo = subprocess.Popen(['sam_metadata_dumper', inputfile],
34  stdout=subprocess.PIPE,
35  stderr=subprocess.PIPE)
36  jobout, joberr = jobinfo.communicate()
37  jobout = convert_str(jobout)
38  joberr = convert_str(joberr)
39  rc = jobinfo.poll()
40  if rc != 0:
41  raise RuntimeError('sam_metadata_dumper failed with status %d' % rc)
42 
43  # Decode json string to dictionary.
44  # Work around art bug by deleting "runs" line.
45 
46  json_str = ''
47  n = jobout.find('"runs"')
48  if n >= 0:
49  m = jobout.rfind('\n', 0, n)
50  if m > 0:
51  json_str = jobout[:m+1]
52  k = jobout.find('\n', n)
53  if k > n:
54  json_str += jobout[k+1:]
55  else:
56  json_str = jobout
57 
58  # End of workaround.
59 
60  js = json.loads(json_str)
61  md = js[inputfile]
62 
63  # Extract stream from json dictionary.
64 
65  if 'data_stream' in md:
66  result = md['data_stream']
67  else:
68  raise RuntimeError('Sam metadata does not contain stream.')
69 
70  # Done.
71 
72  return result
73 
74 # Main program.
75 
def get_stream(inputfile)
Definition: stream.py:27

Variable Documentation

python.stream.stream = get_stream(str(sys.argv[1]))

Definition at line 77 of file stream.py.