from GamTools import corr
import numpy as np
import argparse

parser = argparse.ArgumentParser(description='Calculate coverage over different window sizes for a list of bam files.')
parser.add_argument('npz_frequencies_file', help='An npz file containing co-segregation frequencies to convert to correlations')

args = parser.parse_args()

correlation_file = args.npz_frequencies_file.split('.')
correlation_file = correlation_file[0] + '.correlations.npz'

freqs = np.load(args.npz_frequencies_file)['freqs']

def flatten_freqs(freqs):
        
    freqs_shape = freqs.shape
    flat_shape = ( freqs_shape[0] * freqs_shape[1], freqs_shape[2], freqs_shape[3])
    return freqs.reshape(flat_shape)

distances = np.array(map(corr, flatten_freqs(freqs))).reshape(freqs.shape[:2])

np.save_compressed(correlation_file, corr=distances)

from GamTools import corr
import numpy as np
import argparse

parser = argparse.ArgumentParser(description='Calculate coverage over different window sizes for a list of bam files.')
parser.add_argument('npz_frequencies_file', help='An npz file containing co-segregation frequencies to convert to correlations')

args = parser.parse_args()

correlation_file = args.npz_frequencies_file.split('.')
correlation_file[correlation_file.index('chrom')] = "corr"
correlation_file = '.'.join(correlation_file)

freqs = np.load(args.npz_frequencies_file)['freqs']

def flatten_freqs(freqs):
        
    freqs_shape = freqs.shape
    flat_shape = ( freqs_shape[0] * freqs_shape[1], freqs_shape[2], freqs_shape[3])
    return freqs.reshape(flat_shape)

distances = np.array(map(corr, flatten_freqs(freqs))).reshape(freqs.shape[:2])

np.savez_compressed(correlation_file, corr=distances)

Change how/where to save the file
Change how/where to save the file

  from GamTools import corr
  import numpy as np
  import argparse
  
  parser = argparse.ArgumentParser(description='Calculate coverage over different window sizes for a list of bam files.')
  parser.add_argument('npz_frequencies_file', help='An npz file containing co-segregation frequencies to convert to correlations')
  
  args = parser.parse_args()
  
  correlation_file = args.npz_frequencies_file.split('.')
- correlation_file = correlation_file[0] + '.correlations.npz'
+ correlation_file[correlation_file.index('chrom')] = "corr"
+ correlation_file = '.'.join(correlation_file)
  
  freqs = np.load(args.npz_frequencies_file)['freqs']
  
  def flatten_freqs(freqs):
          
      freqs_shape = freqs.shape
      flat_shape = ( freqs_shape[0] * freqs_shape[1], freqs_shape[2], freqs_shape[3])
      return freqs.reshape(flat_shape)
  
  distances = np.array(map(corr, flatten_freqs(freqs))).reshape(freqs.shape[:2])
  
- np.save_compressed(correlation_file, corr=distances)
+ np.savez_compressed(correlation_file, corr=distances)
  
Change how/where to save the file
## Code Before:
from GamTools import corr
import numpy as np
import argparse

parser = argparse.ArgumentParser(description='Calculate coverage over different window sizes for a list of bam files.')
parser.add_argument('npz_frequencies_file', help='An npz file containing co-segregation frequencies to convert to correlations')

args = parser.parse_args()

correlation_file = args.npz_frequencies_file.split('.')
correlation_file = correlation_file[0] + '.correlations.npz'

freqs = np.load(args.npz_frequencies_file)['freqs']

def flatten_freqs(freqs):
        
    freqs_shape = freqs.shape
    flat_shape = ( freqs_shape[0] * freqs_shape[1], freqs_shape[2], freqs_shape[3])
    return freqs.reshape(flat_shape)

distances = np.array(map(corr, flatten_freqs(freqs))).reshape(freqs.shape[:2])

np.save_compressed(correlation_file, corr=distances)

## Instruction:
Change how/where to save the file
## Code After:
from GamTools import corr
import numpy as np
import argparse

parser = argparse.ArgumentParser(description='Calculate coverage over different window sizes for a list of bam files.')
parser.add_argument('npz_frequencies_file', help='An npz file containing co-segregation frequencies to convert to correlations')

args = parser.parse_args()

correlation_file = args.npz_frequencies_file.split('.')
correlation_file[correlation_file.index('chrom')] = "corr"
correlation_file = '.'.join(correlation_file)

freqs = np.load(args.npz_frequencies_file)['freqs']

def flatten_freqs(freqs):
        
    freqs_shape = freqs.shape
    flat_shape = ( freqs_shape[0] * freqs_shape[1], freqs_shape[2], freqs_shape[3])
    return freqs.reshape(flat_shape)

distances = np.array(map(corr, flatten_freqs(freqs))).reshape(freqs.shape[:2])

np.savez_compressed(correlation_file, corr=distances)
