Пример #1
0
# ------------------------------------
# Classes
# ------------------------------------

# ------------------------------------
# Main
# ------------------------------------

if __name__ == "__main__":
    # Get parameters
    args = argParser()
    fh = IO.mopen(args.ofname, 'w')
    lastbed = Bed("chr1\t0\t0")
    cnt = 0  # count of unique items
    for item in IO.BioReader(args.ifname, args.ftype):
        if item.chrom == lastbed.chrom and item.start == lastbed.start and item.stop == lastbed.stop:
            if args.names == 'c':
                lastbed.id += ";" + item.id
        else:
            if lastbed.stop != 0:
                cnt += 1
                if args.names == 'n':
                    lastbed.id = str(cnt)
                elif args.names == 'p':
                    lastbed.id = args.prefix + "_" + str(cnt)
                print >> fh, lastbed

            lastbed = copy.deepcopy(item)
    if lastbed.stop != 0:
        cnt += 1
Пример #2
0
import sys
import string
from ngslib import IO

# ------------------------------------
# constants
# ------------------------------------

# ------------------------------------
# Misc functions
# ------------------------------------

# ------------------------------------
# Classes
# ------------------------------------

# ------------------------------------
# Main
# ------------------------------------

if __name__=="__main__":
    if len(sys.argv)==1:
        sys.exit("Example:"+sys.argv[0]+" anno.tab/bed\n\tPrint TSS position in Bed format.")
    if sys.argv[1].endswith(".tab"):
        for item in IO.BioReader(sys.argv[1],ftype= 'genepred'):
            print item.toBed().getTSS()
    else:
        for item in IO.BioReader(sys.argv[1],ftype= 'bed'):
            print item.getTSS()

Пример #3
0
        sys.exit(p.print_help())
    args = p.parse_args()
    return args


# ------------------------------------
# Classes
# ------------------------------------

# ------------------------------------
# Main
# ------------------------------------

if __name__ == "__main__":
    # Get parameters
    args = argParser()
    fh = IO.mopen(args.ofname, 'w')
    tlen = 0
    gccnt = 0
    # Read fasta file
    for tseq in IO.BioReader(args.fname, 'fasta'):
        seq = str(tseq.seq).upper()
        cnt = seq.count("G") + seq.count("C")
        length = len(seq) - seq.count("N")
        print >> fh, "%s\t%-3.3f" % (tseq.id, float(cnt) /
                                     (length and length or 1))
        gccnt += cnt
        tlen += length
    print >> fh, "Total\t%-3.3f" % (float(gccnt) / (tlen and tlen or 1))
    IO.mclose(fh)
Пример #4
0
        if '.tab' in sys.argv[1]:
            ftype='gene'
        else:
            ftype='bed'

        # initiation annotations.
        annos={}
        #for chrom in IO.genomeSize('hg19'):
        for chrom in Utils.genomeSize(sys.argv[2]):
            if ftype=='bed':
                annos[chrom]=BedList()
            else:
                annos[chrom]=GeneBedList()
        
        # read annotations.
        for anno in IO.BioReader(sys.argv[1],ftype=ftype):
            if annos.has_key(anno.chrom):
                annos[anno.chrom].append(anno)

        # sort
        for chrom in annos:
            annos[chrom].sort()

        # Find nearest annoations
        for item in IO.BioReader(sys.argv[3],ftype='bed'):
            if annos.has_key(item.chrom) and len(annos[item.chrom])>0:
                tanno=annos[item.chrom][annos[item.chrom].bisect(item)]
                olen=item.overlapLength(tanno)
                if olen==1:
                    annostr=tanno.id+':overlap'
                    olen=0
Пример #5
0
# ------------------------------------

# ------------------------------------
# Classes
# ------------------------------------

# ------------------------------------
# Main
# ------------------------------------

if __name__ == "__main__":
    # Get parameters
    args = argParser()
    fh = IO.mopen(args.ofname, 'w')
    genome = FastaFile(args.genome)
    for i, item in enumerate(IO.BioReader(args.ifname, args.ftype)):
        try:
            strand = item.strand
        except:
            strand = "+"
        seq = item.getSeq(genome)
        if len(seq) > 0:
            print >> fh, '>' + (item.id != "NONAME" and item.id
                                or "item_" + str(i))
            if args.linelength:
                seq = seq.formatSeq(args.linelength)
            if args.case == 'u':
                seq = seq.upper()
            elif args.case == 'l':
                seq = seq.lower()
            print >> fh, seq
Пример #6
0
# ------------------------------------
# python modules
# ------------------------------------

import sys
import string
from ngslib import IO

# ------------------------------------
# constants
# ------------------------------------

# ------------------------------------
# Misc functions
# ------------------------------------

# ------------------------------------
# Classes
# ------------------------------------

# ------------------------------------
# Main
# ------------------------------------

if __name__ == "__main__":
    if len(sys.argv) == 1:
        sys.exit("Example:" + sys.argv[0] + " *.tab ")
    for item in IO.BioReader(sys.argv[1], 'genepred'):
        for exon in item.exons():
            print exon