コード例 #1
0
ファイル: long.py プロジェクト: janetxinli/rosalind
def main():
    check_input(sys.argv[0])
    seqs = []
    for _, seq in read_fasta(sys.argv[1]):
        seqs.append(seq)
    graph = create_graph(seqs)
    print(find_shortest_superstring(graph))
コード例 #2
0
def main():
    """Print distance matrix for input sequences."""
    check_input(sys.argv[0])
    sequences = []
    for _, seq in read_fasta(sys.argv[1]):
        sequences.append(seq)
    for row in create_matrix(sequences):
        print(" ".join([str(i) for i in row]))
コード例 #3
0
ファイル: lcsq.py プロジェクト: janetxinli/rosalind
def main():
    """Find longest common subsequence of input sequences."""
    check_input(sys.argv[0])
    seqs = []
    for _, seq in read_fasta(sys.argv[1]):
        seqs.append(seq)

    print(find_common_subsequence(seqs[0], seqs[1]))
コード例 #4
0
def main():
    """Print erroneous and correct reads."""
    check_input(sys.argv[0])
    reads = []
    for _, seq in read_fasta(sys.argv[1]):
        reads.append(seq)
    corrected_reads = find_erroneous_reads(reads)
    for pair in corrected_reads:
        print("->".join(pair))
コード例 #5
0
def main():
    """Print GC content for input sequence."""
    check_input(sys.argv[0])
    gc_content = {}
    for header, seq in read_fasta(sys.argv[1]):
        gc_content[get_gc(seq)] = header
    max_gc = max(gc_content)
    print(gc_content[max_gc])
    print(max_gc)
コード例 #6
0
def main():
    """Splice and translate input DNA string."""
    check_input(sys.argv[0])
    seqs = []
    for _, seq in read_fasta(sys.argv[1]):
        transcribed = rna(seq)
        seqs.append(transcribed)

    mrna = splice(seqs)
    print(translate(mrna))
コード例 #7
0
def main():
    """Print consensus sequence and profile matrix for a given set of sequences."""
    check_input(sys.argv[0])
    infile = sys.argv[1]
    seqs = []
    for _, seq in read_fasta(infile):
        seqs.append(seq)
    profile = generate_profile(seqs)
    print(get_consensus(profile))
    print_profile(profile)
コード例 #8
0
ファイル: lcsm.py プロジェクト: janetxinli/rosalind
def main():
    """Find common substring in input sequences."""
    check_input(sys.argv[0])
    contigs = []
    for _, seq in read_fasta(sys.argv[1]):
        contigs.append(seq)

    # Check shortest sequence against other sequences
    checker = min(contigs, key=lambda x: len(x))
    print(get_common(contigs, checker))
コード例 #9
0
def main():
    """Find indices of a given subsequence in a given sequence."""
    check_input(sys.argv[0])
    i = 0
    for _, seq in read_fasta(sys.argv[1]):
        if i == 0:
            sequence = seq
        elif i == 1:
            search = seq
        i += 1

    print(find_subsequence(sequence, search))
コード例 #10
0
ファイル: grph.py プロジェクト: janetxinli/rosalind
def main():
    """Load all sequences from the input fasta file and print graph."""
    check_input(sys.argv[0])
    sequences = {}

    for header, seq in read_fasta(sys.argv[1]):
        sequences[header] = seq
    for header_1 in sequences:
        for header_2 in sequences:
            if sequences[header_1] != sequences[
                    header_2]:  # Only compare different seqs
                if suffix(sequences[header_1]) == prefix(sequences[header_2]):
                    print(header_1, header_2, file=sys.stdout)
コード例 #11
0
def main():
    """Count transitions and transversions between two given DNA strings."""
    check_input(sys.argv[0])
    i = 0
    for _, seq in read_fasta(sys.argv[1]):
        if i == 0:
            seq_1 = seq
        elif i == 1:
            seq_2 = seq
        i += 1

    transitions, transversions = count_mutations(seq_1, seq_2)
    ratio = transitions / transversions
    print(ratio)
コード例 #12
0
ファイル: orf.py プロジェクト: janetxinli/rosalind
def main():
    """Find all candidate protein strings."""
    check_input(sys.argv[0])
    for _, seq in read_fasta(sys.argv[1]):
        inseq = seq

    rna_reading_frames = find_all_rnas(inseq)
    orfs = []
    for rna in rna_reading_frames:
        orfs.extend(to_mrna(rna))

    unique_orfs = set(orfs)
    for orf in unique_orfs:
        peptide = translate(orf)
        if len(peptide) > 0:
            print(translate(orf), file=sys.stdout)
コード例 #13
0
ファイル: kmp.py プロジェクト: janetxinli/rosalind
def main():
    """Read file and print the failure array."""
    check_input(sys.argv[0])
    for _, seq in read_fasta(sys.argv[1]):
        print(" ".join([str(x) for x in create_failure_array(seq)]))
コード例 #14
0
def main():
    """Print 4-mer composition array."""
    check_input(sys.argv[0])
    for _, seq in read_fasta(sys.argv[1]):
        count_composition(seq)
コード例 #15
0
def main():
    """Count perfect matchings in input sequence."""
    check_input(sys.argv[0])
    for _, seq in read_fasta(sys.argv[1]):
        print(str(perfect_matchings(seq)))
コード例 #16
0
def main():
    """Count maximum matchings for the input sequence."""
    check_input(sys.argv[0])
    for _, seq in read_fasta(sys.argv[1]):
        print(maximum_matchings(seq))
コード例 #17
0
ファイル: revp.py プロジェクト: janetxinli/rosalind
def main():
    """Find reverse palindromes in input."""
    check_input(sys.argv[0])
    for _, seq in read_fasta(sys.argv[1]):
        for pair in find_revp(seq):
            print(*pair, sep=" ")