-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a bunch of code from old svn archive
- Loading branch information
1 parent
3b974f0
commit 07a15b3
Showing
53 changed files
with
7,243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
|
||
msFile, targetPos, maxDistanceFromTarget = sys.argv[1:] | ||
targetPos = float(targetPos) | ||
maxDistanceFromTarget = float(maxDistanceFromTarget) | ||
|
||
def processSimulation(samples, positions, targetPos, maxDistanceFromTarget, afs): | ||
freqH = {} | ||
for i in range(len(samples[0])): | ||
if abs(targetPos - positions[i]) < maxDistanceFromTarget: | ||
freqH[i] = {} | ||
for sample in samples: | ||
if not freqH[i].has_key(sample[i]): | ||
freqH[i][sample[i]] = 0 | ||
freqH[i][sample[i]] += 1 | ||
for i in freqH.keys(): | ||
alleles = sorted(freqH[i].keys()) | ||
if alleles == ['0', '1']: | ||
freq = freqH[i]['1'] | ||
afs[freq] += 1 | ||
|
||
if msFile == "stdin": | ||
isFile = False | ||
msStream = sys.stdin | ||
else: | ||
isFile = True | ||
msStream = open(msFile) | ||
|
||
header = msStream.readline() | ||
program,numSamples,numSims = header.strip().split()[:3] | ||
numSamples, numSims = int(numSamples), int(numSims) | ||
|
||
processedSims = 0 | ||
#advance to first simulation | ||
line = msStream.readline() | ||
while line.strip() != "//": | ||
line = msStream.readline() | ||
afs = -1 | ||
while line: | ||
if line.strip() != "//": | ||
sys.exit("Malformed ms-style output file: read '%s' instead of '//'. AAAARRRRGGHHH!!!!!\n" %(line.strip())) | ||
segsitesBlah,segsites = msStream.readline().strip().split() | ||
segsites = int(segsites) | ||
if segsitesBlah != "segsites:": | ||
sys.exit("Malformed ms-style output file. AAAARRRRGGHHH!!!!!\n") | ||
|
||
if segsites != 0: | ||
positionsLine = msStream.readline().strip().split() | ||
if not positionsLine[0] == "positions:": | ||
sys.exit("Malformed ms-style output file. AAAARRRRGGHHH!!!!!\n") | ||
positions = [float(x) for x in positionsLine[1:]] | ||
|
||
samples = [] | ||
for i in range(numSamples): | ||
sampleLine = msStream.readline().strip() | ||
if len(sampleLine) != segsites: | ||
sys.exit("Malformed ms-style output file %s segsites but %s columns in line: %s; line %s of %s samples AAAARRRRGGHHH!!!!!\n" %(segsites, len(sampleLine), sampleLine, i, numSamples)) | ||
samples.append(sampleLine) | ||
if len(samples) != numSamples: | ||
raise Exception | ||
if afs == -1: | ||
afs = [0]*len(samples) | ||
processSimulation(samples, positions, targetPos, maxDistanceFromTarget, afs) | ||
processedSims += 1 | ||
line = msStream.readline() | ||
#advance to the next non-empty line or EOF | ||
while line and line.strip() == "": | ||
line = msStream.readline() | ||
#print afs[1:] | ||
denom = float(sum(afs[1:])) | ||
for i in range(1,len(afs)): | ||
print "%i %le" %(i, afs[i]/denom) | ||
if processedSims != numSims: | ||
sys.exit("Malformed ms-style output file: %s of %s sims processed. AAAARRRRGGHHH!!!!!\n" %(processedSims, numSims)) | ||
|
||
if isFile: | ||
msStream.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
CC = gcc | ||
CFLAGS = -O3 -Wall -lm | ||
|
||
msMask: msMask.c | ||
$(CC) msMask.c -o msMask $(CFLAGS) | ||
|
||
msMaskAllRows: msMaskAllRows.c | ||
$(CC) msMaskAllRows.c -o msMaskAllRows $(CFLAGS) | ||
|
||
maskedStats: maskedStats.c msGeneralStats.c | ||
$(CC) maskedStats.c msGeneralStats.c -o maskedStats $(CFLAGS) | ||
|
||
niceStatsDan: niceStatsDan.c msGeneralStats.c | ||
$(CC) niceStatsDan.c msGeneralStats.c -g -o niceStatsDan $(CFLAGS) | ||
|
||
niceStatsSFSRegular: niceStatsSFSRegular.c msGeneralStats.c | ||
$(CC) niceStatsSFSRegular.c msGeneralStats.c -g -o niceStatsSFSRegular $(CFLAGS) | ||
|
||
niceStats: niceStats.c msGeneralStats.c | ||
$(CC) niceStats.c msGeneralStats.c -o niceStats $(CFLAGS) | ||
|
||
maskedStatsSubpop: maskedStatsSubpop.c msGeneralStats.c | ||
$(CC) maskedStatsSubpop.c msGeneralStats.c -o maskedStatsSubpop $(CFLAGS) | ||
|
||
twoPopnNiceStats: twoPopnNiceStats.c msGeneralStats.c | ||
$(CC) twoPopnNiceStats.c msGeneralStats.c -o twoPopnNiceStats $(CFLAGS) | ||
|
||
twoPopnStats_forML: twoPopnStats_forML.c msGeneralStats.c | ||
$(CC) twoPopnStats_forML.c msGeneralStats.c -o twoPopnStats_forML $(CFLAGS) | ||
|
||
onePopnStats_forGhostIntroML: onePopnStats_forGhostIntroML.c msGeneralStats.c | ||
$(CC) onePopnStats_forGhostIntroML.c msGeneralStats.c -o onePopnStats_forGhostIntroML $(CFLAGS) | ||
|
||
threePopnStats: threePopnStats.c msGeneralStats.c | ||
$(CC) threePopnStats.c msGeneralStats.c -o threePopnStats $(CFLAGS) | ||
msParams: msParams.c | ||
$(CC) msParams.c ../coalLib/ranlibComplete.c ../pgLib/bedFile.c -o msParams $(CFLAGS) | ||
|
||
msParamsSubpop: msParamsSubpop.c | ||
$(CC) msParamsSubpop.c ../coalLib/ranlibComplete.c ../pgLib/bedFile.c -o msParamsSubpop $(CFLAGS) | ||
|
||
msParamsSubpopNoAd: msParamsSubpopNoAd.c | ||
$(CC) msParamsSubpopNoAd.c ../coalLib/ranlibComplete.c ../pgLib/bedFile.c -o msParamsSubpopNoAd $(CFLAGS) | ||
|
||
msParamsSubpopTrans: msParamsSubpopTrans.c | ||
$(CC) msParamsSubpopTrans.c ../coalLib/ranlibComplete.c ../pgLib/bedFile.c -o msParamsSubpopTrans $(CFLAGS) | ||
|
||
msParamsTest: msParamsTest.c | ||
$(CC) msParamsTest.c ../coalLib/ranlibComplete.c ../pgLib/bedFile.c -o msParamsTest $(CFLAGS) | ||
|
||
pairDist: pairDist.c msGeneralStats.c | ||
$(CC) pairDist.c msGeneralStats.c -o pairDist $(CFLAGS) | ||
pairwiseDists: pairwiseDists.c msGeneralStats.c | ||
$(CC) pairwiseDists.c msGeneralStats.c -o pairwiseDists $(CFLAGS) | ||
|
||
pairwiseIBSTracts: pairwiseIBSTracts.c msGeneralStats.c | ||
$(CC) pairwiseIBSTracts.c msGeneralStats.c -o pairwiseIBSTracts $(CFLAGS) | ||
|
||
msHKA: msHKA.c msGeneralStats.c | ||
$(CC) msHKA.c msGeneralStats.c -o msHKA $(CFLAGS) | ||
|
||
ms2TwoSite: ms2TwoSite.c msGeneralStats.c | ||
$(CC) ms2TwoSite.c msGeneralStats.c -o ms2TwoSite $(CFLAGS) | ||
|
||
ms2TwoSite2Popn: ms2TwoSite2Popn.c msGeneralStats.c | ||
$(CC) ms2TwoSite2Popn.c msGeneralStats.c -o ms2TwoSite2Popn $(CFLAGS) | ||
|
||
ms2SFS2D: ms2SFS2D.c msGeneralStats.c | ||
$(CC) ms2SFS2D.c msGeneralStats.c -o ms2SFS2D $(CFLAGS) | ||
ms2SFS2D_discoal: ms2SFS2D_discoal.c msGeneralStats.c | ||
$(CC) ms2SFS2D_discoal.c msGeneralStats.c -o ms2SFS2D_discoal $(CFLAGS) | ||
|
||
ms2SFSVector: ms2SFSVector.c msGeneralStats.c | ||
$(CC) ms2SFSVector.c msGeneralStats.c -o ms2SFSVector $(CFLAGS) | ||
|
||
ms2SFSVectorWindow: ms2SFSVectorWindow.c msGeneralStats.c | ||
$(CC) ms2SFSVectorWindow.c msGeneralStats.c -o ms2SFSVectorWindow $(CFLAGS) | ||
|
||
discoal_mig2hmm: discoal_mig2hmm.c msGeneralStats.c | ||
$(CC) discoal_mig2hmm.c msGeneralStats.c -o discoal_mig2hmm $(CFLAGS) | ||
|
||
slideFST: slideFST.c msGeneralStats.c | ||
$(CC) slideFST.c msGeneralStats.c -o slideFST $(CFLAGS) | ||
|
||
niceStatsNoOmega: niceStatsNoOmega.c msGeneralStats.c | ||
$(CC) niceStatsNoOmega.c msGeneralStats.c -g -o niceStatsNoOmega $(CFLAGS) | ||
|
||
niceStatsShanku: niceStatsShanku.c msGeneralStats.c | ||
$(CC) niceStatsShanku.c msGeneralStats.c -o niceStatsShanku $(CFLAGS) | ||
|
||
niceStatsAchazSystem: niceStatsAchazSystem.c msGeneralStats.c | ||
$(CC) niceStatsAchazSystem.c msGeneralStats.c -O3 -o niceStatsAchazSystem $(CFLAGS) | ||
|
||
niceStatsDiploid: niceStatsDiploid.c msGeneralStats.c msDiploidStats.c | ||
$(CC) niceStatsDiploid.c msGeneralStats.c msDiploidStats.c -o niceStatsDiploid $(CFLAGS) | ||
niceStats4Gamete: niceStats4Gamete.c msGeneralStats.c | ||
$(CC) niceStats4Gamete.c msGeneralStats.c -o niceStats4Gamete $(CFLAGS) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//bitStuff.c | ||
// basic bit manipulations | ||
|
||
#include "bitStuff.h" | ||
|
||
int setBit(int x, unsigned char position) | ||
{ | ||
int mask = 1 << position; | ||
return x | mask; | ||
} | ||
|
||
int clearBit(int x, unsigned char position) | ||
{ | ||
int mask = 1 << position; | ||
return x & ~mask; | ||
} | ||
|
||
int modifyBit(int x, unsigned char position, bool newState) | ||
{ | ||
int mask = 1 << position; | ||
int state = (int) newState; // relies on true = 1 and false = 0 | ||
return (x & ~mask) | (-state & mask); | ||
} | ||
|
||
int flipBit(int x, unsigned char position) | ||
{ | ||
int mask = 1 << position; | ||
return x ^ mask; | ||
} | ||
|
||
bool isBitSet(int x, unsigned char position) | ||
{ | ||
x >>= position; | ||
return (x & 1) != 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
|
||
int setBit(int x, unsigned char position); | ||
int clearBit(int x, unsigned char position); | ||
int modifyBit(int x, unsigned char position, bool newState); | ||
int flipBit(int x, unsigned char position); | ||
bool isBitSet(int x, unsigned char position); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python | ||
import os, sys, gzip, random | ||
|
||
msFileDir, shuffle = sys.argv[1:] | ||
if not shuffle in ["shuffle", "no_shuffle"]: | ||
sys.exit("shuffle must be set to either 'shuffle' or 'no_shuffle'. AAAARRRRGGGGHHHHHHHHHH!!!!\n") | ||
|
||
def readAllMSRepsFromFile(msFileName): | ||
if msFileName.endswith(".gz"): | ||
fopen = gzip.open | ||
else: | ||
fopen = open | ||
msStream = fopen(msFileName) | ||
|
||
header = msStream.readline().strip().split() | ||
program,numSamples,numSims = header[:3] | ||
if len(header) > 3: | ||
otherParams = " " + " ".join(header[3:]) | ||
else: | ||
otherParams = "" | ||
numSamples, numSims = int(numSamples),int(numSims) | ||
|
||
#advance to first simulation | ||
line = msStream.readline() | ||
while not line.strip().startswith("//"): | ||
line = msStream.readline() | ||
repLs = [] | ||
while line: | ||
if not line.strip().startswith("//"): | ||
sys.exit("Malformed ms-style output file: read '%s' instead of '//'. AAAARRRRGGHHH!!!!!\n" %(line.strip())) | ||
repStr = ["\n//"] | ||
repStr.append(msStream.readline().strip()) #segsites line | ||
positionsLine = msStream.readline().strip() | ||
if not positionsLine.startswith("positions:"): | ||
sys.exit("Malformed ms-style output file. AAAARRRRGGHHH!!!!!\n") | ||
repStr.append(positionsLine) #positions line | ||
|
||
for i in range(numSamples): | ||
currLine = msStream.readline() | ||
repStr.append(currLine.strip()) | ||
line = msStream.readline() | ||
#advance to the next non-empty line or EOF | ||
while line and line.strip() == "": | ||
line = msStream.readline() | ||
repStr = "\n".join(repStr) | ||
repLs.append(repStr) | ||
msStream.close() | ||
|
||
return numSamples, repLs | ||
|
||
repLs = [] | ||
allNumSamples = {} | ||
for msFileName in os.listdir(msFileDir): | ||
sys.stderr.write("%s\n" %(msFileName)) | ||
currNumSamples, currRepLs = readAllMSRepsFromFile(msFileDir + "/" + msFileName) | ||
allNumSamples[currNumSamples] = 1 | ||
repLs += currRepLs | ||
assert len(allNumSamples) == 1 | ||
print "./msStyle %s %s\nblah\n" %(currNumSamples, len(repLs)) | ||
if shuffle == "shuffle": | ||
random.shuffle(repLs) | ||
print "\n".join(repLs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python | ||
import sys, gzip, random | ||
|
||
msFileName1, numReps1, msFileName2, numReps2, shuffle = sys.argv[1:] | ||
numReps1, numReps2 = int(numReps1), int(numReps2) | ||
if not shuffle in ["shuffle", "no_shuffle"]: | ||
sys.exit("shuffle must be set to either 'shuffle' or 'no_shuffle'. AAAARRRRGGGGHHHHHHHHHH!!!!\n") | ||
|
||
def readAllMSRepsFromFile(msFileName): | ||
msStream = open(msFileName) | ||
|
||
header = msStream.readline().strip().split() | ||
program,numSamples,numSims = header[:3] | ||
if len(header) > 3: | ||
otherParams = " " + " ".join(header[3:]) | ||
else: | ||
otherParams = "" | ||
numSamples, numSims = int(numSamples),int(numSims) | ||
|
||
#advance to first simulation | ||
line = msStream.readline() | ||
while line.strip() != "//": | ||
line = msStream.readline() | ||
repLs = [] | ||
while line: | ||
if line.strip() != "//": | ||
sys.exit("Malformed ms-style output file: read '%s' instead of '//'. AAAARRRRGGHHH!!!!!\n" %(line.strip())) | ||
repStr = ["\n//"] | ||
repStr.append(msStream.readline().strip()) #segsites line | ||
positionsLine = msStream.readline().strip() | ||
if not positionsLine.startswith("positions:"): | ||
sys.exit("Malformed ms-style output file. AAAARRRRGGHHH!!!!!\n") | ||
repStr.append(positionsLine) #positions line | ||
|
||
for i in range(numSamples): | ||
currLine = msStream.readline() | ||
repStr.append(currLine.strip()) | ||
line = msStream.readline() | ||
#advance to the next non-empty line or EOF | ||
while line and line.strip() == "": | ||
line = msStream.readline() | ||
repStr = "\n".join(repStr) | ||
repLs.append(repStr) | ||
msStream.close() | ||
|
||
return numSamples, repLs | ||
|
||
numSamples1, repLs1 = readAllMSRepsFromFile(msFileName1) | ||
numSamples2, repLs2 = readAllMSRepsFromFile(msFileName2) | ||
if numSamples1 != numSamples2: | ||
sys.exit("sample size differs between %s (%s) and %s (%s). AAAARRRRGGGGHHHHHHHH!\n" %(msFileName1, numSamples1, msFileName2, numSamples2)) | ||
print "./msStyle %s %s\nblah\n" %(numSamples1, numReps1+numReps2) | ||
if shuffle == "shuffle": | ||
random.shuffle(repLs1) | ||
random.shuffle(repLs2) | ||
print "\n".join(repLs1[:numReps1]) | ||
print "\n".join(repLs2[:numReps2]) |
Oops, something went wrong.