Skip to content

Commit eb847ef

Browse files
authored
Merge pull request #5 from TCLamnidis/optional_outgroup
made outgroup optional
2 parents a9c66c6 + 5488f01 commit eb847ef

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

RASCalculator.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
parser = argparse.ArgumentParser(description="Compute rare allele sharing statistics between two populations with respect to an outgroup, as well as outgroup F3 statistics. Also preforms error estimation using jackknifing, using the number of observed sites for normalisation.")
1111
parser.add_argument("-I", "--Input", metavar="<INPUT FILE>", type=argparse.FileType('r'), help="The input freqsum file. Omit to read from stdin.", required=False)
1212
parser.add_argument("-O", "--Output", metavar="<OUTPUT FILE>", type=argparse.FileType('w'), help="The output file. Omit to print in stdout.")
13-
parser.add_argument("-o", "--outgroup", metavar="POP", type=str, help="The outgroup to polarize all alleles with. As a useful standard choice, use Chimp as outgroup", required=True)
13+
parser.add_argument("-o", "--outgroup", metavar="POP", type=str, help="The outgroup to polarize all alleles with. As a useful standard choice, use Chimp as outgroup")
1414
parser.add_argument("-M", "--maxAF", metavar="<MAX ALLELE COUNT>", type=int, default=10, help="The maximum number of alleles (total) in the reference populations. The default maximum allele value is 10.", required=False)
1515
parser.add_argument("-m", "--minAF", metavar="<MIN ALLELE COUNT>", type=int, default=2, help="The minimum number of alleles (total) in the reference populations. The default minimum allele count is 2.", required=False)
1616

@@ -65,7 +65,7 @@
6565
assert (x in freqSumParser.popNames), "Population {} not found in FreqSum".format(x)
6666
for x in TestPops:
6767
assert (x in freqSumParser.popNames), "Population {} not found in FreqSum".format(x)
68-
assert (args.outgroup in freqSumParser.popNames), "Population {} not found in FreqSum".format(args.outgroup)
68+
assert (args.outgroup is None or args.outgroup in freqSumParser.popNames), "Population {} not found in FreqSum".format(args.outgroup)
6969

7070
def getMissingness(afDict):
7171
missing = 0
@@ -89,7 +89,7 @@ def getTotalDerivedAC(afDict):
8989
if afDict[pop] >= 0:
9090
nonRefAC += afDict[pop]
9191
totalCount += freqSumParser.sizes[pop]
92-
xOutgroup = afDict[args.outgroup] / freqSumParser.sizes[args.outgroup]
92+
xOutgroup = 0.0 if args.outgroup is None else afDict[args.outgroup] / freqSumParser.sizes[args.outgroup]
9393
if xOutgroup < 0.5:
9494
return nonRefAC
9595
else:
@@ -123,7 +123,7 @@ def getTotalDerivedAC(afDict):
123123
if missingness > args.MissingnessCutoff:
124124
continue
125125

126-
if afDict[args.outgroup] < 0:
126+
if args.outgroup is not None and afDict[args.outgroup] < 0:
127127
continue
128128

129129

@@ -143,7 +143,7 @@ def getTotalDerivedAC(afDict):
143143
mj[Lftidx][Tstidx][Chrom] += 1
144144
xLeft = afDict[leftPop] / leftSize
145145
xRight = afDict[testPop] / rightSize
146-
xOutgroup = afDict[args.outgroup] / freqSumParser.sizes[args.outgroup]
146+
xOutgroup = 0.0 if args.outgroup is None else afDict[args.outgroup] / freqSumParser.sizes[args.outgroup]
147147
add = (xLeft - xOutgroup) * (xRight - xOutgroup)
148148
if minorAlleleFreq >= args.f3FreqCutoff:
149149
RAS[Lftidx][Tstidx][maxAF+1][Chrom] += add # For Outgroup F3 Stats

0 commit comments

Comments
 (0)