Ejemplo n.º 1
0
    p.add_argument("-n","--names",dest='names',type=str,metavar="names.lst",required=True,help='A file with sequence names. Can be "stdin".')
    p.add_argument("-o","--output",dest='ofname',type=str, default="stdout", metavar="output.fa",required=False,help='Output file name. Default is "stdout".')
    if len(sys.argv)==1:
        sys.exit(p.print_help())
    args = p.parse_args()
    return args

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

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

if __name__=="__main__":
    args = argParser()
    fh = IO.mopen(args.ofname, 'w')
    # Fasta file
    fa = FastaFile(args.ifname)
    f = IO.mopen(args.names)
    for faid in f:
        faid=faid.rstrip()
        seq=fa.getSeq(faid)
        print >> fh, ">"+faid
        print >> fh, seq.formatSeq()
    fa.close()
    IO.mclose(f)
    IO.mclose(fh)

Ejemplo n.º 2
0
# ------------------------------------
# Misc functions
# ------------------------------------

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

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

if __name__=="__main__":
    # Get parameters
    args=argParser()
    fh = IO.mopen(args.ofname)
    genome=FastaFile(args.genome)
    for i,item in enumerate(IO.BioReader(args.ifname,args.ftype)):
        try:
            strand = item.strand
        except:
            strand = "+"
        seq=genome.getSeq(item.chrom,item.start,item.stop,strand)
        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()
Ejemplo n.º 3
0
def ReadIntervals(bedfile):
    intervals = []
    for tbed in IO.ColumnReader(sys.argv[1], ftype="bed"):
        intervals.append(tbed)
    return intervals