コード例 #1
0
            recs.append(rec)
    return recs


def justin(recs, ALPHA):
    n = len(recs)
    sumP = 0
    keep = 0
    for i in range(n):
        sumP += 1 - recs[i].Preg
        recs[i].fdr = sumP / float(i + 1)
        if (recs[i].fdr > ALPHA): break
        else: recs[i].sig = "SIGNIFICANT"
        keep = i
    return keep


#=========================================================================
# main()
#=========================================================================
if (len(sys.argv) != 3):
    exit(ProgramName.get() + " <predictions.txt> <fdr>\n")
(infile, fdr) = sys.argv[1:]
fdr = float(fdr)

preds = loadPredictions(infile)
preds.sort(key=lambda x: 1 - x.Preg)
keep = justin(preds, fdr)
for rec in preds:
    rec.print()
コード例 #2
0
ファイル: tail-probability.py プロジェクト: wxyz/BIRD
def analyze(fields,greaterLess,threshold,threshold2):
    array=toFloat(fields)
    n=len(array)
    count=None
    if(greaterLess=="less"): count=countLess(array,threshold)
    elif(greaterLess=="greater"): count=countGreater(array,threshold)
    else: count=countTwoTailed(array,threshold,threshold2)
    P=float(count)/float(n)
    return P
        

#=========================================================================
# main()
#=========================================================================
if(len(sys.argv)!=4):
    exit(ProgramName.get()+" <thetas.txt> <greater|less|twotailed> <threshold>\n")
(filename,greaterLess,threshold)=sys.argv[1:]
if(greaterLess not in VALID_COMP): 
    exit("comparison must be one of greater, less, or twotailed")
threshold=float(threshold)
if(threshold<0): exit("threshold cannot be negative")
threshold2=None
if(greaterLess=="twotailed"):
    if(threshold==0.0): exit("threshold cannot be 0 for twotailed")
    threshold2=float(1.0/threshold)
    if(threshold>threshold2): (threshold,threshold2)=(threshold2,threshold)

with open(filename,"rt") as IN:
    for line in IN:
        fields=line.rstrip().split()
        P=analyze(fields,greaterLess,threshold,threshold2)
コード例 #3
0
from Rex import Rex
rex=Rex()

ROOT="/home/bmajoros/PopSTARR/graham"
MEM=50000
NICE=500
jobName="TRIM"
maxParallel=1000
THREADS=31
TRIMMOMATIC="java -jar /data/reddylab/software/Trimmomatic-0.33/Trimmomatic-0.33/trimmomatic-0.33.jar PE"

#=========================================================================
# main()
#=========================================================================
if(len(sys.argv)!=5):
    exit(ProgramName.get()+" <adapters.fasta> <fastq-in> <fastq-out> <full-path-to-slurms>\n")
(adaptersFasta,fastqIn,fastqOut,slurmDir)=sys.argv[1:]

files=os.listdir(fastqIn)
writer=SlurmWriter()
for file in files:
    if(not rex.find("(.*[_-])R1([_-].*)\.fastq.gz",file)): continue
    file1=file
    file2=rex[1]+"R2"+rex[2]+".fastq.gz"
    cmd=TRIMMOMATIC+" -threads "+str(THREADS)+" -phred33 "+\
        fastqIn+"/"+file1+" "+fastqIn+"/"+file2+" "+\
        fastqOut+"/"+rex[1]+"_FWD_paired.fq.gz "+\
        fastqOut+"/"+rex[1]+"_FWD_unpaired.fq.gz "+\
        fastqOut+"/"+rex[1]+"_REV_paired.fq.gz "+\
        fastqOut+"/"+rex[1]+"_REV_unpaired.fq.gz "+\
        "ILLUMINACLIP:"+adaptersFasta+\
コード例 #4
0
ファイル: build-network.py プロジェクト: bmajoros/BioMaLL
    for i in range(n):
        print("   (neuron ",nextIndex," (layer ",whichLayer,")",
              " (transfer sigmoid) (output)",sep="")
        Shuffler.shuffleArray(prevLayer)
        inputs=prevLayer[:fanIn]
        for j in inputs:
            print("      (input (from ",j,") (weight 0))",sep="")
        print("   )")
        indices.append(nextIndex)
        nextIndex+=1

#=========================================================================
# main()
#=========================================================================
if(len(sys.argv)!=3):
    exit(ProgramName.get()+" <layer-sizes:1000,300,30,1> <fan-ins:10,5,30>\n")
(layerSizes,fanIns)=sys.argv[1:]

layerSizes=[int(x) for x in layerSizes.split(",")]
fanIns=[int(x) for x in fanIns.split(",")]
numLayers=len(layerSizes)
if(len(fanIns)!=numLayers-1): raise Exception("number of fan-ins is wrong")

nextIndex=0
prevLayer=None
print("(network")
for layer in range(numLayers):
    if(layer==0): 
        prevLayer=generateInputLayer(layerSizes[0],nextIndex,layer)
    elif(layer<numLayers-1): 
        prevLayer=generateHiddenLayer(layerSizes[layer],nextIndex,layer,
コード例 #5
0
#!/usr/bin/env python
#=========================================================================
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
# License (GPL) version 3, as described at www.opensource.org.
# Copyright (C)2016 William H. Majoros ([email protected]).
#=========================================================================
from __future__ import (absolute_import, division, print_function,
                        unicode_literals, generators, nested_scopes,
                        with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii, chr,
                      hex, input, next, oct, open, pow, round, super, filter,
                      map, zip)
import random
import ProgramName
import sys
from FastaWriter import FastaWriter

if (len(sys.argv) != 3):
    exit(ProgramName.get() + " <length> <id>")
L = int(sys.argv[1])
id = sys.argv[2]
seq = ""
alphabet = ("A", "C", "G", "T")
for i in range(L):
    index = int(random.random() * 4)
    nuc = alphabet[index]
    seq += nuc

writer = FastaWriter()
writer.addToFasta(">" + id, seq, sys.stdout)
コード例 #6
0
ファイル: random-dna.py プロジェクト: bmajoros/python
#!/usr/bin/env python
#=========================================================================
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
# License (GPL) version 3, as described at www.opensource.org.
# Copyright (C)2016 William H. Majoros ([email protected]).
#=========================================================================
from __future__ import (absolute_import, division, print_function, 
   unicode_literals, generators, nested_scopes, with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii,
   chr, hex, input, next, oct, open, pow, round, super, filter, map, zip)
import random
import ProgramName
import sys
from FastaWriter import FastaWriter

if(len(sys.argv)!=3):
    exit(ProgramName.get()+" <length> <id>")
L=int(sys.argv[1])
id=sys.argv[2]
seq=""
alphabet=("A","C","G","T")
for i in range(L):
    index=int(random.random()*4)
    nuc=alphabet[index]
    seq+=nuc

writer=FastaWriter()
writer.addToFasta(">"+id,seq,sys.stdout)


コード例 #7
0
ファイル: fix-vcf.py プロジェクト: ReddyLab/POPSTARR2
                        unicode_literals, generators, nested_scopes,
                        with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii, chr,
                      hex, input, next, oct, open, pow, round, super, filter,
                      map, zip)
# The above imports should allow this program to run in both Python 2 and
# Python 3.  You might need to update your version of module "future".
import sys
import ProgramName
import gzip

#=========================================================================
# main()
#=========================================================================
if (len(sys.argv) != 2):
    exit(ProgramName.get() + " <in.vcf.gz>\n")
(infile, ) = sys.argv[1:]

variants = {}
for line in gzip.open(infile):
    line = line.decode("utf-8").rstrip()
    if (len(line) > 0 and line[0] == "#"):
        print(line)
        continue
    fields = line.split("\t")
    if (len(fields) >= 9):
        if (len(fields[0]) < 3 or fields[0][:3] != "chr"):
            fields[0] = "chr" + fields[0]
        if (fields[2] == "."): fields[2] = fields[0] + "@" + fields[1]
        line = ""
        for field in fields[:len(fields) - 1]:
コード例 #8
0
    reduction=0
    increase=0
    for i in range(n):
        if(thetas[i]<maxLeft): reduction+=1
        if(thetas[i]>minRight): increase+=1
    leftP=float(reduction)/float(n)
    rightP=float(increase)/float(n)
    Preg=leftP if leftP>rightP else rightP
    print(ID,median,CI_left,CI_right,Preg,sep="\t")

#=========================================================================
# main()
#=========================================================================
(options,args)=getopt.getopt(sys.argv[1:],"s:t:")
if(len(args)!=6):
    exit(ProgramName.get()+" [-s stanfile] [-t thetafile] <model> <min-effect> <input.txt> <output.txt> <#MCMC-samples> <firstVariant-lastVariant>\n   -s = save raw STAN file\n   -t = save theta samples\n   variant range is zero-based and inclusive\n   min-effect (lambda) must be >= 1\n")
(model,minEffect,inFile,outfile,numSamples,numVariants)=args
stanFile=None
thetaFile=None
for pair in options:
    (key,value)=pair
    if(key=="-s"): stanFile=value
    if(key=="-t"): thetaFile=value
if(not rex.find("(\d+)-(\d+)",numVariants)):
    exit(numVariants+": specify range of variants: first-last")
firstIndex=int(rex[1])
lastIndex=int(rex[2])
minEffect=float(minEffect)
if(minEffect<1): raise Exception("Min-effect must be >= 1")
THETA=None
if(thetaFile is not None): THETA=open(thetaFile,"wt")
コード例 #9
0
ファイル: hello-world.py プロジェクト: bmajoros/python
#!/usr/bin/env python
from __future__ import (absolute_import, division, print_function, 
   unicode_literals, generators, nested_scopes, with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii, chr, 
   hex, input, next, oct, open, pow, round, super, filter, map, zip)
import ProgramName
import sys
import os
from Interval import Interval
from ConfigFile import ConfigFile
from SummaryStats import SummaryStats
import random

# Process command line
name=ProgramName.get();
if(len(sys.argv)!=3):
  print(name," <parm1> <parm2>")
  exit()
parm1=sys.argv[1]
parm2=sys.argv[2]
print(parm1, parm2)

print ("Hello, world\n")

for i in range(1,10):
  print (i,end="")
print("\n")

i1=Interval(1,10)
i2=Interval(1.5,7.3)
sub=i1.minus(i2)
コード例 #10
0
ファイル: credible-interval.py プロジェクト: wxyz/BIRD
def toFloat(fields):
    array = []
    for field in fields:
        array.append(float(field))
    return array


def analyze(fields, lower, upper):
    array = toFloat(fields)
    npArray = np.array(array)
    a = np.percentile(npArray, lower * 100)
    b = np.percentile(npArray, upper * 100)
    return (a, b)


#=========================================================================
# main()
#=========================================================================
if (len(sys.argv) != 3):
    exit(ProgramName.get() + " <thetas.txt> <alpha>\n")
(filename, alpha) = sys.argv[1:]
alpha = float(alpha)
lower = alpha / 2.0
upper = 1.0 - lower

with open(filename, "rt") as IN:
    for line in IN:
        fields = line.rstrip().split()
        (a, b) = analyze(fields, lower, upper)
        print(a, b, sep="\t")
コード例 #11
0
ファイル: parse-pileup.py プロジェクト: ReddyLab/POPSTARR2
        c = bases[i]
        if (c in ACGT):
            if (index >= len(qual)):
                exit(bases + "\n" + qual + "\n" + str(index) + "\t" + c)
            q = qual[index]
            #print(c,q,ord(q),sep="\t")
            if (QUALITY[ord(q)] >= MIN_QUAL): counts[c] = counts.get(c, 0) + 1
            index += 1
    return counts


#=========================================================================
# main()
#=========================================================================
if (len(sys.argv) != 4):
    exit(ProgramName.get() + " <sorted.vcf.gz> <pileup.txt> <min-quality>\n")
(vcf, pileup, MIN_QUAL) = sys.argv[1:]
MIN_QUAL = int(MIN_QUAL)

# Process the VCF file to get the ref and alt alleles
variants = {}
for line in gzip.open(vcf):
    line = line.decode("utf-8")
    if (len(line) > 0 and line[0] == "#"): continue
    fields = line.rstrip().split()
    if (len(fields) < 9): continue
    (chr, pos, id, ref, alt, x, Pass, flags, GT) = fields[:9]
    altFields = alt.split(",")
    alt = altFields[0]  # Keeping only the first alternate allele
    #if(id=="."): continue
    if (id == "."): id = chr + "@" + pos
コード例 #12
0
ファイル: new-python-class.py プロジェクト: bmajoros/python
#!/usr/bin/env python
#=========================================================================
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
# License (GPL) version 3, as described at www.opensource.org.
# Copyright (C)2016 William H. Majoros ([email protected]).
#=========================================================================
from __future__ import (absolute_import, division, print_function, 
   unicode_literals, generators, nested_scopes, with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii,
   chr, hex, input, next, oct, open, pow, round, super, filter, map, zip)
import os
import sys
import ProgramName

# Process command line
name=ProgramName.get();
if(len(sys.argv)!=2):
    sys.exit(name+" <classname>")
className=sys.argv[1]

# Write file
filename=className+".py"
if(os.path.exists(filename)):
    sys.exit(filename+" exists");
fh=open(filename,"w")
header="\n".join(["#=========================================================================",
    "# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public",
    "# License (GPL) version 3, as described at www.opensource.org.",
    "# Copyright (C)2016 William H. Majoros ([email protected]).",
    "#=========================================================================",
    "from __future__ import (absolute_import, division, print_function,",
コード例 #13
0
        ID = IDs[i]
        phenotypeRec = phenotypes.get(ID, None)
        if (phenotypeRec is None): continue
        phenotype = phenotypeRec[phenotypeID]
        point = [phenotype]
        point.extend(phenotypeRec[5:])
        points.append(point)
    #print(points)
    #exit()


#=========================================================================
# main()
#=========================================================================
if (len(sys.argv) != 2):
    exit(ProgramName.get() + " <phenotype:1-5>\n")
(phenotypeID, ) = sys.argv[1:]
phenotypeID = int(phenotypeID) - 1
if (phenotypeID < 0): exit("phenotype must be 1-5")

phenotypes = loadPhenotypes(PHENOTYPES)
effects = loadEffects(EFFECTS)
IDs = None
points = []
initialized = False
predictorNum = 1
for chrom in CHROMS:
    vcf = VCF + "/" + chrom + "/" + chrom + ".vcf.gz"
    #print("processing",vcf,flush=True)
    IN = gzip.open(vcf, "rt")
    for line in IN:
コード例 #14
0
#!/usr/bin/env python
#=========================================================================
# Copyright (C)William H. Majoros ([email protected])
#=========================================================================
from __future__ import (absolute_import, division, print_function,
                        unicode_literals, generators, nested_scopes,
                        with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii, chr,
                      hex, input, next, oct, open, pow, round, super, filter,
                      map, zip)
# The above imports should allow this program to run in both Python 2 and
# Python 3.  You might need to update your version of module "future".
import sys
import ProgramName

#=========================================================================
# main()
#=========================================================================
if (len(sys.argv) != 2):
    exit(ProgramName.get() + " <>\n")
() = sys.argv[1:]
コード例 #15
0
#!/usr/bin/env python
#=========================================================================
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
# License (GPL) version 3, as described at www.opensource.org.
# Author: William H. Majoros ([email protected])
#=========================================================================
from __future__ import (absolute_import, division, print_function,
                        unicode_literals, generators, nested_scopes,
                        with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii, chr,
                      hex, input, next, oct, open, pow, round, super, filter,
                      map, zip)
# The above imports should allow this program to run in both Python 2 and
# Python 3.  You might need to update your version of module "future".
import sys
import ProgramName
from EssexParser import EssexParser

#=========================================================================
# main()
#=========================================================================
if (len(sys.argv) != 2):
    exit(ProgramName.get() + " <in.essex>\n")
(infile, ) = sys.argv[1:]

parser = EssexParser(infile)
while (True):
    tree = parser.nextElem()
    if (tree is None): break
    tree.print(sys.stdout)
コード例 #16
0
ファイル: parse-pileup.py プロジェクト: BeefSong/POPSTARR2

def parseBases(bases):
    bases = removeIndels(bases)
    bases = bases.upper()
    counts = {}
    for c in bases:
        if (c in ACGT): counts[c] = counts.get(c, 0) + 1
    return counts


#=========================================================================
# main()
#=========================================================================
if (len(sys.argv) != 3):
    exit(ProgramName.get() + " <sorted.vcf.gz> <pileup.txt>\n")
(vcf, pileup) = sys.argv[1:]

# Process the VCF file to get the ref and alt alleles
variants = {}
for line in gzip.open(vcf):
    line = line.decode("utf-8")
    if (len(line) > 0 and line[0] == "#"): continue
    fields = line.rstrip().split()
    if (len(fields) < 9): continue
    (chr, pos, id, ref, alt, x, Pass, flags, GT) = fields[:9]
    altFields = alt.split(",")
    alt = altFields[0]  # Keeping only the first alternate allele
    if (id == "."): continue
    if (variants.get(chr, None) is None): variants[chr] = []
    variants[chr].append(Variant(int(pos), id, ref, alt))
コード例 #17
0
        for line in IN:
            fields = line.rstrip().split()
            if (len(fields) != 12): continue
            (chrom, pos, variant, P, Padj, effect, DNAref, DNAalt, RNAref,
             RNAalt, ref, alt) = fields
            rnaFreq = float(RNAalt) / float(RNAref + RNAalt)
            dnaFreq = float(DNAalt) / float(DNAref + DNAalt)
            hash[variant] = (rnaFreq, dnaFreq)
    return hash


#=========================================================================
# main()
#=========================================================================
if (len(sys.argv) != 3):
    exit(ProgramName.get() + " <bowtie.txt> <hisat.txt>\n")
(bowtieFile, hisatFile) = sys.argv[1:]

bowtie = load(bowtieFile)
hisat = load(hisatFile)
keys = bowtie.keys()
rnaGreater = 0
rnaLess = 0
rnaSame = 0
dnaGreater = 0
dnaLess = 0
dnaSame = 0
agree = 0
disagree = 0
for variant in keys:
    if (hisat.get(variant, None) == None): continue
コード例 #18
0
    bestDiff=None
    bestI=None
    for i in range(n):
        x=legal[i]
        diff=abs(value-x)
        if(best is None or diff<bestDiff):
            best=x
            bestDiff=diff
            bestI=i
    return (best,bestI)

#=========================================================================
# main()
#=========================================================================
if(len(sys.argv)!=5):
    exit("\n"+ProgramName.get()+" <FDR> <effect> <maf> <depth>\n\
  FDR is one of 0.1, 0.05, 0.1\n\
  effect is ratio of transcriptional reates for alt versus ref allele\n\
")
(fdr,theta,maf,depth)=sys.argv[1:]
fdr=float(fdr)
theta=float(theta)
maf=float(maf)
depth=int(depth)

# Check that parms are legal
if(fdr!=0.1 and fdr!=0.05 and fdr!=0.01):
    exit("FDR must be one of 0.1, 0.05, 0.01")
if(theta<0): exit("effect must be > 0")
if(maf<=0 or maf>=1): exit("maf must be between 0 and 1")
if(depth<=0): exit("depth must be > 0")
コード例 #19
0
ファイル: parse-stan.py プロジェクト: bmajoros/python
#=========================================================================
from __future__ import (absolute_import, division, print_function, 
   unicode_literals, generators, nested_scopes, with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii,
   chr, hex, input, next, oct, open, pow, round, super, filter, map, zip)
# The above imports should allow this program to run in both Python 2 and
# Python 3.  You might need to update your version of module "future".
import sys
import ProgramName
from StanParser import StanParser

#=========================================================================
# main()
#=========================================================================
if(len(sys.argv)<3):
    exit(ProgramName.get()+" <infile.txt> <var1> <var2> ...\n")
infile=sys.argv[1]
variables=sys.argv[2:]

parser=StanParser(infile)
#(median,mean,SD,min,max)=parser.getSummary(variable)
#print("# posterior median=",median,sep="")
samplesByVar=[]
n=0
for var in variables:
    samples=parser.getVariable(var)
    samplesByVar.append(samples)
    n=len(samples)
for i in range(n):
    line=[]
    for sample in samplesByVar: line.append(str(sample[i]))
コード例 #20
0
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
# License (GPL) version 3, as described at www.opensource.org.
# Copyright (C)2017 William H. Majoros ([email protected]).
#=========================================================================
from __future__ import (absolute_import, division, print_function,
                        unicode_literals, generators, nested_scopes,
                        with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii, chr,
                      hex, input, next, oct, open, pow, round, super, filter,
                      map, zip)
# The above imports should allow this program to run in both Python 2 and
# Python 3.  You might need to update your version of module "future".
import sys
import ProgramName
from BetaBinomial import BetaBinomial

#=========================================================================
# main()
#=========================================================================
if (len(sys.argv) != 5):
    exit(ProgramName.get() + " <alpha> <beta> <n> <k>\n")
(alpha, beta, n, k) = sys.argv[1:]
alpha = int(alpha)
beta = int(beta)
n = int(n)
k = int(k)

bb = BetaBinomial()
P = bb.P(alpha, beta, n, k)
print(P)
コード例 #21
0
ファイル: reverse.py プロジェクト: bmajoros/python
#!/usr/bin/env python
#=========================================================================
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
# License (GPL) version 3, as described at www.opensource.org.
# Author: William H. Majoros ([email protected])
#=========================================================================
from __future__ import (absolute_import, division, print_function,
                        unicode_literals, generators, nested_scopes,
                        with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii, chr,
                      hex, input, next, oct, open, pow, round, super, filter,
                      map, zip)
# The above imports should allow this program to run in both Python 2 and
# Python 3.  You might need to update your version of module "future".
import sys
import ProgramName

#=========================================================================
# main()
#=========================================================================
if (len(sys.argv) != 2):
    exit(ProgramName.get() + " <infile.txt>\n")
(infile, ) = sys.argv[1:]

lines = []
with open(infile, "rt") as IN:
    for line in IN:
        lines.append(line)
for i in range(len(lines) - 1, -1, -1):
    print(lines[i], end="")
コード例 #22
0
ファイル: fastb-lengths.py プロジェクト: bmajoros/python
#!/usr/bin/env python
#=========================================================================
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
# License (GPL) version 3, as described at www.opensource.org.
# Copyright (C)2016 William H. Majoros ([email protected]).
#=========================================================================
from __future__ import (absolute_import, division, print_function,
                        unicode_literals, generators, nested_scopes,
                        with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii, chr,
                      hex, input, next, oct, open, pow, round, super, filter,
                      map, zip)
from Fastb import Fastb
import ProgramName
import sys

if (len(sys.argv) != 2):
    sys.exit(ProgramName.get() + " in.fastb")
filename = sys.argv[1]

fastb = Fastb(filename)
numTracks = fastb.numTracks()
for i in range(numTracks):
    track = fastb.getIthTrack(i)
    L = track.getLength()
    id = track.getID()
    print(id + "\t" + str(L))
コード例 #23
0
                        with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii, chr,
                      hex, input, next, oct, open, pow, round, super, filter,
                      map, zip)
# The above imports should allow this program to run in both Python 2 and
# Python 3.  You might need to update your version of module "future".
import sys
import ProgramName
from FastaReader import FastaReader
from FastaWriter import FastaWriter
from Rex import Rex

rex = Rex()

#=========================================================================
# main()
#=========================================================================
if (len(sys.argv) != 3):
    exit(ProgramName.get() + " <in.fasta> <out.fasta>\n")
(infile, outfile) = sys.argv[1:]

OUT = open(outfile, "wt")
writer = FastaWriter()
reader = FastaReader(infile)
while (True):
    (defline, seq) = reader.nextSequence()
    if (not defline): break
    if (not rex.find(">chr", defline)): continue
    writer.addToFasta(defline, seq, OUT)
OUT.close()
コード例 #24
0
        interval.begin=interval.intCenter()
        interval.end=interval.begin+1
        interval.type="peak"
        interval.dir=direction
        array.append(interval)

def loadPeaks(bedDir,timepoint,expression):
    addPeaks(bedDir,timepoint,"up",expression)
    addPeaks(bedDir,timepoint,"down",expression)
    addPeaks(bedDir,timepoint,"nonresp",expression)
    
#=========================================================================
# main()
#=========================================================================
if(len(sys.argv)!=3):
    exit(ProgramName.get()+" <bed-dir> <t8> \n")
(bedDir,timepoint)=sys.argv[1:]

print("loading TSSs...",file=sys.stderr,flush=True)
tssHash=loadTSS()

print("loading expression data...",file=sys.stderr,flush=True)
expression=loadExpression(timepoint,tssHash)

print("loading peaks...",file=sys.stderr,flush=True)
#upPeaks=BedReader.readAll(bedDir+"/"+timepoint+"_up.bed")
#downPeaks=BedReader.readAll(bedDir+"/"+timepoint+"_down.bed")
#samePeaks=BedReader.readAll(bedDir+"/"+timepoint+"_nonresp.bed")
loadPeaks(bedDir,timepoint,expression)

print("loading Hi-C data...",file=sys.stderr,flush=True)
コード例 #25
0
ファイル: fastb-lengths.py プロジェクト: bmajoros/python
#!/usr/bin/env python
#=========================================================================
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
# License (GPL) version 3, as described at www.opensource.org.
# Copyright (C)2016 William H. Majoros ([email protected]).
#=========================================================================
from __future__ import (absolute_import, division, print_function, 
   unicode_literals, generators, nested_scopes, with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii,
   chr, hex, input, next, oct, open, pow, round, super, filter, map, zip)
from Fastb import Fastb
import ProgramName
import sys

if(len(sys.argv)!=2):
    sys.exit(ProgramName.get()+" in.fastb")
filename=sys.argv[1]

fastb=Fastb(filename)
numTracks=fastb.numTracks()
for i in range(numTracks):
    track=fastb.getIthTrack(i)
    L=track.getLength()
    id=track.getID()
    print(id+"\t"+str(L))
コード例 #26
0
ファイル: sort-matrixmarket.py プロジェクト: bmajoros/python
# Python 3.  You might need to update your version of module "future".
import sys
import ProgramName
import gzip
from Pipe import Pipe
import TempFilename

HEADERFILE = TempFilename.generate(".header")
SORTEDFILE = TempFilename.generate(".sorted")

#=========================================================================
# main()
#=========================================================================
if (len(sys.argv) != 4):
    exit(
        ProgramName.get() +
        " in.mtx.gz column out.mtx.gz\n    where column = 1-based field index\n"
    )
(infile, index, outfile) = sys.argv[1:]

OUT = open(HEADERFILE, "wt")
numHeader = 1
with gzip.open(infile, "rt") as IN:
    for line in IN:
        if (len(line) == 0): raise Exception("unexpected empty line")
        if (line[0] == "%"):
            numHeader += 1
            print(line, file=OUT, end="")
        else:
            print(line, file=OUT, end="")
            break
コード例 #27
0
            newThisObjects=[]; newOtherObjects=[]
            for obj in thisObjects:
                if(obj.type=="gene"): newOtherObjects.append(obj)
                else: newThisObjects.append(obj)
            for obj in otherObjects:
                if(obj.type=="gene"): newThisObjects.append(obj)
                else: newOtherObjects.append(obj)
            thisRec.objects=newThisObjects
            otherRec.objects=newOtherObjects
                    
    
#=========================================================================
# main()
#=========================================================================
if(len(sys.argv)!=4):
    exit(ProgramName.get()+" <bed-dir> <t8> <randomize:0|1>\n")
(bedDir,timepoint,WANT_RANDOM)=sys.argv[1:]
WANT_RANDOM=int(WANT_RANDOM)

print("loading TSSs...",file=sys.stderr,flush=True)
tssHash=loadTSS()

print("loading expression data...",file=sys.stderr,flush=True)
expression=loadExpression(timepoint,tssHash)

print("loading peaks...",file=sys.stderr,flush=True)
loadPeaks(bedDir,timepoint,expression)

print("loading Hi-C data...",file=sys.stderr,flush=True)
loadHiC(expression)