Skip to content

Commit

Permalink
single-site fix
Browse files Browse the repository at this point in the history
  • Loading branch information
adsnps committed Dec 16, 2016
1 parent 9ff7b3f commit 437c1f7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion hase.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
parser.add_argument('-effect_intercept', action='store_true', default=False, help='Flag for add study effect to PD regression model')
parser.add_argument('-permute_ph', action='store_true', default=False, help='Flag for phenotype permutation')
parser.add_argument('-vcf', action='store_true', default=False, help='Flag for VCF data to convert')
parser.add_argument('-encoded', action='store_true', default=False, help='Flag to notify HASE that the input data are already encoded')
#TODO (low) save genotype after MAF
###

Expand Down Expand Up @@ -227,7 +228,7 @@
mapper.genotype_names=args.study_name
mapper.chunk_size=MAPPER_CHUNK_SIZE
mapper.reference_name=args.ref_name
mapper.load_flip(args.mapper)
mapper.load_flip(args.mapper, erase=args.encoded)
mapper.load(args.mapper)


Expand Down
7 changes: 4 additions & 3 deletions hdgwas/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,9 @@ def get_data(self,key,index):
def get_chunk(self,indices):
indices=self.link(indices)
indices=np.array(indices)
#print indices.shape
keys, ind = np.unique(indices[:,0], return_inverse=True)
result=None
gc.collect()
#print len(keys)
for i,k in enumerate(keys):
r=None
if k in self.loaded:
Expand Down Expand Up @@ -672,7 +670,10 @@ def __init__(self,path):
raise (e)
self.data_info={}
for i in self.files:
df=pd.read_csv(os.path.join(self.path,i), sep='\t', index_col=None)
for j in ['\t', ' ']:
df=pd.read_csv(os.path.join(self.path,i), sep=j, index_col=None)
if df.shape[1] > 1:
break
self.data_info[i]=np.array(df.columns[1:])


Expand Down
10 changes: 5 additions & 5 deletions hdgwas/pard.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ def partial_derivatives(save_path=None,COV=None,PHEN=None, GEN=None,

print ('Time to PD phenotype {} is {} s'.format(np.array(C).shape, t_phen.secs))

N_snps_read=0
while True:

with Timer() as t_gen:
SNPs_index, keys=MAP.get()
if isinstance(SNPs_index, type(None)):
genotype=GEN.get_next()
if isinstance(genotype, type(None)):
np.save(os.path.join(save_path,study_name+'_a_test.npy'), np.concatenate(a_test) )
np.save(os.path.join(save_path,study_name+'_metadata.npy'),metadata)
if B4_flag:
b4=np.concatenate(b4, axis=0)
np.save(os.path.join(save_path,study_name+'_b4.npy'),b4)
break
genotype=GEN.get(SNPs_index[0])
flip=MAP.flip[SNPs_index[0],0]
flip = MAP.flip[N_snps_read:N_snps_read + genotype.shape[0], 0]
N_snps_read += genotype.shape[0]
flip_index=(flip==-1)
genotype=np.apply_along_axis(lambda x: flip*(x-2*flip_index) ,0,genotype)
genotype=genotype[:,row_index[0]]
Expand Down
6 changes: 4 additions & 2 deletions hdgwas/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def summary(self):
print ('DF is not defined. Forced to use z_score statistics!')

if self.result_folder is None:
self.result_folder=glob.glob( os.path.join(self.result_path, '*.npy') )
self.result_folder=[ i for i in glob.glob( os.path.join(self.result_path, '*.npy') ) if 'RSID' not in i]

self.results['RSID']=np.array([])
self.results['p_value']=np.array([])
Expand Down Expand Up @@ -399,7 +399,7 @@ def push(self, new_keys,name=None, new_id=True):#TODO (middle) remove
self.dic[j]=[-1]*(self.n_study+1)
self.dic[j][self.n_study]=i

def load_flip(self,folder):
def load_flip(self,folder,erase=False):

if folder is None:
raise ValueError('Mapper is not defined!')
Expand All @@ -420,6 +420,8 @@ def load_flip(self,folder):
if len_flip!=self.flip[j].shape[0]:
raise ValueError('Different length of flip array between studies; used different ref panel!')
self.flip=np.array(self.flip).T
if erase:
self.flip.fill(1)

def load (self, folder):
if folder is None:
Expand Down

0 comments on commit 437c1f7

Please sign in to comment.