Skip to content

Instantly share code, notes, and snippets.

View StephenFordham's full-sized avatar

Stephen Fordham StephenFordham

View GitHub Profile
def pattern_check(pattern):
answer = pattern.upper()
if (len(answer) < 4 or len(answer) > 8) or re.search('[^AGCT]', answer):
raise argparse.ArgumentTypeError('A valid restriction enzyme must be entered: \n'
'1. Between 4-8 bases long \n2. Comprise of the nucleotides A, G, C and T')
return answer
@StephenFordham
StephenFordham / order_of_arguments.py
Created April 16, 2019 16:07
order_of_arguments
arg_parse.py -p AAGGCGC AGAGGGAT -i E.coli_genome.fasta -c -2
arg_parse.py -i E.coli_genome.fasta -c -2 -p AAGGCGC AGAGGGAT
arg_parse.py --pattern AAGGCGC AGAGGGAT -i E.coli_genome.fasta --count_no 50
arg_parse.py --input_filename E.coli_genome.fasta -c 50 -p AAGGCGC AGAGGGAT
result = []
for seq in args.pattern:
for x in re.findall(seq, DNA):
result.append(x)
restriction_enzyme = collections.Counter(result)
@StephenFordham
StephenFordham / restriciton_enzyme_search.py
Created April 16, 2019 20:11
Restriction_enzyme_search
import re
import collections
import argparse
parser = argparse.ArgumentParser(description='Finding restriction sites in DNA sequences')
def count_valid(count_no):
num = int(count_no)
if num < 1:
@StephenFordham
StephenFordham / add_argument_pattern.py
Created April 17, 2019 19:38
add_argument_pattern
parser.add_argument('-p',
'--pattern',
help='Enter the pattern of the restriction enzyme',
type=pattern_check,
nargs='*')
def count_valid(count_no):
num = int(count_no)
if num < 1:
raise argparse.ArgumentTypeError('The count has to be an integer above 0')
return num
@StephenFordham
StephenFordham / Count_number_argument.py
Created April 17, 2019 19:49
Count_number_argument
parser.add_argument('-c',
'--count_no',
help='count number to be specified',
type=count_valid,
default=0)
import re
import collections
import argparse
parser = argparse.ArgumentParser(description='Finding restriction sites in DNA sequences')
def count_valid(count_no):
num = int(count_no)
if num < 1:
import pandas as pd
Blast = pd.read_csv('SPECIES_BLAST_DATA.CSV')
print(Blast.head())
print(Blast.columns)
print(Blast.shape)