Exemplo n.º 1
0
def unknown_primer(primers=None, input_file=None,output_file=None,
                   hg_version="hg19"):
                   
    ''' From a given primer pair, generate amplicon sequence information by
        parsing to the UCSC isPCR tool
        \b\n
    '''
    header = "\t".join(("Primer", "F_Primer","R_Primer", "Gene", "Product_Size",
                        "Primer_Range","GC%","Number_Amplicons", "\n"))
    print(header[:-1])

    # determine whether the input is a file or string and process accordingly 
    if input_file:
        all_matched_primers = []
        for line in [line.rstrip("\n").split("\t") for line in open(input_file)]:
            primer_name = line[0]
            f_primer = line[1].upper()
            r_primer = line[2].upper()
            full_amplicon_info = get_all_primer_info(primer_name, hg_version, 
                                                     f_primer, r_primer)
            if not full_amplicon_info:
                full_amplicon_info = "\t".join((primer_name, "-", "-", "-", 
                                                "-", "-", "-", "-"))
            all_matched_primers.append(full_amplicon_info)
            print(full_amplicon_info)
    else:
        primer_name = "query"
        f_primer = primers[0]
        r_primer = primers[1]
        full_amplicon_info = get_all_primer_info(primer_name, hg_version, 
                                                 f_primer, r_primer)
        print(full_amplicon_info)

    if output_file:
        write_to_output(all_matched_primers, output_file, header)
Exemplo n.º 2
0
def main(input_file, output_file=None, upstream=20, downstream=20,
         hg_version=default_hg_version,  download='n', configure='n',seq_dir=file_path[:-8]+"test/test_files/", genome=genome_path, vcf=None):
    '''
    From a genomic postion, genomic range or tab-deliminated file produce a
    reference sequence that can be compared with a sanger trace along with 
    said position/ranges gene/transcript/exon information. 
    ''' 
    # whether to download ttuner and or human genomes
    if download:
        subprocess.call([file_path+"download.sh"])
        config.config() 
        sys.exit()

    # write a config file
    if configure:
        config.config()
        sys.exit()
   
    # convert vcf to input file
    if vcf:
        vcf2input.vcf2input(vcf, "temp.tsv")
        sys.exit(0)

    # ensures the wrong human genome isnt used
    if hg_version not in genome:
        genome = None


    # intiate the classes in UCSC 
    reference = ScrapeSeq(input_file, upstream, downstream, hg_version)
    
    # if the arg given is a file, parse it in line by line otherwise assume its a string
    all_scrapped_info = parse_file(input_file, output_file, upstream, downstream,
                                   hg_version, seq_dir, reference, genome)
    

    # write the header and each element per line to the file
    if output_file:
        header = "\t".join(("Name", "Position", "Seq_Range", "AB1", "NGS", "Ref", "Seq",
                            "Result", "\n"))
        write_to_output(all_scrapped_info, output_file, header)
Exemplo n.º 3
0
def main(input_file, distance, size, gc, output_file=None,
         primer_database=file_path[:-8]+"test/primer_database.txt"):           
    ''' Takes variant postion(s) as input and matches it with an appropriate primer
        pair in a given primer database. 
    '''
    # allows one to pipe in an argument at the cmd, requires required=False in 
    # @click.argument()
    if not input_file:
        input_file = input()
    
    # get all genomic locations within primer pairs, from all primers in the database
    all_primer_pos = get_all_primer_pos(primer_database)        
    header = "\t".join(("Variant","Primer", "Position", "Gene_Name", 
                        "Amplicon_Size", "GC%", "Amplicon_Number", 
                        "Dist_from_F","Dist_from_R","\n"))
    print(header[:-1])

    # determine input type and process accordingly
    if os.path.isfile(input_file) is True:
        all_matched_primers = []
        for line in [line.rstrip("\n").split("\t") for line in open(input_file)]:
            var_name = line[0]
            var_pos = line[1].replace("chr","")
            filtered_primer_pos = filter_positions(distance, size, gc,
                                                   all_primer_pos)
            matched_primers = match(var_pos,filtered_primer_pos,var_name)
            all_matched_primers.append(matched_primers)
            print(matched_primers)

    else:
        output_file = None
        position = input_file.replace("chr","")
        filtered_primer_pos = filter_positions(distance, size, gc, all_primer_pos)
        matched_primers = match(position, filtered_primer_pos,"query")
        print(matched_primers)

    
    if output_file:
        write_to_output(all_matched_primers, output_file, header)