derived = gtS[0] gtS[0] = '1' gtS[1] = '0' elif (gtS[0] not in ances_gt) and (gtS[1] not in ances_gt): if gtS[0] == gtS[1]: derived = gtS[0] else: derived = '/'.join(str(e) for e in gtS) gtS[0] = '1' gtS[1] = '1' elif (gtS[0] in ances_gt) and (gtS[1] in ances_gt) and gtS[0] != gtS[1]: gtS = random.choice([['0', '1'], ['1', '0']]) else: raise IOError('Unexpected case: Ancestral:%s, GT:%s ' 'in %s %s' % (ances_gt, gtS, words[0], words[1])) gtSP = '/'.join(str(e) for e in gtS) samples_gtPlarized.append(gtSP) if all('./.' in gt for gt in samples_gtPlarized) or derived == 'N': continue else: wordsP = '\t'.join(str(e) for e in samples_gtPlarized) output.write('%s\t%s\t%s\t%s\t%s\n' % (words[0], words[1], ances_words[2], derived, wordsP)) counter = calls.lineCounter(counter) datafile.close() ances.close() output.close() print('Done!')
halfWindow = float(windows_step) / 2 with open(args.input) as datafile: datafile.readline() for line in datafile: words = line.split() CHRcurrent = words[0] POScurrent = int(words[1]) if CHRprev != CHRcurrent: if numberSNPs != 'NA': POS = int(windowsEnd - halfWindow) processWindow(CHRprev, POS, numberSNPs, output) numberSNPs = 1 windowsEnd = windows_step elif POScurrent > windowsEnd: POS = int(windowsEnd - halfWindow) processWindow(CHRprev, POS, numberSNPs, output) numberSNPs = 1 windowsEnd += windows_step else: numberSNPs += 1 CHRprev = CHRcurrent POSprev = POScurrent lineNumber = calls.lineCounter(lineNumber) POS = int(windowsEnd - halfWindow) processWindow(CHRprev, POS, numberSNPs, output) print 'Done!'