How to use the pyfaidx.wrap_sequence function in pyfaidx

To help you get started, we’ve selected a few pyfaidx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hchyang / PSiTE / psite / chain2fa.py View on Github external
node=os.path.basename(chain)
    node=node.split('.')[0]
    outputf=[]
    for parental in 0,1:
        outputf.append(open(os.path.join(output,'{}.parental_{}.fa'.format(node,parental)),'w'))
    reference=None
    with open(chain) as inputf:
        seq_name=None
        parental=None
        seq=[]
        for line in inputf:
            line=line.rstrip()
            if line.startswith('>'):
                if seq:
                    outputf[parental].write('>{}\n'.format(seq_name))
                    for outputline in pyfaidx.wrap_sequence(width,''.join(seq)):
                        outputf[parental].write(outputline)
                seq_name,parental=line[1:].split()
                if parentalre.match(parental):
                    parental=int(parental.split(':')[1])
                    try:
                        reference=refs[parental]
                    except IndexError as e:
                        raise FastaMissingError('There is no parental {} avalible,\n'.format(parental)+
                            'which is required in the record ({}):\n{}\n'.format(chain,line)) from e
                else:
                    raise ChainFileError('The format of this line below from the chain file '+
                        '({}) is not correct:\n{}'.format(chain,line))
                seq=[]
            else:
                column=line.split()
                chroms=column[0]
github mdshw5 / pyfaidx / pyfaidx / cli.py View on Github external
sys.stderr.write("warning: {name} not found in file\n".format(**locals()))
        return
    if args.complement:
        sequence = sequence.complement
    if args.reverse:
        sequence = sequence.reverse
    if args.no_output:
        return
    if args.no_names:
        pass
    else:
        if (start or end) and not args.no_coords:
            yield ''.join(['>', sequence.fancy_name, '\n'])
        else:
            yield ''.join(['>', sequence.name, '\n'])
    for line in wrap_sequence(line_len, sequence.seq):
        yield line
github mdshw5 / pyfaidx / scripts / benchmark.py View on Github external
def make_long_fasta(filename, nrecs=250, seqlen=SEQLEN):
    headers = []
    with open(filename, 'w') as f:
        s = "ACTGACTGAC"
        for i in range(nrecs):
            h = "header%i" % i
            headers.append(h)
            f.write('>' + h + '\n')
            for line in pyfaidx.wrap_sequence(80, s * (seqlen//10)):
                f.write(line)
    return headers
github hchyang / PSiTE / psite / vcf2fa.py View on Github external
for snp in genome_profile[chroms]['hap_vars'][i]:
                        try:
                            segments.append(reference[chroms][start:(snp[0]-1)].seq)
                        except ValueError:
                            if snp[0]-start==1:
#This snp and the previous one is adjacent snps. e.g. chr1 45 (previous) and chr1 46 (current)
#If you retrive by reference['chr1'][45:(46-1)].seq, the return is not '', an error will pop actually.
                                pass
                            else:
                                raise
                        segments.append(snp[1])
                        start=snp[0]
                    if start{}\n'.format(chroms))
                    for outputline in pyfaidx.wrap_sequence(genome_profile[chroms]['linebases'],''.join(segments)):
                        output.write(outputline)
    t1 = time.time()
    print ("Total time running {}: {} seconds".format
       (prog, str(t1-t0)))